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 -------------------------------------------------------------------------------
11 License
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 
34 template<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 
55  if (lowWeightCorrection_ > 0)
56  {
57  if (defaultValues.size() != tgtAddress_.size())
58  {
60  << "Employing default values when sum of weights falls below "
61  << lowWeightCorrection_
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  {
81  if (tgtWeightsSum_[facei] < lowWeightCorrection_)
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  {
101  if (tgtWeightsSum_[facei] < lowWeightCorrection_)
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 
120 template<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 
206 template<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 
228 template<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 
240 template<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 
262 template<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 
274 template<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 
285 template<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 
296 template<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 
307 template<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 // ************************************************************************* //
profiling.H
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::AMIInterpolation::interpolateToTarget
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolationTemplates.C:36
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
Foam::AMIInterpolation::interpolateToSource
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Definition: AMIInterpolationTemplates.C:122
Foam::Field
Generic templated field type.
Definition: Field.H:63
Foam::List::setSize
void setSize(const label n)
Alias for resize()
Definition: List.H:222
Foam::mapDistribute
Class containing processor-to-processor mapping information.
Definition: mapDistribute.H:163
fld
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))
Definition: gmvOutputLagrangian.H:23
Foam::mapDistribute::distribute
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
Definition: mapDistributeTemplates.C:152
addProfiling
#define addProfiling(name, descr)
Define profiling trigger with specified name and description string.
Definition: profilingTrigger.H:113
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::multiplyWeightedOp
Definition: ops.H:250
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
Foam::nl
constexpr char nl
Definition: Ostream.H:404
mapDistribute.H
Foam::List< Type >
Foam::UList< Type >
Foam::plusEqOp
Definition: ops.H:72
Foam::UList::size
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114