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  IOobject::REGISTER
51  ),
52  weights[0]*(*fields[indices[0]])
53  );
54  auto& fld = tfld();
55 
56  for (label i = 1; i < indices.size(); ++i)
57  {
58  fld += weights[i]*(*fields[indices[i]]);
59  }
60 
61  return tfld;
62 }
63 
64 
65 template<class GeoField>
67 (
68  const IOobject& fieldIO,
69  const word& fieldName,
70  const wordList& times,
71  const scalarField& weights,
72  const objectRegistry& fieldsCache
73 )
74 {
75  // Look up the first field
76  const objectRegistry& time0Fields = fieldsCache.lookupObject
77  <
78  const objectRegistry
79  >
80  (
81  times[0]
82  );
83  const GeoField& field0 = time0Fields.lookupObject
84  <
85  const GeoField
86  >
87  (
88  fieldName
89  );
90 
91 
92  // Interpolate
93  auto tfld = tmp<GeoField>::New(fieldIO, weights[0]*field0);
94  GeoField& fld = tfld.ref();
95 
96  for (label i = 1; i < times.size(); ++i)
97  {
98  const objectRegistry& timeIFields =
99  fieldsCache.lookupObject<const objectRegistry>(times[i]);
100 
101  const GeoField& fieldi =
102  timeIFields.lookupObject<const GeoField>(fieldName);
103 
104  fld += weights[i]*fieldi;
105  }
106 
107  return tfld;
108 }
109 
110 
111 template<class GeoField>
113 (
114  const IOobject& fieldIO,
115  const word& fieldName,
116  const wordList& times,
117  const scalarField& weights,
118  const word& registryName
119 )
120 {
121  return uniformInterpolate<GeoField>
122  (
123  fieldIO,
124  fieldName,
125  times,
126  weights,
127  fieldIO.db().subRegistry(registryName, true)
128  );
129 }
130 
131 
132 // ************************************************************************* //
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)
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.
multivariateSurfaceInterpolationScheme< scalar >::fieldTable fields
Definition: createFields.H:97
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
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))
List< word > wordList
List of word.
Definition: fileName.H:59
List< label > labelList
A List of labels.
Definition: List.H:62
A class for managing temporary objects.
Definition: HashPtrTable.H:50