FreeFOAM The Cross-Platform CFD Toolkit
enrichedPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
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
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25 
26 \*---------------------------------------------------------------------------*/
27 
28 #include "enrichedPatch.H"
30 #include <OpenFOAM/OFstream.H>
31 #include <meshTools/meshTools.H>
32 
33 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34 
35 namespace Foam
36 {
37  defineTypeNameAndDebug(enrichedPatch, 0);
38 }
39 
40 
41 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42 
43 void Foam::enrichedPatch::calcMeshPoints() const
44 {
45  if (meshPointsPtr_)
46  {
47  FatalErrorIn("void enrichedPatch::calcMeshPoints() const")
48  << "Mesh points already calculated."
49  << abort(FatalError);
50  }
51 
52  meshPointsPtr_ = new labelList(pointMap().toc());
53  labelList& mp = *meshPointsPtr_;
54 
55  sort(mp);
56 }
57 
58 
59 void Foam::enrichedPatch::calcLocalFaces() const
60 {
61  if (localFacesPtr_)
62  {
63  FatalErrorIn("void enrichedPatch::calcLocalFaces() const")
64  << "Local faces already calculated."
65  << abort(FatalError);
66  }
67 
68  // Invert mesh points and renumber faces using it
69  const labelList& mp = meshPoints();
70 
71  Map<label> mpLookup(2*mp.size());
72 
73  forAll (mp, mpI)
74  {
75  mpLookup.insert(mp[mpI], mpI);
76  }
77 
78  const faceList& faces = enrichedFaces();
79 
80  localFacesPtr_ = new faceList(faces.size());
81  faceList& lf = *localFacesPtr_;
82 
83  forAll (faces, faceI)
84  {
85  const face& f = faces[faceI];
86 
87  face& curlf = lf[faceI];
88 
89  curlf.setSize(f.size());
90 
91  forAll (f, pointI)
92  {
93  curlf[pointI] = mpLookup.find(f[pointI])();
94  }
95  }
96 }
97 
98 
99 void Foam::enrichedPatch::calcLocalPoints() const
100 {
101  if (localPointsPtr_)
102  {
103  FatalErrorIn("void enrichedPatch::calcLocalPoints() const")
104  << "Local points already calculated."
105  << abort(FatalError);
106  }
107 
108  const labelList& mp = meshPoints();
109 
110  localPointsPtr_ = new pointField(mp.size());
111  pointField& lp = *localPointsPtr_;
112 
113  forAll (lp, i)
114  {
115  lp[i] = pointMap().find(mp[i])();
116  }
117 }
118 
119 
120 void Foam::enrichedPatch::clearOut()
121 {
122  deleteDemandDrivenData(enrichedFacesPtr_);
123 
124  deleteDemandDrivenData(meshPointsPtr_);
125  deleteDemandDrivenData(localFacesPtr_);
126  deleteDemandDrivenData(localPointsPtr_);
127  deleteDemandDrivenData(pointPointsPtr_);
128  deleteDemandDrivenData(masterPointFacesPtr_);
129 
130  clearCutFaces();
131 }
132 
133 
134 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
135 
136 // Construct from components
137 Foam::enrichedPatch::enrichedPatch
138 (
139  const primitiveFacePatch& masterPatch,
140  const primitiveFacePatch& slavePatch,
141  const labelList& slavePointPointHits,
142  const labelList& slavePointEdgeHits,
143  const List<objectHit>& slavePointFaceHits
144 )
145 :
146  masterPatch_(masterPatch),
147  slavePatch_(slavePatch),
148  pointMap_
149  (
150  masterPatch_.meshPoints().size()
151  + slavePatch_.meshPoints().size()
152  ),
153  pointMapComplete_(false),
154  pointMergeMap_(2*slavePatch_.meshPoints().size()),
155  slavePointPointHits_(slavePointPointHits),
156  slavePointEdgeHits_(slavePointEdgeHits),
157  slavePointFaceHits_(slavePointFaceHits),
158  enrichedFacesPtr_(NULL),
159  meshPointsPtr_(NULL),
160  localFacesPtr_(NULL),
161  localPointsPtr_(NULL),
162  pointPointsPtr_(NULL),
163  masterPointFacesPtr_(NULL),
164  cutFacesPtr_(NULL),
165  cutFaceMasterPtr_(NULL),
166  cutFaceSlavePtr_(NULL)
167 {}
168 
169 
170 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
171 
173 {
174  clearOut();
175 }
176 
177 
178 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
179 
181 {
182  if (!meshPointsPtr_)
183  {
184  calcMeshPoints();
185  }
186 
187  return *meshPointsPtr_;
188 }
189 
190 
192 {
193  if (!localFacesPtr_)
194  {
195  calcLocalFaces();
196  }
197 
198  return *localFacesPtr_;
199 }
200 
201 
203 {
204  if (!localPointsPtr_)
205  {
206  calcLocalPoints();
207  }
208 
209  return *localPointsPtr_;
210 }
211 
212 
214 {
215  if (!pointPointsPtr_)
216  {
217  calcPointPoints();
218  }
219 
220  return *pointPointsPtr_;
221 }
222 
223 
225 {
226  const faceList& faces = enrichedFaces();
227 
228  bool error = false;
229 
230  forAll (faces, faceI)
231  {
232  const face& curFace = faces[faceI];
233 
234  forAll (curFace, pointI)
235  {
236  if (!pointMap().found(curFace[pointI]))
237  {
238  WarningIn("void enrichedPatch::checkSupport()")
239  << "Point " << pointI << " of face " << faceI
240  << " global point index: " << curFace[pointI]
241  << " not supported in point map. This is not allowed."
242  << endl;
243 
244  error = true;
245  }
246  }
247  }
248 
249  return error;
250 }
251 
252 
253 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
254 {
255  OFstream str(fName);
256 
257  const pointField& lp = localPoints();
258 
259  forAll(lp, pointI)
260  {
261  meshTools::writeOBJ(str, lp[pointI]);
262  }
263 
264  const faceList& faces = localFaces();
265 
266  forAll(faces, faceI)
267  {
268  const face& f = faces[faceI];
269 
270  str << 'f';
271  forAll(f, fp)
272  {
273  str << ' ' << f[fp]+1;
274  }
275  str << nl;
276  }
277 }
278 
279 
280 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
281 
282 
283 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
284 
285 
286 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
287 
288 
289 // ************************ vim: set sw=4 sts=4 et: ************************ //