1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | foam-extend: Open Source CFD
4 \\ / O peration | Version: 3.2
5 \\ / A nd | Web: http://www.foam-extend.org
6 \\/ M anipulation | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
9 This file is part of foam-extend.
11 foam-extend 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 3 of the License, or (at your
14 option) any later version.
16 foam-extend is distributed in the hope that it will be useful, but
17 WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with foam-extend. If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "engineMassFlowRateInletVelocityFvPatchVectorField.H"
27 #include "volFields.H"
28 #include "addToRunTimeSelectionTable.H"
29 #include "fvPatchFieldMapper.H"
30 #include "surfaceFields.H"
32 #include "interpolateXY.H"
35 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
38 engineMassFlowRateInletVelocityFvPatchVectorField::
39 engineMassFlowRateInletVelocityFvPatchVectorField
42 const DimensionedField<vector, volMesh>& iF
45 fixedValueFvPatchField<vector>(p, iF),
49 engineDB_((refCast<const engineTime>(this->db().time())))
53 engineMassFlowRateInletVelocityFvPatchVectorField::
54 engineMassFlowRateInletVelocityFvPatchVectorField
56 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
58 const DimensionedField<vector, volMesh>& iF,
59 const fvPatchFieldMapper& mapper
62 fixedValueFvPatchField<vector>(ptf, p, iF, mapper),
63 phiName_(ptf.phiName_),
64 rhoName_(ptf.rhoName_),
65 timeDataFileName_(ptf.timeDataFileName_),
67 engineDB_((refCast<const engineTime>(this->db().time())))
71 engineMassFlowRateInletVelocityFvPatchVectorField::
72 engineMassFlowRateInletVelocityFvPatchVectorField
75 const DimensionedField<vector, volMesh>& iF,
76 const dictionary& dict
79 fixedValueFvPatchField<vector>(p, iF, dict),
82 timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()),
84 engineDB_((refCast<const engineTime>(this->db().time())))
86 if (dict.found("phi"))
88 dict.lookup("phi") >> phiName_;
91 if (dict.found("rho"))
93 dict.lookup("rho") >> rhoName_;
98 engineMassFlowRateInletVelocityFvPatchVectorField::
99 engineMassFlowRateInletVelocityFvPatchVectorField
101 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf
104 fixedValueFvPatchField<vector>(ptf),
105 phiName_(ptf.phiName_),
106 rhoName_(ptf.rhoName_),
107 timeDataFileName_(ptf.timeDataFileName_),
109 engineDB_((refCast<const engineTime>(this->db().time())))
113 engineMassFlowRateInletVelocityFvPatchVectorField::
114 engineMassFlowRateInletVelocityFvPatchVectorField
116 const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
117 const DimensionedField<vector, volMesh>& iF
120 fixedValueFvPatchField<vector>(ptf, iF),
121 phiName_(ptf.phiName_),
122 rhoName_(ptf.rhoName_),
123 timeDataFileName_(ptf.timeDataFileName_),
125 engineDB_((refCast<const engineTime>(this->db().time())))
129 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
131 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::checkTable()
133 if (!timeDataPtr_.valid())
137 new graph("title", "x", "y", IFstream(timeDataFileName_)())
141 if (engineDB_.theta() < min(timeDataPtr_().x()))
145 "engineTimeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs()"
146 ) << "current time (" << engineDB_.theta()
147 << ") is less than the minimum in the data table ("
148 << min(timeDataPtr_().x()) << ')' << endl
149 << " Continuing with the value for the smallest time"
153 if (engineDB_.theta() < min(timeDataPtr_().x()))
157 "engineTimeVaryingUniformFixedValueFvPatchField<Type>::updateCoeffs()"
158 ) << "current time (" << engineDB_.theta()
159 << ") is greater than the maximum in the data table ("
160 << max(timeDataPtr_().x()) << ')' << endl
161 << " Continuing with the value for the largest time"
169 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
176 // a simpler way of doing this would be nice
179 scalar massFlowRate =
190 scalar avgU = -massFlowRate/gSum(patch().magSf());
192 vectorField n = patch().nf();
194 const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>
199 if (phi.dimensions() == dimVelocity*dimArea)
201 // volumetric flow-rate
204 else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
206 const fvPatchField<scalar>& rhop =
207 lookupPatchField<volScalarField, scalar>(rhoName_);
210 operator==(n*avgU/rhop);
216 "engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()"
217 ) << "dimensions of phi are incorrect"
218 << "\n on patch " << this->patch().name()
219 << " of field " << this->dimensionedInternalField().name()
220 << " in file " << this->dimensionedInternalField().objectPath()
224 fixedValueFvPatchField<vector>::updateCoeffs();
228 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
230 fvPatchField<vector>::write(os);
232 if (phiName_ != "phi")
234 os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
237 if (rhoName_ != "rho")
239 os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
242 os.writeKeyword("timeDataFileName")
243 << timeDataFileName_ << token::END_STATEMENT << nl;
245 writeEntry("value", os);
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
256 engineMassFlowRateInletVelocityFvPatchVectorField
261 // ************************************************************************* //