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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2017 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "enrichedPatch.H"
30 #include "demandDrivenData.H"
31 #include "OFstream.H"
32 #include "meshTools.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38  defineTypeNameAndDebug(enrichedPatch, 0);
39 }
40 
41 
42 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43 
44 void Foam::enrichedPatch::calcMeshPoints() const
45 {
46  if (meshPointsPtr_)
47  {
49  << "Mesh points already calculated."
50  << abort(FatalError);
51  }
52 
53  meshPointsPtr_ = new labelList(pointMap().toc());
54  labelList& mp = *meshPointsPtr_;
55 
56  sort(mp);
57 }
58 
59 
60 void Foam::enrichedPatch::calcLocalFaces() const
61 {
62  if (localFacesPtr_)
63  {
65  << "Local faces already calculated."
66  << abort(FatalError);
67  }
68 
69  // Invert mesh points and renumber faces using it
70  const labelList& mp = meshPoints();
71 
72  Map<label> mpLookup(2*mp.size());
73 
74  forAll(mp, mpI)
75  {
76  mpLookup.insert(mp[mpI], mpI);
77  }
78 
79  const faceList& faces = enrichedFaces();
80 
81  localFacesPtr_ = new faceList(faces.size());
82  faceList& lf = *localFacesPtr_;
83 
84  forAll(faces, facei)
85  {
86  const face& f = faces[facei];
87 
88  face& curlf = lf[facei];
89 
90  curlf.setSize(f.size());
91 
92  forAll(f, pointi)
93  {
94  curlf[pointi] = mpLookup.cfind(f[pointi])();
95  }
96  }
97 }
98 
99 
100 void Foam::enrichedPatch::calcLocalPoints() const
101 {
102  if (localPointsPtr_)
103  {
105  << "Local points already calculated."
106  << abort(FatalError);
107  }
108 
109  const labelList& mp = meshPoints();
110 
111  localPointsPtr_ = new pointField(mp.size());
112  pointField& lp = *localPointsPtr_;
113 
114  forAll(lp, i)
115  {
116  lp[i] = pointMap().cfind(mp[i])();
117  }
118 }
119 
120 
121 void Foam::enrichedPatch::clearOut()
122 {
123  deleteDemandDrivenData(enrichedFacesPtr_);
124 
125  deleteDemandDrivenData(meshPointsPtr_);
126  deleteDemandDrivenData(localFacesPtr_);
127  deleteDemandDrivenData(localPointsPtr_);
128  deleteDemandDrivenData(pointPointsPtr_);
129  deleteDemandDrivenData(masterPointFacesPtr_);
130 
131  clearCutFaces();
132 }
133 
134 
135 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
136 
137 Foam::enrichedPatch::enrichedPatch
138 (
139  const primitiveFacePatch& masterPatch,
140  const primitiveFacePatch& slavePatch,
141  const labelUList& slavePointPointHits,
142  const labelUList& slavePointEdgeHits,
143  const UList<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_(nullptr),
159  meshPointsPtr_(nullptr),
160  localFacesPtr_(nullptr),
161  localPointsPtr_(nullptr),
162  pointPointsPtr_(nullptr),
163  masterPointFacesPtr_(nullptr),
164  cutFacesPtr_(nullptr),
165  cutFaceMasterPtr_(nullptr),
166  cutFaceSlavePtr_(nullptr)
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  {
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  meshTools::writeOBJ(str, localPoints());
258 
259  const faceList& faces = localFaces();
260 
261  for (const face& f : faces)
262  {
263  str << 'f';
264  for (const label fp : f)
265  {
266  str << ' ' << fp+1;
267  }
268  str << nl;
269  }
270 }
271 
272 
273 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:74
Foam::pointField
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
meshTools.H
Foam::constant::atomic::mp
const dimensionedScalar mp
Proton mass.
Foam::enrichedPatch::meshPoints
const labelList & meshPoints() const
Return mesh points.
Definition: enrichedPatch.C:180
Foam::fileName
A class for handling file names.
Definition: fileName.H:69
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
demandDrivenData.H
Template functions to aid in the implementation of demand driven data.
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:337
Foam::enrichedPatch::writeOBJ
void writeOBJ(const fileName &fName) const
Debugging: dump graphical representation to obj format file.
Definition: enrichedPatch.C:253
Foam::enrichedPatch::localPoints
const pointField & localPoints() const
Return local points.
Definition: enrichedPatch.C:202
Foam::enrichedPatch::checkSupport
bool checkSupport() const
Check if the patch is fully supported.
Definition: enrichedPatch.C:224
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:290
OFstream.H
Foam::deleteDemandDrivenData
void deleteDemandDrivenData(DataPtr &dataPtr)
Definition: demandDrivenData.H:42
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
Foam::Field< vector >
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:241
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::enrichedPatch::localFaces
const faceList & localFaces() const
Return local faces.
Definition: enrichedPatch.C:191
Foam::enrichedPatch::pointPoints
const labelListList & pointPoints() const
Return point-point addressing.
Definition: enrichedPatch.C:213
Foam::enrichedPatch::~enrichedPatch
~enrichedPatch()
Destructor.
Definition: enrichedPatch.C:172
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:99
found
bool found
Definition: TABSMDCalcMethod2.H:32
Foam::enrichedPatch::pointMap
const Map< point > & pointMap() const
Return map of points.
Definition: enrichedPatchI.H:30
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
f
labelList f(nPoints)
Foam::faceList
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
Foam::List< label >
Foam::UList< label >
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::List::setSize
void setSize(const label newSize)
Alias for resize(const label)
Definition: ListI.H:146
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:294
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:64
enrichedPatch.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:90