cyclicFvPatchField.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-2017 OpenFOAM Foundation
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 "fvMatrix.H"
30#include "cyclicFvPatchField.H"
31#include "transformField.H"
32#include "volFields.H"
33
34// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
35
36template<class Type>
38(
39 const fvPatch& p,
41)
42:
43 coupledFvPatchField<Type>(p, iF),
44 cyclicPatch_(refCast<const cyclicFvPatch>(p))
45{}
46
47
48template<class Type>
50(
51 const fvPatch& p,
53 const dictionary& dict,
54 const bool valueRequired
55)
56:
57 coupledFvPatchField<Type>(p, iF, dict, false), // Pass no valueRequired
58 cyclicPatch_(refCast<const cyclicFvPatch>(p, dict))
59{
60 if (!isA<cyclicFvPatch>(p))
61 {
63 << " patch type '" << p.type()
64 << "' not constraint type '" << typeName << "'"
65 << "\n for patch " << p.name()
66 << " of field " << this->internalField().name()
67 << " in file " << this->internalField().objectPath()
69 }
70
71 if (valueRequired)
72 {
74 }
75}
76
77
78template<class Type>
80(
81 const cyclicFvPatchField<Type>& ptf,
82 const fvPatch& p,
84 const fvPatchFieldMapper& mapper
85)
86:
87 coupledFvPatchField<Type>(ptf, p, iF, mapper),
88 cyclicPatch_(refCast<const cyclicFvPatch>(p))
89{
90 if (!isA<cyclicFvPatch>(this->patch()))
91 {
93 << "' not constraint type '" << typeName << "'"
94 << "\n for patch " << p.name()
95 << " of field " << this->internalField().name()
96 << " in file " << this->internalField().objectPath()
97 << exit(FatalError);
98 }
99}
100
101
102template<class Type>
104(
105 const cyclicFvPatchField<Type>& ptf
106)
107:
109 coupledFvPatchField<Type>(ptf),
110 cyclicPatch_(ptf.cyclicPatch_)
111{}
112
113
114template<class Type>
116(
117 const cyclicFvPatchField<Type>& ptf,
120:
121 coupledFvPatchField<Type>(ptf, iF),
122 cyclicPatch_(ptf.cyclicPatch_)
123{}
124
125
126// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
127
128template<class Type>
131{
132 const Field<Type>& iField = this->primitiveField();
133 const labelUList& nbrFaceCells =
134 cyclicPatch().cyclicPatch().neighbPatch().faceCells();
135
136 tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
137 Field<Type>& pnf = tpnf.ref();
138
139
140 if (doTransform())
141 {
142 forAll(pnf, facei)
144 pnf[facei] = transform
145 (
146 forwardT()[0], iField[nbrFaceCells[facei]]
147 );
148 }
149 }
150 else
151 {
152 forAll(pnf, facei)
153 {
154 pnf[facei] = iField[nbrFaceCells[facei]];
155 }
156 }
157
158 return tpnf;
159}
160
161
162template<class Type>
165{
168 (
169 this->primitiveField()
170 );
171
172 return refCast<const cyclicFvPatchField<Type>>
173 (
174 fld.boundaryField()[this->cyclicPatch().neighbPatchID()]
175 );
177
178
180template<class Type>
183 solveScalarField& result,
184 const bool add,
185 const lduAddressing& lduAddr,
186 const label patchId,
187 const solveScalarField& psiInternal,
188 const scalarField& coeffs,
189 const direction cmpt,
190 const Pstream::commsTypes commsType
191) const
192{
193 const labelUList& nbrFaceCells =
194 lduAddr.patchAddr
196 this->cyclicPatch().neighbPatchID()
197 );
198
199 solveScalarField pnf(psiInternal, nbrFaceCells);
200
201 // Transform according to the transformation tensors
202 transformCoupleField(pnf, cmpt);
203
204
205 const labelUList& faceCells = lduAddr.patchAddr(patchId);
206
207 // Multiply the field by coefficients and add into the result
208 this->addToInternalField(result, !add, faceCells, coeffs, pnf);
209}
210
211
212template<class Type>
214(
215 Field<Type>& result,
216 const bool add,
217 const lduAddressing& lduAddr,
218 const label patchId,
219 const Field<Type>& psiInternal,
220 const scalarField& coeffs,
222) const
223{
224 const labelList& nbrFaceCells =
225 lduAddr.patchAddr
226 (
227 this->cyclicPatch().neighbPatchID()
228 );
229
230 Field<Type> pnf(psiInternal, nbrFaceCells);
231
232 // Transform according to the transformation tensors
233 transformCoupleField(pnf);
234
235 const labelUList& faceCells = lduAddr.patchAddr(patchId);
236
237 // Multiply the field by coefficients and add into the result
238 this->addToInternalField(result, !add, faceCells, coeffs, pnf);
239}
240
241
242template<class Type>
244{
246}
248
249template<class Type>
251(
252 fvMatrix<Type>& matrix,
253 const label mat,
254 const direction cmpt
255)
256{
257 if (this->cyclicPatch().owner())
258 {
259 label index = this->patch().index();
260
261 const label globalPatchID =
262 matrix.lduMeshAssembly().patchLocalToGlobalMap()[mat][index];
263
264 const Field<scalar> intCoeffsCmpt
265 (
266 matrix.internalCoeffs()[globalPatchID].component(cmpt)
267 );
268
269 const Field<scalar> boundCoeffsCmpt
270 (
271 matrix.boundaryCoeffs()[globalPatchID].component(cmpt)
272 );
273
274 const labelUList& u = matrix.lduAddr().upperAddr();
275 const labelUList& l = matrix.lduAddr().lowerAddr();
276
277 const labelList& faceMap =
278 matrix.lduMeshAssembly().faceBoundMap()[mat][index];
279
280 forAll (faceMap, faceI)
281 {
282 label globalFaceI = faceMap[faceI];
283
284 const scalar boundCorr = -boundCoeffsCmpt[faceI];
285 const scalar intCorr = -intCoeffsCmpt[faceI];
286
287 matrix.upper()[globalFaceI] += boundCorr;
288 matrix.diag()[u[globalFaceI]] -= boundCorr;
289 matrix.diag()[l[globalFaceI]] -= intCorr;
290
291 if (matrix.asymmetric())
292 {
293 matrix.lower()[globalFaceI] += intCorr;
294 }
295 }
296
297 if (matrix.psi(mat).mesh().fluxRequired(this->internalField().name()))
298 {
299 matrix.internalCoeffs().set
300 (
301 globalPatchID, intCoeffsCmpt*pTraits<Type>::one
302 );
303 matrix.boundaryCoeffs().set
304 (
305 globalPatchID, boundCoeffsCmpt*pTraits<Type>::one
306 );
307
308 const label nbrPathID = this->cyclicPatch().neighbPatchID();
309
310 const label nbrGlobalPatchID =
311 matrix.lduMeshAssembly().patchLocalToGlobalMap()[mat][nbrPathID];
312
313 matrix.internalCoeffs().set
314 (
315 nbrGlobalPatchID, intCoeffsCmpt*pTraits<Type>::one
316
317 );
318 matrix.boundaryCoeffs().set
319 (
320 nbrGlobalPatchID, boundCoeffsCmpt*pTraits<Type>::one
321 );
322 }
323 }
324}
325
326// ************************************************************************* //
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))
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
Generic GeometricField class.
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:65
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
commsTypes
Types of communications.
Definition: UPstream.H:67
Abstract base class for coupled patches.
virtual void evaluate(const Pstream::commsTypes commsType)
Evaluate the patch field.
This boundary condition enforces a cyclic condition between a pair of boundaries.
const cyclicFvPatchField< Type > & neighbourPatchField() const
Return reference to neighbour patchField.
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 void manipulateMatrix(fvMatrix< Type > &m, const label iMatrix, const direction cmp)
Manipulate matrix.
tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled internal cell data.
Cyclic-plane patch.
Definition: cyclicFvPatch.H:58
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
Smooth ATC in cells next to a set of patches supplied by type.
Definition: faceCells.H:59
virtual bool write()
Write the output fields.
A special matrix type and solver, designed for finite volume solutions of scalar equations....
Definition: fvMatrix.H:121
const FieldField< Field, Type > & internalCoeffs() const noexcept
Definition: fvMatrix.H:470
const FieldField< Field, Type > & boundaryCoeffs() const noexcept
Definition: fvMatrix.H:484
const lduPrimitiveMeshAssembly & lduMeshAssembly()
Return optional lduAdressing.
Definition: fvMatrix.H:405
const GeometricField< Type, fvPatchField, volMesh > & psi(const label i=0) const
Return psi.
Definition: fvMatrix.H:412
A FieldMapper for finite-volume patch fields.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:82
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:368
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:362
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:71
virtual const word & name() const
Return name.
Definition: fvPatch.H:173
The class contains the addressing required by the lduMatrix: upper, lower and losort.
virtual const labelUList & upperAddr() const =0
Return upper addressing.
virtual const labelUList & lowerAddr() const =0
Return lower addressing.
virtual const labelUList & patchAddr(const label patchNo) const =0
Return patch to internal addressing given patch number.
scalarField & upper()
Definition: lduMatrix.C:203
const lduAddressing & lduAddr() const
Return the LDU addressing.
Definition: lduMatrix.H:578
scalarField & lower()
Definition: lduMatrix.C:174
scalarField & diag()
Definition: lduMatrix.C:192
bool asymmetric() const
Definition: lduMatrix.H:633
const labelListListList & faceBoundMap() const
Return boundary face map.
const labelListList & patchLocalToGlobalMap() const
Return patchLocalToGlobalMap.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
Definition: one.H:62
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
OBJstream os(runTime.globalPath()/outputName)
label patchId(-1)
Pair< int > faceMap(const label facePi, const face &faceP, const label faceNi, const face &faceN)
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
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
dict add("bounds", meshBb)
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:333
Spatial transformation functions for primitive fields.