enrichedPatch.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
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 \*---------------------------------------------------------------------------*/
25 
26 #include "enrichedPatch.H"
27 #include "demandDrivenData.H"
28 #include "OFstream.H"
29 #include "meshTools.H"
30 
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 
33 namespace Foam
34 {
35  defineTypeNameAndDebug(enrichedPatch, 0);
36 }
37 
38 
39 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
40 
41 void Foam::enrichedPatch::calcMeshPoints() const
42 {
43  if (meshPointsPtr_)
44  {
46  << "Mesh points already calculated."
47  << abort(FatalError);
48  }
49 
50  meshPointsPtr_ = new labelList(pointMap().toc());
51  labelList& mp = *meshPointsPtr_;
52 
53  sort(mp);
54 }
55 
56 
57 void Foam::enrichedPatch::calcLocalFaces() const
58 {
59  if (localFacesPtr_)
60  {
62  << "Local faces already calculated."
63  << abort(FatalError);
64  }
65 
66  // Invert mesh points and renumber faces using it
67  const labelList& mp = meshPoints();
68 
69  Map<label> mpLookup(2*mp.size());
70 
71  forAll(mp, mpI)
72  {
73  mpLookup.insert(mp[mpI], mpI);
74  }
75 
76  const faceList& faces = enrichedFaces();
77 
78  localFacesPtr_ = new faceList(faces.size());
79  faceList& lf = *localFacesPtr_;
80 
81  forAll(faces, facei)
82  {
83  const face& f = faces[facei];
84 
85  face& curlf = lf[facei];
86 
87  curlf.setSize(f.size());
88 
89  forAll(f, pointi)
90  {
91  curlf[pointi] = mpLookup.find(f[pointi])();
92  }
93  }
94 }
95 
96 
97 void Foam::enrichedPatch::calcLocalPoints() const
98 {
99  if (localPointsPtr_)
100  {
102  << "Local points already calculated."
103  << abort(FatalError);
104  }
105 
106  const labelList& mp = meshPoints();
107 
108  localPointsPtr_ = new pointField(mp.size());
109  pointField& lp = *localPointsPtr_;
110 
111  forAll(lp, i)
112  {
113  lp[i] = pointMap().find(mp[i])();
114  }
115 }
116 
117 
118 void Foam::enrichedPatch::clearOut()
119 {
120  deleteDemandDrivenData(enrichedFacesPtr_);
121 
122  deleteDemandDrivenData(meshPointsPtr_);
123  deleteDemandDrivenData(localFacesPtr_);
124  deleteDemandDrivenData(localPointsPtr_);
125  deleteDemandDrivenData(pointPointsPtr_);
126  deleteDemandDrivenData(masterPointFacesPtr_);
127 
128  clearCutFaces();
129 }
130 
131 
132 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
133 
134 // Construct from components
136 (
137  const primitiveFacePatch& masterPatch,
138  const primitiveFacePatch& slavePatch,
139  const labelList& slavePointPointHits,
140  const labelList& slavePointEdgeHits,
141  const List<objectHit>& slavePointFaceHits
142 )
143 :
144  masterPatch_(masterPatch),
145  slavePatch_(slavePatch),
146  pointMap_
147  (
148  masterPatch_.meshPoints().size()
149  + slavePatch_.meshPoints().size()
150  ),
151  pointMapComplete_(false),
152  pointMergeMap_(2*slavePatch_.meshPoints().size()),
153  slavePointPointHits_(slavePointPointHits),
154  slavePointEdgeHits_(slavePointEdgeHits),
155  slavePointFaceHits_(slavePointFaceHits),
156  enrichedFacesPtr_(nullptr),
157  meshPointsPtr_(nullptr),
158  localFacesPtr_(nullptr),
159  localPointsPtr_(nullptr),
160  pointPointsPtr_(nullptr),
161  masterPointFacesPtr_(nullptr),
162  cutFacesPtr_(nullptr),
163  cutFaceMasterPtr_(nullptr),
164  cutFaceSlavePtr_(nullptr)
165 {}
166 
167 
168 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
169 
171 {
172  clearOut();
173 }
174 
175 
176 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
177 
179 {
180  if (!meshPointsPtr_)
181  {
182  calcMeshPoints();
183  }
184 
185  return *meshPointsPtr_;
186 }
187 
188 
190 {
191  if (!localFacesPtr_)
192  {
193  calcLocalFaces();
194  }
195 
196  return *localFacesPtr_;
197 }
198 
199 
201 {
202  if (!localPointsPtr_)
203  {
204  calcLocalPoints();
205  }
206 
207  return *localPointsPtr_;
208 }
209 
210 
212 {
213  if (!pointPointsPtr_)
214  {
215  calcPointPoints();
216  }
217 
218  return *pointPointsPtr_;
219 }
220 
221 
223 {
224  const faceList& faces = enrichedFaces();
225 
226  bool error = false;
227 
228  forAll(faces, facei)
229  {
230  const face& curFace = faces[facei];
231 
232  forAll(curFace, pointi)
233  {
234  if (!pointMap().found(curFace[pointi]))
235  {
237  << "Point " << pointi << " of face " << facei
238  << " global point index: " << curFace[pointi]
239  << " not supported in point map. This is not allowed."
240  << endl;
241 
242  error = true;
243  }
244  }
245  }
246 
247  return error;
248 }
249 
250 
251 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
252 {
253  OFstream str(fName);
254 
255  const pointField& lp = localPoints();
256 
257  forAll(lp, pointi)
258  {
259  meshTools::writeOBJ(str, lp[pointi]);
260  }
261 
262  const faceList& faces = localFaces();
263 
264  forAll(faces, facei)
265  {
266  const face& f = faces[facei];
267 
268  str << 'f';
269  forAll(f, fp)
270  {
271  str << ' ' << f[fp]+1;
272  }
273  str << nl;
274  }
275 }
276 
277 
278 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
279 
280 
281 // * * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * //
282 
283 
284 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
285 
286 
287 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A class for handling file names.
Definition: fileName.H:79
void writeOBJ(const fileName &) const
Debugging: dump graphical representation to obj format file.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
enrichedPatch(const primitiveFacePatch &masterPatch, const primitiveFacePatch &slavePatch, const labelList &slavePointPointHits, const labelList &slavePointEdgeHits, const List< objectHit > &slavePointFaceHits)
Construct from components.
Output to file stream.
Definition: OFstream.H:82
List< face > faceList
Definition: faceListFwd.H:43
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
bool checkSupport() const
Check if the patch is fully supported.
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66
~enrichedPatch()
Destructor.
A list of faces which address into the list of points.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
void sort(UList< T > &)
Definition: UList.C:115
List< label > labelList
A List of labels.
Definition: labelList.H:56
errorManip< error > abort(error &err)
Definition: errorManip.H:131
const labelListList & pointPoints() const
Return point-point addressing.
static const char nl
Definition: Ostream.H:260
defineTypeNameAndDebug(combustionModel, 0)
const pointField & localPoints() const
Return local points.
Template functions to aid in the implementation of demand driven data.
#define WarningInFunction
Report a warning using Foam::Warning.
const faceList & localFaces() const
Return local faces.
const labelList & meshPoints() const
Return mesh points.
void deleteDemandDrivenData(DataPtr &dataPtr)
bool found
Namespace for OpenFOAM.