interpolation.C
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 \*---------------------------------------------------------------------------*/
25 
26 #include "interpolation.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 :
33  psi_(psi),
34  mesh_(psi.mesh())
35 {}
36 
37 
38 template<class Type>
40 (
42 )
43 :
44  psi_(i.psi_),
45  mesh_(i.mesh_)
46 {}
47 
48 
49 // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
50 
51 template<class Type>
53 (
54  const word& interpolationType,
55  const VolField<Type>& psi
56 )
57 {
58  typename dictionaryConstructorTable::iterator cstrIter =
59  dictionaryConstructorTablePtr_->find(interpolationType);
60 
61  if (cstrIter == dictionaryConstructorTablePtr_->end())
62  {
64  << "Unknown interpolation type " << interpolationType
65  << " for field " << psi.name() << nl << nl
66  << "Valid interpolation types : " << endl
67  << dictionaryConstructorTablePtr_->sortedToc()
68  << exit(FatalError);
69  }
70 
71  return autoPtr<interpolation<Type>>(cstrIter()(psi));
72 }
73 
74 
75 template<class Type>
77 (
78  const dictionary& interpolationSchemes,
79  const VolField<Type>& psi
80 )
81 {
82  return New(word(interpolationSchemes.lookup(psi.name())), psi);
83 }
84 
85 
86 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
87 
88 template<class Type>
90 {}
91 
92 
93 template<class Type>
95 {}
96 
97 
98 template<class Type>
100 {}
101 
102 
103 // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
104 
105 template<class Type>
107 (
108  const barycentric& coordinates,
109  const tetIndices& tetIs,
110  const label facei
111 ) const
112 {
113  return
115  (
116  tetIs.tet(this->mesh_).barycentricToPoint(coordinates),
117  tetIs.cell(),
118  facei
119  );
120 }
121 
122 
123 template<class Type>
126 (
127  const vector& position,
128  const label celli,
129  const label facei
130 ) const
131 {
133  << "Interpolation method " << type() << " for field "
134  << this->psi_.name() << " does not support gradient interpolation"
135  << exit(FatalError);
136 
138 }
139 
140 
141 template<class Type>
144 (
145  const barycentric& coordinates,
146  const tetIndices& tetIs,
147  const label facei
148 ) const
149 {
150  return
151  interpolateGrad
152  (
153  tetIs.tet(this->mesh_).barycentricToPoint(coordinates),
154  tetIs.cell(),
155  facei
156  );
157 }
158 
159 
160 template<class Type, class InterpolationType>
163 (
164  const vectorField& position,
165  const labelList& celli,
166  const labelList& facei
167 ) const
168 {
169  tmp<Field<Type>> tField(new Field<Type>(position.size()));
170 
171  Field<Type>& field = tField.ref();
172 
173  forAll(field, i)
174  {
175  field[i] =
176  static_cast<const InterpolationType&>(*this).interpolate
177  (
178  position[i],
179  celli[i],
180  isNull(facei) ? -1 : facei[i]
181  );
182  }
183 
184  return tField;
185 }
186 
187 
188 template<class Type, class InterpolationType>
191 (
193  const labelList& celli,
194  const labelList& tetFacei,
195  const labelList& tetPti,
196  const labelList& facei
197 ) const
198 {
200 
201  Field<Type>& field = tField.ref();
202 
203  forAll(field, i)
204  {
205  field[i] =
206  static_cast<const InterpolationType&>(*this).interpolate
207  (
208  coordinates[i],
209  tetIndices(celli[i], tetFacei[i], tetPti[i]),
210  isNull(facei) ? -1 : facei[i]
211  );
212  }
213 
214  return tField;
215 }
216 
217 
218 template<class Type, class InterpolationType>
221 (
222  const vectorField& position,
223  const labelList& celli,
224  const labelList& facei
225 ) const
226 {
228  (
230  );
231 
232  Field<interpolationGradType<Type>>& field = tField.ref();
233 
234  forAll(field, i)
235  {
236  field[i] =
237  static_cast<const InterpolationType&>(*this).interpolateGrad
238  (
239  position[i],
240  celli[i],
241  isNull(facei) ? -1 : facei[i]
242  );
243  }
244 
245  return tField;
246 }
247 
248 
249 template<class Type, class InterpolationType>
252 (
254  const labelList& celli,
255  const labelList& tetFacei,
256  const labelList& tetPti,
257  const labelList& facei
258 ) const
259 {
261  (
263  );
264 
265  Field<interpolationGradType<Type>>& field = tField.ref();
266 
267  forAll(field, i)
268  {
269  field[i] =
270  static_cast<const InterpolationType&>(*this).interpolateGrad
271  (
272  coordinates[i],
273  tetIndices(celli[i], tetFacei[i], tetPti[i]),
274  isNull(facei) ? -1 : facei[i]
275  );
276  }
277 
278  return tField;
279 }
280 
281 
282 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
Generic GeometricField class.
const word & name() const
Return name.
Definition: IOobject.H:307
static direction size()
Return the number of elements in the VectorSpace = Ncmpts.
Definition: VectorSpaceI.H:83
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
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.
Definition: dictionary.C:669
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
interpolationBase(const VolField< Type > &psi)
Construct from components.
Definition: interpolation.C:31
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 ~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.
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 ~interpolation()
Destructor.
Definition: interpolation.C:99
Traits class for primitives.
Definition: pTraits.H:53
Storage and named access for the indices of a tet which is part of the decomposition of a cell.
Definition: tetIndices.H:82
label cell() const
Return the cell.
Definition: tetIndicesI.H:31
tetPointRef tet(const polyMesh &mesh, const pointField &meshPoints, const pointField &cellCentres) const
Return the geometry corresponding to this tet and the given.
Definition: tetIndicesI.H:109
Point barycentricToPoint(const barycentric &bary) const
Calculate the point from the given barycentric coordinates.
Definition: tetrahedronI.H:245
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:197
A class for handling words, derived from string.
Definition: word.H:63
Foam::fvMesh mesh(Foam::IOobject(regionName, runTime.name(), runTime, Foam::IOobject::MUST_READ), false)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
const volScalarField & psi
static tmp< SurfaceField< Type > > interpolate(const VolField< Type > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
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
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
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
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:288
typename outerProduct< Type, vector >::type interpolationGradType
Definition: interpolation.H:52
bool isNull(const T &t)
Return true if t is a reference to the nullObject of type T.
Definition: nullObjectI.H:58
error FatalError
tmp< DimensionedField< TypeR, GeoMesh, Field > > New(const tmp< DimensionedField< TypeR, GeoMesh, Field >> &tdf1, const word &name, const dimensionSet &dimensions)
static const char nl
Definition: Ostream.H:297
fileType type(const fileName &, const bool checkVariants=true, const bool followLink=true)
Return the file type: directory or file.
Definition: POSIX.C:488