uniformInterpolate.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 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
28 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
29 
30 template<class GeoField>
32 (
33  const HashPtrTable<GeoField, label, Hash<label>>& fields,
34  const labelList& indices,
35  const scalarField& weights
36 )
37 {
38  const GeoField& field0 = *(*fields.begin());
39 
40  // Interpolate
41  auto tfld = tmp<GeoField>::New
42  (
43  IOobject
44  (
45  "uniformInterpolate(" + field0.name() + ')',
46  field0.time().timeName(),
47  field0.db(),
48  IOobject::NO_READ,
49  IOobject::AUTO_WRITE
50  ),
51  weights[0]*(*fields[indices[0]])
52  );
53  auto& fld = tfld();
54 
55  for (label i = 1; i < indices.size(); ++i)
56  {
57  fld += weights[i]*(*fields[indices[i]]);
58  }
59 
60  return tfld;
61 }
62 
63 
64 template<class GeoField>
66 (
67  const IOobject& fieldIO,
68  const word& fieldName,
69  const wordList& times,
70  const scalarField& weights,
71  const objectRegistry& fieldsCache
72 )
73 {
74  // Look up the first field
75  const objectRegistry& time0Fields = fieldsCache.lookupObject
76  <
77  const objectRegistry
78  >
79  (
80  times[0]
81  );
82  const GeoField& field0 = time0Fields.lookupObject
83  <
84  const GeoField
85  >
86  (
87  fieldName
88  );
89 
90 
91  // Interpolate
92  auto tfld = tmp<GeoField>::New(fieldIO, weights[0]*field0);
93  GeoField& fld = tfld.ref();
94 
95  for (label i = 1; i < times.size(); ++i)
96  {
97  const objectRegistry& timeIFields =
98  fieldsCache.lookupObject<const objectRegistry>(times[i]);
99 
100  const GeoField& fieldi =
101  timeIFields.lookupObject<const GeoField>(fieldName);
102 
103  fld += weights[i]*fieldi;
104  }
105 
106  return tfld;
107 }
108 
109 
110 template<class GeoField>
112 (
113  const IOobject& fieldIO,
114  const word& fieldName,
115  const wordList& times,
116  const scalarField& weights,
117  const word& registryName
118 )
119 {
120  return uniformInterpolate<GeoField>
121  (
122  fieldIO,
123  fieldName,
124  times,
125  weights,
126  fieldIO.db().subRegistry(registryName, true)
127  );
128 }
129 
130 
131 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:67
Foam::scalarField
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Definition: primitiveFieldsFwd.H:52
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:62
fld
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))
Definition: gmvOutputLagrangian.H:23
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::uniformInterpolate
tmp< GeoField > uniformInterpolate(const HashPtrTable< GeoField, label, Hash< label >> &fields, const labelList &indices, const scalarField &weights)
Interpolate selected fields (given by indices and corresponding weights)
fields
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97