Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 faPatch& p,
37)
38:
39 mixedFaPatchField<Type>(p, iF),
40 refValueFunc_(nullptr),
41 refGradFunc_(nullptr),
42 valueFractionFunc_(nullptr)
43{}
44
45
46template<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
61template<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 (
73 Function1<Type>::NewIfPresent
74 (
75 /* p.patch(), */
76 "uniformValue",
77 dict,
78 &iF.db()
79 )
80 ),
81 refGradFunc_
82 (
83 Function1<Type>::NewIfPresent
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
135template<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
151template<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
164template<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();
181}
182
183
184// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
185
186template<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
232template<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// ************************************************************************* //
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
Top level data entry class for use in dictionaries. Provides a mechanism to specify a variable as a c...
Definition Function1.H:92
const word & name() const noexcept
Return the object name.
Definition IOobjectI.H:205
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:59
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.
bool updated() const noexcept
True if the boundary condition has already been updated.
const faPatch & patch() const noexcept
Return the patch.
A FieldMapper for finite-area patch fields.
void writeValueEntry(Ostream &os) const
Write *this field as a "value" entry.
virtual void write(Ostream &os) const
Write.
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
const DimensionedField< Type, areaMesh > & internalField() const noexcept
Return const-reference to the dimensioned internal 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.
Finite area patch class. Used for 2-D non-Euclidian finite area method.
Definition faPatch.H:76
This boundary condition provides a base class for 'mixed' type boundary conditions,...
mixedFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
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.
const word & name() const noexcept
The patch name.
This boundary condition provides 'mixed' type boundary condition that mix a uniform fixed value and a...
virtual tmp< faPatchField< Type > > clone() const
Return clone.
virtual void write(Ostream &os) const
Write includes "value" entry (for visualisation / restart).
virtual void updateCoeffs()
Update the coefficients associated with the patch field.
uniformMixedFaPatchField(const faPatch &, const DimensionedField< Type, areaMesh > &)
Construct from patch and internal field.
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