fix consistancy of gradient on coupled patches
[OpenFOAM-1.6-ext.git] / src / engine / derivedFvPatchFields / engineMassFlowRateInletVelocity / engineMassFlowRateInletVelocityFvPatchVectorField.C
blobba86c31b1f7bd915cd0bf098abd6603438d7dcde
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
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
19     for more details.
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"
32 #include "graph.H"
33 #include "interpolateXY.H"
34 #include "IFstream.H"
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 Foam::
39 engineMassFlowRateInletVelocityFvPatchVectorField::
40 engineMassFlowRateInletVelocityFvPatchVectorField
42     const fvPatch& p,
43     const DimensionedField<vector, volMesh>& iF
46     fixedValueFvPatchField<vector>(p, iF),
47     phiName_("phi"),
48     rhoName_("rho"),
49     timeDataPtr_(NULL),
50     engineDB_((refCast<const engineTime>(this->db().time())))
53 Foam::
54 engineMassFlowRateInletVelocityFvPatchVectorField::
55 engineMassFlowRateInletVelocityFvPatchVectorField
57     const engineMassFlowRateInletVelocityFvPatchVectorField& ptf,
58     const fvPatch& p,
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_),
67     timeDataPtr_(NULL),
68     engineDB_((refCast<const engineTime>(this->db().time())))
71 Foam::
72 engineMassFlowRateInletVelocityFvPatchVectorField::
73 engineMassFlowRateInletVelocityFvPatchVectorField
75     const fvPatch& p,
76     const DimensionedField<vector, volMesh>& iF,
77     const dictionary& dict
80     fixedValueFvPatchField<vector>(p, iF, dict),
81     phiName_("phi"),
82     rhoName_("rho"),
83     timeDataFileName_(fileName(dict.lookup("timeDataFileName")).expand()),
84     timeDataPtr_(NULL),
85     engineDB_((refCast<const engineTime>(this->db().time())))
87     if (dict.found("phi"))
88     {
89         dict.lookup("phi") >> phiName_;
90     }
92     if (dict.found("rho"))
93     {
94         dict.lookup("rho") >> rhoName_;
95     }
98 Foam::
99 engineMassFlowRateInletVelocityFvPatchVectorField::
100 engineMassFlowRateInletVelocityFvPatchVectorField
102     const engineMassFlowRateInletVelocityFvPatchVectorField& ptf
105     fixedValueFvPatchField<vector>(ptf),
106     phiName_(ptf.phiName_),
107     rhoName_(ptf.rhoName_),
108     timeDataFileName_(ptf.timeDataFileName_),
109     timeDataPtr_(NULL),
110     engineDB_((refCast<const engineTime>(this->db().time())))
113 Foam::
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_),
125     timeDataPtr_(NULL),
126     engineDB_((refCast<const engineTime>(this->db().time())))
130 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
132 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::checkTable()
134     if (!timeDataPtr_.valid())
135     {
136         timeDataPtr_.reset
137         (
138             new graph("title", "x", "y", IFstream(timeDataFileName_)())
139         );
140     }
142     if (engineDB_.theta() < min(timeDataPtr_().x()))
143     {
144         WarningIn
145         (
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"
151             << endl;
152     }
154     if (engineDB_.theta() < min(timeDataPtr_().x()))
155     {
156         WarningIn
157         (
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"
163             << endl;
164     }
170 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::updateCoeffs()
172     if (updated())
173     {
174         return;
175     }
177     // a simpler way of doing this would be nice
178     checkTable();
179     
180     scalar massFlowRate = 
181     (
182         interpolateXY
183         (
184             engineDB_.theta(),
185             timeDataPtr_().x(),
186             timeDataPtr_().y()
187         )
188     );
191     scalar avgU = -massFlowRate/gSum(patch().magSf());
193     vectorField n = patch().nf();
195     const surfaceScalarField& phi = db().lookupObject<surfaceScalarField>
196     (
197         phiName_
198     );
200     if (phi.dimensions() == dimVelocity*dimArea)
201     {
202         // volumetric flow-rate
203         operator==(n*avgU);
204     }
205     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
206     {
207         const fvPatchField<scalar>& rhop =
208             patch().lookupPatchField<volScalarField, scalar>(rhoName_);
210         // mass flow-rate
211         operator==(n*avgU/rhop);
212     }
213     else
214     {
215         FatalErrorIn
216         (
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()
222             << exit(FatalError);
223     }
225     fixedValueFvPatchField<vector>::updateCoeffs();
229 void Foam::engineMassFlowRateInletVelocityFvPatchVectorField::write(Ostream& os) const
231     fvPatchField<vector>::write(os);
233     if (phiName_ != "phi")
234     {
235         os.writeKeyword("phi") << phiName_ << token::END_STATEMENT << nl;
236     }
238     if (rhoName_ != "rho")
239     {
240         os.writeKeyword("rho") << rhoName_ << token::END_STATEMENT << nl;
241     }
243     os.writeKeyword("timeDataFileName")
244         << timeDataFileName_ << token::END_STATEMENT << nl;
246     writeEntry("value", os);
250 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
252 namespace Foam
254    makePatchTypeField
255    (
256        fvPatchVectorField,
257        engineMassFlowRateInletVelocityFvPatchVectorField
258    );
262 // ************************************************************************* //