Files
OpenFOAM-12/src/functionObjects/solvers/scalarTransport/scalarTransport.C
Will Bainbridge 1bbac95448 objectRegistry: Improvements to caching of temporary objects
Cached temporary objects are now registered from the moment of
construction. This means it is possible to use them before they go out
of scope. Non-cached temporaries are not registered, as before.

The check for the existence of requested cached objects is now done
after function object evaluation. This means that caching can be done on
fields generated by the function objects themselves without generating
warning messages.

The above, however, means that if an object isn't successfully cached
and it's lookup in a function fails, then the warning will not be
generated before the lookup raises an error. This could make diagnosing
the reason for such a failure more difficult. To remedy this the content
of the warning (i.e., the list of objects that are available for
caching) has been added to the lookup error message if the looked up
name is on the caching list. The same level of logged information is
therefore retained in the event of caching and lookup failures.
2019-09-30 16:32:39 +01:00

251 lines
6.4 KiB
C

/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2019 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 "scalarTransport.H"
#include "surfaceFields.H"
#include "fvmDdt.H"
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "fvmSup.H"
#include "turbulentTransportModel.H"
#include "turbulentFluidThermoModel.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(scalarTransport, 0);
addToRunTimeSelectionTable
(
functionObject,
scalarTransport,
dictionary
);
}
}
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
(
const surfaceScalarField& phi
) const
{
typedef incompressible::turbulenceModel icoModel;
typedef compressible::turbulenceModel cmpModel;
word Dname("D" + s_.name());
if (constantD_)
{
return volScalarField::New
(
Dname,
mesh_,
dimensionedScalar(Dname, phi.dimensions()/dimLength, D_)
);
}
else if (mesh_.foundObject<icoModel>(turbulenceModel::propertiesName))
{
const icoModel& model = mesh_.lookupObject<icoModel>
(
turbulenceModel::propertiesName
);
return alphaD_*model.nu() + alphaDt_*model.nut();
}
else if (mesh_.foundObject<cmpModel>(turbulenceModel::propertiesName))
{
const cmpModel& model = mesh_.lookupObject<cmpModel>
(
turbulenceModel::propertiesName
);
return alphaD_*model.mu() + alphaDt_*model.mut();
}
else
{
return volScalarField::New
(
Dname,
mesh_,
dimensionedScalar(Dname, phi.dimensions()/dimLength, 0)
);
}
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::scalarTransport::scalarTransport
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldName_(dict.lookupOrDefault<word>("field", "s")),
D_(0),
nCorr_(0),
fvOptions_(mesh_),
s_
(
IOobject
(
fieldName_,
mesh_.time().timeName(),
mesh_,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh_
)
{
read(dict);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::scalarTransport::~scalarTransport()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
phiName_ = dict.lookupOrDefault<word>("phi", "phi");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
schemesField_ = dict.lookupOrDefault<word>("schemesField", fieldName_);
constantD_ = dict.readIfPresent("D", D_);
alphaD_ = dict.lookupOrDefault("alphaD", 1.0);
alphaDt_ = dict.lookupOrDefault("alphaDt", 1.0);
dict.readIfPresent("nCorr", nCorr_);
if (dict.found("fvOptions"))
{
fvOptions_.reset(dict.subDict("fvOptions"));
}
return true;
}
bool Foam::functionObjects::scalarTransport::execute()
{
Info<< type() << " write:" << endl;
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);
// Calculate the diffusivity
volScalarField D("D" + s_.name(), this->D(phi));
word divScheme("div(phi," + schemesField_ + ")");
word laplacianScheme("laplacian(" + D.name() + "," + schemesField_ + ")");
// Set under-relaxation coeff
scalar relaxCoeff = 0.0;
if (mesh_.relaxEquation(schemesField_))
{
relaxCoeff = mesh_.equationRelaxationFactor(schemesField_);
}
if (phi.dimensions() == dimMass/dimTime)
{
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);
for (int i=0; i<=nCorr_; i++)
{
fvScalarMatrix sEqn
(
fvm::ddt(rho, s_)
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(rho, s_)
);
sEqn.relax(relaxCoeff);
fvOptions_.constrain(sEqn);
sEqn.solve(schemesField_);
}
}
else if (phi.dimensions() == dimVolume/dimTime)
{
for (int i=0; i<=nCorr_; i++)
{
fvScalarMatrix sEqn
(
fvm::ddt(s_)
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(s_)
);
sEqn.relax(relaxCoeff);
fvOptions_.constrain(sEqn);
sEqn.solve(schemesField_);
}
}
else
{
FatalErrorInFunction
<< "Incompatible dimensions for phi: " << phi.dimensions() << nl
<< "Dimensions should be " << dimMass/dimTime << " or "
<< dimVolume/dimTime << exit(FatalError);
}
Info<< endl;
return true;
}
bool Foam::functionObjects::scalarTransport::write()
{
return true;
}
// ************************************************************************* //