AMIInterpolationTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "AMIInterpolation.H"
27 #include "AMIMethod.H"
28 #include "meshTools.H"
29 #include "mapDistribute.H"
30 #include "flipOp.H"
31 
32 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
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  if (fld.size() != srcAddress_.size())
44  {
46  << "Supplied field size is not equal to source patch size" << nl
47  << " source patch = " << srcAddress_.size() << nl
48  << " target patch = " << tgtAddress_.size() << nl
49  << " supplied field = " << fld.size()
50  << abort(FatalError);
51  }
52 
53  if (lowWeightCorrection_ > 0)
54  {
55  if (defaultValues.size() != tgtAddress_.size())
56  {
58  << "Employing default values when sum of weights falls below "
59  << lowWeightCorrection_
60  << " but supplied default field size is not equal to target "
61  << "patch size" << nl
62  << " default values = " << defaultValues.size() << nl
63  << " target patch = " << tgtAddress_.size() << nl
64  << abort(FatalError);
65  }
66  }
67 
68  result.setSize(tgtAddress_.size());
69 
70  if (singlePatchProc_ == -1)
71  {
72  const mapDistribute& map = srcMapPtr_();
73 
74  List<Type> work(fld);
75  map.distribute(work);
76 
77  forAll(result, facei)
78  {
79  if (tgtWeightsSum_[facei] < lowWeightCorrection_)
80  {
81  result[facei] = defaultValues[facei];
82  }
83  else
84  {
85  const labelList& faces = tgtAddress_[facei];
86  const scalarList& weights = tgtWeights_[facei];
87 
88  forAll(faces, i)
89  {
90  cop(result[facei], facei, work[faces[i]], weights[i]);
91  }
92  }
93  }
94  }
95  else
96  {
97  forAll(result, facei)
98  {
99  if (tgtWeightsSum_[facei] < lowWeightCorrection_)
100  {
101  result[facei] = defaultValues[facei];
102  }
103  else
104  {
105  const labelList& faces = tgtAddress_[facei];
106  const scalarList& weights = tgtWeights_[facei];
107 
108  forAll(faces, i)
109  {
110  cop(result[facei], facei, fld[faces[i]], weights[i]);
111  }
112  }
113  }
114  }
115 }
116 
117 
118 template<class Type, class CombineOp>
120 (
121  const UList<Type>& fld,
122  const CombineOp& cop,
123  List<Type>& result,
124  const UList<Type>& defaultValues
125 ) const
126 {
127  if (fld.size() != tgtAddress_.size())
128  {
130  << "Supplied field size is not equal to target patch size" << nl
131  << " source patch = " << srcAddress_.size() << nl
132  << " target patch = " << tgtAddress_.size() << nl
133  << " supplied field = " << fld.size()
134  << abort(FatalError);
135  }
136 
137  if (lowWeightCorrection_ > 0)
138  {
139  if (defaultValues.size() != srcAddress_.size())
140  {
142  << "Employing default values when sum of weights falls below "
143  << lowWeightCorrection_
144  << " but supplied default field size is not equal to target "
145  << "patch size" << nl
146  << " default values = " << defaultValues.size() << nl
147  << " source patch = " << srcAddress_.size() << nl
148  << abort(FatalError);
149  }
150  }
151 
152  result.setSize(srcAddress_.size());
153 
154  if (singlePatchProc_ == -1)
155  {
156  const mapDistribute& map = tgtMapPtr_();
157 
158  List<Type> work(fld);
159  map.distribute(work);
160 
161  forAll(result, facei)
162  {
163  if (srcWeightsSum_[facei] < lowWeightCorrection_)
164  {
165  result[facei] = defaultValues[facei];
166  }
167  else
168  {
169  const labelList& faces = srcAddress_[facei];
170  const scalarList& weights = srcWeights_[facei];
171 
172  forAll(faces, i)
173  {
174  cop(result[facei], facei, work[faces[i]], weights[i]);
175  }
176  }
177  }
178  }
179  else
180  {
181  forAll(result, facei)
182  {
183  if (srcWeightsSum_[facei] < lowWeightCorrection_)
184  {
185  result[facei] = defaultValues[facei];
186  }
187  else
188  {
189  const labelList& faces = srcAddress_[facei];
190  const scalarList& weights = srcWeights_[facei];
191 
192  forAll(faces, i)
193  {
194  cop(result[facei], facei, fld[faces[i]], weights[i]);
195  }
196  }
197  }
198  }
199 }
200 
201 
202 template<class Type, class CombineOp>
205 (
206  const Field<Type>& fld,
207  const CombineOp& cop,
208  const UList<Type>& defaultValues
209 ) const
210 {
211  tmp<Field<Type>> tresult
212  (
213  new Field<Type>
214  (
215  srcAddress_.size(),
216  Zero
217  )
218  );
219 
220  interpolateToSource
221  (
222  fld,
224  tresult.ref(),
225  defaultValues
226  );
227 
228  return tresult;
229 }
230 
231 
232 template<class Type, class CombineOp>
235 (
236  const tmp<Field<Type>>& tFld,
237  const CombineOp& cop,
238  const UList<Type>& defaultValues
239 ) const
240 {
241  return interpolateToSource(tFld(), cop, defaultValues);
242 }
243 
244 
245 template<class Type, class CombineOp>
248 (
249  const Field<Type>& fld,
250  const CombineOp& cop,
251  const UList<Type>& defaultValues
252 ) const
253 {
254  tmp<Field<Type>> tresult
255  (
256  new Field<Type>
257  (
258  tgtAddress_.size(),
259  Zero
260  )
261  );
262 
263  interpolateToTarget
264  (
265  fld,
267  tresult.ref(),
268  defaultValues
269  );
270 
271  return tresult;
272 }
273 
274 
275 template<class Type, class CombineOp>
278 (
279  const tmp<Field<Type>>& tFld,
280  const CombineOp& cop,
281  const UList<Type>& defaultValues
282 ) const
283 {
284  return interpolateToTarget(tFld(), cop, defaultValues);
285 }
286 
287 
288 template<class Type>
291 (
292  const Field<Type>& fld,
293  const UList<Type>& defaultValues
294 ) const
295 {
296  return interpolateToSource(fld, plusEqOp<Type>(), defaultValues);
297 }
298 
299 
300 template<class Type>
303 (
304  const tmp<Field<Type>>& tFld,
305  const UList<Type>& defaultValues
306 ) const
307 {
308  return interpolateToSource(tFld(), plusEqOp<Type>(), defaultValues);
309 }
310 
311 
312 template<class Type>
315 (
316  const Field<Type>& fld,
317  const UList<Type>& defaultValues
318 ) const
319 {
320  return interpolateToTarget(fld, plusEqOp<Type>(), defaultValues);
321 }
322 
323 
324 template<class Type>
327 (
328  const tmp<Field<Type>>& tFld,
329  const UList<Type>& defaultValues
330 ) const
331 {
332  return interpolateToTarget(tFld(), plusEqOp<Type>(), defaultValues);
333 }
334 
335 
336 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
void distribute(List< T > &fld, const bool dummyTransform=true, const int tag=UPstream::msgType()) const
Distribute data using default commsType.
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
Pre-declare SubField and related Field type.
Definition: Field.H:56
static const zero Zero
Definition: zero.H:97
void interpolateToTarget(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from source to target with supplied op.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
static const char nl
Definition: Ostream.H:260
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
Interpolate from target to source with supplied op.
void setSize(const label)
Reset size of List.
Definition: List.C:281
Class containing processor-to-processor mapping information.
A class for managing temporary objects.
Definition: PtrList.H:53
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311