PatchToPatchInterpolation.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-2016 OpenFOAM Foundation
9  Copyright (C) 2022 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::PatchToPatchInterpolation
29 
30 Description
31  Interpolation class dealing with transfer of data between two
32  primitivePatches
33 
34 SourceFiles
35  PatchToPatchInterpolation.C
36  PatchToPatchInterpolate.C
37  CalcPatchToPatchWeights.C
38 
39 \*---------------------------------------------------------------------------*/
40 
41 #ifndef Foam_PatchToPatchInterpolation_H
42 #define Foam_PatchToPatchInterpolation_H
43 
44 #include "className.H"
45 #include "labelList.H"
46 #include "scalarField.H"
47 #include "pointField.H"
48 #include "FieldFields.H"
49 #include "faceList.H"
50 #include "intersection.H"
51 
52 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 
54 namespace Foam
55 {
56 
57 /*---------------------------------------------------------------------------*\
58  Class PatchToPatchInterpolationBase Declaration
59 \*---------------------------------------------------------------------------*/
60 
62 {
63 protected:
64 
65  // Protected Static Data
66 
67  //- Relative merge tolerance for projected points missing the target
68  // Expressed as the fraction of min involved edge size
69  static scalar projectionTol_;
70 
71  //- Direct hit tolerance
72  static const scalar directHitTol;
73 
74 
75 public:
76 
77  //- Runtime type information
78  ClassName("PatchToPatchInterpolation");
79 
80 
81  // Constructors
82 
83  //- Default construct
85 
86 
87  // Member Functions
88 
89  //- Access to projection tolerance
90  static scalar projectionTol() noexcept
91  {
92  return projectionTol_;
93  }
94 
95  //- Change propagation tolerance, return previous value
96  static scalar setProjectionTol(const scalar tol)
97  {
98  if (tol < -VSMALL)
99  {
101  }
102  scalar old(projectionTol_);
103  projectionTol_ = tol;
104  return old;
105  }
106 };
107 
108 
109 /*---------------------------------------------------------------------------*\
110  Class PatchToPatchInterpolation Declaration
111 \*---------------------------------------------------------------------------*/
112 
113 template<class FromPatch, class ToPatch>
114 class PatchToPatchInterpolation
115 :
116  public PatchToPatchInterpolationBase
117 {
118  // Private Data
119 
120  //- Reference to the source patch
121  const FromPatch& fromPatch_;
123  //- Reference to the target patch
124  const ToPatch& toPatch_;
125 
126  //- Type of intersection algorithm to use in projection
128 
129  //- Direction projection to use in projection
131 
132 
133  // Point Addressing
134 
135  //- Face into which each point of target patch is projected
136  mutable std::unique_ptr<labelList> pointAddressingPtr_;
137 
138  //- Weighting factors
139  mutable std::unique_ptr<FieldField<Field, scalar>> pointWeightsPtr_;
140 
141  //- Distance to intersection for patch points
142  mutable std::unique_ptr<scalarField> pointDistancePtr_;
143 
144 
145  // Face Addressing
146 
147  //- Face into which each face centre of target patch is projected
148  mutable std::unique_ptr<labelList> faceAddressingPtr_;
149 
150  //- Weighting factors
151  mutable std::unique_ptr<FieldField<Field, scalar>> faceWeightsPtr_;
152 
153  //- Distance to intersection for patch face centres
154  mutable std::unique_ptr<scalarField> faceDistancePtr_;
155 
156 
157  // Private Member Functions
158 
159  //- No copy construct
161 
162  //- No copy assignment
163  void operator=(const PatchToPatchInterpolation&) = delete;
164 
165  //- Calculate point weights
166  void calcPointAddressing() const;
167 
168  //- Calculate face weights
169  void calcFaceAddressing() const;
170 
171  //- Clear all geometry and addressing
172  void clearOut();
173 
174 
175  //- Return reference to point addressing
176  const labelList& pointAddr() const;
177 
178  //- Return reference to point weights
179  const FieldField<Field, scalar>& pointWeights() const;
180 
181  //- Return reference to face addressing
182  const labelList& faceAddr() const;
183 
184  //- Return reference to face weights
185  const FieldField<Field, scalar>& faceWeights() const;
186 
187 
188 public:
189 
190  // Constructors
191 
192  //- Construct from components
194  (
195  const FromPatch& fromPatch,
196  const ToPatch& toPatch,
199  );
200 
201 
202  //- Destructor
204 
205 
206  // Member Functions
207 
208  //- Return ype of intersection algorithm to use in projection
210  {
211  return alg_;
212  }
213 
214  //- Return direction projection to use in projection
216  {
217  return dir_;
218  }
219 
220  //- Return distance to intersection for patch points
222 
223  //- Return distance to intersection for patch face centres
225 
226  //- Correct weighting factors for moving mesh.
227  bool movePoints();
228 
229 
230  //- Interpolate point field
231  template<class Type>
232  tmp<Field<Type>> pointInterpolate(const Field<Type>& pf) const;
233 
234  template<class Type>
235  tmp<Field<Type>> pointInterpolate(const tmp<Field<Type>>& tpf) const;
236 
237  //- Interpolate face field
238  template<class Type>
239  tmp<Field<Type>> faceInterpolate(const Field<Type>& pf) const;
240 
241  template<class Type>
242  tmp<Field<Type>> faceInterpolate(const tmp<Field<Type>>& tpf) const;
243 
244 };
245 
246 
247 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
248 
249 } // End namespace Foam
250 
251 #ifdef NoRepository
252  #include "PatchToPatchInterpolation.C"
253 #endif
254 
255 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 
257 #endif
258 
259 // ************************************************************************* //
static const scalar directHitTol
Direct hit tolerance.
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
ClassName("PatchToPatchInterpolation")
Runtime type information.
const scalarField & faceDistanceToIntersection() const
Return distance to intersection for patch face centres.
const scalarField & pointDistanceToIntersection() const
Return distance to intersection for patch points.
tmp< Field< Type > > pointInterpolate(const Field< Type > &pf) const
Interpolate point field.
A field of fields is a PtrList of fields with reference counting.
Definition: FieldField.H:51
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
errorManip< error > abort(error &err)
Definition: errorManip.H:139
intersection::direction projectionDir() const
Return direction projection to use in projection.
intersection::algorithm projectionAlgo() const
Return ype of intersection algorithm to use in projection.
const direction noexcept
Definition: Scalar.H:258
static scalar setProjectionTol(const scalar tol)
Change propagation tolerance, return previous value.
Macro definitions for declaring ClassName(), NamespaceName(), etc.
bool movePoints()
Correct weighting factors for moving mesh.
static scalar projectionTol_
Relative merge tolerance for projected points missing the target.
tmp< Field< Type > > faceInterpolate(const Field< Type > &pf) const
Interpolate face field.
static scalar projectionTol() noexcept
Access to projection tolerance.
Interpolation class dealing with transfer of data between two primitivePatches.
Namespace for OpenFOAM.
PatchToPatchInterpolationBase() noexcept=default
Default construct.