/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Copyright (C) 2012-2026 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 .
\*---------------------------------------------------------------------------*/
#include "scalarTransport.H"
#include "surfaceFields.H"
#include "fvmDdt.H"
#include "fviDdt.H"
#include "fvmDiv.H"
#include "fvmLaplacian.H"
#include "fvmSup.H"
#include "fvcFlux.H"
#include "fvModels.H"
#include "fvConstraints.H"
#include "incompressibleMomentumTransportModel.H"
#include "compressibleMomentumTransportModel.H"
#include "CMULES.H"
#include "EulerDdtScheme.H"
#include "localEulerDdtScheme.H"
#include "CrankNicolsonDdtScheme.H"
#include "localMax.H"
#include "zeroGradientFvPatchFields.H"
#include "subCycle.H"
#include "interfaceCompression.H"
#include "addToRunTimeSelectionTable.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
namespace functionObjects
{
defineTypeNameAndDebug(scalarTransport, 0);
addToRunTimeSelectionTable
(
functionObject,
scalarTransport,
dictionary
);
}
}
const Foam::NamedEnum
<
Foam::functionObjects::scalarTransport::diffusivityType,
4
> Foam::functionObjects::scalarTransport::diffusivityTypeNames_
{
"none",
"constant",
"field",
"viscosity"
};
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
Foam::tmp
Foam::functionObjects::scalarTransport::D() const
{
if (diffusivity_ == diffusivityType::field)
{
return mesh_.lookupObject(Dname_);
}
if (diffusivity_ == diffusivityType::viscosity)
{
const momentumTransportModel& turbulence =
mesh_.lookupType();
return volScalarField::New
(
"D" + fieldName_,
alphal_*turbulence.nu() + alphat_*turbulence.nut()
);
}
FatalErrorInFunction
<< "Diffusivity field requested for non-field diffusivity option '"
<< diffusivityTypeNames_[diffusivity_] << "'"
<< exit(FatalError);
return tmp();
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::functionObjects::scalarTransport::scalarTransport
(
const word& name,
const Time& runTime,
const dictionary& dict
)
:
fvMeshFunctionObject(name, runTime, dict),
fieldName_(dict.lookupOrDefault("field", "s")),
diffusivity_(diffusivityType::none),
D_("D", dimensions::kinematicViscosity, NaN),
Dname_(word::null),
alphal_("alphal", dimless, NaN),
alphat_("alphal", dimless, NaN),
s_
(
IOobject
(
fieldName_,
time_.name(),
mesh_,
IOobject::MUST_READ,
IOobject::NO_WRITE
),
mesh_
),
MULES_(false),
deltaN_
(
"deltaN",
s_.dimensions()/dimensions::length,
1e-8/pow(average(mesh_.V()), 1.0/3.0).value()
)
{
read(dict);
if (mesh_.solution().solversDict().found(fieldName_))
{
const dictionary& controls = mesh_.solution().solverDict(fieldName_);
if (controls.found("nSubCycles"))
{
MULES_ = true;
if (controls.lookupOrDefault("MULESCorr", false))
{
mesh_.schemes().setFluxRequired(fieldName_);
}
}
}
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::functionObjects::scalarTransport::~scalarTransport()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
{
fvMeshFunctionObject::read(dict);
phiName_ = dict.lookupOrDefault("phi", "phi");
rhoName_ = dict.lookupOrDefault("rho", "rho");
schemesField_ = dict.lookupOrDefault("schemesField", fieldName_);
solverField_ = dict.lookupOrDefault("solverField", fieldName_);
diffusivity_ = diffusivityTypeNames_.read(dict.lookup("diffusivity"));
switch(diffusivity_)
{
case diffusivityType::none:
break;
case diffusivityType::constant:
// This is used instead of D_.read(dict) in order to avoid
// successfully parsing a word as the name of the dimensioned type,
// and then mucking up the subsequent error message
D_.value() = dict.lookup(D_.name(), D_.dimensions());
break;
case diffusivityType::field:
Dname_ = dict.lookup("D");
break;
case diffusivityType::viscosity:
alphal_.read(dict);
alphat_.read(dict);
break;
}
return true;
}
Foam::wordList Foam::functionObjects::scalarTransport::fields() const
{
return wordList{phiName_};
}
bool Foam::functionObjects::scalarTransport::execute()
{
Info<< type() << " execute:" << endl;
const surfaceScalarField& phi =
mesh_.lookupObject(phiName_);
const word divScheme("div(phi,", schemesField_, ')');
const int nCorr =
mesh_.solution().solverDict(solverField_)
.lookupOrDefaultBackwardsCompatible