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 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  if (pTraits<Type>::rank == 0)
57  {
58  return interpolateUntransformed(fld, defaultValues);
59  }
60  else
61  {
62  autoPtr<coordSystem::cylindrical> cs(cylindricalCS());
63  if (!cs)
64  {
65  return interpolateUntransformed(fld, defaultValues);
66  }
67  else
68  {
69  const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
70 
71  if (debug)
72  {
73  Pout<< "cyclicAMIPolyPatch::interpolate :"
74  << " patch:" << this->name()
75  << " size:" << this->size()
76  << " nbrPatch:" << nbrPp.name()
77  << " size:" << nbrPp.size()
78  << endl;
79  }
80 
81  if (fld.size() != nbrPp.size())
82  {
84  << "Patch:" << this->name()
85  << " size:" << this->size()
86  << " neighbour patch:" << nbrPp.name()
87  << " size:" << nbrPp.size()
88  << " fld size:" << fld.size()
89  << exit(FatalError);
90  }
91 
92 
93  auto tlocalFld(tmp<Field<Type>>::New(fld.size()));
94  Field<Type>& localFld = tlocalFld.ref();
95 
96  // Transform to cylindrical coords
97  {
98  tmp<tensorField> nbrT(cs().R(nbrPp.faceCentres()));
99  localFld = Foam::invTransform(nbrT(), fld);
100  }
101 
102  if (debug&2)
103  {
104  const vectorField::subField nbrFc(nbrPp.faceCentres());
105 
106  Pout<< "On patch:" << this->name()
107  << " size:" << this->size()
108  << " fc:" << gAverage(this->faceCentres())
109  << " getting remote data from:" << nbrPp.name()
110  << " size:" << nbrPp.size()
111  << " fc:" << gAverage(nbrFc)
112  << endl;
113 
114  forAll(fld, i)
115  {
116  Pout<< "At:" << nbrFc[i] << nl
117  << " cart:" << fld[i] << nl
118  << " cyli:" << localFld[i] << nl
119  << endl;
120  }
121  }
122 
123 
124  const tmp<tensorField> T(cs().R(this->faceCentres()));
125 
126  List<Type> localDeflt(defaultValues.size());
127  if (defaultValues.size() == size())
128  {
129  // Transform default values into cylindrical coords (using
130  // *this faceCentres)
131  // We get in UList (why? Copied from cyclicAMI). Convert to
132  // Field so we can use transformField routines.
133  const SubField<Type> defaultSubFld(defaultValues);
134  const Field<Type>& defaultFld(defaultSubFld);
135  localDeflt = Foam::invTransform(T(), defaultFld);
136  }
137 
138  // Do the actual interpolation and interpolate back to cartesian
139  // coords
140  return Foam::transform
141  (
142  T,
143  interpolateUntransformed(localFld, localDeflt)
144  );
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, class CombineOp>
163 (
164  const UList<Type>& fld,
165  const CombineOp& cop,
166  List<Type>& result,
167  const UList<Type>& defaultValues
168 ) const
169 {
170  //- Commented out for now since called with non-primitives (e.g. wallPoint
171  // from FaceCellWave) - these are missing the pTraits<Type>::rank and
172  // Foam::transform
173  /*
174  autoPtr<coordSystem::cylindrical> cs(cylindricalCS());
175 
176  if (cs && pTraits<Type>::rank > 0)
177  {
178  const cyclicAMIPolyPatch& nbrPp = this->neighbPatch();
179 
180  tmp<tensorField> nbrT(cs().R(nbrPp.faceCentres()));
181 
182  result = Foam::invTransform(nbrT, result);
183  List<Type> localDeflt(defaultValues.size());
184  if (defaultValues.size() == nbrT().size())
185  {
186  // We get in UList (why? Copied from cyclicAMI). Convert to
187  // Field so we can use transformField routines.
188  const SubField<Type> defaultSubFld(defaultValues);
189  const Field<Type>& defaultFld(defaultSubFld);
190  localDeflt = Foam::invTransform(nbrT, defaultFld);
191  }
192 
193  // Do actual AMI interpolation
194  if (owner())
195  {
196  AMI().interpolateToSource
197  (
198  fld,
199  cop,
200  result,
201  localDeflt
202  );
203  }
204  else
205  {
206  neighbPatch().AMI().interpolateToTarget
207  (
208  fld,
209  cop,
210  result,
211  localDeflt
212  );
213  }
214 
215  // Transform back. Result is now at *this
216  const vectorField::subField fc(this->faceCentres());
217  result = Foam::transform(cs().R(fc), result);
218  }
219  else
220  */
221  {
222  if (owner())
223  {
224  AMI().interpolateToSource
225  (
226  fld,
227  cop,
228  result,
229  defaultValues
230  );
231  }
232  else
233  {
234  neighbPatch().AMI().interpolateToTarget
235  (
236  fld,
237  cop,
238  result,
239  defaultValues
240  );
241  }
242  }
243 }
244 
245 
246 // ************************************************************************* //
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:578
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:49
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:487
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:414
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:52
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...
int debug
Static debugging option.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
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))
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)
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.