processorFaPatchField.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) 2016-2017 Wikki Ltd
9  Copyright (C) 2019 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 "processorFaPatchField.H"
31 #include "transformField.H"
32 
33 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
34 
35 template<class Type>
37 (
38  const faPatch& p,
40 )
41 :
42  coupledFaPatchField<Type>(p, iF),
43  procPatch_(refCast<const processorFaPatch>(p))
44 {}
45 
46 
47 template<class Type>
49 (
50  const faPatch& p,
52  const Field<Type>& f
53 )
54 :
55  coupledFaPatchField<Type>(p, iF, f),
56  procPatch_(refCast<const processorFaPatch>(p))
57 {}
58 
59 
60 template<class Type>
62 (
63  const processorFaPatchField<Type>& ptf,
64  const faPatch& p,
66  const faPatchFieldMapper& mapper
67 )
68 :
69  coupledFaPatchField<Type>(ptf, p, iF, mapper),
70  procPatch_(refCast<const processorFaPatch>(p))
71 {
72  if (!isType<processorFaPatch>(this->patch()))
73  {
75  << "\n patch type '" << p.type()
76  << "' not constraint type '" << typeName << "'"
77  << "\n for patch " << p.name()
78  << " of field " << this->internalField().name()
79  << " in file " << this->internalField().objectPath()
81  }
82 }
83 
84 
85 template<class Type>
87 (
88  const faPatch& p,
89  const DimensionedField<Type, areaMesh>& iF,
90  const dictionary& dict
91 )
92 :
93  coupledFaPatchField<Type>(p, iF, dict),
94  procPatch_(refCast<const processorFaPatch>(p, dict))
95 {
96  if (!isType<processorFaPatch>(p))
97  {
99  << "\n patch type '" << p.type()
100  << "' not constraint type '" << typeName << "'"
101  << "\n for patch " << p.name()
102  << " of field " << this->internalField().name()
103  << " in file " << this->internalField().objectPath()
105  }
106 }
107 
108 
109 template<class Type>
111 (
112  const processorFaPatchField<Type>& ptf
113 )
114 :
115  processorLduInterfaceField(),
117  procPatch_(refCast<const processorFaPatch>(ptf.patch()))
118 {}
119 
120 
121 template<class Type>
123 (
124  const processorFaPatchField<Type>& ptf,
126 )
127 :
128  coupledFaPatchField<Type>(ptf, iF),
129  procPatch_(refCast<const processorFaPatch>(ptf.patch()))
130 {}
131 
132 
133 // * * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * //
134 
135 template<class Type>
137 {}
138 
139 
140 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
141 
142 template<class Type>
145 {
146  return *this;
147 }
148 
149 
150 template<class Type>
152 (
153  const Pstream::commsTypes commsType
154 )
155 {
156  if (Pstream::parRun())
157  {
158  procPatch_.send(commsType, this->patchInternalField()());
159  }
160 }
161 
162 
163 template<class Type>
165 (
166  const Pstream::commsTypes commsType
167 )
168 {
169  if (Pstream::parRun())
170  {
171  procPatch_.receive<Type>(commsType, *this);
172 
173  if (doTransform())
174  {
175  transform(*this, procPatch_.forwardT(), *this);
176  }
177  }
178 }
179 
180 
181 template<class Type>
183 {
184  return this->patch().deltaCoeffs()*(*this - this->patchInternalField());
185 }
186 
187 
188 template<class Type>
190 (
191  solveScalarField& result,
192  const bool add,
193  const lduAddressing& lduAddr,
194  const label patchId,
195  const solveScalarField& psiInternal,
196  const scalarField& coeffs,
197  const direction,
198  const Pstream::commsTypes commsType
199 ) const
200 {
201  procPatch_.send
202  (
203  commsType,
204  this->patch().patchInternalField(psiInternal)()
205  );
206 }
207 
208 
209 template<class Type>
211 (
212  solveScalarField& result,
213  const bool add,
214  const lduAddressing& lduAddr,
215  const label patchId,
216  const solveScalarField&,
217  const scalarField& coeffs,
218  const direction cmpt,
219  const Pstream::commsTypes commsType
220 ) const
221 {
222  solveScalarField pnf
223  (
224  procPatch_.receive<solveScalar>(commsType, this->size())()
225  );
226 
227  // Transform according to the transformation tensor
228  transformCoupleField(pnf, cmpt);
229 
230  // Multiply the field by coefficients and add into the result
231 
232  const labelUList& edgeFaces = this->patch().edgeFaces();
233 
234  if (add)
235  {
236  forAll(edgeFaces, elemI)
237  {
238  result[edgeFaces[elemI]] += coeffs[elemI]*pnf[elemI];
239  }
240  }
241  else
242  {
243  forAll(edgeFaces, elemI)
244  {
245  result[edgeFaces[elemI]] -= coeffs[elemI]*pnf[elemI];
246  }
247  }
248 }
249 
250 
251 template<class Type>
253 (
254  Field<Type>& result,
255  const bool add,
256  const lduAddressing& lduAddr,
257  const label patchId,
258  const Field<Type>& psiInternal,
259  const scalarField& coeffs,
260  const Pstream::commsTypes commsType
261 ) const
262 {
263  procPatch_.send
264  (
265  commsType,
266  this->patch().patchInternalField(psiInternal)()
267  );
268 }
269 
270 
271 template<class Type>
273 (
274  Field<Type>& result,
275  const bool add,
276  const lduAddressing& lduAddr,
277  const label patchId,
278  const Field<Type>&,
279  const scalarField& coeffs,
280  const Pstream::commsTypes commsType
281 ) const
282 {
283  Field<Type> pnf
284  (
285  procPatch_.receive<Type>(commsType, this->size())()
286  );
287 
288  // Multiply the field by coefficients and add into the result
289 
290  const labelUList& edgeFaces = this->patch().edgeFaces();
291 
292  if (add)
293  {
294  forAll(edgeFaces, elemI)
295  {
296  result[edgeFaces[elemI]] += coeffs[elemI]*pnf[elemI];
297  }
298  }
299  else
300  {
301  forAll(edgeFaces, elemI)
302  {
303  result[edgeFaces[elemI]] -= coeffs[elemI]*pnf[elemI];
304  }
305  }
306 }
307 
308 
309 // ************************************************************************* //
label patchId(-1)
dictionary dict
const faPatch & patch() const noexcept
The associated objectRegistry.
Definition: faPatchField.H:179
uint8_t direction
Definition: direction.H:46
virtual void initEvaluate(const Pstream::commsTypes commsType)
Initialise the evaluation of the patch field.
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
commsTypes
Types of communications.
Definition: UPstream.H:66
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
Type & refCast(U &obj)
A dynamic_cast (for references) that generates FatalError on failed casts, uses the virtual type() me...
Definition: typeInfo.H:151
static bool & parRun() noexcept
Test if this a parallel run.
Definition: UPstream.H:639
const DimensionedField< Type, areaMesh > & internalField() const noexcept
Return dimensioned internal field reference.
Definition: faPatchField.H:491
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:413
virtual void updateInterfaceMatrix(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
static const char *const typeName
Typename for Field.
Definition: Field.H:86
Spatial transformation functions for primitive fields.
Generic templated field type.
Definition: Field.H:61
Field< scalar > scalarField
Specialisation of Field<T> for scalar.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
virtual void initInterfaceMatrixUpdate(solveScalarField &result, const bool add, const lduAddressing &lduAddr, const label patchId, const solveScalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Initialise neighbour matrix update.
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
labelList f(nPoints)
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:607
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
virtual tmp< Field< Type > > snGrad() const
Return patch-normal gradient.
The class contains the addressing required by the lduMatrix: upper, lower and losort.
volScalarField & p
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:529
A FieldMapper for finite-area patch fields.
processorFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
Processor patch.
tmp< Field< Type > > patchNeighbourField() const
Return neighbour field given internal field.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...