uniformInterpolate.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) 2012-2018 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 
27 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
28 
29 template<class GeoField>
31 (
32  const HashPtrTable<GeoField, label, Hash<label>>& fields,
33  const labelList& indices,
34  const scalarField& weights
35 )
36 {
37  const GeoField& field0 = *(*fields.begin());
38 
39  // Interpolate
40  tmp<GeoField> tfld
41  (
43  (
44  "uniformInterpolate(" + field0.name() + ')',
45  weights[0]*(*fields[indices[0]])
46  )
47  );
48  GeoField& fld = tfld();
49 
50  for (label i = 1; i < indices.size(); ++i)
51  {
52  fld += weights[i]*(*fields[indices[i]]);
53  }
54 
55  return tfld;
56 }
57 
58 
59 template<class GeoField>
61 (
62  const IOobject& fieldIO,
63  const word& fieldName,
64  const wordList& times,
65  const scalarField& weights,
66  const objectRegistry& fieldsCache
67 )
68 {
69  // Look up the first field
70  const objectRegistry& time0Fields = fieldsCache.lookupObject
71  <
72  const objectRegistry
73  >
74  (
75  times[0]
76  );
77  const GeoField& field0 = time0Fields.lookupObject
78  <
79  const GeoField
80  >
81  (
82  fieldName
83  );
84 
85 
86  // Interpolate
87  tmp<GeoField> tfld(GeoField::New(fieldIO.name(), weights[0]*field0));
88  GeoField& fld = tfld.ref();
89 
90  for (label i = 1; i < times.size(); ++i)
91  {
92  const objectRegistry& timeIFields = fieldsCache.lookupObject
93  <
94  const objectRegistry
95  >
96  (
97  times[i]
98  );
99  const GeoField& fieldi = timeIFields.lookupObject
100  <
101  const GeoField
102  >
103  (
104  fieldName
105  );
106 
107  fld += weights[i]*fieldi;
108  }
109 
110  return tfld;
111 }
112 
113 
114 template<class GeoField>
116 (
117  const IOobject& fieldIO,
118  const word& fieldName,
119  const wordList& times,
120  const scalarField& weights,
121  const word& registryName
122 )
123 {
124  return uniformInterpolate<GeoField>
125  (
126  fieldIO,
127  fieldName,
128  times,
129  weights,
130  fieldIO.db().subRegistry(registryName, true)
131  );
132 }
133 
134 
135 // ************************************************************************* //
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
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)
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
List< label > labelList
A List of labels.
Definition: labelList.H:56
volScalarField scalarField(fieldObject, mesh)
List< word > wordList
A List of words.
Definition: fileName.H:54
A class for managing temporary objects.
Definition: PtrList.H:53