cyclicFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2022 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "cyclicFvPatchField.H"
27 #include "transformField.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class Type>
33 (
34  const fvPatch& p,
36 )
37 :
39  cyclicPatch_(refCast<const cyclicFvPatch>(p))
40 {}
41 
42 
43 template<class Type>
45 (
46  const fvPatch& p,
48  const dictionary& dict
49 )
50 :
51  coupledFvPatchField<Type>(p, iF, dict, false),
52  cyclicPatch_(refCast<const cyclicFvPatch>(p))
53 {
54  if (!isA<cyclicFvPatch>(p))
55  {
57  (
58  dict
59  ) << " patch type '" << p.type()
60  << "' not constraint type '" << typeName << "'"
61  << "\n for patch " << p.name()
62  << " of field " << this->internalField().name()
63  << " in file " << this->internalField().objectPath()
64  << exit(FatalIOError);
65  }
66 
67  this->evaluate(Pstream::commsTypes::blocking);
68 }
69 
70 
71 template<class Type>
73 (
74  const cyclicFvPatchField<Type>& ptf,
75  const fvPatch& p,
77  const fvPatchFieldMapper& mapper
78 )
79 :
80  coupledFvPatchField<Type>(ptf, p, iF, mapper),
82  cyclicPatch_(refCast<const cyclicFvPatch>(p))
83 {
84  if (!isA<cyclicFvPatch>(this->patch()))
85  {
87  << "' not constraint type '" << typeName << "'"
88  << "\n for patch " << p.name()
89  << " of field " << this->internalField().name()
90  << " in file " << this->internalField().objectPath()
91  << exit(FatalIOError);
92  }
93 }
94 
95 
96 template<class Type>
98 (
99  const cyclicFvPatchField<Type>& ptf,
101 )
102 :
103  coupledFvPatchField<Type>(ptf, iF),
105  cyclicPatch_(ptf.cyclicPatch_)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Type>
114 (
115  const Pstream::commsTypes
116 ) const
117 {
118  const Field<Type>& iField = this->primitiveField();
119  const labelUList& nbrFaceCells =
120  cyclicPatch().nbrPatch().faceCells();
121 
122  tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
123  Field<Type>& pnf = tpnf.ref();
124 
125  forAll(pnf, facei)
126  {
127  pnf[facei] = transform().transform(iField[nbrFaceCells[facei]]);
128  }
129 
130  return tpnf;
131 }
132 
133 
134 template<class Type>
137 {
140  (
141  this->primitiveField()
142  );
143 
144  return refCast<const cyclicFvPatchField<Type>>
145  (
146  fld.boundaryField()[this->cyclicPatch().nbrPatchID()]
147  );
148 }
149 
150 
151 template<class Type>
153 (
154  scalarField& result,
155  const scalarField& psiInternal,
156  const scalarField& coeffs,
157  const direction cmpt,
158  const Pstream::commsTypes
159 ) const
160 {
161  const labelUList& nbrFaceCells =
162  cyclicPatch().nbrPatch().faceCells();
163 
164  scalarField pnf(psiInternal, nbrFaceCells);
165 
166  // Transform according to the transformation tensors
167  transformCoupleField(pnf, cmpt);
168 
169  // Multiply the field by coefficients and add into the result
170  const labelUList& faceCells = cyclicPatch().faceCells();
171 
172  forAll(faceCells, elemI)
173  {
174  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
175  }
176 }
177 
178 
179 template<class Type>
181 (
182  Field<Type>& result,
183  const Field<Type>& psiInternal,
184  const scalarField& coeffs,
185  const Pstream::commsTypes
186 ) const
187 {
188  const labelUList& nbrFaceCells =
189  cyclicPatch().nbrPatch().faceCells();
190 
191  Field<Type> pnf(psiInternal, nbrFaceCells);
192 
193  // Transform according to the transformation tensors
194  transformCoupleField(pnf);
195 
196  // Multiply the field by coefficients and add into the result
197  const labelUList& faceCells = cyclicPatch().faceCells();
198 
199  forAll(faceCells, elemI)
200  {
201  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
202  }
203 }
204 
205 
206 template<class Type>
208 {
210 }
211 
212 
213 // ************************************************************************* //
dictionary dict
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void evaluate(GeometricField< Type, PatchField, GeoMesh > &result, const Function1< Type > &func, const GeometricField< Type, PatchField, GeoMesh > &x)
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
const Boundary & boundaryField() const
Return const-reference to the boundary field.
commsTypes
Types of communications.
Definition: UPstream.H:64
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
uint8_t direction
Definition: direction.H:45
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:63
Generic GeometricField class.
const cyclicFvPatchField< Type > & nbrPatchField() const
Return reference to neighbour patchField.
Spatial transformation functions for primitive fields.
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().x()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().y()<< ' ';}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){ gmvFile<< iter().position().z()<< ' ';}gmvFile<< nl;forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
Pre-declare SubField and related Field type.
Definition: Field.H:56
Foam::fvPatchFieldMapper.
void write(std::ostream &os, const bool binary, List< floatScalar > &fField)
Write floats ascii or binary.
Abstract base class for coupled patches.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:60
This boundary condition enforces a cyclic condition between a pair of boundaries. ...
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType) const
Return neighbour coupled internal cell data.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
virtual void write(Ostream &os) const
Write.
virtual void updateInterfaceMatrix(scalarField &result, const scalarField &psiInternal, const scalarField &coeffs, const direction cmpt, const Pstream::commsTypes commsType) const
Update result field based on interface functionality.
friend dimensionSet transform(const dimensionSet &)
Return the argument; transformations do not change the dimensions.
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
Abstract base class for cyclic coupled interfaces.
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483
IOerror FatalIOError
cyclicFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.