AMIInterpolation.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2017 OpenFOAM Foundation
9  Copyright (C) 2016-2018 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::AMIInterpolation
29 
30 Description
31  Interpolation class dealing with transfer of data between two
32  primitive patches with an arbitrary mesh interface (AMI).
33 
34  Based on the algorithm given in:
35 
36  Conservative interpolation between volume meshes by local Galerkin
37  projection, Farrell PE and Maddison JR, 2011, Comput. Methods Appl.
38  Mech Engrg, Volume 200, Issues 1-4, pp 89-100
39 
40  Interpolation requires that the two patches should have opposite
41  orientations (opposite normals). The 'reverseTarget' flag can be used to
42  reverse the orientation of the target patch.
43 
44 
45 SourceFiles
46  AMIInterpolation.C
47  AMIInterpolationName.C
48  AMIInterpolationParallelOps.C
49 
50 \*---------------------------------------------------------------------------*/
51 
52 #ifndef AMIInterpolation_H
53 #define AMIInterpolation_H
54 
55 #include "className.H"
56 #include "searchableSurface.H"
57 #include "treeBoundBoxList.H"
58 #include "boolList.H"
59 #include "primitivePatch.H"
60 #include "faceAreaIntersect.H"
61 #include "globalIndex.H"
62 #include "ops.H"
63 #include "Enum.H"
64 
65 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
66 
67 namespace Foam
68 {
69 
70 /*---------------------------------------------------------------------------*\
71  Class AMIInterpolationName Declaration
72 \*---------------------------------------------------------------------------*/
73 
74 TemplateName(AMIInterpolation);
75 
76 
77 /*---------------------------------------------------------------------------*\
78  Class AMIInterpolation Declaration
79 \*---------------------------------------------------------------------------*/
80 
81 template<class SourcePatch, class TargetPatch>
82 class AMIInterpolation
83 :
84  public AMIInterpolationName
85 {
86 public:
87 
88  // Public data types
89 
90  //- Enumeration specifying interpolation method
92  {
97  };
98 
100 
101  static bool cacheIntersections_;
102 
103  //- Calculate the patch face magnitudes for the given tri-mode
104  template<class Patch>
106  (
107  const Patch& patch,
109  );
110 
111 
112 private:
113 
114  // Private data
115 
116  //- Interpolation method
117  const word methodName_;
118 
119  //- Flag to indicate that the two patches are co-directional and
120  //- that the orientation of the target patch should be reversed
121  const bool reverseTarget_;
122 
123  //- Flag to indicate that the two patches must be matched/an overlap
124  //- exists between them
125  const bool requireMatch_;
126 
127  //- Index of processor that holds all of both sides. -1 in all other
128  //- cases
129  label singlePatchProc_;
130 
131  //- Threshold weight below which interpolation is deactivated
132  scalar lowWeightCorrection_;
133 
134 
135  // Source patch
136 
137  //- Source face areas
138  scalarList srcMagSf_;
139 
140  //- Addresses of target faces per source face
141  labelListList srcAddress_;
142 
143  //- Weights of target faces per source face
144  scalarListList srcWeights_;
145 
146  //- Sum of weights of target faces per source face
147  scalarField srcWeightsSum_;
148 
149 
150  // Target patch
151 
152  //- Target face areas
153  scalarList tgtMagSf_;
154 
155  //- Addresses of source faces per target face
156  labelListList tgtAddress_;
157 
158  //- Weights of source faces per target face
159  scalarListList tgtWeights_;
160 
161  //- Sum of weights of source faces per target face
162  scalarField tgtWeightsSum_;
163 
164 
165  //- Face triangulation mode
167 
168  //- Source map pointer - parallel running only
169  autoPtr<mapDistribute> srcMapPtr_;
170 
171  //- Target map pointer - parallel running only
172  autoPtr<mapDistribute> tgtMapPtr_;
173 
174 
175  // Private Member Functions
176 
177  //- No copy construct
178  AMIInterpolation(const AMIInterpolation&) = delete;
179 
180  //- No copy assignment
181  void operator=(const AMIInterpolation&) = delete;
182 
183 
184  // Parallel functionality
185 
186  //- Calculate if patches are on multiple processors
187  label calcDistribution
188  (
189  const SourcePatch& srcPatch,
190  const TargetPatch& tgtPatch
191  ) const;
192 
193  label calcOverlappingProcs
194  (
195  const List<treeBoundBoxList>& procBb,
196  const treeBoundBox& bb,
197  boolList& overlaps
198  ) const;
199 
200  void distributePatches
201  (
202  const mapDistribute& map,
203  const TargetPatch& pp,
204  const globalIndex& gi,
205  List<faceList>& faces,
207  List<labelList>& tgtFaceIDs
208  ) const;
209 
210  void distributeAndMergePatches
211  (
212  const mapDistribute& map,
213  const TargetPatch& tgtPatch,
214  const globalIndex& gi,
215  faceList& tgtFaces,
216  pointField& tgtPoints,
217  labelList& tgtFaceIDs
218  ) const;
219 
220  autoPtr<mapDistribute> calcProcMap
221  (
222  const SourcePatch& srcPatch,
223  const TargetPatch& tgtPatch
224  ) const;
225 
226 
227  // Initialisation
228 
229  //- Project points to surface
230  void projectPointsToSurface
231  (
232  const searchableSurface& surf,
233  pointField& pts
234  ) const;
235 
236 
237  // Evaluation
238 
239  //- Normalise the (area) weights - suppresses numerical error in
240  //- weights calculation
241  // NOTE: if area weights are incorrect by 'a significant amount'
242  // normalisation may stabilise the solution, but will introduce
243  // numerical error!
244  static void normaliseWeights
245  (
246  const scalarList& patchAreas,
247  const word& patchName,
248  const labelListList& addr,
249  scalarListList& wght,
250  scalarField& wghtSum,
251  const bool conformal,
252  const bool output,
253  const scalar lowWeightTol
254  );
255 
256 
257  // Constructor helpers
258 
259  static void agglomerate
260  (
261  const autoPtr<mapDistribute>& targetMap,
262  const scalarList& fineSrcMagSf,
263  const labelListList& fineSrcAddress,
264  const scalarListList& fineSrcWeights,
265 
266  const labelList& sourceRestrictAddressing,
267  const labelList& targetRestrictAddressing,
268 
274  );
275 
276  void constructFromSurface
277  (
278  const SourcePatch& srcPatch,
279  const TargetPatch& tgtPatch,
280  const autoPtr<searchableSurface>& surfPtr
281  );
282 
283 public:
284 
285  // Constructors
286 
287  //- Construct from components
289  (
290  const SourcePatch& srcPatch,
291  const TargetPatch& tgtPatch,
293  const bool requireMatch = true,
294  const interpolationMethod& method = imFaceAreaWeight,
295  const scalar lowWeightCorrection = -1,
296  const bool reverseTarget = false
297  );
298 
299  //- Construct from components
301  (
302  const SourcePatch& srcPatch,
303  const TargetPatch& tgtPatch,
305  const bool requireMatch = true,
306  const word& methodName =
308  const scalar lowWeightCorrection = -1,
309  const bool reverseTarget = false
310  );
311 
312  //- Construct from components, with projection surface
314  (
315  const SourcePatch& srcPatch,
316  const TargetPatch& tgtPatch,
317  const autoPtr<searchableSurface>& surf,
319  const bool requireMatch = true,
320  const interpolationMethod& method = imFaceAreaWeight,
321  const scalar lowWeightCorrection = -1,
322  const bool reverseTarget = false
323  );
324 
325  //- Construct from components, with projection surface
327  (
328  const SourcePatch& srcPatch,
329  const TargetPatch& tgtPatch,
330  const autoPtr<searchableSurface>& surf,
332  const bool requireMatch = true,
333  const word& methodName =
335  const scalar lowWeightCorrection = -1,
336  const bool reverseTarget = false
337  );
338 
339  //- Construct from agglomeration of AMIInterpolation. Agglomeration
340  // passed in as new coarse size and addressing from fine from coarse
342  (
344  const labelList& sourceRestrictAddressing,
345  const labelList& neighbourRestrictAddressing
346  );
347 
348 
349  //- Destructor
351 
352  // Typedef to SourcePatch type this AMIInterpolation is instantiated on
353  typedef SourcePatch sourcePatchType;
354 
355  // Typedef to TargetPatch type this AMIInterpolation is instantiated on
356  typedef TargetPatch targetPatchType;
357 
358 
359  // Member Functions
360 
361  // Access
362 
363  //- Set to -1, or the processor holding all faces (both sides) of
364  //- the AMI
365  inline label singlePatchProc() const;
366 
367  //- Threshold weight below which interpolation is deactivated
368  inline scalar lowWeightCorrection() const;
369 
370  //- Return true if employing a 'lowWeightCorrection'
371  inline bool applyLowWeightCorrection() const;
372 
373 
374  // Source patch
375 
376  //- Return const access to source patch face areas
377  inline const List<scalar>& srcMagSf() const;
378 
379  //- Return access to source patch face areas
380  inline List<scalar>& srcMagSf();
381 
382  //- Return const access to source patch addressing
383  inline const labelListList& srcAddress() const;
384 
385  //- Return access to source patch addressing
386  inline labelListList& srcAddress();
387 
388  //- Return const access to source patch weights
389  inline const scalarListList& srcWeights() const;
390 
391  //- Return access to source patch weights
392  inline scalarListList& srcWeights();
393 
394  //- Return const access to normalisation factor of source
395  //- patch weights (i.e. the sum before normalisation)
396  inline const scalarField& srcWeightsSum() const;
397 
398  //- Return access to normalisation factor of source
399  //- patch weights (i.e. the sum before normalisation)
400  inline scalarField& srcWeightsSum();
401 
402  //- Source map pointer - valid only if singlePatchProc = -1
403  //- This gets source data into a form to be consumed by
404  //- tgtAddress, tgtWeights
405  inline const mapDistribute& srcMap() const;
406 
407 
408  // Target patch
409 
410  //- Return const access to target patch face areas
411  inline const List<scalar>& tgtMagSf() const;
412 
413  //- Return access to target patch face areas
414  inline List<scalar>& tgtMagSf();
415 
416  //- Return const access to target patch addressing
417  inline const labelListList& tgtAddress() const;
418 
419  //- Return access to target patch addressing
420  inline labelListList& tgtAddress();
421 
422  //- Return const access to target patch weights
423  inline const scalarListList& tgtWeights() const;
424 
425  //- Return access to target patch weights
426  inline scalarListList& tgtWeights();
427 
428  //- Return const access to normalisation factor of target
429  //- patch weights (i.e. the sum before normalisation)
430  inline const scalarField& tgtWeightsSum() const;
431 
432  //- Return access to normalisation factor of target
433  //- patch weights (i.e. the sum before normalisation)
434  inline scalarField& tgtWeightsSum();
435 
436  //- Target map pointer - valid only if singlePatchProc=-1.
437  //- This gets target data into a form to be consumed by
438  //- srcAddress, srcWeights
439  inline const mapDistribute& tgtMap() const;
440 
441 
442  // Manipulation
443 
444  //- Update addressing and weights
445  void update
446  (
447  const SourcePatch& srcPatch,
448  const TargetPatch& tgtPatch
449  );
450 
451  //- Append additional addressing and weights
452  void append
453  (
454  const SourcePatch& srcPatch,
455  const TargetPatch& tgtPatch
456  );
457 
458  //- Normalise the weights
459  void normaliseWeights(const bool conformal, const bool output);
460 
461 
462  // Evaluation
463 
464  // Low-level
465 
466  //- Interpolate from target to source with supplied op
467  //- to combine existing value with remote value and weight
468  template<class Type, class CombineOp>
470  (
471  const UList<Type>& fld,
472  const CombineOp& cop,
473  List<Type>& result,
474  const UList<Type>& defaultValues = UList<Type>::null()
475  ) const;
476 
477  //- Interpolate from source to target with supplied op
478  //- to combine existing value with remote value and weight
479  template<class Type, class CombineOp>
481  (
482  const UList<Type>& fld,
483  const CombineOp& cop,
484  List<Type>& result,
485  const UList<Type>& defaultValues = UList<Type>::null()
486  ) const;
487 
488 
489  //- Interpolate from target to source with supplied op
490  template<class Type, class CombineOp>
492  (
493  const Field<Type>& fld,
494  const CombineOp& cop,
495  const UList<Type>& defaultValues = UList<Type>::null()
496  ) const;
497 
498  //- Interpolate from target tmp field to source with supplied op
499  template<class Type, class CombineOp>
501  (
502  const tmp<Field<Type>>& tFld,
503  const CombineOp& cop,
504  const UList<Type>& defaultValues = UList<Type>::null()
505  ) const;
506 
507  //- Interpolate from source to target with supplied op
508  template<class Type, class CombineOp>
510  (
511  const Field<Type>& fld,
512  const CombineOp& cop,
513  const UList<Type>& defaultValues = UList<Type>::null()
514  ) const;
515 
516  //- Interpolate from source tmp field to target with supplied op
517  template<class Type, class CombineOp>
519  (
520  const tmp<Field<Type>>& tFld,
521  const CombineOp& cop,
522  const UList<Type>& defaultValues = UList<Type>::null()
523  ) const;
524 
525  //- Interpolate from target to source
526  template<class Type>
528  (
529  const Field<Type>& fld,
530  const UList<Type>& defaultValues = UList<Type>::null()
531  ) const;
532 
533  //- Interpolate from target tmp field
534  template<class Type>
536  (
537  const tmp<Field<Type>>& tFld,
538  const UList<Type>& defaultValues = UList<Type>::null()
539  ) const;
540 
541  //- Interpolate from source to target
542  template<class Type>
544  (
545  const Field<Type>& fld,
546  const UList<Type>& defaultValues = UList<Type>::null()
547  ) const;
548 
549  //- Interpolate from source tmp field
550  template<class Type>
552  (
553  const tmp<Field<Type>>& tFld,
554  const UList<Type>& defaultValues = UList<Type>::null()
555  ) const;
556 
557 
558  // Point intersections
559 
560  //- Return source patch face index of point on target patch face
562  (
563  const SourcePatch& srcPatch,
564  const TargetPatch& tgtPatch,
565  const vector& n,
566  const label tgtFacei,
567  point& tgtPoint
568  )
569  const;
570 
571  //- Return target patch face index of point on source patch face
573  (
574  const SourcePatch& srcPatch,
575  const TargetPatch& tgtPatch,
576  const vector& n,
577  const label srcFacei,
578  point& srcPoint
579  )
580  const;
581 
582 
583  // Checks
584 
585  //- Write face connectivity as OBJ file
587  (
588  const SourcePatch& srcPatch,
589  const TargetPatch& tgtPatch,
591  ) const;
592 };
593 
594 
595 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
596 
597 } // End namespace Foam
598 
599 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
600 
601 #include "AMIInterpolationI.H"
602 
603 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
604 
605 #ifdef NoRepository
606  #include "AMIInterpolation.C"
608 #endif
609 
610 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
611 
612 #endif
613 
614 // ************************************************************************* //
Foam::AMIInterpolation::interpolationMethod
interpolationMethod
Enumeration specifying interpolation method.
Definition: AMIInterpolation.H:90
Foam::AMIInterpolation::append
void append(const SourcePatch &srcPatch, const TargetPatch &tgtPatch)
Append additional addressing and weights.
Definition: AMIInterpolation.C:1061
Foam::Enum< interpolationMethod >
AMIInterpolationI.H
Foam::AMIInterpolation::interpolationMethodNames_
static const Enum< interpolationMethod > interpolationMethodNames_
Definition: AMIInterpolation.H:98
boolList.H
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:62
searchableSurface.H
Foam::AMIInterpolation::tgtPointFace
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.
Definition: AMIInterpolation.C:1650
Foam::faceAreaIntersect::triangulationMode
triangulationMode
Definition: faceAreaIntersect.H:62
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::AMIInterpolation::tgtWeightsSum
const scalarField & tgtWeightsSum() const
Definition: AMIInterpolationI.H:176
Foam::AMIInterpolation::imFaceAreaWeight
Definition: AMIInterpolation.H:94
globalIndex.H
Foam::treeBoundBox
Standard boundBox with extra functionality for use in octree.
Definition: treeBoundBox.H:87
ops.H
Various functors for unary and binary operations. Can be used for parallel combine-reduce operations ...
Foam::AMIInterpolation::srcWeightsSum
const scalarField & srcWeightsSum() const
Definition: AMIInterpolationI.H:104
Foam::AMIInterpolation::tgtAddress
const labelListList & tgtAddress() const
Return const access to target patch addressing.
Definition: AMIInterpolationI.H:144
Foam::AMIInterpolation::tgtWeights
const scalarListList & tgtWeights() const
Return const access to target patch weights.
Definition: AMIInterpolationI.H:160
Foam::AMIInterpolation::interpolateToTarget
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolation.C:1287
faceAreaIntersect.H
Foam::AMIInterpolation::targetPatchType
TargetPatch targetPatchType
Definition: AMIInterpolation.H:355
AMIInterpolation.C
n
label n
Definition: TABSMDCalcMethod2.H:31
Foam::AMIInterpolation::tgtMap
const mapDistribute & tgtMap() const
Definition: AMIInterpolationI.H:192
Foam::label
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:62
Foam::AMIInterpolation::interpolateToSource
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolation.C:1374
Foam::Field< scalar >
AMIInterpolationParallelOps.C
Foam::AMIInterpolation::cacheIntersections_
static bool cacheIntersections_
Definition: AMIInterpolation.H:100
Foam::AMIInterpolation::~AMIInterpolation
~AMIInterpolation()
Destructor.
Definition: AMIInterpolation.C:840
Foam::searchableSurface
Base class of (analytical or triangulated) surface. Encapsulates all the search routines....
Definition: searchableSurface.H:69
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
className.H
Macro definitions for declaring ClassName(), NamespaceName(), etc.
Foam::TemplateName
TemplateName(blendedSchemeBase)
Foam::AMIInterpolation::writeFaceConnectivity
void writeFaceConnectivity(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
Definition: AMIInterpolation.C:1698
fld
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Definition: gmvOutputLagrangian.H:23
Foam::AMIInterpolation::singlePatchProc
label singlePatchProc() const
Definition: AMIInterpolationI.H:31
Foam::AMIInterpolation::patchMagSf
static tmp< scalarField > patchMagSf(const Patch &patch, const faceAreaIntersect::triangulationMode triMode)
Calculate the patch face magnitudes for the given tri-mode.
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::globalIndex
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:68
Foam::AMIInterpolation::srcPointFace
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.
Definition: AMIInterpolation.C:1602
Foam::AMIInterpolation::srcMagSf
const List< scalar > & srcMagSf() const
Return const access to source patch face areas.
Definition: AMIInterpolationI.H:56
treeBoundBoxList.H
Foam::AMIInterpolation::imDirect
Definition: AMIInterpolation.H:92
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
Foam::AMIInterpolation::lowWeightCorrection
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
Definition: AMIInterpolationI.H:39
Foam::AMIInterpolation::srcMap
const mapDistribute & srcMap() const
Definition: AMIInterpolationI.H:120
Foam::AMIInterpolation::applyLowWeightCorrection
bool applyLowWeightCorrection() const
Return true if employing a 'lowWeightCorrection'.
Definition: AMIInterpolationI.H:48
Foam::foamVersion::patch
const std::string patch
OpenFOAM patch number as a std::string.
Foam::Vector< scalar >
Foam::List< scalar >
Foam::AMIInterpolation
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
Definition: AMIInterpolation.H:81
Foam::UList< Type >
points
const pointField & points
Definition: gmvOutputHeader.H:1
Foam::AMIInterpolation::imPartialFaceAreaWeight
Definition: AMIInterpolation.H:95
Foam::AMIInterpolation::imMapNearest
Definition: AMIInterpolation.H:93
Foam::AMIInterpolation::update
void update(const SourcePatch &srcPatch, const TargetPatch &tgtPatch)
Update addressing and weights.
Definition: AMIInterpolation.C:848
Foam::AMIInterpolation::tgtMagSf
const List< scalar > & tgtMagSf() const
Return const access to target patch face areas.
Definition: AMIInterpolationI.H:128
Foam::AMIInterpolation::sourcePatchType
SourcePatch sourcePatchType
Definition: AMIInterpolation.H:352
primitivePatch.H
Foam::AMIInterpolation::srcAddress
const labelListList & srcAddress() const
Return const access to source patch addressing.
Definition: AMIInterpolationI.H:72
Foam::AMIInterpolation::srcWeights
const scalarListList & srcWeights() const
Return const access to source patch weights.
Definition: AMIInterpolationI.H:88
Enum.H