cyclicFaPatchField.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-------------------------------------------------------------------------------
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#include "cyclicFaPatchField.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33template<class Type>
35(
36 const faPatch& p,
38)
39:
40 coupledFaPatchField<Type>(p, iF),
41 cyclicPatch_(refCast<const cyclicFaPatch>(p))
42{}
43
44
45template<class Type>
47(
48 const cyclicFaPatchField<Type>& ptf,
49 const faPatch& p,
51 const faPatchFieldMapper& mapper
52)
53:
54 coupledFaPatchField<Type>(ptf, p, iF, mapper),
55 cyclicPatch_(refCast<const cyclicFaPatch>(p))
56{
57 if (!isA<cyclicFaPatch>(this->patch()))
58 {
60 << "\n patch type '" << p.type()
61 << "' not constraint type '" << typeName << "'"
62 << "\n for patch " << p.name()
63 << " of field " << this->internalField().name()
64 << " in file " << this->internalField().objectPath()
65 << exit(FatalError);
66 }
67}
68
69
70template<class Type>
72(
73 const faPatch& p,
75 const dictionary& dict
76)
77:
78 coupledFaPatchField<Type>(p, iF, dict),
79 cyclicPatch_(refCast<const cyclicFaPatch>(p, dict))
80{
81 if (!isA<cyclicFaPatch>(p))
82 {
84 << "\n patch type '" << p.type()
85 << "' not constraint type '" << typeName << "'"
86 << "\n for patch " << p.name()
87 << " of field " << this->internalField().name()
88 << " in file " << this->internalField().objectPath()
90 }
91
93}
94
95
96template<class Type>
98(
100)
101:
103 coupledFaPatchField<Type>(ptf),
104 cyclicPatch_(ptf.cyclicPatch_)
105{}
106
107
108template<class Type>
110(
111 const cyclicFaPatchField<Type>& ptf,
113)
114:
115 coupledFaPatchField<Type>(ptf, iF),
116 cyclicPatch_(ptf.cyclicPatch_)
117{}
118
119
120// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
121
122template<class Type>
125{
126 const Field<Type>& iField = this->primitiveField();
127 const labelUList& faceCells = cyclicPatch_.faceCells();
128
129 tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
130 Field<Type>& pnf = tpnf.ref();
131
132 const label sizeby2 = this->size()/2;
133
134 if (doTransform())
135 {
136 for (label facei=0; facei<sizeby2; ++facei)
137 {
138 pnf[facei] = transform
139 (
140 forwardT()[0], iField[faceCells[facei + sizeby2]]
141 );
142
143 pnf[facei + sizeby2] = transform
144 (
145 reverseT()[0], iField[faceCells[facei]]
146 );
147 }
148 }
149 else
150 {
151 for (label facei=0; facei<sizeby2; ++facei)
152 {
153 pnf[facei] = iField[faceCells[facei + sizeby2]];
154 pnf[facei + sizeby2] = iField[faceCells[facei]];
155 }
156 }
157
158 return tpnf;
159}
160
161
162template<class Type>
164(
165 solveScalarField& result,
166 const bool add,
167 const lduAddressing& lduAddr,
168 const label patchId,
169 const solveScalarField& psiInternal,
170 const scalarField& coeffs,
171 const direction cmpt,
172 const Pstream::commsTypes commsType
173) const
174{
175 solveScalarField pnf(this->size());
176
177 const label sizeby2 = this->size()/2;
178 const labelUList& faceCells = cyclicPatch_.faceCells();
179
180 for (label facei = 0; facei < sizeby2; ++facei)
181 {
182 pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
183 pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
184 }
185
186 // Transform according to the transformation tensors
187 transformCoupleField(pnf, cmpt);
188
189 // Multiply the field by coefficients and add into the result
190 if (add)
191 {
192 forAll(faceCells, elemI)
193 {
194 result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
195 }
196 }
197 else
198 {
199 forAll(faceCells, elemI)
200 {
201 result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
202 }
203 }
204}
205
206
207template<class Type>
209(
210 Field<Type>& result,
211 const bool add,
212 const lduAddressing& lduAddr,
213 const label patchId,
214 const Field<Type>& psiInternal,
215 const scalarField& coeffs,
216 const Pstream::commsTypes commsType
217) const
218{
219 Field<Type> pnf(this->size());
220
221 const label sizeby2 = this->size()/2;
222 const labelUList& faceCells = cyclicPatch_.faceCells();
223
224 for (label facei = 0; facei < sizeby2; ++facei)
225 {
226 pnf[facei] = psiInternal[faceCells[facei + sizeby2]];
227 pnf[facei + sizeby2] = psiInternal[faceCells[facei]];
228 }
229
230 // Multiply the field by coefficients and add into the result
231 if (add)
232 {
233 forAll(faceCells, elemI)
234 {
235 result[faceCells[elemI]] += coeffs[elemI]*pnf[elemI];
236 }
237 }
238 else
239 {
240 forAll(faceCells, elemI)
241 {
242 result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
243 }
244 }
245}
246
247
248// ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
static const char *const typeName
Typename for Field.
Definition: FieldBase.H:59
Generic templated field type.
Definition: Field.H:82
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
commsTypes
Types of communications.
Definition: UPstream.H:67
Author Zeljko Tukovic, FMENA Hrvoje Jasak, Wikki Ltd.
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
Foam::cyclicFaPatchField.
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.
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled given internal cell data.
Cyclic-plane patch.
Definition: cyclicFaPatch.H:61
Abstract base class for cyclic coupled interfaces.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
A FieldMapper for finite-area patch fields.
const faPatch & patch() const
Return patch.
Definition: faPatchField.H:286
const DimensionedField< Type, areaMesh > & internalField() const
Return dimensioned internal field reference.
Definition: faPatchField.H:292
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:78
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
The class contains the addressing required by the lduMatrix: upper, lower and losort.
A class for managing temporary objects.
Definition: tmp.H:65
T & ref() const
Definition: tmpI.H:227
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
label patchId(-1)
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:131
dimensionSet transform(const dimensionSet &ds)
Return the argument; transformations do not change the dimensions.
Definition: dimensionSet.C:536
void add(FieldField< Field1, typename typeOfSum< Type1, Type2 >::type > &f, const FieldField< Field1, Type1 > &f1, const FieldField< Field2, Type2 > &f2)
uint8_t direction
Definition: direction.H:56
IOerror FatalIOError
error FatalError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333