Go to the documentation of this file.00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 #include "enrichedPatch.H"
00029 #include <OpenFOAM/demandDrivenData.H>
00030 #include <OpenFOAM/OFstream.H>
00031 #include <meshTools/meshTools.H>
00032 
00033 
00034 
00035 namespace Foam
00036 {
00037     defineTypeNameAndDebug(enrichedPatch, 0);
00038 }
00039 
00040 
00041 
00042 
00043 void Foam::enrichedPatch::calcMeshPoints() const
00044 {
00045     if (meshPointsPtr_)
00046     {
00047         FatalErrorIn("void enrichedPatch::calcMeshPoints() const")
00048             << "Mesh points already calculated."
00049             << abort(FatalError);
00050     }
00051 
00052     meshPointsPtr_ = new labelList(pointMap().toc());
00053     labelList& mp = *meshPointsPtr_;
00054 
00055     sort(mp);
00056 }
00057 
00058 
00059 void Foam::enrichedPatch::calcLocalFaces() const
00060 {
00061     if (localFacesPtr_)
00062     {
00063         FatalErrorIn("void enrichedPatch::calcLocalFaces() const")
00064             << "Local faces already calculated."
00065             << abort(FatalError);
00066     }
00067 
00068     
00069     const labelList& mp = meshPoints();
00070 
00071     Map<label> mpLookup(2*mp.size());
00072 
00073     forAll (mp, mpI)
00074     {
00075         mpLookup.insert(mp[mpI], mpI);
00076     }
00077 
00078     const faceList& faces = enrichedFaces();
00079 
00080     localFacesPtr_ = new faceList(faces.size());
00081     faceList& lf = *localFacesPtr_;
00082 
00083     forAll (faces, faceI)
00084     {
00085         const face& f = faces[faceI];
00086 
00087         face& curlf = lf[faceI];
00088 
00089         curlf.setSize(f.size());
00090 
00091         forAll (f, pointI)
00092         {
00093             curlf[pointI] = mpLookup.find(f[pointI])();
00094         }
00095     }
00096 }
00097 
00098 
00099 void Foam::enrichedPatch::calcLocalPoints() const
00100 {
00101     if (localPointsPtr_)
00102     {
00103         FatalErrorIn("void enrichedPatch::calcLocalPoints() const")
00104             << "Local points already calculated."
00105             << abort(FatalError);
00106     }
00107 
00108     const labelList& mp = meshPoints();
00109 
00110     localPointsPtr_ = new pointField(mp.size());
00111     pointField& lp = *localPointsPtr_;
00112 
00113     forAll (lp, i)
00114     {
00115         lp[i] = pointMap().find(mp[i])();
00116     }
00117 }
00118 
00119 
00120 void Foam::enrichedPatch::clearOut()
00121 {
00122     deleteDemandDrivenData(enrichedFacesPtr_);
00123 
00124     deleteDemandDrivenData(meshPointsPtr_);
00125     deleteDemandDrivenData(localFacesPtr_);
00126     deleteDemandDrivenData(localPointsPtr_);
00127     deleteDemandDrivenData(pointPointsPtr_);
00128     deleteDemandDrivenData(masterPointFacesPtr_);
00129 
00130     clearCutFaces();
00131 }
00132 
00133 
00134 
00135 
00136 
00137 Foam::enrichedPatch::enrichedPatch
00138 (
00139     const primitiveFacePatch& masterPatch,
00140     const primitiveFacePatch& slavePatch,
00141     const labelList& slavePointPointHits,
00142     const labelList& slavePointEdgeHits,
00143     const List<objectHit>& slavePointFaceHits
00144 )
00145 :
00146     masterPatch_(masterPatch),
00147     slavePatch_(slavePatch),
00148     pointMap_
00149     (
00150         masterPatch_.meshPoints().size()
00151       + slavePatch_.meshPoints().size()
00152     ),
00153     pointMapComplete_(false),
00154     pointMergeMap_(2*slavePatch_.meshPoints().size()),
00155     slavePointPointHits_(slavePointPointHits),
00156     slavePointEdgeHits_(slavePointEdgeHits),
00157     slavePointFaceHits_(slavePointFaceHits),
00158     enrichedFacesPtr_(NULL),
00159     meshPointsPtr_(NULL),
00160     localFacesPtr_(NULL),
00161     localPointsPtr_(NULL),
00162     pointPointsPtr_(NULL),
00163     masterPointFacesPtr_(NULL),
00164     cutFacesPtr_(NULL),
00165     cutFaceMasterPtr_(NULL),
00166     cutFaceSlavePtr_(NULL)
00167 {}
00168 
00169 
00170 
00171 
00172 Foam::enrichedPatch::~enrichedPatch()
00173 {
00174     clearOut();
00175 }
00176 
00177 
00178 
00179 
00180 const Foam::labelList& Foam::enrichedPatch::meshPoints() const
00181 {
00182     if (!meshPointsPtr_)
00183     {
00184         calcMeshPoints();
00185     }
00186 
00187     return *meshPointsPtr_;
00188 }
00189 
00190 
00191 const Foam::faceList& Foam::enrichedPatch::localFaces() const
00192 {
00193     if (!localFacesPtr_)
00194     {
00195         calcLocalFaces();
00196     }
00197 
00198     return *localFacesPtr_;
00199 }
00200 
00201 
00202 const Foam::pointField& Foam::enrichedPatch::localPoints() const
00203 {
00204     if (!localPointsPtr_)
00205     {
00206         calcLocalPoints();
00207     }
00208 
00209     return *localPointsPtr_;
00210 }
00211 
00212 
00213 const Foam::labelListList& Foam::enrichedPatch::pointPoints() const
00214 {
00215     if (!pointPointsPtr_)
00216     {
00217         calcPointPoints();
00218     }
00219 
00220     return *pointPointsPtr_;
00221 }
00222 
00223 
00224 bool Foam::enrichedPatch::checkSupport() const
00225 {
00226     const faceList& faces = enrichedFaces();
00227 
00228     bool error = false;
00229 
00230     forAll (faces, faceI)
00231     {
00232         const face& curFace = faces[faceI];
00233 
00234         forAll (curFace, pointI)
00235         {
00236             if (!pointMap().found(curFace[pointI]))
00237             {
00238                 WarningIn("void enrichedPatch::checkSupport()")
00239                     << "Point " << pointI << " of face " << faceI
00240                     << " global point index: " << curFace[pointI]
00241                     << " not supported in point map.  This is not allowed."
00242                     << endl;
00243 
00244                 error = true;
00245             }
00246         }
00247     }
00248 
00249     return error;
00250 }
00251 
00252 
00253 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
00254 {
00255     OFstream str(fName);
00256 
00257     const pointField& lp = localPoints();
00258 
00259     forAll(lp, pointI)
00260     {
00261         meshTools::writeOBJ(str, lp[pointI]);
00262     }
00263 
00264     const faceList& faces = localFaces();
00265 
00266     forAll(faces, faceI)
00267     {
00268         const face& f = faces[faceI];
00269 
00270         str << 'f';
00271         forAll(f, fp)
00272         {
00273             str << ' ' << f[fp]+1;
00274         }
00275         str << nl;
00276     }
00277 }
00278 
00279 
00280 
00281 
00282 
00283 
00284 
00285 
00286 
00287 
00288 
00289