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 | Copyright (C) 2011-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::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 data types
85 
86  //- Enumeration specifying interpolation method
88  {
93  };
94 
95  //- Convert interpolationMethod to word representation
97  (
98  const interpolationMethod& method
99  );
100 
101  //- Convert word to interpolationMethod
103  (
104  const word& method
105  );
106 
107 
108 private:
109 
110  // Private data
111 
112  //- Interpolation method
113  const word methodName_;
114 
115  //- Flag to indicate that the two patches are co-directional and
116  // that the orientation of the target patch should be reversed
117  const bool reverseTarget_;
118 
119  //- Flag to indicate that the two patches must be matched/an overlap
120  // exists between them
121  const bool requireMatch_;
122 
123  //- Index of processor that holds all of both sides. -1 in all other
124  // cases
125  label singlePatchProc_;
126 
127  //- Threshold weight below which interpolation is deactivated
128  scalar lowWeightCorrection_;
129 
130 
131  // Source patch
132 
133  //- Source face areas
134  scalarField srcMagSf_;
135 
136  //- Addresses of target faces per source face
137  labelListList srcAddress_;
138 
139  //- Weights of target faces per source face
140  scalarListList srcWeights_;
141 
142  //- Sum of weights of target faces per source face
143  scalarField srcWeightsSum_;
144 
145 
146  // Target patch
147 
148  //- Target face areas
149  scalarField tgtMagSf_;
150 
151  //- Addresses of source faces per target face
152  labelListList tgtAddress_;
153 
154  //- Weights of source faces per target face
155  scalarListList tgtWeights_;
156 
157  //- Sum of weights of source faces per target face
158  scalarField tgtWeightsSum_;
159 
160 
161  //- Face triangulation mode
163 
164  //- Source map pointer - parallel running only
165  autoPtr<mapDistribute> srcMapPtr_;
166 
167  //- Target map pointer - parallel running only
168  autoPtr<mapDistribute> tgtMapPtr_;
169 
170 
171  // Private Member Functions
172 
173  //- Disallow default bitwise copy construct
175 
176  //- Disallow default bitwise assignment
177  void operator=(const AMIInterpolation&);
178 
179 
180  // Parallel functionality
181 
182  //- Calculate if patches are on multiple processors
183  label calcDistribution
184  (
185  const SourcePatch& srcPatch,
186  const TargetPatch& tgtPatch
187  ) const;
188 
189  label calcOverlappingProcs
190  (
191  const List<treeBoundBoxList>& procBb,
192  const treeBoundBox& bb,
193  boolList& overlaps
194  ) const;
195 
196  void distributePatches
197  (
198  const mapDistribute& map,
199  const TargetPatch& pp,
200  const globalIndex& gi,
201  List<faceList>& faces,
203  List<labelList>& tgtFaceIDs
204  ) const;
205 
206  void distributeAndMergePatches
207  (
208  const mapDistribute& map,
209  const TargetPatch& tgtPatch,
210  const globalIndex& gi,
211  faceList& tgtFaces,
212  pointField& tgtPoints,
213  labelList& tgtFaceIDs
214  ) const;
215 
216  autoPtr<mapDistribute> calcProcMap
217  (
218  const SourcePatch& srcPatch,
219  const TargetPatch& tgtPatch
220  ) const;
221 
222 
223  // Initialisation
224 
225  //- Project points to surface
226  void projectPointsToSurface
227  (
228  const searchableSurface& surf,
229  pointField& pts
230  ) const;
231 
232 
233  // Evaluation
234 
235  //- Normalise the (area) weights - suppresses numerical error in
236  // weights calculation
237  // NOTE: if area weights are incorrect by 'a significant amount'
238  // normalisation may stabilise the solution, but will introduce
239  // numerical error!
240  static void normaliseWeights
241  (
242  const scalarField& patchAreas,
243  const word& patchName,
244  const labelListList& addr,
245  scalarListList& wght,
246  scalarField& wghtSum,
247  const bool conformal,
248  const bool output,
249  const scalar lowWeightTol
250  );
251 
252 
253  // Constructor helpers
254 
255  static void agglomerate
256  (
257  const autoPtr<mapDistribute>& targetMap,
258  const scalarField& fineSrcMagSf,
259  const labelListList& fineSrcAddress,
260  const scalarListList& fineSrcWeights,
261 
262  const labelList& sourceRestrictAddressing,
263  const labelList& targetRestrictAddressing,
264 
270  );
271 
272  void constructFromSurface
273  (
274  const SourcePatch& srcPatch,
275  const TargetPatch& tgtPatch,
276  const autoPtr<searchableSurface>& surfPtr
277  );
278 
279 public:
280 
281  // Constructors
282 
283  //- Construct from components
285  (
286  const SourcePatch& srcPatch,
287  const TargetPatch& tgtPatch,
289  const bool requireMatch = true,
290  const interpolationMethod& method = imFaceAreaWeight,
291  const scalar lowWeightCorrection = -1,
292  const bool reverseTarget = false
293  );
294 
295  //- Construct from components
297  (
298  const SourcePatch& srcPatch,
299  const TargetPatch& tgtPatch,
301  const bool requireMatch = true,
302  const word& methodName =
304  const scalar lowWeightCorrection = -1,
305  const bool reverseTarget = false
306  );
307 
308  //- Construct from components, with projection surface
310  (
311  const SourcePatch& srcPatch,
312  const TargetPatch& tgtPatch,
313  const autoPtr<searchableSurface>& surf,
315  const bool requireMatch = true,
316  const interpolationMethod& method = imFaceAreaWeight,
317  const scalar lowWeightCorrection = -1,
318  const bool reverseTarget = false
319  );
320 
321  //- Construct from components, with projection surface
323  (
324  const SourcePatch& srcPatch,
325  const TargetPatch& tgtPatch,
326  const autoPtr<searchableSurface>& surf,
328  const bool requireMatch = true,
329  const word& methodName =
331  const scalar lowWeightCorrection = -1,
332  const bool reverseTarget = false
333  );
334 
335  //- Construct from agglomeration of AMIInterpolation. Agglomeration
336  // passed in as new coarse size and addressing from fine from coarse
338  (
340  const labelList& sourceRestrictAddressing,
341  const labelList& neighbourRestrictAddressing
342  );
343 
344 
345  //- Destructor
347 
348  // Typedef to SourcePatch type this AMIInterplation is instantiated on
349  typedef SourcePatch sourcePatchType;
350 
351  // Typedef to TargetPatch type this AMIInterplation is instantiated on
352  typedef TargetPatch targetPatchType;
353 
354 
355  // Member Functions
356 
357  // Access
358 
359  //- Set to -1, or the processor holding all faces (both sides) of
360  // the AMI
361  inline label singlePatchProc() const;
362 
363  //- Threshold weight below which interpolation is deactivated
364  inline scalar lowWeightCorrection() const;
365 
366  //- Return true if employing a 'lowWeightCorrection'
367  inline bool applyLowWeightCorrection() const;
368 
369 
370  // Source patch
371 
372  //- Return const access to source patch face areas
373  inline const scalarField& srcMagSf() const;
374 
375  //- Return const access to source patch addressing
376  inline const labelListList& srcAddress() const;
377 
378  //- Return const access to source patch weights
379  inline const scalarListList& srcWeights() const;
380 
381  //- Return access to source patch weights
382  inline scalarListList& srcWeights();
383 
384  //- Return const access to normalisation factor of source
385  // patch weights (i.e. the sum before normalisation)
386  inline const scalarField& srcWeightsSum() const;
387 
388  //- Return access to normalisation factor of source
389  // patch weights (i.e. the sum before normalisation)
390  inline scalarField& srcWeightsSum();
391 
392  //- Source map pointer - valid only if singlePatchProc = -1
393  // This gets source data into a form to be consumed by
394  // tgtAddress, tgtWeights
395  inline const mapDistribute& srcMap() const;
396 
397 
398  // Target patch
399 
400  //- Return const access to target patch face areas
401  inline const scalarField& tgtMagSf() const;
402 
403  //- Return const access to target patch addressing
404  inline const labelListList& tgtAddress() const;
405 
406  //- Return const access to target patch weights
407  inline const scalarListList& tgtWeights() const;
408 
409  //- Return access to target patch weights
410  inline scalarListList& tgtWeights();
411 
412  //- Return const access to normalisation factor of target
413  // patch weights (i.e. the sum before normalisation)
414  inline const scalarField& tgtWeightsSum() const;
415 
416  //- Return access to normalisation factor of target
417  // patch weights (i.e. the sum before normalisation)
418  inline scalarField& tgtWeightsSum();
419 
420  //- Target map pointer - valid only if singlePatchProc=-1.
421  // This gets target data into a form to be consumed by
422  // srcAddress, srcWeights
423  inline const mapDistribute& tgtMap() const;
424 
425 
426  // Manipulation
427 
428  //- Update addressing and weights
429  void update
430  (
431  const SourcePatch& srcPatch,
432  const TargetPatch& tgtPatch
433  );
434 
435 
436  // Evaluation
437 
438  // Low-level
439 
440  //- Interpolate from target to source with supplied op
441  // to combine existing value with remote value and weight
442  template<class Type, class CombineOp>
444  (
445  const UList<Type>& fld,
446  const CombineOp& cop,
447  List<Type>& result,
448  const UList<Type>& defaultValues = UList<Type>::null()
449  ) const;
450 
451  //- Interpolate from source to target with supplied op
452  // to combine existing value with remote value and weight
453  template<class Type, class CombineOp>
455  (
456  const UList<Type>& fld,
457  const CombineOp& cop,
458  List<Type>& result,
459  const UList<Type>& defaultValues = UList<Type>::null()
460  ) const;
461 
462 
463  //- Interpolate from target to source with supplied op
464  template<class Type, class CombineOp>
466  (
467  const Field<Type>& fld,
468  const CombineOp& cop,
469  const UList<Type>& defaultValues = UList<Type>::null()
470  ) const;
471 
472  //- Interpolate from target tmp field to source with supplied op
473  template<class Type, class CombineOp>
475  (
476  const tmp<Field<Type>>& tFld,
477  const CombineOp& cop,
478  const UList<Type>& defaultValues = UList<Type>::null()
479  ) const;
480 
481  //- Interpolate from source to target with supplied op
482  template<class Type, class CombineOp>
484  (
485  const Field<Type>& fld,
486  const CombineOp& cop,
487  const UList<Type>& defaultValues = UList<Type>::null()
488  ) const;
489 
490  //- Interpolate from source tmp field to target with supplied op
491  template<class Type, class CombineOp>
493  (
494  const tmp<Field<Type>>& tFld,
495  const CombineOp& cop,
496  const UList<Type>& defaultValues = UList<Type>::null()
497  ) const;
498 
499  //- Interpolate from target to source
500  template<class Type>
502  (
503  const Field<Type>& fld,
504  const UList<Type>& defaultValues = UList<Type>::null()
505  ) const;
506 
507  //- Interpolate from target tmp field
508  template<class Type>
510  (
511  const tmp<Field<Type>>& tFld,
512  const UList<Type>& defaultValues = UList<Type>::null()
513  ) const;
514 
515  //- Interpolate from source to target
516  template<class Type>
518  (
519  const Field<Type>& fld,
520  const UList<Type>& defaultValues = UList<Type>::null()
521  ) const;
522 
523  //- Interpolate from source tmp field
524  template<class Type>
526  (
527  const tmp<Field<Type>>& tFld,
528  const UList<Type>& defaultValues = UList<Type>::null()
529  ) const;
530 
531 
532  // Point intersections
533 
534  //- Return source patch face index of point on target patch face
536  (
537  const SourcePatch& srcPatch,
538  const TargetPatch& tgtPatch,
539  const vector& n,
540  const label tgtFacei,
541  point& tgtPoint
542  )
543  const;
544 
545  //- Return target patch face index of point on source patch face
547  (
548  const SourcePatch& srcPatch,
549  const TargetPatch& tgtPatch,
550  const vector& n,
551  const label srcFacei,
552  point& srcPoint
553  )
554  const;
555 
556 
557  // Checks
558 
559  //- Write face connectivity as OBJ file
561  (
562  const SourcePatch& srcPatch,
563  const TargetPatch& tgtPatch,
565  ) const;
566 };
567 
568 
569 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
570 
571 } // End namespace Foam
572 
573 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
574 
575 #include "AMIInterpolationI.H"
576 
577 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
578 
579 #ifdef NoRepository
580  #include "AMIInterpolation.C"
582 #endif
583 
584 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
585 
586 #endif
587 
588 // ************************************************************************* //
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.
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.
void update(const SourcePatch &srcPatch, const TargetPatch &tgtPatch)
Update addressing and weights.
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
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.