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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Description
27  A mesh which allows changes in the patch distribution of the
28  faces. The change in patching is set using changePatchID. For a
29  boundary face, a new patch ID is given. If the face is internal,
30  it will be added to the first patch and its opposite to the second
31  patch (take care with face orientation!).
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #include "repatchPolyTopoChanger.H"
36 #include "polyTopoChanger.H"
37 #include "mapPolyMesh.H"
38 #include "polyModifyFace.H"
39 
40 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
41 
42 Foam::polyTopoChange& Foam::repatchPolyTopoChanger::meshMod()
43 {
44  if (meshModPtr_.empty())
45  {
46  meshModPtr_.reset(new polyTopoChange(mesh_));
47  }
48  return *meshModPtr_;
49 }
50 
51 
52 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
53 
54 Foam::repatchPolyTopoChanger::repatchPolyTopoChanger(polyMesh& mesh)
55 :
56  mesh_(mesh),
57  meshModPtr_(nullptr)
58 {}
59 
60 
61 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
62 
64 (
66 )
67 {
68  if (meshModPtr_.valid())
69  {
71  << "Cannot change patches after having changed faces. " << nl
72  << "Please call changePatches first."
73  << exit(FatalError);
74  }
75  meshModPtr_.clear();
76  mesh_.removeBoundary();
77  mesh_.addPatches(patches);
78 }
79 
80 
82 (
83  const label faceID,
84  const label patchID
85 )
86 {
88  {
89  // Check that the request is possible
90  if
91  (
92  faceID >= mesh_.faces().size()
93  || patchID >= mesh_.boundaryMesh().size()
94  || mesh_.isInternalFace(faceID)
95  )
96  {
98  << " patchID: " << patchID << ". "
99  << "Labels out of range or internal face."
100  << abort(FatalError);
101  }
102  }
103 
104  const label zoneID = mesh_.faceZones().whichZone(faceID);
105 
106  bool zoneFlip = false;
107 
108  if (zoneID >= 0)
109  {
110  const faceZone& fZone = mesh_.faceZones()[zoneID];
111 
112  zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
113  }
114 
115  meshMod().setAction
116  (
118  (
119  mesh_.faces()[faceID], // face
120  faceID, // face ID
121  mesh_.faceOwner()[faceID], // owner
122  -1, // neighbour
123  false, // flip flux
124  patchID, // patch ID
125  false, // remove from zone
126  zoneID, // zone ID
127  zoneFlip // zone flip
128  )
129  );
130 }
131 
132 
134 (
135  const label faceID,
136  const label zoneID,
137  const bool zoneFlip
138 )
139 {
141  {
142  // Check that the request is possible
143  if (faceID > mesh_.faces().size())
144  {
146  << "out of range."
147  << abort(FatalError);
148  }
149  }
150 
151  meshMod().setAction
152  (
154  (
155  mesh_.faces()[faceID], // face
156  faceID, // face ID
157  mesh_.faceOwner()[faceID], // owner
158  mesh_.faceNeighbour()[faceID], // neighbour
159  false, // flip flux
160  mesh_.boundaryMesh().whichPatch(faceID), // patch ID
161  true, // remove from zone
162  zoneID, // zone ID
163  zoneFlip // zone flip
164  )
165  );
166 }
167 
168 
170 (
171  const label faceID,
172  const label fp
173 )
174 {
176  {
177  // Check that the request is possible
178  if (faceID > mesh_.faces().size())
179  {
181  << "out of range."
182  << abort(FatalError);
183  }
184  }
185 
186  const face& f = mesh_.faces()[faceID];
187 
188  if ((fp < 0) || (fp >= f.size()))
189  {
191  << "Error in definition. Face point: " << fp
192  << "indexes out of face " << f
193  << abort(FatalError);
194  }
195 
196  label patchID = mesh_.boundaryMesh().whichPatch(faceID);
197 
198  const label zoneID = mesh_.faceZones().whichZone(faceID);
199 
200  bool zoneFlip = false;
201 
202  if (zoneID >= 0)
203  {
204  const faceZone& fZone = mesh_.faceZones()[zoneID];
205 
206  zoneFlip = fZone.flipMap()[fZone.whichFace(faceID)];
207  }
208 
209  if (fp == 0)
210  {
211  // Do dummy modify to keep patch ordering.
212  meshMod().setAction
213  (
215  (
216  f, // face
217  faceID, // face ID
218  mesh_.faceOwner()[faceID], // owner
219  -1, // neighbour
220  false, // flip flux
221  patchID, // patch ID
222  false, // remove from zone
223  zoneID, // zone ID
224  zoneFlip // zone flip
225  )
226  );
227  }
228  else
229  {
230  // Construct new face with fp as first point.
231 
232  face newFace(f.size());
233 
234  label fVert = fp;
235 
236  forAll(f, i)
237  {
238  newFace[i] = f[fVert++];
239 
240  if (fVert == f.size())
241  {
242  fVert = 0;
243  }
244  }
245 
246 
247  meshMod().setAction
248  (
250  (
251  newFace, // face
252  faceID, // face ID
253  mesh_.faceOwner()[faceID], // owner
254  -1, // neighbour
255  false, // flip flux
256  patchID, // patch ID
257  false, // remove from zone
258  zoneID, // zone ID
259  zoneFlip // zone flip
260  )
261  );
262  }
263 }
264 
265 
267 {
268  // Change mesh, no inflation
269  meshMod().changeMesh(mesh_, false);
270 
271  // Clear topo change for the next operation
272  meshModPtr_.clear();
273 }
274 
275 
276 // ************************************************************************* //
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:170
Foam::repatchPolyTopoChanger::setFaceZone
void setFaceZone(const label faceID, const label zoneID, const bool zoneFlip)
Set zone ID for a face.
Definition: repatchPolyTopoChanger.C:134
mapPolyMesh.H
polyTopoChanger.H
Foam::polyTopoChange
Direct mesh changes based on v1.3 polyTopoChange syntax.
Definition: polyTopoChange.H:100
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:290
Foam::label
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:62
Foam::faceZone
A subset of mesh faces organised as a primitive patch.
Definition: faceZone.H:65
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:64
Foam::faceZone::whichFace
label whichFace(const label globalCellID) const
Helper function to re-direct to zone::localID(...)
Definition: faceZone.C:388
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
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:355
Foam::nl
constexpr char nl
Definition: Ostream.H:372
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: HashTable.H:102
patches
const polyBoundaryMesh & patches
Definition: convertProcessorPatches.H:65
Foam::face
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:74
Foam::repatchPolyTopoChanger::repatch
void repatch()
Re-patch the mesh.
Definition: repatchPolyTopoChanger.C:266
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:82
repatchPolyTopoChanger.H
Foam::faceZone::flipMap
const boolList & flipMap() const
Return face flip map.
Definition: faceZone.H:271