interpolation.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-2025 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::interpolation
26 
27 Description
28  Abstract base class for interpolation
29 
30 SourceFiles
31  interpolation.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef interpolation_H
36 #define interpolation_H
37 
38 #include "autoPtr.H"
39 #include "tetIndices.H"
40 #include "volFieldsFwd.H"
41 #include "runTimeSelectionTables.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 namespace Foam
46 {
47 
48 /*---------------------------------------------------------------------------*\
49  Typedef interpolationGradType Declaration
50 \*---------------------------------------------------------------------------*/
51 
52 template<class Type>
54 
55 
56 /*---------------------------------------------------------------------------*\
57  Class interpolationBase Declaration
58 \*---------------------------------------------------------------------------*/
59 
60 template<class Type>
62 {
63 protected:
64 
65  // Protected data
66 
67  //- The vol field to interpolate
68  const VolField<Type>& psi_;
69 
70  //- Reference to the mesh
71  const polyMesh& mesh_;
72 
73 
74 public:
75 
76  // Constructors
77 
78  //- Construct from components
80 
81  //- Copy constructor
83 
84 
85  //- Destructor
86  virtual ~interpolationBase();
87 
88 
89  // Member Functions
90 
91  //- Return the field to be interpolated
92  const VolField<Type>& psi() const
93  {
94  return psi_;
95  }
96 
97  //- Interpolate to the given point in the given cell
98  virtual Type interpolate
99  (
100  const vector& position,
101  const label celli,
102  const label facei = -1
103  ) const = 0;
104 
105  //- As above, but for a field
107  (
108  const vectorField& position,
109  const labelList& celli,
110  const labelList& facei = NullObjectRef<labelList>()
111  ) const = 0;
112 
113  //- Interpolate to the given coordinates in the
114  // tetrahedron defined by the given indices. Calls interpolate
115  // function above here except where overridden by derived
116  // interpolation types.
117  virtual Type interpolate
118  (
119  const barycentric& coordinates,
120  const tetIndices& tetIs,
121  const label facei = -1
122  ) const;
123 
124  //- As above, but for a field
126  (
128  const labelList& celli,
129  const labelList& tetFacei,
130  const labelList& tetPti,
131  const labelList& facei = NullObjectRef<labelList>()
132  ) const = 0;
133 };
134 
135 
136 /*---------------------------------------------------------------------------*\
137  Class interpolationGradBase Declaration
138 \*---------------------------------------------------------------------------*/
139 
140 template<class Type>
142 :
143  public interpolationBase<Type>
144 {
145 protected:
146 
147  // Protected Type Definitions
148 
149  //- The type of the interpolated gradient
151 
152 
153 public:
154 
155  //- Runtime type information
156  virtual const word& type() const = 0;
157 
158 
159  // Constructors
160 
161  //- Inherit base class constructors
163 
164 
165  //- Destructor
166  virtual ~interpolationGradBase();
167 
168 
169  // Member Functions
170 
171  //- Interpolate the gradient to the given point in the given cell.
172  // Fails with a "not supported" error unless overridden by derived
173  // interpolation types.
175  (
176  const vector& position,
177  const label celli,
178  const label facei = -1
179  ) const;
180 
181  //- As above, but for a field
183  (
184  const vectorField& position,
185  const labelList& celli,
186  const labelList& facei = NullObjectRef<labelList>()
187  ) const = 0;
188 
189  //- Interpolate the gradient to the given coordinates in the
190  // tetrahedron defined by the given indices. Calls interpolateGrad
191  // function above here except where overridden by derived
192  // interpolation types.
194  (
195  const barycentric& coordinates,
196  const tetIndices& tetIs,
197  const label facei = -1
198  ) const;
199 
200  //- As above, but for a field
202  (
204  const labelList& celli,
205  const labelList& tetFacei,
206  const labelList& tetPti,
207  const labelList& facei = NullObjectRef<labelList>()
208  ) const = 0;
209 };
210 
211 
212 /*---------------------------------------------------------------------------*\
213  Typedef interpolationBaseOrGradBase Declaration
214 \*---------------------------------------------------------------------------*/
215 
216 template<class Type>
218  typename std::conditional
219  <
220  (pTraits<Type>::rank > 1),
223  >::type;
224 
225 
226 /*---------------------------------------------------------------------------*\
227  Class interpolation Declaration
228 \*---------------------------------------------------------------------------*/
229 
230 template<class Type>
231 class interpolation
232 :
233  public interpolationBaseOrGradBase<Type>
234 {
235  // Private Type Definitions
236 
237  //- The base class
239 
240 
241 public:
242 
243  //- Runtime type information
244  TypeName("interpolation");
245 
246 
247  // Declare run-time constructor selection table
248 
250  (
251  autoPtr,
253  dictionary,
254  (const VolField<Type>& psi),
255  (psi)
256  );
257 
258 
259  // Selectors
260 
261  //- Return a reference to the specified interpolation scheme
263  (
264  const word& interpolationType,
265  const VolField<Type>& psi
266  );
267 
268  //- Return a reference to the selected interpolation scheme
270  (
271  const dictionary& interpolationSchemes,
272  const VolField<Type>& psi
273  );
274 
275 
276  // Constructors
277 
278  //- Inherit base class constructors
279  using Base::Base;
280 
281  //- Clone
282  virtual autoPtr<interpolation<Type>> clone() const = 0;
283 
284 
285  //- Destructor
286  virtual ~interpolation();
287 };
288 
289 
290 /*---------------------------------------------------------------------------*\
291  Class fieldInterpolationBase Declaration
292 \*---------------------------------------------------------------------------*/
293 
294 template<class Type, class InterpolationType>
296 :
297  public interpolation<Type>
298 {
299 public:
300 
301  // Constructors
302 
303  //- Inherit base class constructors
305 
306 
307  // Member Functions
308 
309  //- Inherit non-field interpolation methods
311 
312  //- Interpolate to the points in the given cells
314  (
315  const vectorField& position,
316  const labelList& celli,
317  const labelList& facei = NullObjectRef<labelList>()
318  ) const;
319 
320  //- Interpolate to the coordinates in the given tetrahedra
322  (
324  const labelList& celli,
325  const labelList& tetFacei,
326  const labelList& tetPti,
327  const labelList& facei = NullObjectRef<labelList>()
328  ) const;
329 };
330 
331 
332 /*---------------------------------------------------------------------------*\
333  Class fieldInterpolationGradBase Declaration
334 \*---------------------------------------------------------------------------*/
335 
336 template<class Type, class InterpolationType>
338 :
339  public fieldInterpolationBase<Type, InterpolationType>
340 {
341 public:
342 
343  // Constructors
344 
345  //- Inherit base class constructors
346  using
348  fieldInterpolationBase;
349 
350 
351  // Member Functions
352 
353  //- Inherit non-field gradient interpolation methods
355 
356  //- Interpolate the gradient to the points in the given cells
358  (
359  const vectorField& position,
360  const labelList& celli,
361  const labelList& facei = NullObjectRef<labelList>()
362  ) const;
363 
364  //- Interpolate the gradient to the coordinates in the given tetrahedra
366  (
368  const labelList& celli,
369  const labelList& tetFacei,
370  const labelList& tetPti,
371  const labelList& facei = NullObjectRef<labelList>()
372  ) const;
373 };
374 
375 
376 /*---------------------------------------------------------------------------*\
377  Typedef fieldInterpolationBaseOrGradBase Declaration
378 \*---------------------------------------------------------------------------*/
379 
380 template<class Type, class InterpolationType>
382  typename std::conditional
383  <
384  (pTraits<Type>::rank > 1),
387  >::type;
388 
389 
390 /*---------------------------------------------------------------------------*\
391  Class fieldInterpolation Declaration
392 \*---------------------------------------------------------------------------*/
393 
394 template<class Type, class InterpolationType>
395 class fieldInterpolation
396 :
397  public fieldInterpolationBaseOrGradBase<Type, InterpolationType>
398 {
399  // Private Type Definitions
400 
401  //- The base class
403 
404 
405 public:
406 
407  // Constructors
408 
409  //- Inherit base class constructors
410  using Base::Base;
411 };
412 
413 
414 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
415 
416 } // End namespace Foam
417 
418 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
419 
420 #define makeInterpolation(Type, InterpolationType) \
421  \
422  defineNamedTemplateTypeNameAndDebug(InterpolationType<Type>, 0); \
423  \
424  addTemplatedToRunTimeSelectionTable \
425  ( \
426  interpolation, \
427  InterpolationType, \
428  Type, \
429  dictionary \
430  );
431 
432 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
433 
434 #ifdef NoRepository
435  #include "interpolation.C"
436 #endif
437 
438 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439 
440 #endif
441 
442 // ************************************************************************* //
Generic GeometricField class.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: autoPtr.H:51
A list of keywords followed by any number of values (e.g. words and numbers) or sub-dictionaries.
Definition: dictionary.H:162
virtual tmp< Field< Type > > interpolate(const vectorField &position, const labelList &celli, const labelList &facei=NullObjectRef< labelList >()) const
Interpolate to the points in the given cells.
virtual tmp< Field< interpolationGradType< Type > > > interpolateGrad(const vectorField &position, const labelList &celli, const labelList &facei=NullObjectRef< labelList >()) const
Interpolate the gradient to the points in the given cells.
virtual ~interpolationBase()
Destructor.
Definition: interpolation.C:89
const VolField< Type > & psi() const
Return the field to be interpolated.
Definition: interpolation.H:91
const VolField< Type > & psi_
The vol field to interpolate.
Definition: interpolation.H:67
interpolationBase(const VolField< Type > &psi)
Construct from components.
Definition: interpolation.C:31
const polyMesh & mesh_
Reference to the mesh.
Definition: interpolation.H:70
virtual Type interpolate(const vector &position, const label celli, const label facei=-1) const =0
Interpolate to the given point in the given cell.
virtual const word & type() const =0
Runtime type information.
outerProduct< Type, vector >::type GradType
The type of the interpolated gradient.
virtual ~interpolationGradBase()
Destructor.
Definition: interpolation.C:94
virtual interpolationGradType< Type > interpolateGrad(const vector &position, const label celli, const label facei=-1) const
Interpolate the gradient to the given point in the given cell.
Abstract base class for interpolation.
static autoPtr< interpolation< Type > > New(const word &interpolationType, const VolField< Type > &psi)
Return a reference to the specified interpolation scheme.
Definition: interpolation.C:53
virtual autoPtr< interpolation< Type > > clone() const =0
Clone.
virtual ~interpolation()
Destructor.
Definition: interpolation.C:99
declareRunTimeSelectionTable(autoPtr, interpolation, dictionary,(const VolField< Type > &psi),(psi))
TypeName("interpolation")
Runtime type information.
typeOfRank< typename pTraits< arg1 >::cmptType, direction(pTraits< arg1 >::rank)+direction(pTraits< arg2 >::rank) >::type type
Definition: products.H:90
Traits class for primitives.
Definition: pTraits.H:53
Mesh consisting of general polyhedral cells.
Definition: polyMesh.H:78
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
A class for managing temporary objects.
Definition: tmp.H:55
A class for handling words, derived from string.
Definition: word.H:63
const volScalarField & psi
barycentric coordinates(const polyMesh &mesh, const point &position, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the coordinates given the position and tet topology.
Definition: tracking.C:1258
point position(const polyMesh &mesh, const barycentric &coordinates, const label celli, const label facei, const label faceTrii, const scalar stepFraction)
Return the position given the coordinates and tet topology.
Definition: trackingI.H:224
Namespace for OpenFOAM.
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
typename outerProduct< Type, vector >::type interpolationGradType
Definition: interpolation.H:52
typename std::conditional<(pTraits< Type >::rank > 1), fieldInterpolationBase< Type, InterpolationType >, fieldInterpolationGradBase< Type, InterpolationType > >::type fieldInterpolationBaseOrGradBase
typename std::conditional<(pTraits< Type >::rank > 1), interpolationBase< Type >, interpolationGradBase< Type > >::type interpolationBaseOrGradBase
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488
Macros to ease declaration of run-time selection tables.