meshObjectsTemplates.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) 2022-2023 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 \*---------------------------------------------------------------------------*/
25 
26 #include "meshObjects.H"
27 #include "MeshObjects.H"
28 
29 // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
30 
31 template<class Mesh>
32 void Foam::meshObjects::Delete(regIOobject& io)
33 {
34  if (meshObjects::debug)
35  {
36  Pout<< " Destroying " << io.name() << endl;
37  }
38 
39  if (io.ownedByRegistry())
40  {
41  io.checkOut();
42  }
43  else
44  {
46  << "Attempt to checkout and delete object " << io.name()
47  << " not owned by registry."
48  << abort(FatalError);
49  }
50 }
51 
52 
53 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
54 
55 template<class Mesh>
57 {
59  (
61  );
62 
63  if (meshObjects::debug)
64  {
65  Pout<< "meshObjects::movePoints(objectRegistry&) :"
66  << " moving " << Mesh::typeName
67  << " meshObjects for region " << obr.name() << endl;
68  }
69 
71  (
74  iter
75  )
76  {
77  if (isA<MoveableMeshObject<Mesh>>(*iter()))
78  {
79  if (meshObjects::debug)
80  {
81  Pout<< " Moving " << iter()->io_.name() << endl;
82  }
83  dynamic_cast<MoveableMeshObject<Mesh>*>(iter())->movePoints();
84  }
85  else
86  {
87  Delete<Mesh>(iter()->io_);
88  }
89  }
90 }
91 
92 
93 template<class Mesh>
95 (
96  objectRegistry& obr,
97  const polyDistributionMap& map
98 )
99 {
101  (
103  );
104 
105  if (meshObjects::debug)
106  {
107  Pout<< "meshObjects::distribute(objectRegistry&, "
108  "const polyDistributionMap& map) : updating "
109  << Mesh::typeName
110  << " meshObjects for region " << obr.name() << endl;
111  }
112 
113  forAllIter
114  (
116  meshObjects,
117  iter
118  )
119  {
120  if (isA<TopoChangeableMeshObject<Mesh>>(*iter()))
121  {
122  if (meshObjects::debug)
123  {
124  Pout<< " Distributing " << iter()->io_.name() << endl;
125  }
126  dynamic_cast<DistributeableMeshObject<Mesh>*>(iter())
127  ->distribute(map);
128  }
129  else
130  {
131  Delete<Mesh>(iter()->io_);
132  }
133  }
134 }
135 
136 
137 template<class Mesh>
139 (
140  objectRegistry& obr,
141  const polyTopoChangeMap& map
142 )
143 {
145  (
147  );
148 
149  if (meshObjects::debug)
150  {
151  Pout<< "meshObjects::topoChange(objectRegistry&, "
152  "const polyTopoChangeMap& map) : updating " << Mesh::typeName
153  << " meshObjects for region " << obr.name() << endl;
154  }
155 
156  forAllIter
157  (
159  meshObjects,
160  iter
161  )
162  {
163  if (isA<TopoChangeableMeshObject<Mesh>>(*iter()))
164  {
165  if (meshObjects::debug)
166  {
167  Pout<< " Updating " << iter()->io_.name() << endl;
168  }
169  dynamic_cast<TopoChangeableMeshObject<Mesh>*>(iter())
170  ->topoChange(map);
171  }
172  else
173  {
174  Delete<Mesh>(iter()->io_);
175  }
176  }
177 }
178 
179 
180 template<class Mesh>
182 (
183  objectRegistry& obr,
184  const polyMeshMap& map
185 )
186 {
188  (
190  );
191 
192  if (meshObjects::debug)
193  {
194  Pout<< "meshObjects::mapMesh(objectRegistry&, "
195  "const polyMeshMap& map) : updating " << Mesh::typeName
196  << " meshObjects for region " << obr.name() << endl;
197  }
198 
199  forAllIter
200  (
202  meshObjects,
203  iter
204  )
205  {
206  if (isA<TopoChangeableMeshObject<Mesh>>(*iter()))
207  {
208  if (meshObjects::debug)
209  {
210  Pout<< " Updating " << iter()->io_.name() << endl;
211  }
212  dynamic_cast<TopoChangeableMeshObject<Mesh>*>(iter())->mapMesh(map);
213  }
214  else
215  {
216  Delete<Mesh>(iter()->io_);
217  }
218  }
219 }
220 
221 
222 template<class Mesh>
224 {
226  (
228  );
229 
230  if (meshObjects::debug)
231  {
232  Pout<< "meshObjects::addPatch(objectRegistry&, "
233  "const label patchi) : updating " << Mesh::typeName
234  << " meshObjects for region " << obr.name() << endl;
235  }
236 
237  forAllIter
238  (
240  meshObjects,
241  iter
242  )
243  {
244  if (isA<RepatchableMeshObject<Mesh>>(*iter()))
245  {
246  if (meshObjects::debug)
247  {
248  Pout<< " Adding patch to " << iter()->io_.name() << endl;
249  }
250  dynamic_cast<RepatchableMeshObject<Mesh>*>(iter())
251  ->addPatch(patchi);
252  }
253  else
254  {
255  Delete<Mesh>(iter()->io_);
256  }
257  }
258 }
259 
260 
261 template<class Mesh>
263 (
264  objectRegistry& obr,
265  const labelUList& newToOld,
266  const bool validBoundary
267 )
268 {
270  (
272  );
273 
274  if (meshObjects::debug)
275  {
276  Pout<< "meshObjects::addPatch(objectRegistry&, "
277  "const labelUList&, const bool) : updating " << Mesh::typeName
278  << " meshObjects for region " << obr.name() << endl;
279  }
280 
281  forAllIter
282  (
284  meshObjects,
285  iter
286  )
287  {
288  if (isA<RepatchableMeshObject<Mesh>>(*iter()))
289  {
290  if (meshObjects::debug)
291  {
292  Pout<< " Adding patch to " << iter()->io_.name() << endl;
293  }
294  dynamic_cast<RepatchableMeshObject<Mesh>*>(iter())->reorderPatches
295  (
296  newToOld,
297  validBoundary
298  );
299  }
300  else
301  {
302  Delete<Mesh>(iter()->io_);
303  }
304  }
305 }
306 
307 
308 template<class Mesh, template<class> class MeshObjectType>
310 {
312  (
313  obr.lookupClass<MeshObjectType<Mesh>>()
314  );
315 
316  if (meshObjects::debug)
317  {
318  Pout<< "meshObjects::clear(objectRegistry&) :"
319  << " clearing " << Mesh::typeName
320  << " meshObjects for region " << obr.name() << endl;
321  }
322 
323  forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
324  {
325  Delete<Mesh>(iter()->io_);
326  }
327 }
328 
329 
330 template
331 <
332  class Mesh,
333  template<class> class FromType,
334  template<class> class ToType
335 >
337 {
339  (
340  obr.lookupClass<FromType<Mesh>>()
341  );
342 
343  if (meshObjects::debug)
344  {
345  Pout<< "meshObjects::clearUpto(objectRegistry&) :"
346  << " clearing " << Mesh::typeName
347  << " meshObjects for region " << obr.name() << endl;
348  }
349 
350  forAllIter(typename HashTable<FromType<Mesh>*>, meshObjects, iter)
351  {
352  if (!isA<ToType<Mesh>>(*iter()))
353  {
354  Delete<Mesh>(iter()->io_);
355  }
356  }
357 }
358 
359 
360 // ************************************************************************* //
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
MeshObject types:
Definition: MeshObjects.H:67
An STL-conforming hash table.
Definition: HashTable.H:127
const word & name() const
Return name.
Definition: IOobject.H:310
virtual const fileName & name() const
Return the name of the stream.
Definition: OSstream.H:85
Templated abstract base-class for optional mesh objects used to automate their allocation to the mesh...
Definition: meshObjects.H:95
static void clearUpto(objectRegistry &)
Clear all meshObjects derived from FromType up to (but not including)
static void movePoints(objectRegistry &)
static void mapMesh(objectRegistry &, const polyMeshMap &)
static void clear(objectRegistry &)
static void distribute(objectRegistry &, const polyDistributionMap &)
static void addPatch(objectRegistry &, const label patchi)
static void topoChange(objectRegistry &, const polyTopoChangeMap &)
static void reorderPatches(objectRegistry &, const labelUList &newToOld, const bool validBoundary)
Registry of regIOobjects.
HashTable< const Type * > lookupClass(const bool strict=false) const
Lookup and return all objects of the given Type.
Class containing mesh-to-mesh mapping information after a mesh distribution where we send parts of me...
Class containing mesh-to-mesh mapping information.
Definition: polyMeshMap.H:51
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
label patchi
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:257
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool isA(const Type &t)
Check if a dynamic_cast to typeid is possible.
Definition: typeInfo.H:166
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError