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-2026 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 (
225  objectRegistry& obr,
226  Mesh& otherMesh
227 )
228 {
230  (
232  );
233 
234  if (meshObjects::debug)
235  {
236  Pout<< "meshObjects::swap(objectRegistry&, "
237  "const Mesh& otherMesh) : swapping " << Mesh::typeName
238  << " meshObjects for region " << obr.name() << endl;
239  }
240 
241  forAllIter
242  (
244  meshObjects,
245  iter
246  )
247  {
248  if (isA<TopoChangeableMeshObject<Mesh>>(*iter()))
249  {
250  if (meshObjects::debug)
251  {
252  Pout<< " Swapping " << iter()->io_.name() << endl;
253  }
254  dynamic_cast<TopoChangeableMeshObject<Mesh>*>(iter())
255  ->swap(otherMesh);
256  }
257  else
258  {
259  Delete<Mesh>(iter()->io_);
260  }
261  }
262 }
263 
264 
265 template<class Mesh>
267 {
269  (
271  );
272 
273  if (meshObjects::debug)
274  {
275  Pout<< "meshObjects::addPatch(objectRegistry&, "
276  "const label patchi) : updating " << Mesh::typeName
277  << " meshObjects for region " << obr.name() << endl;
278  }
279 
280  forAllIter
281  (
283  meshObjects,
284  iter
285  )
286  {
287  if (isA<RepatchableMeshObject<Mesh>>(*iter()))
288  {
289  if (meshObjects::debug)
290  {
291  Pout<< " Adding patch to " << iter()->io_.name() << endl;
292  }
293  dynamic_cast<RepatchableMeshObject<Mesh>*>(iter())
294  ->addPatch(patchi);
295  }
296  else
297  {
298  Delete<Mesh>(iter()->io_);
299  }
300  }
301 }
302 
303 
304 template<class Mesh>
306 (
307  objectRegistry& obr,
308  const labelUList& newToOld,
309  const bool validBoundary
310 )
311 {
313  (
315  );
316 
317  if (meshObjects::debug)
318  {
319  Pout<< "meshObjects::addPatch(objectRegistry&, "
320  "const labelUList&, const bool) : updating " << Mesh::typeName
321  << " meshObjects for region " << obr.name() << endl;
322  }
323 
324  forAllIter
325  (
327  meshObjects,
328  iter
329  )
330  {
331  if (isA<RepatchableMeshObject<Mesh>>(*iter()))
332  {
333  if (meshObjects::debug)
334  {
335  Pout<< " Adding patch to " << iter()->io_.name() << endl;
336  }
337  dynamic_cast<RepatchableMeshObject<Mesh>*>(iter())->reorderPatches
338  (
339  newToOld,
340  validBoundary
341  );
342  }
343  else
344  {
345  Delete<Mesh>(iter()->io_);
346  }
347  }
348 }
349 
350 
351 template<class Mesh>
353 {
355  (
357  );
358 
359  if (meshObjects::debug)
360  {
361  Pout<< "meshObjects::reset(objectRegistry&) :"
362  << " resetting " << Mesh::typeName
363  << " meshObjects for region " << obr.name() << endl;
364  }
365 
366  forAllIter
367  (
369  meshObjects,
370  iter
371  )
372  {
373  if (isA<PermanentMeshObject<Mesh>>(*iter()))
374  {
375  if (meshObjects::debug)
376  {
377  Pout<< " Resetting " << iter()->io_.name() << endl;
378  }
379  dynamic_cast<PermanentMeshObject<Mesh>*>(iter())->reset();
380  }
381  else
382  {
383  Delete<Mesh>(iter()->io_);
384  }
385  }
386 }
387 
388 
389 
390 template<class Mesh, template<class> class MeshObjectType>
392 {
394  (
395  obr.lookupClass<MeshObjectType<Mesh>>()
396  );
397 
398  if (meshObjects::debug)
399  {
400  Pout<< "meshObjects::clear(objectRegistry&) :"
401  << " clearing " << Mesh::typeName
402  << " meshObjects for region " << obr.name() << endl;
403  }
404 
405  forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
406  {
407  if (isA<PermanentMeshObject<Mesh>>(*iter()))
408  {
409  if (meshObjects::debug)
410  {
411  Pout<< " Clearing " << iter()->io_.name() << endl;
412  }
413  dynamic_cast<PermanentMeshObject<Mesh>*>(iter())->clear();
414  }
415  else
416  {
417  Delete<Mesh>(iter()->io_);
418  }
419  }
420 }
421 
422 
423 template
424 <
425  class Mesh,
426  template<class> class FromType,
427  template<class> class ToType
428 >
430 {
432  (
433  obr.lookupClass<FromType<Mesh>>()
434  );
435 
436  if (meshObjects::debug)
437  {
438  Pout<< "meshObjects::clearUpto(objectRegistry&) :"
439  << " clearing " << Mesh::typeName
440  << " meshObjects for region " << obr.name() << endl;
441  }
442 
443  forAllIter(typename HashTable<FromType<Mesh>*>, meshObjects, iter)
444  {
445  if (!isA<ToType<Mesh>>(*iter()))
446  {
447  Delete<Mesh>(iter()->io_);
448  }
449  }
450 }
451 
452 
453 template<class Mesh, template<class> class MeshObjectType>
455 {
457  (
458  obr.lookupClass<MeshObjectType<Mesh>>()
459  );
460 
461  if (meshObjects::debug)
462  {
463  Pout<< "meshObjects::clear(objectRegistry&) :"
464  << " clearing " << Mesh::typeName
465  << " meshObjects for region " << obr.name() << endl;
466  }
467 
468  forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
469  {
470  Delete<Mesh>(iter()->io_);
471  }
472 }
473 
474 
475 // ************************************************************************* //
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:474
MeshObject types:
Definition: MeshObjects.H:70
An STL-conforming hash table.
Definition: HashTable.H:127
const word & name() const
Return name.
Definition: IOobject.H:307
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 reset(objectRegistry &)
static void clearAll(objectRegistry &)
Clear all meshObjects of type MeshObjectType.
static void clear(objectRegistry &)
Clear all but permanent meshObjects of type MeshObjectType.
static void distribute(objectRegistry &, const polyDistributionMap &)
static void addPatch(objectRegistry &, const label patchi)
static void swap(objectRegistry &, Mesh &otherMesh)
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
tUEqn clear()
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:288
String typeName(const std::type_info &info)
Return the un-mangled name given the standard type info.
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:178
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError