From 7b825d0817e14e1dab4c75a4b33d200b7cd77e41 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 12 May 2017 11:04:38 +0100 Subject: [PATCH 1/6] rhoPimpleFoam: Updated transonic option to be consistent with sonicFoam Improves stability on start-up and allows running at slightly larger time-steps. --- .../solvers/compressible/rhoPimpleFoam/pEqn.H | 15 +- .../compressible/rhoPimpleFoam/pcEqn.H | 14 +- .../solvers/compressible/rhoSimpleFoam/pEqn.H | 197 +++++++++--------- .../compressible/rhoSimpleFoam/pcEqn.H | 14 +- .../general/pressureControl/pressureControl.C | 22 +- .../general/pressureControl/pressureControl.H | 4 +- 6 files changed, 145 insertions(+), 121 deletions(-) diff --git a/applications/solvers/compressible/rhoPimpleFoam/pEqn.H b/applications/solvers/compressible/rhoPimpleFoam/pEqn.H index 5aab536239..9eecd01d99 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/pEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/pEqn.H @@ -1,3 +1,5 @@ +rho = thermo.rho(); + volScalarField rAU(1.0/UEqn.A()); surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); @@ -10,7 +12,7 @@ if (pimple.nCorrPISO() <= 1) surfaceScalarField phiHbyA ( "phiHbyA", - fvc::flux(rho*HbyA) + fvc::interpolate(rho)*fvc::flux(HbyA) + rhorAUf*fvc::ddtCorr(rho, U, phi) ); @@ -26,7 +28,8 @@ if (pimple.transonic()) "phid", (fvc::interpolate(psi)/fvc::interpolate(rho))*phiHbyA ); - phiHbyA -= fvc::interpolate(p)*phid; + + phiHbyA -= fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); while (pimple.correctNonOrthogonal()) { @@ -84,9 +87,11 @@ U.correctBoundaryConditions(); fvOptions.correct(U); K = 0.5*magSqr(U); -pressureControl.limit(p); -p.correctBoundaryConditions(); -rho = thermo.rho(); +if (pressureControl.limit(p)) +{ + p.correctBoundaryConditions(); + rho = thermo.rho(); +} if (!pimple.transonic()) { diff --git a/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H b/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H index afbc2851e4..34657a1892 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H @@ -1,3 +1,5 @@ +rho = thermo.rho(); + volScalarField rAU(1.0/UEqn.A()); volScalarField rAtU(1.0/(1.0/rAU - UEqn.H1())); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); @@ -11,7 +13,7 @@ surfaceScalarField phiHbyA ( "phiHbyA", ( - fvc::flux(rho*HbyA) + fvc::interpolate(rho)*fvc::flux(HbyA) + fvc::interpolate(rho*rAU)*fvc::ddtCorr(rho, U, phi) ) ); @@ -33,7 +35,7 @@ if (pimple.transonic()) phiHbyA += fvc::interpolate(rho*(rAtU - rAU))*fvc::snGrad(p)*mesh.magSf() - - fvc::interpolate(p)*phid; + - fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); HbyA -= (rAU - rAtU)*fvc::grad(p); @@ -96,9 +98,11 @@ U.correctBoundaryConditions(); fvOptions.correct(U); K = 0.5*magSqr(U); -pressureControl.limit(p); -p.correctBoundaryConditions(); -rho = thermo.rho(); +if (pressureControl.limit(p)) +{ + p.correctBoundaryConditions(); + rho = thermo.rho(); +} if (!pimple.transonic()) { diff --git a/applications/solvers/compressible/rhoSimpleFoam/pEqn.H b/applications/solvers/compressible/rhoSimpleFoam/pEqn.H index c7edbb9e87..0f290ed273 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/pEqn.H +++ b/applications/solvers/compressible/rhoSimpleFoam/pEqn.H @@ -1,109 +1,110 @@ +volScalarField rAU(1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); +tUEqn.clear(); + +bool closedVolume = false; + +surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(rho)*fvc::flux(HbyA)); +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); + +if (simple.transonic()) { - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); - tUEqn.clear(); + surfaceScalarField phid + ( + "phid", + (fvc::interpolate(psi)/fvc::interpolate(rho))*phiHbyA + ); - bool closedVolume = false; + phiHbyA -= fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); - surfaceScalarField phiHbyA("phiHbyA", fvc::flux(rho*HbyA)); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); - - // Update the pressure BCs to ensure flux consistency - constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); - - if (simple.transonic()) + while (simple.correctNonOrthogonal()) { - surfaceScalarField phid + fvScalarMatrix pEqn ( - "phid", - (fvc::interpolate(psi)/fvc::interpolate(rho))*phiHbyA + fvc::div(phiHbyA) + + fvm::div(phid, p) + - fvm::laplacian(rhorAUf, p) + == + fvOptions(psi, p, rho.name()) ); - phiHbyA -= fvc::interpolate(p)*phid; - while (simple.correctNonOrthogonal()) + // Relax the pressure equation to ensure diagonal-dominance + pEqn.relax(); + + pEqn.setReference + ( + pressureControl.refCell(), + pressureControl.refValue() + ); + + pEqn.solve(); + + if (simple.finalNonOrthogonalIter()) { - fvScalarMatrix pEqn - ( - fvc::div(phiHbyA) - + fvm::div(phid, p) - - fvm::laplacian(rhorAUf, p) - == - fvOptions(psi, p, rho.name()) - ); - - // Relax the pressure equation to ensure diagonal-dominance - pEqn.relax(); - - pEqn.setReference - ( - pressureControl.refCell(), - pressureControl.refValue() - ); - - pEqn.solve(); - - if (simple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } + phi = phiHbyA + pEqn.flux(); } } - else - { - closedVolume = adjustPhi(phiHbyA, U, p); - - while (simple.correctNonOrthogonal()) - { - fvScalarMatrix pEqn - ( - fvc::div(phiHbyA) - - fvm::laplacian(rhorAUf, p) - == - fvOptions(psi, p, rho.name()) - ); - - pEqn.setReference - ( - pressureControl.refCell(), - pressureControl.refValue() - ); - - pEqn.solve(); - - if (simple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } - } - } - - - #include "incompressible/continuityErrs.H" - - // Explicitly relax pressure for momentum corrector - p.relax(); - - U = HbyA - rAU*fvc::grad(p); - U.correctBoundaryConditions(); - fvOptions.correct(U); - - pressureControl.limit(p); - - // For closed-volume cases adjust the pressure and density levels - // to obey overall mass continuity - if (closedVolume) - { - p += (initialMass - fvc::domainIntegrate(psi*p)) - /fvc::domainIntegrate(psi); - } - - p.correctBoundaryConditions(); - - rho = thermo.rho(); - - if (!simple.transonic()) - { - rho.relax(); - } +} +else +{ + closedVolume = adjustPhi(phiHbyA, U, p); + + while (simple.correctNonOrthogonal()) + { + fvScalarMatrix pEqn + ( + fvc::div(phiHbyA) + - fvm::laplacian(rhorAUf, p) + == + fvOptions(psi, p, rho.name()) + ); + + pEqn.setReference + ( + pressureControl.refCell(), + pressureControl.refValue() + ); + + pEqn.solve(); + + if (simple.finalNonOrthogonalIter()) + { + phi = phiHbyA + pEqn.flux(); + } + } +} + +#include "incompressible/continuityErrs.H" + +// Explicitly relax pressure for momentum corrector +p.relax(); + +U = HbyA - rAU*fvc::grad(p); +U.correctBoundaryConditions(); +fvOptions.correct(U); + +bool pLimited = pressureControl.limit(p); + +// For closed-volume cases adjust the pressure and density levels +// to obey overall mass continuity +if (closedVolume) +{ + p += (initialMass - fvc::domainIntegrate(psi*p)) + /fvc::domainIntegrate(psi); +} + +if (pLimited || closedVolume) +{ + p.correctBoundaryConditions(); +} + +rho = thermo.rho(); + +if (!simple.transonic()) +{ + rho.relax(); } diff --git a/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H b/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H index c7dc0f864d..51560aab5f 100644 --- a/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H +++ b/applications/solvers/compressible/rhoSimpleFoam/pcEqn.H @@ -1,3 +1,5 @@ +rho = thermo.rho(); + volScalarField rAU(1.0/UEqn.A()); volScalarField rAtU(1.0/(1.0/rAU - UEqn.H1())); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); @@ -5,7 +7,7 @@ tUEqn.clear(); bool closedVolume = false; -surfaceScalarField phiHbyA("phiHbyA", fvc::flux(rho*HbyA)); +surfaceScalarField phiHbyA("phiHbyA", fvc::interpolate(rho)*fvc::flux(HbyA)); MRF.makeRelative(fvc::interpolate(rho), phiHbyA); volScalarField rhorAtU("rhorAtU", rho*rAtU); @@ -23,7 +25,7 @@ if (simple.transonic()) phiHbyA += fvc::interpolate(rho*(rAtU - rAU))*fvc::snGrad(p)*mesh.magSf() - - fvc::interpolate(p)*phid; + - fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); HbyA -= (rAU - rAtU)*fvc::grad(p); @@ -98,7 +100,7 @@ U = HbyA - rAtU*fvc::grad(p); U.correctBoundaryConditions(); fvOptions.correct(U); -pressureControl.limit(p); +bool pLimited = pressureControl.limit(p); // For closed-volume cases adjust the pressure and density levels // to obey overall mass continuity @@ -108,9 +110,11 @@ if (closedVolume) /fvc::domainIntegrate(psi); } -p.correctBoundaryConditions(); +if (pLimited || closedVolume) +{ + p.correctBoundaryConditions(); +} -// Recalculate density from the relaxed pressure rho = thermo.rho(); if (!simple.transonic()) diff --git a/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.C b/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.C index aca22e7699..abd71e60ac 100644 --- a/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.C +++ b/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.C @@ -207,14 +207,24 @@ Foam::pressureControl::pressureControl // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // -void Foam::pressureControl::limit(volScalarField& p) const +bool Foam::pressureControl::limit(volScalarField& p) const { - Info<< "pressureControl: p max/min " - << max(p).value() << " " - << min(p).value() << endl; + scalar pMax = max(p).value(); + scalar pMin = min(p).value(); - p = max(p, pMin_); - p = min(p, pMax_); + if (pMax > pMax_.value() || pMin < pMin_.value()) + { + Info<< "pressureControl: p max/min " << pMax << " " << pMin << endl; + + p = max(p, pMin_); + p = min(p, pMax_); + + return true; + } + else + { + return false; + } } diff --git a/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.H b/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.H index 61f510ac60..0bb49c99a5 100644 --- a/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.H +++ b/src/finiteVolume/cfdTools/general/pressureControl/pressureControl.H @@ -89,8 +89,8 @@ public: //- Return the pressure reference level inline scalar refValue() const; - //- Limit the pressure - void limit(volScalarField& p) const; + //- Limit the pressure if necessary and return true if so + bool limit(volScalarField& p) const; }; From b83af3b085abde7ce80d8213b609666c1c699804 Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Fri, 12 May 2017 18:34:00 +0100 Subject: [PATCH 2/6] rhoPimpleDyMFoam: Updated transonic formulation for consistency with sonicFoam --- .../rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H index 0f85562618..1540f601c1 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H @@ -1,3 +1,5 @@ +rho = thermo.rho(); + volScalarField rAU(1.0/UEqn.A()); surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); @@ -27,7 +29,8 @@ if (pimple.transonic()) "phid", (fvc::interpolate(psi)/fvc::interpolate(rho))*phiHbyA ); - phiHbyA -= fvc::interpolate(p)*phid; + + phiHbyA -= fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); while (pimple.correctNonOrthogonal()) { @@ -86,9 +89,11 @@ U.correctBoundaryConditions(); fvOptions.correct(U); K = 0.5*magSqr(U); -pressureControl.limit(p); -p.correctBoundaryConditions(); -rho = thermo.rho(); +if (pressureControl.limit(p)) +{ + p.correctBoundaryConditions(); + rho = thermo.rho(); +} if (!pimple.transonic()) { From 39476bde1c8feefcd4e37c55663bca8fa43e422d Mon Sep 17 00:00:00 2001 From: Henry Weller Date: Wed, 17 May 2017 17:05:43 +0100 Subject: [PATCH 3/6] GIT: Resolve conflict associated with cherry-pick of Foundation commit 79ff91350 79ff91350 - rhoPimpleFoam: Improved support for compressible liquids (2017-05-17 17:05:43 +0100) --- .../combustion/reactingFoam/createFields.H | 22 +-- .../solvers/combustion/reactingFoam/pEqn.H | 17 +- .../solvers/combustion/reactingFoam/pcEqn.H | 21 +-- .../combustion/reactingFoam/reactingFoam.C | 5 +- .../rhoReactingBuoyantFoam/pEqn.H | 130 +++++++------ .../rhoReactingFoam/createFields.H | 2 + .../reactingFoam/rhoReactingFoam/pEqn.H | 109 ----------- .../rhoReactingFoam/rhoReactingFoam.C | 12 +- .../compressible/rhoPimpleFoam/createFields.H | 4 +- .../solvers/compressible/rhoPimpleFoam/pEqn.H | 52 +++--- .../compressible/rhoPimpleFoam/pcEqn.H | 52 +++--- .../rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H | 9 +- .../rhoPimpleFoam/rhoPimpleFoam.C | 2 + .../heatTransfer/buoyantPimpleFoam/pEqn.H | 173 +++++++---------- .../chtMultiRegionFoam/fluid/pEqn.H | 176 ++++++++---------- .../coalChemistryFoam/coalChemistryFoam.C | 3 +- .../lagrangian/reactingParcelFoam/pEqn.H | 128 +++++++------ .../simpleReactingParcelFoam/pEqn.H | 96 +++++----- .../compressibleInterDyMFoam/pEqn.H | 4 +- .../compressibleInterFoam/createFields.H | 4 +- .../multiphase/compressibleInterFoam/pEqn.H | 4 +- .../pimpleControl/pimpleControl.C | 4 +- .../pimpleControl/pimpleControl.H | 10 +- .../pimpleControl/pimpleControlI.H | 8 +- .../basic/fluidThermo/fluidThermo.H | 6 +- .../basic/psiThermo/psiThermo.C | 6 +- .../basic/psiThermo/psiThermo.H | 7 +- .../basic/rhoThermo/rhoThermo.C | 8 +- .../basic/rhoThermo/rhoThermo.H | 6 +- .../RAS/angledDuct/system/fvSolution | 1 + .../rhoPimpleFoam/RAS/squareBendLiq/0/T | 42 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/U | 43 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/alphat | 45 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/epsilon | 49 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/k | 46 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/nut | 47 +++++ .../rhoPimpleFoam/RAS/squareBendLiq/0/p | 41 ++++ .../constant/thermophysicalProperties | 31 +++ .../constant/turbulenceProperties | 30 +++ .../RAS/squareBendLiq/system/blockMeshDict | 127 +++++++++++++ .../RAS/squareBendLiq/system/controlDict | 51 +++++ .../RAS/squareBendLiq/system/decomposeParDict | 45 +++++ .../RAS/squareBendLiq/system/fvSchemes | 60 ++++++ .../RAS/squareBendLiq/system/fvSolution | 63 +++++++ 44 files changed, 1194 insertions(+), 607 deletions(-) delete mode 100644 applications/solvers/combustion/reactingFoam/rhoReactingFoam/pEqn.H create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/T create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/U create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/alphat create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/epsilon create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/k create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/nut create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/0/p create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/constant/thermophysicalProperties create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/constant/turbulenceProperties create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/system/blockMeshDict create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/system/controlDict create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/system/decomposeParDict create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/system/fvSchemes create mode 100644 tutorials/compressible/rhoPimpleFoam/RAS/squareBendLiq/system/fvSolution diff --git a/applications/solvers/combustion/reactingFoam/createFields.H b/applications/solvers/combustion/reactingFoam/createFields.H index 6fcf83624c..bc09358193 100644 --- a/applications/solvers/combustion/reactingFoam/createFields.H +++ b/applications/solvers/combustion/reactingFoam/createFields.H @@ -52,27 +52,7 @@ volScalarField& p = thermo.p(); #include "compressibleCreatePhi.H" -dimensionedScalar rhoMax -( - dimensionedScalar::lookupOrDefault - ( - "rhoMax", - pimple.dict(), - dimDensity, - GREAT - ) -); - -dimensionedScalar rhoMin -( - dimensionedScalar::lookupOrDefault - ( - "rhoMin", - pimple.dict(), - dimDensity, - 0 - ) -); +pressureControl pressureControl(p, rho, pimple.dict(), false); mesh.setFluxRequired(p.name()); diff --git a/applications/solvers/combustion/reactingFoam/pEqn.H b/applications/solvers/combustion/reactingFoam/pEqn.H index ac7107acf0..81ab6424b4 100644 --- a/applications/solvers/combustion/reactingFoam/pEqn.H +++ b/applications/solvers/combustion/reactingFoam/pEqn.H @@ -1,7 +1,4 @@ rho = thermo.rho(); -rho = max(rho, rhoMin); -rho = min(rho, rhoMax); -rho.relax(); volScalarField rAU(1.0/UEqn.A()); surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); @@ -87,19 +84,17 @@ else // Explicitly relax pressure for momentum corrector p.relax(); -// Recalculate density from the relaxed pressure -rho = thermo.rho(); -rho = max(rho, rhoMin); -rho = min(rho, rhoMax); -rho.relax(); -Info<< "rho max/min : " << max(rho).value() - << " " << min(rho).value() << endl; - U = HbyA - rAU*fvc::grad(p); U.correctBoundaryConditions(); fvOptions.correct(U); K = 0.5*magSqr(U); +if (pressureControl.limit(p)) +{ + p.correctBoundaryConditions(); + rho = thermo.rho(); +} + if (thermo.dpdt()) { dpdt = fvc::ddt(p); diff --git a/applications/solvers/combustion/reactingFoam/pcEqn.H b/applications/solvers/combustion/reactingFoam/pcEqn.H index 713f443fc5..a1564b0f20 100644 --- a/applications/solvers/combustion/reactingFoam/pcEqn.H +++ b/applications/solvers/combustion/reactingFoam/pcEqn.H @@ -1,7 +1,4 @@ rho = thermo.rho(); -rho = max(rho, rhoMin); -rho = min(rho, rhoMax); -rho.relax(); volScalarField rAU(1.0/UEqn.A()); volScalarField rAtU(1.0/(1.0/rAU - UEqn.H1())); @@ -109,19 +106,13 @@ U.correctBoundaryConditions(); fvOptions.correct(U); K = 0.5*magSqr(U); +if (pressureControl.limit(p)) +{ + p.correctBoundaryConditions(); + rho = thermo.rho(); +} + if (thermo.dpdt()) { dpdt = fvc::ddt(p); } - -// Recalculate density from the relaxed pressure -rho = thermo.rho(); -rho = max(rho, rhoMin); -rho = min(rho, rhoMax); - -if (!pimple.transonic()) -{ - rho.relax(); -} - -Info<< "rho max/min : " << max(rho).value() << " " << min(rho).value() << endl; diff --git a/applications/solvers/combustion/reactingFoam/reactingFoam.C b/applications/solvers/combustion/reactingFoam/reactingFoam.C index a06eef279c..d3e1b19ad3 100644 --- a/applications/solvers/combustion/reactingFoam/reactingFoam.C +++ b/applications/solvers/combustion/reactingFoam/reactingFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -37,6 +37,7 @@ Description #include "psiCombustionModel.H" #include "multivariateScheme.H" #include "pimpleControl.H" +#include "pressureControl.H" #include "fvOptions.H" #include "localEulerDdtScheme.H" #include "fvcSmooth.H" @@ -114,6 +115,8 @@ int main(int argc, char *argv[]) } } + rho = thermo.rho(); + runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/pEqn.H b/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/pEqn.H index 926e69f7c1..04296ddfc2 100644 --- a/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/pEqn.H +++ b/applications/solvers/combustion/reactingFoam/rhoReactingBuoyantFoam/pEqn.H @@ -1,76 +1,74 @@ +rho = thermo.rho(); + +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); + +volScalarField rAU(1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); + +surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); + +surfaceScalarField phiHbyA +( + "phiHbyA", + ( + fvc::flux(rho*HbyA) + + rhorAUf*fvc::ddtCorr(rho, U, phi) + ) + + phig +); + +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); + +fvScalarMatrix p_rghDDtEqn +( + fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) + + fvc::div(phiHbyA) + == + fvOptions(psi, p_rgh, rho.name()) +); + +while (pimple.correctNonOrthogonal()) { - rho = thermo.rho(); - - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p; - - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); - - surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); - - surfaceScalarField phiHbyA + fvScalarMatrix p_rghEqn ( - "phiHbyA", - ( - fvc::flux(rho*HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi) - ) - + phig + p_rghDDtEqn + - fvm::laplacian(rhorAUf, p_rgh) ); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter()))); - // Update the pressure BCs to ensure flux consistency - constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); - - fvScalarMatrix p_rghDDtEqn - ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) - + fvc::div(phiHbyA) - == - fvOptions(psi, p_rgh, rho.name()) - ); - - while (pimple.correctNonOrthogonal()) + if (pimple.finalNonOrthogonalIter()) { - fvScalarMatrix p_rghEqn - ( - p_rghDDtEqn - - fvm::laplacian(rhorAUf, p_rgh) - ); + // Calculate the conservative fluxes + phi = phiHbyA + p_rghEqn.flux(); - p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter()))); + // Explicitly relax pressure for momentum corrector + p_rgh.relax(); - if (pimple.finalNonOrthogonalIter()) - { - // Calculate the conservative fluxes - phi = phiHbyA + p_rghEqn.flux(); - - // Explicitly relax pressure for momentum corrector - p_rgh.relax(); - - // Correct the momentum source with the pressure gradient flux - // calculated from the relaxed pressure - U = HbyA + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); - U.correctBoundaryConditions(); - fvOptions.correct(U); - K = 0.5*magSqr(U); - } + // Correct the momentum source with the pressure gradient flux + // calculated from the relaxed pressure + U = HbyA + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); + U.correctBoundaryConditions(); + fvOptions.correct(U); + K = 0.5*magSqr(U); } - - p = p_rgh + rho*gh; - - // Second part of thermodynamic density update - thermo.rho() += psi*p; - - if (thermo.dpdt()) - { - dpdt = fvc::ddt(p); - } - - #include "rhoEqn.H" - #include "compressibleContinuityErrs.H" } + +p = p_rgh + rho*gh; + +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + +if (thermo.dpdt()) +{ + dpdt = fvc::ddt(p); +} + +#include "rhoEqn.H" +#include "compressibleContinuityErrs.H" diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFields.H b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFields.H index 687dffcc13..e56035f24a 100644 --- a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFields.H +++ b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/createFields.H @@ -52,6 +52,8 @@ volScalarField& p = thermo.p(); #include "compressibleCreatePhi.H" +pressureControl pressureControl(p, rho, pimple.dict(), false); + mesh.setFluxRequired(p.name()); diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/pEqn.H b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/pEqn.H deleted file mode 100644 index eff014cf43..0000000000 --- a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/pEqn.H +++ /dev/null @@ -1,109 +0,0 @@ -{ - rho = thermo.rho(); - - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p; - - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); - - if (pimple.transonic()) - { - surfaceScalarField phiHbyA - ( - "phiHbyA", - ( - fvc::flux(HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi)/fvc::interpolate(rho) - ) - ); - - MRF.makeRelative(phiHbyA); - - surfaceScalarField phid("phid", fvc::interpolate(thermo.psi())*phiHbyA); - - phiHbyA *= fvc::interpolate(rho); - - fvScalarMatrix pDDtEqn - ( - fvc::ddt(rho) + fvc::div(phiHbyA) - + correction(psi*fvm::ddt(p) + fvm::div(phid, p)) - ); - - while (pimple.correctNonOrthogonal()) - { - fvScalarMatrix pEqn - ( - pDDtEqn - - fvm::laplacian(rhorAUf, p) - == - fvOptions(psi, p, rho.name()) - ); - - pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); - - if (pimple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } - } - } - else - { - surfaceScalarField phiHbyA - ( - "phiHbyA", - ( - fvc::flux(rho*HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi) - ) - ); - - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); - - // Update the pressure BCs to ensure flux consistency - constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); - - fvScalarMatrix pDDtEqn - ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p)) - + fvc::div(phiHbyA) - == - fvOptions(psi, p, rho.name()) - ); - - while (pimple.correctNonOrthogonal()) - { - fvScalarMatrix pEqn - ( - pDDtEqn - - fvm::laplacian(rhorAUf, p) - ); - - pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); - - if (pimple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } - } - } - - // Second part of thermodynamic density update - thermo.rho() += psi*p; - - #include "rhoEqn.H" - #include "compressibleContinuityErrs.H" - - U = HbyA - rAU*fvc::grad(p); - U.correctBoundaryConditions(); - fvOptions.correct(U); - K = 0.5*magSqr(U); - - if (thermo.dpdt()) - { - dpdt = fvc::ddt(p); - } -} diff --git a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/rhoReactingFoam.C b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/rhoReactingFoam.C index 55de274d83..5be897c6c7 100644 --- a/applications/solvers/combustion/reactingFoam/rhoReactingFoam/rhoReactingFoam.C +++ b/applications/solvers/combustion/reactingFoam/rhoReactingFoam/rhoReactingFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -38,6 +38,7 @@ Description #include "turbulentFluidThermoModel.H" #include "multivariateScheme.H" #include "pimpleControl.H" +#include "pressureControl.H" #include "fvOptions.H" #include "localEulerDdtScheme.H" #include "fvcSmooth.H" @@ -100,7 +101,14 @@ int main(int argc, char *argv[]) // --- Pressure corrector loop while (pimple.correct()) { - #include "pEqn.H" + if (pimple.consistent()) + { + #include "../../../compressible/rhoPimpleFoam/pcEqn.H" + } + else + { + #include "../../../compressible/rhoPimpleFoam/pEqn.H" + } } if (pimple.turbCorr()) diff --git a/applications/solvers/compressible/rhoPimpleFoam/createFields.H b/applications/solvers/compressible/rhoPimpleFoam/createFields.H index 84f70f2cd0..3ec620dc22 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/createFields.H +++ b/applications/solvers/compressible/rhoPimpleFoam/createFields.H @@ -42,6 +42,8 @@ volVectorField U pressureControl pressureControl(p, rho, pimple.dict(), false); +mesh.setFluxRequired(p.name()); + Info<< "Creating turbulence model\n" << endl; autoPtr turbulence ( @@ -54,8 +56,6 @@ autoPtr turbulence ) ); -mesh.setFluxRequired(p.name()); - Info<< "Creating field dpdt\n" << endl; volScalarField dpdt ( diff --git a/applications/solvers/compressible/rhoPimpleFoam/pEqn.H b/applications/solvers/compressible/rhoPimpleFoam/pEqn.H index 9eecd01d99..83eeb8fc68 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/pEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/pEqn.H @@ -1,4 +1,11 @@ -rho = thermo.rho(); +if (!pimple.SIMPLErho()) +{ + rho = thermo.rho(); +} + +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); volScalarField rAU(1.0/UEqn.A()); surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); @@ -31,17 +38,17 @@ if (pimple.transonic()) phiHbyA -= fvc::interpolate(psi*p)*phiHbyA/fvc::interpolate(rho); + fvScalarMatrix pDDtEqn + ( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phiHbyA) + fvm::div(phid, p) + == + fvOptions(psi, p, rho.name()) + ); + while (pimple.correctNonOrthogonal()) { - fvScalarMatrix pEqn - ( - fvm::ddt(psi, p) - + fvc::div(phiHbyA) - + fvm::div(phid, p) - - fvm::laplacian(rhorAUf, p) - == - fvOptions(psi, p, rho.name()) - ); + fvScalarMatrix pEqn(pDDtEqn - fvm::laplacian(rhorAUf, p)); // Relax the pressure equation to ensure diagonal-dominance pEqn.relax(); @@ -56,16 +63,17 @@ if (pimple.transonic()) } else { + fvScalarMatrix pDDtEqn + ( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phiHbyA) + == + fvOptions(psi, p, rho.name()) + ); + while (pimple.correctNonOrthogonal()) { - fvScalarMatrix pEqn - ( - fvm::ddt(psi, p) - + fvc::div(phiHbyA) - - fvm::laplacian(rhorAUf, p) - == - fvOptions(psi, p, rho.name()) - ); + fvScalarMatrix pEqn(pDDtEqn - fvm::laplacian(rhorAUf, p)); pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); @@ -76,6 +84,9 @@ else } } +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + #include "rhoEqn.H" #include "compressibleContinuityErrs.H" @@ -92,10 +103,9 @@ if (pressureControl.limit(p)) p.correctBoundaryConditions(); rho = thermo.rho(); } - -if (!pimple.transonic()) +else if (pimple.SIMPLErho()) { - rho.relax(); + rho = thermo.rho(); } if (thermo.dpdt()) diff --git a/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H b/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H index 34657a1892..e9b849bc05 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/pcEqn.H @@ -1,4 +1,11 @@ -rho = thermo.rho(); +if (!pimple.SIMPLErho()) +{ + rho = thermo.rho(); +} + +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); volScalarField rAU(1.0/UEqn.A()); volScalarField rAtU(1.0/(1.0/rAU - UEqn.H1())); @@ -39,17 +46,17 @@ if (pimple.transonic()) HbyA -= (rAU - rAtU)*fvc::grad(p); + fvScalarMatrix pDDtEqn + ( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phiHbyA) + fvm::div(phid, p) + == + fvOptions(psi, p, rho.name()) + ); + while (pimple.correctNonOrthogonal()) { - fvScalarMatrix pEqn - ( - fvm::ddt(psi, p) - + fvc::div(phiHbyA) - + fvm::div(phid, p) - - fvm::laplacian(rhorAtU, p) - == - fvOptions(psi, p, rho.name()) - ); + fvScalarMatrix pEqn(pDDtEqn - fvm::laplacian(rhorAtU, p)); // Relax the pressure equation to ensure diagonal-dominance pEqn.relax(); @@ -67,16 +74,17 @@ else phiHbyA += fvc::interpolate(rho*(rAtU - rAU))*fvc::snGrad(p)*mesh.magSf(); HbyA -= (rAU - rAtU)*fvc::grad(p); + fvScalarMatrix pDDtEqn + ( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phiHbyA) + == + fvOptions(psi, p, rho.name()) + ); + while (pimple.correctNonOrthogonal()) { - fvScalarMatrix pEqn - ( - fvm::ddt(psi, p) - + fvc::div(phiHbyA) - - fvm::laplacian(rhorAtU, p) - == - fvOptions(psi, p, rho.name()) - ); + fvScalarMatrix pEqn(pDDtEqn - fvm::laplacian(rhorAtU, p)); pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); @@ -87,6 +95,9 @@ else } } +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + #include "rhoEqn.H" #include "compressibleContinuityErrs.H" @@ -103,10 +114,9 @@ if (pressureControl.limit(p)) p.correctBoundaryConditions(); rho = thermo.rho(); } - -if (!pimple.transonic()) +else if (pimple.SIMPLErho()) { - rho.relax(); + rho = thermo.rho(); } if (thermo.dpdt()) diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H index 1540f601c1..ed802ba6d2 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleDyMFoam/pEqn.H @@ -36,7 +36,7 @@ if (pimple.transonic()) { fvScalarMatrix pEqn ( - fvm::ddt(psi, p) + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + fvc::div(phiHbyA) + fvm::div(phid, p) - fvm::laplacian(rhorAUf, p) @@ -62,7 +62,7 @@ else // Pressure corrector fvScalarMatrix pEqn ( - fvm::ddt(psi, p) + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + fvc::div(phiHbyA) - fvm::laplacian(rhorAUf, p) == @@ -95,11 +95,6 @@ if (pressureControl.limit(p)) rho = thermo.rho(); } -if (!pimple.transonic()) -{ - rho.relax(); -} - { rhoUf = fvc::interpolate(rho*U); surfaceVectorField n(mesh.Sf()/mesh.magSf()); diff --git a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C index 0fbe7717e3..5d5ed3f5f4 100644 --- a/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C +++ b/applications/solvers/compressible/rhoPimpleFoam/rhoPimpleFoam.C @@ -122,6 +122,8 @@ int main(int argc, char *argv[]) } } + rho = thermo.rho(); + runTime.write(); Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" diff --git a/applications/solvers/heatTransfer/buoyantPimpleFoam/pEqn.H b/applications/solvers/heatTransfer/buoyantPimpleFoam/pEqn.H index 15c87f9c85..c097118753 100644 --- a/applications/solvers/heatTransfer/buoyantPimpleFoam/pEqn.H +++ b/applications/solvers/heatTransfer/buoyantPimpleFoam/pEqn.H @@ -1,115 +1,74 @@ +rho = thermo.rho(); + +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); + +volScalarField rAU(1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh)); + +surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); + +surfaceScalarField phiHbyA +( + "phiHbyA", + ( + fvc::flux(rho*HbyA) + + rhorAUf*fvc::ddtCorr(rho, U, phi) + ) + + phig +); + +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); + +fvScalarMatrix p_rghDDtEqn +( + fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) + + fvc::div(phiHbyA) + == + fvOptions(psi, p_rgh, rho.name()) +); + +while (pimple.correctNonOrthogonal()) { - bool closedVolume = p_rgh.needReference(); - - dimensionedScalar compressibility = fvc::domainIntegrate(psi); - bool compressible = (compressibility.value() > SMALL); - - rho = thermo.rho(); - - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p_rgh; - - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh)); - - surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); - - surfaceScalarField phiHbyA + fvScalarMatrix p_rghEqn ( - "phiHbyA", - ( - fvc::flux(rho*HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi) - ) - + phig + p_rghDDtEqn + - fvm::laplacian(rhorAUf, p_rgh) ); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter()))); - // Update the pressure BCs to ensure flux consistency - constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); - - tmp p_rghDDtEqn - ( - new fvScalarMatrix(p_rgh, dimMass/dimTime) - ); - - if (compressible) + if (pimple.finalNonOrthogonalIter()) { - p_rghDDtEqn = - ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) - ); + // Calculate the conservative fluxes + phi = phiHbyA + p_rghEqn.flux(); + + // Explicitly relax pressure for momentum corrector + p_rgh.relax(); + + // Correct the momentum source with the pressure gradient flux + // calculated from the relaxed pressure + U = HbyA + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); + U.correctBoundaryConditions(); + fvOptions.correct(U); + K = 0.5*magSqr(U); } - - while (pimple.correctNonOrthogonal()) - { - fvScalarMatrix p_rghEqn - ( - p_rghDDtEqn() - + fvc::div(phiHbyA) - - fvm::laplacian(rhorAUf, p_rgh) - == - fvOptions(psi, p_rgh, rho.name()) - ); - - p_rghEqn.solve(mesh.solver(p_rgh.select(pimple.finalInnerIter()))); - - if (pimple.finalNonOrthogonalIter()) - { - // Calculate the conservative fluxes - phi = phiHbyA + p_rghEqn.flux(); - - // Explicitly relax pressure for momentum corrector - p_rgh.relax(); - - // Correct the momentum source with the pressure gradient flux - // calculated from the relaxed pressure - U = HbyA + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); - U.correctBoundaryConditions(); - fvOptions.correct(U); - K = 0.5*magSqr(U); - } - } - - p = p_rgh + rho*gh; - - // Second part of thermodynamic density update - thermo.rho() += psi*p_rgh; - - if (thermo.dpdt()) - { - dpdt = fvc::ddt(p); - } - - if (compressible) - { - #include "rhoEqn.H" - } - #include "compressibleContinuityErrs.H" - - if (closedVolume) - { - if (!compressible) - { - p += dimensionedScalar - ( - "p", - p.dimensions(), - pRefValue - getRefCellValue(p, pRefCell) - ); - } - else - { - p += (initialMass - fvc::domainIntegrate(thermo.rho())) - /compressibility; - rho = thermo.rho(); - } - p_rgh = p - rho*gh; - } - - Info<< "rho max/min : " << max(rho).value() << " " << min(rho).value() - << endl; } + +p = p_rgh + rho*gh; + +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + +if (thermo.dpdt()) +{ + dpdt = fvc::ddt(p); +} + +#include "rhoEqn.H" +#include "compressibleContinuityErrs.H" diff --git a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H index 09d90906c0..bd955882b1 100644 --- a/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H +++ b/applications/solvers/heatTransfer/chtMultiRegionFoam/fluid/pEqn.H @@ -1,114 +1,100 @@ +bool closedVolume = p_rgh.needReference(); +dimensionedScalar compressibility = fvc::domainIntegrate(psi); +bool compressible = (compressibility.value() > SMALL); + +rho = thermo.rho(); + +volScalarField rAU("rAU", 1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh)); + +surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); + +surfaceScalarField phiHbyA +( + "phiHbyA", + ( + fvc::flux(rho*HbyA) + + rhorAUf*fvc::ddtCorr(rho, U, phi) + ) + + phig +); + +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); + { - bool closedVolume = p_rgh.needReference(); - dimensionedScalar compressibility = fvc::domainIntegrate(psi); - bool compressible = (compressibility.value() > SMALL); - - rho = thermo.rho(); - - volScalarField rAU("rAU", 1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p_rgh)); - - surfaceScalarField phig(-rhorAUf*ghf*fvc::snGrad(rho)*mesh.magSf()); - - surfaceScalarField phiHbyA + fvScalarMatrix p_rghDDtEqn ( - "phiHbyA", - ( - fvc::flux(rho*HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi) - ) - + phig + fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) + + fvc::div(phiHbyA) ); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); - - // Update the pressure BCs to ensure flux consistency - constrainPressure(p_rgh, rho, U, phiHbyA, rhorAUf, MRF); - - tmp p_rghDDtEqn - ( - new fvScalarMatrix(p_rgh, dimMass/dimTime) - ); + // Thermodynamic density needs to be updated by psi*d(p) after the + // pressure solution + const volScalarField psip0(psi*p); + for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) { - if (compressible) - { - p_rghDDtEqn = - ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p_rgh)) - == - fvOptions(psi, p_rgh, rho.name()) - ); - } + fvScalarMatrix p_rghEqn + ( + p_rghDDtEqn + - fvm::laplacian(rhorAUf, p_rgh) + ); - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p_rgh; - - for (int nonOrth=0; nonOrth<=nNonOrthCorr; nonOrth++) - { - fvScalarMatrix p_rghEqn + solvPerfp_rgh = p_rghEqn.solve + ( + mesh.solver ( - p_rghDDtEqn() - + fvc::div(phiHbyA) - - fvm::laplacian(rhorAUf, p_rgh) - ); - - p_rghEqn.solve - ( - mesh.solver + p_rgh.select ( - p_rgh.select ( - ( - oCorr == nOuterCorr-1 - && corr == nCorr-1 - && nonOrth == nNonOrthCorr - ) + oCorr == nOuterCorr-1 + && corr == nCorr-1 + && nonOrth == nNonOrthCorr ) ) - ); + ) + ); - if (nonOrth == nNonOrthCorr) - { - phi = phiHbyA + p_rghEqn.flux(); - U = HbyA - + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); - U.correctBoundaryConditions(); - fvOptions.correct(U); - K = 0.5*magSqr(U); - } + if (nonOrth == nNonOrthCorr) + { + phi = phiHbyA + p_rghEqn.flux(); + U = HbyA + + rAU*fvc::reconstruct((phig + p_rghEqn.flux())/rhorAUf); + U.correctBoundaryConditions(); + fvOptions.correct(U); + K = 0.5*magSqr(U); } - - // Second part of thermodynamic density update - thermo.rho() += psi*p_rgh; } p = p_rgh + rho*gh; - // Update pressure time derivative if needed - if (thermo.dpdt()) - { - dpdt = fvc::ddt(p); - } - - if (compressible) - { - // Solve continuity - #include "rhoEqn.H" - } - - // Update continuity errors - #include "compressibleContinuityErrors.H" - - // For closed-volume cases adjust the pressure and density levels - // to obey overall mass continuity - if (closedVolume && compressible) - { - p += (initialMass - fvc::domainIntegrate(thermo.rho())) - /compressibility; - rho = thermo.rho(); - p_rgh = p - rho*gh; - } + // Thermodynamic density update + thermo.correctRho(psi*p - psip0); +} + + +// Update pressure time derivative if needed +if (thermo.dpdt()) +{ + dpdt = fvc::ddt(p); +} + +// Solve continuity +#include "rhoEqn.H" + +// Update continuity errors +#include "compressibleContinuityErrors.H" + +// For closed-volume cases adjust the pressure and density levels +// to obey overall mass continuity +if (closedVolume && compressible) +{ + p += (initialMass - fvc::domainIntegrate(thermo.rho())) + /compressibility; + rho = thermo.rho(); + p_rgh = p - rho*gh; } diff --git a/applications/solvers/lagrangian/coalChemistryFoam/coalChemistryFoam.C b/applications/solvers/lagrangian/coalChemistryFoam/coalChemistryFoam.C index 544cccdae2..c7ea95929c 100644 --- a/applications/solvers/lagrangian/coalChemistryFoam/coalChemistryFoam.C +++ b/applications/solvers/lagrangian/coalChemistryFoam/coalChemistryFoam.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -42,6 +42,7 @@ Description #include "radiationModel.H" #include "SLGThermo.H" #include "pimpleControl.H" +#include "pressureControl.H" #include "localEulerDdtScheme.H" #include "fvcSmooth.H" diff --git a/applications/solvers/lagrangian/reactingParcelFoam/pEqn.H b/applications/solvers/lagrangian/reactingParcelFoam/pEqn.H index f6c8ceec21..f2cb294718 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/pEqn.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/pEqn.H @@ -1,73 +1,71 @@ +rho = thermo.rho(); + +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); + +volScalarField rAU(1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); +surfaceScalarField phiHbyA +( + "phiHbyA", + ( + fvc::flux(rho*HbyA) + + rhorAUf*fvc::ddtCorr(rho, U, phi) + ) +); + +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); + +fvScalarMatrix pDDtEqn +( + fvc::ddt(rho) + psi*correction(fvm::ddt(p)) + + fvc::div(phiHbyA) + == + parcels.Srho() + + fvOptions(psi, p, rho.name()) +); + +while (pimple.correctNonOrthogonal()) { - rho = thermo.rho(); - - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p; - - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); - surfaceScalarField phiHbyA + fvScalarMatrix pEqn ( - "phiHbyA", - ( - fvc::flux(rho*HbyA) - + rhorAUf*fvc::ddtCorr(rho, U, phi) - ) + pDDtEqn + - fvm::laplacian(rhorAUf, p) ); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); - // Update the pressure BCs to ensure flux consistency - constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); - - fvScalarMatrix pDDtEqn - ( - fvc::ddt(rho) + psi*correction(fvm::ddt(p)) - + fvc::div(phiHbyA) - == - parcels.Srho() - + fvOptions(psi, p, rho.name()) - ); - - while (pimple.correctNonOrthogonal()) + if (pimple.finalNonOrthogonalIter()) { - fvScalarMatrix pEqn - ( - pDDtEqn - - fvm::laplacian(rhorAUf, p) - ); - - pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); - - if (pimple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } + phi = phiHbyA + pEqn.flux(); } - - p.relax(); - - // Second part of thermodynamic density update - thermo.rho() += psi*p; - - #include "rhoEqn.H" // NOTE: flux and time scales now inconsistent - #include "compressibleContinuityErrs.H" - - U = HbyA - rAU*fvc::grad(p); - U.correctBoundaryConditions(); - fvOptions.correct(U); - K = 0.5*magSqr(U); - - if (thermo.dpdt()) - { - dpdt = fvc::ddt(p); - } - - rho = thermo.rho(); - rho = max(rho, rhoMin); - rho = min(rho, rhoMax); - - Info<< "p min/max = " << min(p).value() << ", " << max(p).value() << endl; } + +p.relax(); + +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + +#include "rhoEqn.H" // NOTE: flux and time scales now inconsistent +#include "compressibleContinuityErrs.H" + +U = HbyA - rAU*fvc::grad(p); +U.correctBoundaryConditions(); +fvOptions.correct(U); +K = 0.5*magSqr(U); + +if (thermo.dpdt()) +{ + dpdt = fvc::ddt(p); +} + +rho = thermo.rho(); +rho = max(rho, rhoMin); +rho = min(rho, rhoMax); + +Info<< "p min/max = " << min(p).value() << ", " << max(p).value() << endl; diff --git a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/pEqn.H b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/pEqn.H index 055eff6f0b..1ce5db0ec8 100644 --- a/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/pEqn.H +++ b/applications/solvers/lagrangian/reactingParcelFoam/simpleReactingParcelFoam/pEqn.H @@ -1,57 +1,55 @@ -{ - // Thermodynamic density needs to be updated by psi*d(p) after the - // pressure solution - done in 2 parts. Part 1: - thermo.rho() -= psi*p; +// Thermodynamic density needs to be updated by psi*d(p) after the +// pressure solution +const volScalarField psip0(psi*p); - volScalarField rAU(1.0/UEqn.A()); - surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); - volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); - tUEqn.clear(); - surfaceScalarField phiHbyA +volScalarField rAU(1.0/UEqn.A()); +surfaceScalarField rhorAUf("rhorAUf", fvc::interpolate(rho*rAU)); +volVectorField HbyA(constrainHbyA(rAU*UEqn.H(), U, p)); +tUEqn.clear(); +surfaceScalarField phiHbyA +( + "phiHbyA", + fvc::interpolate(rho)*fvc::flux(HbyA) +); + +MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + +// Update the pressure BCs to ensure flux consistency +constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); + +while (simple.correctNonOrthogonal()) +{ + fvScalarMatrix pEqn ( - "phiHbyA", - fvc::interpolate(rho)*fvc::flux(HbyA) + fvc::div(phiHbyA) + - fvm::laplacian(rhorAUf, p) + == + parcels.Srho() + + fvOptions(psi, p, rho.name()) ); - MRF.makeRelative(fvc::interpolate(rho), phiHbyA); + pEqn.solve(); - // Update the pressure BCs to ensure flux consistency - constrainPressure(p, rho, U, phiHbyA, rhorAUf, MRF); - - while (simple.correctNonOrthogonal()) + if (simple.finalNonOrthogonalIter()) { - fvScalarMatrix pEqn - ( - fvc::div(phiHbyA) - - fvm::laplacian(rhorAUf, p) - == - parcels.Srho() - + fvOptions(psi, p, rho.name()) - ); - - pEqn.solve(); - - if (simple.finalNonOrthogonalIter()) - { - phi = phiHbyA + pEqn.flux(); - } + phi = phiHbyA + pEqn.flux(); } - - p.relax(); - - // Second part of thermodynamic density update - thermo.rho() += psi*p; - - #include "compressibleContinuityErrs.H" - - U = HbyA - rAU*fvc::grad(p); - U.correctBoundaryConditions(); - fvOptions.correct(U); - - rho = thermo.rho(); - rho = max(rho, rhoMin); - rho = min(rho, rhoMax); - rho.relax(); - - Info<< "p min/max = " << min(p).value() << ", " << max(p).value() << endl; } + +p.relax(); + +// Thermodynamic density update +thermo.correctRho(psi*p - psip0); + +#include "compressibleContinuityErrs.H" + +U = HbyA - rAU*fvc::grad(p); +U.correctBoundaryConditions(); +fvOptions.correct(U); + +rho = thermo.rho(); +rho = max(rho, rhoMin); +rho = min(rho, rhoMax); +rho.relax(); + +Info<< "p min/max = " << min(p).value() << ", " << max(p).value() << endl; diff --git a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/pEqn.H b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/pEqn.H index 7cd3875e85..e84c19453f 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/pEqn.H +++ b/applications/solvers/multiphase/compressibleInterFoam/compressibleInterDyMFoam/pEqn.H @@ -104,8 +104,8 @@ } // Update densities from change in p_rgh - rho1 += psi1*(p_rgh - p_rgh_0); - rho2 += psi2*(p_rgh - p_rgh_0); + mixture.thermo1().correctRho(psi1*(p_rgh - p_rgh_0)); + mixture.thermo2().correctRho(psi2*(p_rgh - p_rgh_0)); rho = alpha1*rho1 + alpha2*rho2; diff --git a/applications/solvers/multiphase/compressibleInterFoam/createFields.H b/applications/solvers/multiphase/compressibleInterFoam/createFields.H index 46168e6b87..0616b80ea8 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/createFields.H +++ b/applications/solvers/multiphase/compressibleInterFoam/createFields.H @@ -38,8 +38,8 @@ volScalarField& alpha2(mixture.alpha2()); Info<< "Reading thermophysical properties\n" << endl; -volScalarField& rho1 = mixture.thermo1().rho(); -volScalarField& rho2 = mixture.thermo2().rho(); +const volScalarField& rho1 = mixture.thermo1().rho(); +const volScalarField& rho2 = mixture.thermo2().rho(); volScalarField rho ( diff --git a/applications/solvers/multiphase/compressibleInterFoam/pEqn.H b/applications/solvers/multiphase/compressibleInterFoam/pEqn.H index 51c58ba536..93412c9dba 100644 --- a/applications/solvers/multiphase/compressibleInterFoam/pEqn.H +++ b/applications/solvers/multiphase/compressibleInterFoam/pEqn.H @@ -104,8 +104,8 @@ } // Update densities from change in p_rgh - rho1 += psi1*(p_rgh - p_rgh_0); - rho2 += psi2*(p_rgh - p_rgh_0); + mixture.thermo1().correctRho(psi1*(p_rgh - p_rgh_0)); + mixture.thermo2().correctRho(psi2*(p_rgh - p_rgh_0)); rho = alpha1*rho1 + alpha2*rho2; diff --git a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C index e500ab7587..6d031f05b6 100644 --- a/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C +++ b/src/finiteVolume/cfdTools/general/solutionControl/pimpleControl/pimpleControl.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2017 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -45,6 +45,7 @@ void Foam::pimpleControl::read() solveFlow_ = pimpleDict.lookupOrDefault("solveFlow", true); nCorrPIMPLE_ = pimpleDict.lookupOrDefault