mixedFvPatchField.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "mixedFvPatchField.H"
30 
31 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
32 
33 template<class Type>
35 (
36  const dictionary& dict,
38 )
39 {
40  if (!IOobjectOption::isAnyRead(readOpt)) return false;
41  const auto& p = fvPatchFieldBase::patch();
42 
43 
44  // If there is a 'refValue', also require all others
45  const auto* hasValue = dict.findEntry("refValue", keyType::LITERAL);
46 
47  if (!hasValue && IOobjectOption::isReadOptional(readOpt))
48  {
49  return false;
50  }
51 
52  const auto* hasGrad = dict.findEntry("refGradient", keyType::LITERAL);
53  const auto* hasFrac = dict.findEntry("valueFraction", keyType::LITERAL);
54 
55  // Combined error message on failure
56  if (!hasValue || !hasGrad || !hasFrac)
57  {
59  << "Required entries:";
60 
61  if (!hasValue) FatalIOError << " 'refValue'";
62  if (!hasGrad) FatalIOError << " 'refGradient'";
63  if (!hasFrac) FatalIOError << " 'valueFraction'";
64 
66  << " : missing for patch " << p.name()
67  << " : in dictionary " << dict.relativeName() << nl
68  << exit(FatalIOError);
69  }
70 
71  // Everything verified - can assign
72  refValue_.assign(*hasValue, p.size());
73  refGrad_.assign(*hasGrad, p.size());
74  valueFraction_.assign(*hasFrac, p.size());
75 
76  return true;
77 }
78 
79 
80 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
81 
82 template<class Type>
84 (
85  const fvPatch& p,
87 )
88 :
89  fvPatchField<Type>(p, iF),
90  refValue_(p.size()),
91  refGrad_(p.size()),
92  valueFraction_(p.size()),
93  source_(p.size(), Zero)
94 {}
95 
96 
97 template<class Type>
99 (
100  const fvPatch& p,
102  const Foam::zero
103 )
104 :
105  fvPatchField<Type>(p, iF),
106  refValue_(p.size(), Zero),
107  refGrad_(p.size(), Zero),
108  valueFraction_(p.size(), Zero),
109  source_(p.size(), Zero)
110 {}
111 
112 
113 template<class Type>
115 (
116  const fvPatch& p,
118  const dictionary& dict,
119  IOobjectOption::readOption requireMixed
120 )
121 :
122  // The "value" entry is not required
123  fvPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
124  refValue_(p.size()),
125  refGrad_(p.size()),
126  valueFraction_(p.size()),
127  source_(p.size(), Zero)
128 {
129  if (!readMixedEntries(dict, requireMixed))
130  {
131  // Not read (eg, optional and missing): no evaluate possible/need
132  return;
133  }
134 
135  // Could also check/clamp fraction to 0-1 range
136  evaluate();
137 }
138 
139 
140 template<class Type>
142 (
143  const mixedFvPatchField<Type>& ptf,
144  const fvPatch& p,
146  const fvPatchFieldMapper& mapper
147 )
148 :
149  fvPatchField<Type>(ptf, p, iF, mapper),
150  refValue_(ptf.refValue_, mapper),
151  refGrad_(ptf.refGrad_, mapper),
152  valueFraction_(ptf.valueFraction_, mapper),
153  source_(ptf.source_, mapper)
154 {
155  if (notNull(iF) && mapper.hasUnmapped())
156  {
158  << "On field " << iF.name() << " patch " << p.name()
159  << " patchField " << this->type()
160  << " : mapper does not map all values." << nl
161  << " To avoid this warning fully specify the mapping in derived"
162  << " patch fields." << endl;
163  }
164 }
165 
166 
167 template<class Type>
169 (
170  const mixedFvPatchField<Type>& ptf
171 )
172 :
173  fvPatchField<Type>(ptf),
174  refValue_(ptf.refValue_),
175  refGrad_(ptf.refGrad_),
176  valueFraction_(ptf.valueFraction_),
177  source_(ptf.source_)
178 {}
179 
180 
181 template<class Type>
183 (
184  const mixedFvPatchField<Type>& ptf,
186 )
187 :
188  fvPatchField<Type>(ptf, iF),
189  refValue_(ptf.refValue_),
190  refGrad_(ptf.refGrad_),
191  valueFraction_(ptf.valueFraction_),
192  source_(ptf.source_)
193 {}
194 
195 
196 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
197 
198 template<class Type>
200 (
201  const fvPatchFieldMapper& m
202 )
203 {
205  refValue_.autoMap(m);
206  refGrad_.autoMap(m);
207  valueFraction_.autoMap(m);
208  source_.autoMap(m);
209 }
210 
211 
212 template<class Type>
214 (
215  const fvPatchField<Type>& ptf,
216  const labelList& addr
217 )
218 {
219  fvPatchField<Type>::rmap(ptf, addr);
220 
221  const mixedFvPatchField<Type>& mptf =
222  refCast<const mixedFvPatchField<Type>>(ptf);
223 
224  refValue_.rmap(mptf.refValue_, addr);
225  refGrad_.rmap(mptf.refGrad_, addr);
226  valueFraction_.rmap(mptf.valueFraction_, addr);
227  source_.rmap(mptf.source_, addr);
228 }
229 
230 
231 template<class Type>
233 {
234  if (!this->updated())
235  {
236  this->updateCoeffs();
237  }
238 
239  Field<Type>::operator=
240  (
241  lerp
242  (
243  this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
244  refValue_,
245  valueFraction_
246  )
247  );
250 }
251 
252 
253 template<class Type>
256 {
257  return lerp
258  (
259  refGrad_,
260  (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
261  valueFraction_
262  );
263 }
264 
265 
266 template<class Type>
269 (
270  const tmp<scalarField>&
271 ) const
272 {
273  return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
274 }
275 
276 
277 template<class Type>
280 (
281  const tmp<scalarField>&
282 ) const
283 {
284  return lerp
285  (
286  refGrad_/this->patch().deltaCoeffs(),
287  refValue_,
288  valueFraction_
289  );
290 }
291 
292 
293 template<class Type>
296 {
297  return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
298 }
299 
300 
301 template<class Type>
304 {
305  return lerp
306  (
307  refGrad_,
308  this->patch().deltaCoeffs()*refValue_,
309  valueFraction_
310  );
311 }
312 
313 
314 template<class Type>
316 {
318  refValue_.writeEntry("refValue", os);
319  refGrad_.writeEntry("refGradient", os);
320  valueFraction_.writeEntry("valueFraction", os);
321  source_.writeEntry("source", os);
323 }
324 
325 
326 // ************************************************************************* //
dictionary dict
type
Types of root.
Definition: Roots.H:52
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
commsTypes
Communications types.
Definition: UPstream.H:72
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
const word & name() const noexcept
Return the object name.
Definition: IOobjectI.H:195
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:531
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
virtual tmp< Field< Type > > snGrad() const
Return gradient at boundary.
This boundary condition provides a base class for &#39;mixed&#39; type boundary conditions, i.e. conditions that mix fixed value and patch-normal gradient conditions.
Abstract base class with a fat-interface to all derived classes covering all possible ways in which t...
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
bool readMixedEntries(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the &#39;refValue&#39;, &#39;refGradient&#39; and &#39;valueFraction&#39; entries into their respective places...
void write(vtk::formatter &fmt, const Type &val, const label n=1)
Component-wise write of a value (N times)
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
A FieldMapper for finite-volume patch fields.
string evaluate(label fieldWidth, const std::string &s, size_t pos=0, size_t len=std::string::npos)
String evaluation with specified (positive, non-zero) field width.
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
virtual bool hasUnmapped() const =0
Any unmapped values?
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual void rmap(const fvPatchField< Type > &, const labelList &)
Reverse map the given fvPatchField onto this fvPatchField.
OBJstream os(runTime.globalPath()/outputName)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
#define WarningInFunction
Report a warning using Foam::Warning.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
mixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
A simple container of IOobject preferences. Can also be used for general handling of read/no-read/rea...
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
const std::string patch
OpenFOAM patch number as a std::string.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
virtual void write(Ostream &) const
Write.
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
bool notNull(const T *ptr)
True if ptr is not a pointer (of type T) to the nullObject.
Definition: nullObject.H:246
virtual void autoMap(const fvPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional &#39;FOAM FATAL IO ERROR&#39; header text and ...
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:127
readOption
Enumeration defining read preferences.