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-2014 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 const access to normalisation factor of source
382  // patch weights (i.e. the sum before normalisation)
383  inline const scalarField& srcWeightsSum() const;
384 
385  //- Source map pointer - valid only if singlePatchProc = -1
386  // This gets source data into a form to be consumed by
387  // tgtAddress, tgtWeights
388  inline const mapDistribute& srcMap() const;
389 
390 
391  // Target patch
392 
393  //- Return const access to target patch face areas
394  inline const scalarField& tgtMagSf() const;
395 
396  //- Return const access to target patch addressing
397  inline const labelListList& tgtAddress() const;
398 
399  //- Return const access to target patch weights
400  inline const scalarListList& tgtWeights() const;
401 
402  //- Return const access to normalisation factor of target
403  // patch weights (i.e. the sum before normalisation)
404  inline const scalarField& tgtWeightsSum() const;
405 
406  //- Target map pointer - valid only if singlePatchProc=-1.
407  // This gets target data into a form to be consumed by
408  // srcAddress, srcWeights
409  inline const mapDistribute& tgtMap() const;
410 
411 
412  // Manipulation
413 
414  //- Update addressing and weights
415  void update
416  (
417  const SourcePatch& srcPatch,
418  const TargetPatch& tgtPatch
419  );
420 
421 
422  // Evaluation
423 
424  // Low-level
425 
426  //- Interpolate from target to source with supplied op
427  // to combine existing value with remote value and weight
428  template<class Type, class CombineOp>
430  (
431  const UList<Type>& fld,
432  const CombineOp& cop,
433  List<Type>& result,
434  const UList<Type>& defaultValues = UList<Type>::null()
435  ) const;
436 
437  //- Interpolate from source to target with supplied op
438  // to combine existing value with remote value and weight
439  template<class Type, class CombineOp>
441  (
442  const UList<Type>& fld,
443  const CombineOp& cop,
444  List<Type>& result,
445  const UList<Type>& defaultValues = UList<Type>::null()
446  ) const;
447 
448 
449  //- Interpolate from target to source with supplied op
450  template<class Type, class CombineOp>
452  (
453  const Field<Type>& fld,
454  const CombineOp& cop,
455  const UList<Type>& defaultValues = UList<Type>::null()
456  ) const;
457 
458  //- Interpolate from target tmp field to source with supplied op
459  template<class Type, class CombineOp>
461  (
462  const tmp<Field<Type> >& tFld,
463  const CombineOp& cop,
464  const UList<Type>& defaultValues = UList<Type>::null()
465  ) const;
466 
467  //- Interpolate from source to target with supplied op
468  template<class Type, class CombineOp>
470  (
471  const Field<Type>& fld,
472  const CombineOp& cop,
473  const UList<Type>& defaultValues = UList<Type>::null()
474  ) const;
475 
476  //- Interpolate from source tmp field to target with supplied op
477  template<class Type, class CombineOp>
479  (
480  const tmp<Field<Type> >& tFld,
481  const CombineOp& cop,
482  const UList<Type>& defaultValues = UList<Type>::null()
483  ) const;
484 
485  //- Interpolate from target to source
486  template<class Type>
488  (
489  const Field<Type>& fld,
490  const UList<Type>& defaultValues = UList<Type>::null()
491  ) const;
492 
493  //- Interpolate from target tmp field
494  template<class Type>
496  (
497  const tmp<Field<Type> >& tFld,
498  const UList<Type>& defaultValues = UList<Type>::null()
499  ) const;
500 
501  //- Interpolate from source to target
502  template<class Type>
504  (
505  const Field<Type>& fld,
506  const UList<Type>& defaultValues = UList<Type>::null()
507  ) const;
508 
509  //- Interpolate from source tmp field
510  template<class Type>
512  (
513  const tmp<Field<Type> >& tFld,
514  const UList<Type>& defaultValues = UList<Type>::null()
515  ) const;
516 
517 
518  // Point intersections
519 
520  //- Return source patch face index of point on target patch face
522  (
523  const SourcePatch& srcPatch,
524  const TargetPatch& tgtPatch,
525  const vector& n,
526  const label tgtFaceI,
527  point& tgtPoint
528  )
529  const;
530 
531  //- Return target patch face index of point on source patch face
533  (
534  const SourcePatch& srcPatch,
535  const TargetPatch& tgtPatch,
536  const vector& n,
537  const label srcFaceI,
538  point& srcPoint
539  )
540  const;
541 
542 
543  // Checks
544 
545  //- Write face connectivity as OBJ file
547  (
548  const SourcePatch& srcPatch,
549  const TargetPatch& tgtPatch,
551  ) const;
552 };
553 
554 
555 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
556 
557 } // End namespace Foam
558 
559 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
560 
561 #include "AMIInterpolationI.H"
562 
563 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
564 
565 #ifdef NoRepository
566 # include "AMIInterpolation.C"
568 #endif
569 
570 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
571 
572 #endif
573 
574 // ************************************************************************* //
bool applyLowWeightCorrection() const
Return true if employing a &#39;lowWeightCorrection&#39;.
const pointField & points
Base class of (analytical or triangulated) surface. Encapsulates all the search routines. WIP.
Class containing processor-to-processor mapping information.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
Definition: globalIndex.H:63
A class for handling words, derived from string.
Definition: word.H:59
const scalarField & tgtWeightsSum() const
Return const access to normalisation factor of target.
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
Standard boundBox + extra functionality for use in octree.
Definition: treeBoundBox.H:75
scalar lowWeightCorrection() const
Threshold weight below which interpolation is deactivated.
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.
void update(const SourcePatch &srcPatch, const TargetPatch &tgtPatch)
Update addressing and weights.
const labelListList & tgtAddress() const
Return const access to target patch addressing.
Namespace for OpenFOAM.
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.
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.
label n
interpolationMethod
Enumeration specifying interpolation method.
const mapDistribute & tgtMap() const
Target map pointer - valid only if singlePatchProc=-1.
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.
const scalarListList & tgtWeights() const
Return const access to target patch weights.
Macro definitions for declaring ClassName(), NamespaceName(), etc.
const scalarField & srcMagSf() const
Return const access to source patch face areas.
~AMIInterpolation()
Destructor.
const labelListList & srcAddress() const
Return const access to source patch addressing.
Interpolation class dealing with transfer of data between two primitive patches with an arbitrary mes...
label singlePatchProc() const
Set to -1, or the processor holding all faces (both sides) of.
const scalarListList & srcWeights() const
Return const access to source patch weights.
const mapDistribute & srcMap() const
Source map pointer - valid only if singlePatchProc = -1.
static word interpolationMethodToWord(const interpolationMethod &method)
Convert interpolationMethod to word representation.
const scalarField & tgtMagSf() const
Return const access to target patch face areas.
const scalarField & srcWeightsSum() const
Return const access to normalisation factor of source.
TemplateName(blendedSchemeBase)
Combination-Reduction operation for a parallel run.
static interpolationMethod wordTointerpolationMethod(const word &method)
Convert word to interpolationMethod.
void writeFaceConnectivity(const SourcePatch &srcPatch, const TargetPatch &tgtPatch, const labelListList &srcAddress) const
Write face connectivity as OBJ file.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
A class for managing temporary objects.
Definition: PtrList.H:118