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-2025 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>
66 
67  //- Alias the patchToPatch intersection part struct
69 
70  //- Alias the patchToPatch intersection couple struct
72 
73 
74 private:
75 
76  // Private Static Data
77 
78  //- Minimum projected volume fraction that results in a warning
79  static const scalar minWarnProjectedVolumeFraction_;
80 
81 
82  // Private Data
83 
84  //- Non-const fvMesh reference to allow update
85  fvMesh& mesh_;
86 
87  //- Flag to indicate whether this region is ready to be stitched
88  bool ready_;
89 
90  //- Cache of loaded region poly face IO objects
91  HashPtrTable<IOobject> regionPolyFacesBfIOs_;
92 
93  //- Cache of loaded region poly face boundary fields
94  HashPtrTable<SurfaceFieldBoundary<label>> regionPolyFacesBfs_;
95 
96 
97  // Private Member Functions
98 
99  // Regions
100 
101  //- Construct a table of connected region names. Recurses to
102  // find neighbours-of-neighbours and so on. Includes this region.
103  static void regionNames(const fvMesh& mesh, wordHashSet& names);
104 
105  //- Get a list of the connected region names
106  wordList regionNames() const;
107 
108  //- Get a list of the connected region meshes
109  UPtrList<const fvMesh> regionMeshes() const;
110 
111  //- Get a list of the connected region meshes
112  UPtrList<fvMesh> regionMeshes();
113 
114 
115  // Topology access
116 
117  //- Get the IO for the poly faces boundary field for a given mesh
118  static IOobject polyFacesBfIO(const fvMesh& mesh);
119 
120  //- Load the poly faces boundary field for this mesh, and also make
121  // sure that all neighbouring regions' poly faces boundary fields
122  // are available either by lookup or in the region cache
123  bool loadPolyFacesBf
124  (
125  IOobject& polyFacesBfIO,
126  SurfaceFieldBoundary<label>& polyFacesBf
127  );
128 
129  //- Access the poly faces boundary field for a region
130  const SurfaceFieldBoundary<label>& getPolyFacesBf
131  (
132  const word& regionName
133  ) const;
134 
135  //- Get fields of neighbouring original face properties
136  void getOrigNbrBfs
137  (
138  const SurfaceFieldBoundary<label>& polyFacesBf,
139  const SurfaceFieldBoundary<vector>& SfBf,
140  const SurfaceFieldBoundary<vector>& CfBf,
141  tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
142  tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
143  tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf
144  ) const;
145 
146 
147  // Intersection
148 
149  //- Unpack the patchToPatch addressing into lists of indices (fixed
150  // lists of 3 labels; owner face, neighbour face, couple index).
151  // These will be used to create the non-conformal faces, so sort
152  // them to make sure the non-conformal interfaces are ordered.
153  static List<List<FixedList<label, 3>>> procFacesToIndices
154  (
155  const List<List<remote>>& faceOtherProcFaces,
156  const bool owner
157  );
158 
159  //- If addressing has been provided, then modify the indices to
160  // match. When a coupling has to be added, the couple index is set
161  // to -1. This indicates that there is no geometry in the
162  // patchToPatch engine for this coupling, and for a small
163  // stabilisation value to be used instead.
164  static void matchIndices
165  (
166  const SurfaceFieldBoundary<label>& polyFacesBf,
167  const SurfaceFieldBoundary<label>& origFacesNbrBf,
168  List<List<FixedList<label, 3>>>& indices,
169  const fvPatch& ncFvp,
170  const polyPatch& origPp,
171  const labelList& patchis,
172  const labelList& patchOffsets,
173  const labelList& patchSizes,
174  const bool owner
175  );
176 
177  //- Return the number of valid indices in the given list
178  static label nValidIndices
179  (
180  const List<FixedList<label, 3>>& indices
181  );
182 
183  //- Create couplings by transferring geometry from the original to
184  // the non-conformal patches
185  static void createCouplings
186  (
187  SurfaceFieldBoundary<label>& polyFacesBf,
190  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
191  const tmp<SurfaceFieldBoundary<vector>>& tOrigCfNbrBf,
192  const List<List<FixedList<label, 3>>>& indices,
193  const List<DynamicList<couple>>& couples,
194  const polyPatch& origPp,
195  const labelList& patchis,
196  const labelList& patchOffsets,
197  const bool owner
198  );
199 
200  //- Add error geometry to the original patches and store the edge
201  // parts
202  static void createErrorAndEdgeParts
203  (
206  List<part>& origEdgeParts,
208  const polyPatch& origPp
209  );
210 
211  //- Perform intersections for the given non-conformal cyclic
212  void intersectNonConformalCyclic
213  (
214  const nonConformalCyclicFvPatch& nccFvp,
215  SurfaceFieldBoundary<label>& polyFacesBf,
218  const tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
219  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
220  const tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf,
221  List<part>& origEdgeParts
222  ) const;
223 
224  //- Perform intersections for the given non-conformal mapped
225  void intersectNonConformalMappedWall
226  (
227  const nonConformalMappedWallFvPatch& ncmwFvp,
228  SurfaceFieldBoundary<label>& polyFacesBf,
231  const tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
232  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
233  const tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf,
234  List<part>& origEdgeParts
235  ) const;
236 
237  //- Convert per-patch lists of edge parts into a single
238  // owner-orig-boundary list of edge parts that can be applied to
239  // the mesh
240  List<part> calculateOwnerOrigBoundaryEdgeParts
241  (
242  const List<List<part>>& patchEdgeParts
243  ) const;
244 
245  //- Apply a list of owner-orig-boundary edge parts to
246  // non-orig-patch faces (both internal and boundary)
247  void applyOwnerOrigBoundaryEdgeParts
248  (
249  surfaceVectorField& SfSf,
250  surfaceVectorField& CfSf,
251  const List<part>& ownerOrigBoundaryEdgeParts
252  ) const;
253 
254  //- Stabilise the faces that have had non-conformal coupled parts
255  // cut out from them
256  void stabiliseOrigPatchFaces
257  (
260  ) const;
261 
262  //- Perform intersections for all non-conformal interfaces. For
263  // patches that can be coupled, this creates the intersection
264  // geometry. For patches that cannot, this just sets small
265  // stabilisation values for the given topology (if any).
266  void intersect
267  (
268  SurfaceFieldBoundary<label>& polyFacesBf,
269  surfaceVectorField& SfSf,
270  surfaceVectorField& CfSf,
271  const boolList& patchCoupleds,
272  const bool matchTopology
273  ) const;
274 
275 
276  // Motion
277 
278  //- Return whether or not this stitcher supports a changing mesh
279  virtual bool changing() const = 0;
280 
281  //- Correct the mesh fluxes following a conform operation
282  virtual void conformCorrectMeshPhi(surfaceScalarField& phi) = 0;
283 
284  //- Initialise correction of the mesh fluxes
285  virtual void createNonConformalCorrectMeshPhiGeometry
286  (
287  SurfaceFieldBoundary<label>& polyFacesBf,
288  surfaceVectorField& SfSf,
289  surfaceVectorField& CfSf
290  ) = 0;
291 
292  //- Correct the mesh fluxes following an unconform operation
293  virtual void unconformCorrectMeshPhi
294  (
295  const SurfaceFieldBoundary<label>& polyFacesBf,
296  surfaceVectorField& SfSf,
297  surfaceVectorField& CfSf,
298  surfaceScalarField& phi
299  ) = 0;
300 
301 
302  // Connection
303 
304  //- Disconnect the mesh by removing faces from the
305  // nonConformalCyclics
306  bool disconnectThis
307  (
308  const bool changing,
309  const bool geometric
310  );
311 
312  //- Connect the mesh by adding faces into the nonConformalCyclics
313  bool connectThis
314  (
315  const bool changing,
316  const bool geometric,
317  const bool load
318  );
319 
320 
321  // Field Mapping
322 
323  //- Resize the patch fields of a given type and class to match the
324  // sizes of the patches in the mesh
325  template<class Type, template<class> class GeoField>
326  void resizePatchFields();
327 
328  //- As above, for all types
329  template<template<class> class GeoField>
330  void resizePatchFields();
331 
332  //- Pre-conform surface fields of a given type. This maps all the
333  // non-conformal values to the original patch faces so that they
334  // can be mapped across subsequent mesh changes. See
335  // conformedFvsPatchField::conform for details.
336  template<class Type>
337  void preConformSurfaceFields();
338 
339  //- Calls pre-conform surface field functions for all types
340  void preConformSurfaceFields();
341 
342  //- Pre-conform the volume fields of a given type. This maps all the
343  // non-conformal values to the original patch faces so that they
344  // can be mapped across subsequent mesh changes. See
345  // conformedFvPatchField::conform for details.
346  template<class Type>
347  void preConformVolFields();
348 
349  //- Calls pre-conform volume field functions for all types
350  void preConformVolFields();
351 
352  //- Post-unconform surface fields of a given type. This takes all
353  // the non-conformal values which were mapped onto the conformal
354  // faces by the pre-conform call and maps them back into the new
355  // non-conformal faces. See conformedFvsPatchField::unconform for
356  // details.
357  template<class Type>
358  void postUnconformSurfaceFields();
359 
360  //- Calls post-unconform surface field functions for all types
361  void postUnconformSurfaceFields();
362 
363  //- Post-unconform volume fields of a given type. This takes all
364  // the non-conformal values which were mapped onto the conformal
365  // faces by the pre-conform call and maps them back into the new
366  // non-conformal faces. See conformedFvPatchField::unconform for
367  // details.
368  template<class Type>
369  void postUnconformVolFields();
370 
371  //- Evaluate all non-conformal vol patch fields of a given type
372  template<class Type>
373  void postUnconformEvaluateVolFields();
374 
375  //- Calls post-unconform volume field functions for all types
376  void postUnconformVolFields();
377 
378 
379 protected:
380 
381  // Protected Member Functions
382 
383  // Checking
384 
385  //- Determine which patches are coupled; i.e., for which
386  // non-conformal patches are the remote or neighbouring meshes
387  // available
388  boolList patchCoupleds() const;
389 
390  //- Is the connection "geometric", or has the topology just been
391  // loaded and stabilisation geometry applied?
392  bool geometric() const;
393 
394  //- Return the non-dimensional cell openness for debugging/checking
396 
397  //- Return the non-dimensional old-time volume conservation error
398  // for a specified old-time index for debugging/checking
400  volumeConservationError(const label n) const;
401 
402  //- Return the projected volume fraction for debugging/checking
404  projectedVolumeFraction() const;
405 
406 
407 public:
408 
409  //- Runtime type information
410  TypeName("fvMeshStitcher");
411 
412 
413  // Declare run-time constructor selection table
414 
416  (
417  autoPtr,
419  fvMesh,
420  (fvMesh& mesh),
421  (mesh)
422  );
423 
424 
425  // Constructors
426 
427  //- Construct from fvMesh
428  explicit fvMeshStitcher(fvMesh&);
429 
430  //- Disallow default bitwise copy construction
431  fvMeshStitcher(const fvMeshStitcher&) = delete;
432 
433 
434  // Selectors
435 
436  //- Select, construct and return the fvMeshStitcher
437  static autoPtr<fvMeshStitcher> New(fvMesh&, bool changing);
438 
439 
440  //- Destructor
441  virtual ~fvMeshStitcher();
442 
443 
444  // Member Functions
445 
446  //- Return the fvMesh
447  fvMesh& mesh()
448  {
449  return mesh_;
450  }
451 
452  //- Does this stitcher do anything?
453  bool stitches() const;
454 
455  //- Disconnect the mesh by removing faces from the nonConformalCyclics
456  bool disconnect
457  (
458  const bool changing,
459  const bool geometric
460  );
461 
462  //- Connect the mesh by adding faces into the nonConformalCyclics
463  bool connect
464  (
465  const bool changing,
466  const bool geometric,
467  const bool load
468  );
469 
470  //- Re-compute the connection. Topology is preserved. Permits a change
471  // in whether or not the connection is "geometric".
472  void reconnect(const bool geometric) const;
473 
474  //- Update corresponding to the given map
475  virtual void topoChange(const polyTopoChangeMap&);
476 
477  //- Update from another mesh using the given map
478  virtual void mapMesh(const polyMeshMap&);
479 
480  //- Update corresponding to the given distribution map
481  virtual void distribute(const polyDistributionMap&);
482 
483  //- Write the stitcher state
484  virtual bool write(const bool write = true) const
485  {
486  return true;
487  }
488 
489 
490  // Member Operators
491 
492  //- Disallow default bitwise assignment
493  void operator=(const fvMeshStitcher&) = delete;
494 };
495 
496 
497 // Template Specialisations
498 
499 template<>
500 void fvMeshStitcher::postUnconformSurfaceFields<Foam::vector>();
501 
502 
503 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
504 
505 } // End namespace Foam
506 
507 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
508 
509 #ifdef NoRepository
510  #include "fvMeshStitcherTemplates.C"
511 #endif
512 
513 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
514 
515 #endif
516 
517 // ************************************************************************* //
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.
fvMeshStitcher(fvMesh &)
Construct from fvMesh.
tmp< DimensionedField< scalar, volMesh > > projectedVolumeFraction() const
Return the projected volume fraction for debugging/checking.
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.
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:96
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.
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:218
Structure to store the geometry associated with the coupling.
Structure to store the geometry associated with part of a patch.