mixedFvPatchField.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-2024 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 "mixedFvPatchField.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class Type>
32 (
33  const fvPatch& p,
35 )
36 :
37  fvPatchField<Type>(p, iF),
38  refValue_(p.size()),
39  refGrad_(p.size()),
40  valueFraction_(p.size())
41 {}
42 
43 
44 template<class Type>
46 (
47  const fvPatch& p,
49  const dictionary& dict,
50  const bool valuesRequired
51 )
52 :
53  fvPatchField<Type>(p, iF, dict, false),
54  refValue_(p.size()),
55  refGrad_(p.size()),
56  valueFraction_(p.size())
57 {
58  if (valuesRequired)
59  {
60  if (dict.found("refValue"))
61  {
62  refValue_ =
64  (
65  "refValue",
66  iF.dimensions(),
67  dict,
68  p.size()
69  );
70  }
71  else
72  {
74  << "Essential entry 'refValue' missing"
75  << exit(FatalIOError);
76  }
77 
78  if (dict.found("refGradient"))
79  {
80  refGrad_ =
82  (
83  "refGradient",
84  iF.dimensions()/dimLength,
85  dict,
86  p.size()
87  );
88  }
89  else
90  {
92  << "Essential entry 'refGradient' missing"
93  << exit(FatalIOError);
94  }
95 
96  if (dict.found("valueFraction"))
97  {
98  valueFraction_ =
99  Field<scalar>("valueFraction", unitFraction, dict, p.size());
100  }
101  else
102  {
104  << "Essential entry 'valueFraction' missing"
105  << exit(FatalIOError);
106  }
107 
108  evaluate();
109  }
110 }
111 
112 
113 template<class Type>
115 (
116  const mixedFvPatchField<Type>& ptf,
117  const fvPatch& p,
119  const fieldMapper& mapper,
120  const bool mappingRequired
121 )
122 :
123  fvPatchField<Type>(ptf, p, iF, mapper, mappingRequired),
124  refValue_(p.size()),
125  refGrad_(p.size()),
126  valueFraction_(p.size())
127 {
128  if (mappingRequired)
129  {
130  mapper(refValue_, ptf.refValue_);
131  mapper(refGrad_, ptf.refGrad_);
132  mapper(valueFraction_, ptf.valueFraction_);
133  }
134 }
135 
136 
137 template<class Type>
139 (
140  const mixedFvPatchField<Type>& ptf,
142 )
143 :
144  fvPatchField<Type>(ptf, iF),
145  refValue_(ptf.refValue_),
146  refGrad_(ptf.refGrad_),
147  valueFraction_(ptf.valueFraction_)
148 {}
149 
150 
151 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
152 
153 template<class Type>
155 (
156  const fvPatchField<Type>& ptf,
157  const fieldMapper& mapper
158 )
159 {
160  fvPatchField<Type>::map(ptf, mapper);
161 
162  const mixedFvPatchField<Type>& mptf =
163  refCast<const mixedFvPatchField<Type>>(ptf);
164 
165  mapper(refValue_, mptf.refValue_);
166  mapper(refGrad_, mptf.refGrad_);
167  mapper(valueFraction_, mptf.valueFraction_);
168 }
169 
170 
171 template<class Type>
173 {
175 
176  const mixedFvPatchField<Type>& mptf =
177  refCast<const mixedFvPatchField<Type>>(ptf);
178 
179  refValue_.reset(mptf.refValue_);
180  refGrad_.reset(mptf.refGrad_);
181  valueFraction_.reset(mptf.valueFraction_);
182 }
183 
184 
185 template<class Type>
187 {
188  if (!this->updated())
189  {
190  this->updateCoeffs();
191  }
192 
194  (
195  valueFraction_*refValue_
196  +
197  (1.0 - valueFraction_)*
198  (
199  this->patchInternalField()
200  + refGrad_/this->patch().deltaCoeffs()
201  )
202  );
203 
205 }
206 
207 
208 template<class Type>
211 {
212  return
213  valueFraction_
214  *(refValue_ - this->patchInternalField())
215  *this->patch().deltaCoeffs()
216  + (1.0 - valueFraction_)*refGrad_;
217 }
218 
219 
220 template<class Type>
223 (
224  const tmp<scalarField>&
225 ) const
226 {
227  return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
228 }
229 
230 
231 template<class Type>
234 (
235  const tmp<scalarField>&
236 ) const
237 {
238  return
239  valueFraction_*refValue_
240  + (1.0 - valueFraction_)*refGrad_/this->patch().deltaCoeffs();
241 }
242 
243 
244 template<class Type>
247 {
248  return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
249 }
250 
251 
252 template<class Type>
255 {
256  return
257  valueFraction_*this->patch().deltaCoeffs()*refValue_
258  + (1.0 - valueFraction_)*refGrad_;
259 }
260 
261 
262 template<class Type>
264 {
266  writeEntry(os, "refValue", refValue_);
267  writeEntry(os, "refGradient", refGrad_);
268  writeEntry(os, "valueFraction", valueFraction_);
269  writeEntry(os, "value", *this);
270 }
271 
272 
273 // ************************************************************************* //
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const dimensionSet & dimensions() const
Return dimensions.
Pre-declare SubField and related Field type.
Definition: Field.H:83
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
A list of keyword definitions, which are a keyword followed by any number of values (e....
Definition: dictionary.H:162
Abstract base class for field mapping.
Definition: fieldMapper.H:48
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:88
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:209
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:229
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:195
virtual void map(const fvPatchField< Type > &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:185
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:64
This boundary condition provides a base class for 'mixed' type boundary conditions,...
mixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
virtual void write(Ostream &) const
Write.
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > snGrad() const
Return gradient at boundary.
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
virtual void map(const fvPatchField< Type > &, const fieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Traits class for primitives.
Definition: pTraits.H:53
A class for managing temporary objects.
Definition: tmp.H:55
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:346
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
const dimensionSet dimLength
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
IOerror FatalIOError
const unitConversion unitFraction
dictionary dict
volScalarField & p