Loading...
Searching...
No Matches
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 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
65template<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
111template<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// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-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:75
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