uniformMixedFvPatchField.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) 2023 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*---------------------------------------------------------------------------*/
27 
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class Type>
34 (
35  const fvPatch& p,
37 )
38 :
39  mixedFvPatchField<Type>(p, iF),
40  refValueFunc_(nullptr),
41  refGradFunc_(nullptr),
42  valueFractionFunc_(nullptr)
43 {}
44 
45 
46 template<class Type>
48 (
49  const fvPatch& p,
51  const Field<Type>& fld
52 )
53 :
54  mixedFvPatchField<Type>(p, iF, fld),
55  refValueFunc_(nullptr),
56  refGradFunc_(nullptr),
57  valueFractionFunc_(nullptr)
58 {}
59 
60 
61 template<class Type>
63 (
64  const fvPatch& p,
66  const dictionary& dict
67 )
68 :
69  // Bypass dict constructor, default initialise as zero-gradient
70  mixedFvPatchField<Type>(p, iF, Foam::zero{}),
71  refValueFunc_
72  (
73  PatchFunction1<Type>::NewIfPresent(p.patch(), "uniformValue", dict)
74  ),
75  refGradFunc_
76  (
77  PatchFunction1<Type>::NewIfPresent(p.patch(), "uniformGradient", dict)
78  ),
79  valueFractionFunc_(nullptr)
80 {
81  fvPatchFieldBase::readDict(dict); // Consistent with a dict constructor
82 
83  if (refValueFunc_)
84  {
85  if (refGradFunc_)
86  {
87  // Both value + gradient: needs valueFraction
88  valueFractionFunc_.reset
89  (
90  PatchFunction1<scalar>::New
91  (
92  p.patch(),
93  "uniformValueFraction",
94  dict
95  )
96  );
97  }
98  }
99  else if (!refGradFunc_)
100  {
101  // Missing both value and gradient: FatalIOError
103  << "For " << this->internalField().name() << " on "
104  << this->patch().name() << nl
105  << "Require either or both: uniformValue and uniformGradient"
106  << " (possibly uniformValueFraction as well)" << nl
107  << exit(FatalIOError);
108  }
109 
110  // Use restart value if provided...
111  if (!this->readValueEntry(dict))
112  {
113  // Ensure field has reasonable initial values
114  this->extrapolateInternal();
115 
116  // Evaluate to assign a value
117  this->evaluate();
118  }
119 }
120 
121 
122 template<class Type>
124 (
125  const uniformMixedFvPatchField<Type>& ptf,
126  const fvPatch& p,
127  const DimensionedField<Type, volMesh>& iF,
128  const fvPatchFieldMapper& mapper
129 )
130 :
131  mixedFvPatchField<Type>(ptf, p, iF, mapper),
132  refValueFunc_(ptf.refValueFunc_.clone(p.patch())),
133  refGradFunc_(ptf.refGradFunc_.clone(p.patch())),
134  valueFractionFunc_(ptf.valueFractionFunc_.clone(p.patch()))
135 {}
136 
137 
138 template<class Type>
140 (
142 )
143 :
144  mixedFvPatchField<Type>(ptf),
145  refValueFunc_(ptf.refValueFunc_.clone(this->patch().patch())),
146  refGradFunc_(ptf.refGradFunc_.clone(this->patch().patch())),
147  valueFractionFunc_(ptf.valueFractionFunc_.clone(this->patch().patch()))
148 {}
149 
150 
151 template<class Type>
153 (
156 )
157 :
158  mixedFvPatchField<Type>(ptf, iF),
159  refValueFunc_(ptf.refValueFunc_.clone(this->patch().patch())),
160  refGradFunc_(ptf.refGradFunc_.clone(this->patch().patch())),
161  valueFractionFunc_(ptf.valueFractionFunc_.clone(this->patch().patch()))
162 {
163  // Evaluate the profile if defined
164  if (ptf.refValueFunc_ || ptf.refGradFunc_)
165  {
166  this->evaluate();
167  }
168 }
169 
170 
171 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172 
173 template<class Type>
175 {
176  if (this->updated())
177  {
178  return;
179  }
180 
181  const scalar t = this->db().time().timeOutputValue();
182 
183  if (refValueFunc_)
184  {
185  this->refValue() = refValueFunc_->value(t);
186 
187  if (refGradFunc_)
188  {
189  // Both value + gradient: has valueFraction too
190  this->valueFraction() = valueFractionFunc_->value(t);
191  }
192  else
193  {
194  // Has value only
195  this->valueFraction() = 1;
196  }
197  }
198  else
199  {
200  this->refValue() = Zero;
201  this->valueFraction() = 0;
202  }
203  if (refGradFunc_)
204  {
205  this->refGrad() = refGradFunc_->value(t);
206  }
207  else
208  {
209  this->refGrad() = Zero;
210  }
211 
212  // Missing both value and gradient is caught as an error in
213  // dictionary constructor, but treated as zero-gradient here.
214 
216 }
217 
218 
219 template<class Type>
221 {
223 
224  if (refValueFunc_)
225  {
226  refValueFunc_->writeData(os);
227  }
228  if (refGradFunc_)
229  {
230  refGradFunc_->writeData(os);
231  }
232  if (valueFractionFunc_)
233  {
234  valueFractionFunc_->writeData(os);
235  }
236 
237  // For visualisation / restart
239 }
240 
241 
242 // ************************************************************************* //
dictionary dict
This boundary condition provides &#39;mixed&#39; type boundary condition that mix a uniform fixed value and a...
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:125
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:129
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition: fvPatch.H:70
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.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: fvPatchField.H:375
virtual void write(Ostream &) const
Write.
Definition: fvPatchField.C:372
virtual void readDict(const dictionary &dict)
Read dictionary entries.
virtual void write(Ostream &os) const
Write.
uniformMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
Generic templated field type.
Definition: Field.H:62
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.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
gmvFile<< "tracers "<< particles.size()<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().x()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().y()<< ' ';}gmvFile<< nl;for(const passiveParticle &p :particles){ gmvFile<< p.position().z()<< ' ';}gmvFile<< nl;for(const word &name :lagrangianScalarNames){ IOField< scalar > fld(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:627
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: fvPatchField.C:309
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Definition: areaFieldsFwd.H:42
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const std::string patch
OpenFOAM patch number as a std::string.
static autoPtr< PatchFunction1< Type > > NewIfPresent(const polyPatch &pp, const word &entryName, const dictionary &dict, const bool faceValues=true)
An optional selector.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
volScalarField & p
Namespace for OpenFOAM.
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