diff --git a/applications/solvers/multiphase/icoReactingMultiPhaseInterFoam/createFields.H b/applications/solvers/multiphase/icoReactingMultiPhaseInterFoam/createFields.H index 9e58b66b45..e1bfdebea3 100644 --- a/applications/solvers/multiphase/icoReactingMultiPhaseInterFoam/createFields.H +++ b/applications/solvers/multiphase/icoReactingMultiPhaseInterFoam/createFields.H @@ -26,6 +26,22 @@ mesh ); + // Note: construct T to be around before the thermos. The thermos will + // not update T. + Info<< "Reading field T\n" << endl; + volScalarField T + ( + IOobject + ( + "T", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + Info<< "Calculating field g.h\n" << endl; #include "readGravitationalAcceleration.H" @@ -45,6 +61,7 @@ p_rgh ); + Info<< "Creating multiphaseSystem\n" << endl; autoPtr fluidPtr = multiphaseSystem::New(mesh); @@ -57,8 +74,6 @@ } - volScalarField& T = fluid.T(); - // Need to store rho for ddt(rho, U) volScalarField rho ( diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.C b/src/thermophysicalModels/basic/basicThermo/basicThermo.C index 25371182d6..f2ed8410c9 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.C +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.C @@ -126,10 +126,16 @@ Foam::wordList Foam::basicThermo::heBoundaryTypes() Foam::volScalarField& Foam::basicThermo::lookupOrConstruct ( const fvMesh& mesh, - const word& name -) const + const word& name, + bool& isOwner +) { - if (!mesh.objectRegistry::foundObject(name)) + const volScalarField* p = + mesh.objectRegistry::lookupObjectPtr(name); + + isOwner = !p; + + if (!p) { volScalarField* fPtr ( @@ -149,12 +155,12 @@ Foam::volScalarField& Foam::basicThermo::lookupOrConstruct // Transfer ownership of this object to the objectRegistry fPtr->store(fPtr); + return *fPtr; + } + else + { + return const_cast(*p); } - - return const_cast - ( - mesh.objectRegistry::lookupObject(name) - ); } @@ -172,12 +178,28 @@ Foam::basicThermo::basicThermo const fvMesh& mesh, const word& phaseName ) +: + basicThermo + ( + mesh, + phaseName, + phasePropertyName(dictName, phaseName) + ) +{} + + +Foam::basicThermo::basicThermo +( + const fvMesh& mesh, + const word& phaseName, + const word& dictionaryName +) : IOdictionary ( IOobject ( - phasePropertyName(dictName, phaseName), + dictionaryName, mesh.time().constant(), mesh, IOobject::MUST_READ_IF_MODIFIED, @@ -187,9 +209,10 @@ Foam::basicThermo::basicThermo phaseName_(phaseName), - p_(lookupOrConstruct(mesh, "p")), + p_(lookupOrConstruct(mesh, "p", pOwner_)), - T_(lookupOrConstruct(mesh, phasePropertyName("T"))), + T_(lookupOrConstruct(mesh, phasePropertyName("T"), TOwner_)), + TOwner_(lookupOrDefault("updateT", TOwner_)), alpha_ ( @@ -210,10 +233,17 @@ Foam::basicThermo::basicThermo ) ), - dpdt_(lookupOrDefault("dpdt", true)), - - tempBased_(lookupOrDefault("tempBased", false)) -{} + dpdt_(lookupOrDefault("dpdt", true)) +{ + if (debug) + { + Pout<< "Constructed thermo : mesh:" << mesh.name() + << " phase:" << phaseName + << " dictionary:" << dictionaryName + << " alphaName:" << alpha_.name() + << " updateT:" << TOwner_ << endl; + } +} Foam::basicThermo::basicThermo @@ -238,9 +268,10 @@ Foam::basicThermo::basicThermo phaseName_(phaseName), - p_(lookupOrConstruct(mesh, "p")), + p_(lookupOrConstruct(mesh, "p", pOwner_)), - T_(lookupOrConstruct(mesh, phasePropertyName("T"))), + T_(lookupOrConstruct(mesh, phasePropertyName("T"), TOwner_)), + TOwner_(lookupOrDefault("updateT", TOwner_)), alpha_ ( @@ -259,58 +290,7 @@ Foam::basicThermo::basicThermo dimensionSet(1, -1, -1, 0, 0), Zero ) - ), - - tempBased_(lookupOrDefault("tempBased", false)) -{} - -Foam::basicThermo::basicThermo -( - const fvMesh& mesh, - const word& phaseName, - const word& dictionaryName -) -: - IOdictionary - ( - IOobject - ( - dictionaryName, - mesh.time().constant(), - mesh, - IOobject::MUST_READ_IF_MODIFIED, - IOobject::NO_WRITE - ) - ), - - phaseName_(phaseName), - - p_(lookupOrConstruct(mesh, "p")), - - T_(lookupOrConstruct(mesh, "T")), - - alpha_ - ( - IOobject - ( - "thermo:alpha", - mesh.time().timeName(), - mesh, - IOobject::READ_IF_PRESENT, - IOobject::NO_WRITE - ), - mesh, - dimensionedScalar - ( - "zero", - dimensionSet(1, -1, -1, 0, 0), - Zero - ) - ), - - dpdt_(lookupOrDefault("dpdt", true)), - - tempBased_(lookupOrDefault("tempBased", true)) + ) {} diff --git a/src/thermophysicalModels/basic/basicThermo/basicThermo.H b/src/thermophysicalModels/basic/basicThermo/basicThermo.H index c2cee25ece..83da7eb562 100644 --- a/src/thermophysicalModels/basic/basicThermo/basicThermo.H +++ b/src/thermophysicalModels/basic/basicThermo/basicThermo.H @@ -27,6 +27,14 @@ Class Description Abstract base-class for fluid and solid thermodynamic properties + An important concept is that the thermo can share an existing T + (similar to p) in which case it will not try to update it. This gets + triggered purely on construction order - the first one to register + T is repsonsible for updating it. Note that the mechanism also means + that if multiple thermos are running on the same mesh, only the first one + will update the temperature. The behaviour can be overridden using the + 'updateT' dictionary entry. + SourceFiles basicThermo.C @@ -68,18 +76,19 @@ protected: //- Pressure [Pa] volScalarField& p_; + bool pOwner_; + //- Temperature [K] volScalarField& T_; + bool TOwner_; + //- Laminar thermal diffusivity [kg/m/s] volScalarField alpha_; //- Should the dpdt term be included in the enthalpy equation Switch dpdt_; - //- Temperature based thermo - Switch tempBased_; - // Protected Member Functions @@ -87,11 +96,12 @@ protected: basicThermo(const basicThermo&); //- Look up or construct field - volScalarField& lookupOrConstruct + static volScalarField& lookupOrConstruct ( const fvMesh& mesh, - const word& - ) const; + const word&, + bool& isOwner + ); //- Lookup and check out field void lookupAndCheckout(const char* name) const; @@ -150,8 +160,8 @@ public: const word& phaseName ); - //- Construct from mesh,dictionary,phase name with a single temperature - // solved on the top level solver (tempBased = true) + //- Construct from mesh, phase name and explicit naming of the + // dictionary (so it can be shared amongst phases). basicThermo ( const fvMesh&, @@ -304,10 +314,10 @@ public: return dpdt_; } - //- Is the thermo T based - Switch tempBased() const + //- Should T be updated + Switch updateT() const { - return tempBased_; + return TOwner_; } diff --git a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C index 68188f937f..f3a6446ee8 100644 --- a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C +++ b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C @@ -68,7 +68,7 @@ void Foam::hePsiThermo::calculate const typename MixtureType::thermoType& mixture_ = this->cellMixture(celli); - if (!this->tempBased()) + if (this->updateT()) { TCells[celli] = mixture_.THE ( @@ -121,7 +121,7 @@ void Foam::hePsiThermo::calculate const typename MixtureType::thermoType& mixture_ = this->patchFaceMixture(patchi, facei); - if (!this->tempBased()) + if (this->updateT()) { pT[facei] = mixture_.THE(phe[facei], pp[facei], pT[facei]); } diff --git a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H index 716ccaed68..f13e890b0a 100644 --- a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H +++ b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H @@ -66,9 +66,6 @@ class hePsiThermo const bool doOldTimes ); - //- Calculate the thermo variables for thermos based on T - void calculateT(); - //- Construct as copy (not implemented) hePsiThermo(const hePsiThermo&); diff --git a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C index b567f55c49..ec58b428c5 100644 --- a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C +++ b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C @@ -71,7 +71,7 @@ void Foam::heRhoThermo::calculate const typename MixtureType::thermoType& mixture_ = this->cellMixture(celli); - if (!this->tempBased()) + if (this->updateT()) { TCells[celli] = mixture_.THE ( @@ -128,7 +128,7 @@ void Foam::heRhoThermo::calculate const typename MixtureType::thermoType& mixture_ = this->patchFaceMixture(patchi, facei); - if (!this->tempBased()) + if (this->updateT()) { pT[facei] = mixture_.THE(phe[facei], pp[facei], pT[facei]); } diff --git a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H index 63f5f743a8..9fc5ac0a31 100644 --- a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H +++ b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H @@ -67,9 +67,6 @@ class heRhoThermo const bool doOldTimes ); - //- Calculate the thermo variables based on T - void calculateT(); - //- Construct as copy (not implemented) heRhoThermo(const heRhoThermo&); diff --git a/src/thermophysicalModels/reactionThermo/psiuReactionThermo/heheuPsiThermo.C b/src/thermophysicalModels/reactionThermo/psiuReactionThermo/heheuPsiThermo.C index be24bc09dd..3c367fbcd6 100644 --- a/src/thermophysicalModels/reactionThermo/psiuReactionThermo/heheuPsiThermo.C +++ b/src/thermophysicalModels/reactionThermo/psiuReactionThermo/heheuPsiThermo.C @@ -47,7 +47,7 @@ void Foam::heheuPsiThermo::calculate() const typename MixtureType::thermoType& mixture_ = this->cellMixture(celli); - if (!this->tempBased()) + if (this->updateT()) { TCells[celli] = mixture_.THE ( @@ -126,7 +126,7 @@ void Foam::heheuPsiThermo::calculate() const typename MixtureType::thermoType& mixture_ = this->patchFaceMixture(patchi, facei); - if (!this->tempBased()) + if (this->updateT()) { pT[facei] = mixture_.THE(phe[facei], pp[facei], pT[facei]); } diff --git a/src/thermophysicalModels/solidThermo/solidThermo/heSolidThermo.C b/src/thermophysicalModels/solidThermo/solidThermo/heSolidThermo.C index a115b1879f..98dee15d60 100644 --- a/src/thermophysicalModels/solidThermo/solidThermo/heSolidThermo.C +++ b/src/thermophysicalModels/solidThermo/solidThermo/heSolidThermo.C @@ -46,7 +46,7 @@ void Foam::heSolidThermo::calculate() const typename MixtureType::thermoType& volMixture_ = this->cellVolMixture(pCells[celli], TCells[celli], celli); - if (!this->tempBased()) + if (this->updateT()) { TCells[celli] = mixture_.THE ( @@ -128,7 +128,7 @@ void Foam::heSolidThermo::calculate() facei ); - if (!this->tempBased()) + if (this->updateT()) { pT[facei] = mixture_.THE(phe[facei], pp[facei] ,pT[facei]); } diff --git a/tutorials/multiphase/icoReactingMultiPhaseInterFoam/solidMelting2D/system/controlDict b/tutorials/multiphase/icoReactingMultiPhaseInterFoam/solidMelting2D/system/controlDict index 4ea37937b1..1507e053fc 100644 --- a/tutorials/multiphase/icoReactingMultiPhaseInterFoam/solidMelting2D/system/controlDict +++ b/tutorials/multiphase/icoReactingMultiPhaseInterFoam/solidMelting2D/system/controlDict @@ -16,7 +16,7 @@ FoamFile // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -application interThermalDyMFoam; +application icoReactingMultiPhaseInterFoam; startFrom latestTime;