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 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<UpdateableMeshObject<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<UpdateableMeshObject<Mesh>>(*iter()))
164  {
165  if (meshObjects::debug)
166  {
167  Pout<< " Updating " << iter()->io_.name() << endl;
168  }
169  dynamic_cast<UpdateableMeshObject<Mesh>*>(iter())->topoChange(map);
170  }
171  else
172  {
173  Delete<Mesh>(iter()->io_);
174  }
175  }
176 }
177 
178 
179 template<class Mesh>
181 (
182  objectRegistry& obr,
183  const polyMeshMap& map
184 )
185 {
187  (
189  );
190 
191  if (meshObjects::debug)
192  {
193  Pout<< "meshObjects::mapMesh(objectRegistry&, "
194  "const polyMeshMap& map) : updating " << Mesh::typeName
195  << " meshObjects for region " << obr.name() << endl;
196  }
197 
198  forAllIter
199  (
201  meshObjects,
202  iter
203  )
204  {
205  if (isA<UpdateableMeshObject<Mesh>>(*iter()))
206  {
207  if (meshObjects::debug)
208  {
209  Pout<< " Updating " << iter()->io_.name() << endl;
210  }
211  dynamic_cast<UpdateableMeshObject<Mesh>*>(iter())->mapMesh(map);
212  }
213  else
214  {
215  Delete<Mesh>(iter()->io_);
216  }
217  }
218 }
219 
220 
221 template<class Mesh>
223 {
225  (
227  );
228 
229  if (meshObjects::debug)
230  {
231  Pout<< "meshObjects::addPatch(objectRegistry&, "
232  "const label patchi) : updating " << Mesh::typeName
233  << " meshObjects for region " << obr.name() << endl;
234  }
235 
236  forAllIter
237  (
239  meshObjects,
240  iter
241  )
242  {
243  if (isA<PatchMeshObject<Mesh>>(*iter()))
244  {
245  if (meshObjects::debug)
246  {
247  Pout<< " Adding patch to " << iter()->io_.name() << endl;
248  }
249  dynamic_cast<PatchMeshObject<Mesh>*>(iter())->addPatch(patchi);
250  }
251  else
252  {
253  Delete<Mesh>(iter()->io_);
254  }
255  }
256 }
257 
258 
259 template<class Mesh>
261 (
262  objectRegistry& obr,
263  const labelUList& newToOld,
264  const bool validBoundary
265 )
266 {
268  (
270  );
271 
272  if (meshObjects::debug)
273  {
274  Pout<< "meshObjects::addPatch(objectRegistry&, "
275  "const labelUList&, const bool) : updating " << Mesh::typeName
276  << " meshObjects for region " << obr.name() << endl;
277  }
278 
279  forAllIter
280  (
282  meshObjects,
283  iter
284  )
285  {
286  if (isA<PatchMeshObject<Mesh>>(*iter()))
287  {
288  if (meshObjects::debug)
289  {
290  Pout<< " Adding patch to " << iter()->io_.name() << endl;
291  }
292  dynamic_cast<PatchMeshObject<Mesh>*>(iter())->reorderPatches
293  (
294  newToOld,
295  validBoundary
296  );
297  }
298  else
299  {
300  Delete<Mesh>(iter()->io_);
301  }
302  }
303 }
304 
305 
306 template<class Mesh, template<class> class MeshObjectType>
308 {
310  (
311  obr.lookupClass<MeshObjectType<Mesh>>()
312  );
313 
314  if (meshObjects::debug)
315  {
316  Pout<< "meshObjects::clear(objectRegistry&) :"
317  << " clearing " << Mesh::typeName
318  << " meshObjects for region " << obr.name() << endl;
319  }
320 
321  forAllIter(typename HashTable<MeshObjectType<Mesh>*>, meshObjects, iter)
322  {
323  Delete<Mesh>(iter()->io_);
324  }
325 }
326 
327 
328 template
329 <
330  class Mesh,
331  template<class> class FromType,
332  template<class> class ToType
333 >
335 {
337  (
338  obr.lookupClass<FromType<Mesh>>()
339  );
340 
341  if (meshObjects::debug)
342  {
343  Pout<< "meshObjects::clearUpto(objectRegistry&) :"
344  << " clearing " << Mesh::typeName
345  << " meshObjects for region " << obr.name() << endl;
346  }
347 
348  forAllIter(typename HashTable<FromType<Mesh>*>, meshObjects, iter)
349  {
350  if (!isA<ToType<Mesh>>(*iter()))
351  {
352  Delete<Mesh>(iter()->io_);
353  }
354  }
355 }
356 
357 
358 // ************************************************************************* //
#define forAllIter(Container, container, iter)
Iterate across all elements in the container object of type.
Definition: UList.H:459
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:88
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:306
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:251
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:139
prefixOSstream Pout(cout, "Pout")
Definition: IOstreams.H:53
error FatalError