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 -------------------------------------------------------------------------------
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 Note
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 
33 #include "repatchPolyTopoChanger.H"
34 #include "polyTopoChanger.H"
35 #include "mapPolyMesh.H"
36 #include "polyModifyFace.H"
37 
38 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
39 
40 Foam::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 
52 Foam::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 label faceID,
82  const label patchID
83 )
84 {
86  {
87  // Check that the request is possible
88  if
89  (
90  faceID >= mesh_.faces().size()
91  || patchID >= mesh_.boundaryMesh().size()
92  || mesh_.isInternalFace(faceID)
93  )
94  {
96  << " patchID: " << patchID << ". "
97  << "Labels out of range or internal face."
98  << abort(FatalError);
99  }
100  }
101 
102  const label zoneID = mesh_.faceZones().whichZone(faceID);
103 
104  bool zoneFlip = false;
105 
106  if (zoneID >= 0)
107  {
108  const faceZone& fZone = mesh_.faceZones()[zoneID];
109 
110  zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
111  }
112 
113  meshMod().setAction
114  (
116  (
117  mesh_.faces()[faceID], // face
118  faceID, // face ID
119  mesh_.faceOwner()[faceID], // owner
120  -1, // neighbour
121  false, // flip flux
122  patchID, // patch ID
123  false, // remove from zone
124  zoneID, // zone ID
125  zoneFlip // zone flip
126  )
127  );
128 }
129 
130 
132 (
133  const label faceID,
134  const label zoneID,
135  const bool zoneFlip
136 )
137 {
139  {
140  // Check that the request is possible
141  if (faceID > mesh_.faces().size())
142  {
144  << "out of range."
145  << abort(FatalError);
146  }
147  }
148 
149  meshMod().setAction
150  (
152  (
153  mesh_.faces()[faceID], // face
154  faceID, // face ID
155  mesh_.faceOwner()[faceID], // owner
156  mesh_.faceNeighbour()[faceID], // neighbour
157  false, // flip flux
158  mesh_.boundaryMesh().whichPatch(faceID), // patch ID
159  true, // remove from zone
160  zoneID, // zone ID
161  zoneFlip // zone flip
162  )
163  );
164 }
165 
166 
168 (
169  const label faceID,
170  const label fp
171 )
172 {
174  {
175  // Check that the request is possible
176  if (faceID > mesh_.faces().size())
177  {
179  << "out of range."
180  << abort(FatalError);
181  }
182  }
183 
184  const face& f = mesh_.faces()[faceID];
185 
186  if ((fp < 0) || (fp >= f.size()))
187  {
189  << "Error in definition. Face point: " << fp
190  << "indexes out of face " << f
191  << abort(FatalError);
192  }
193 
194  label patchID = mesh_.boundaryMesh().whichPatch(faceID);
195 
196  const label zoneID = mesh_.faceZones().whichZone(faceID);
197 
198  bool zoneFlip = false;
199 
200  if (zoneID >= 0)
201  {
202  const faceZone& fZone = mesh_.faceZones()[zoneID];
203 
204  zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
205  }
206 
207  if (fp == 0)
208  {
209  // Do dummy modify to keep patch ordering.
210  meshMod().setAction
211  (
213  (
214  f, // face
215  faceID, // face ID
216  mesh_.faceOwner()[faceID], // owner
217  -1, // neighbour
218  false, // flip flux
219  patchID, // patch ID
220  false, // remove from zone
221  zoneID, // zone ID
222  zoneFlip // zone flip
223  )
224  );
225  }
226  else
227  {
228  // Construct new face with fp as first point.
229 
230  face newFace(f.size());
231 
232  label fVert = fp;
233 
234  forAll(f, i)
235  {
236  newFace[i] = f[fVert++];
237 
238  if (fVert == f.size())
239  {
240  fVert = 0;
241  }
242  }
243 
244 
245  meshMod().setAction
246  (
248  (
249  newFace, // face
250  faceID, // face ID
251  mesh_.faceOwner()[faceID], // owner
252  -1, // neighbour
253  false, // flip flux
254  patchID, // patch ID
255  false, // remove from zone
256  zoneID, // zone ID
257  zoneFlip // zone flip
258  )
259  );
260  }
261 }
262 
263 
265 {
266  // Change mesh, no inflation
267  meshMod().changeMesh(mesh_, false);
268 
269  // Clear topo change for the next operation
270  meshModPtr_.reset(nullptr);
271 }
272 
273 
274 // ************************************************************************* //
Foam::expressions::patchExpr::debug
int debug
Static debugging option.
Foam::repatchPolyTopoChanger::changeAnchorPoint
void changeAnchorPoint(const label faceID, const label fp)
Change anchor point (zero'th point of face) for a boundary face.
Definition: repatchPolyTopoChanger.C:168
Foam::faceZone::flipMap
const boolList & flipMap() const noexcept
Return face flip map.
Definition: faceZone.H:272
Foam::repatchPolyTopoChanger::setFaceZone
void setFaceZone(const label faceID, const label zoneID, const bool zoneFlip)
Set zone ID for a face.
Definition: repatchPolyTopoChanger.C:132
mapPolyMesh.H
polyTopoChanger.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:99
Foam::polyModifyFace
Class describing modification of a face.
Definition: polyModifyFace.H:50
Foam::polyMesh
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:77
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
patchID
label patchID
Definition: boundaryProcessorFaPatchPoints.H:5
Foam::FatalError
error FatalError
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
zoneID
const labelIOList & zoneID
Definition: interpolatedFaces.H:22
Foam::repatchPolyTopoChanger::changePatches
void changePatches(const List< polyPatch * > &patches)
Change patches.
Definition: repatchPolyTopoChanger.C:62
Foam::faceZone::whichFace
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:372
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
polyModifyFace.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
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::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:72
Foam::repatchPolyTopoChanger::repatch
void repatch()
Re-patch the mesh.
Definition: repatchPolyTopoChanger.C:264
Foam::repatchPolyTopoChanger::changePatchID
void changePatchID(const label faceID, const label patchID)
Change patch ID for a boundary face. Note: patchID should be in new.
Definition: repatchPolyTopoChanger.C:80
repatchPolyTopoChanger.H