initial commit for version 1.6.x patch release
[OpenFOAM-1.6.x.git] / src / finiteVolume / fields / fvPatchFields / derived / syringePressure / syringePressureFvPatchScalarField.C
blob6fd51f56324ac54af6c8ad822984ff338b64e007
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
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 "syringePressureFvPatchScalarField.H"
28 #include "volMesh.H"
29 #include "addToRunTimeSelectionTable.H"
30 #include "fvPatchFieldMapper.H"
31 #include "surfaceFields.H"
33 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
35 namespace Foam
38 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
40 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
42     const fvPatch& p,
43     const DimensionedField<scalar, volMesh>& iF
46     fixedValueFvPatchScalarField(p, iF),
47     curTimeIndex_(-1)
51 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
53     const syringePressureFvPatchScalarField& sppsf,
54     const fvPatch& p,
55     const DimensionedField<scalar, volMesh>& iF,
56     const fvPatchFieldMapper& mapper
59     fixedValueFvPatchScalarField(sppsf, p, iF, mapper),
60     Ap_(sppsf.Ap_),
61     Sp_(sppsf.Sp_),
62     VsI_(sppsf.VsI_),
63     tas_(sppsf.tas_),
64     tae_(sppsf.tae_),
65     tds_(sppsf.tds_),
66     tde_(sppsf.tde_),
67     psI_(sppsf.psI_),
68     psi_(sppsf.psi_),
69     ams_(sppsf.ams_),
70     ams0_(sppsf.ams0_),
71     curTimeIndex_(-1)
75 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
77     const fvPatch& p,
78     const DimensionedField<scalar, volMesh>& iF,
79     const dictionary& dict
82     fixedValueFvPatchScalarField(p, iF),
83     Ap_(readScalar(dict.lookup("Ap"))),
84     Sp_(readScalar(dict.lookup("Sp"))),
85     VsI_(readScalar(dict.lookup("VsI"))),
86     tas_(readScalar(dict.lookup("tas"))),
87     tae_(readScalar(dict.lookup("tae"))),
88     tds_(readScalar(dict.lookup("tds"))),
89     tde_(readScalar(dict.lookup("tde"))),
90     psI_(readScalar(dict.lookup("psI"))),
91     psi_(readScalar(dict.lookup("psi"))),
92     ams_(readScalar(dict.lookup("ams"))),
93     ams0_(ams_),
94     curTimeIndex_(-1)
96     scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(db().time().value());
97     fvPatchField<scalar>::operator=(ps);
101 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
103     const syringePressureFvPatchScalarField& sppsf,
104     const DimensionedField<scalar, volMesh>& iF
107     fixedValueFvPatchScalarField(sppsf, iF),
108     Ap_(sppsf.Ap_),
109     Sp_(sppsf.Sp_),
110     VsI_(sppsf.VsI_),
111     tas_(sppsf.tas_),
112     tae_(sppsf.tae_),
113     tds_(sppsf.tds_),
114     tde_(sppsf.tde_),
115     psI_(sppsf.psI_),
116     psi_(sppsf.psi_),
117     ams_(sppsf.ams_),
118     ams0_(sppsf.ams0_),
119     curTimeIndex_(-1)
123 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
125     const syringePressureFvPatchScalarField& sppsf
128     fixedValueFvPatchScalarField(sppsf),
129     Ap_(sppsf.Ap_),
130     Sp_(sppsf.Sp_),
131     VsI_(sppsf.VsI_),
132     tas_(sppsf.tas_),
133     tae_(sppsf.tae_),
134     tds_(sppsf.tds_),
135     tde_(sppsf.tde_),
136     psI_(sppsf.psI_),
137     psi_(sppsf.psi_),
138     ams_(sppsf.ams_),
139     ams0_(sppsf.ams0_),
140     curTimeIndex_(-1)
144 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
146 scalar syringePressureFvPatchScalarField::Vs(const scalar t) const
148     if (t < tas_)
149     {
150         return VsI_;
151     }
152     else if (t < tae_)
153     {
154         return 
155             VsI_
156           + 0.5*Ap_*Sp_*sqr(t - tas_)/(tae_ - tas_);
157     }
158     else if (t < tds_)
159     {
160         return 
161             VsI_ 
162           + 0.5*Ap_*Sp_*(tae_ - tas_)
163           + Ap_*Sp_*(t - tae_);
164     }
165     else if (t < tde_)
166     {
167         return 
168             VsI_ 
169           + 0.5*Ap_*Sp_*(tae_ - tas_) 
170           + Ap_*Sp_*(tds_ - tae_)
171           + Ap_*Sp_*(t - tds_)
172           - 0.5*Ap_*Sp_*sqr(t - tds_)/(tde_ - tds_);
173     }
174     else
175     {
176         return 
177             VsI_ 
178           + 0.5*Ap_*Sp_*(tae_ - tas_) 
179           + Ap_*Sp_*(tds_ - tae_)
180           + 0.5*Ap_*Sp_*(tde_ - tds_);
181     }
185 void syringePressureFvPatchScalarField::updateCoeffs()
187     if (updated())
188     {
189         return;
190     }
192     if (curTimeIndex_ != db().time().timeIndex())
193     {
194         ams0_ = ams_;
195         curTimeIndex_ = db().time().timeIndex();
196     }
198     scalar t = db().time().value();
199     scalar deltaT = db().time().deltaT().value();
201     const surfaceScalarField& phi =
202         db().lookupObject<surfaceScalarField>("phi");
204     const fvsPatchField<scalar>& phip =
205         patch().patchField<surfaceScalarField, scalar>(phi);
207     if (phi.dimensions() == dimVelocity*dimArea)
208     {
209         ams_ = ams0_ + deltaT*sum((*this*psi_)*phip);
210     }
211     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
212     {
213         ams_ = ams0_ + deltaT*sum(phip);
214     }
215     else
216     {
217         FatalErrorIn("syringePressureFvPatchScalarField::updateCoeffs()")
218             << "dimensions of phi are not correct"
219             << "\n    on patch " << this->patch().name()
220             << " of field " << this->dimensionedInternalField().name()
221             << " in file " << this->dimensionedInternalField().objectPath()
222             << exit(FatalError);
223     }
225     scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(t);
227     operator==(ps);
229     fixedValueFvPatchScalarField::updateCoeffs();
233 void syringePressureFvPatchScalarField::write(Ostream& os) const
235     fvPatchScalarField::write(os);
237     os.writeKeyword("Ap") << Ap_ << token::END_STATEMENT << nl;
238     os.writeKeyword("Sp") << Sp_ << token::END_STATEMENT << nl;
239     os.writeKeyword("VsI") << VsI_ << token::END_STATEMENT << nl;
240     os.writeKeyword("tas") << tas_ << token::END_STATEMENT << nl;
241     os.writeKeyword("tae") << tae_ << token::END_STATEMENT << nl;
242     os.writeKeyword("tds") << tds_ << token::END_STATEMENT << nl;
243     os.writeKeyword("tde") << tde_ << token::END_STATEMENT << nl;
244     os.writeKeyword("psI") << psI_ << token::END_STATEMENT << nl;
245     os.writeKeyword("psi") << psi_ << token::END_STATEMENT << nl;
246     os.writeKeyword("ams") << ams_ << token::END_STATEMENT << nl;
248     writeEntry("value", os);
252 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
254 makePatchTypeField
256     fvPatchScalarField,
257     syringePressureFvPatchScalarField
260 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
262 } // End namespace Foam
264 // ************************************************************************* //