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,
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 Field<Type>& iField = this->primitiveField();
132  const labelUList& nbrFaceCells =
133  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
134 
135  Field<Type> pnf(iField, nbrFaceCells);
136 
137  tmp<Field<Type>> tpnf;
138  if (cyclicAMIPatch_.applyLowWeightCorrection())
139  {
140  tpnf = cyclicAMIPatch_.interpolate(pnf, this->patchInternalField()());
141  }
142  else
143  {
144  tpnf = cyclicAMIPatch_.interpolate(pnf);
145  }
146 
147  transform().transform(tpnf.ref(), tpnf());
148 
149  return tpnf;
150 }
151 
152 
153 template<class Type>
156 {
159  (
160  this->primitiveField()
161  );
162 
163  return refCast<const cyclicAMIFvPatchField<Type>>
164  (
165  fld.boundaryField()[cyclicAMIPatch_.nbrPatchID()]
166  );
167 }
168 
169 
170 template<class Type>
172 (
173  scalarField& result,
174  const scalarField& psiInternal,
175  const scalarField& coeffs,
176  const direction cmpt,
177  const Pstream::commsTypes
178 ) const
179 {
180  const labelUList& nbrFaceCells =
181  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
182 
183  scalarField pnf(psiInternal, nbrFaceCells);
184 
185  // Transform according to the transformation tensors
186  transformCoupleField(pnf, cmpt);
187 
188  if (cyclicAMIPatch_.applyLowWeightCorrection())
189  {
190  scalarField pif(psiInternal, cyclicAMIPatch_.faceCells());
191  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
192  }
193  else
194  {
195  pnf = cyclicAMIPatch_.interpolate(pnf);
196  }
197 
198  // Multiply the field by coefficients and add into the result
199  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
200 
201  forAll(faceCells, elemI)
202  {
203  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
204  }
205 }
206 
207 
208 template<class Type>
210 (
211  Field<Type>& result,
212  const Field<Type>& psiInternal,
213  const scalarField& coeffs,
214  const Pstream::commsTypes
215 ) const
216 {
217  const labelUList& nbrFaceCells =
218  cyclicAMIPatch_.cyclicAMIPatch().nbrPatch().faceCells();
219 
220  Field<Type> pnf(psiInternal, nbrFaceCells);
221 
222  // Transform according to the transformation tensors
223  transformCoupleField(pnf);
224 
225  if (cyclicAMIPatch_.applyLowWeightCorrection())
226  {
227  Field<Type> pif(psiInternal, cyclicAMIPatch_.faceCells());
228  pnf = cyclicAMIPatch_.interpolate(pnf, pif);
229  }
230  else
231  {
232  pnf = cyclicAMIPatch_.interpolate(pnf);
233  }
234 
235  // Multiply the field by coefficients and add into the result
236  const labelUList& faceCells = cyclicAMIPatch_.faceCells();
237 
238  forAll(faceCells, elemI)
239  {
240  result[faceCells[elemI]] -= coeffs[elemI]*pnf[elemI];
241  }
242 }
243 
244 
245 template<class Type>
247 {
249  writeEntry(os, "value", *this);
250 }
251 
252 
253 // ************************************************************************* //
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:323
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:62
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:335
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