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-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 "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_ = Field<Type>("refValue", dict, p.size());
63  }
64  else
65  {
67  << "Essential entry 'refValue' missing"
68  << exit(FatalIOError);
69  }
70 
71  if (dict.found("refGradient"))
72  {
73  refGrad_ = Field<Type>("refGradient", dict, p.size());
74  }
75  else
76  {
78  << "Essential entry 'refGradient' missing"
79  << exit(FatalIOError);
80  }
81 
82  if (dict.found("valueFraction"))
83  {
84  valueFraction_ = Field<scalar>("valueFraction", dict, p.size());
85  }
86  else
87  {
89  << "Essential entry 'valueFraction' missing"
90  << exit(FatalIOError);
91  }
92 
93  evaluate();
94  }
95 }
96 
97 
98 template<class Type>
100 (
101  const mixedFvPatchField<Type>& ptf,
102  const fvPatch& p,
104  const fvPatchFieldMapper& mapper,
105  const bool mappingRequired
106 )
107 :
108  fvPatchField<Type>(ptf, p, iF, mapper, mappingRequired),
109  refValue_(mapper(ptf.refValue_)),
110  refGrad_(mapper(ptf.refGrad_)),
111  valueFraction_(mapper(ptf.valueFraction_))
112 {}
113 
114 
115 template<class Type>
117 (
118  const mixedFvPatchField<Type>& ptf,
120 )
121 :
122  fvPatchField<Type>(ptf, iF),
123  refValue_(ptf.refValue_),
124  refGrad_(ptf.refGrad_),
125  valueFraction_(ptf.valueFraction_)
126 {}
127 
128 
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
130 
131 template<class Type>
133 (
134  const fvPatchField<Type>& ptf,
135  const fvPatchFieldMapper& mapper
136 )
137 {
138  fvPatchField<Type>::map(ptf, mapper);
139 
140  const mixedFvPatchField<Type>& mptf =
141  refCast<const mixedFvPatchField<Type>>(ptf);
142 
143  mapper(refValue_, mptf.refValue_);
144  mapper(refGrad_, mptf.refGrad_);
145  mapper(valueFraction_, mptf.valueFraction_);
146 }
147 
148 
149 template<class Type>
151 {
153 
154  const mixedFvPatchField<Type>& mptf =
155  refCast<const mixedFvPatchField<Type>>(ptf);
156 
157  refValue_.reset(mptf.refValue_);
158  refGrad_.reset(mptf.refGrad_);
159  valueFraction_.reset(mptf.valueFraction_);
160 }
161 
162 
163 template<class Type>
165 {
166  if (!this->updated())
167  {
168  this->updateCoeffs();
169  }
170 
172  (
173  valueFraction_*refValue_
174  +
175  (1.0 - valueFraction_)*
176  (
177  this->patchInternalField()
178  + refGrad_/this->patch().deltaCoeffs()
179  )
180  );
181 
183 }
184 
185 
186 template<class Type>
189 {
190  return
191  valueFraction_
192  *(refValue_ - this->patchInternalField())
193  *this->patch().deltaCoeffs()
194  + (1.0 - valueFraction_)*refGrad_;
195 }
196 
197 
198 template<class Type>
201 (
202  const tmp<scalarField>&
203 ) const
204 {
205  return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
206 }
207 
208 
209 template<class Type>
212 (
213  const tmp<scalarField>&
214 ) const
215 {
216  return
217  valueFraction_*refValue_
218  + (1.0 - valueFraction_)*refGrad_/this->patch().deltaCoeffs();
219 }
220 
221 
222 template<class Type>
225 {
226  return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
227 }
228 
229 
230 template<class Type>
233 {
234  return
235  valueFraction_*this->patch().deltaCoeffs()*refValue_
236  + (1.0 - valueFraction_)*refGrad_;
237 }
238 
239 
240 template<class Type>
242 {
244  writeEntry(os, "refValue", refValue_);
245  writeEntry(os, "refGradient", refGrad_);
246  writeEntry(os, "valueFraction", valueFraction_);
247  writeEntry(os, "value", *this);
248 }
249 
250 
251 // ************************************************************************* //
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
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:160
Foam::fvPatchFieldMapper.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
Definition: fvPatchField.H:87
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets Updated to false.
Definition: fvPatchField.C:211
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:231
virtual void reset(const fvPatchField< Type > &)
Reset the fvPatchField to the given fvPatchField.
Definition: fvPatchField.C:197
virtual void map(const fvPatchField< Type > &, const fvPatchFieldMapper &)
Map the given fvPatchField onto this fvPatchField.
Definition: fvPatchField.C:187
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 void map(const fvPatchField< Type > &, const fvPatchFieldMapper &)
Map the given fvPatchField onto this fvPatchField.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
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:318
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:124
void writeEntry(Ostream &os, const HashTable< T, Key, Hash > &ht)
Definition: HashTableIO.C:96
IOerror FatalIOError
dictionary dict
volScalarField & p