Resolves bug-report http://www.openfoam.org/mantisbt/view.php?id=1938 Because C++ does not support overloading based on the return-type there is a problem defining both const and non-const member functions which are resolved based on the const-ness of the object for which they are called rather than the intent of the programmer declared via the const-ness of the returned type. The issue for the "boundaryField()" member function is that the non-const version increments the event-counter and checks the state of the stored old-time fields in case the returned value is altered whereas the const version has no side-effects and simply returns the reference. If the the non-const function is called within the patch-loop the event-counter may overflow. To resolve this it in necessary to avoid calling the non-const form of "boundaryField()" if the results is not altered and cache the reference outside the patch-loop when mutation of the patch fields is needed. The most straight forward way of resolving this problem is to name the const and non-const forms of the member functions differently e.g. the non-const form could be named: mutableBoundaryField() mutBoundaryField() nonConstBoundaryField() boundaryFieldRef() Given that in C++ a reference is non-const unless specified as const: "T&" vs "const T&" the logical convention would be boundaryFieldRef() boundaryFieldConstRef() and given that the const form which is more commonly used is it could simply be named "boundaryField()" then the logical convention is GeometricBoundaryField& boundaryFieldRef(); inline const GeometricBoundaryField& boundaryField() const; This is also consistent with the new "tmp" class for which non-const access to the stored object is obtained using the ".ref()" member function. This new convention for non-const access to the components of GeometricField will be applied to "dimensionedInternalField()" and "internalField()" in the future, i.e. "dimensionedInternalFieldRef()" and "internalFieldRef()".
265 lines
5.9 KiB
C
265 lines
5.9 KiB
C
/*---------------------------------------------------------------------------*\
|
|
========= |
|
|
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
|
\\ / O peration |
|
|
\\ / A nd | Copyright (C) 2013-2016 OpenFOAM Foundation
|
|
\\/ M anipulation |
|
|
-------------------------------------------------------------------------------
|
|
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 <http://www.gnu.org/licenses/>.
|
|
|
|
\*---------------------------------------------------------------------------*/
|
|
|
|
#include "phasePressureModel.H"
|
|
#include "twoPhaseSystem.H"
|
|
|
|
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
|
|
|
Foam::RASModels::phasePressureModel::phasePressureModel
|
|
(
|
|
const volScalarField& alpha,
|
|
const volScalarField& rho,
|
|
const volVectorField& U,
|
|
const surfaceScalarField& alphaRhoPhi,
|
|
const surfaceScalarField& phi,
|
|
const transportModel& phase,
|
|
const word& propertiesName,
|
|
const word& type
|
|
)
|
|
:
|
|
eddyViscosity
|
|
<
|
|
RASModel<EddyDiffusivity<ThermalDiffusivity
|
|
<
|
|
PhaseCompressibleTurbulenceModel<phaseModel>
|
|
>>>
|
|
>
|
|
(
|
|
type,
|
|
alpha,
|
|
rho,
|
|
U,
|
|
alphaRhoPhi,
|
|
phi,
|
|
phase,
|
|
propertiesName
|
|
),
|
|
|
|
phase_(phase),
|
|
|
|
alphaMax_(readScalar(coeffDict_.lookup("alphaMax"))),
|
|
preAlphaExp_(readScalar(coeffDict_.lookup("preAlphaExp"))),
|
|
expMax_(readScalar(coeffDict_.lookup("expMax"))),
|
|
g0_
|
|
(
|
|
"g0",
|
|
dimensionSet(1, -1, -2, 0, 0),
|
|
coeffDict_.lookup("g0")
|
|
)
|
|
{
|
|
nut_ == dimensionedScalar("zero", nut_.dimensions(), 0.0);
|
|
|
|
if (type == typeName)
|
|
{
|
|
printCoeffs(type);
|
|
}
|
|
}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
|
|
|
Foam::RASModels::phasePressureModel::~phasePressureModel()
|
|
{}
|
|
|
|
|
|
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
|
|
|
bool Foam::RASModels::phasePressureModel::read()
|
|
{
|
|
if
|
|
(
|
|
eddyViscosity
|
|
<
|
|
RASModel<EddyDiffusivity<ThermalDiffusivity
|
|
<
|
|
PhaseCompressibleTurbulenceModel<phaseModel>
|
|
>>>
|
|
>::read()
|
|
)
|
|
{
|
|
coeffDict().lookup("alphaMax") >> alphaMax_;
|
|
coeffDict().lookup("preAlphaExp") >> preAlphaExp_;
|
|
coeffDict().lookup("expMax") >> expMax_;
|
|
g0_.readIfPresent(coeffDict());
|
|
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::volScalarField>
|
|
Foam::RASModels::phasePressureModel::k() const
|
|
{
|
|
NotImplemented;
|
|
return nut_;
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::volScalarField>
|
|
Foam::RASModels::phasePressureModel::epsilon() const
|
|
{
|
|
NotImplemented;
|
|
return nut_;
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::volSymmTensorField>
|
|
Foam::RASModels::phasePressureModel::R() const
|
|
{
|
|
return tmp<volSymmTensorField>
|
|
(
|
|
new volSymmTensorField
|
|
(
|
|
IOobject
|
|
(
|
|
IOobject::groupName("R", U_.group()),
|
|
runTime_.timeName(),
|
|
mesh_,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE
|
|
),
|
|
mesh_,
|
|
dimensioned<symmTensor>
|
|
(
|
|
"R",
|
|
dimensionSet(0, 2, -2, 0, 0),
|
|
Zero
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::volScalarField>
|
|
Foam::RASModels::phasePressureModel::pPrime() const
|
|
{
|
|
tmp<volScalarField> tpPrime
|
|
(
|
|
g0_
|
|
*min
|
|
(
|
|
exp(preAlphaExp_*(alpha_ - alphaMax_)),
|
|
expMax_
|
|
)
|
|
);
|
|
|
|
volScalarField::GeometricBoundaryField& bpPrime =
|
|
tpPrime.ref().boundaryFieldRef();
|
|
|
|
forAll(bpPrime, patchi)
|
|
{
|
|
if (!bpPrime[patchi].coupled())
|
|
{
|
|
bpPrime[patchi] == 0;
|
|
}
|
|
}
|
|
|
|
return tpPrime;
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::surfaceScalarField>
|
|
Foam::RASModels::phasePressureModel::pPrimef() const
|
|
{
|
|
tmp<surfaceScalarField> tpPrime
|
|
(
|
|
g0_
|
|
*min
|
|
(
|
|
exp(preAlphaExp_*(fvc::interpolate(alpha_) - alphaMax_)),
|
|
expMax_
|
|
)
|
|
);
|
|
|
|
surfaceScalarField::GeometricBoundaryField& bpPrime =
|
|
tpPrime.ref().boundaryFieldRef();
|
|
|
|
forAll(bpPrime, patchi)
|
|
{
|
|
if (!bpPrime[patchi].coupled())
|
|
{
|
|
bpPrime[patchi] == 0;
|
|
}
|
|
}
|
|
|
|
return tpPrime;
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::volSymmTensorField>
|
|
Foam::RASModels::phasePressureModel::devRhoReff() const
|
|
{
|
|
return tmp<volSymmTensorField>
|
|
(
|
|
new volSymmTensorField
|
|
(
|
|
IOobject
|
|
(
|
|
IOobject::groupName("devRhoReff", U_.group()),
|
|
runTime_.timeName(),
|
|
mesh_,
|
|
IOobject::NO_READ,
|
|
IOobject::NO_WRITE
|
|
),
|
|
mesh_,
|
|
dimensioned<symmTensor>
|
|
(
|
|
"R",
|
|
rho_.dimensions()*dimensionSet(0, 2, -2, 0, 0),
|
|
Zero
|
|
)
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
Foam::tmp<Foam::fvVectorMatrix>
|
|
Foam::RASModels::phasePressureModel::divDevRhoReff
|
|
(
|
|
volVectorField& U
|
|
) const
|
|
{
|
|
return tmp<fvVectorMatrix>
|
|
(
|
|
new fvVectorMatrix
|
|
(
|
|
U,
|
|
rho_.dimensions()*dimensionSet(0, 4, -2, 0, 0)
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
void Foam::RASModels::phasePressureModel::correct()
|
|
{}
|
|
|
|
|
|
// ************************************************************************* //
|