Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
11License
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
36namespace Foam
37{
39}
40
41
42// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
43
44void 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
57void 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
87void 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
108void 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);
118 clearCutFaces();
119}
120
121
122// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
123
124Foam::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 }
224 }
225
226 return error;
227}
228
229
230void 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// ************************************************************************* //
Various functions to operate on Lists.
bool found
A HashTable to objects of type <T> with a label key.
Definition Map.H:54
Output to file stream as an OSstream, normally using std::ofstream for the actual output.
Definition OFstream.H:75
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition UList.H:89
The enriched patch contains a double set of faces from the two sides of the sliding interface before ...
const faceList & localFaces() const
Return local faces.
const pointField & localPoints() const
Return local points.
void writeOBJ(const fileName &fName) const
Debugging: dump graphical representation to obj format file.
const faceList & enrichedFaces() const
Return enriched faces.
const labelList & meshPoints() const
Return mesh points.
const labelListList & pointPoints() const
Return point-point addressing.
const Map< point > & pointMap() const
Return map of points.
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:74
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
A class for handling file names.
Definition fileName.H:75
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition className.H:142
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
#define WarningInFunction
Report a warning using Foam::Warning.
List< label > sortedToc(const UList< bool > &bools)
Return the (sorted) values corresponding to 'true' entries.
Definition BitOps.C:200
const dimensionedScalar mp
Proton mass.
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition meshTools.C:196
Namespace for OpenFOAM.
void inplaceRenumber(const labelUList &oldToNew, IntListType &input)
Inplace renumber the values within a list.
List< labelList > labelListList
List of labelList.
Definition labelList.H:38
Map< label > invertToMap(const labelUList &values)
Create inverse mapping, which is a lookup table into the given list.
Definition ListOps.C:105
List< label > labelList
A List of labels.
Definition List.H:62
List< face > faceList
List of faces.
Definition faceListFwd.H:41
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
PrimitivePatch< List< face >, const pointField & > primitiveFacePatch
A PrimitivePatch with List storage for the faces, const reference for the point field.
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
vectorField pointField
pointField is a vectorField.
UList< label > labelUList
A UList of labels.
Definition UList.H:75
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition stdFoam.H:299