All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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 "mapDistribute.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 public:
64 
65  // Public data types
66 
67  //- Enumeration specifying interpolation method
69  {
73  };
74 
77 
78 private:
79 
80  // Private Data
81 
82  //- Reference to the source mesh
83  const polyMesh& srcRegion_;
84 
85  //- Reference to the target mesh
86  const polyMesh& tgtRegion_;
87 
88  //- List of target patch IDs per source patch (local index)
89  List<label> srcPatchID_;
90 
91  //- List of source patch IDs per target patch (local index)
92  List<label> tgtPatchID_;
93 
94  //- List of AMIs between source and target patches
95  PtrList<AMIInterpolation> patchAMIs_;
96 
97  //- Cutting patches whose values are set using a zero-gradient condition
98  List<label> cuttingPatches_;
99 
100  //- Source to target cell addressing
101  labelListList srcToTgtCellAddr_;
102 
103  //- Target to source cell addressing
104  labelListList tgtToSrcCellAddr_;
105 
106  //- Source to target cell interpolation weights
107  scalarListList srcToTgtCellWght_;
108 
109  //- Target to source cell interpolation weights
110  scalarListList tgtToSrcCellWght_;
111 
112  //- Cell total volume in overlap region [m^3]
113  scalar V_;
114 
115  //- Index of processor that holds all of both sides. -1 in all other
116  // cases
117  label singleMeshProc_;
118 
119  //- Source map pointer - parallel running only
120  autoPtr<mapDistribute> srcMapPtr_;
121 
122  //- Target map pointer - parallel running only
123  autoPtr<mapDistribute> tgtMapPtr_;
124 
125 
126  // Private Member Functions
127 
128  //- Helper function to add a constant offset to a list
129  template<class Type>
130  void add(UList<Type>& fld, const label offset) const;
131 
132  //- Helper function to interpolate patch field. Template
133  // specialisations below
134  template<class Type, class CombineOp>
135  void mapAndOpSrcToTgt
136  (
137  const AMIInterpolation& AMI,
138  const Field<Type>& srcField,
139  Field<Type>& tgtField,
140  const CombineOp& cop
141  ) const;
142 
143  //- Helper function to interpolate patch field. Template
144  // specialisations below
145  template<class Type, class CombineOp>
146  void mapAndOpTgtToSrc
147  (
148  const AMIInterpolation& AMI,
149  Field<Type>& srcField,
150  const Field<Type>& tgtField,
151  const CombineOp& cop
152  ) const;
153 
154  //- Return src cell IDs for the overlap region
155  labelList maskCells(const polyMesh& src, const polyMesh& tgt) const;
156 
157  //- Normalise the interpolation weights
158  void normaliseWeights
159  (
160  const word& descriptor,
161  const labelListList& addr,
162  scalarListList& wght
163  ) const;
164 
165  //- Calculate the addressing between overlapping regions of src and tgt
166  // meshes
167  void calcAddressing
168  (
169  const word& methodName,
170  const polyMesh& src,
171  const polyMesh& tgt
172  );
173 
174  //- Calculate - main driver function
175  void calculate(const word& methodName);
176 
177  //- Calculate patch overlap
178  void calculatePatchAMIs(const word& amiMethodName);
179 
180  //- Constructor helper
181  void constructNoCuttingPatches
182  (
183  const word& methodName,
184  const word& AMIMethodName,
185  const bool interpAllPatches
186  );
187 
188  //- Constructor helper
189  void constructFromCuttingPatches
190  (
191  const word& methodName,
192  const word& AMIMethodName,
193  const HashTable<word>& patchMap,
194  const wordList& cuttingPatches
195  );
196 
197  //- Return the list of AMIs between source and target patches
198  inline const PtrList<AMIInterpolation>&
199  patchAMIs() const;
200 
201 
202  // Parallel operations
203 
204  //- Determine whether the meshes are split across multiple pocessors
205  label calcDistribution
206  (
207  const polyMesh& src,
208  const polyMesh& tgt
209  ) const;
210 
211  //- Determine which processor bounding-boxes overlap
212  label calcOverlappingProcs
213  (
214  const List<boundBox>& procBb,
215  const boundBox& bb,
216  boolList& overlaps
217  ) const;
218 
219  //- Calculate the mapping between processors
220  autoPtr<mapDistribute> calcProcMap
221  (
222  const polyMesh& src,
223  const polyMesh& tgt
224  ) const;
225 
226  //- Distribute mesh info from 'my' processor to others
227  void distributeCells
228  (
229  const mapDistribute& map,
230  const polyMesh& tgtMesh,
231  const globalIndex& globalI,
233  List<label>& nInternalFaces,
234  List<faceList>& faces,
235  List<labelList>& faceOwner,
236  List<labelList>& faceNeighbour,
237  List<labelList>& cellIDs,
238  List<labelList>& nbrProcIDs,
239  List<labelList>& procLocalFaceIDs
240  ) const;
241 
242  //- Collect pieces of tgt mesh from other processors and restructure
243  void distributeAndMergeCells
244  (
245  const mapDistribute& map,
246  const polyMesh& tgt,
247  const globalIndex& globalI,
248  pointField& tgtPoints,
249  faceList& tgtFaces,
250  labelList& tgtFaceOwners,
251  labelList& tgtFaceNeighbours,
252  labelList& tgtCellIDs
253  ) const;
254 
255 
256 public:
257 
258  //- Run-time type information
259  TypeName("meshToMesh");
260 
261  // Constructors
262 
263  //- Construct from source and target meshes
264  meshToMesh
265  (
266  const polyMesh& src,
267  const polyMesh& tgt,
268  const interpolationMethod& method,
269  const bool interpAllPatches = true
270  );
271 
272  //- Construct from source and target meshes, generic mapping methods
273  meshToMesh
274  (
275  const polyMesh& src,
276  const polyMesh& tgt,
277  const word& methodName, // internal mapping
278  const word& AMIMethodName, // boundary mapping
279  const bool interpAllPatches = true
280  );
281 
282  //- Construct from source and target meshes
283  meshToMesh
284  (
285  const polyMesh& src,
286  const polyMesh& tgt,
287  const interpolationMethod& method,
288  const HashTable<word>& patchMap,
289  const wordList& cuttingPatches
290  );
291 
292  //- Construct from source and target meshes, generic mapping methods
293  meshToMesh
294  (
295  const polyMesh& src,
296  const polyMesh& tgt,
297  const word& methodName, // internal mapping
298  const word& AMIMethodName, // boundary mapping
299  const HashTable<word>& patchMap,
300  const wordList& cuttingPatches
301  );
302 
303  //- Disallow default bitwise copy construction
304  meshToMesh(const meshToMesh&) = delete;
305 
306 
307  //- Destructor
308  virtual ~meshToMesh();
309 
310 
311  // Member Functions
312 
313  // Access
314 
315  //- Return const access to the source mesh
316  inline const polyMesh& srcRegion() const;
317 
318  //- Return const access to the target mesh
319  inline const polyMesh& tgtRegion() const;
320 
321  //- Return const access to the source to target cell addressing
322  inline const labelListList& srcToTgtCellAddr() const;
323 
324  //- Return const access to the target to source cell addressing
325  inline const labelListList& tgtToSrcCellAddr() const;
326 
327  //- Return const access to the source to target cell weights
328  inline const scalarListList& srcToTgtCellWght() const;
329 
330  //- Return const access to the target to source cell weights
331  inline const scalarListList& tgtToSrcCellWght() const;
332 
333  //- Return const access to the overlap volume
334  inline scalar V() const;
335 
336  //- Conversion between mesh and patch interpolation methods
339 
340 
341  // Evaluation
342 
343  // Source-to-target field mapping
344 
345  //- Map field from src to tgt mesh with defined operation
346  // Values passed in via 'result' are used to initialise the
347  // return value
348  template<class Type, class CombineOp>
349  void mapSrcToTgt
350  (
351  const UList<Type>& srcFld,
352  const CombineOp& cop,
353  List<Type>& result
354  ) const;
355 
356  //- Return the src field mapped to the tgt mesh with a defined
357  // operation. Initial values of the result are set to zero
358  template<class Type, class CombineOp>
360  (
361  const Field<Type>& srcFld,
362  const CombineOp& cop
363  ) const;
364 
365  //- Convenience function to map a tmp field to the tgt mesh
366  // with a defined operation
367  template<class Type, class CombineOp>
369  (
370  const tmp<Field<Type>>& tsrcFld,
371  const CombineOp& cop
372  ) const;
373 
374  //- Convenience function to map a field to the tgt mesh with a
375  // default operation (plusEqOp)
376  template<class Type>
378  (
379  const Field<Type>& srcFld
380  ) const;
381 
382  //- Convenience function to map a tmp field to the tgt mesh
383  // with a default operation (plusEqOp)
384  template<class Type>
386  (
387  const tmp<Field<Type>>& tsrcFld
388  ) const;
389 
390 
391  // Target-to-source field mapping
392 
393  //- Map field from tgt to src mesh with defined operation
394  // Values passed in via 'result' are used to initialise the
395  // return value
396  template<class Type, class CombineOp>
397  void mapTgtToSrc
398  (
399  const UList<Type>& tgtFld,
400  const CombineOp& cop,
401  List<Type>& result
402  ) const;
403 
404  //- Return the tgt field mapped to the src mesh with a defined
405  // operation. Initial values of the result are set to zero
406  template<class Type, class CombineOp>
408  (
409  const Field<Type>& tgtFld,
410  const CombineOp& cop
411  ) const;
412 
413  //- Convenience function to map a tmp field to the src mesh
414  // with a defined operation
415  template<class Type, class CombineOp>
417  (
418  const tmp<Field<Type>>& ttgtFld,
419  const CombineOp& cop
420  ) const;
421 
422  //- Convenience function to map a field to the src mesh with a
423  // default operation (plusEqOp)
424  template<class Type>
426  (
427  const Field<Type>& tgtFld
428  ) const;
429 
430  //- Convenience function to map a tmp field to the src mesh
431  // with a default operation (plusEqOp)
432  template<class Type>
434  (
435  const tmp<Field<Type>>& ttgtFld
436  ) const;
437 
438 
439  // Source-to-target volume field mapping
440 
441  //- Interpolate a field with a defined operation. Values
442  // passed in via 'result' are used to initialise the return
443  // value
444  template<class Type, class CombineOp>
445  void mapSrcToTgt
446  (
448  const CombineOp& cop,
450  ) const;
451 
452  //- Interpolate a field with a defined operation. The initial
453  // values of the result are set to zero
454  template<class Type, class CombineOp>
456  (
458  const CombineOp& cop
459  ) const;
460 
461  //- Interpolate a tmp field with a defined operation. The
462  // initial values of the result are set to zero
463  template<class Type, class CombineOp>
465  (
467  tfield,
468  const CombineOp& cop
469  ) const;
470 
471  //- Convenience function to map a field with a default
472  // operation (plusEqOp)
473  template<class Type>
475  (
477  ) const;
478 
479  //- Convenience function to map a tmp field with a default
480  // operation (plusEqOp)
481  template<class Type>
483  (
485  tfield
486  ) const;
487 
488 
489  // Target-to-source volume field mapping
490 
491  //- Interpolate a field with a defined operation. Values
492  // passed in via 'result' are used to initialise the return
493  // value
494  template<class Type, class CombineOp>
495  void mapTgtToSrc
496  (
498  const CombineOp& cop,
500  ) const;
501 
502  //- Interpolate a field with a defined operation. The initial
503  // values of the result are set to zero
504  template<class Type, class CombineOp>
506  (
508  const CombineOp& cop
509  ) const;
510 
511  //- Interpolate a tmp field with a defined operation. The
512  // initial values of the result are set to zero
513  template<class Type, class CombineOp>
515  (
517  tfield,
518  const CombineOp& cop
519  ) const;
520 
521  //- Convenience function to map a field with a default
522  // operation (plusEqOp)
523  template<class Type>
525  (
527  ) const;
528 
529  //- Convenience function to map a tmp field with a default
530  // operation (plusEqOp)
531  template<class Type>
533  (
535  tfield
536  ) const;
537 
538 
539  // Member Operators
540 
541  //- Disallow default bitwise assignment
542  void operator=(const meshToMesh&) = delete;
543 };
544 
545 
546 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
547 
548 // Disable fvPatchField value override after rmap
549 
550 template<>
551 void meshToMesh::mapAndOpSrcToTgt
552 (
553  const AMIInterpolation& AMI,
554  const Field<scalar>& srcField,
555  Field<scalar>& tgtField,
556  const plusEqOp<scalar>& cop
557 ) const;
558 template<>
559 void meshToMesh::mapAndOpSrcToTgt
560 (
561  const AMIInterpolation& AMI,
562  const Field<vector>& srcField,
563  Field<vector>& tgtField,
564  const plusEqOp<vector>& cop
565 ) const;
566 template<>
567 void meshToMesh::mapAndOpSrcToTgt
568 (
569  const AMIInterpolation& AMI,
570  const Field<sphericalTensor>& srcField,
571  Field<sphericalTensor>& tgtField,
572  const plusEqOp<sphericalTensor>& cop
573 ) const;
574 template<>
575 void meshToMesh::mapAndOpSrcToTgt
576 (
577  const AMIInterpolation& AMI,
578  const Field<symmTensor>& srcField,
579  Field<symmTensor>& tgtField,
580  const plusEqOp<symmTensor>& cop
581 ) const;
582 template<>
583 void meshToMesh::mapAndOpSrcToTgt
584 (
585  const AMIInterpolation& AMI,
586  const Field<tensor>& srcField,
587  Field<tensor>& tgtField,
588  const plusEqOp<tensor>& cop
589 ) const;
590 
591 
592 template<>
593 void meshToMesh::mapAndOpTgtToSrc
594 (
595  const AMIInterpolation& AMI,
596  Field<scalar>& srcField,
597  const Field<scalar>& tgtField,
598  const plusEqOp<scalar>& cop
599 ) const;
600 template<>
601 void meshToMesh::mapAndOpTgtToSrc
602 (
603  const AMIInterpolation& AMI,
604  Field<vector>& srcField,
605  const Field<vector>& tgtField,
606  const plusEqOp<vector>& cop
607 ) const;
608 template<>
609 void meshToMesh::mapAndOpTgtToSrc
610 (
611  const AMIInterpolation& AMI,
612  Field<sphericalTensor>& srcField,
613  const Field<sphericalTensor>& tgtField,
614  const plusEqOp<sphericalTensor>& cop
615 ) const;
616 template<>
617 void meshToMesh::mapAndOpTgtToSrc
618 (
619  const AMIInterpolation& AMI,
620  Field<symmTensor>& srcField,
621  const Field<symmTensor>& tgtField,
622  const plusEqOp<symmTensor>& cop
623 ) const;
624 template<>
625 void meshToMesh::mapAndOpTgtToSrc
626 (
627  const AMIInterpolation& AMI,
628  Field<tensor>& srcField,
629  const Field<tensor>& tgtField,
630  const plusEqOp<tensor>& cop
631 ) const;
632 
633 } // End namespace Foam
634 
635 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
636 
637 #include "meshToMeshI.H"
638 
639 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
640 
641 #ifdef NoRepository
642  #include "meshToMeshTemplates.C"
643 #endif
644 
645 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
646 
647 #endif
648 
649 // ************************************************************************* //
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 polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:30
static const NamedEnum< interpolationMethod, 3 > interpolationMethodNames_
Definition: meshToMesh.H:75
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
interpolationMethod
Enumeration specifying interpolation method.
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
static AMIInterpolation::interpolationMethod interpolationMethodAMI(const interpolationMethod method)
Conversion between mesh and patch interpolation methods.
Definition: meshToMesh.C:462
TypeName("meshToMesh")
Run-time type information.
const labelListList & tgtToSrcCellAddr() const
Return const access to the target to source cell addressing.
Definition: meshToMeshI.H:50
meshToMesh(const polyMesh &src, const polyMesh &tgt, const interpolationMethod &method, const bool interpAllPatches=true)
Construct from source and target meshes.
Definition: meshToMesh.C:637
Class containing processor-to-processor mapping information.
virtual ~meshToMesh()
Destructor.
Definition: meshToMesh.C:773
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
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:74
interpolationMethod
Enumeration specifying interpolation method.
Definition: meshToMesh.H:67
rDeltaTY field()
A class for managing temporary objects.
Definition: PtrList.H:53
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
const polyMesh & tgtRegion() const
Return const access to the target mesh.
Definition: meshToMeshI.H:36
Namespace for OpenFOAM.
void mapTgtToSrc(const UList< Type > &tgtFld, const CombineOp &cop, List< Type > &result) const
Map field from tgt to src mesh with defined operation.
const scalarListList & tgtToSrcCellWght() const
Return const access to the target to source cell weights.
Definition: meshToMeshI.H:64