Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / finiteVolume / fields / fvPatchFields / derived / syringePressure / syringePressureFvPatchScalarField.C
blobcfa0b80e5f379f12741ec81d9680f9f2b2684fb5
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 "fvPatchFields.H"
27 #include "syringePressureFvPatchScalarField.H"
28 #include "addToRunTimeSelectionTable.H"
30 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
32 namespace Foam
35 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
37 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
39     const fvPatch& p,
40     const DimensionedField<scalar, volMesh>& iF
43     fixedValueFvPatchScalarField(p, iF),
44     curTimeIndex_(-1)
48 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
50     const syringePressureFvPatchScalarField& sppsf,
51     const fvPatch& p,
52     const DimensionedField<scalar, volMesh>& iF,
53     const fvPatchFieldMapper& mapper
56     fixedValueFvPatchScalarField(sppsf, p, iF, mapper),
57     Ap_(sppsf.Ap_),
58     Sp_(sppsf.Sp_),
59     VsI_(sppsf.VsI_),
60     tas_(sppsf.tas_),
61     tae_(sppsf.tae_),
62     tds_(sppsf.tds_),
63     tde_(sppsf.tde_),
64     psI_(sppsf.psI_),
65     psi_(sppsf.psi_),
66     ams_(sppsf.ams_),
67     ams0_(sppsf.ams0_),
68     curTimeIndex_(-1)
72 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
74     const fvPatch& p,
75     const DimensionedField<scalar, volMesh>& iF,
76     const dictionary& dict
79     fixedValueFvPatchScalarField(p, iF),
80     Ap_(readScalar(dict.lookup("Ap"))),
81     Sp_(readScalar(dict.lookup("Sp"))),
82     VsI_(readScalar(dict.lookup("VsI"))),
83     tas_(readScalar(dict.lookup("tas"))),
84     tae_(readScalar(dict.lookup("tae"))),
85     tds_(readScalar(dict.lookup("tds"))),
86     tde_(readScalar(dict.lookup("tde"))),
87     psI_(readScalar(dict.lookup("psI"))),
88     psi_(readScalar(dict.lookup("psi"))),
89     ams_(readScalar(dict.lookup("ams"))),
90     ams0_(ams_),
91     curTimeIndex_(-1)
93     scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(db().time().value());
94     fvPatchField<scalar>::operator=(ps);
98 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
100     const syringePressureFvPatchScalarField& sppsf,
101     const DimensionedField<scalar, volMesh>& iF
104     fixedValueFvPatchScalarField(sppsf, iF),
105     Ap_(sppsf.Ap_),
106     Sp_(sppsf.Sp_),
107     VsI_(sppsf.VsI_),
108     tas_(sppsf.tas_),
109     tae_(sppsf.tae_),
110     tds_(sppsf.tds_),
111     tde_(sppsf.tde_),
112     psI_(sppsf.psI_),
113     psi_(sppsf.psi_),
114     ams_(sppsf.ams_),
115     ams0_(sppsf.ams0_),
116     curTimeIndex_(-1)
120 syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
122     const syringePressureFvPatchScalarField& sppsf
125     fixedValueFvPatchScalarField(sppsf),
126     Ap_(sppsf.Ap_),
127     Sp_(sppsf.Sp_),
128     VsI_(sppsf.VsI_),
129     tas_(sppsf.tas_),
130     tae_(sppsf.tae_),
131     tds_(sppsf.tds_),
132     tde_(sppsf.tde_),
133     psI_(sppsf.psI_),
134     psi_(sppsf.psi_),
135     ams_(sppsf.ams_),
136     ams0_(sppsf.ams0_),
137     curTimeIndex_(-1)
141 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
143 scalar syringePressureFvPatchScalarField::Vs(const scalar t) const
145     if (t < tas_)
146     {
147         return VsI_;
148     }
149     else if (t < tae_)
150     {
151         return
152             VsI_
153           + 0.5*Ap_*Sp_*sqr(t - tas_)/(tae_ - tas_);
154     }
155     else if (t < tds_)
156     {
157         return
158             VsI_
159           + 0.5*Ap_*Sp_*(tae_ - tas_)
160           + Ap_*Sp_*(t - tae_);
161     }
162     else if (t < tde_)
163     {
164         return
165             VsI_
166           + 0.5*Ap_*Sp_*(tae_ - tas_)
167           + Ap_*Sp_*(tds_ - tae_)
168           + Ap_*Sp_*(t - tds_)
169           - 0.5*Ap_*Sp_*sqr(t - tds_)/(tde_ - tds_);
170     }
171     else
172     {
173         return
174             VsI_
175           + 0.5*Ap_*Sp_*(tae_ - tas_)
176           + Ap_*Sp_*(tds_ - tae_)
177           + 0.5*Ap_*Sp_*(tde_ - tds_);
178     }
182 void syringePressureFvPatchScalarField::updateCoeffs()
184     if (updated())
185     {
186         return;
187     }
189     if (curTimeIndex_ != db().time().timeIndex())
190     {
191         ams0_ = ams_;
192         curTimeIndex_ = db().time().timeIndex();
193     }
195     scalar t = db().time().value();
196     scalar deltaT = db().time().deltaT().value();
198     const surfaceScalarField& phi =
199         db().lookupObject<surfaceScalarField>("phi");
201     const fvsPatchField<scalar>& phip =
202         patch().patchField<surfaceScalarField, scalar>(phi);
204     if (phi.dimensions() == dimVelocity*dimArea)
205     {
206         ams_ = ams0_ + deltaT*sum((*this*psi_)*phip);
207     }
208     else if (phi.dimensions() == dimDensity*dimVelocity*dimArea)
209     {
210         ams_ = ams0_ + deltaT*sum(phip);
211     }
212     else
213     {
214         FatalErrorIn("syringePressureFvPatchScalarField::updateCoeffs()")
215             << "dimensions of phi are not correct"
216             << "\n    on patch " << this->patch().name()
217             << " of field " << this->dimensionedInternalField().name()
218             << " in file " << this->dimensionedInternalField().objectPath()
219             << exit(FatalError);
220     }
222     scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(t);
224     operator==(ps);
226     fixedValueFvPatchScalarField::updateCoeffs();
230 void syringePressureFvPatchScalarField::write(Ostream& os) const
232     fvPatchScalarField::write(os);
234     os.writeKeyword("Ap") << Ap_ << token::END_STATEMENT << nl;
235     os.writeKeyword("Sp") << Sp_ << token::END_STATEMENT << nl;
236     os.writeKeyword("VsI") << VsI_ << token::END_STATEMENT << nl;
237     os.writeKeyword("tas") << tas_ << token::END_STATEMENT << nl;
238     os.writeKeyword("tae") << tae_ << token::END_STATEMENT << nl;
239     os.writeKeyword("tds") << tds_ << token::END_STATEMENT << nl;
240     os.writeKeyword("tde") << tde_ << token::END_STATEMENT << nl;
241     os.writeKeyword("psI") << psI_ << token::END_STATEMENT << nl;
242     os.writeKeyword("psi") << psi_ << token::END_STATEMENT << nl;
243     os.writeKeyword("ams") << ams_ << token::END_STATEMENT << nl;
245     writeEntry("value", os);
249 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
251 makePatchTypeField
253     fvPatchScalarField,
254     syringePressureFvPatchScalarField
257 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259 } // End namespace Foam
261 // ************************************************************************* //