From 4f9e48bfc5e2d2fe6bf89220be97105dbba46d21 Mon Sep 17 00:00:00 2001 From: mattijs Date: Mon, 9 Nov 2015 15:42:16 +0000 Subject: [PATCH] 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. --- .../scalarTransport/scalarTransport.C | 68 ++++++++++++------- .../scalarTransport/scalarTransport.H | 8 +-- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C index 97dde67611..d38cc9d14d 100644 --- a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C +++ b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.C @@ -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(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 + ( + mesh_.lookupObject(name()) + ); +} + + Foam::tmp 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(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); diff --git a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H index 3006ca197d..c2ffbcec2c 100644 --- a/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H +++ b/src/postProcessing/functionObjects/utilities/scalarTransport/scalarTransport.H @@ -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 DT(const surfaceScalarField& phi) const;