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

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