From 95c37c0cbb6c953dca8df2e416750ee9ba865bd3 Mon Sep 17 00:00:00 2001 From: Andrew Heather Date: Tue, 4 Apr 2017 12:41:35 +0100 Subject: [PATCH] ENH: Updated second-order restart for thermo fields --- .../basic/heThermo/heThermo.C | 35 ++++-- .../basic/heThermo/heThermo.H | 9 +- .../basic/psiThermo/hePsiThermo.C | 106 ++++++++++------- .../basic/psiThermo/hePsiThermo.H | 14 ++- .../basic/rhoThermo/heRhoThermo.C | 110 +++++++++++------- .../basic/rhoThermo/heRhoThermo.H | 14 ++- 6 files changed, 186 insertions(+), 102 deletions(-) diff --git a/src/thermophysicalModels/basic/heThermo/heThermo.C b/src/thermophysicalModels/basic/heThermo/heThermo.C index c06ffb75d7..cb10d720e9 100644 --- a/src/thermophysicalModels/basic/heThermo/heThermo.C +++ b/src/thermophysicalModels/basic/heThermo/heThermo.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -52,11 +52,16 @@ heBoundaryCorrection(volScalarField& h) template -void Foam::heThermo::init() +void Foam::heThermo::init +( + const volScalarField& p, + const volScalarField& T, + volScalarField& he +) { - scalarField& heCells = he_.primitiveFieldRef(); - const scalarField& pCells = this->p_; - const scalarField& TCells = this->T_; + scalarField& heCells = he.primitiveFieldRef(); + const scalarField& pCells = p.primitiveField(); + const scalarField& TCells = T.primitiveField(); forAll(heCells, celli) { @@ -64,19 +69,25 @@ void Foam::heThermo::init() this->cellMixture(celli).HE(pCells[celli], TCells[celli]); } - volScalarField::Boundary& heBf = he_.boundaryFieldRef(); + volScalarField::Boundary& heBf = he.boundaryFieldRef(); forAll(heBf, patchi) { - heBf[patchi] == he + heBf[patchi] == this->he ( - this->p_.boundaryField()[patchi], - this->T_.boundaryField()[patchi], + p.boundaryField()[patchi], + T.boundaryField()[patchi], patchi ); } - this->heBoundaryCorrection(he_); + this->heBoundaryCorrection(he); + + // Note: T does not have oldTime + if (p.nOldTimes() > 0) + { + init(p.oldTime(), T.oldTime(), he.oldTime()); + } } @@ -112,7 +123,7 @@ Foam::heThermo::heThermo this->heBoundaryBaseTypes() ) { - init(); + init(this->p_, this->T_, he_); } @@ -146,7 +157,7 @@ Foam::heThermo::heThermo this->heBoundaryBaseTypes() ) { - init(); + init(this->p_, this->T_, he_); } diff --git a/src/thermophysicalModels/basic/heThermo/heThermo.H b/src/thermophysicalModels/basic/heThermo/heThermo.H index 7967cc44cc..02b0ad419e 100644 --- a/src/thermophysicalModels/basic/heThermo/heThermo.H +++ b/src/thermophysicalModels/basic/heThermo/heThermo.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -77,7 +77,12 @@ private: //- Initialize heThermo - void init(); + void init + ( + const volScalarField& p, + const volScalarField& T, + volScalarField& he + ); public: diff --git a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C index 71cc38498e..1765619767 100644 --- a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C +++ b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,15 +28,40 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::hePsiThermo::calculate() +void Foam::hePsiThermo::calculate +( + const volScalarField& p, + volScalarField& T, + volScalarField& he, + volScalarField& psi, + volScalarField& mu, + volScalarField& alpha, + const bool doOldTimes +) { - const scalarField& hCells = this->he_; - const scalarField& pCells = this->p_; + // Note: update oldTimes before current time so that if T.oldTime() is + // created from T, it starts from the unconverted T + if (doOldTimes && (p.nOldTimes() || T.nOldTimes())) + { + calculate + ( + p.oldTime(), + T.oldTime(), + he.oldTime(), + psi.oldTime(), + mu.oldTime(), + alpha.oldTime(), + true + ); + } - scalarField& TCells = this->T_.primitiveFieldRef(); - scalarField& psiCells = this->psi_.primitiveFieldRef(); - scalarField& muCells = this->mu_.primitiveFieldRef(); - scalarField& alphaCells = this->alpha_.primitiveFieldRef(); + const scalarField& hCells = he.primitiveField(); + const scalarField& pCells = p.primitiveField(); + + scalarField& TCells = T.primitiveFieldRef(); + scalarField& psiCells = psi.primitiveFieldRef(); + scalarField& muCells = mu.primitiveFieldRef(); + scalarField& alphaCells = alpha.primitiveFieldRef(); forAll(TCells, celli) { @@ -56,27 +81,16 @@ void Foam::hePsiThermo::calculate() alphaCells[celli] = mixture_.alphah(pCells[celli], TCells[celli]); } - volScalarField::Boundary& pBf = - this->p_.boundaryFieldRef(); + const volScalarField::Boundary& pBf = p.boundaryField(); + volScalarField::Boundary& TBf = T.boundaryFieldRef(); + volScalarField::Boundary& psiBf = psi.boundaryFieldRef(); + volScalarField::Boundary& heBf = he.boundaryFieldRef(); + volScalarField::Boundary& muBf = mu.boundaryFieldRef(); + volScalarField::Boundary& alphaBf = alpha.boundaryFieldRef(); - volScalarField::Boundary& TBf = - this->T_.boundaryFieldRef(); - - volScalarField::Boundary& psiBf = - this->psi_.boundaryFieldRef(); - - volScalarField::Boundary& heBf = - this->he().boundaryFieldRef(); - - volScalarField::Boundary& muBf = - this->mu_.boundaryFieldRef(); - - volScalarField::Boundary& alphaBf = - this->alpha_.boundaryFieldRef(); - - forAll(this->T_.boundaryField(), patchi) + forAll(pBf, patchi) { - fvPatchScalarField& pp = pBf[patchi]; + const fvPatchScalarField& pp = pBf[patchi]; fvPatchScalarField& pT = TBf[patchi]; fvPatchScalarField& ppsi = psiBf[patchi]; fvPatchScalarField& phe = heBf[patchi]; @@ -126,10 +140,16 @@ Foam::hePsiThermo::hePsiThermo : heThermo(mesh, phaseName) { - calculate(); - - // Switch on saving old time - this->psi_.oldTime(); + calculate + ( + this->p_, + this->T_, + this->he_, + this->psi_, + this->mu_, + this->alpha_, + true // Create old time fields + ); } @@ -145,20 +165,20 @@ Foam::hePsiThermo::~hePsiThermo() template void Foam::hePsiThermo::correct() { - if (debug) - { - InfoInFunction << endl; - } + DebugInFunction << endl; - // force the saving of the old-time values - this->psi_.oldTime(); + calculate + ( + this->p_, + this->T_, + this->he_, + this->psi_, + this->mu_, + this->alpha_, + false // No need to update old times + ); - calculate(); - - if (debug) - { - Info<< " Finished" << endl; - } + DebugInFunction << "Finished" << endl; } diff --git a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H index ca5a89f73f..9b12c53ee7 100644 --- a/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H +++ b/src/thermophysicalModels/basic/psiThermo/hePsiThermo.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,11 +55,21 @@ class hePsiThermo // Private Member Functions //- Calculate the thermo variables - void calculate(); + void calculate + ( + const volScalarField& p, + volScalarField& T, + volScalarField& he, + volScalarField& psi, + volScalarField& mu, + volScalarField& alpha, + const bool doOldTimes + ); //- Construct as copy (not implemented) hePsiThermo(const hePsiThermo&); + public: //- Runtime type information diff --git a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C index 9c889ac7f3..cc545d55e9 100644 --- a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C +++ b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.C @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -28,16 +28,43 @@ License // * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * // template -void Foam::heRhoThermo::calculate() +void Foam::heRhoThermo::calculate +( + const volScalarField& p, + volScalarField& T, + volScalarField& he, + volScalarField& psi, + volScalarField& rho, + volScalarField& mu, + volScalarField& alpha, + const bool doOldTimes +) { - const scalarField& hCells = this->he(); - const scalarField& pCells = this->p_; + // Note: update oldTimes before current time so that if T.oldTime() is + // created from T, it starts from the unconverted T + if (doOldTimes && (p.nOldTimes() || T.nOldTimes())) + { + calculate + ( + p.oldTime(), + T.oldTime(), + he.oldTime(), + psi.oldTime(), + rho.oldTime(), + mu.oldTime(), + alpha.oldTime(), + true + ); + } - scalarField& TCells = this->T_.primitiveFieldRef(); - scalarField& psiCells = this->psi_.primitiveFieldRef(); - scalarField& rhoCells = this->rho_.primitiveFieldRef(); - scalarField& muCells = this->mu_.primitiveFieldRef(); - scalarField& alphaCells = this->alpha_.primitiveFieldRef(); + const scalarField& hCells = he.primitiveField(); + const scalarField& pCells = p.primitiveField(); + + scalarField& TCells = T.primitiveFieldRef(); + scalarField& psiCells = psi.primitiveFieldRef(); + scalarField& rhoCells = rho.primitiveFieldRef(); + scalarField& muCells = mu.primitiveFieldRef(); + scalarField& alphaCells = alpha.primitiveFieldRef(); forAll(TCells, celli) { @@ -58,30 +85,17 @@ void Foam::heRhoThermo::calculate() alphaCells[celli] = mixture_.alphah(pCells[celli], TCells[celli]); } - volScalarField::Boundary& pBf = - this->p_.boundaryFieldRef(); + const volScalarField::Boundary& pBf = p.boundaryField(); + volScalarField::Boundary& TBf = T.boundaryFieldRef(); + volScalarField::Boundary& psiBf = psi.boundaryFieldRef(); + volScalarField::Boundary& rhoBf = rho.boundaryFieldRef(); + volScalarField::Boundary& heBf = he.boundaryFieldRef(); + volScalarField::Boundary& muBf = mu.boundaryFieldRef(); + volScalarField::Boundary& alphaBf = alpha.boundaryFieldRef(); - volScalarField::Boundary& TBf = - this->T_.boundaryFieldRef(); - - volScalarField::Boundary& psiBf = - this->psi_.boundaryFieldRef(); - - volScalarField::Boundary& rhoBf = - this->rho_.boundaryFieldRef(); - - volScalarField::Boundary& heBf = - this->he().boundaryFieldRef(); - - volScalarField::Boundary& muBf = - this->mu_.boundaryFieldRef(); - - volScalarField::Boundary& alphaBf = - this->alpha_.boundaryFieldRef(); - - forAll(this->T_.boundaryField(), patchi) + forAll(pBf, patchi) { - fvPatchScalarField& pp = pBf[patchi]; + const fvPatchScalarField& pp = pBf[patchi]; fvPatchScalarField& pT = TBf[patchi]; fvPatchScalarField& ppsi = psiBf[patchi]; fvPatchScalarField& prho = rhoBf[patchi]; @@ -134,7 +148,17 @@ Foam::heRhoThermo::heRhoThermo : heThermo(mesh, phaseName) { - calculate(); + calculate + ( + this->p_, + this->T_, + this->he_, + this->psi_, + this->rho_, + this->mu_, + this->alpha_, + true // Create old time fields + ); } @@ -150,17 +174,21 @@ Foam::heRhoThermo::~heRhoThermo() template void Foam::heRhoThermo::correct() { - if (debug) - { - InfoInFunction << endl; - } + DebugInFunction << endl; - calculate(); + calculate + ( + this->p_, + this->T_, + this->he_, + this->psi_, + this->rho_, + this->mu_, + this->alpha_, + false // No need to update old times + ); - if (debug) - { - Info<< " Finished" << endl; - } + DebugInFunction << "Finished" << endl; } diff --git a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H index 7e2138d127..042e3c62e8 100644 --- a/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H +++ b/src/thermophysicalModels/basic/rhoThermo/heRhoThermo.H @@ -3,7 +3,7 @@ \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation - \\/ M anipulation | + \\/ M anipulation | Copyright (C) 2015-2017 OpenCFD Ltd. ------------------------------------------------------------------------------- License This file is part of OpenFOAM. @@ -55,7 +55,17 @@ class heRhoThermo // Private Member Functions //- Calculate the thermo variables - void calculate(); + void calculate + ( + const volScalarField& p, + volScalarField& T, + volScalarField& he, + volScalarField& psi, + volScalarField& rho, + volScalarField& mu, + volScalarField& alpha, + const bool doOldTimes + ); //- Construct as copy (not implemented) heRhoThermo(const heRhoThermo&);