mixedFaPatchField.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) 2016-2017 Wikki Ltd
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 "mixedFaPatchField.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 = faPatchFieldBase::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 faPatch& p,
87 )
88 :
89  faPatchField<Type>(p, iF),
90  refValue_(p.size()),
91  refGrad_(p.size()),
92  valueFraction_(p.size())
93 {}
94 
95 
96 template<class Type>
98 (
99  const faPatch& p,
101  const Foam::zero
102 )
103 :
104  faPatchField<Type>(p, iF),
105  refValue_(p.size(), Zero),
106  refGrad_(p.size(), Zero),
107  valueFraction_(p.size(), Zero)
108 {}
109 
110 
111 template<class Type>
113 (
114  const faPatch& p,
116  const dictionary& dict,
117  IOobjectOption::readOption requireMixed
118 )
119 :
120  // The "value" entry is not required
121  faPatchField<Type>(p, iF, dict, IOobjectOption::NO_READ),
122  refValue_(p.size()),
123  refGrad_(p.size()),
124  valueFraction_(p.size())
125 {
126  if (!readMixedEntries(dict, requireMixed))
127  {
128  // Not read (eg, optional and missing): no evaluate possible/need
129  return;
130  }
131 
132  // Could also check/clamp fraction to 0-1 range
133  evaluate();
134 }
135 
136 
137 template<class Type>
139 (
140  const mixedFaPatchField<Type>& ptf,
141  const faPatch& p,
143  const faPatchFieldMapper& mapper
144 )
145 :
146  faPatchField<Type>(ptf, p, iF, mapper),
147  refValue_(ptf.refValue_, mapper),
148  refGrad_(ptf.refGrad_, mapper),
149  valueFraction_(ptf.valueFraction_, mapper)
150 {}
151 
152 
153 template<class Type>
155 (
156  const mixedFaPatchField<Type>& ptf
157 )
158 :
159  faPatchField<Type>(ptf),
160  refValue_(ptf.refValue_),
161  refGrad_(ptf.refGrad_),
162  valueFraction_(ptf.valueFraction_)
163 {}
164 
165 
166 template<class Type>
168 (
169  const mixedFaPatchField<Type>& ptf,
171 )
172 :
173  faPatchField<Type>(ptf, iF),
174  refValue_(ptf.refValue_),
175  refGrad_(ptf.refGrad_),
176  valueFraction_(ptf.valueFraction_)
177 {}
178 
179 
180 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
181 
182 template<class Type>
184 (
185  const faPatchFieldMapper& m
186 )
187 {
189  refValue_.autoMap(m);
190  refGrad_.autoMap(m);
191  valueFraction_.autoMap(m);
192 }
193 
194 
195 template<class Type>
197 (
198  const faPatchField<Type>& ptf,
199  const labelList& addr
200 )
201 {
202  faPatchField<Type>::rmap(ptf, addr);
203 
204  const auto& mptf = refCast<const mixedFaPatchField<Type>>(ptf);
205 
206  refValue_.rmap(mptf.refValue_, addr);
207  refGrad_.rmap(mptf.refGrad_, addr);
208  valueFraction_.rmap(mptf.valueFraction_, addr);
209 }
210 
211 
212 template<class Type>
214 {
215  if (!this->updated())
216  {
217  this->updateCoeffs();
218  }
219 
221  (
222  lerp
223  (
224  this->patchInternalField() + refGrad_/this->patch().deltaCoeffs(),
225  refValue_,
226  valueFraction_
227  )
228  );
229 
231 }
232 
233 
234 template<class Type>
236 {
237  return lerp
238  (
239  refGrad_,
240  (refValue_ - this->patchInternalField())*this->patch().deltaCoeffs(),
241  valueFraction_
242  );
243 }
244 
245 
246 template<class Type>
248 (
249  const tmp<scalarField>&
250 ) const
251 {
252  return Type(pTraits<Type>::one)*(1.0 - valueFraction_);
253 }
254 
255 
256 template<class Type>
258 (
259  const tmp<scalarField>&
260 ) const
261 {
262  return lerp
263  (
264  refGrad_/this->patch().deltaCoeffs(),
265  refValue_,
266  valueFraction_
267  );
268 }
269 
270 
271 template<class Type>
274 {
275  return -Type(pTraits<Type>::one)*valueFraction_*this->patch().deltaCoeffs();
276 }
277 
278 
279 template<class Type>
282 {
283  return lerp
284  (
285  refGrad_,
286  this->patch().deltaCoeffs()*refValue_,
287  valueFraction_
288  );
289 }
290 
291 
292 template<class Type>
294 {
296  refValue_.writeEntry("refValue", os);
297  refGrad_.writeEntry("refGradient", os);
298  valueFraction_.writeEntry("valueFraction", os);
300 }
301 
302 
303 // ************************************************************************* //
dictionary dict
virtual void write(Ostream &os) const
Write.
Definition: faPatchField.C:253
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
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.
virtual tmp< Field< Type > > snGrad() const
Return gradient at boundary.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A traits class, which is primarily used for primitives and vector-space.
Definition: pTraits.H:75
virtual tmp< Field< Type > > gradientInternalCoeffs() const
Return the matrix diagonal coefficients corresponding to the.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: faPatchField.H:317
faPatchField<Type> abstract base class. This class gives a fat-interface to all derived classes cover...
Definition: areaFieldsFwd.H:56
friend Ostream & operator(Ostream &, const Field< Type > &)
bool readMixedEntries(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "refValue", "refGradient" and "valueFraction" entries into their respective places...
virtual tmp< Field< Type > > valueInternalCoeffs(const tmp< scalarField > &) const
Return the matrix diagonal coefficients corresponding to the.
virtual void autoMap(const faPatchFieldMapper &)
Map (and resize as needed) from self given a mapping object.
virtual tmp< Field< Type > > gradientBoundaryCoeffs() const
Return the matrix source coefficients corresponding to the.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
virtual tmp< Field< Type > > valueBoundaryCoeffs(const tmp< scalarField > &) const
Return the matrix source coefficients corresponding to the.
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
OBJstream os(runTime.globalPath()/outputName)
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
dimensioned< Type > lerp(const dimensioned< Type > &a, const dimensioned< Type > &b, const scalar t)
void autoMap(const FieldMapper &map, const bool applyFlip=true)
Map from self.
Definition: Field.C:466
virtual void rmap(const faPatchField< Type > &, const labelList &)
Reverse map the given faPatchField onto this faPatchField.
Definition: faPatchField.C:224
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field, sets updated() to false.
Definition: faPatchField.C:241
mixedFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
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
virtual void write(Ostream &) const
Write.
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
volScalarField & p
A class for managing temporary objects.
Definition: HashPtrTable.H:50
A FieldMapper for finite-area patch fields.
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.