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) 2011-2015 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 
42 {
43  if (meshPointsPtr_)
44  {
46  << "Mesh points already calculated."
47  << abort(FatalError);
48  }
49 
50  meshPointsPtr_ = new labelList(pointMap().toc());
52 
53  sort(mp);
54 }
55 
56 
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 
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 
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_(NULL),
157  meshPointsPtr_(NULL),
158  localFacesPtr_(NULL),
159  localPointsPtr_(NULL),
160  pointPointsPtr_(NULL),
161  masterPointFacesPtr_(NULL),
162  cutFacesPtr_(NULL),
163  cutFaceMasterPtr_(NULL),
164  cutFaceSlavePtr_(NULL)
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 // ************************************************************************* //
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:42
meshTools.H
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
Foam::enrichedPatch::meshPoints
const labelList & meshPoints() const
Return mesh points.
Definition: enrichedPatch.C:178
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::labelList
List< label > labelList
A List of labels.
Definition: labelList.H:56
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:406
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of point.
Definition: meshTools.C:203
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::Map< label >
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:251
Foam::enrichedPatch::localPoints
const pointField & localPoints() const
Return local points.
Definition: enrichedPatch.C:200
Foam::enrichedPatch::checkSupport
bool checkSupport() const
Check if the patch is fully supported.
Definition: enrichedPatch.C:222
Foam::enrichedPatch::meshPointsPtr_
labelList * meshPointsPtr_
Mesh points.
Definition: enrichedPatch.H:102
OFstream.H
Foam::enrichedPatch::pointMap
Map< point > & pointMap()
Return non-const access to point map to add points.
Definition: enrichedPatchPointMap.C:83
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:40
Foam::Field
Pre-declare SubField and related Field type.
Definition: Field.H:57
Foam::nl
static const char nl
Definition: Ostream.H:260
Foam::enrichedPatch::writeOBJ
void writeOBJ(const fileName &) const
Debugging: dump graphical representation to obj format file.
Definition: enrichedPatch.C:251
Foam::FatalError
error FatalError
Foam::enrichedPatch::calcLocalPoints
void calcLocalPoints() const
Calculate local points.
Definition: enrichedPatch.C:97
Foam
Namespace for OpenFOAM.
Definition: combustionModel.C:30
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::enrichedPatch::localFaces
const faceList & localFaces() const
Return local faces.
Definition: enrichedPatch.C:189
Foam::enrichedPatch::pointPoints
const labelListList & pointPoints() const
Return point-point addressing.
Definition: enrichedPatch.C:211
Foam::enrichedPatch::~enrichedPatch
~enrichedPatch()
Destructor.
Definition: enrichedPatch.C:170
Foam::OFstream
Output to file stream.
Definition: OFstream.H:81
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::List::setSize
void setSize(const label)
Reset size of List.
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::enrichedPatch::clearOut
void clearOut()
Clear out demand-driven data.
Definition: enrichedPatch.C:118
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
Definition: faceListFwd.H:43
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
Foam::sort
void sort(UList< T > &)
Definition: UList.C:107
Foam::List::size
void size(const label)
Override size to be inconsistent with allocated storage.
Foam::enrichedPatch::calcMeshPoints
void calcMeshPoints() const
Calculate mesh points.
Definition: enrichedPatch.C:41
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
Foam::enrichedPatch::enrichedPatch
enrichedPatch(const enrichedPatch &)
Disallow default bitwise copy construct.
Foam::enrichedPatch::calcLocalFaces
void calcLocalFaces() const
Calculate local faces.
Definition: enrichedPatch.C:57
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:259
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:66
enrichedPatch.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatchTemplate.H:88