meshToMesh.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 2012-2016 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"
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
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 interplation weights
107  scalarListList srcToTgtCellWght_;
108 
109  //- Target to source cell interpolation weights
110  scalarListList tgtToSrcCellWght_;
111 
112  //- Cell total volume in overlap region [m3]
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 AMIPatchToPatchInterpolation& 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 AMIPatchToPatchInterpolation& 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
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 procssors 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  //- Disallow default bitwise copy construct
257  meshToMesh(const meshToMesh&);
258 
259  //- Disallow default bitwise assignment
260  void operator=(const meshToMesh&);
261 
262 
263 public:
264 
265  //- Run-time type information
266  TypeName("meshToMesh");
267 
268 
269  //- Construct from source and target meshes
270  meshToMesh
271  (
272  const polyMesh& src,
273  const polyMesh& tgt,
274  const interpolationMethod& method,
275  const bool interpAllPatches = true
276  );
277 
278  //- Construct from source and target meshes, generic mapping methods
279  meshToMesh
280  (
281  const polyMesh& src,
282  const polyMesh& tgt,
283  const word& methodName, // internal mapping
284  const word& AMIMethodName, // boundary mapping
285  const bool interpAllPatches = true
286  );
287 
288  //- Construct from source and target meshes
289  meshToMesh
290  (
291  const polyMesh& src,
292  const polyMesh& tgt,
293  const interpolationMethod& method,
294  const HashTable<word>& patchMap,
295  const wordList& cuttingPatches
296  );
297 
298 
299  //- Construct from source and target meshes, generic mapping methods
300  meshToMesh
301  (
302  const polyMesh& src,
303  const polyMesh& tgt,
304  const word& methodName, // internal mapping
305  const word& AMIMethodName, // boundary mapping
306  const HashTable<word>& patchMap,
307  const wordList& cuttingPatches
308  );
309 
310 
311  //- Destructor
312  virtual ~meshToMesh();
313 
314 
315  // Member Functions
316 
317  // Access
318 
319  //- Return const access to the source mesh
320  inline const polyMesh& srcRegion() const;
321 
322  //- Return const access to the target mesh
323  inline const polyMesh& tgtRegion() const;
324 
325  //- Return const access to the source to target cell addressing
326  inline const labelListList& srcToTgtCellAddr() const;
327 
328  //- Return const access to the target to source cell addressing
329  inline const labelListList& tgtToSrcCellAddr() const;
330 
331  //- Return const access to the source to target cell weights
332  inline const scalarListList& srcToTgtCellWght() const;
333 
334  //- Return const access to the target to source cell weights
335  inline const scalarListList& tgtToSrcCellWght() const;
336 
337  //- Return const access to the overlap volume
338  inline scalar V() const;
339 
340  //- Conversion between mesh and patch interpolation methods
343  (
344  const interpolationMethod method
345  );
346 
347 
348  // Evaluation
349 
350  // Source-to-target field mapping
351 
352  //- Map field from src to tgt mesh with defined operation
353  // Values passed in via 'result' are used to initialise the
354  // return value
355  template<class Type, class CombineOp>
356  void mapSrcToTgt
357  (
358  const UList<Type>& srcFld,
359  const CombineOp& cop,
360  List<Type>& result
361  ) const;
362 
363  //- Return the src field mapped to the tgt mesh with a defined
364  // operation. Initial values of the result are set to zero
365  template<class Type, class CombineOp>
367  (
368  const Field<Type>& srcFld,
369  const CombineOp& cop
370  ) const;
371 
372  //- Convenience function to map a tmp field to the tgt mesh
373  // with a defined operation
374  template<class Type, class CombineOp>
376  (
377  const tmp<Field<Type>>& tsrcFld,
378  const CombineOp& cop
379  ) const;
380 
381  //- Convenience function to map a field to the tgt mesh with a
382  // default operation (plusEqOp)
383  template<class Type>
385  (
386  const Field<Type>& srcFld
387  ) const;
388 
389  //- Convenience function to map a tmp field to the tgt mesh
390  // with a default operation (plusEqOp)
391  template<class Type>
393  (
394  const tmp<Field<Type>>& tsrcFld
395  ) const;
396 
397 
398  // Target-to-source field mapping
399 
400  //- Map field from tgt to src mesh with defined operation
401  // Values passed in via 'result' are used to initialise the
402  // return value
403  template<class Type, class CombineOp>
404  void mapTgtToSrc
405  (
406  const UList<Type>& tgtFld,
407  const CombineOp& cop,
408  List<Type>& result
409  ) const;
410 
411  //- Return the tgt field mapped to the src mesh with a defined
412  // operation. Initial values of the result are set to zero
413  template<class Type, class CombineOp>
415  (
416  const Field<Type>& tgtFld,
417  const CombineOp& cop
418  ) const;
419 
420  //- Convenience function to map a tmp field to the src mesh
421  // with a defined operation
422  template<class Type, class CombineOp>
424  (
425  const tmp<Field<Type>>& ttgtFld,
426  const CombineOp& cop
427  ) const;
428 
429  //- Convenience function to map a field to the src mesh with a
430  // default operation (plusEqOp)
431  template<class Type>
433  (
434  const Field<Type>& tgtFld
435  ) const;
436 
437  //- Convenience function to map a tmp field to the src mesh
438  // with a default operation (plusEqOp)
439  template<class Type>
441  (
442  const tmp<Field<Type>>& ttgtFld
443  ) const;
444 
445 
446  // Source-to-target volume field mapping
447 
448  //- Interpolate a field with a defined operation. Values
449  // passed in via 'result' are used to initialise the return
450  // value
451  template<class Type, class CombineOp>
452  void mapSrcToTgt
453  (
455  const CombineOp& cop,
457  ) const;
458 
459  //- Interpolate a field with a defined operation. The initial
460  // values of the result are set to zero
461  template<class Type, class CombineOp>
463  (
465  const CombineOp& cop
466  ) const;
467 
468  //- Interpolate a tmp field with a defined operation. The
469  // initial values of the result are set to zero
470  template<class Type, class CombineOp>
472  (
474  tfield,
475  const CombineOp& cop
476  ) const;
477 
478  //- Convenience function to map a field with a default
479  // operation (plusEqOp)
480  template<class Type>
482  (
484  ) const;
485 
486  //- Convenience function to map a tmp field with a default
487  // operation (plusEqOp)
488  template<class Type>
490  (
492  tfield
493  ) const;
494 
495 
496  // Target-to-source volume field mapping
497 
498  //- Interpolate a field with a defined operation. Values
499  // passed in via 'result' are used to initialise the return
500  // value
501  template<class Type, class CombineOp>
502  void mapTgtToSrc
503  (
505  const CombineOp& cop,
507  ) const;
508 
509  //- Interpolate a field with a defined operation. The initial
510  // values of the result are set to zero
511  template<class Type, class CombineOp>
513  (
515  const CombineOp& cop
516  ) const;
517 
518  //- Interpolate a tmp field with a defined operation. The
519  // initial values of the result are set to zero
520  template<class Type, class CombineOp>
522  (
524  tfield,
525  const CombineOp& cop
526  ) const;
527 
528  //- Convenience function to map a field with a default
529  // operation (plusEqOp)
530  template<class Type>
532  (
534  ) const;
535 
536  //- Convenience function to map a tmp field with a default
537  // operation (plusEqOp)
538  template<class Type>
540  (
542  tfield
543  ) const;
544 };
545 
546 
547 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
548 
549 // Disable fvPatchField value override after rmap
550 
551 template<>
552 void meshToMesh::mapAndOpSrcToTgt
553 (
554  const AMIPatchToPatchInterpolation& AMI,
555  const Field<scalar>& srcField,
556  Field<scalar>& tgtField,
557  const plusEqOp<scalar>& cop
558 ) const;
559 template<>
560 void meshToMesh::mapAndOpSrcToTgt
561 (
562  const AMIPatchToPatchInterpolation& AMI,
563  const Field<vector>& srcField,
564  Field<vector>& tgtField,
565  const plusEqOp<vector>& cop
566 ) const;
567 template<>
568 void meshToMesh::mapAndOpSrcToTgt
569 (
570  const AMIPatchToPatchInterpolation& AMI,
571  const Field<sphericalTensor>& srcField,
572  Field<sphericalTensor>& tgtField,
573  const plusEqOp<sphericalTensor>& cop
574 ) const;
575 template<>
576 void meshToMesh::mapAndOpSrcToTgt
577 (
578  const AMIPatchToPatchInterpolation& AMI,
579  const Field<symmTensor>& srcField,
580  Field<symmTensor>& tgtField,
581  const plusEqOp<symmTensor>& cop
582 ) const;
583 template<>
584 void meshToMesh::mapAndOpSrcToTgt
585 (
586  const AMIPatchToPatchInterpolation& AMI,
587  const Field<tensor>& srcField,
588  Field<tensor>& tgtField,
589  const plusEqOp<tensor>& cop
590 ) const;
591 
592 
593 template<>
594 void meshToMesh::mapAndOpTgtToSrc
595 (
596  const AMIPatchToPatchInterpolation& AMI,
597  Field<scalar>& srcField,
598  const Field<scalar>& tgtField,
599  const plusEqOp<scalar>& cop
600 ) const;
601 template<>
602 void meshToMesh::mapAndOpTgtToSrc
603 (
604  const AMIPatchToPatchInterpolation& AMI,
605  Field<vector>& srcField,
606  const Field<vector>& tgtField,
607  const plusEqOp<vector>& cop
608 ) const;
609 template<>
610 void meshToMesh::mapAndOpTgtToSrc
611 (
612  const AMIPatchToPatchInterpolation& AMI,
613  Field<sphericalTensor>& srcField,
614  const Field<sphericalTensor>& tgtField,
615  const plusEqOp<sphericalTensor>& cop
616 ) const;
617 template<>
618 void meshToMesh::mapAndOpTgtToSrc
619 (
620  const AMIPatchToPatchInterpolation& AMI,
621  Field<symmTensor>& srcField,
622  const Field<symmTensor>& tgtField,
623  const plusEqOp<symmTensor>& cop
624 ) const;
625 template<>
626 void meshToMesh::mapAndOpTgtToSrc
627 (
628  const AMIPatchToPatchInterpolation& AMI,
629  Field<tensor>& srcField,
630  const Field<tensor>& tgtField,
631  const plusEqOp<tensor>& cop
632 ) const;
633 
634 } // End namespace Foam
635 
636 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
637 
638 #include "meshToMeshI.H"
639 
640 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
641 
642 #ifdef NoRepository
643  #include "meshToMeshTemplates.C"
644 #endif
645 
646 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
647 
648 #endif
649 
650 // ************************************************************************* //
const labelListList & tgtToSrcCellAddr() const
Return const access to the target to source cell addressing.
Definition: meshToMeshI.H:50
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
static const NamedEnum< interpolationMethod, 3 > interpolationMethodNames_
Definition: meshToMesh.H:75
const labelListList & srcToTgtCellAddr() const
Return const access to the source to target cell addressing.
Definition: meshToMeshI.H:43
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
const scalarListList & srcToTgtCellWght() const
Return const access to the source to target cell weights.
Definition: meshToMeshI.H:57
interpolationMethod
Enumeration specifying interpolation method.
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:57
A class for handling words, derived from string.
Definition: word.H:59
void mapSrcToTgt(const UList< Type > &srcFld, const CombineOp &cop, List< Type > &result) const
Map field from src to tgt mesh with defined operation.
An STL-conforming hash table.
Definition: HashTable.H:61
const polyMesh & srcRegion() const
Return const access to the source mesh.
Definition: meshToMeshI.H:30
scalar V() const
Return const access to the overlap volume.
Definition: meshToMeshI.H:70
TypeName("meshToMesh")
Run-time type information.
Class containing processor-to-processor mapping information.
const polyMesh & tgtRegion() const
Return const access to the target mesh.
Definition: meshToMeshI.H:36
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:62
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
const scalarListList & tgtToSrcCellWght() const
Return const access to the target to source cell weights.
Definition: meshToMeshI.H:64
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:74
interpolationMethod
Enumeration specifying interpolation method.
Definition: meshToMesh.H:67
A class for managing temporary objects.
Definition: PtrList.H:54
void mapTgtToSrc(const UList< Type > &tgtFld, const CombineOp &cop, List< Type > &result) const
Map field from tgt to src mesh with defined operation.
static AMIPatchToPatchInterpolation::interpolationMethod interpolationMethodAMI(const interpolationMethod method)
Conversion between mesh and patch interpolation methods.
Definition: meshToMesh.C:462
Namespace for OpenFOAM.