Formatting
[foam-extend-3.2.git] / src / engine / derivedFvPatchFields / engineMassFlowRateInletVelocity / engineMassFlowRateInletVelocityFvPatchVectorField.C
blob9c1263fce1f9e609450366b0354ecfcc6dd9c973
1 /*---------------------------------------------------------------------------*\
2   =========                 |
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 -------------------------------------------------------------------------------
8 License
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"
31 #include "graph.H"
32 #include "interpolateXY.H"
33 #include "IFstream.H"
35 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
37 Foam::
38 engineMassFlowRateInletVelocityFvPatchVectorField::
39 engineMassFlowRateInletVelocityFvPatchVectorField
41     const fvPatch& p,
42     const DimensionedField<vector, volMesh>& iF
45     fixedValueFvPatchField<vector>(p, iF),
46     phiName_("phi"),
47     rhoName_("rho"),
48     timeDataPtr_(NULL),
49     engineDB_((refCast<const engineTime>(this->db().time())))
52 Foam::
53 engineMassFlowRateInletVelocityFvPatchVectorField::
54 engineMassFlowRateInletVelocityFvPatchVectorField
56     const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
57     const fvPatch& p,
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_),
66     timeDataPtr_(NULL),
67     engineDB_((refCast<const engineTime>(this->db().time())))
70 Foam::
71 engineMassFlowRateInletVelocityFvPatchVectorField::
72 engineMassFlowRateInletVelocityFvPatchVectorField
74     const fvPatch& p,
75     const DimensionedField<vector, volMesh>& iF,
76     const dictionary& dict
79     fixedValueFvPatchField<vector>(p, iF, dict),
80     phiName_("phi"),
81     rhoName_("rho"),
82     timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()),
83     timeDataPtr_(NULL),
84     engineDB_((refCast<const engineTime>(this->db().time())))
86     if (dict.found("phi"))
87     {
88         dict.lookup("phi") >> phiName_;
89     }
91     if (dict.found("rho"))
92     {
93         dict.lookup("rho") >> rhoName_;
94     }
97 Foam::
98 engineMassFlowRateInletVelocityFvPatchVectorField::
99 engineMassFlowRateInletVelocityFvPatchVectorField
101     const engineMassFlowRateInletVelocityFvPatchVectorField& ptf
104     fixedValueFvPatchField<vector>(ptf),
105     phiName_(ptf.phiName_),
106     rhoName_(ptf.rhoName_),
107     timeDataFileName_(ptf.timeDataFileName_),
108     timeDataPtr_(NULL),
109     engineDB_((refCast<const engineTime>(this->db().time())))
112 Foam::
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_),
124     timeDataPtr_(NULL),
125     engineDB_((refCast<const engineTime>(this->db().time())))
129 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
131 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::checkTable()
133     if (!timeDataPtr_.valid())
134     {
135         timeDataPtr_.reset
136         (
137             new graph("title", "x", "y", IFstream(timeDataFileName_)())
138         );
139     }
141     if (engineDB_.theta() < min(timeDataPtr_().x()))
142     {
143         WarningIn
144         (
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"
150             << endl;
151     }
153     if (engineDB_.theta() < min(timeDataPtr_().x()))
154     {
155         WarningIn
156         (
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"
162             << endl;
163     }
169 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
171     if (updated())
172     {
173         return;
174     }
176     // a simpler way of doing this would be nice
177     checkTable();
179     scalar massFlowRate =
180     (
181         interpolateXY
182         (
183             engineDB_.theta(),
184             timeDataPtr_().x(),
185             timeDataPtr_().y()
186         )
187     );
190     scalar avgU = -massFlowRate/gSum(patch().magSf());
192     vectorField n = patch().nf();
194     const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>
195     (
196         phiName_
197     );
199     if (phi.dimensions() == dimVelocity*dimArea)
200     {
201         // volumetric flow-rate
202         operator==(n*avgU);
203     }
204     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
205     {
206         const fvPatchField<scalar>& rhop =
207             lookupPatchField<volScalarField, scalar>(rhoName_);
209         // mass flow-rate
210         operator==(n*avgU/rhop);
211     }
212     else
213     {
214         FatalErrorIn
215         (
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()
221             << exit(FatalError);
222     }
224     fixedValueFvPatchField<vector>::updateCoeffs();
228 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
230     fvPatchField<vector>::write(os);
232     if (phiName_ != "phi")
233     {
234         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
235     }
237     if (rhoName_ != "rho")
238     {
239         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
240     }
242     os.writeKeyword("timeDataFileName")
243         << timeDataFileName_ << token::END_STATEMENT << nl;
245     writeEntry("value", os);
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 namespace Foam
253    makePatchTypeField
254    (
255        fvPatchVectorField,
256        engineMassFlowRateInletVelocityFvPatchVectorField
257    );
261 // ************************************************************************* //