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-2018 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  AMIInterpolationName.C
45  AMIInterpolationParallelOps.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 AMIInterpolationName Declaration
68 \*---------------------------------------------------------------------------*/
69 
70 TemplateName(AMIInterpolation);
71 
72 
73 /*---------------------------------------------------------------------------*\
74  Class AMIInterpolation Declaration
75 \*---------------------------------------------------------------------------*/
76 
77 template<class SourcePatch, class TargetPatch>
78 class AMIInterpolation
79 :
80  public AMIInterpolationName
81 {
82 public:
83 
84  // Public typedefs
85 
86  // Typedef to SourcePatch type this AMIInterplation is instantiated on
87  typedef SourcePatch sourcePatchType;
88 
89  // Typedef to TargetPatch type this AMIInterplation is instantiated on
90  typedef TargetPatch targetPatchType;
91 
92 
93  // Public data types
94 
95  //- Enumeration specifying interpolation method
97  {
103  };
104 
105  //- Convert interpolationMethod to word representation
107  (
108  const interpolationMethod& method
109  );
110 
111  //- Convert word to interpolationMethod
113  (
114  const word& method
115  );
116 
117  //- Calculate the patch face magnitudes for the given tri-mode
118  template<class Patch>
120  (
121  const Patch& patch,
123  );
124 
125 
126 private:
127 
128  // Private data
129 
130  //- Interpolation method
131  const word methodName_;
132 
133  //- Flag to indicate that the two patches are co-directional and
134  // that the orientation of the target patch should be reversed
135  const bool reverseTarget_;
136 
137  //- Flag to indicate that the two patches must be matched/an overlap
138  // exists between them
139  const bool requireMatch_;
140 
141  //- Index of processor that holds all of both sides. -1 in all other
142  // cases
143  label singlePatchProc_;
144 
145  //- Threshold weight below which interpolation is deactivated
146  scalar lowWeightCorrection_;
147 
148 
149  // Source patch
150 
151  //- Source face areas
152  scalarField srcMagSf_;
153 
154  //- Addresses of target faces per source face
155  labelListList srcAddress_;
156 
157  //- Weights of target faces per source face
158  scalarListList srcWeights_;
159 
160  //- Sum of weights of target faces per source face
161  scalarField srcWeightsSum_;
162 
163 
164  // Target patch
165 
166  //- Target face areas
167  scalarField tgtMagSf_;
168 
169  //- Addresses of source faces per target face
170  labelListList tgtAddress_;
171 
172  //- Weights of source faces per target face
173  scalarListList tgtWeights_;
174 
175  //- Sum of weights of source faces per target face
176  scalarField tgtWeightsSum_;
177 
178 
179  //- Face triangulation mode
181 
182  //- Source map pointer - parallel running only
183  autoPtr<mapDistribute> srcMapPtr_;
184 
185  //- Target map pointer - parallel running only
186  autoPtr<mapDistribute> tgtMapPtr_;
187 
188 
189  // Private Member Functions
190 
191  //- Disallow default bitwise copy construct
193 
194  //- Disallow default bitwise assignment
195  void operator=(const AMIInterpolation&);
196 
197 
198  // Parallel functionality
199 
200  //- Calculate if patches are on multiple processors
201  label calcDistribution
202  (
203  const SourcePatch& srcPatch,
204  const TargetPatch& tgtPatch
205  ) const;
206 
207  label calcOverlappingProcs
208  (
209  const List<treeBoundBoxList>& procBb,
210  const treeBoundBox& bb,
211  boolList& overlaps
212  ) const;
213 
214  void distributePatches
215  (
216  const mapDistribute& map,
217  const TargetPatch& pp,
218  const globalIndex& gi,
219  List<faceList>& faces,
221  List<labelList>& tgtFaceIDs
222  ) const;
223 
224  void distributeAndMergePatches
225  (
226  const mapDistribute& map,
227  const TargetPatch& tgtPatch,
228  const globalIndex& gi,
229  faceList& tgtFaces,
230  pointField& tgtPoints,
231  labelList& tgtFaceIDs
232  ) const;
233 
234  autoPtr<mapDistribute> calcProcMap
235  (
236  const SourcePatch& srcPatch,
237  const TargetPatch& tgtPatch
238  ) const;
239 
240 
241  // Initialisation
242 
243  //- Project points to surface
244  void projectPointsToSurface
245  (
246  const searchableSurface& surf,
247  pointField& pts
248  ) const;
249 
250 
251  // Manipulation
252 
253  //- Sum the weights for each face
254  static void sumWeights
255  (
256  const scalarListList& wght,
257  scalarField& wghtSum
258  );
259 
260  //- As above, but for multiple sets of weights
261  static void sumWeights
262  (
263  const UPtrList<scalarListList>& wghts,
264  scalarField& wghtSum
265  );
266 
267  //- Print out information relating to the weights sum. Values close
268  // to one are ideal. This information acts as a measure of the
269  // quality of the AMI.
270  static void reportSumWeights
271  (
272  const scalarField& patchAreas,
273  const word& patchName,
274  const scalarField& wghtSum,
275  const scalar lowWeightTol
276  );
277 
278  //- Normalise the weights so that they sum to one for each face.
279  // This may stabilise the solution at the expense of accuracy.
280  static void normaliseWeights
281  (
282  scalarListList& wght,
283  const scalarField& wghtSum
284  );
285 
286  //- As above but for multiple sets of weights
287  static void normaliseWeights
288  (
290  const scalarField& wghtSum
291  );
292 
293 
294  // Constructor helpers
295 
296  static void agglomerate
297  (
298  const autoPtr<mapDistribute>& targetMap,
299  const scalarField& fineSrcMagSf,
300  const labelListList& fineSrcAddress,
301  const scalarListList& fineSrcWeights,
302 
303  const labelList& sourceRestrictAddressing,
304  const labelList& targetRestrictAddressing,
305 
311  );
312 
313  void constructFromSurface
314  (
315  const SourcePatch& srcPatch,
316  const TargetPatch& tgtPatch,
317  const autoPtr<searchableSurface>& surfPtr,
318  const bool report
319  );
320 
321 public:
322 
323  // Constructors
324 
325  //- Construct from components
327  (
328  const SourcePatch& srcPatch,
329  const TargetPatch& tgtPatch,
331  const bool requireMatch = true,
332  const interpolationMethod& method = imFaceAreaWeight,
333  const scalar lowWeightCorrection = -1,
334  const bool reverseTarget = false,
335  const bool report = true
336  );
337 
338  //- Construct from components
340  (
341  const SourcePatch& srcPatch,
342  const TargetPatch& tgtPatch,
344  const bool requireMatch = true,
345  const word& methodName =
347  const scalar lowWeightCorrection = -1,
348  const bool reverseTarget = false,
349  const bool report = true
350  );
351 
352  //- Construct from components, with projection surface
354  (
355  const SourcePatch& srcPatch,
356  const TargetPatch& tgtPatch,
357  const autoPtr<searchableSurface>& surf,
359  const bool requireMatch = true,
360  const interpolationMethod& method = imFaceAreaWeight,
361  const scalar lowWeightCorrection = -1,
362  const bool reverseTarget = false,
363  const bool report = true
364  );
365 
366  //- Construct from components, with projection surface
368  (
369  const SourcePatch& srcPatch,
370  const TargetPatch& tgtPatch,
371  const autoPtr<searchableSurface>& surf,
373  const bool requireMatch = true,
374  const word& methodName =
376  const scalar lowWeightCorrection = -1,
377  const bool reverseTarget = false,
378  const bool report = true
379  );
380 
381  //- Construct from agglomeration of AMIInterpolation. Agglomeration
382  // passed in as new coarse size and addressing from fine from coarse
384  (
386  const labelList& sourceRestrictAddressing,
387  const labelList& neighbourRestrictAddressing,
388  const bool report = false
389  );
390 
391 
392  //- Destructor
394 
395 
396  // Member Functions
397 
398  // Access
399 
400  //- Set to -1, or the processor holding all faces (both sides) of
401  // the AMI
402  inline label singlePatchProc() const;
403 
404  //- Threshold weight below which interpolation is deactivated
405  inline scalar lowWeightCorrection() const;
406 
407  //- Return true if employing a 'lowWeightCorrection'
408  inline bool applyLowWeightCorrection() const;
409 
410 
411  // Source patch
412 
413  //- Return const access to source patch face areas
414  inline const scalarField& srcMagSf() const;
415 
416  //- Return const access to source patch addressing
417  inline const labelListList& srcAddress() const;
418 
419  //- Return const access to source patch weights
420  inline const scalarListList& srcWeights() const;
421 
422  //- Return access to source patch weights
423  inline scalarListList& srcWeights();
424 
425  //- Return const access to normalisation factor of source
426  // patch weights (i.e. the sum before normalisation)
427  inline const scalarField& srcWeightsSum() const;
428 
429  //- Return access to normalisation factor of source
430  // patch weights (i.e. the sum before normalisation)
431  inline scalarField& srcWeightsSum();
432 
433  //- Source map pointer - valid only if singlePatchProc = -1
434  // This gets source data into a form to be consumed by
435  // tgtAddress, tgtWeights
436  inline const mapDistribute& srcMap() const;
437 
438 
439  // Target patch
440 
441  //- Return const access to target patch face areas
442  inline const scalarField& tgtMagSf() const;
443 
444  //- Return const access to target patch addressing
445  inline const labelListList& tgtAddress() const;
446 
447  //- Return const access to target patch weights
448  inline const scalarListList& tgtWeights() const;
449 
450  //- Return access to target patch weights
451  inline scalarListList& tgtWeights();
452 
453  //- Return const access to normalisation factor of target
454  // patch weights (i.e. the sum before normalisation)
455  inline const scalarField& tgtWeightsSum() const;
456 
457  //- Return access to normalisation factor of target
458  // patch weights (i.e. the sum before normalisation)
459  inline scalarField& tgtWeightsSum();
460 
461  //- Target map pointer - valid only if singlePatchProc=-1.
462  // This gets target data into a form to be consumed by
463  // srcAddress, srcWeights
464  inline const mapDistribute& tgtMap() const;
465 
466 
467  // Manipulation
468 
469  //- Update addressing and weights
470  void update
471  (
472  const SourcePatch& srcPatch,
473  const TargetPatch& tgtPatch,
474  const bool report
475  );
476 
477  //- Sum the weights on both sides of an AMI
478  static void sumWeights
479  (
481  );
482 
483  //- As above, but for multiple AMI-s
484  static void sumWeights
485  (
487  );
488 
489  //- Print out information relating to the weights sum. Values close
490  // to one are ideal. This information acts as a measure of the
491  // quality of the AMI.
492  static void reportSumWeights
493  (
495  );
496 
497  //- Normalise the weights on both sides of an AMI
498  static void normaliseWeights
499  (
501  );
502 
503  //- As above, but for multiple AMI-s
504  static void normaliseWeights
505  (
507  );
508 
509 
510  // Evaluation
511 
512  // Low-level
513 
514  //- Interpolate from target to source with supplied op
515  // to combine existing value with remote value and weight
516  template<class Type, class CombineOp>
518  (
519  const UList<Type>& fld,
520  const CombineOp& cop,
521  List<Type>& result,
522  const UList<Type>& defaultValues = UList<Type>::null()
523  ) const;
524 
525  //- Interpolate from source to target with supplied op
526  // to combine existing value with remote value and weight
527  template<class Type, class CombineOp>
529  (
530  const UList<Type>& fld,
531  const CombineOp& cop,
532  List<Type>& result,
533  const UList<Type>& defaultValues = UList<Type>::null()
534  ) const;
535 
536 
537  //- Interpolate from target to source with supplied op
538  template<class Type, class CombineOp>
540  (
541  const Field<Type>& fld,
542  const CombineOp& cop,
543  const UList<Type>& defaultValues = UList<Type>::null()
544  ) const;
545 
546  //- Interpolate from target tmp field to source with supplied op
547  template<class Type, class CombineOp>
549  (
550  const tmp<Field<Type>>& tFld,
551  const CombineOp& cop,
552  const UList<Type>& defaultValues = UList<Type>::null()
553  ) const;
554 
555  //- Interpolate from source to target with supplied op
556  template<class Type, class CombineOp>
558  (
559  const Field<Type>& fld,
560  const CombineOp& cop,
561  const UList<Type>& defaultValues = UList<Type>::null()
562  ) const;
563 
564  //- Interpolate from source tmp field to target with supplied op
565  template<class Type, class CombineOp>
567  (
568  const tmp<Field<Type>>& tFld,
569  const CombineOp& cop,
570  const UList<Type>& defaultValues = UList<Type>::null()
571  ) const;
572 
573  //- Interpolate from target to source
574  template<class Type>
576  (
577  const Field<Type>& fld,
578  const UList<Type>& defaultValues = UList<Type>::null()
579  ) const;
580 
581  //- Interpolate from target tmp field
582  template<class Type>
584  (
585  const tmp<Field<Type>>& tFld,
586  const UList<Type>& defaultValues = UList<Type>::null()
587  ) const;
588 
589  //- Interpolate from source to target
590  template<class Type>
592  (
593  const Field<Type>& fld,
594  const UList<Type>& defaultValues = UList<Type>::null()
595  ) const;
596 
597  //- Interpolate from source tmp field
598  template<class Type>
600  (
601  const tmp<Field<Type>>& tFld,
602  const UList<Type>& defaultValues = UList<Type>::null()
603  ) const;
604 
605 
606  // Point intersections
607 
608  //- Return source patch face index of point on target patch face
610  (
611  const SourcePatch& srcPatch,
612  const TargetPatch& tgtPatch,
613  const vector& n,
614  const label tgtFacei,
615  point& tgtPoint
616  )
617  const;
618 
619  //- Return target patch face index of point on source patch face
621  (
622  const SourcePatch& srcPatch,
623  const TargetPatch& tgtPatch,
624  const vector& n,
625  const label srcFacei,
626  point& srcPoint
627  )
628  const;
629 
630 
631  // Checks
632 
633  //- Write face connectivity as OBJ file
635  (
636  const SourcePatch& srcPatch,
637  const TargetPatch& tgtPatch,
639  ) const;
640 };
641 
642 
643 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
644 
645 } // End namespace Foam
646 
647 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
648 
649 #include "AMIInterpolationI.H"
650 
651 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
652 
653 #ifdef NoRepository
654  #include "AMIInterpolation.C"
656 #endif
657 
658 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
659 
660 #endif
661 
662 // ************************************************************************* //
static word interpolationMethodToWord(const interpolationMethod &method)
Convert interpolationMethod to word representation.
TemplateName(blendedSchemeBase)
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
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.
const mapDistribute & srcMap() const
Source map pointer - valid only if singlePatchProc = -1.
static interpolationMethod wordTointerpolationMethod(const word &method)
Convert word to interpolationMethod.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
Combination-Reduction operation for a parallel run.
label tgtPointFace(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const vector &n, const label srcFacei, point &srcPoint) const
Return target patch face index of point on source patch face.
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
label srcPointFace(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const vector &n, const label tgtFacei, point &tgtPoint) const
Return source patch face index of point on target patch face.
interpolationMethod
Enumeration specifying interpolation method.
void writeFaceConnectivity(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
const scalarField & srcMagSf() const
Return const access to source patch face areas.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
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.
~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:63
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
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
void update(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const bool report)
Update addressing and weights.
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
const labelListList & srcAddress() const
Return const access to source patch addressing.
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.
static tmp< scalarField > patchMagSf(const Patch &patch, const faceAreaIntersect::triangulationMode triMode)
Calculate the patch face magnitudes for the given tri-mode.