AMIInterpolationTemplates.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) 2011-2017 OpenFOAM Foundation
9 Copyright (C) 2015-2018 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "profiling.H"
30#include "mapDistribute.H"
31
32// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
33
34template<class Type, class CombineOp>
36(
37 const UList<Type>& fld,
38 const CombineOp& cop,
39 List<Type>& result,
40 const UList<Type>& defaultValues
41) const
42{
43 addProfiling(ami, "AMIInterpolation::interpolateToTarget");
44
45 if (fld.size() != srcAddress_.size())
46 {
48 << "Supplied field size is not equal to source patch size" << nl
49 << " source patch = " << srcAddress_.size() << nl
50 << " target patch = " << tgtAddress_.size() << nl
51 << " supplied field = " << fld.size()
52 << abort(FatalError);
53 }
54
56 {
57 if (defaultValues.size() != tgtAddress_.size())
58 {
60 << "Employing default values when sum of weights falls below "
62 << " but supplied default field size is not equal to target "
63 << "patch size" << nl
64 << " default values = " << defaultValues.size() << nl
65 << " target patch = " << tgtAddress_.size() << nl
66 << abort(FatalError);
67 }
68 }
69
70 result.setSize(tgtAddress_.size());
71
72 if (distributed())
73 {
74 const mapDistribute& map = srcMapPtr_();
75
76 List<Type> work(fld);
77 map.distribute(work);
78
79 forAll(result, facei)
80 {
82 {
83 result[facei] = defaultValues[facei];
84 }
85 else
86 {
87 const labelList& faces = tgtAddress_[facei];
88 const scalarList& weights = tgtWeights_[facei];
89
90 forAll(faces, i)
91 {
92 cop(result[facei], facei, work[faces[i]], weights[i]);
93 }
94 }
95 }
96 }
97 else
98 {
99 forAll(result, facei)
100 {
102 {
103 result[facei] = defaultValues[facei];
104 }
105 else
106 {
107 const labelList& faces = tgtAddress_[facei];
108 const scalarList& weights = tgtWeights_[facei];
109
110 forAll(faces, i)
111 {
112 cop(result[facei], facei, fld[faces[i]], weights[i]);
113 }
114 }
115 }
116 }
117}
118
119
120template<class Type, class CombineOp>
122(
123 const UList<Type>& fld,
124 const CombineOp& cop,
125 List<Type>& result,
126 const UList<Type>& defaultValues
127) const
128{
129 addProfiling(ami, "AMIInterpolation::interpolateToSource");
130
131 if (fld.size() != tgtAddress_.size())
132 {
134 << "Supplied field size is not equal to target patch size" << nl
135 << " source patch = " << srcAddress_.size() << nl
136 << " target patch = " << tgtAddress_.size() << nl
137 << " supplied field = " << fld.size()
138 << abort(FatalError);
139 }
140
141 if (lowWeightCorrection_ > 0)
142 {
143 if (defaultValues.size() != srcAddress_.size())
144 {
146 << "Employing default values when sum of weights falls below "
147 << lowWeightCorrection_
148 << " but supplied default field size is not equal to source "
149 << "patch size" << nl
150 << " default values = " << defaultValues.size() << nl
151 << " source patch = " << srcAddress_.size() << nl
152 << abort(FatalError);
153 }
154 }
155
156 result.setSize(srcAddress_.size());
157
158 if (distributed())
159 {
160 const mapDistribute& map = tgtMapPtr_();
161
162 List<Type> work(fld);
163 map.distribute(work);
164
165 forAll(result, facei)
166 {
167 if (srcWeightsSum_[facei] < lowWeightCorrection_)
168 {
169 result[facei] = defaultValues[facei];
170 }
171 else
172 {
173 const labelList& faces = srcAddress_[facei];
174 const scalarList& weights = srcWeights_[facei];
175
176 forAll(faces, i)
177 {
178 cop(result[facei], facei, work[faces[i]], weights[i]);
179 }
180 }
181 }
182 }
183 else
184 {
185 forAll(result, facei)
186 {
187 if (srcWeightsSum_[facei] < lowWeightCorrection_)
188 {
189 result[facei] = defaultValues[facei];
190 }
191 else
192 {
193 const labelList& faces = srcAddress_[facei];
194 const scalarList& weights = srcWeights_[facei];
195
196 forAll(faces, i)
197 {
198 cop(result[facei], facei, fld[faces[i]], weights[i]);
199 }
200 }
201 }
202 }
203}
204
205
206template<class Type, class CombineOp>
208(
209 const Field<Type>& fld,
210 const CombineOp& cop,
211 const UList<Type>& defaultValues
212) const
213{
214 auto tresult = tmp<Field<Type>>::New(srcAddress_.size(), Zero);
215
216 interpolateToSource
217 (
218 fld,
220 tresult.ref(),
221 defaultValues
222 );
223
224 return tresult;
225}
226
227
228template<class Type, class CombineOp>
230(
231 const tmp<Field<Type>>& tFld,
232 const CombineOp& cop,
233 const UList<Type>& defaultValues
234) const
235{
236 return interpolateToSource(tFld(), cop, defaultValues);
237}
238
239
240template<class Type, class CombineOp>
242(
243 const Field<Type>& fld,
244 const CombineOp& cop,
245 const UList<Type>& defaultValues
246) const
247{
248 auto tresult = tmp<Field<Type>>::New(tgtAddress_.size(), Zero);
249
250 interpolateToTarget
251 (
252 fld,
254 tresult.ref(),
255 defaultValues
256 );
257
258 return tresult;
259}
260
261
262template<class Type, class CombineOp>
264(
265 const tmp<Field<Type>>& tFld,
266 const CombineOp& cop,
267 const UList<Type>& defaultValues
268) const
269{
270 return interpolateToTarget(tFld(), cop, defaultValues);
271}
272
273
274template<class Type>
276(
277 const Field<Type>& fld,
278 const UList<Type>& defaultValues
279) const
280{
281 return interpolateToSource(fld, plusEqOp<Type>(), defaultValues);
282}
283
284
285template<class Type>
287(
288 const tmp<Field<Type>>& tFld,
289 const UList<Type>& defaultValues
290) const
291{
292 return interpolateToSource(tFld(), plusEqOp<Type>(), defaultValues);
293}
294
295
296template<class Type>
298(
299 const Field<Type>& fld,
300 const UList<Type>& defaultValues
301) const
302{
303 return interpolateToTarget(fld, plusEqOp<Type>(), defaultValues);
304}
305
306
307template<class Type>
309(
310 const tmp<Field<Type>>& tFld,
311 const UList<Type>& defaultValues
312) const
313{
314 return interpolateToTarget(tFld(), plusEqOp<Type>(), defaultValues);
315}
316
317
318// ************************************************************************* //
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))
labelListList srcAddress_
Addresses of target faces per source face.
bool distributed() const
Access to the distributed flag.
autoPtr< mapDistribute > srcMapPtr_
Source map pointer - parallel running only.
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
labelListList tgtAddress_
Addresses of source faces per target face.
const scalar lowWeightCorrection_
Threshold weight below which interpolation is deactivated.
scalarListList tgtWeights_
Weights of source faces per target face.
scalarField tgtWeightsSum_
Sum of weights of source faces per target face.
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Generic templated field type.
Definition: Field.H:82
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void setSize(const label n)
Alias for resize()
Definition: List.H:218
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
Class containing processor-to-processor mapping information.
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
A class for managing temporary objects.
Definition: tmp.H:65
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
errorManip< error > abort(error &err)
Definition: errorManip.H:144
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh > > &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
error FatalError
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333