Commit 4f9e48bf authored by mattijs's avatar mattijs
Browse files

BUG: scalarTransport: have regIOobject member data

functionObjects only get detroyed when the runTime gets destroyed. So the
mesh is already destroyed and we cannot hold e.g. a volScalarField since
that will try to 'checkOut' from the objectRegistry(=mesh) upon destruction.
Note that we only see this in chtMultiRegionFoam.
parent 0431b8fb
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2015 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -70,6 +70,34 @@ Foam::wordList Foam::scalarTransport::boundaryTypes() const
}
Foam::volScalarField& Foam::scalarTransport::transportedField()
{
if (!mesh_.foundObject<volScalarField>(name()))
{
volScalarField* fldPtr = new volScalarField
(
IOobject
(
name(),
mesh_.time().timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("zero", dimless, 0.0),
boundaryTypes()
);
fldPtr->store();
}
return const_cast<volScalarField&>
(
mesh_.lookupObject<volScalarField>(name())
);
}
Foam::tmp<Foam::volScalarField> Foam::scalarTransport::DT
(
const surfaceScalarField& phi
......@@ -158,27 +186,13 @@ Foam::scalarTransport::scalarTransport
resetOnStartUp_(false),
nCorr_(0),
autoSchemes_(false),
fvOptions_(mesh_),
T_
(
IOobject
(
name,
mesh_.time().timeName(),
mesh_,
IOobject::READ_IF_PRESENT,
IOobject::AUTO_WRITE
),
mesh_,
dimensionedScalar("zero", dimless, 0.0),
boundaryTypes()
)
fvOptions_(mesh_)
{
read(dict);
if (resetOnStartUp_)
{
T_ == dimensionedScalar("zero", dimless, 0.0);
transportedField() == dimensionedScalar("zero", dimless, 0.0);
}
}
......@@ -227,11 +241,13 @@ void Foam::scalarTransport::execute()
const surfaceScalarField& phi =
mesh_.lookupObject<surfaceScalarField>(phiName_);
volScalarField& T = transportedField();
// calculate the diffusivity
volScalarField DT(this->DT(phi));
// set schemes
word schemeVar = T_.name();
word schemeVar = T.name();
if (autoSchemes_)
{
schemeVar = UName_;
......@@ -257,11 +273,11 @@ void Foam::scalarTransport::execute()
{
fvScalarMatrix TEqn
(
fvm::ddt(rho, T_)
+ fvm::div(phi, T_, divScheme)
- fvm::laplacian(DT, T_, laplacianScheme)
fvm::ddt(rho, T)
+ fvm::div(phi, T, divScheme)
- fvm::laplacian(DT, T, laplacianScheme)
==
fvOptions_(rho, T_)
fvOptions_(rho, T)
);
TEqn.relax(relaxCoeff);
......@@ -278,11 +294,11 @@ void Foam::scalarTransport::execute()
{
fvScalarMatrix TEqn
(
fvm::ddt(T_)
+ fvm::div(phi, T_, divScheme)
- fvm::laplacian(DT, T_, laplacianScheme)
fvm::ddt(T)
+ fvm::div(phi, T, divScheme)
- fvm::laplacian(DT, T, laplacianScheme)
==
fvOptions_(T_)
fvOptions_(T)
);
TEqn.relax(relaxCoeff);
......
......@@ -3,7 +3,7 @@
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2012-2013 OpenFOAM Foundation
\\/ M anipulation |
\\/ M anipulation | Copyright (C) 2015 OpenCFD Ltd.
-------------------------------------------------------------------------------
License
This file is part of OpenFOAM.
......@@ -108,15 +108,15 @@ class scalarTransport
//- Run-time selectable finite volume options, e.g. sources, constraints
fv::optionList fvOptions_;
//- The scalar field
volScalarField T_;
// Private Member Functions
//- Return the boundary types for the scalar field
wordList boundaryTypes() const;
//- Return reference to registered transported field
volScalarField& transportedField();
//- Return the diffusivity field
tmp<volScalarField> DT(const surfaceScalarField& phi) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment