Skip to content
Permalink
Browse files

functionObjects::scalarTransport: simplified, standardized, rationalized

tutorials/incompressible/pisoFoam/les/pitzDaily: Added scalarTransport
functionObject to demonstrate the new functionality
  • Loading branch information...
Henry Weller
Henry Weller committed Jun 8, 2016
1 parent ada7953 commit d744705ee4424d8fa577f1573e8bb862ba5d095b
@@ -6,17 +6,14 @@
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/

type scalarTransport;
libs ("libutilityFunctionObjects.so");
scalarTransport
{
type scalarTransport;
libs ("libsolverFunctionObjects.so");

writeControl timeStep;
writeInterval 1;

write true;
log false;

resetOnStartUp false;
autoSchemes true;
fvOptions {};
field s;
schemesField s;
D 1e-09;
}

// ************************************************************************* //
@@ -6,12 +6,7 @@
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/

T
{
#includeEtc "caseDicts/postProcessing/scalarTransport/scalarTransport.cfg"

userDT true;
DT 1e-09;
}
type scalarTransport;
libs ("libsolverFunctionObjects.so");

// ************************************************************************* //
File renamed without changes.
@@ -20,6 +20,6 @@ writeInterval 1e-2;
// transportProperties settings
DT DT [ 0 2 -1 0 0 0 0 ] 1e-9;

#includeEtc "caseDicts/postProcessing/scalarTransport/scalarTransportDict.cfg"
#includeEtc "caseDicts/solvers/scalarTransport/scalarTransportDict.cfg"

// ************************************************************************* //
@@ -25,13 +25,8 @@ License

#include "scalarTransport.H"
#include "surfaceFields.H"
#include "dictionary.H"
#include "fixedValueFvPatchFields.H"
#include "zeroGradientFvPatchFields.H"
#include "fvScalarMatrix.H"
#include "fvmDdt.H"
#include "fvmDiv.H"
#include "fvcDiv.H"
#include "fvmLaplacian.H"
#include "fvmSup.H"
#include "turbulentTransportModel.H"
@@ -58,53 +53,32 @@ namespace functionObjects

// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //

Foam::wordList Foam::functionObjects::scalarTransport::boundaryTypes() const
{
const volVectorField& U = mesh_.lookupObject<volVectorField>(UName_);

wordList bTypes(U.boundaryField().size());

forAll(bTypes, patchi)
{
const fvPatchField<vector>& pf = U.boundaryField()[patchi];
if (isA<fixedValueFvPatchVectorField>(pf))
{
bTypes[patchi] = fixedValueFvPatchScalarField::typeName;
}
else
{
bTypes[patchi] = zeroGradientFvPatchScalarField::typeName;
}
}

return bTypes;
}


Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::DT
Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::D
(
const surfaceScalarField& phi
) const
{
typedef incompressible::turbulenceModel icoModel;
typedef compressible::turbulenceModel cmpModel;

if (userDT_)
word Dname("D" + s_.name());

if (constantD_)
{
return tmp<volScalarField>
(
new volScalarField
(
IOobject
(
"DT",
Dname,
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("DT", phi.dimensions()/dimLength, DT_)
dimensionedScalar(Dname, phi.dimensions()/dimLength, D_)
)
);
}
@@ -134,14 +108,14 @@ Foam::tmp<Foam::volScalarField> Foam::functionObjects::scalarTransport::DT
(
IOobject
(
"DT",
Dname,
mesh_.time().timeName(),
mesh_.time(),
IOobject::NO_READ,
IOobject::NO_WRITE
),
mesh_,
dimensionedScalar("DT", phi.dimensions()/dimLength, 0.0)
dimensionedScalar(Dname, phi.dimensions()/dimLength, 0.0)
)
);
}
@@ -158,30 +132,24 @@ Foam::functionObjects::scalarTransport::scalarTransport
)
:
fvMeshFunctionObject(name, runTime, dict),
DT_(0.0),
fieldName_(dict.lookupOrDefault<word>("field", "s")),
D_(0),
nCorr_(0),
fvOptions_(mesh_),
T_
s_
(
IOobject
(
name,
fieldName_,
mesh_.time().timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::MUST_READ,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("zero", dimless, 0.0),
boundaryTypes()
mesh_
)
{
read(dict);

if (resetOnStartUp_)
{
T_ == dimensionedScalar("zero", dimless, 0.0);
}
}


@@ -198,22 +166,21 @@ bool Foam::functionObjects::scalarTransport::read(const dictionary& dict)
fvMeshFunctionObject::read(dict);

phiName_ = dict.lookupOrDefault<word>("phi", "phi");
UName_ = dict.lookupOrDefault<word>("U", "U");
rhoName_ = dict.lookupOrDefault<word>("rho", "rho");
schemesField_ = dict.lookupOrDefault<word>("schemesField", fieldName_);

userDT_ = false;
if (dict.readIfPresent("DT", DT_))
constantD_ = false;
if (dict.readIfPresent("D", D_))
{
userDT_ = true;
constantD_ = true;
}

dict.lookup("resetOnStartUp") >> resetOnStartUp_;

dict.readIfPresent("nCorr", nCorr_);

dict.lookup("autoSchemes") >> autoSchemes_;

fvOptions_.reset(dict.subDict("fvOptions"));
if (dict.found("fvOptions"))
{
fvOptions_.reset(dict.subDict("fvOptions"));
}

return true;
}
@@ -226,69 +193,60 @@ bool Foam::functionObjects::scalarTransport::execute(const bool postProcess)
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);

// calculate the diffusivity
volScalarField DT(this->DT(phi));

// set schemes
word schemeVar = T_.name();
if (autoSchemes_)
{
schemeVar = UName_;
}
// Calculate the diffusivity
volScalarField D(this->D(phi));

word divScheme("div(phi," + schemeVar + ")");
word laplacianScheme("laplacian(" + DT.name() + "," + schemeVar + ")");
word divScheme("div(phi," + schemesField_ + ")");
word laplacianScheme("laplacian(" + D.name() + "," + schemesField_ + ")");

// set under-relaxation coeff
// Set under-relaxation coeff
scalar relaxCoeff = 0.0;
if (mesh_.relaxEquation(schemeVar))
if (mesh_.relaxEquation(schemesField_))
{
relaxCoeff = mesh_.equationRelaxationFactor(schemeVar);
relaxCoeff = mesh_.equationRelaxationFactor(schemesField_);
}

if (phi.dimensions() == dimMass/dimTime)
{
const volScalarField& rho =
mesh_.lookupObject<volScalarField>(rhoName_);

// solve
for (label i = 0; i <= nCorr_; i++)
{
fvScalarMatrix TEqn
fvScalarMatrix sEqn
(
fvm::ddt(rho, T_)
+ fvm::div(phi, T_, divScheme)
- fvm::laplacian(DT, T_, laplacianScheme)
fvm::ddt(rho, s_)
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(rho, T_)
fvOptions_(rho, s_)
);

TEqn.relax(relaxCoeff);
sEqn.relax(relaxCoeff);

fvOptions_.constrain(TEqn);
fvOptions_.constrain(sEqn);

TEqn.solve(mesh_.solverDict(schemeVar));
sEqn.solve(mesh_.solverDict(schemesField_));
}
}
else if (phi.dimensions() == dimVolume/dimTime)
{
// solve
for (label i = 0; i <= nCorr_; i++)
{
fvScalarMatrix TEqn
fvScalarMatrix sEqn
(
fvm::ddt(T_)
+ fvm::div(phi, T_, divScheme)
- fvm::laplacian(DT, T_, laplacianScheme)
fvm::ddt(s_)
+ fvm::div(phi, s_, divScheme)
- fvm::laplacian(D, s_, laplacianScheme)
==
fvOptions_(T_)
fvOptions_(s_)
);

TEqn.relax(relaxCoeff);
sEqn.relax(relaxCoeff);

fvOptions_.constrain(TEqn);
fvOptions_.constrain(sEqn);

TEqn.solve(mesh_.solverDict(schemeVar));
sEqn.solve(mesh_.solverDict(schemesField_));
}
}
else
@@ -28,16 +28,13 @@ Group
grpSolversFunctionObjects
Description
This function object evolves a passive scalar transport equation. The
field in ininitially zero, to which sources are added. The field name
is assigned the name of the function object. Boundary conditions are
automatically applied, based on the velocity boundary conditions.
This function object evolves a passive scalar transport equation.
- the field can be zeroed on start-up using the resetOnStartUp flag
- to employ the same numerical schemes as the flow velocity, use the
autoSchemes flag
- the diffusivity can be set manually using the DT entry, or retrieved
from the turbulence model (if applicable)
- To specify the field name set the 'field' entry
- To employ the same numerical schemes as another field set
the 'schemesField' entry,
- The diffusivity can be set manually using the 'D' entry, or retrieved
from the turbulence model (if applicable).
SeeAlso
Foam::functionObjects::fvMeshFunctionObject
@@ -52,7 +49,6 @@ SourceFiles

#include "fvMeshFunctionObject.H"
#include "volFields.H"
#include "surfaceFieldsFwd.H"
#include "fvOptionList.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@@ -72,44 +68,38 @@ class scalarTransport
{
// Private data

//- Name of field to process
word fieldName_;

//- Name of flux field (optional)
word phiName_;

//- Name of velocity field (optional)
word UName_;

//- Name of density field (optional)
word rhoName_;

//- Diffusion coefficient (optional)
scalar DT_;
scalar D_;

//- Flag to indicate whether user DT_ is used
bool userDT_;

//- Flag to reset scalar field on start-up
bool resetOnStartUp_;
//- Flag to indicate whether a constant, uniform D_ is specified
bool constantD_;

//- Number of corrector iterations (optional)
label nCorr_;

//- Flag to employ schemes for velocity for scalar transport
bool autoSchemes_;
//- Name of field whose schemes are used (optional)
word schemesField_;

//- Run-time selectable finite volume options, e.g. sources, constraints
fv::optionList fvOptions_;

//- The scalar field
volScalarField T_;
volScalarField s_;


// Private Member Functions

//- Return the boundary types for the scalar field
wordList boundaryTypes() const;

//- Return the diffusivity field
tmp<volScalarField> DT(const surfaceScalarField& phi) const;
tmp<volScalarField> D(const surfaceScalarField& phi) const;

//- Disallow default bitwise copy construct
scalarTransport(const scalarTransport&);

0 comments on commit d744705

Please sign in to comment.
You can’t perform that action at this time.