repatchPolyTopoChanger.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Description
25  A mesh which allows changes in the patch distribution of the
26  faces. The change in patching is set using changePatchID. For a
27  boundary face, a new patch ID is given. If the face is internal,
28  it will be added to the first patch and its opposite to the second
29  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_.empty())
43  {
44  meshModPtr_.reset(new polyTopoChange(mesh_));
45  }
46  return meshModPtr_();
47 }
48 
49 
50 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
51 
53 :
54  mesh_(mesh),
55  meshModPtr_(nullptr)
56 {}
57 
58 
59 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
60 
62 (
63  const List<polyPatch*>& patches
64 )
65 {
66  if (meshModPtr_.valid())
67  {
69  << "Cannot change patches after having changed faces. " << nl
70  << "Please call changePatches first."
71  << exit(FatalError);
72  }
73  meshModPtr_.clear();
74  mesh_.removeBoundary();
75  mesh_.addPatches(patches);
76 }
77 
78 
80 (
81  const label faceID,
82  const label patchID
83 )
84 {
85  if (polyTopoChanger::debug)
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 {
138  if (polyTopoChanger::debug)
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 {
173  if (polyTopoChanger::debug)
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_.clear();
271 }
272 
273 
274 // ************************************************************************* //
const polyBoundaryMesh & boundaryMesh() const
Return boundary mesh.
Definition: polyMesh.H:434
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
Class describing modification of a face.
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:75
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
virtual const labelList & faceNeighbour() const
Return face neighbour.
Definition: polyMesh.C:1175
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
const boolList & flipMap() const
Return face flip map.
Definition: faceZone.H:248
void setFaceZone(const label faceID, const label zoneID, const bool zoneFlip)
Set zone ID for a face.
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:306
void changeAnchorPoint(const label faceID, const label fp)
Change anchor point (zero&#39;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.
void repatch()
Re-patch the mesh.
dynamicFvMesh & mesh
virtual const labelList & faceOwner() const
Return face owner.
Definition: polyMesh.C:1169
virtual const faceList & faces() const
Return raw faces.
Definition: polyMesh.C:1156
void changePatches(const List< polyPatch *> &patches)
Change patches.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void addPatches(const List< polyPatch *> &, const bool validBoundary=true)
Add boundary patches.
Definition: polyMesh.C:909
bool isInternalFace(const label faceIndex) const
Return true if given face label is internal to the mesh.
void removeBoundary()
Remove boundary patches.
Definition: polyMeshClear.C:36
static const char nl
Definition: Ostream.H:260
labelList f(nPoints)
label size() const
Return the number of elements in the UPtrList.
Definition: UPtrListI.H:29
label whichZone(const label objectIndex) const
Given a global object index, return the zone it is in.
Definition: MeshZones.C:221
const meshFaceZones & faceZones() const
Return face zones.
Definition: polyMesh.H:476
Direct mesh changes based on v1.3 polyTopoChange syntax.
repatchPolyTopoChanger(polyMesh &mesh)
Construct for given mesh.
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:64
autoPtr< mapPolyMesh > changeMesh(polyMesh &mesh, const bool inflate, const bool syncParallel=true, const bool orderCells=false, const bool orderPoints=false)
Inplace changes mesh without change of patches.
label whichPatch(const label faceIndex) const
Return patch index for a given face label.
label setAction(const topoAction &action)
For compatibility with polyTopoChange: set topological action.