Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
10License
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
32template<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
46template<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
61template<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
122template<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
138template<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
151template<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();
168}
169
170
171// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
172
173template<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
219template<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// ************************************************************************* //
Info<< nl;Info<< "Write faMesh in vtk format:"<< nl;{ vtk::uindirectPatchWriter writer(aMesh.patch(), fileName(aMesh.time().globalPath()/vtkBaseFileName));writer.writeGeometry();globalIndex procAddr(aMesh.nFaces());labelList cellIDs;if(UPstream::master()) { cellIDs.resize(procAddr.totalSize());for(const labelRange &range :procAddr.ranges()) { auto slice=cellIDs.slice(range);slice=identity(range);} } writer.beginCellData(4);writer.writeProcIDs();writer.write("cellID", cellIDs);writer.write("area", aMesh.S().field());writer.write("normal", aMesh.faceAreaNormals());writer.beginPointData(1);writer.write("normal", aMesh.pointAreaNormals());Info<< " "<< writer.output().name()<< nl;}{ vtk::lineWriter writer(aMesh.points(), aMesh.edges(), fileName(aMesh.time().globalPath()/(vtkBaseFileName+"-edges")));writer.writeGeometry();writer.beginCellData(4);writer.writeProcIDs();{ Field< scalar > fld(faMeshTools::flattenEdgeField(aMesh.magLe(), true))
Field with dimensions and associated with geometry type GeoMesh which is used to size the field and a...
Generic templated field type that is much like a Foam::List except that it is expected to hold numeri...
Definition Field.H:172
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
const objectRegistry & db() const
The associated objectRegistry.
virtual void readDict(const dictionary &dict)
Read dictionary entries.
const fvPatch & patch() const noexcept
Return the patch.
bool updated() const noexcept
True if the boundary condition has already been updated.
A FieldMapper for finite-volume patch fields.
virtual void write(Ostream &) const
Write.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
const DimensionedField< Type, volMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal field.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
bool readValueEntry(const dictionary &dict, IOobjectOption::readOption readOpt=IOobjectOption::LAZY_READ)
Read the "value" entry into *this.
void extrapolateInternal()
Assign the patch field from the internal field.
A finiteVolume patch using a polyPatch and a fvBoundaryMesh.
Definition fvPatch.H:71
virtual const word & name() const
Return name.
Definition fvPatch.H:210
This boundary condition provides a base class for 'mixed' type boundary conditions,...
mixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual Field< Type > & refGrad()
virtual Field< Type > & refValue()
virtual scalarField & valueFraction()
virtual void evaluate(const Pstream::commsTypes commsType=Pstream::commsTypes::buffered)
Evaluate the patch field.
This boundary condition provides 'mixed' type boundary condition that mix a uniform fixed value and a...
uniformMixedFvPatchField(const fvPatch &, const DimensionedField< Type, volMesh > &)
Construct from patch and internal field.
virtual void write(Ostream &os) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
virtual tmp< fvPatchField< Type > > clone() const
Return a clone.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
volScalarField & p
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition error.H:629
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
IOerror FatalIOError
Error stream (stdout output on all processes), with additional 'FOAM FATAL IO ERROR' header text and ...
static constexpr const zero Zero
Global zero (0).
Definition zero.H:127
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition errorManip.H:125
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
dictionary dict
A non-counting (dummy) refCount.
Definition refCount.H:55