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  (
42  new GeoField
43  (
44  IOobject
45  (
46  "uniformInterpolate(" + field0.name() + ')',
47  field0.time().timeName(),
48  field0.db(),
49  IOobject::NO_READ,
50  IOobject::AUTO_WRITE
51  ),
52  weights[0]*(*fields[indices[0]])
53  )
54  );
55  GeoField& fld = tfld();
56 
57  for (label i = 1; i < indices.size(); ++i)
58  {
59  fld += weights[i]*(*fields[indices[i]]);
60  }
61 
62  return tfld;
63 }
64 
65 
66 template<class GeoField>
68 (
69  const IOobject& fieldIO,
70  const word& fieldName,
71  const wordList& times,
72  const scalarField& weights,
73  const objectRegistry& fieldsCache
74 )
75 {
76  // Look up the first field
77  const objectRegistry& time0Fields = fieldsCache.lookupObject
78  <
79  const objectRegistry
80  >
81  (
82  times[0]
83  );
84  const GeoField& field0 = time0Fields.lookupObject
85  <
86  const GeoField
87  >
88  (
89  fieldName
90  );
91 
92 
93  // Interpolate
94  tmp<GeoField> tfld(new GeoField(fieldIO, weights[0]*field0));
95  GeoField& fld = tfld.ref();
96 
97  for (label i = 1; i < times.size(); ++i)
98  {
99  const objectRegistry& timeIFields = fieldsCache.lookupObject
100  <
101  const objectRegistry
102  >
103  (
104  times[i]
105  );
106  const GeoField& fieldi = timeIFields.lookupObject
107  <
108  const GeoField
109  >
110  (
111  fieldName
112  );
113 
114  fld += weights[i]*fieldi;
115  }
116 
117  return tfld;
118 }
119 
120 
121 template<class GeoField>
123 (
124  const IOobject& fieldIO,
125  const word& fieldName,
126  const wordList& times,
127  const scalarField& weights,
128  const word& registryName
129 )
130 {
131  return uniformInterpolate<GeoField>
132  (
133  fieldIO,
134  fieldName,
135  times,
136  weights,
137  fieldIO.db().subRegistry(registryName, true)
138  );
139 }
140 
141 
142 // ************************************************************************* //
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
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