Loading...
Searching...
No Matches
repatchPolyTopoChanger.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) 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
27Note
28 If the face is internal, it will be added to the first patch and
29 its opposite to the second patch (take care with face orientation!).
30
31\*---------------------------------------------------------------------------*/
32
34#include "polyTopoChanger.H"
35#include "mapPolyMesh.H"
36#include "polyModifyFace.H"
37
38// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39
40Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
41{
42 if (!meshModPtr_)
43 {
44 meshModPtr_.reset(new polyTopoChange(mesh_));
45 }
46 return *meshModPtr_;
47}
48
49
50// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51
52Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
53:
54 mesh_(mesh),
55 meshModPtr_(nullptr)
56{}
57
58
59// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60
62(
64)
65{
66 if (meshModPtr_)
67 {
69 << "Cannot change patches after having changed faces. " << nl
70 << "Please call changePatches first."
71 << exit(FatalError);
72 }
73 meshModPtr_.reset(nullptr);
74 mesh_.removeBoundary();
75 mesh_.addPatches(patches);
76}
77
78
80(
81 const List<polyPatch*>& patches
82)
83{
84 // Acquire ownership of the pointers
85 polyPatchList plist(const_cast<List<polyPatch*>&>(patches));
86
87 changePatches(plist);
88}
89
90
92(
93 const label faceID,
94 const label patchID
95)
96{
97 if (polyTopoChanger::debug)
98 {
99 // Check that the request is possible
100 if
101 (
102 faceID >= mesh_.faces().size()
103 || patchID >= mesh_.boundaryMesh().size()
104 || mesh_.isInternalFace(faceID)
105 )
106 {
108 << " patchID: " << patchID << ". "
109 << "Labels out of range or internal face."
110 << abort(FatalError);
111 }
112 }
113
114 const label zoneID = mesh_.faceZones().whichZone(faceID);
115
116 bool zoneFlip = false;
117
118 if (zoneID >= 0)
119 {
120 const faceZone& fZone = mesh_.faceZones()[zoneID];
121
122 zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
123 }
124
125 meshMod().setAction
126 (
128 (
129 mesh_.faces()[faceID], // face
130 faceID, // face ID
131 mesh_.faceOwner()[faceID], // owner
132 -1, // neighbour
133 false, // flip flux
134 patchID, // patch ID
135 false, // remove from zone
136 zoneID, // zone ID
137 zoneFlip // zone flip
138 )
139 );
140}
141
142
144(
145 const label faceID,
146 const label zoneID,
147 const bool zoneFlip
148)
149{
150 if (polyTopoChanger::debug)
151 {
152 // Check that the request is possible
153 if (faceID > mesh_.faces().size())
154 {
156 << "out of range."
157 << abort(FatalError);
158 }
159 }
160
161 meshMod().setAction
162 (
163 polyModifyFace
164 (
165 mesh_.faces()[faceID], // face
166 faceID, // face ID
167 mesh_.faceOwner()[faceID], // owner
168 mesh_.faceNeighbour()[faceID], // neighbour
169 false, // flip flux
170 mesh_.boundaryMesh().whichPatch(faceID), // patch ID
171 true, // remove from zone
172 zoneID, // zone ID
173 zoneFlip // zone flip
174 )
175 );
176}
177
178
180(
181 const label faceID,
182 const label fp
183)
184{
185 if (polyTopoChanger::debug)
186 {
187 // Check that the request is possible
188 if (faceID > mesh_.faces().size())
189 {
191 << "out of range."
192 << abort(FatalError);
193 }
194 }
195
196 const face& f = mesh_.faces()[faceID];
197
198 if ((fp < 0) || (fp >= f.size()))
199 {
201 << "Error in definition. Face point: " << fp
202 << "indexes out of face " << f
203 << abort(FatalError);
204 }
205
206 label patchID = mesh_.boundaryMesh().whichPatch(faceID);
207
208 const label zoneID = mesh_.faceZones().whichZone(faceID);
209
210 bool zoneFlip = false;
211
212 if (zoneID >= 0)
213 {
214 const faceZone& fZone = mesh_.faceZones()[zoneID];
215
216 zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
217 }
218
219 if (fp == 0)
220 {
221 // Do dummy modify to keep patch ordering.
222 meshMod().setAction
223 (
225 (
226 f, // face
227 faceID, // face ID
228 mesh_.faceOwner()[faceID], // owner
229 -1, // neighbour
230 false, // flip flux
231 patchID, // patch ID
232 false, // remove from zone
233 zoneID, // zone ID
234 zoneFlip // zone flip
235 )
236 );
237 }
238 else
239 {
240 // Construct new face with fp as first point.
241
242 face newFace(f.size());
243
244 label fVert = fp;
245
246 forAll(f, i)
247 {
248 newFace[i] = f[fVert++];
249
250 if (fVert == f.size())
251 {
252 fVert = 0;
253 }
254 }
255
256
257 meshMod().setAction
258 (
260 (
261 newFace, // face
262 faceID, // face ID
263 mesh_.faceOwner()[faceID], // owner
264 -1, // neighbour
265 false, // flip flux
266 patchID, // patch ID
267 false, // remove from zone
268 zoneID, // zone ID
269 zoneFlip // zone flip
270 )
271 );
272 }
273}
274
275
277{
278 // Change mesh, no inflation
279 meshMod().changeMesh(mesh_, false);
280
281 // Clear topo change for the next operation
282 meshModPtr_.reset(nullptr);
283}
284
285
286// ************************************************************************* //
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A subset of mesh faces organised as a primitive patch.
Definition faceZone.H:63
label whichFace(const label meshFaceID) const
The local index of the given mesh face, -1 if not in the zone.
Definition faceZone.H:394
const boolList & flipMap() const noexcept
Return face flip map.
Definition faceZone.H:389
A face is a list of labels corresponding to mesh vertices.
Definition face.H:71
Mesh consisting of general polyhedral cells.
Definition polyMesh.H:79
Class describing modification of a face.
Direct mesh changes based on v1.3 polyTopoChange syntax.
void changeAnchorPoint(const label faceID, const label fp)
Change anchor point (zero'th point of face) for a boundary face.
void changePatchID(const label faceID, const label patchID)
Change patch ID for a boundary face. Note: patchID should be in new numbering.
void changePatches(polyPatchList &patches)
Change patches.
void setFaceZone(const label faceID, const label zoneID, const bool zoneFlip)
Set zone ID for a face.
const polyBoundaryMesh & patches
dynamicFvMesh & mesh
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
PtrList< polyPatch > polyPatchList
Store lists of polyPatch as a PtrList.
Definition polyPatch.H:61
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...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
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