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-2020 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
109 )
110 :
113  cyclicAMIPatch_(ptf.cyclicAMIPatch_)
114 {}
115 
116 
117 template<class Type>
119 (
120  const cyclicAMIFvPatchField<Type>& ptf,
122 )
123 :
124  coupledFvPatchField<Type>(ptf, iF),
126  cyclicAMIPatch_(ptf.cyclicAMIPatch_)
127 {}
128 
129 
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 
132 template<class Type>
134 {
135  return cyclicAMIPatch_.coupled();
136 }
137 
138 
139 template<class Type>
142 {
143  const Field<Type>& iField = this->primitiveField();
144  const labelUList& nbrFaceCells =
145  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
146 
147  Field<Type> pnf(iField, nbrFaceCells);
148 
149  tmp<Field<Type>> tpnf;
150  if (cyclicAMIPatch_.applyLowWeightCorrection())
151  {
152  tpnf = cyclicAMIPatch_.interpolate(pnf, this->patchInternalField()());
153  }
154  else
155  {
156  tpnf = cyclicAMIPatch_.interpolate(pnf);
157  }
158 
159  transform().transform(tpnf.ref(), tpnf());
160 
161  return tpnf;
162 }
163 
164 
165 template<class Type>
168 {
171  (
172  this->primitiveField()
173  );
174 
175  return refCast<const cyclicAMIFvPatchField<Type>>
176  (
177  fld.boundaryField()[cyclicAMIPatch_.nbrPatchID()]
178  );
179 }
180 
181 
182 template<class Type>
184 (
185  scalarField& result,
186  const scalarField& psiInternal,
187  const scalarField& coeffs,
188  const direction cmpt,
189  const Pstream::commsTypes
190 ) const
191 {
192  const labelUList& nbrFaceCells =
193  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
194 
195  scalarField pnf(psiInternal, nbrFaceCells);
196 
197  // Transform according to the transformation tensors
198  transformCoupleField(pnf, cmpt);
199 
200  if (cyclicAMIPatch_.applyLowWeightCorrection())
201  {
202  scalarField pif(psiInternal, cyclicAMIPatch_.faceCells());
203  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
204  }
205  else
206  {
207  pnf = cyclicAMIPatch_.interpolate(pnf);
208  }
209 
210  // Multiply the field by coefficients and add into the result
211  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
212 
213  forAll(faceCells, elemI)
214  {
215  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
216  }
217 }
218 
219 
220 template<class Type>
222 (
223  Field<Type>& result,
224  const Field<Type>& psiInternal,
225  const scalarField& coeffs,
226  const Pstream::commsTypes
227 ) const
228 {
229  const labelUList& nbrFaceCells =
230  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
231 
232  Field<Type> pnf(psiInternal, nbrFaceCells);
233 
234  // Transform according to the transformation tensors
235  transformCoupleField(pnf);
236 
237  if (cyclicAMIPatch_.applyLowWeightCorrection())
238  {
239  Field<Type> pif(psiInternal, cyclicAMIPatch_.faceCells());
240  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
241  }
242  else
243  {
244  pnf = cyclicAMIPatch_.interpolate(pnf);
245  }
246 
247  // Multiply the field by coefficients and add into the result
248  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
249 
250  forAll(faceCells, elemI)
251  {
252  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
253  }
254 }
255 
256 
257 template<class Type>
259 {
261  writeEntry(os, "value", *this);
262 }
263 
264 
265 // ************************************************************************* //
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
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:158
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
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:174
uint8_t direction
Definition: direction.H:45
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:61
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
virtual tmp< Field< Type > > patchNeighbourField() const
Return neighbour coupled internal cell data.
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:331
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:477
IOerror FatalIOError