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

PrimitivePatchMeshData.C

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 \*---------------------------------------------------------------------------*/
00026 
00027 #include "PrimitivePatch.H"
00028 #include "Map.H"
00029 
00030 
00031 
00032 // * * * * * * * * * * * * * Private Member Functions  * * * * * * * * * * * //
00033 
00034 template
00035 <
00036     class Face,
00037     template<class> class FaceList,
00038     class PointField,
00039     class PointType
00040 >
00041 
00042 void
00043 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00044 calcMeshData() const
00045 {
00046     if (debug)
00047     {
00048         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00049                "calcMeshData() : "
00050                "calculating mesh data in PrimitivePatch"
00051             << endl;
00052     }
00053 
00054     // It is considered an error to attempt to recalculate meshPoints
00055     // if they have already been calculated.
00056     if (meshPointsPtr_ || localFacesPtr_)
00057     {
00058         FatalErrorIn
00059         (
00060             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00061             "calcMeshData()"
00062         )   << "meshPointsPtr_ or localFacesPtr_already allocated"
00063             << abort(FatalError);
00064     }
00065 
00066     // Create a map for marking points.  Estimated size is 4 times the
00067     // number of faces in the patch
00068     Map<label> markedPoints(4*this->size());
00069 
00070 
00071     // Important:
00072     // ~~~~~~~~~~
00073     // In <= 1.5 the meshPoints would be in increasing order but this gives
00074     // problems in processor point synchronisation where we have to find out
00075     // how the opposite side would have allocated points.
00076 
00079     //forAll (*this, faceI)
00080     //{
00081     //    const Face& curPoints = this->operator[](faceI);
00082     //
00083     //    forAll (curPoints, pointI)
00084     //    {
00085     //        markedPoints.insert(curPoints[pointI], -1);
00086     //    }
00087     //}
00088     //
00091     //meshPointsPtr_ = new labelList(markedPoints.toc());
00092     //labelList& pointPatch = *meshPointsPtr_;
00093     //
00095     //sort(pointPatch);
00096     //
00098     //forAll (pointPatch, pointI)
00099     //{
00100     //    markedPoints.find(pointPatch[pointI])() = pointI;
00101     //}
00102 
00103     //- Unsorted version:
00104     DynamicList<label> meshPoints(2*this->size());
00105     forAll (*this, faceI)
00106     {
00107         const Face& curPoints = this->operator[](faceI);
00108 
00109         forAll (curPoints, pointI)
00110         {
00111             if (markedPoints.insert(curPoints[pointI], meshPoints.size()))
00112             {
00113                 meshPoints.append(curPoints[pointI]);
00114             }
00115         }
00116     }
00117     // Transfer to straight list (reuses storage)
00118     meshPointsPtr_ = new labelList(meshPoints, true);
00119 
00120 
00121     // Create local faces. Note that we start off from copy of original face
00122     // list (even though vertices are overwritten below). This is done so
00123     // additional data gets copied (e.g. region number of labelledTri)
00124     localFacesPtr_ = new List<Face>(*this);
00125     List<Face>& lf = *localFacesPtr_;
00126 
00127     forAll (*this, faceI)
00128     {
00129         const Face& curFace = this->operator[](faceI);
00130         lf[faceI].setSize(curFace.size());
00131 
00132         forAll (curFace, labelI)
00133         {
00134             lf[faceI][labelI] = markedPoints.find(curFace[labelI])();
00135         }
00136     }
00137 
00138     if (debug)
00139     {
00140         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00141                "calcMeshData() : "
00142                "finished calculating mesh data in PrimitivePatch"
00143             << endl;
00144     }
00145 }
00146 
00147 
00148 template
00149 <
00150     class Face,
00151     template<class> class FaceList,
00152     class PointField,
00153     class PointType
00154 >
00155 
00156 void
00157 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00158 calcMeshPointMap() const
00159 {
00160     if (debug)
00161     {
00162         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00163                "calcMeshPointMap() : "
00164                "calculating mesh point map in PrimitivePatch"
00165             << endl;
00166     }
00167 
00168     // It is considered an error to attempt to recalculate meshPoints
00169     // if they have already been calculated.
00170     if (meshPointMapPtr_)
00171     {
00172         FatalErrorIn
00173         (
00174             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00175             "calcMeshPointMap()"
00176         )   << "meshPointMapPtr_ already allocated"
00177             << abort(FatalError);
00178     }
00179 
00180     const labelList& mp = meshPoints();
00181 
00182     meshPointMapPtr_ = new Map<label>(2*mp.size());
00183     Map<label>& mpMap = *meshPointMapPtr_;
00184 
00185     forAll (mp, i)
00186     {
00187         mpMap.insert(mp[i], i);
00188     }
00189 
00190     if (debug)
00191     {
00192         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00193                "calcMeshPointMap() : "
00194                "finished calculating mesh point map in PrimitivePatch"
00195             << endl;
00196     }
00197 }
00198 
00199 
00200 template
00201 <
00202     class Face,
00203     template<class> class FaceList,
00204     class PointField,
00205     class PointType
00206 >
00207 
00208 void
00209 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00210 calcLocalPoints() const
00211 {
00212     if (debug)
00213     {
00214         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00215                "calcLocalPoints() : "
00216                "calculating localPoints in PrimitivePatch"
00217             << endl;
00218     }
00219 
00220     // It is considered an error to attempt to recalculate localPoints
00221     // if they have already been calculated.
00222     if (localPointsPtr_)
00223     {
00224         FatalErrorIn
00225         (
00226             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00227             "calcLocalPoints()"
00228         )   << "localPointsPtr_already allocated"
00229             << abort(FatalError);
00230     }
00231 
00232     const labelList& meshPts = meshPoints();
00233 
00234     localPointsPtr_ = new Field<PointType>(meshPts.size());
00235 
00236     Field<PointType>& locPts = *localPointsPtr_;
00237 
00238     forAll (meshPts, pointI)
00239     {
00240         locPts[pointI] = points_[meshPts[pointI]];
00241     }
00242 
00243     if (debug)
00244     {
00245         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00246             << "calcLocalPoints() : "
00247             << "finished calculating localPoints in PrimitivePatch"
00248             << endl;
00249     }
00250 }
00251 
00252 
00253 template
00254 <
00255     class Face,
00256     template<class> class FaceList,
00257     class PointField,
00258     class PointType
00259 >
00260 
00261 void
00262 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00263 calcPointNormals() const
00264 {
00265     if (debug)
00266     {
00267         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00268                "calcPointNormals() : "
00269                "calculating pointNormals in PrimitivePatch"
00270             << endl;
00271     }
00272 
00273     // It is considered an error to attempt to recalculate pointNormals
00274     // if they have already been calculated.
00275     if (pointNormalsPtr_)
00276     {
00277         FatalErrorIn
00278         (
00279             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00280             "calcPointNormals()"
00281         )   << "pointNormalsPtr_already allocated"
00282             << abort(FatalError);
00283     }
00284 
00285     const Field<PointType>& faceUnitNormals = faceNormals();
00286 
00287     const labelListList& pf = pointFaces();
00288 
00289     pointNormalsPtr_ = new Field<PointType>
00290     (
00291         meshPoints().size(),
00292         PointType::zero
00293     );
00294 
00295     Field<PointType>& n = *pointNormalsPtr_;
00296 
00297     forAll (pf, pointI)
00298     {
00299         PointType& curNormal = n[pointI];
00300 
00301         const labelList& curFaces = pf[pointI];
00302 
00303         forAll (curFaces, faceI)
00304         {
00305             curNormal += faceUnitNormals[curFaces[faceI]];
00306         }
00307 
00308         curNormal /= mag(curNormal) + VSMALL;
00309     }
00310 
00311     if (debug)
00312     {
00313         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00314                "calcPointNormals() : "
00315                "finished calculating pointNormals in PrimitivePatch"
00316             << endl;
00317     }
00318 }
00319 
00320 
00321 template
00322 <
00323     class Face,
00324     template<class> class FaceList,
00325     class PointField,
00326     class PointType
00327 >
00328 
00329 void
00330 Foam::PrimitivePatch<Face, FaceList, PointField, PointType>::
00331 calcFaceNormals() const
00332 {
00333     if (debug)
00334     {
00335         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00336                "calcFaceNormals() : "
00337                "calculating faceNormals in PrimitivePatch"
00338             << endl;
00339     }
00340 
00341     // It is considered an error to attempt to recalculate faceNormals
00342     // if they have already been calculated.
00343     if (faceNormalsPtr_)
00344     {
00345         FatalErrorIn
00346         (
00347             "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00348             "calcFaceNormals()"
00349         )   << "faceNormalsPtr_already allocated"
00350             << abort(FatalError);
00351     }
00352 
00353     faceNormalsPtr_ = new Field<PointType>(this->size());
00354 
00355     Field<PointType>& n = *faceNormalsPtr_;
00356 
00357     forAll (n, faceI)
00358     {
00359         n[faceI] = this->operator[](faceI).normal(points_);
00360         n[faceI] /= mag(n[faceI]) + VSMALL;
00361     }
00362 
00363     if (debug)
00364     {
00365         Pout<< "PrimitivePatch<Face, FaceList, PointField, PointType>::"
00366                "calcFaceNormals() : "
00367                "finished calculating faceNormals in PrimitivePatch"
00368             << endl;
00369     }
00370 }
00371 
00372 
00373 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd