cyclicAMIPolyPatchTemplates.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-2016 OpenFOAM Foundation
9  Copyright (C) 2021-2023 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 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const Field<Type>& fld,
35  const UList<Type>& defaultValues
36 ) const
37 {
38  if (owner())
39  {
40  return AMI().interpolateToSource(fld, defaultValues);
41  }
42  else
43  {
44  return neighbPatch().AMI().interpolateToTarget(fld, defaultValues);
45  }
46 }
47 
48 
49 template<class Type>
51 (
52  const Field<Type>& fld,
53  const UList<Type>& defaultValues
54 ) const
55 {
56  autoPtr<coordSystem::cylindrical> cs;
57 
58  // Similar to doTransform.
59  // - could also check if !std::is_same<sphericalTensor, Type>:value
60 
61  if (is_vectorspace<Type>::value)
62  {
63  cs.reset(cylindricalCS());
64  }
65 
66  if (!cs)
67  {
68  return interpolateUntransformed(fld, defaultValues);
69  }
70  else
71  {
72  const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
73 
74  if (debug)
75  {
76  Pout<< "cyclicAMIPolyPatch::interpolate :"
77  << " patch:" << this->name()
78  << " size:" << this->size()
79  << " nbrPatch:" << nbrPp.name()
80  << " size:" << nbrPp.size()
81  << endl;
82  }
83 
84  if (fld.size() != nbrPp.size())
85  {
87  << "Patch:" << this->name()
88  << " size:" << this->size()
89  << " neighbour patch:" << nbrPp.name()
90  << " size:" << nbrPp.size()
91  << " fld size:" << fld.size()
92  << exit(FatalError);
93  }
94 
95 
96  Field<Type> localFld(fld.size());
97 
98  // Transform to cylindrical coords
99  {
100  const tensorField nbrT(cs().R(nbrPp.faceCentres()));
101  Foam::invTransform(localFld, nbrT, fld);
102  }
103 
104  if (debug&2)
105  {
106  const vectorField::subField nbrFc(nbrPp.faceCentres());
107 
108  Pout<< "On patch:" << this->name()
109  << " size:" << this->size()
110  << " fc:" << gAverage(this->faceCentres())
111  << " getting remote data from:" << nbrPp.name()
112  << " size:" << nbrPp.size()
113  << " fc:" << gAverage(nbrFc)
114  << endl;
115 
116  forAll(fld, i)
117  {
118  Pout<< "At:" << nbrFc[i] << nl
119  << " cart:" << fld[i] << nl
120  << " cyli:" << localFld[i] << nl
121  << endl;
122  }
123  }
124 
125 
126  const tensorField ownT(cs().R(this->faceCentres()));
127 
128  Field<Type> localDeflt(defaultValues.size());
129  if (defaultValues.size() == size())
130  {
131  // Transform default values into cylindrical coords (using
132  // *this faceCentres)
133  // We get in UList (why? Copied from cyclicAMI). Convert to
134  // Field so we can use transformField routines.
135  const SubField<Type> defaultSubFld(defaultValues);
136  const Field<Type>& defaultFld(defaultSubFld);
137  Foam::invTransform(localDeflt, ownT, defaultFld);
138  }
139 
140  // Do the actual interpolation and interpolate back to cartesian
141  return Foam::transform
142  (
143  ownT,
144  interpolateUntransformed(localFld, localDeflt)
145  );
146  }
147 }
148 
149 
150 template<class Type>
152 (
153  const tmp<Field<Type>>& tFld,
154  const UList<Type>& defaultValues
155 ) const
156 {
157  return interpolate(tFld(), defaultValues);
158 }
159 
160 
161 template<class Type>
163 (
164  const Field<Type>& fld,
165  labelRange& sendRequests,
166  PtrList<List<Type>>& sendBuffers,
167  labelRange& recvRequests,
168  PtrList<List<Type>>& recvBuffers
169 ) const
170 {
171  const auto& AMI = (owner() ? this->AMI() : neighbPatch().AMI());
172 
173  if (AMI.distributed())
174  {
175  const auto& map = (owner() ? AMI.tgtMap() : AMI.srcMap());
176 
177  // Insert send/receive requests (non-blocking)
178  map.send(fld, sendRequests, sendBuffers, recvRequests, recvBuffers);
179  }
180 }
181 
182 
183 template<class Type>
185 (
186  const Field<Type>& fld,
187  labelRange& sendRequests,
188  PtrList<List<Type>>& sendBuffers,
189  labelRange& recvRequests,
190  PtrList<List<Type>>& recvBuffers
191 ) const
192 {
193  const auto& AMI = (owner() ? this->AMI() : neighbPatch().AMI());
194 
195  if (!AMI.distributed())
196  {
197  return;
198  }
199 
200  autoPtr<coordSystem::cylindrical> cs;
201 
202  if (is_vectorspace<Type>::value)
203  {
204  cs.reset(cylindricalCS());
205  }
206 
207  if (!cs)
208  {
209  initInterpolateUntransformed
210  (
211  fld,
212  sendRequests,
213  sendBuffers,
214  recvRequests,
215  recvBuffers
216  );
217  }
218  else
219  {
220  const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
221 
222  Field<Type> localFld(fld.size());
223 
224  // Transform to cylindrical coords
225  {
226  const tensorField nbrT(cs().R(nbrPp.faceCentres()));
227  Foam::invTransform(localFld, nbrT, fld);
228  }
229 
230  initInterpolateUntransformed
231  (
232  localFld,
233  sendRequests,
234  sendBuffers,
235  recvRequests,
236  recvBuffers
237  );
238  }
239 }
240 
241 
242 template<class Type>
244 (
245  const Field<Type>& localFld,
246  const labelRange& requests,
247  const PtrList<List<Type>>& recvBuffers,
248  const UList<Type>& defaultValues
249 ) const
250 {
251  const auto& AMI = (owner() ? this->AMI() : neighbPatch().AMI());
252  const auto& map = (owner() ? AMI.tgtMap() : AMI.srcMap());
253 
254  Field<Type> work;
255  if (AMI.distributed())
256  {
257  // Receive (= copy) data from buffers into work. TBD: receive directly
258  // into slices of work.
259  map.receive(requests, recvBuffers, work);
260  }
261  const Field<Type>& fld = (AMI.distributed() ? work : localFld);
262 
263  auto tresult = tmp<Field<Type>>::New(this->size(), Zero);
264 
265  // Note: tresult is optionally in transformed coord system
266  autoPtr<coordSystem::cylindrical> cs;
267 
268  if (is_vectorspace<Type>::value)
269  {
270  cs.reset(cylindricalCS());
271  }
272 
273  if (!cs)
274  {
275  AMI.weightedSum
276  (
277  owner(),
278  fld,
279  tresult.ref(),
280  defaultValues
281  );
282  }
283  else
284  {
285  const tensorField ownT(cs().R(this->faceCentres()));
286 
287  Field<Type> localDeflt(defaultValues.size());
288  if (defaultValues.size() == size())
289  {
290  // Transform default values into cylindrical coords (using
291  // *this faceCentres)
292  // We get in UList (why? Copied from cyclicAMI). Convert to
293  // Field so we can use transformField routines.
294  const SubField<Type> defaultSubFld(defaultValues);
295  const Field<Type>& defaultFld(defaultSubFld);
296  Foam::invTransform(localDeflt, ownT, defaultFld);
297  }
298 
299  AMI.weightedSum
300  (
301  owner(),
302  fld,
303  tresult.ref(),
304  localDeflt
305  );
306 
307  // Transform back
308  Foam::transform(tresult.ref(), ownT, tresult());
309  }
311  return tresult;
312 }
313 
314 
315 template<class Type, class CombineOp>
317 (
318  const UList<Type>& fld,
319  const CombineOp& cop,
320  List<Type>& result,
321  const UList<Type>& defaultValues
322 ) const
323 {
324  //- Commented out for now since called with non-primitives (e.g. wallPoint
325  // from FaceCellWave) - missing Foam::transform, Foam::invTransform
326  /*
327  autoPtr<coordSystem::cylindrical> cs;
328 
329  if (is_vectorspace<Type>::value)
330  {
331  cs.reset(cylindricalCS());
332  }
333 
334  if (cs)
335  {
336  const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
337 
338  // Transform to cylindrical coords
339  {
340  const tensorField nbrT(cs().R(nbrPp.faceCentres()));
341  Foam::invTransform(result, nbrT, result);
342  }
343 
344  const tensorField ownT(cs().R(this->faceCentres()));
345 
346  Field<Type> localDeflt(defaultValues.size());
347  if (defaultValues.size() == size())
348  {
349  // Transform default values into cylindrical coords (using
350  // *this faceCentres)
351  // We get in UList (why? Copied from cyclicAMI). Convert to
352  // Field so we can use transformField routines.
353  const SubField<Type> defaultSubFld(defaultValues);
354  const Field<Type>& defaultFld(defaultSubFld);
355  Foam::invTransform(localDeflt, ownT, defaultFld);
356  }
357 
358  // Do actual AMI interpolation
359  if (owner())
360  {
361  AMI().interpolateToSource
362  (
363  fld,
364  cop,
365  result,
366  localDeflt
367  );
368  }
369  else
370  {
371  neighbPatch().AMI().interpolateToTarget
372  (
373  fld,
374  cop,
375  result,
376  localDeflt
377  );
378  }
379 
380  // Transform back. Result is now at *this
381  Foam::transform(result, ownT, result);
382  }
383  else
384  */
385  {
386  if (owner())
387  {
388  AMI().interpolateToSource
389  (
390  fld,
391  cop,
392  result,
393  defaultValues
394  );
395  }
396  else
397  {
398  neighbPatch().AMI().interpolateToTarget
399  (
400  fld,
401  cop,
402  result,
403  defaultValues
404  );
405  }
406  }
407 }
408 
409 
410 // ************************************************************************* //
const AMIPatchToPatchInterpolation & AMI() const
Return a reference to the AMI interpolator.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:527
error FatalError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL ERROR&#39; header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:598
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
tmp< Field< Type > > interpolate(const Field< Type > &fld, const UList< Type > &defaultValues=UList< Type >()) const
Interpolate field.
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:421
void initInterpolate(const Field< Type > &fld, labelRange &sendRequests, PtrList< List< Type >> &sendBuffers, labelRange &recvRequests, PtrList< List< Type >> &recvBuffers) const
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
Definition: exprTraits.C:127
Generic templated field type.
Definition: Field.H:62
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 to combine existing value with remote value and we...
void initInterpolateUntransformed(const Field< Type > &fld, labelRange &sendRequests, PtrList< List< Type >> &sendBuffers, labelRange &recvRequests, PtrList< List< Type >> &recvBuffers) const
int debug
Static debugging option.
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 to combine existing value with remote value and we...
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))
Field< tensor > tensorField
Specialisation of Field<T> for tensor.
tmp< Field< Type > > interpolateUntransformed(const Field< Type > &fld, const UList< Type > &defaultValues) const
Interpolate without periodic.
#define R(A, B, C, D, E, F, K, M)
Type gAverage(const FieldField< Field, Type > &f)
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
virtual const cyclicAMIPolyPatch & neighbPatch() const
Return a reference to the neighbour patch.
virtual bool owner() const
Does this side own the patch?
SubField< vector > subField
Declare type of subField.
Definition: Field.H:128
A class for managing temporary objects.
Definition: HashPtrTable.H:50
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:521
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
coordSystem::cylindrical cylindricalCS
Compatibility typedef 1806.
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127