fvMeshStitcher.H
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) 2021-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 Class
25  Foam::fvMeshStitcher
26 
27 Description
28  Mesh manipulator that uses the intersection provided by the cyclic
29  non-conformal poly patches to create non-conformal finite volume
30  interfaces.
31 
32 SourceFiles
33  fvMeshStitcher.C
34 
35 \*---------------------------------------------------------------------------*/
36 
37 #ifndef fvMeshStitcher_H
38 #define fvMeshStitcher_H
39 
40 #include "fvMesh.H"
41 #include "HashPtrTable.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 class nonConformalCyclicFvPatch;
50 class nonConformalMappedWallFvPatch;
51 
52 /*---------------------------------------------------------------------------*\
53  Class fvMeshStitcher Declaration
54 \*---------------------------------------------------------------------------*/
55 
56 class fvMeshStitcher
57 {
58 protected:
59 
60  // Protected Typedefs
61 
62  //- Alias for surface boundary fields to reduce verbosity of method
63  // definitions below
64  template<class Type>
65  using SurfaceFieldBoundary =
67 
68  //- Alias the patchToPatch intersection part struct
70 
71  //- Alias the patchToPatch intersection couple struct
73 
74 
75 private:
76 
77  // Private Data
78 
79  //- Non-const fvMesh reference to allow update
80  fvMesh& mesh_;
81 
82  //- Flag to indicate whether this region is ready to be stitched
83  bool ready_;
84 
85  //- Cache of loaded region poly face IO objects
86  HashPtrTable<IOobject> regionPolyFacesBfIOs_;
87 
88  //- Cache of loaded region poly face boundary fields
89  HashPtrTable<SurfaceFieldBoundary<label>> regionPolyFacesBfs_;
90 
91 
92  // Private Member Functions
93 
94  // Regions
95 
96  //- Construct a table of connected region names. Recurses to
97  // find neighbours-of-neighbours and so on. Includes this region.
98  static void regionNames(const fvMesh& mesh, wordHashSet& names);
99 
100  //- Get a list of the connected region names
101  wordList regionNames() const;
102 
103  //- Get a list of the connected region meshes
104  UPtrList<const fvMesh> regionMeshes() const;
105 
106  //- Get a list of the connected region meshes
107  UPtrList<fvMesh> regionMeshes();
108 
109 
110  // Topology access
111 
112  //- Get the IO for the poly faces boundary field for a given mesh
113  static IOobject polyFacesBfIO(const fvMesh& mesh);
114 
115  //- Load the poly faces boundary field for this mesh, and also make
116  // sure that all neighbouring regions' poly faces boundary fields
117  // are available either by lookup or in the region cache
118  bool loadPolyFacesBf
119  (
120  IOobject& polyFacesBfIO,
121  SurfaceFieldBoundary<label>& polyFacesBf
122  );
123 
124  //- Access the poly faces boundary field for a region
125  const SurfaceFieldBoundary<label>& getPolyFacesBf
126  (
127  const word& regionName
128  ) const;
129 
130  //- Get fields of neighbouring original face properties
131  void getOrigNbrBfs
132  (
133  const SurfaceFieldBoundary<label>& polyFacesBf,
134  const SurfaceFieldBoundary<vector>& SfBf,
135  const SurfaceFieldBoundary<vector>& CfBf,
136  tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
137  tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
138  tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf
139  ) const;
140 
141 
142  // Intersection
143 
144  //- Unpack the patchToPatch addressing into lists of indices (fixed
145  // lists of 3 labels; owner face, neighbour face, couple index).
146  // These will be used to create the non-conformal faces, so sort
147  // them to make sure the non-conformal interfaces are ordered.
148  static List<List<FixedList<label, 3>>> procFacesToIndices
149  (
150  const List<List<remote>>& faceOtherProcFaces,
151  const bool owner
152  );
153 
154  //- If addressing has been provided, then modify the indices to
155  // match. When a coupling has to be added, the couple index is set
156  // to -1. This indicates that there is no geometry in the
157  // patchToPatch engine for this coupling, and for a small
158  // stabilisation value to be used instead.
159  static void matchIndices
160  (
161  const SurfaceFieldBoundary<label>& polyFacesBf,
162  const SurfaceFieldBoundary<label>& origFacesNbrBf,
163  List<List<FixedList<label, 3>>>& indices,
164  const fvPatch& ncFvp,
165  const polyPatch& origPp,
166  const labelList& patchis,
167  const labelList& patchOffsets,
168  const labelList& patchSizes,
169  const bool owner
170  );
171 
172  //- Create couplings by transferring geometry from the original to
173  // the non-conformal patches
174  static void createCouplings
175  (
176  SurfaceFieldBoundary<label>& polyFacesBf,
179  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
180  const tmp<SurfaceFieldBoundary<vector>>& tOrigCfNbrBf,
181  const List<List<FixedList<label, 3>>>& indices,
182  const List<DynamicList<couple>>& couples,
183  const polyPatch& origPp,
184  const labelList& patchis,
185  const labelList& patchOffsets,
186  const bool owner
187  );
188 
189  //- Add error geometry to the original patches and store the edge
190  // parts
191  static void createErrorAndEdgeParts
192  (
195  List<part>& origEdgeParts,
197  const polyPatch& origPp
198  );
199 
200  //- Perform intersections for the given non-conformal cyclic
201  void intersectNonConformalCyclic
202  (
203  const nonConformalCyclicFvPatch& nccFvp,
204  SurfaceFieldBoundary<label>& polyFacesBf,
207  const tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
208  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
209  const tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf,
210  List<part>& origEdgeParts
211  ) const;
212 
213  //- Perform intersections for the given non-conformal mapped
214  void intersectNonConformalMappedWall
215  (
216  const nonConformalMappedWallFvPatch& ncmwFvp,
217  SurfaceFieldBoundary<label>& polyFacesBf,
220  const tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
221  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
222  const tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf,
223  List<part>& origEdgeParts
224  ) const;
225 
226  //- Convert per-patch lists of edge parts into a single
227  // owner-orig-boundary list of edge parts that can be applied to
228  // the mesh
229  List<part> calculateOwnerOrigBoundaryEdgeParts
230  (
231  const List<List<part>>& patchEdgeParts
232  ) const;
233 
234  //- Apply a list of owner-orig-boundary edge parts to
235  // non-orig-patch faces (both internal and boundary)
236  void applyOwnerOrigBoundaryEdgeParts
237  (
238  surfaceVectorField& SfSf,
239  surfaceVectorField& CfSf,
240  const List<part>& ownerOrigBoundaryEdgeParts
241  ) const;
242 
243  //- Stabilise the faces that have had non-conformal coupled parts
244  // cut out from them
245  void stabiliseOrigPatchFaces
246  (
249  ) const;
250 
251  //- Perform intersections for all non-conformal interfaces. For
252  // patches that can be coupled, this creates the intersection
253  // geometry. For patches that cannot, this just sets small
254  // stabilisation values for the given topology (if any).
255  void intersect
256  (
257  SurfaceFieldBoundary<label>& polyFacesBf,
258  surfaceVectorField& SfSf,
259  surfaceVectorField& CfSf,
260  const boolList& patchCoupleds,
261  const bool matchTopology
262  ) const;
263 
264 
265  // Motion
266 
267  //- Return whether or not this stitcher supports a changing mesh
268  virtual bool changing() const = 0;
269 
270  //- Correct the mesh fluxes following a conform operation
271  virtual void conformCorrectMeshPhi(surfaceScalarField& phi) = 0;
272 
273  //- Initialise correction of the mesh fluxes
274  virtual void createNonConformalCorrectMeshPhiGeometry
275  (
276  SurfaceFieldBoundary<label>& polyFacesBf,
277  surfaceVectorField& SfSf,
278  surfaceVectorField& CfSf
279  ) = 0;
280 
281  //- Correct the mesh fluxes following an unconform operation
282  virtual void unconformCorrectMeshPhi
283  (
284  const SurfaceFieldBoundary<label>& polyFacesBf,
285  surfaceVectorField& SfSf,
286  surfaceVectorField& CfSf,
287  surfaceScalarField& phi
288  ) = 0;
289 
290 
291  // Connection
292 
293  //- Disconnect the mesh by removing faces from the
294  // nonConformalCyclics
295  bool disconnectThis
296  (
297  const bool changing,
298  const bool geometric
299  );
300 
301  //- Connect the mesh by adding faces into the nonConformalCyclics
302  bool connectThis
303  (
304  const bool changing,
305  const bool geometric,
306  const bool load
307  );
308 
309 
310  // Field Mapping
311 
312  //- Resize the patch fields of a given type and class to match the
313  // sizes of the patches in the mesh
314  template<class Type, template<class> class GeoField>
315  void resizePatchFields();
316 
317  //- As above, for all types
318  template<template<class> class GeoField>
319  void resizePatchFields();
320 
321  //- Pre-conform the volume fields of a given type. This maps all the
322  // non-conformal values to the original patch faces so that they
323  // can be mapped across subsequent mesh changes. See
324  // conformedFvPatchField::conform for details.
325  template<class Type>
326  void preConformVolFields();
327 
328  //- Calls pre-conform volume field functions for all types
329  void preConformVolFields();
330 
331  //- Pre-conform surface fields of a given type. This maps all the
332  // non-conformal values to the original patch faces so that they
333  // can be mapped across subsequent mesh changes. See
334  // conformedFvsPatchField::conform for details.
335  template<class Type>
336  void preConformSurfaceFields();
337 
338  //- Calls pre-conform surface field functions for all types
339  void preConformSurfaceFields();
340 
341  //- Post-unconform volume fields of a given type. This takes all
342  // the non-conformal values which were mapped onto the conformal
343  // faces by the pre-conform call and maps them back into the new
344  // non-conformal faces. See conformedFvPatchField::unconform for
345  // details.
346  template<class Type>
347  void postUnconformVolFields();
348 
349  //- Evaluate all non-conformal vol patch fields of a given type
350  template<class Type>
351  void postUnconformEvaluateVolFields();
352 
353  //- Calls post-unconform volume field functions for all types
354  void postUnconformVolFields();
355 
356  //- Post-unconform surface fields of a given type. This takes all
357  // the non-conformal values which were mapped onto the conformal
358  // faces by the pre-conform call and maps them back into the new
359  // non-conformal faces. See conformedFvsPatchField::unconform for
360  // details.
361  template<class Type>
362  void postUnconformSurfaceFields();
363 
364  //- Calls post-unconform surface field functions for all types
365  void postUnconformSurfaceFields();
366 
367 
368 protected:
369 
370  // Protected Member Functions
371 
372  //- Access the boundary field reference of a field, without updating
373  // the time index, storing old time fields, etc...
374  template<class GeoField>
375  static typename GeoField::Boundary& boundaryFieldRefNoUpdate
376  (
377  GeoField& fld
378  );
379 
380 
381  // Checking
382 
383  //- Determine which patches are coupled; i.e., for which
384  // non-conformal patches are the remote or neighbouring meshes
385  // available
386  boolList patchCoupleds() const;
387 
388  //- Is the connection "geometric", or has the topology just been
389  // loaded and stabilisation geometry applied?
390  bool geometric() const;
391 
392  //- Return the non-dimensional cell openness for debugging/checking
394 
395  //- Return the non-dimensional old-time volume conservation error
396  // for a specified old-time index for debugging/checking
398  (
399  const label n
400  ) const;
401 
402 
403 public:
404 
405  //- Runtime type information
406  TypeName("fvMeshStitcher");
407 
408 
409  // Declare run-time constructor selection table
410 
412  (
413  autoPtr,
415  fvMesh,
416  (fvMesh& mesh),
417  (mesh)
418  );
419 
420 
421  // Constructors
422 
423  //- Construct from fvMesh
424  explicit fvMeshStitcher(fvMesh&);
425 
426  //- Disallow default bitwise copy construction
427  fvMeshStitcher(const fvMeshStitcher&) = delete;
428 
429 
430  // Selectors
431 
432  //- Select, construct and return the fvMeshStitcher
433  static autoPtr<fvMeshStitcher> New(fvMesh&, bool changing);
434 
435 
436  //- Destructor
437  virtual ~fvMeshStitcher();
438 
439 
440  // Member Functions
441 
442  //- Return the fvMesh
443  fvMesh& mesh()
444  {
445  return mesh_;
446  }
447 
448  //- Does this stitcher do anything?
449  bool stitches() const;
450 
451  //- Is the set of connected region meshes dynamic?
452  bool dynamic() const;
453 
454  //- Disconnect the mesh by removing faces from the nonConformalCyclics
455  bool disconnect
456  (
457  const bool changing,
458  const bool geometric
459  );
460 
461  //- Connect the mesh by adding faces into the nonConformalCyclics
462  bool connect
463  (
464  const bool changing,
465  const bool geometric,
466  const bool load
467  );
468 
469  //- Re-compute the connection. Topology is preserved. Permits a change
470  // in whether or not the connection is "geometric".
471  void reconnect(const bool geometric) const;
472 
473  //- Update corresponding to the given map
474  virtual void topoChange(const polyTopoChangeMap&);
475 
476  //- Update from another mesh using the given map
477  virtual void mapMesh(const polyMeshMap&);
478 
479  //- Update corresponding to the given distribution map
480  virtual void distribute(const polyDistributionMap&);
481 
482  //- Write the stitcher state
483  virtual bool write(const bool write = true) const
484  {
485  return true;
486  }
487 
488 
489  // Member Operators
490 
491  //- Disallow default bitwise assignment
492  void operator=(const fvMeshStitcher&) = delete;
493 };
494 
495 
496 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
497 
498 } // End namespace Foam
499 
500 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
501 
502 #ifdef NoRepository
503  #include "fvMeshStitcherTemplates.C"
504 #endif
505 
506 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
507 
508 #endif
509 
510 // ************************************************************************* //
label n
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Definition: DynamicList.H:78
Generic GeometricBoundaryField class.
Generic GeometricField class.
A HashTable with keys but without contents.
Definition: HashSet.H:62
IOobject defines the attributes of an object for which implicit objectRegistry management is supporte...
Definition: IOobject.H:99
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:66
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
Mesh manipulator that uses the intersection provided by the cyclic non-conformal poly patches to crea...
bool disconnect(const bool changing, const bool geometric)
Disconnect the mesh by removing faces from the nonConformalCyclics.
TypeName("fvMeshStitcher")
Runtime type information.
bool connect(const bool changing, const bool geometric, const bool load)
Connect the mesh by adding faces into the nonConformalCyclics.
static autoPtr< fvMeshStitcher > New(fvMesh &, bool changing)
Select, construct and return the fvMeshStitcher.
void reconnect(const bool geometric) const
Re-compute the connection. Topology is preserved. Permits a change.
bool geometric() const
Is the connection "geometric", or has the topology just been.
static GeoField::Boundary & boundaryFieldRefNoUpdate(GeoField &fld)
Access the boundary field reference of a field, without updating.
fvMeshStitcher(fvMesh &)
Construct from fvMesh.
virtual void topoChange(const polyTopoChangeMap &)
Update corresponding to the given map.
virtual void distribute(const polyDistributionMap &)
Update corresponding to the given distribution map.
bool stitches() const
Does this stitcher do anything?
fvMesh & mesh()
Return the fvMesh.
virtual void mapMesh(const polyMeshMap &)
Update from another mesh using the given map.
void operator=(const fvMeshStitcher &)=delete
Disallow default bitwise assignment.
tmp< DimensionedField< scalar, volMesh > > openness() const
Return the non-dimensional cell openness for debugging/checking.
declareRunTimeSelectionTable(autoPtr, fvMeshStitcher, fvMesh,(fvMesh &mesh),(mesh))
tmp< DimensionedField< scalar, volMesh > > volumeConservationError(const label n) const
Return the non-dimensional old-time volume conservation error.
bool dynamic() const
Is the set of connected region meshes dynamic?
boolList patchCoupleds() const
Determine which patches are coupled; i.e., for which.
virtual ~fvMeshStitcher()
Destructor.
virtual bool write(const bool write=true) const
Write the stitcher state.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:99
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
Foam::intersection.
Definition: intersection.H:50
Non-conformal cyclic FV patch. As nonConformalCoupledFvPatch, but the neighbouring patch is local and...
Wall fv patch which can do non-conformal mapping of values from another potentially non-globally conf...
Class to generate patchToPatch coupling geometry. A full geometric intersection is done between a fac...
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
A patch is a list of labels that address the faces in the global face list.
Definition: polyPatch.H:70
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:62
Perform mapping of finite volume fields required by stitching.
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Namespace for OpenFOAM.
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
const word & regionName(const solver &region)
Definition: solver.H:209
Structure to store the geometry associated with the coupling.
Structure to store the geometry associated with part of a patch.