pointToPointPlanarInterpolationTemplates.C
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) 2012-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 \*---------------------------------------------------------------------------*/
28 
30 
31 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32 
33 template<class Type>
36 (
37  const Field<Type>& sourceFld
38 ) const
39 {
40  if (nPoints_ != sourceFld.size())
41  {
43  << "Number of source points = " << nPoints_
44  << " number of values = " << sourceFld.size()
45  << exit(FatalError);
46  }
47 
48  auto tfld = tmp<Field<Type>>::New(nearestVertex_.size());
49  auto& fld = tfld.ref();
50 
51  forAll(fld, i)
52  {
53  const FixedList<label, 3>& verts = nearestVertex_[i];
54  const FixedList<scalar, 3>& w = nearestVertexWeight_[i];
55 
56  if (verts[1] == -1)
57  {
58  // Use vertex (0) only
59  fld[i] = sourceFld[verts[0]];
60  }
61  else if (verts[2] == -1)
62  {
63  // Use vertex (0,1)
64  fld[i] =
65  (
66  w[0]*sourceFld[verts[0]]
67  + w[1]*sourceFld[verts[1]]
68  );
69  }
70  else
71  {
72  // Use vertex (0,1,2)
73  fld[i] =
74  (
75  w[0]*sourceFld[verts[0]]
76  + w[1]*sourceFld[verts[1]]
77  + w[2]*sourceFld[verts[2]]
78  );
79  }
80  }
81  return tfld;
82 }
83 
84 
85 template<class Type>
88 (
89  const tmp<Field<Type>>& tsource
90 ) const
91 {
92  tmp<Field<Type>> tresult = this->interpolate(tsource());
93  tsource.clear();
94 
95  return tresult;
96 }
97 
98 
99 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
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
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
Generic templated field type.
Definition: Field.H:62
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
tmp< Field< Type > > interpolate(const Field< Type > &sourceFld) const
Interpolate from field on source points to dest points.
A class for managing temporary objects.
Definition: HashPtrTable.H:50