1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27 \*---------------------------------------------------------------------------*/
29 #include "enrichedPatch.H"
30 #include "demandDrivenData.H"
32 #include "meshTools.H"
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
38 defineTypeNameAndDebug(enrichedPatch, 0);
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
44 void Foam::enrichedPatch::calcMeshPoints() const
48 FatalErrorIn("void enrichedPatch::calcMeshPoints() const")
49 << "Mesh points already calculated."
53 meshPointsPtr_ = new labelList(pointMap().toc());
54 labelList& mp = *meshPointsPtr_;
60 void Foam::enrichedPatch::calcLocalFaces() const
64 FatalErrorIn("void enrichedPatch::calcLocalFaces() const")
65 << "Local faces already calculated."
69 // Invert mesh points and renumber faces using it
70 const labelList& mp = meshPoints();
72 Map<label> mpLookup(2*mp.size());
76 mpLookup.insert(mp[mpI], mpI);
79 const faceList& faces = enrichedFaces();
81 localFacesPtr_ = new faceList(faces.size());
82 faceList& lf = *localFacesPtr_;
86 const face& f = faces[faceI];
88 face& curlf = lf[faceI];
90 curlf.setSize(f.size());
94 curlf[pointI] = mpLookup.find(f[pointI])();
100 void Foam::enrichedPatch::calcLocalPoints() const
104 FatalErrorIn("void enrichedPatch::calcLocalPoints() const")
105 << "Local points already calculated."
106 << abort(FatalError);
109 const labelList& mp = meshPoints();
111 localPointsPtr_ = new pointField(mp.size());
112 pointField& lp = *localPointsPtr_;
116 lp[i] = pointMap().find(mp[i])();
121 void Foam::enrichedPatch::clearOut()
123 deleteDemandDrivenData(enrichedFacesPtr_);
125 deleteDemandDrivenData(meshPointsPtr_);
126 deleteDemandDrivenData(localFacesPtr_);
127 deleteDemandDrivenData(localPointsPtr_);
128 deleteDemandDrivenData(pointPointsPtr_);
129 deleteDemandDrivenData(masterPointFacesPtr_);
135 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
137 // Construct from components
138 Foam::enrichedPatch::enrichedPatch
140 const primitiveFacePatch& masterPatch,
141 const primitiveFacePatch& slavePatch,
142 const labelList& slavePointPointHits,
143 const labelList& slavePointEdgeHits,
144 const List<objectHit>& slavePointFaceHits
147 masterPatch_(masterPatch),
148 slavePatch_(slavePatch),
151 masterPatch_.meshPoints().size()
152 + slavePatch_.meshPoints().size()
154 pointMapComplete_(false),
155 pointMergeMap_(2*slavePatch_.meshPoints().size()),
156 slavePointPointHits_(slavePointPointHits),
157 slavePointEdgeHits_(slavePointEdgeHits),
158 slavePointFaceHits_(slavePointFaceHits),
159 enrichedFacesPtr_(NULL),
160 meshPointsPtr_(NULL),
161 localFacesPtr_(NULL),
162 localPointsPtr_(NULL),
163 pointPointsPtr_(NULL),
164 masterPointFacesPtr_(NULL),
166 cutFaceMasterPtr_(NULL),
167 cutFaceSlavePtr_(NULL)
171 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
173 Foam::enrichedPatch::~enrichedPatch()
179 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 const Foam::labelList& Foam::enrichedPatch::meshPoints() const
188 return *meshPointsPtr_;
192 const Foam::faceList& Foam::enrichedPatch::localFaces() const
199 return *localFacesPtr_;
203 const Foam::pointField& Foam::enrichedPatch::localPoints() const
205 if (!localPointsPtr_)
210 return *localPointsPtr_;
214 const Foam::labelListList& Foam::enrichedPatch::pointPoints() const
216 if (!pointPointsPtr_)
221 return *pointPointsPtr_;
225 bool Foam::enrichedPatch::checkSupport() const
227 const faceList& faces = enrichedFaces();
231 forAll (faces, faceI)
233 const face& curFace = faces[faceI];
235 forAll (curFace, pointI)
237 if (!pointMap().found(curFace[pointI]))
239 WarningIn("void enrichedPatch::checkSupport()")
240 << "Point " << pointI << " of face " << faceI
241 << " global point index: " << curFace[pointI]
242 << " not supported in point map. This is not allowed."
254 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
258 const pointField& lp = localPoints();
262 meshTools::writeOBJ(str, lp[pointI]);
265 const faceList& faces = localFaces();
269 const face& f = faces[faceI];
274 str << ' ' << f[fp]+1;
281 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
284 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
287 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
290 // ************************************************************************* //