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-------------------------------------------------------------------------------
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
33// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
34
35namespace Foam
36{
38}
39
40
41// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
42
43void 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
56void 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
93void 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
114void 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
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
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// ************************************************************************* //
bool found
Output to file stream, using an OSstream.
Definition: OFstream.H:57
A list of faces which address into the list of points.
The enriched patch contains a double set of faces from the two sides of the sliding interface before ...
Definition: enrichedPatch.H:70
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 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:77
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
A class for handling file names.
Definition: fileName.H:76
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
Definition: className.H:121
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
#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:203
const dimensionedScalar mp
Proton mass.
void writeOBJ(Ostream &os, const point &pt)
Write obj representation of a point.
Definition: meshTools.C:203
Namespace for OpenFOAM.
List< label > labelList
A List of labels.
Definition: List.H:66
vectorField pointField
pointField is a vectorField.
Definition: pointFieldFwd.H:44
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError
List< face > faceList
A List of faces.
Definition: faceListFwd.H:47
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
labelList f(nPoints)
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333