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>
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,
176  ) = 0;
177 
178 
179  // Field Mapping
180 
181  //- Store old times for all fields of a given type and class
182  template<class Type, template<class> class GeoField>
183  void storeOldTimeFields();
184 
185  //- Store old times for all fields of a given class
186  template<template<class> class GeoField>
187  void storeOldTimeFields();
188 
189  //- Resize the patch fields of a given type and class to match the
190  // mesh
191  template<class Type, template<class> class GeoField>
192  void resizePatchFields();
193 
194  //- Resize the patch fields of a given class to match the mesh
195  template<template<class> class GeoField>
196  void resizePatchFields();
197 
198  //- Pre-conform surface fields of a given type by separating NCC
199  // and original parts of non-conformal couplings and storing them
200  // in the database as separate fields
201  template<class Type>
202  void preConformSurfaceFields();
203 
204  //- Pre-conform surface fields by separating NCC and original
205  // parts of non-conformal couplings and storing them in the
206  // database as separate fields
207  inline void preConformSurfaceFields();
208 
209  //- Post-non-conform surface fields of a given type by looking up
210  // NCC and original parts of non-conformal couplings and combining
211  // them into a single non-conformal boundary field
212  template<class Type>
213  void postNonConformSurfaceFields();
214 
215  //- Post-non-conform surface fields by looking up NCC and
216  // original parts of non-conformal couplings and combining them
217  // into a single non-conformal boundary field
218  inline void postNonConformSurfaceFields();
219 
220  //- Evaluate all non-conformal vol patch fields of a given type
221  template<class Type>
222  void evaluateVolFields();
223 
224  //- Evaluate all non-conformal vol patch fields
225  inline void evaluateVolFields();
226 
227  //- Special post-non-conform for surface velocities
228  inline void postNonConformSurfaceVelocities();
229 
230 
231 protected:
232 
233  // Protected Member Functions
234 
235  // Field Mapping
236 
237  //- Resize the patch field of a given field to match the mesh
238  template<class GeoBoundaryField>
240  (
241  const SurfaceFieldBoundary<label>& polyFacesBf,
242  GeoBoundaryField& fieldBf
243  );
244 
245  //- Resize the patch field of a given field to match the mesh
246  template<class GeoField>
248  (
249  const SurfaceFieldBoundary<label>& polyFacesBf,
250  GeoField& field
251  );
252 
253  //- Reverse-map sum the values of a field
254  template<class Type>
256  (
257  const Field<Type>& f,
258  const label size,
259  const labelUList& addr
260  );
261 
262  //- Reverse-map sum the values of a field
263  template<class Type>
265  (
266  const tmp<Field<Type>>& f,
267  const label size,
268  const labelUList& addr
269  );
270 
271  //- Return the total non-conformal area associated with each
272  // original face
274 
275  //- Extract the non-conformal-coupled parts of the boundary field
276  // and store it on the conformal faces
277  template<class Type>
279  (
280  const SurfaceFieldBoundary<Type>& fieldb
281  ) const;
282 
283  //- Extract the original parts of the boundary field and store it
284  // on the conformal faces
285  template<class Type>
287  (
288  const SurfaceFieldBoundary<Type>& fieldb
289  ) const;
290 
291  //- Combine non-conformal-coupled and original parts of the
292  // boundary field from the conformal faces to construct the
293  // complete non-conformal boundary field
294  template<class Type>
296  (
297  const SurfaceFieldBoundary<Type>& nccFieldb,
298  const SurfaceFieldBoundary<Type>& origFieldb
299  ) const;
300 
301  //- Synchronise the boundary field by combining corresponding
302  // values across couplings with the given weightings
303  template<class Type>
305  (
306  const SurfaceFieldBoundary<Type>& fieldb,
307  const bool flip,
308  const scalar ownerWeight,
309  const scalar neighbourWeight
310  ) const;
311 
312  //- Synchronise the boundary field by combining corresponding
313  // values across couplings with equal weightings
314  template<class Type>
316  (
317  const SurfaceFieldBoundary<Type>& fieldb
318  ) const;
319 
320 
321  // Checking
322 
323  //- Is the connection "geometric", or has the topology just been
324  // loaded and stabilisation geometry applied?
325  bool geometric() const;
326 
327  //- Return the non-dimensional cell openness for debugging/checking
329 
330  //- Return the non-dimensional old-time volume conservation error
331  // for a specified old-time index for debugging/checking
333  (
334  const label n
335  ) const;
336 
337 
338 public:
339 
340  //- Runtime type information
341  TypeName("fvMeshStitcher");
342 
343 
344  // Declare run-time constructor selection table
345 
347  (
348  autoPtr,
350  fvMesh,
351  (fvMesh& mesh),
352  (mesh)
353  );
354 
355 
356  // Constructors
357 
358  //- Construct from fvMesh
359  explicit fvMeshStitcher(fvMesh&);
360 
361  //- Disallow default bitwise copy construction
362  fvMeshStitcher(const fvMeshStitcher&) = delete;
363 
364 
365  // Selectors
366 
367  //- Select, construct and return the fvMeshStitcher
368  static autoPtr<fvMeshStitcher> New(fvMesh&, bool changing);
369 
370 
371  //- Destructor
372  virtual ~fvMeshStitcher();
373 
374 
375  // Member Functions
376 
377  //- Return the fvMesh
378  fvMesh& mesh()
379  {
380  return mesh_;
381  }
382 
383  //- Does this stitcher do anything?
384  bool stitches() const;
385 
386  //- Update local data for topology changes
387  virtual void updateMesh(const polyTopoChangeMap&);
388 
389  //- Update local data for mesh motion
390  virtual void movePoints();
391 
392  //- Disconnect the mesh by removing faces from the nonConformalCyclics
393  virtual bool disconnect
394  (
395  const bool changing,
396  const bool geometric
397  );
398 
399  //- Connect the mesh by adding faces into the nonConformalCyclics
400  virtual bool connect
401  (
402  const bool changing,
403  const bool geometric,
404  const bool load
405  );
406 
407  //- Re-compute the connection. Topology is preserved. Permits a change
408  // in whether or not the connection is "geometric".
409  void reconnect(const bool geometric) const;
410 
411  //- Write the mover state
412  virtual bool write(const bool write = true) const
413  {
414  return true;
415  }
416 
417 
418  // Member Operators
419 
420  //- Disallow default bitwise assignment
421  void operator=(const fvMeshStitcher&) = delete;
422 };
423 
424 
425 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
426 
427 } // End namespace Foam
428 
429 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
430 
431 #ifdef NoRepository
432  #include "fvMeshStitcherTemplates.C"
433 #endif
434 
435 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
436 
437 #endif
438 
439 // ************************************************************************* //
virtual bool disconnect(const bool changing, const bool geometric)
Disconnect the mesh by removing faces from the nonConformalCyclics.
static tmp< Field< Type > > fieldRMapSum(const Field< Type > &f, const label size, const labelUList &addr)
Reverse-map sum the values of a field.
tmp< SurfaceFieldBoundary< Type > > conformalNccBoundaryField(const SurfaceFieldBoundary< Type > &fieldb) const
Extract the non-conformal-coupled parts of the boundary field.
tmp< SurfaceFieldBoundary< Type > > nonConformalBoundaryField(const SurfaceFieldBoundary< Type > &nccFieldb, const SurfaceFieldBoundary< Type > &origFieldb) const
Combine non-conformal-coupled and original parts of the.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
declareRunTimeSelectionTable(autoPtr, fvMeshStitcher, fvMesh,(fvMesh &mesh),(mesh))
bool geometric() const
Is the connection "geometric", or has the topology just been.
Mesh manipulator that uses the intersection provided by the cyclic non-conformal poly patches to crea...
virtual bool write(const bool write=true) const
Write the mover state.
Structure to store the geometry associated with part of a patch.
Non-conformal cyclic FV patch. As nonConformalCoupledFvPatch, but the neighbouring patch is local and...
tmp< DimensionedField< scalar, volMesh > > volumeConservationError(const label n) const
Return the non-dimensional old-time volume conservation error.
Perform mapping of finite volume fields required by stitching.
fvMesh & mesh()
Return the fvMesh.
tmp< SurfaceFieldBoundary< scalar > > getOrigNccMagSfb() const
Return the total non-conformal area associated with each.
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.
tmp< SurfaceFieldBoundary< Type > > conformalOrigBoundaryField(const SurfaceFieldBoundary< Type > &fieldb) const
Extract the original parts of the boundary field and store it.
virtual void movePoints()
Update local data for mesh motion.
Pre-declare SubField and related Field type.
Definition: Field.H:56
void resizeFieldPatchFields(const SurfaceFieldBoundary< label > &polyFacesBf, GeoField &field)
Resize the patch field of a given field to match the mesh.
A class for handling words, derived from string.
Definition: word.H:59
Class containing mesh-to-mesh mapping information after a change in polyMesh topology.
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.
virtual void updateMesh(const polyTopoChangeMap &)
Update local data for topology changes.
virtual bool connect(const bool changing, const bool geometric, const bool load)
Connect the mesh by adding faces into the nonConformalCyclics.
phi
Definition: correctPhi.H:3
TypeName("fvMeshStitcher")
Runtime type information.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
bool stitches() const
Does this stitcher do anything?
virtual ~fvMeshStitcher()
Destructor.
labelList f(nPoints)
void operator=(const fvMeshStitcher &)=delete
Disallow default bitwise assignment.
Generic GeometricBoundaryField class.
Definition: fvMesh.H:80
Structure to store the geometry associated with the coupling.
Mesh data needed to do the Finite Volume discretisation.
Definition: fvMesh.H:95
label n
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
static autoPtr< fvMeshStitcher > New(fvMesh &, bool changing)
Select, construct and return the fvMeshStitcher.
tmp< DimensionedField< scalar, volMesh > > openness() const
Return the non-dimensional cell openness for debugging/checking.
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
void reconnect(const bool geometric) const
Re-compute the connection. Topology is preserved. Permits a change.
Namespace for OpenFOAM.