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-2020 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 "OFstream.H"
31 #include "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  {
48  << "Mesh points already calculated."
49  << abort(FatalError);
50  }
51 
52  meshPointsPtr_.reset(new labelList(pointMap().sortedToc()));
53 }
54 
55 
56 void Foam::enrichedPatch::calcLocalFaces() const
57 {
58  if (localFacesPtr_)
59  {
61  << "Local faces already calculated."
62  << abort(FatalError);
63  }
64 
65  // Invert mesh points and renumber faces using it
66  const labelList& mp = meshPoints();
67 
68  Map<label> mpLookup(2*mp.size());
69 
70  forAll(mp, mpi)
71  {
72  mpLookup.insert(mp[mpi], mpi);
73  }
74 
75  // Create local faces.
76  // Copy original faces and overwrite vertices after
77 
78  const faceList& faces = enrichedFaces();
79 
80  localFacesPtr_.reset(new faceList(faces));
81  auto& locFaces = *localFacesPtr_;
82 
83  for (face& f : locFaces)
84  {
85  for (label& pointi : f)
86  {
87  pointi = *(mpLookup.cfind(pointi));
88  }
89  }
90 }
91 
92 
93 void Foam::enrichedPatch::calcLocalPoints() const
94 {
95  if (localPointsPtr_)
96  {
98  << "Local points already calculated."
99  << abort(FatalError);
100  }
101 
102  const labelList& mp = meshPoints();
103 
104  localPointsPtr_.reset(new pointField(mp.size()));
105  auto& locPoints = *localPointsPtr_;
106 
107  forAll(locPoints, i)
108  {
109  locPoints[i] = *(pointMap().cfind(mp[i]));
110  }
111 }
112 
113 
114 void Foam::enrichedPatch::clearOut()
115 {
116  enrichedFacesPtr_.reset(nullptr);
117 
118  meshPointsPtr_.reset(nullptr);
119  localFacesPtr_.reset(nullptr);
120  localPointsPtr_.reset(nullptr);
121  pointPointsPtr_.reset(nullptr);
122  masterPointFacesPtr_.reset(nullptr);
123 
124  clearCutFaces();
125 }
126 
127 
128 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
129 
130 Foam::enrichedPatch::enrichedPatch
131 (
132  const primitiveFacePatch& masterPatch,
133  const primitiveFacePatch& slavePatch,
134  const labelUList& slavePointPointHits,
135  const labelUList& slavePointEdgeHits,
136  const UList<objectHit>& slavePointFaceHits
137 )
138 :
139  masterPatch_(masterPatch),
140  slavePatch_(slavePatch),
141  pointMap_
142  (
143  masterPatch_.meshPoints().size()
144  + slavePatch_.meshPoints().size()
145  ),
146  pointMapComplete_(false),
147  pointMergeMap_(2*slavePatch_.meshPoints().size()),
148  slavePointPointHits_(slavePointPointHits),
149  slavePointEdgeHits_(slavePointEdgeHits),
150  slavePointFaceHits_(slavePointFaceHits),
151  enrichedFacesPtr_(nullptr),
152  meshPointsPtr_(nullptr),
153  localFacesPtr_(nullptr),
154  localPointsPtr_(nullptr),
155  pointPointsPtr_(nullptr),
156  masterPointFacesPtr_(nullptr),
157  cutFacesPtr_(nullptr),
158  cutFaceMasterPtr_(nullptr),
159  cutFaceSlavePtr_(nullptr)
160 {}
161 
162 
163 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
164 
166 {
167  if (!meshPointsPtr_)
168  {
169  calcMeshPoints();
170  }
171 
172  return *meshPointsPtr_;
173 }
174 
175 
177 {
178  if (!localFacesPtr_)
179  {
180  calcLocalFaces();
181  }
182 
183  return *localFacesPtr_;
184 }
185 
186 
188 {
189  if (!localPointsPtr_)
190  {
191  calcLocalPoints();
192  }
193 
194  return *localPointsPtr_;
195 }
196 
197 
199 {
200  if (!pointPointsPtr_)
201  {
202  calcPointPoints();
203  }
204 
205  return *pointPointsPtr_;
206 }
207 
208 
210 {
211  const faceList& faces = enrichedFaces();
212 
213  bool error = false;
214 
215  forAll(faces, facei)
216  {
217  for (const label pointi : faces[facei])
218  {
219  if (!pointMap().found(pointi))
220  {
222  << "Point " << pointi << " of face " << facei
223  << " global point index: " << pointi
224  << " not supported in point map. This is not allowed."
225  << endl;
226 
227  error = true;
228  }
229  }
230  }
231 
232  return error;
233 }
234 
235 
236 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
237 {
238  OFstream str(fName);
239 
240  meshTools::writeOBJ(str, localPoints());
241 
242  const faceList& faces = localFaces();
243 
244  for (const face& f : faces)
245  {
246  str << 'f';
247  for (const label fp : f)
248  {
249  str << ' ' << fp+1;
250  }
251  str << nl;
252  }
253 }
254 
255 
256 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
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:165
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::meshTools::writeOBJ
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::enrichedPatch::writeOBJ
void writeOBJ(const fileName &fName) const
Debugging: dump graphical representation to obj format file.
Definition: enrichedPatch.C:236
Foam::enrichedPatch::localPoints
const pointField & localPoints() const
Return local points.
Definition: enrichedPatch.C:187
Foam::enrichedPatch::checkSupport
bool checkSupport() const
Check if the patch is fully supported.
Definition: enrichedPatch.C:209
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
OFstream.H
Foam::Field< vector >
Foam::FatalError
error FatalError
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::enrichedPatch::localFaces
const faceList & localFaces() const
Return local faces.
Definition: enrichedPatch.C:176
Foam::enrichedPatch::pointPoints
const labelListList & pointPoints() const
Return point-point addressing.
Definition: enrichedPatch.C:198
Foam::OFstream
Output to file stream, using an OSstream.
Definition: OFstream.H:53
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:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
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:72
Foam::defineTypeNameAndDebug
defineTypeNameAndDebug(combustionModel, 0)
WarningInFunction
#define WarningInFunction
Report a warning using Foam::Warning.
Definition: messageStream.H:328
Foam::error
Class to handle errors and exceptions in a simple, consistent stream-based manner.
Definition: error.H:73
enrichedPatch.H
Foam::PrimitivePatch
A list of faces which address into the list of points.
Definition: PrimitivePatch.H:79