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-------------------------------------------------------------------------------
10License
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
30template<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
64template<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
110template<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// ************************************************************************* //
Info<< nl<< "Wrote faMesh in vtk format: "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.mesh().time().globalPath()/"finiteArea-edges"));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
A class for managing temporary objects.
Definition: tmp.H:65
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