repatcher.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-2024 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 "repatcher.H"
34 #include "polyTopoChange.H"
35 
36 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
37 
38 Foam::polyTopoChange& Foam::repatcher::meshMod()
39 {
40  if (meshModPtr_.empty())
41  {
42  meshModPtr_.reset(new polyTopoChange(mesh_));
43  }
44  return meshModPtr_();
45 }
46 
47 
48 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
49 
51 :
52  mesh_(mesh),
53  meshModPtr_(nullptr)
54 {}
55 
56 
57 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
58 
60 {}
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
66 (
68 )
69 {
70  if (meshModPtr_.valid())
71  {
73  << "Cannot change patches after faces have changed"
74  << exit(FatalError);
75  }
76 
77  mesh_.removeBoundary();
78  mesh_.addPatches(patches);
79 }
80 
81 
83 (
84  const label faceID,
85  const label patchID
86 )
87 {
88  if (polyTopoChange::debug)
89  {
90  // Check that the request is possible
91  if
92  (
93  faceID >= mesh_.faces().size()
94  || patchID >= mesh_.boundaryMesh().size()
95  || mesh_.isInternalFace(faceID)
96  )
97  {
99  << " patchID: " << patchID << ". "
100  << "Labels out of range or internal face."
101  << abort(FatalError);
102  }
103  }
104 
105  meshMod().modifyFace
106  (
107  mesh_.faces()[faceID], // face
108  faceID, // face ID
109  mesh_.faceOwner()[faceID], // owner
110  -1, // neighbour
111  false, // flip flux
112  patchID // patch ID
113  );
114 }
115 
116 
118 (
119  const label faceID,
120  const label fp
121 )
122 {
123  if (polyTopoChange::debug)
124  {
125  // Check that the request is possible
126  if (faceID > mesh_.faces().size())
127  {
129  << "out of range."
130  << abort(FatalError);
131  }
132  }
133 
134  const face& f = mesh_.faces()[faceID];
135 
136  if ((fp < 0) || (fp >= f.size()))
137  {
139  << "Error in definition. Face point: " << fp
140  << "indexes out of face " << f
141  << abort(FatalError);
142  }
143 
144  label patchID = mesh_.boundaryMesh().whichPatch(faceID);
145 
146  if (fp == 0)
147  {
148  // Do dummy modify to keep patch ordering.
149  meshMod().modifyFace
150  (
151  f, // face
152  faceID, // face ID
153  mesh_.faceOwner()[faceID], // owner
154  -1, // neighbour
155  false, // flip flux
156  patchID // patch ID
157  );
158  }
159  else
160  {
161  // Construct new face with fp as first point.
162 
163  face newFace(f.size());
164 
165  label fVert = fp;
166 
167  forAll(f, i)
168  {
169  newFace[i] = f[fVert++];
170 
171  if (fVert == f.size())
172  {
173  fVert = 0;
174  }
175  }
176 
177  meshMod().modifyFace
178  (
179  newFace, // face
180  faceID, // face ID
181  mesh_.faceOwner()[faceID], // owner
182  -1, // neighbour
183  false, // flip flux
184  patchID // patch ID
185  );
186  }
187 }
188 
189 
191 {
192  // Apply patch changes to mesh
193  meshMod().changeMesh(mesh_);
194 
195  // Clear topo change for the next operation
196  meshModPtr_.clear();
197 }
198 
199 
200 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
void size(const label)
Override size to be inconsistent with allocated storage.
Definition: ListI.H:164
A face is a list of labels corresponding to mesh vertices.
Definition: face.H:76
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:80
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.
Definition: repatcher.C:118
void changePatchID(const label faceID, const label patchID)
Change patch ID for a boundary face. Note: patchID should be in new.
Definition: repatcher.C:83
void changePatches(const List< polyPatch * > &patches)
Change patches.
Definition: repatcher.C:66
virtual ~repatcher()
Destructor.
Definition: repatcher.C:59
void repatch()
Re-patch the mesh.
Definition: repatcher.C:190
repatcher(polyMesh &mesh)
Construct for given mesh.
Definition: repatcher.C:50
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const fvPatchList & patches
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
error FatalError
labelList f(nPoints)