/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | www.openfoam.com
\\/ M anipulation |
-------------------------------------------------------------------------------
Copyright (C) 2011-2016 OpenFOAM Foundation
Copyright (C) 2020 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
OpenFOAM is free software: you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with OpenFOAM. If not, see .
\*---------------------------------------------------------------------------*/
#include "syringePressureFvPatchScalarField.H"
#include "volMesh.H"
#include "addToRunTimeSelectionTable.H"
#include "fvPatchFieldMapper.H"
#include "surfaceFields.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField& iF
)
:
fixedValueFvPatchScalarField(p, iF),
phiName_("phi"),
curTimeIndex_(-1)
{}
Foam::syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
(
const fvPatch& p,
const DimensionedField& iF,
const dictionary& dict
)
:
fixedValueFvPatchScalarField(p, iF, dict, IOobjectOption::NO_READ),
Ap_(dict.get("Ap")),
Sp_(dict.get("Sp")),
VsI_(dict.get("VsI")),
tas_(dict.get("tas")),
tae_(dict.get("tae")),
tds_(dict.get("tds")),
tde_(dict.get("tde")),
psI_(dict.get("psI")),
psi_(dict.get("psi")),
ams_(dict.get("ams")),
ams0_(ams_),
phiName_(dict.getOrDefault("phi", "phi")),
curTimeIndex_(-1)
{
scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(db().time().value());
fvPatchField::operator=(ps);
}
Foam::syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
(
const syringePressureFvPatchScalarField& sppsf,
const fvPatch& p,
const DimensionedField& iF,
const fvPatchFieldMapper& mapper
)
:
fixedValueFvPatchScalarField(sppsf, p, iF, mapper),
Ap_(sppsf.Ap_),
Sp_(sppsf.Sp_),
VsI_(sppsf.VsI_),
tas_(sppsf.tas_),
tae_(sppsf.tae_),
tds_(sppsf.tds_),
tde_(sppsf.tde_),
psI_(sppsf.psI_),
psi_(sppsf.psi_),
ams_(sppsf.ams_),
ams0_(sppsf.ams0_),
phiName_(sppsf.phiName_),
curTimeIndex_(-1)
{}
Foam::syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
(
const syringePressureFvPatchScalarField& sppsf,
const DimensionedField& iF
)
:
fixedValueFvPatchScalarField(sppsf, iF),
Ap_(sppsf.Ap_),
Sp_(sppsf.Sp_),
VsI_(sppsf.VsI_),
tas_(sppsf.tas_),
tae_(sppsf.tae_),
tds_(sppsf.tds_),
tde_(sppsf.tde_),
psI_(sppsf.psI_),
psi_(sppsf.psi_),
ams_(sppsf.ams_),
ams0_(sppsf.ams0_),
phiName_(sppsf.phiName_),
curTimeIndex_(-1)
{}
Foam::syringePressureFvPatchScalarField::syringePressureFvPatchScalarField
(
const syringePressureFvPatchScalarField& sppsf
)
:
fixedValueFvPatchScalarField(sppsf),
Ap_(sppsf.Ap_),
Sp_(sppsf.Sp_),
VsI_(sppsf.VsI_),
tas_(sppsf.tas_),
tae_(sppsf.tae_),
tds_(sppsf.tds_),
tde_(sppsf.tde_),
psI_(sppsf.psI_),
psi_(sppsf.psi_),
ams_(sppsf.ams_),
ams0_(sppsf.ams0_),
phiName_(sppsf.phiName_),
curTimeIndex_(-1)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
Foam::scalar Foam::syringePressureFvPatchScalarField::Vs(const scalar t) const
{
if (t < tas_)
{
return VsI_;
}
else if (t < tae_)
{
return
VsI_
+ 0.5*Ap_*Sp_*sqr(t - tas_)/(tae_ - tas_);
}
else if (t < tds_)
{
return
VsI_
+ 0.5*Ap_*Sp_*(tae_ - tas_)
+ Ap_*Sp_*(t - tae_);
}
else if (t < tde_)
{
return
VsI_
+ 0.5*Ap_*Sp_*(tae_ - tas_)
+ Ap_*Sp_*(tds_ - tae_)
+ Ap_*Sp_*(t - tds_)
- 0.5*Ap_*Sp_*sqr(t - tds_)/(tde_ - tds_);
}
else
{
return
VsI_
+ 0.5*Ap_*Sp_*(tae_ - tas_)
+ Ap_*Sp_*(tds_ - tae_)
+ 0.5*Ap_*Sp_*(tde_ - tds_);
}
}
void Foam::syringePressureFvPatchScalarField::updateCoeffs()
{
if (updated())
{
return;
}
if (curTimeIndex_ != db().time().timeIndex())
{
ams0_ = ams_;
curTimeIndex_ = db().time().timeIndex();
}
scalar t = db().time().value();
scalar deltaT = db().time().deltaTValue();
const auto& phip = patch().lookupPatchField(phiName_);
if (phip.internalField().dimensions() == dimVolume/dimTime)
{
ams_ = ams0_ + deltaT*sum((*this*psi_)*phip);
}
else if (phip.internalField().dimensions() == dimMass/dimTime)
{
ams_ = ams0_ + deltaT*sum(phip);
}
else
{
FatalErrorInFunction
<< "dimensions of phi are not correct"
<< "\n on patch " << this->patch().name()
<< " of field " << this->internalField().name()
<< " in file " << this->internalField().objectPath()
<< exit(FatalError);
}
scalar ps = (psI_*VsI_ + ams_/psi_)/Vs(t);
operator==(ps);
fixedValueFvPatchScalarField::updateCoeffs();
}
void Foam::syringePressureFvPatchScalarField::write(Ostream& os) const
{
fvPatchField::write(os);
os.writeEntry("Ap", Ap_);
os.writeEntry("Sp", Sp_);
os.writeEntry("VsI", VsI_);
os.writeEntry("tas", tas_);
os.writeEntry("tae", tae_);
os.writeEntry("tds", tds_);
os.writeEntry("tde", tde_);
os.writeEntry("psI", psI_);
os.writeEntry("psi", psi_);
os.writeEntry("ams", ams_);
os.writeEntryIfDifferent("phi", "phi", phiName_);
fvPatchField::writeValueEntry(os);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
makePatchTypeField
(
fvPatchScalarField,
syringePressureFvPatchScalarField
);
}
// ************************************************************************* //