meshToMesh.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) 2012-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::meshToMesh
26 
27 Description
28  Class to calculate the cell-addressing between two overlapping meshes
29 
30  Mapping is performed using a run-time selectable interpolation mothod
31 
32 See also
33  meshToMeshMethod
34 
35 SourceFiles
36  meshToMesh.C
37  meshToMeshParallelOps.C
38  meshToMeshTemplates.C
39 
40 \*---------------------------------------------------------------------------*/
41 
42 #ifndef meshToMesh_H
43 #define meshToMesh_H
44 
45 #include "polyMesh.H"
46 #include "boundBox.H"
47 #include "distributionMap.H"
48 #include "volFieldsFwd.H"
49 #include "NamedEnum.H"
50 #include "AMIInterpolation.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class meshToMesh Declaration
59 \*---------------------------------------------------------------------------*/
60 
61 class meshToMesh
62 {
63  // Private Data
64 
65  //- Reference to the source mesh
66  const polyMesh& srcRegion_;
67 
68  //- Reference to the target mesh
69  const polyMesh& tgtRegion_;
70 
71  //- List of target patch IDs per source patch (local index)
72  List<label> srcPatchID_;
73 
74  //- List of source patch IDs per target patch (local index)
75  List<label> tgtPatchID_;
76 
77  //- List of AMIs between source and target patches
78  PtrList<AMIInterpolation> patchAMIs_;
79 
80  //- Cutting patches whose values are set using a zero-gradient condition
81  List<label> cuttingPatches_;
82 
83  //- Source to target cell addressing
84  labelListList srcToTgtCellAddr_;
85 
86  //- Target to source cell addressing
87  labelListList tgtToSrcCellAddr_;
88 
89  //- Source to target cell interpolation weights
90  scalarListList srcToTgtCellWght_;
91 
92  //- Target to source cell interpolation weights
93  scalarListList tgtToSrcCellWght_;
94 
95  //- Cell total volume in overlap region [m^3]
96  scalar V_;
97 
98  //- Index of processor that holds all of both sides. -1 in all other
99  // cases
100  label singleMeshProc_;
101 
102  //- Source map pointer - parallel running only
103  autoPtr<distributionMap> srcMapPtr_;
104 
105  //- Target map pointer - parallel running only
106  autoPtr<distributionMap> tgtMapPtr_;
107 
108 
109  // Private Member Functions
110 
111  //- Helper function to add a constant offset to a list
112  template<class Type>
113  void add(UList<Type>& fld, const label offset) const;
114 
115  //- Helper function to interpolate patch field. Template
116  // specialisations below
117  template<class Type>
118  void mapAndOpSrcToTgt
119  (
120  const AMIInterpolation& AMI,
121  const Field<Type>& srcField,
122  Field<Type>& tgtField
123  ) const;
124 
125  //- Helper function to interpolate patch field. Template
126  // specialisations below
127  template<class Type>
128  void mapAndOpTgtToSrc
129  (
130  const AMIInterpolation& AMI,
131  Field<Type>& srcField,
132  const Field<Type>& tgtField
133  ) const;
134 
135  //- Return src cell IDs for the overlap region
136  labelList maskCells(const polyMesh& src, const polyMesh& tgt) const;
137 
138  //- Normalise the interpolation weights
139  void normaliseWeights
140  (
141  const word& descriptor,
142  const labelListList& addr,
143  scalarListList& wght
144  ) const;
145 
146  //- Calculate the addressing between overlapping regions of src and tgt
147  // meshes
148  word calcAddressing
149  (
150  const word& methodName,
151  const polyMesh& src,
152  const polyMesh& tgt
153  );
154 
155  //- Calculate - main driver function
156  // Returns the corresponding AMImethod
157  word calculate(const word& methodName);
158 
159  //- Calculate patch overlap
160  void calculatePatchAMIs(const word& amiMethodName);
161 
162  //- Constructor helper
163  void constructNoCuttingPatches
164  (
165  const word& methodName,
166  const bool interpAllPatches
167  );
168 
169  //- Constructor helper
170  void constructFromCuttingPatches
171  (
172  const word& methodName,
173  const HashTable<word>& patchMap,
174  const wordList& cuttingPatches
175  );
176 
177  //- Return the list of AMIs between source and target patches
178  inline const PtrList<AMIInterpolation>&
179  patchAMIs() const;
180 
181 
182  // Parallel operations
183 
184  //- Determine whether the meshes are split across multiple pocessors
185  label calcDistribution
186  (
187  const polyMesh& src,
188  const polyMesh& tgt
189  ) const;
190 
191  //- Determine which processor bounding-boxes overlap
192  label calcOverlappingProcs
193  (
194  const List<boundBox>& procBb,
195  const boundBox& bb,
196  boolList& overlaps
197  ) const;
198 
199  //- Calculate the mapping between processors
200  autoPtr<distributionMap> calcProcMap
201  (
202  const polyMesh& src,
203  const polyMesh& tgt
204  ) const;
205 
206  //- Distribute mesh info from 'my' processor to others
207  void distributeCells
208  (
209  const distributionMap& map,
210  const polyMesh& tgtMesh,
211  const globalIndex& globalI,
213  List<label>& nInternalFaces,
214  List<faceList>& faces,
215  List<labelList>& faceOwner,
216  List<labelList>& faceNeighbour,
217  List<labelList>& cellIDs,
218  List<labelList>& nbrProcIDs,
219  List<labelList>& procLocalFaceIDs
220  ) const;
221 
222  //- Collect pieces of tgt mesh from other processors and restructure
223  void distributeAndMergeCells
224  (
225  const distributionMap& map,
226  const polyMesh& tgt,
227  const globalIndex& globalI,
228  pointField& tgtPoints,
229  faceList& tgtFaces,
230  labelList& tgtFaceOwners,
231  labelList& tgtFaceNeighbours,
232  labelList& tgtCellIDs
233  ) const;
234 
235 
236 public:
237 
238  //- Run-time type information
239  TypeName("meshToMesh");
240 
241  // Constructors
242 
243  //- Construct from source and target meshes, generic mapping methods
244  meshToMesh
245  (
246  const polyMesh& src,
247  const polyMesh& tgt,
248  const word& methodName,
249  const bool interpAllPatches = true
250  );
251 
252  //- Construct from source and target meshes, generic mapping methods
253  meshToMesh
254  (
255  const polyMesh& src,
256  const polyMesh& tgt,
257  const word& methodName,
258  const HashTable<word>& patchMap,
259  const wordList& cuttingPatches
260  );
261 
262  //- Disallow default bitwise copy construction
263  meshToMesh(const meshToMesh&) = delete;
264 
265 
266  //- Destructor
267  virtual ~meshToMesh();
268 
269 
270  // Member Functions
271 
272  // Access
273 
274  //- Return const access to the source mesh
275  inline const polyMesh& srcRegion() const;
276 
277  //- Return const access to the target mesh
278  inline const polyMesh& tgtRegion() const;
279 
280  //- Return const access to the source to target cell addressing
281  inline const labelListList& srcToTgtCellAddr() const;
282 
283  //- Return const access to the target to source cell addressing
284  inline const labelListList& tgtToSrcCellAddr() const;
285 
286  //- Return const access to the source to target cell weights
287  inline const scalarListList& srcToTgtCellWght() const;
288 
289  //- Return const access to the target to source cell weights
290  inline const scalarListList& tgtToSrcCellWght() const;
291 
292  //- Return const access to the overlap volume
293  inline scalar V() const;
294 
295 
296  // Evaluation
297 
298  // Source-to-target field mapping
299 
300  //- Map field from src to tgt mesh with defined operation
301  // Values passed in via 'result' are used to initialise the
302  // return value
303  template<class Type>
304  void mapSrcToTgt
305  (
306  const UList<Type>& srcFld,
307  List<Type>& result
308  ) const;
309 
310  //- Return the src field mapped to the tgt mesh with a defined
311  // operation. Initial values of the result are set to zero
312  template<class Type>
314  (
315  const Field<Type>& srcFld
316  ) const;
317 
318  //- Convenience function to map a tmp field to the tgt mesh
319  // with a defined operation
320  template<class Type>
322  (
323  const tmp<Field<Type>>& tsrcFld
324  ) const;
325 
326 
327  // Target-to-source field mapping
328 
329  //- Map field from tgt to src mesh with defined operation
330  // Values passed in via 'result' are used to initialise the
331  // return value
332  template<class Type>
333  void mapTgtToSrc
334  (
335  const UList<Type>& tgtFld,
336  List<Type>& result
337  ) const;
338 
339  //- Return the tgt field mapped to the src mesh with a defined
340  // operation. Initial values of the result are set to zero
341  template<class Type>
343  (
344  const Field<Type>& tgtFld
345  ) const;
346 
347  //- Convenience function to map a tmp field to the src mesh
348  // with a defined operation
349  template<class Type>
351  (
352  const tmp<Field<Type>>& ttgtFld
353  ) const;
354 
355 
356  // Source-to-target volume field mapping
357 
358  //- Interpolate a field with a defined operation. Values
359  // passed in via 'result' are used to initialise the return
360  // value
361  template<class Type>
362  void mapSrcToTgt
363  (
366  ) const;
367 
368  //- Interpolate a field with a defined operation. The initial
369  // values of the result are set to zero
370  template<class Type>
372  (
374  ) const;
375 
376  //- Interpolate a tmp field with a defined operation. The
377  // initial values of the result are set to zero
378  template<class Type>
380  (
382  tfield
383  ) const;
384 
385 
386  // Target-to-source volume field mapping
387 
388  //- Interpolate a field with a defined operation. Values
389  // passed in via 'result' are used to initialise the return
390  // value
391  template<class Type>
392  void mapTgtToSrc
393  (
396  ) const;
397 
398  //- Interpolate a field with a defined operation. The initial
399  // values of the result are set to zero
400  template<class Type>
402  (
404  ) const;
405 
406  //- Interpolate a tmp field with a defined operation. The
407  // initial values of the result are set to zero
408  template<class Type>
410  (
412  tfield
413  ) const;
414 
415 
416  // Member Operators
417 
418  //- Disallow default bitwise assignment
419  void operator=(const meshToMesh&) = delete;
420 };
421 
422 
423 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
424 
425 // Disable fvPatchField value override after rmap
426 
427 template<>
428 void meshToMesh::mapAndOpSrcToTgt
429 (
430  const AMIInterpolation& AMI,
431  const Field<scalar>& srcField,
432  Field<scalar>& tgtField
433 ) const;
434 template<>
435 void meshToMesh::mapAndOpSrcToTgt
436 (
437  const AMIInterpolation& AMI,
438  const Field<vector>& srcField,
439  Field<vector>& tgtField
440 ) const;
441 template<>
442 void meshToMesh::mapAndOpSrcToTgt
443 (
444  const AMIInterpolation& AMI,
445  const Field<sphericalTensor>& srcField,
446  Field<sphericalTensor>& tgtField
447 ) const;
448 template<>
449 void meshToMesh::mapAndOpSrcToTgt
450 (
451  const AMIInterpolation& AMI,
452  const Field<symmTensor>& srcField,
453  Field<symmTensor>& tgtField
454 ) const;
455 template<>
456 void meshToMesh::mapAndOpSrcToTgt
457 (
458  const AMIInterpolation& AMI,
459  const Field<tensor>& srcField,
460  Field<tensor>& tgtField
461 ) const;
462 
463 
464 template<>
465 void meshToMesh::mapAndOpTgtToSrc
466 (
467  const AMIInterpolation& AMI,
468  Field<scalar>& srcField,
469  const Field<scalar>& tgtField
470 ) const;
471 template<>
472 void meshToMesh::mapAndOpTgtToSrc
473 (
474  const AMIInterpolation& AMI,
475  Field<vector>& srcField,
476  const Field<vector>& tgtField
477 ) const;
478 template<>
479 void meshToMesh::mapAndOpTgtToSrc
480 (
481  const AMIInterpolation& AMI,
482  Field<sphericalTensor>& srcField,
483  const Field<sphericalTensor>& tgtField
484 ) const;
485 template<>
486 void meshToMesh::mapAndOpTgtToSrc
487 (
488  const AMIInterpolation& AMI,
489  Field<symmTensor>& srcField,
490  const Field<symmTensor>& tgtField
491 ) const;
492 template<>
493 void meshToMesh::mapAndOpTgtToSrc
494 (
495  const AMIInterpolation& AMI,
496  Field<tensor>& srcField,
497  const Field<tensor>& tgtField
498 ) const;
499 
500 } // End namespace Foam
501 
502 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
503 
504 #include "meshToMeshI.H"
505 
506 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
507 
508 #ifdef NoRepository
509  #include "meshToMeshTemplates.C"
510 #endif
511 
512 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
513 
514 #endif
515 
516 // ************************************************************************* //
const polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:30
A bounding box defined in terms of the points at its extremities.
Definition: boundBox.H:58
Generic GeometricField class.
Class to calculate the cell-addressing between two overlapping meshes.
Definition: meshToMesh.H:60
void mapSrcToTgt(const UList< Type > &srcFld, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
const labelListList & srcToTgtCellAddr() const
Return const access to the source to target cell addressing.
Definition: meshToMeshI.H:43
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
const pointField & points
Pre-declare SubField and related Field type.
Definition: Field.H:56
A class for handling words, derived from string.
Definition: word.H:59
scalar V() const
Return const access to the overlap volume.
Definition: meshToMeshI.H:70
void operator=(const meshToMesh &)=delete
Disallow default bitwise assignment.
An STL-conforming hash table.
Definition: HashTable.H:61
TypeName("meshToMesh")
Run-time type information.
meshToMesh(const polyMesh &src, const polyMesh &tgt, const word &methodName, const bool interpAllPatches=true)
Construct from source and target meshes, generic mapping methods.
Definition: meshToMesh.C:585
const labelListList & tgtToSrcCellAddr() const
Return const access to the target to source cell addressing.
Definition: meshToMeshI.H:50
Class containing processor-to-processor mapping information.
virtual ~meshToMesh()
Destructor.
Definition: meshToMesh.C:646
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: List.H:70
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const scalarListList & srcToTgtCellWght() const
Return const access to the source to target cell weights.
Definition: meshToMeshI.H:57
void mapTgtToSrc(const UList< Type > &tgtFld, List< Type > &result) const
Map field from tgt to src mesh with defined operation.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:76
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
const polyMesh & tgtRegion() const
Return const access to the target mesh.
Definition: meshToMeshI.H:36
Namespace for OpenFOAM.
const scalarListList & tgtToSrcCellWght() const
Return const access to the target to source cell weights.
Definition: meshToMeshI.H:64