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-------------------------------------------------------------------------------
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// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30
31template<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
49template<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 {
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
150template<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
161template<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// ************************************************************************* //
#define R(A, B, C, D, E, F, K, M)
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))
void interpolateToSource(const UList< Type > &fld, const CombineOp &cop, List< Type > &result, const UList< Type > &defaultValues=UList< Type >::null()) const
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
SubField is a Field obtained as a section of another Field, without its own allocation....
Definition: SubField.H:62
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
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: autoPtr.H:66
Cyclic patch for Arbitrary Mesh Interface (AMI)
virtual bool owner() const
Does this side own the patch?
tmp< Field< Type > > interpolateUntransformed(const Field< Type > &fld, const UList< Type > &defaultValues) const
Interpolate without periodic.
const AMIPatchToPatchInterpolation & AMI() const
Return a reference to the AMI interpolator.
virtual const cyclicAMIPolyPatch & neighbPatch() const
Return a reference to the neighbour patch.
A traits class, which is primarily used for primitives.
Definition: pTraits.H:59
const word & name() const noexcept
The patch name.
const vectorField::subField faceCentres() const
Return face centres.
Definition: polyPatch.C:321
bool interpolate() const noexcept
Same as isPointData()
A class for managing temporary objects.
Definition: tmp.H:65
const volScalarField & T
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
dimensionSet invTransform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:542
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:372
coordSystem::cylindrical cylindricalCS
Compatibility typedef 1806.
Type gAverage(const FieldField< Field, Type > &f)
bool interpolate(const vector &p1, const vector &p2, const vector &o, vector &n, scalar l)
Definition: curveTools.C:75
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
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
Definition: exprTraits.C:59
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333