uniformMixedFaPatchField.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 faPatch& p,
37 )
38 :
39  mixedFaPatchField<Type>(p, iF),
40  refValueFunc_(nullptr),
41  refGradFunc_(nullptr),
42  valueFractionFunc_(nullptr)
43 {}
44 
45 
46 template<class Type>
48 (
49  const faPatch& p,
51  const Field<Type>& fld
52 )
53 :
54  mixedFaPatchField<Type>(p, iF, fld),
55  refValueFunc_(nullptr),
56  refGradFunc_(nullptr),
57  valueFractionFunc_(nullptr)
58 {}
59 
60 
61 template<class Type>
63 (
64  const faPatch& p,
66  const dictionary& dict
67 )
68 :
69  // Bypass dict constructor, default initialise as zero-gradient
70  mixedFaPatchField<Type>(p, iF, Foam::zero{}),
71  refValueFunc_
72  (
74  (
75  /* p.patch(), */
76  "uniformValue",
77  dict,
78  &iF.db()
79  )
80  ),
81  refGradFunc_
82  (
84  (
85  // p.patch(),
86  "uniformGradient",
87  dict,
88  &iF.db()
89  )
90  ),
91  valueFractionFunc_(nullptr)
92 {
93  faPatchFieldBase::readDict(dict); // Consistent with a dict constructor
94 
95  if (refValueFunc_)
96  {
97  if (refGradFunc_)
98  {
99  // Both value + gradient: needs valueFraction
100  valueFractionFunc_.reset
101  (
102  Function1<scalar>::New
103  (
104  /* p.patch(), */
105  "uniformValueFraction",
106  dict,
107  &iF.db()
108  )
109  );
110  }
111  }
112  else if (!refGradFunc_)
113  {
114  // Missing both value and gradient: FatalIOError
116  << "For " << this->internalField().name() << " on "
117  << this->patch().name() << nl
118  << "Require either or both: uniformValue and uniformGradient"
119  << " (possibly uniformValueFraction as well)" << nl
120  << exit(FatalIOError);
121  }
122 
123  // Use restart value if provided...
124  if (!this->readValueEntry(dict))
125  {
126  // Ensure field has reasonable initial values
127  this->extrapolateInternal();
128 
129  // Evaluate to assign a value
130  this->evaluate();
131  }
132 }
133 
134 
135 template<class Type>
137 (
138  const uniformMixedFaPatchField<Type>& ptf,
139  const faPatch& p,
140  const DimensionedField<Type, areaMesh>& iF,
141  const faPatchFieldMapper& mapper
142 )
143 :
144  mixedFaPatchField<Type>(ptf, p, iF, mapper),
145  refValueFunc_(ptf.refValueFunc_.clone(/*p.patch()*/)),
146  refGradFunc_(ptf.refGradFunc_.clone(/*p.patch()*/)),
147  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*p.patch()*/))
148 {}
149 
150 
151 template<class Type>
153 (
155 )
156 :
157  mixedFaPatchField<Type>(ptf),
158  refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)),
159  refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)),
160  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/))
161 {}
162 
163 
164 template<class Type>
166 (
169 )
170 :
171  mixedFaPatchField<Type>(ptf, iF),
172  refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)),
173  refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)),
174  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/))
175 {
176  // Evaluate the profile if defined
177  if (ptf.refValueFunc_ || ptf.refGradFunc_)
178  {
179  this->evaluate();
180  }
181 }
182 
183 
184 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185 
186 template<class Type>
188 {
189  if (this->updated())
190  {
191  return;
192  }
193 
194  const scalar t = this->db().time().timeOutputValue();
195 
196  if (refValueFunc_)
197  {
198  this->refValue() = refValueFunc_->value(t);
199 
200  if (refGradFunc_)
201  {
202  // Both value + gradient: has valueFraction too
203  this->valueFraction() = valueFractionFunc_->value(t);
204  }
205  else
206  {
207  // Has value only
208  this->valueFraction() = 1;
209  }
210  }
211  else
212  {
213  this->refValue() = Zero;
214  this->valueFraction() = 0;
215  }
216  if (refGradFunc_)
217  {
218  this->refGrad() = refGradFunc_->value(t);
219  }
220  else
221  {
222  this->refGrad() = Zero;
223  }
224 
225  // Missing both value and gradient is caught as an error in
226  // dictionary constructor, but treated as zero-gradient here.
227 
229 }
230 
231 
232 template<class Type>
234 {
236 
237  if (refValueFunc_)
238  {
239  refValueFunc_->writeData(os);
240  }
241  if (refGradFunc_)
242  {
243  refGradFunc_->writeData(os);
244  }
245  if (valueFractionFunc_)
246  {
247  valueFractionFunc_->writeData(os);
248  }
249 
250  // For visualisation / restart
252 }
253 
254 
255 // ************************************************************************* //
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
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.
constexpr char nl
The newline &#39;\n&#39; character (0x0a)
Definition: Ostream.H:50
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: faPatchField.H:345
virtual void write(Ostream &os) const
Write includes "value" entry (for visualisation / restart)
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.
const objectRegistry & db() const noexcept
Return the local objectRegistry.
Definition: IOobject.C:450
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
OBJstream os(runTime.globalPath()/outputName)
static autoPtr< Function1< Type > > NewIfPresent(const word &entryName, const dictionary &dict, const word &redirectType, const objectRegistry *obrPtr=nullptr)
An optional selector, with fallback redirection.
Definition: Function1New.C:209
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition: faPatch.H:72
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:637
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
Definition: faPatchField.C:234
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
const std::string patch
OpenFOAM patch number as a std::string.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
This boundary condition provides &#39;mixed&#39; type boundary condition that mix a uniform fixed value and a...
volScalarField & p
uniformMixedFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
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