1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright held by original author
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software; you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by the
13 Free Software Foundation; either version 2 of the License, or (at your
14 option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM; if not, write to the Free Software Foundation,
23 Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "engineMassFlowRateInletVelocityFvPatchVectorField.H"
28 #include "volFields.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "fvPatchFieldMapper.H"
31 #include "surfaceFields.H"
33 #include "interpolateXY.H"
36 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
39 engineMassFlowRateInletVelocityFvPatchVectorField::
40 engineMassFlowRateInletVelocityFvPatchVectorField
43 const DimensionedField<vector, volMesh>& iF
46 fixedValueFvPatchField<vector>(p, iF),
50 engineDB_((refCast<const engineTime>(this->db().time())))
54 engineMassFlowRateInletVelocityFvPatchVectorField::
55 engineMassFlowRateInletVelocityFvPatchVectorField
57 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
59 const DimensionedField<vector, volMesh>& iF,
60 const fvPatchFieldMapper& mapper
63 fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
64 phiName_(ptf.phiName_),
65 rhoName_(ptf.rhoName_),
66 timeDataFileName_(ptf.timeDataFileName_),
68 engineDB_((refCast<const engineTime>(this->db().time())))
72 engineMassFlowRateInletVelocityFvPatchVectorField::
73 engineMassFlowRateInletVelocityFvPatchVectorField
76 const DimensionedField<vector, volMesh>& iF,
77 const dictionary& dict
80 fixedValueFvPatchField<vector>(p, iF, dict),
83 timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()),
85 engineDB_((refCast<const engineTime>(this->db().time())))
87 if (dict.found("phi"))
89 dict.lookup("phi") >> phiName_;
92 if (dict.found("rho"))
94 dict.lookup("rho") >> rhoName_;
99 engineMassFlowRateInletVelocityFvPatchVectorField::
100 engineMassFlowRateInletVelocityFvPatchVectorField
102 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf
105 fixedValueFvPatchField<vector>(ptf),
106 phiName_(ptf.phiName_),
107 rhoName_(ptf.rhoName_),
108 timeDataFileName_(ptf.timeDataFileName_),
110 engineDB_((refCast<const engineTime>(this->db().time())))
114 engineMassFlowRateInletVelocityFvPatchVectorField::
115 engineMassFlowRateInletVelocityFvPatchVectorField
117 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
118 const DimensionedField<vector, volMesh>& iF
121 fixedValueFvPatchField<vector>(ptf, iF),
122 phiName_(ptf.phiName_),
123 rhoName_(ptf.rhoName_),
124 timeDataFileName_(ptf.timeDataFileName_),
126 engineDB_((refCast<const engineTime>(this->db().time())))
130 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
132 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::checkTable()
134 if (!timeDataPtr_.valid())
138 new graph("title", "x", "y", IFstream(timeDataFileName_)())
142 if (engineDB_.theta() < min(timeDataPtr_().x()))
146 "engineTimeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs()"
147 ) << "current time (" << engineDB_.theta()
148 << ") is less than the minimum in the data table ("
149 << min(timeDataPtr_().x()) << ')' << endl
150 << " Continuing with the value for the smallest time"
154 if (engineDB_.theta() < min(timeDataPtr_().x()))
158 "engineTimeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs()"
159 ) << "current time (" << engineDB_.theta()
160 << ") is greater than the maximum in the data table ("
161 << max(timeDataPtr_().x()) << ')' << endl
162 << " Continuing with the value for the largest time"
170 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
177 // a simpler way of doing this would be nice
180 scalar massFlowRate =
191 scalar avgU = -massFlowRate/gSum(patch().magSf());
193 vectorField n = patch().nf();
195 const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>
200 if (phi.dimensions() == dimVelocity*dimArea)
202 // volumetric flow-rate
205 else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
207 const fvPatchField<scalar>& rhop =
208 patch().lookupPatchField<volScalarField, scalar>(rhoName_);
211 operator==(n*avgU/rhop);
217 "engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()"
218 ) << "dimensions of phi are incorrect"
219 << "\n on patch " << this->patch().name()
220 << " of field " << this->dimensionedInternalField().name()
221 << " in file " << this->dimensionedInternalField().objectPath()
225 fixedValueFvPatchField<vector>::updateCoeffs();
229 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
231 fvPatchField<vector>::write(os);
233 if (phiName_ != "phi")
235 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
238 if (rhoName_ != "rho")
240 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
243 os.writeKeyword("timeDataFileName")
244 << timeDataFileName_ << token::END_STATEMENT << nl;
246 writeEntry("value", os);
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
257 engineMassFlowRateInletVelocityFvPatchVectorField
262 // ************************************************************************* //