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-2024 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 #include "ListOps.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_.reset(new labelList(pointMap().sortedToc()));
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(invertToMap(mp));
70 
71 
72  // Create local faces.
73  // Copy original faces and overwrite vertices after
74 
75  const faceList& faces = enrichedFaces();
76 
77  localFacesPtr_.reset(new faceList(faces));
78  auto& locFaces = *localFacesPtr_;
79 
80  for (face& f : locFaces)
81  {
82  inplaceRenumber(mpLookup, f);
83  }
84 }
85 
86 
87 void Foam::enrichedPatch::calcLocalPoints() const
88 {
89  if (localPointsPtr_)
90  {
92  << "Local points already calculated."
93  << abort(FatalError);
94  }
95 
96  const labelList& mp = meshPoints();
97 
98  localPointsPtr_.reset(new pointField(mp.size()));
99  auto& locPoints = *localPointsPtr_;
100 
101  forAll(locPoints, i)
102  {
103  locPoints[i] = *(pointMap().cfind(mp[i]));
104  }
105 }
106 
107 
108 void Foam::enrichedPatch::clearOut()
109 {
110  enrichedFacesPtr_.reset(nullptr);
111 
112  meshPointsPtr_.reset(nullptr);
113  localFacesPtr_.reset(nullptr);
114  localPointsPtr_.reset(nullptr);
115  pointPointsPtr_.reset(nullptr);
116  masterPointFacesPtr_.reset(nullptr);
117 
118  clearCutFaces();
119 }
120 
121 
122 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123 
124 Foam::enrichedPatch::enrichedPatch
125 (
126  const primitiveFacePatch& masterPatch,
127  const primitiveFacePatch& slavePatch,
128  const labelUList& slavePointPointHits,
129  const labelUList& slavePointEdgeHits,
130  const UList<objectHit>& slavePointFaceHits
131 )
132 :
133  masterPatch_(masterPatch),
134  slavePatch_(slavePatch),
135  pointMap_
136  (
137  masterPatch_.meshPoints().size()
138  + slavePatch_.meshPoints().size()
139  ),
140  pointMapComplete_(false),
141  pointMergeMap_(2*slavePatch_.meshPoints().size()),
142  slavePointPointHits_(slavePointPointHits),
143  slavePointEdgeHits_(slavePointEdgeHits),
144  slavePointFaceHits_(slavePointFaceHits),
145  enrichedFacesPtr_(nullptr),
146  meshPointsPtr_(nullptr),
147  localFacesPtr_(nullptr),
148  localPointsPtr_(nullptr),
149  pointPointsPtr_(nullptr),
150  masterPointFacesPtr_(nullptr),
151  cutFacesPtr_(nullptr),
152  cutFaceMasterPtr_(nullptr),
153  cutFaceSlavePtr_(nullptr)
154 {}
155 
156 
157 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
158 
160 {
161  if (!meshPointsPtr_)
162  {
163  calcMeshPoints();
164  }
165 
166  return *meshPointsPtr_;
167 }
168 
169 
171 {
172  if (!localFacesPtr_)
173  {
174  calcLocalFaces();
175  }
176 
177  return *localFacesPtr_;
178 }
179 
180 
182 {
183  if (!localPointsPtr_)
184  {
185  calcLocalPoints();
186  }
187 
188  return *localPointsPtr_;
189 }
190 
191 
193 {
194  if (!pointPointsPtr_)
195  {
196  calcPointPoints();
197  }
198 
199  return *pointPointsPtr_;
200 }
201 
202 
204 {
205  const faceList& faces = enrichedFaces();
206 
207  bool error = false;
208 
209  forAll(faces, facei)
210  {
211  for (const label pointi : faces[facei])
212  {
213  if (!pointMap().found(pointi))
214  {
216  << "Point " << pointi << " of face " << facei
217  << " global point index: " << pointi
218  << " not supported in point map. This is not allowed."
219  << endl;
220 
221  error = true;
222  }
223  }
224  }
225 
226  return error;
227 }
228 
229 
230 void Foam::enrichedPatch::writeOBJ(const fileName& fName) const
231 {
232  OFstream str(fName);
233 
234  meshTools::writeOBJ(str, localPoints());
235 
236  const faceList& faces = localFaces();
237 
238  for (const face& f : faces)
239  {
240  str << 'f';
241  for (const label fp : f)
242  {
243  str << ' ' << fp+1;
244  }
245  str << nl;
246  }
247 }
248 
249 
250 // ************************************************************************* //
void writeOBJ(const fileName &fName) const
Debugging: dump graphical representation to obj format file.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:608
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:196
bool checkSupport() const
Check if the patch is fully supported.
Various functions to operate on Lists.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
List< face > faceList
List of faces.
Definition: faceListFwd.H:39
A list of faces which address into the list of points.
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:38
const Map< point > & pointMap() const
Return map of points.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
const labelListList & pointPoints() const
Return point-point addressing.
defineTypeNameAndDebug(combustionModel, 0)
const pointField & localPoints() const
Return local points.
labelList f(nPoints)
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
#define WarningInFunction
Report a warning using Foam::Warning.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to &#39;true&#39; entries.
Definition: BitOps.C:195
const faceList & localFaces() const
Return local faces.
List< label > labelList
A List of labels.
Definition: List.H:62
const labelList & meshPoints() const
Return mesh points.
Map< label > invertToMap(const labelUList &values)
Create inverse mapping, which is a lookup table into the given list.
Definition: ListOps.C:107
bool found
const dimensionedScalar mp
Proton mass.
Namespace for OpenFOAM.