All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AMIInterpolation.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) 2011-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::AMIInterpolation
26 
27 Description
28  Interpolation class dealing with transfer of data between two
29  primitive patches with an arbitrary mesh interface (AMI).
30 
31  Based on the algorithm given in:
32 
33  Conservative interpolation between volume meshes by local Galerkin
34  projection, Farrell PE and Maddison JR, 2011, Comput. Methods Appl.
35  Mech Engrg, Volume 200, Issues 1-4, pp 89-100
36 
37  Interpolation requires that the two patches should have opposite
38  orientations (opposite normals). The 'reverseTarget' flag can be used to
39  reverse the orientation of the target patch.
40 
41 
42 SourceFiles
43  AMIInterpolation.C
44  AMIInterpolationParallelOps.C
45  AMIInterpolationTemplates.C
46 
47 \*---------------------------------------------------------------------------*/
48 
49 #ifndef AMIInterpolation_H
50 #define AMIInterpolation_H
51 
52 #include "className.H"
53 #include "searchableSurface.H"
54 #include "treeBoundBoxList.H"
55 #include "boolList.H"
56 #include "primitivePatch.H"
57 #include "faceAreaIntersect.H"
58 #include "globalIndex.H"
59 #include "ops.H"
60 
61 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
62 
63 namespace Foam
64 {
65 
66 /*---------------------------------------------------------------------------*\
67  Class AMIInterpolation Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 class AMIInterpolation
71 {
72 public:
73 
74  // Public data types
75 
76  //- Enumeration specifying interpolation method
78  {
84  };
85 
86  //- Convert interpolationMethod to word representation
88  (
89  const interpolationMethod& method
90  );
91 
92  //- Convert word to interpolationMethod
94  (
95  const word& method
96  );
97 
98  //- Calculate the patch face magnitudes for the given tri-mode
100  (
101  const primitivePatch& patch,
103  );
104 
105 
106 private:
107 
108  // Private Data
109 
110  //- Interpolation method
111  const word methodName_;
112 
113  //- Flag to indicate that the two patches are co-directional and
114  // that the orientation of the target patch should be reversed
115  const bool reverseTarget_;
116 
117  //- Flag to indicate that the two patches must be matched/an overlap
118  // exists between them
119  const bool requireMatch_;
120 
121  //- Index of processor that holds all of both sides. -1 in all other
122  // cases
123  label singlePatchProc_;
124 
125  //- Threshold weight below which interpolation is deactivated
126  scalar lowWeightCorrection_;
127 
128 
129  // Source patch
130 
131  //- Source face areas
132  scalarField srcMagSf_;
133 
134  //- Addresses of target faces per source face
135  labelListList srcAddress_;
136 
137  //- Weights of target faces per source face
138  scalarListList srcWeights_;
139 
140  //- Sum of weights of target faces per source face
141  scalarField srcWeightsSum_;
142 
143 
144  // Target patch
145 
146  //- Target face areas
147  scalarField tgtMagSf_;
148 
149  //- Addresses of source faces per target face
150  labelListList tgtAddress_;
151 
152  //- Weights of source faces per target face
153  scalarListList tgtWeights_;
154 
155  //- Sum of weights of source faces per target face
156  scalarField tgtWeightsSum_;
157 
158 
159  //- Face triangulation mode
161 
162  //- Source map pointer - parallel running only
163  autoPtr<mapDistribute> srcMapPtr_;
164 
165  //- Target map pointer - parallel running only
166  autoPtr<mapDistribute> tgtMapPtr_;
167 
168 
169  // Parallel functionality
170 
171  //- Calculate if patches are on multiple processors
172  label calcDistribution
173  (
174  const primitivePatch& srcPatch,
175  const primitivePatch& tgtPatch
176  ) const;
177 
178  label calcOverlappingProcs
179  (
180  const List<treeBoundBoxList>& procBb,
181  const treeBoundBox& bb,
182  boolList& overlaps
183  ) const;
184 
185  void distributePatches
186  (
187  const mapDistribute& map,
188  const primitivePatch& pp,
189  const globalIndex& gi,
190  List<faceList>& faces,
192  List<labelList>& tgtFaceIDs
193  ) const;
194 
195  void distributeAndMergePatches
196  (
197  const mapDistribute& map,
198  const primitivePatch& tgtPatch,
199  const globalIndex& gi,
200  faceList& tgtFaces,
201  pointField& tgtPoints,
202  labelList& tgtFaceIDs
203  ) const;
204 
205  autoPtr<mapDistribute> calcProcMap
206  (
207  const primitivePatch& srcPatch,
208  const primitivePatch& tgtPatch
209  ) const;
210 
211 
212  // Initialisation
213 
214  //- Project points to surface
215  void projectPointsToSurface
216  (
217  const searchableSurface& surf,
218  pointField& pts
219  ) const;
220 
221 
222  // Manipulation
223 
224  //- Sum the weights for each face
225  static void sumWeights
226  (
227  const scalarListList& wght,
228  scalarField& wghtSum
229  );
230 
231  //- As above, but for multiple sets of weights
232  static void sumWeights
233  (
234  const UPtrList<scalarListList>& wghts,
235  scalarField& wghtSum
236  );
237 
238  //- Print out information relating to the weights sum. Values close
239  // to one are ideal. This information acts as a measure of the
240  // quality of the AMI.
241  static void reportSumWeights
242  (
243  const scalarField& patchAreas,
244  const word& patchName,
245  const scalarField& wghtSum,
246  const scalar lowWeightTol
247  );
248 
249  //- Normalise the weights so that they sum to one for each face.
250  // This may stabilise the solution at the expense of accuracy.
251  static void normaliseWeights
252  (
253  scalarListList& wght,
254  const scalarField& wghtSum
255  );
256 
257  //- As above but for multiple sets of weights
258  static void normaliseWeights
259  (
261  const scalarField& wghtSum
262  );
263 
264 
265  // Constructor helpers
266 
267  static void agglomerate
268  (
269  const autoPtr<mapDistribute>& targetMap,
270  const scalarField& fineSrcMagSf,
271  const labelListList& fineSrcAddress,
272  const scalarListList& fineSrcWeights,
273 
274  const labelList& sourceRestrictAddressing,
275  const labelList& targetRestrictAddressing,
276 
282  );
283 
284  void constructFromSurface
285  (
286  const primitivePatch& srcPatch,
287  const primitivePatch& tgtPatch,
288  const autoPtr<searchableSurface>& surfPtr,
289  const bool report
290  );
291 
292 public:
293 
294  //- Runtime type information
295  TypeName("cyclicAMI");
296 
297 
298  // Constructors
299 
300  //- Construct from components
302  (
303  const primitivePatch& srcPatch,
304  const primitivePatch& tgtPatch,
306  const bool requireMatch = true,
307  const interpolationMethod& method = imFaceAreaWeight,
308  const scalar lowWeightCorrection = -1,
309  const bool reverseTarget = false,
310  const bool report = true
311  );
312 
313  //- Construct from components
315  (
316  const primitivePatch& srcPatch,
317  const primitivePatch& tgtPatch,
319  const bool requireMatch = true,
320  const word& methodName =
322  const scalar lowWeightCorrection = -1,
323  const bool reverseTarget = false,
324  const bool report = true
325  );
326 
327  //- Construct from components, with projection surface
329  (
330  const primitivePatch& srcPatch,
331  const primitivePatch& tgtPatch,
332  const autoPtr<searchableSurface>& surf,
334  const bool requireMatch = true,
335  const interpolationMethod& method = imFaceAreaWeight,
336  const scalar lowWeightCorrection = -1,
337  const bool reverseTarget = false,
338  const bool report = true
339  );
340 
341  //- Construct from components, with projection surface
343  (
344  const primitivePatch& srcPatch,
345  const primitivePatch& tgtPatch,
346  const autoPtr<searchableSurface>& surf,
348  const bool requireMatch = true,
349  const word& methodName =
351  const scalar lowWeightCorrection = -1,
352  const bool reverseTarget = false,
353  const bool report = true
354  );
355 
356  //- Construct from agglomeration of AMIInterpolation.
357  // Agglomeration passed in as new coarse size and addressing from fine
358  // from coarse
360  (
361  const AMIInterpolation& fineAMI,
362  const labelList& sourceRestrictAddressing,
363  const labelList& neighbourRestrictAddressing,
364  const bool report = false
365  );
366 
367  //- Disallow default bitwise copy construction
368  AMIInterpolation(const AMIInterpolation&) = delete;
369 
370 
371  //- Destructor
372  virtual ~AMIInterpolation();
373 
374 
375  // Member Functions
376 
377  // Access
378 
379  //- Set to -1, or the processor holding all faces (both sides) of
380  // the AMI
381  inline label singlePatchProc() const;
382 
383  //- Threshold weight below which interpolation is deactivated
384  inline scalar lowWeightCorrection() const;
385 
386  //- Return true if employing a 'lowWeightCorrection'
387  inline bool applyLowWeightCorrection() const;
388 
389 
390  // Source patch
391 
392  //- Return const access to source patch face areas
393  inline const scalarField& srcMagSf() const;
394 
395  //- Return const access to source patch addressing
396  inline const labelListList& srcAddress() const;
397 
398  //- Return const access to source patch weights
399  inline const scalarListList& srcWeights() const;
400 
401  //- Return access to source patch weights
402  inline scalarListList& srcWeights();
403 
404  //- Return const access to normalisation factor of source
405  // patch weights (i.e. the sum before normalisation)
406  inline const scalarField& srcWeightsSum() const;
407 
408  //- Return access to normalisation factor of source
409  // patch weights (i.e. the sum before normalisation)
410  inline scalarField& srcWeightsSum();
411 
412  //- Source map pointer - valid only if singlePatchProc = -1
413  // This gets source data into a form to be consumed by
414  // tgtAddress, tgtWeights
415  inline const mapDistribute& srcMap() const;
416 
417 
418  // Target patch
419 
420  //- Return const access to target patch face areas
421  inline const scalarField& tgtMagSf() const;
422 
423  //- Return const access to target patch addressing
424  inline const labelListList& tgtAddress() const;
425 
426  //- Return const access to target patch weights
427  inline const scalarListList& tgtWeights() const;
428 
429  //- Return access to target patch weights
430  inline scalarListList& tgtWeights();
431 
432  //- Return const access to normalisation factor of target
433  // patch weights (i.e. the sum before normalisation)
434  inline const scalarField& tgtWeightsSum() const;
435 
436  //- Return access to normalisation factor of target
437  // patch weights (i.e. the sum before normalisation)
438  inline scalarField& tgtWeightsSum();
439 
440  //- Target map pointer - valid only if singlePatchProc=-1.
441  // This gets target data into a form to be consumed by
442  // srcAddress, srcWeights
443  inline const mapDistribute& tgtMap() const;
444 
445 
446  // Manipulation
447 
448  //- Update addressing and weights
449  void update
450  (
451  const primitivePatch& srcPatch,
452  const primitivePatch& tgtPatch,
453  const bool report
454  );
455 
456  //- Sum the weights on both sides of an AMI
457  static void sumWeights(AMIInterpolation& AMI);
458 
459  //- As above, but for multiple AMI-s
460  static void sumWeights(PtrList<AMIInterpolation>& AMIs);
461 
462  //- Print out information relating to the weights sum. Values close
463  // to one are ideal. This information acts as a measure of the
464  // quality of the AMI.
465  static void reportSumWeights(AMIInterpolation& AMI);
466 
467  //- Normalise the weights on both sides of an AMI
468  static void normaliseWeights(AMIInterpolation& AMI);
469 
470  //- As above, but for multiple AMI-s
471  static void normaliseWeights(UPtrList<AMIInterpolation>& AMIs);
472 
473 
474  // Evaluation
475 
476  // Low-level
477 
478  //- Interpolate from target to source with supplied op
479  // to combine existing value with remote value and weight
480  template<class Type, class CombineOp>
482  (
483  const UList<Type>& fld,
484  const CombineOp& cop,
485  List<Type>& result,
486  const UList<Type>& defaultValues = UList<Type>::null()
487  ) const;
488 
489  //- Interpolate from source to target with supplied op
490  // to combine existing value with remote value and weight
491  template<class Type, class CombineOp>
493  (
494  const UList<Type>& fld,
495  const CombineOp& cop,
496  List<Type>& result,
497  const UList<Type>& defaultValues = UList<Type>::null()
498  ) const;
499 
500 
501  //- Interpolate from target to source with supplied op
502  template<class Type, class CombineOp>
504  (
505  const Field<Type>& fld,
506  const CombineOp& cop,
507  const UList<Type>& defaultValues = UList<Type>::null()
508  ) const;
509 
510  //- Interpolate from target tmp field to source with supplied op
511  template<class Type, class CombineOp>
513  (
514  const tmp<Field<Type>>& tFld,
515  const CombineOp& cop,
516  const UList<Type>& defaultValues = UList<Type>::null()
517  ) const;
518 
519  //- Interpolate from source to target with supplied op
520  template<class Type, class CombineOp>
522  (
523  const Field<Type>& fld,
524  const CombineOp& cop,
525  const UList<Type>& defaultValues = UList<Type>::null()
526  ) const;
527 
528  //- Interpolate from source tmp field to target with supplied op
529  template<class Type, class CombineOp>
531  (
532  const tmp<Field<Type>>& tFld,
533  const CombineOp& cop,
534  const UList<Type>& defaultValues = UList<Type>::null()
535  ) const;
536 
537  //- Interpolate from target to source
538  template<class Type>
540  (
541  const Field<Type>& fld,
542  const UList<Type>& defaultValues = UList<Type>::null()
543  ) const;
544 
545  //- Interpolate from target tmp field
546  template<class Type>
548  (
549  const tmp<Field<Type>>& tFld,
550  const UList<Type>& defaultValues = UList<Type>::null()
551  ) const;
552 
553  //- Interpolate from source to target
554  template<class Type>
556  (
557  const Field<Type>& fld,
558  const UList<Type>& defaultValues = UList<Type>::null()
559  ) const;
560 
561  //- Interpolate from source tmp field
562  template<class Type>
564  (
565  const tmp<Field<Type>>& tFld,
566  const UList<Type>& defaultValues = UList<Type>::null()
567  ) const;
568 
569 
570  // Point intersections
571 
572  //- Return source patch face index of point on target patch face
574  (
575  const primitivePatch& srcPatch,
576  const primitivePatch& tgtPatch,
577  const vector& n,
578  const label tgtFacei,
579  point& tgtPoint
580  )
581  const;
582 
583  //- Return target patch face index of point on source patch face
585  (
586  const primitivePatch& srcPatch,
587  const primitivePatch& tgtPatch,
588  const vector& n,
589  const label srcFacei,
590  point& srcPoint
591  )
592  const;
593 
594 
595  // Checks
596 
597  //- Write face connectivity as OBJ file
599  (
600  const primitivePatch& srcPatch,
601  const primitivePatch& tgtPatch,
603  ) const;
604 
605 
606  // Member Operators
607 
608  //- Disallow default bitwise assignment
609  void operator=(const AMIInterpolation&) = delete;
610 };
611 
612 
613 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
614 
615 } // End namespace Foam
616 
617 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
618 
619 #include "AMIInterpolationI.H"
620 
621 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
622 
623 #ifdef NoRepository
624  #include "AMIInterpolationTemplates.C"
625 #endif
626 
627 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
628 
629 #endif
630 
631 // ************************************************************************* //
static word interpolationMethodToWord(const interpolationMethod &method)
Convert interpolationMethod to word representation.
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
void update(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const bool report)
Update addressing and weights.
label tgtPointFace(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const vector &n, const label srcFacei, point &srcPoint) const
Return target patch face index of point on source patch face.
label singlePatchProc() const
Set to -1, or the processor holding all faces (both sides) of.
const scalarListList & tgtWeights() const
Return const access to target patch weights.
void writeFaceConnectivity(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
label srcPointFace(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const vector &n, const label tgtFacei, point &tgtPoint) const
Return source patch face index of point on target patch face.
const mapDistribute & srcMap() const
Source map pointer - valid only if singlePatchProc = -1.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
static tmp< scalarField > patchMagSf(const primitivePatch &patch, const faceAreaIntersect::triangulationMode triMode)
Calculate the patch face magnitudes for the given tri-mode.
Combination-Reduction operation for a parallel run.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
interpolationMethod
Enumeration specifying interpolation method.
const scalarField & srcMagSf() const
Return const access to source patch face areas.
A list of faces which address into the list of points.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
AMIInterpolation(const primitivePatch &srcPatch, const primitivePatch &tgtPatch, const faceAreaIntersect::triangulationMode &triMode, const bool requireMatch=true, const interpolationMethod &method=imFaceAreaWeight, const scalar lowWeightCorrection=-1, const bool reverseTarget=false, const bool report=true)
Construct from components.
const pointField & points
A class for handling words, derived from string.
Definition: word.H:59
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target.
virtual ~AMIInterpolation()
Destructor.
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from source to target with supplied op.
A templated 1D list of pointers to objects of type <T>, where the size of the array is known and used...
Definition: UPtrList.H:54
const scalarListList & srcWeights() const
Return const access to source patch weights.
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from target to source with supplied op.
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source.
Class containing processor-to-processor mapping information.
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
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:87
label n
static interpolationMethod wordTointerpolationMethod(const word &method)
Convert word to interpolationMethod.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
const mapDistribute & tgtMap() const
Target map pointer - valid only if singlePatchProc=-1.
A class for managing temporary objects.
Definition: PtrList.H:53
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
const labelListList & srcAddress() const
Return const access to source patch addressing.
void operator=(const AMIInterpolation &)=delete
Disallow default bitwise assignment.
TypeName("cyclicAMI")
Runtime type information.
const scalarField & tgtMagSf() const
Return const access to target patch face areas.
bool applyLowWeightCorrection() const
Return true if employing a &#39;lowWeightCorrection&#39;.
Namespace for OpenFOAM.