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-2023 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 #include "volFields.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const fvPatch& p,
37 )
38 :
39  coupledFvPatchField<Type>(p, iF),
40  cyclicPatch_(refCast<const cyclicFvPatch>(p))
41 {}
42 
43 
44 template<class Type>
46 (
47  const fvPatch& p,
49  const dictionary& dict
50 )
51 :
52  coupledFvPatchField<Type>(p, iF, dict, false),
53  cyclicPatch_(refCast<const cyclicFvPatch>(p))
54 {
55  if (!isA<cyclicFvPatch>(p))
56  {
58  (
59  dict
60  ) << " 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(FatalIOError);
66  }
67 
69 }
70 
71 
72 template<class Type>
74 (
75  const cyclicFvPatchField<Type>& ptf,
76  const fvPatch& p,
78  const fvPatchFieldMapper& mapper
79 )
80 :
81  coupledFvPatchField<Type>(ptf, p, iF, mapper),
83  cyclicPatch_(refCast<const cyclicFvPatch>(p))
84 {
85  if (!isA<cyclicFvPatch>(this->patch()))
86  {
88  << "' not constraint type '" << typeName << "'"
89  << "\n for patch " << p.name()
90  << " of field " << this->internalField().name()
91  << " in file " << this->internalField().objectPath()
92  << exit(FatalIOError);
93  }
94 }
95 
96 
97 template<class Type>
99 (
100  const cyclicFvPatchField<Type>& ptf,
102 )
103 :
104  coupledFvPatchField<Type>(ptf, iF),
106  cyclicPatch_(ptf.cyclicPatch_)
107 {}
108 
109 
110 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
111 
112 template<class Type>
115 (
116  const Pstream::commsTypes
117 ) const
118 {
119  const Field<Type>& iField = this->primitiveField();
120  const labelUList& nbrFaceCells =
121  cyclicPatch().nbrPatch().faceCells();
122 
123  tmp<Field<Type>> tpnf(new Field<Type>(this->size()));
124  Field<Type>& pnf = tpnf.ref();
125 
126  forAll(pnf, facei)
127  {
128  pnf[facei] = transform().transform(iField[nbrFaceCells[facei]]);
129  }
130 
131  return tpnf;
132 }
133 
134 
135 template<class Type>
138 {
139  const VolField<Type>& fld =
140  static_cast<const VolField<Type>&>
141  (
142  this->primitiveField()
143  );
144 
145  return refCast<const cyclicFvPatchField<Type>>
146  (
147  fld.boundaryField()[this->cyclicPatch().nbrPatchID()]
148  );
149 }
150 
151 
152 template<class Type>
154 (
155  scalarField& result,
156  const scalarField& psiInternal,
157  const scalarField& coeffs,
158  const direction cmpt,
159  const Pstream::commsTypes
160 ) const
161 {
162  const labelUList& nbrFaceCells =
163  cyclicPatch().nbrPatch().faceCells();
164 
165  scalarField pnf(psiInternal, nbrFaceCells);
166 
167  // Transform according to the transformation tensors
168  transformCoupleField(pnf, cmpt);
169 
170  // Multiply the field by coefficients and add into the result
171  const labelUList& faceCells = cyclicPatch().faceCells();
172 
173  forAll(faceCells, elemI)
174  {
175  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
176  }
177 }
178 
179 
180 template<class Type>
182 (
183  Field<Type>& result,
184  const Field<Type>& psiInternal,
185  const scalarField& coeffs,
186  const Pstream::commsTypes
187 ) const
188 {
189  const labelUList& nbrFaceCells =
190  cyclicPatch().nbrPatch().faceCells();
191 
192  Field<Type> pnf(psiInternal, nbrFaceCells);
193 
194  // Transform according to the transformation tensors
195  transformCoupleField(pnf);
196 
197  // Multiply the field by coefficients and add into the result
198  const labelUList& faceCells = cyclicPatch().faceCells();
199 
200  forAll(faceCells, elemI)
201  {
202  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
203  }
204 }
205 
206 
207 template<class Type>
209 {
211 }
212 
213 
214 // ************************************************************************* //
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Pre-declare SubField and related Field type.
Definition: Field.H:82
static const char *const typeName
Definition: Field.H:105
Generic GeometricField class.
virtual void updateInterfaceMatrix(scalarField &, const scalarField &, const scalarField &, const direction, const Pstream::commsTypes commsType) const=0
Inherit updateInterfaceMatrix from lduInterfaceField.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:57
commsTypes
Types of communications.
Definition: UPstream.H:65
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.
cyclicFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes commsType) const
Return neighbour coupled internal cell data.
virtual void write(Ostream &os) const
Write.
const cyclicFvPatchField< Type > & nbrPatchField() const
Return reference to neighbour patchField.
Cyclic-plane patch.
Definition: cyclicFvPatch.H:55
Abstract base class for cyclic coupled interfaces.
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:160
friend dimensionSet transform(const dimensionSet &)
Return the argument; transformations do not change the dimensions.
Foam::fvPatchFieldMapper.
const DimensionedField< Type, volMesh > & internalField() const
Return dimensioned internal field reference.
Definition: fvPatchField.H:361
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:231
const fvPatch & patch() const
Return patch.
Definition: fvPatchField.H:355
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
virtual const word & name() const
Return name.
Definition: fvPatch.H:145
A class for managing temporary objects.
Definition: tmp.H:55
T & ref() const
Return non-const reference or generate a fatal error.
Definition: tmpI.H:181
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:318
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
gmvFile<< "tracers "<< particles.size()<< nl;{ pointField positions(particles.size());label particlei=0;forAllConstIter(Cloud< passiveParticle >, particles, iter) { positions[particlei++]=iter().position(mesh);} for(i=0;i< pTraits< point >::nComponents;i++) { forAll(positions, particlei) { gmvFile<< component(positions[particlei], i)<< ' ';} gmvFile<< nl;}}forAll(lagrangianScalarNames, i){ const word &name=lagrangianScalarNames[i];IOField< scalar > fld(IOobject(name, runTime.name(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
To & refCast(From &r)
Reference type cast template function.
Definition: typeInfo.H:111
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483
IOerror FatalIOError
uint8_t direction
Definition: direction.H:45
dictionary dict
volScalarField & p
Spatial transformation functions for primitive fields.