OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

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