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-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 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"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 class nonConformalCyclicFvPatch;
49 
50 /*---------------------------------------------------------------------------*\
51  Class fvMeshStitcher Declaration
52 \*---------------------------------------------------------------------------*/
53 
54 class fvMeshStitcher
55 {
56 protected:
57 
58  // Protected Typedefs
59 
60  //- Alias for surface boundary fields to reduce verbosity of method
61  // definitions below
62  template<class Type>
63  using SurfaceFieldBoundary =
65 
66  //- Alias the patchToPatch intersection part struct
68 
69  //- Alias the patchToPatch intersection couple struct
71 
72 
73 private:
74 
75  // Private Static Data
76 
77  //- Prefix applied to the names of non-conformal fields which are
78  // stored for mapping purposes
79  static const word nccFieldPrefix_;
80 
81 
82  // Private Data
83 
84  //- Non-const fvMesh reference to allow update
85  fvMesh& mesh_;
86 
87 
88  // Private Member Functions
89 
90  // Intersection
91 
92  //- Perform intersections for the given non-conformal interface
93  void intersectNonConformalCyclic
94  (
95  const nonConformalCyclicFvPatch& nccFvp,
96  SurfaceFieldBoundary<label>& polyFacesBf,
99  const tmp<SurfaceFieldBoundary<label>>& tOrigFacesNbrBf,
100  const tmp<SurfaceFieldBoundary<vector>>& tOrigSfNbrBf,
101  const tmp<SurfaceFieldBoundary<point>>& tOrigCfNbrBf,
102  List<part>& origEdgeParts
103  ) const;
104 
105  //- Convert per-patch lists of edge parts into a single
106  // owner-orig-boundary list of edge parts that can be applied to
107  // the mesh
108  List<part> calculateOwnerOrigBoundaryEdgeParts
109  (
110  const List<List<part>>& patchEdgeParts
111  ) const;
112 
113  //- Apply a list of owner-orig-boundary edge parts to
114  // non-orig-patch faces (both internal and boundary)
115  void applyOwnerOrigBoundaryEdgeParts
116  (
117  surfaceVectorField& SfSf,
118  surfaceVectorField& CfSf,
119  const List<part>& ownerOrigBoundaryEdgeParts
120  ) const;
121 
122  //- Stabilise the faces that have had non-conformal coupled parts
123  // cut out from them
124  void stabiliseOrigPatchFaces
125  (
128  ) const;
129 
130  //- Perform intersections for all non-conformal interfaces
131  void intersectNonConformalCyclics
132  (
133  SurfaceFieldBoundary<label>& polyFacesBf,
134  surfaceVectorField& SfSf,
135  surfaceVectorField& CfSf,
136  const bool haveTopology
137  ) const;
138 
139  //- Apply the given non-conformal topology (polyFacesBf) to the
140  // face geometry fields for the given patch type. Just set small
141  // stabilisation values. Don't actually do any cutting. Used for
142  // initialisation, or in situations when cutting cannot be done
143  // (e.g., when post processing a processor case).
144  template<class NonConformalFvPatch>
145  inline void createNonConformalStabilisationGeometry
146  (
147  const SurfaceFieldBoundary<label>& polyFacesBf,
148  surfaceVectorField& SfSf,
149  surfaceVectorField& CfSf
150  ) const;
151 
152 
153  // Motion
154 
155  //- Return whether or not this stitcher supports a changing mesh
156  virtual bool changing() const = 0;
157 
158  //- Correct the mesh fluxes following a conform operation
159  virtual void conformCorrectMeshPhi(surfaceScalarField& phi) = 0;
160 
161  //- Initialise correction of the mesh fluxes
162  virtual void createNonConformalCorrectMeshPhiGeometry
163  (
164  SurfaceFieldBoundary<label>& polyFacesBf,
165  surfaceVectorField& SfSf,
166  surfaceVectorField& CfSf
167  ) = 0;
168 
169  //- Correct the mesh fluxes following an unconform operation
170  virtual void unconformCorrectMeshPhi
171  (
172  const SurfaceFieldBoundary<label>& polyFacesBf,
173  surfaceVectorField& SfSf,
174  surfaceVectorField& CfSf,
175  surfaceScalarField& phi
176  ) = 0;
177 
178 
179  // Field Mapping
180 
181  //- Resize the patch fields of a given type and class to match the
182  // mesh
183  template<class Type, template<class> class GeoField>
184  void resizePatchFields();
185 
186  //- Resize the patch fields of a given class to match the mesh
187  template<template<class> class GeoField>
188  void resizePatchFields();
189 
190  //- Pre-conform surface fields of a given type by separating NCC
191  // and original parts of non-conformal couplings and storing them
192  // in the database as separate fields
193  template<class Type>
194  void preConformSurfaceFields();
195 
196  //- Pre-conform surface fields by separating NCC and original
197  // parts of non-conformal couplings and storing them in the
198  // database as separate fields
199  inline void preConformSurfaceFields();
200 
201  //- Post-non-conform surface fields of a given type by looking up
202  // NCC and original parts of non-conformal couplings and combining
203  // them into a single non-conformal boundary field
204  template<class Type>
205  void postNonConformSurfaceFields();
206 
207  //- Post-non-conform surface fields by looking up NCC and
208  // original parts of non-conformal couplings and combining them
209  // into a single non-conformal boundary field
210  inline void postNonConformSurfaceFields();
211 
212  //- Evaluate all non-conformal vol patch fields of a given type
213  template<class Type>
214  void evaluateVolFields();
215 
216  //- Evaluate all non-conformal vol patch fields
217  inline void evaluateVolFields();
218 
219  //- Special post-non-conform for surface velocities
220  inline void postNonConformSurfaceVelocities();
221 
222 
223 protected:
224 
225  // Protected Member Functions
226 
227  // Field Mapping
228 
229  //- Resize the patch field of a given field to match the mesh
230  template<class GeoBoundaryField>
232  (
233  const SurfaceFieldBoundary<label>& polyFacesBf,
234  GeoBoundaryField& fieldBf
235  );
236 
237  //- Resize the patch field of a given field to match the mesh
238  template<class GeoField>
240  (
241  const SurfaceFieldBoundary<label>& polyFacesBf,
242  GeoField& field
243  );
244 
245  //- Reverse-map sum the values of a field
246  template<class Type>
248  (
249  const Field<Type>& f,
250  const label size,
251  const labelUList& addr
252  );
253 
254  //- Reverse-map sum the values of a field
255  template<class Type>
257  (
258  const tmp<Field<Type>>& f,
259  const label size,
260  const labelUList& addr
261  );
262 
263  //- Return the total non-conformal area associated with each
264  // original face
266 
267  //- Extract the non-conformal-coupled parts of the boundary field
268  // and store it on the conformal faces
269  template<class Type>
271  (
272  const SurfaceFieldBoundary<Type>& fieldb
273  ) const;
274 
275  //- Extract the original parts of the boundary field and store it
276  // on the conformal faces
277  template<class Type>
279  (
280  const SurfaceFieldBoundary<Type>& fieldb
281  ) const;
282 
283  //- Combine non-conformal-coupled and original parts of the
284  // boundary field from the conformal faces to construct the
285  // complete non-conformal boundary field
286  template<class Type>
288  (
289  const SurfaceFieldBoundary<Type>& nccFieldb,
290  const SurfaceFieldBoundary<Type>& origFieldb
291  ) const;
292 
293  //- Synchronise the boundary field by combining corresponding
294  // values across couplings with the given weightings
295  template<class Type>
297  (
298  const SurfaceFieldBoundary<Type>& fieldb,
299  const bool flip,
300  const scalar ownerWeight,
301  const scalar neighbourWeight
302  ) const;
303 
304  //- Synchronise the boundary field by combining corresponding
305  // values across couplings with equal weightings
306  template<class Type>
308  (
309  const SurfaceFieldBoundary<Type>& fieldb
310  ) const;
311 
312 
313  // Checking
314 
315  //- Is the connection "geometric", or has the topology just been
316  // loaded and stabilisation geometry applied?
317  bool geometric() const;
318 
319  //- Return the non-dimensional cell openness for debugging/checking
321 
322  //- Return the non-dimensional old-time volume conservation error
323  // for a specified old-time index for debugging/checking
325  (
326  const label n
327  ) const;
328 
329 
330 public:
331 
332  //- Runtime type information
333  TypeName("fvMeshStitcher");
334 
335 
336  // Declare run-time constructor selection table
337 
339  (
340  autoPtr,
342  fvMesh,
343  (fvMesh& mesh),
344  (mesh)
345  );
346 
347 
348  // Constructors
349 
350  //- Construct from fvMesh
351  explicit fvMeshStitcher(fvMesh&);
352 
353  //- Disallow default bitwise copy construction
354  fvMeshStitcher(const fvMeshStitcher&) = delete;
355 
356 
357  // Selectors
358 
359  //- Select, construct and return the fvMeshStitcher
360  static autoPtr<fvMeshStitcher> New(fvMesh&, bool changing);
361 
362 
363  //- Destructor
364  virtual ~fvMeshStitcher();
365 
366 
367  // Member Functions
368 
369  //- Return the fvMesh
370  fvMesh& mesh()
371  {
372  return mesh_;
373  }
374 
375  //- Does this stitcher do anything?
376  bool stitches() const;
377 
378  //- Update local data for topology changes
379  virtual void updateMesh(const polyTopoChangeMap&);
380 
381  //- Update local data for mesh motion
382  virtual void movePoints();
383 
384  //- Disconnect the mesh by removing faces from the nonConformalCyclics
385  virtual bool disconnect
386  (
387  const bool changing,
388  const bool geometric
389  );
390 
391  //- Connect the mesh by adding faces into the nonConformalCyclics
392  virtual bool connect
393  (
394  const bool changing,
395  const bool geometric,
396  const bool load
397  );
398 
399  //- Re-compute the connection. Topology is preserved. Permits a change
400  // in whether or not the connection is "geometric".
401  void reconnect(const bool geometric) const;
402 
403  //- Write the mover state
404  virtual bool write(const bool write = true) const
405  {
406  return true;
407  }
408 
409 
410  // Member Operators
411 
412  //- Disallow default bitwise assignment
413  void operator=(const fvMeshStitcher&) = delete;
414 };
415 
416 
417 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
418 
419 } // End namespace Foam
420 
421 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
422 
423 #ifdef NoRepository
424  #include "fvMeshStitcherTemplates.C"
425 #endif
426 
427 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
428 
429 #endif
430 
431 // ************************************************************************* //
label n
Pre-declare SubField and related Field type.
Definition: Field.H:82
Generic GeometricBoundaryField class.
Generic GeometricField class.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
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...
tmp< SurfaceFieldBoundary< Type > > conformalNccBoundaryField(const SurfaceFieldBoundary< Type > &fieldb) const
Extract the non-conformal-coupled parts of the boundary field.
virtual bool disconnect(const bool changing, const bool geometric)
Disconnect the mesh by removing faces from the nonConformalCyclics.
TypeName("fvMeshStitcher")
Runtime type information.
virtual void updateMesh(const polyTopoChangeMap &)
Update local data for topology changes.
tmp< SurfaceFieldBoundary< Type > > nonConformalBoundaryField(const SurfaceFieldBoundary< Type > &nccFieldb, const SurfaceFieldBoundary< Type > &origFieldb) const
Combine non-conformal-coupled and original parts of the.
virtual 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.
static tmp< Field< Type > > fieldRMapSum(const Field< Type > &f, const label size, const labelUList &addr)
Reverse-map sum the values of a field.
bool geometric() const
Is the connection "geometric", or has the topology just been.
tmp< SurfaceFieldBoundary< Type > > conformalOrigBoundaryField(const SurfaceFieldBoundary< Type > &fieldb) const
Extract the original parts of the boundary field and store it.
fvMeshStitcher(fvMesh &)
Construct from fvMesh.
void resizeBoundaryFieldPatchFields(const SurfaceFieldBoundary< label > &polyFacesBf, GeoBoundaryField &fieldBf)
Resize the patch field of a given field to match the mesh.
virtual void movePoints()
Update local data for mesh motion.
bool stitches() const
Does this stitcher do anything?
fvMesh & mesh()
Return the fvMesh.
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.
tmp< SurfaceFieldBoundary< Type > > synchronisedBoundaryField(const SurfaceFieldBoundary< Type > &fieldb, const bool flip, const scalar ownerWeight, const scalar neighbourWeight) const
Synchronise the boundary field by combining corresponding.
tmp< SurfaceFieldBoundary< scalar > > getOrigNccMagSfb() const
Return the total non-conformal area associated with each.
virtual ~fvMeshStitcher()
Destructor.
virtual bool write(const bool write=true) const
Write the mover state.
void resizeFieldPatchFields(const SurfaceFieldBoundary< label > &polyFacesBf, GeoField &field)
Resize the patch field of a given field to match the mesh.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:101
Non-conformal cyclic FV patch. As nonConformalCoupledFvPatch, but the neighbouring patch is local and...
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
labelList f(nPoints)
Structure to store the geometry associated with the coupling.
Structure to store the geometry associated with part of a patch.