diff --git a/applications/test/RhoPimpleFoam/EEqn.H b/applications/test/RhoPimpleFoam/EEqn.H new file mode 100644 index 0000000000000000000000000000000000000000..9972bdfff7b295d03e939b29996330d22c832a4e --- /dev/null +++ b/applications/test/RhoPimpleFoam/EEqn.H @@ -0,0 +1,33 @@ +{ + volScalarField& he = thermo.he(); + + fvScalarMatrix EEqn + ( + fvm::ddt(rho, he) + fvm::div(phi, he) + + fvc::ddt(rho, K) + fvc::div(phi, K) + + ( + he.name() == "e" + ? fvc::div + ( + fvc::absolute(phi/fvc::interpolate(rho), U), + p, + "div(phiv,p)" + ) + : -dpdt + ) + //- fvm::laplacian(turbulence->alphaEff(), he) + - fvm::laplacian(turbulence->muEff(), he) + == + fvOptions(rho, he) + ); + + EEqn.relax(); + + fvOptions.constrain(EEqn); + + EEqn.solve(); + + fvOptions.correct(he); + + thermo.correct(); +} diff --git a/applications/test/RhoPimpleFoam/Make/files b/applications/test/RhoPimpleFoam/Make/files new file mode 100644 index 0000000000000000000000000000000000000000..087a67d2136b2dcc3ca9580c4af54021e0244e17 --- /dev/null +++ b/applications/test/RhoPimpleFoam/Make/files @@ -0,0 +1,3 @@ +rhoPimpleFoam.C + +EXE = $(FOAM_USER_APPBIN)/RhoPimpleFoam diff --git a/applications/test/RhoPimpleFoam/Make/options b/applications/test/RhoPimpleFoam/Make/options new file mode 100644 index 0000000000000000000000000000000000000000..cc667ece05958b37358e128065b7fa0c25f65c49 --- /dev/null +++ b/applications/test/RhoPimpleFoam/Make/options @@ -0,0 +1,20 @@ +EXE_INC = \ + -I$(LIB_SRC)/TurbulenceModels/turbulenceModel/lnInclude \ + -I$(LIB_SRC)/TurbulenceModels/compressible/lnInclude \ + -I$(LIB_SRC)/thermophysicalModels/basic/lnInclude \ + -I$(LIB_SRC)/finiteVolume/cfdTools \ + -I$(LIB_SRC)/finiteVolume/lnInclude \ + -I$(LIB_SRC)/meshTools/lnInclude \ + -I$(LIB_SRC)/sampling/lnInclude \ + -I$(LIB_SRC)/fvOptions/lnInclude + +EXE_LIBS = \ + -lfluidThermophysicalModels \ + -lspecie \ + -lturbulenceModels \ + -lcompressibleTurbulenceModels \ + -lincompressibleTransportModels \ + -lfiniteVolume \ + -lmeshTools \ + -lsampling \ + -lfvOptions diff --git a/applications/test/RhoPimpleFoam/UEqn.H b/applications/test/RhoPimpleFoam/UEqn.H new file mode 100644 index 0000000000000000000000000000000000000000..1adabbc1f09d365005cd7d09e0663f1052702160 --- /dev/null +++ b/applications/test/RhoPimpleFoam/UEqn.H @@ -0,0 +1,22 @@ +// Solve the Momentum equation + +tmp<fvVectorMatrix> UEqn +( + fvm::ddt(rho, U) + + fvm::div(phi, U) + + turbulence->divDevRhoReff(U) + == + fvOptions(rho, U) +); + +UEqn().relax(); + +fvOptions.constrain(UEqn()); + +if (pimple.momentumPredictor()) +{ + solve(UEqn() == -fvc::grad(p)); + + fvOptions.correct(U); + K = 0.5*magSqr(U); +} diff --git a/applications/test/RhoPimpleFoam/createFields.H b/applications/test/RhoPimpleFoam/createFields.H new file mode 100644 index 0000000000000000000000000000000000000000..3a94360376f5c53578494fdbd0b3d686593e9c30 --- /dev/null +++ b/applications/test/RhoPimpleFoam/createFields.H @@ -0,0 +1,73 @@ + Info<< "Reading thermophysical properties\n" << endl; + + autoPtr<psiThermo> pThermo + ( + psiThermo::New(mesh) + ); + psiThermo& thermo = pThermo(); + thermo.validate(args.executable(), "h", "e"); + + volScalarField& p = thermo.p(); + const volScalarField& psi = thermo.psi(); + + volScalarField rho + ( + IOobject + ( + "rho", + runTime.timeName(), + mesh, + IOobject::READ_IF_PRESENT, + IOobject::AUTO_WRITE + ), + thermo.rho() + ); + + Info<< "Reading field U\n" << endl; + volVectorField U + ( + IOobject + ( + "U", + runTime.timeName(), + mesh, + IOobject::MUST_READ, + IOobject::AUTO_WRITE + ), + mesh + ); + + #include "compressibleCreatePhi.H" + + dimensionedScalar rhoMax(pimple.dict().lookup("rhoMax")); + dimensionedScalar rhoMin(pimple.dict().lookup("rhoMin")); + + Info<< "Creating turbulence model\n" << endl; + + autoPtr<CompressibleTurbulenceModel<fluidThermo> > + turbulence + ( + CompressibleTurbulenceModel<fluidThermo>::New + ( + rho, + U, + phi, + thermo + ) + ); + + Info<< "Creating field dpdt\n" << endl; + volScalarField dpdt + ( + IOobject + ( + "dpdt", + runTime.timeName(), + mesh + ), + mesh, + dimensionedScalar("dpdt", p.dimensions()/dimTime, 0) + ); + + Info<< "Creating field kinetic energy K\n" << endl; + volScalarField K("K", 0.5*magSqr(U)); diff --git a/applications/test/RhoPimpleFoam/pEqn.H b/applications/test/RhoPimpleFoam/pEqn.H new file mode 100644 index 0000000000000000000000000000000000000000..78f4ddb0316da812837722fde3d8baba8540512b --- /dev/null +++ b/applications/test/RhoPimpleFoam/pEqn.H @@ -0,0 +1,113 @@ +rho = thermo.rho(); +rho = max(rho, rhoMin); +rho = min(rho, rhoMax); +rho.relax(); + +volScalarField rAU(1.0/UEqn().A()); +volVectorField HbyA("HbyA", U); +HbyA = rAU*UEqn().H(); + +if (pimple.nCorrPISO() <= 1) +{ + UEqn.clear(); +} + +if (pimple.transonic()) +{ + surfaceScalarField phid + ( + "phid", + fvc::interpolate(psi) + *( + (fvc::interpolate(HbyA) & mesh.Sf()) + + fvc::ddtPhiCorr(rAU, rho, U, phi) + ) + ); + + fvOptions.relativeFlux(fvc::interpolate(psi), phid); + + volScalarField Dp("Dp", rho*rAU); + + while (pimple.correctNonOrthogonal()) + { + fvScalarMatrix pEqn + ( + fvm::ddt(psi, p) + + fvm::div(phid, p) + - fvm::laplacian(Dp, p) + == + fvOptions(psi, p, rho.name()) + ); + + fvOptions.constrain(pEqn); + + pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); + + if (pimple.finalNonOrthogonalIter()) + { + phi == pEqn.flux(); + } + } +} +else +{ + surfaceScalarField phiHbyA + ( + "phiHbyA", + fvc::interpolate(rho) + *( + (fvc::interpolate(HbyA) & mesh.Sf()) + + fvc::ddtPhiCorr(rAU, rho, U, phi) + ) + ); + + fvOptions.relativeFlux(fvc::interpolate(rho), phiHbyA); + + volScalarField Dp("Dp", rho*rAU); + + while (pimple.correctNonOrthogonal()) + { + // Pressure corrector + fvScalarMatrix pEqn + ( + fvm::ddt(psi, p) + + fvc::div(phiHbyA) + - fvm::laplacian(Dp, p) + == + fvOptions(psi, p, rho.name()) + ); + + fvOptions.constrain(pEqn); + + pEqn.solve(mesh.solver(p.select(pimple.finalInnerIter()))); + + if (pimple.finalNonOrthogonalIter()) + { + phi = phiHbyA + pEqn.flux(); + } + } +} + +#include "rhoEqn.H" +#include "compressibleContinuityErrs.H" + +// 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 (thermo.dpdt()) +{ + dpdt = fvc::ddt(p); +} diff --git a/applications/test/RhoPimpleFoam/rhoPimpleFoam.C b/applications/test/RhoPimpleFoam/rhoPimpleFoam.C new file mode 100644 index 0000000000000000000000000000000000000000..2a17c938f44b72fc32fc89f6149327d64bf77ebd --- /dev/null +++ b/applications/test/RhoPimpleFoam/rhoPimpleFoam.C @@ -0,0 +1,107 @@ +/*---------------------------------------------------------------------------*\ + ========= | + \\ / F ield | OpenFOAM: The Open Source CFD Toolbox + \\ / O peration | + \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\/ M anipulation | +------------------------------------------------------------------------------- +License + This file is part of OpenFOAM. + + OpenFOAM is free software: you can redistribute it and/or modify it + under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + OpenFOAM is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. + +Application + rhoPimpleFoam + +Description + Transient solver for laminar or turbulent flow of compressible fluids + for HVAC and similar applications. + + Uses the flexible PIMPLE (PISO-SIMPLE) solution for time-resolved and + pseudo-transient simulations. + +\*---------------------------------------------------------------------------*/ + +#include "fvCFD.H" +#include "psiThermo.H" +#include "CompressibleTurbulenceModel.H" +#include "bound.H" +#include "pimpleControl.H" +#include "fvIOoptionList.H" + +// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + +int main(int argc, char *argv[]) +{ + #include "setRootCase.H" + #include "createTime.H" + #include "createMesh.H" + + pimpleControl pimple(mesh); + + #include "createFields.H" + #include "createFvOptions.H" + #include "initContinuityErrs.H" + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // + + Info<< "\nStarting time loop\n" << endl; + + while (runTime.run()) + { + #include "readTimeControls.H" + #include "compressibleCourantNo.H" + #include "setDeltaT.H" + + runTime++; + + Info<< "Time = " << runTime.timeName() << nl << endl; + + if (pimple.nCorrPIMPLE() <= 1) + { + #include "rhoEqn.H" + } + + // --- Pressure-velocity PIMPLE corrector loop + while (pimple.loop()) + { + #include "UEqn.H" + #include "EEqn.H" + + // --- Pressure corrector loop + while (pimple.correct()) + { + #include "pEqn.H" + } + + if (pimple.turbCorr()) + { + turbulence->correct(); + } + } + + runTime.write(); + + Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s" + << " ClockTime = " << runTime.elapsedClockTime() << " s" + << nl << endl; + } + + Info<< "End\n" << endl; + + return 0; +} + + +// ************************************************************************* //