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  )
79  ),
80  refGradFunc_
81  (
83  (
84  // p.patch(),
85  "uniformGradient",
86  dict
87  )
88  ),
89  valueFractionFunc_(nullptr)
90 {
91  faPatchFieldBase::readDict(dict); // Consistent with a dict constructor
92 
93  if (refValueFunc_)
94  {
95  if (refGradFunc_)
96  {
97  // Both value + gradient: needs valueFraction
98  valueFractionFunc_.reset
99  (
100  Function1<scalar>::New
101  (
102  /* p.patch(), */
103  "uniformValueFraction",
104  dict
105  )
106  );
107  }
108  }
109  else if (!refGradFunc_)
110  {
111  // Missing both value and gradient: FatalIOError
113  << "For " << this->internalField().name() << " on "
114  << this->patch().name() << nl
115  << "Require either or both: uniformValue and uniformGradient"
116  << " (possibly uniformValueFraction as well)" << nl
117  << exit(FatalIOError);
118  }
119 
120  // Use restart value if provided...
121  if (!this->readValueEntry(dict))
122  {
123  // Ensure field has reasonable initial values
124  this->extrapolateInternal();
125 
126  // Evaluate to assign a value
127  this->evaluate();
128  }
129 }
130 
131 
132 template<class Type>
134 (
135  const uniformMixedFaPatchField<Type>& ptf,
136  const faPatch& p,
137  const DimensionedField<Type, areaMesh>& iF,
138  const faPatchFieldMapper& mapper
139 )
140 :
141  mixedFaPatchField<Type>(ptf, p, iF, mapper),
142  refValueFunc_(ptf.refValueFunc_.clone(/*p.patch()*/)),
143  refGradFunc_(ptf.refGradFunc_.clone(/*p.patch()*/)),
144  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*p.patch()*/))
145 {}
146 
147 
148 template<class Type>
150 (
152 )
153 :
154  mixedFaPatchField<Type>(ptf),
155  refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)),
156  refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)),
157  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/))
158 {}
159 
160 
161 template<class Type>
163 (
166 )
167 :
168  mixedFaPatchField<Type>(ptf, iF),
169  refValueFunc_(ptf.refValueFunc_.clone(/*this->patch().patch()*/)),
170  refGradFunc_(ptf.refGradFunc_.clone(/*this->patch().patch()*/)),
171  valueFractionFunc_(ptf.valueFractionFunc_.clone(/*this->patch().patch()*/))
172 {
173  // Evaluate the profile if defined
174  if (ptf.refValueFunc_ || ptf.refGradFunc_)
175  {
176  this->evaluate();
177  }
178 }
179 
180 
181 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
182 
183 template<class Type>
185 {
186  if (this->updated())
187  {
188  return;
189  }
190 
191  const scalar t = this->db().time().timeOutputValue();
192 
193  if (refValueFunc_)
194  {
195  this->refValue() = refValueFunc_->value(t);
196 
197  if (refGradFunc_)
198  {
199  // Both value + gradient: has valueFraction too
200  this->valueFraction() = valueFractionFunc_->value(t);
201  }
202  else
203  {
204  // Has value only
205  this->valueFraction() = 1;
206  }
207  }
208  else
209  {
210  this->refValue() = Zero;
211  this->valueFraction() = 0;
212  }
213  if (refGradFunc_)
214  {
215  this->refGrad() = refGradFunc_->value(t);
216  }
217  else
218  {
219  this->refGrad() = Zero;
220  }
221 
222  // Missing both value and gradient is caught as an error in
223  // dictionary constructor, but treated as zero-gradient here.
224 
226 }
227 
228 
229 template<class Type>
231 {
233 
234  if (refValueFunc_)
235  {
236  refValueFunc_->writeData(os);
237  }
238  if (refGradFunc_)
239  {
240  refGradFunc_->writeData(os);
241  }
242  if (valueFractionFunc_)
243  {
244  valueFractionFunc_->writeData(os);
245  }
246 
247  // For visualisation / restart
249 }
250 
251 
252 // ************************************************************************* //
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 readDict(const dictionary &dict)
Read dictionary entries.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
Definition: faPatchField.H:317
virtual void write(Ostream &os) const
Write.
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
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::blocking)
Evaluate the patch field.
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:627
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...
Definition: areaFieldsFwd.H:42
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