FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

cyclicPolyPatch.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2010 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software: you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by
00013     the Free Software Foundation, either version 3 of the License, or
00014     (at your option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
00023 
00024 Class
00025     Foam::cyclicPolyPatch
00026 
00027 Description
00028     Cyclic plane patch.
00029 
00030     Note: morph patch face ordering uses geometric matching so with the
00031     following restrictions:
00032         -halves should be flat planes.
00033         -no rotation in patch plane
00034 
00035     Uses a featureCos to find the two halves (or should be fully
00036     disconnected). Uses coupledPolyPatch::calcFaceTol to calculate
00037     tolerance per face which might need tweaking.
00038 
00039     Switch on 'cyclicPolyPatch' debug flag to write .obj files to show
00040     the matching.
00041 
00042 SourceFiles
00043     cyclicPolyPatch.C
00044     cyclicPolyPatchMorph.C
00045 
00046 \*---------------------------------------------------------------------------*/
00047 
00048 #ifndef cyclicPolyPatch_H
00049 #define cyclicPolyPatch_H
00050 
00051 #include <OpenFOAM/coupledPolyPatch.H>
00052 #include <OpenFOAM/SubField.H>
00053 #include <OpenFOAM/FixedList.H>
00054 #include <OpenFOAM/edgeList.H>
00055 #include <OpenFOAM/transform.H>
00056 
00057 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00058 
00059 namespace Foam
00060 {
00061 
00062 /*---------------------------------------------------------------------------*\
00063                       Class cyclicPolyPatch Declaration
00064 \*---------------------------------------------------------------------------*/
00065 
00066 class cyclicPolyPatch
00067 :
00068     public coupledPolyPatch
00069 {
00070     // Private data
00071 
00072         //- List of edges formed from connected points. e[0] is the point on
00073         //  the first half of the patch, e[1] the corresponding point on the
00074         //  second half.
00075         mutable edgeList* coupledPointsPtr_;
00076 
00077         //- List of connected edges. e[0] is the edge on the first half of the
00078         //  patch, e[1] the corresponding edge on the second half.
00079         mutable edgeList* coupledEdgesPtr_;
00080 
00081         //- Morph:angle between normals of neighbouring faces.
00082         //  Used to split cyclic into halves.
00083         scalar featureCos_;
00084 
00085         //- Type of transformation - rotational or translational
00086         transformType transform_;
00087 
00088         // For rotation
00089 
00090             //- Axis of rotation for rotational cyclics
00091             vector rotationAxis_;
00092 
00093             //- point on axis of rotation for rotational cyclics
00094             point rotationCentre_;
00095 
00096         // For translation
00097 
00098             //- Translation vector
00099             vector separationVector_;
00100 
00101 
00102     // Private member functions
00103 
00104         //- Find amongst selected faces the one with the largest area
00105         static label findMaxArea(const pointField&, const faceList&);
00106 
00107         void calcTransforms();
00108 
00109 
00110         // Face ordering
00111 
00112             //- Find the two parts of the faces of pp using feature edges.
00113             //  Returns true if successfull.
00114             bool getGeometricHalves
00115             (
00116                 const primitivePatch&,
00117                 labelList&,
00118                 labelList&
00119             ) const;
00120 
00121             //- Calculate geometric factors of the two halves.
00122             void getCentresAndAnchors
00123             (
00124                 const primitivePatch&,
00125                 const faceList& half0Faces,
00126                 const faceList& half1Faces,
00127 
00128                 pointField& ppPoints,
00129                 pointField& half0Ctrs,
00130                 pointField& half1Ctrs,
00131                 pointField& anchors0,
00132                 scalarField& tols
00133             ) const;
00134 
00135             //- Given matched faces matches the anchor point. Sets faceMap,
00136             //  rotation. Returns true if all matched.
00137             bool matchAnchors
00138             (
00139                 const bool report,
00140                 const primitivePatch&,
00141                 const labelList&,
00142                 const pointField&,
00143                 const labelList&,
00144                 const faceList&,
00145                 const labelList&,
00146                 const scalarField&,
00147 
00148                 labelList& faceMap,
00149                 labelList& rotation
00150             ) const;
00151 
00152             //- For rotational cases, try to find a unique face on each side
00153             //  of the cyclic.
00154             label getConsistentRotationFace
00155             (
00156                 const pointField& faceCentres
00157             ) const;
00158 
00159 
00160 protected:
00161 
00162     // Protected Member functions
00163 
00164         //- Initialise the calculation of the patch geometry
00165         virtual void initGeometry();
00166 
00167         //- Calculate the patch geometry
00168         virtual void calcGeometry();
00169 
00170         //- Initialise the patches for moving points
00171         virtual void initMovePoints(const pointField&);
00172 
00173         //- Correct patches after moving points
00174         virtual void movePoints(const pointField&);
00175 
00176         //- Initialise the update of the patch topology
00177         virtual void initUpdateMesh();
00178 
00179         //- Update of the patch topology
00180         virtual void updateMesh();
00181 
00182 public:
00183 
00184     //- Runtime type information
00185     TypeName("cyclic");
00186 
00187 
00188     // Constructors
00189 
00190         //- Construct from components
00191         cyclicPolyPatch
00192         (
00193             const word& name,
00194             const label size,
00195             const label start,
00196             const label index,
00197             const polyBoundaryMesh& bm
00198         );
00199 
00200         //- Construct from dictionary
00201         cyclicPolyPatch
00202         (
00203             const word& name,
00204             const dictionary& dict,
00205             const label index,
00206             const polyBoundaryMesh& bm
00207         );
00208 
00209         //- Construct as copy, resetting the boundary mesh
00210         cyclicPolyPatch(const cyclicPolyPatch&, const polyBoundaryMesh&);
00211 
00212         //- Construct given the original patch and resetting the
00213         //  face list and boundary mesh information
00214         cyclicPolyPatch
00215         (
00216             const cyclicPolyPatch& pp,
00217             const polyBoundaryMesh& bm,
00218             const label index,
00219             const label newSize,
00220             const label newStart
00221         );
00222 
00223         //- Construct and return a clone, resetting the boundary mesh
00224         virtual autoPtr<polyPatch> clone(const polyBoundaryMesh& bm) const
00225         {
00226             return autoPtr<polyPatch>(new cyclicPolyPatch(*this, bm));
00227         }
00228 
00229         //- Construct and return a clone, resetting the face list
00230         //  and boundary mesh
00231         virtual autoPtr<polyPatch> clone
00232         (
00233             const polyBoundaryMesh& bm,
00234             const label index,
00235             const label newSize,
00236             const label newStart
00237         ) const
00238         {
00239             return autoPtr<polyPatch>
00240             (
00241                 new cyclicPolyPatch(*this, bm, index, newSize, newStart)
00242             );
00243         }
00244 
00245 
00246     // Destructor
00247 
00248         virtual ~cyclicPolyPatch();
00249 
00250 
00251     // Member Functions
00252 
00253         //- Return connected points (in patch local point indexing). Demand
00254         //  driven calculation. Does primitivePatch::clearOut after calculation!
00255         const edgeList& coupledPoints() const;
00256 
00257         //- Return connected edges (in patch local edge indexing). Demand
00258         //  driven calculation. Does primitivePatch::clearOut after calculation!
00259         const edgeList& coupledEdges() const;
00260 
00261 
00262 
00263         // Transformation
00264 
00265             vector separation(const label facei) const
00266             {
00267                 if (facei < size()/2)
00268                 {
00269                     return coupledPolyPatch::separation()[0];
00270                 }
00271                 else
00272                 {
00273                     return -coupledPolyPatch::separation()[0];
00274                 }
00275             }
00276 
00277             const tensor& transformT(const label facei) const
00278             {
00279                 if (facei < size()/2)
00280                 {
00281                     return reverseT()[0];
00282                 }
00283                 else
00284                 {
00285                     return forwardT()[0];
00286                 }
00287             }
00288 
00289             template<class T>
00290             T transform(const T& t, const label facei) const
00291             {
00292                 if (parallel())
00293                 {
00294                     return t;
00295                 }
00296                 else
00297                 {
00298                     return Foam::transform(transformT(facei), t);
00299                 }
00300             }
00301 
00302             label transformLocalFace(const label facei) const
00303             {
00304                 if (facei < size()/2)
00305                 {
00306                     return facei + size()/2;
00307                 }
00308                 else
00309                 {
00310                     return facei - size()/2;
00311                 }
00312             }
00313 
00314             label transformGlobalFace(const label facei) const
00315             {
00316                 if (facei - start() < size()/2)
00317                 {
00318                     return facei + size()/2;
00319                 }
00320                 else
00321                 {
00322                     return facei - size()/2;
00323                 }
00324             }
00325 
00326             //- Type of transform
00327             transformType transform() const
00328             {
00329                 return transform_;
00330             }
00331 
00332             //- Axis of rotation for rotational cyclics
00333             const vector& rotationAxis() const
00334             {
00335                 return rotationAxis_;
00336             }
00337 
00338             //- point on axis of rotation for rotational cyclics
00339             const point& rotationCentre() const
00340             {
00341                 return rotationCentre_;
00342             }
00343 
00344             //- Translation vector for translational cyclics
00345             const vector& separationVector() const
00346             {
00347                 return separationVector_;
00348             }
00349 
00350 
00351 
00352         //- Initialize ordering for primitivePatch. Does not
00353         //  refer to *this (except for name() and type() etc.)
00354         virtual void initOrder(const primitivePatch&) const;
00355 
00356         //- Return new ordering for primitivePatch.
00357         //  Ordering is -faceMap: for every face
00358         //  index of the new face -rotation:for every new face the clockwise
00359         //  shift of the original face. Return false if nothing changes
00360         //  (faceMap is identity, rotation is 0), true otherwise.
00361         virtual bool order
00362         (
00363             const primitivePatch&,
00364             labelList& faceMap,
00365             labelList& rotation
00366         ) const;
00367 
00368 
00369         //- Write the polyPatch data as a dictionary
00370         virtual void write(Ostream&) const;
00371 };
00372 
00373 
00374 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00375 
00376 } // End namespace Foam
00377 
00378 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00379 
00380 #endif
00381 
00382 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines