cyclicAMIFvPatchField.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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class Type>
30 (
31  const fvPatch& p,
33 )
34 :
37  cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p))
38 {}
39 
40 
41 template<class Type>
43 (
44  const fvPatch& p,
46  const dictionary& dict
47 )
48 :
49  coupledFvPatchField<Type>(p, iF, dict, dict.found("value")),
51  cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p))
52 {
53  if (!isA<cyclicAMIFvPatch>(p))
54  {
56  (
57  dict
58  ) << " patch type '" << p.type()
59  << "' not constraint type '" << typeName << "'"
60  << "\n for patch " << p.name()
61  << " of field " << this->internalField().name()
62  << " in file " << this->internalField().objectPath()
63  << exit(FatalIOError);
64  }
65 
66  if (!dict.found("value"))
67  {
68  if (this->coupled())
69  {
70  this->evaluate(Pstream::commsTypes::blocking);
71  }
72  else
73  {
74  fvPatchField<Type>::operator=(this->patchInternalField());
75  }
76  }
77 }
78 
79 
80 template<class Type>
82 (
83  const cyclicAMIFvPatchField<Type>& ptf,
84  const fvPatch& p,
86  const fvPatchFieldMapper& mapper
87 )
88 :
89  coupledFvPatchField<Type>(ptf, p, iF, mapper),
91  cyclicAMIPatch_(refCast<const cyclicAMIFvPatch>(p))
92 {
93  if (!isA<cyclicAMIFvPatch>(this->patch()))
94  {
96  << "' not constraint type '" << typeName << "'"
97  << "\n for patch " << p.name()
98  << " of field " << this->internalField().name()
99  << " in file " << this->internalField().objectPath()
100  << exit(FatalIOError);
101  }
102 }
103 
104 
105 template<class Type>
107 (
108  const cyclicAMIFvPatchField<Type>& ptf,
110 )
111 :
112  coupledFvPatchField<Type>(ptf, iF),
114  cyclicAMIPatch_(ptf.cyclicAMIPatch_)
115 {}
116 
117 
118 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
119 
120 template<class Type>
122 {
123  return cyclicAMIPatch_.coupled();
124 }
125 
126 
127 template<class Type>
130 (
131  const Pstream::commsTypes
132 ) const
133 {
134  const Field<Type>& iField = this->primitiveField();
135  const labelUList& nbrFaceCells =
136  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
137 
138  Field<Type> pnf(iField, nbrFaceCells);
139 
140  tmp<Field<Type>> tpnf;
141  if (cyclicAMIPatch_.applyLowWeightCorrection())
142  {
143  tpnf = cyclicAMIPatch_.interpolate(pnf, this->patchInternalField()());
144  }
145  else
146  {
147  tpnf = cyclicAMIPatch_.interpolate(pnf);
148  }
149 
150  transform().transform(tpnf.ref(), tpnf());
151 
152  return tpnf;
153 }
154 
155 
156 template<class Type>
159 {
162  (
163  this->primitiveField()
164  );
165 
166  return refCast<const cyclicAMIFvPatchField<Type>>
167  (
168  fld.boundaryField()[cyclicAMIPatch_.nbrPatchID()]
169  );
170 }
171 
172 
173 template<class Type>
175 (
176  scalarField& result,
177  const scalarField& psiInternal,
178  const scalarField& coeffs,
179  const direction cmpt,
180  const Pstream::commsTypes
181 ) const
182 {
183  const labelUList& nbrFaceCells =
184  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
185 
186  scalarField pnf(psiInternal, nbrFaceCells);
187 
188  // Transform according to the transformation tensors
189  transformCoupleField(pnf, cmpt);
190 
191  if (cyclicAMIPatch_.applyLowWeightCorrection())
192  {
193  scalarField pif(psiInternal, cyclicAMIPatch_.faceCells());
194  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
195  }
196  else
197  {
198  pnf = cyclicAMIPatch_.interpolate(pnf);
199  }
200 
201  // Multiply the field by coefficients and add into the result
202  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
203 
204  forAll(faceCells, elemI)
205  {
206  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
207  }
208 }
209 
210 
211 template<class Type>
213 (
214  Field<Type>& result,
215  const Field<Type>& psiInternal,
216  const scalarField& coeffs,
217  const Pstream::commsTypes
218 ) const
219 {
220  const labelUList& nbrFaceCells =
221  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
222 
223  Field<Type> pnf(psiInternal, nbrFaceCells);
224 
225  // Transform according to the transformation tensors
226  transformCoupleField(pnf);
227 
228  if (cyclicAMIPatch_.applyLowWeightCorrection())
229  {
230  Field<Type> pif(psiInternal, cyclicAMIPatch_.faceCells());
231  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
232  }
233  else
234  {
235  pnf = cyclicAMIPatch_.interpolate(pnf);
236  }
237 
238  // Multiply the field by coefficients and add into the result
239  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
240 
241  forAll(faceCells, elemI)
242  {
243  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
244  }
245 }
246 
247 
248 template<class Type>
250 {
252  writeEntry(os, "value", *this);
253 }
254 
255 
256 // ************************************************************************* //
dictionary dict
virtual bool coupled() const
Return true if coupled. Note that the underlying patch.
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:434
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.
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
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:66
Generic GeometricField class.
Abstract base class for cyclic AMI coupled interfaces.
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))
const cyclicAMIFvPatchField< Type > & nbrPatchField() const
Return reference to neighbour patchField.
Pre-declare SubField and related Field type.
Definition: Field.H:56
virtual void write(Ostream &os) const
Write.
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
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:54
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
#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...
friend dimensionSet transform(const dimensionSet &)
Return the argument; transformations do not change the dimensions.
cyclicAMIFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
This boundary condition enforces a cyclic condition between a pair of boundaries, whereby communicati...
dimensionSet transform(const dimensionSet &)
Definition: dimensionSet.C:483
virtual tmp< Field< Type > > patchNeighbourField(const Pstream::commsTypes) const
Return neighbour coupled internal cell data.
IOerror FatalIOError