OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

rhoCentralFoam.C

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Application
00026     rhoCentralFoam
00027 
00028 Description
00029     Density-based compressible flow solver based on central-upwind schemes of
00030     Kurganov and Tadmor
00031 
00032 \*---------------------------------------------------------------------------*/
00033 
00034 #include "fvCFD.H"
00035 #include "basicPsiThermo.H"
00036 #include "zeroGradientFvPatchFields.H"
00037 #include "fixedRhoFvPatchScalarField.H"
00038 
00039 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00040 
00041 int main(int argc, char *argv[])
00042 {
00043     #include "setRootCase.H"
00044 
00045     #include "createTime.H"
00046     #include "createMesh.H"
00047     #include "createFields.H"
00048     #include "readThermophysicalProperties.H"
00049     #include "readTimeControls.H"
00050 
00051     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053     #include "readFluxScheme.H"
00054 
00055     dimensionedScalar v_zero("v_zero",dimVolume/dimTime, 0.0);
00056 
00057     Info<< "\nStarting time loop\n" << endl;
00058 
00059     while (runTime.run())
00060     {
00061         // --- upwind interpolation of primitive fields on faces
00062 
00063         surfaceScalarField rho_pos =
00064             fvc::interpolate(rho, pos, "reconstruct(rho)");
00065         surfaceScalarField rho_neg =
00066             fvc::interpolate(rho, neg, "reconstruct(rho)");
00067 
00068         surfaceVectorField rhoU_pos =
00069             fvc::interpolate(rhoU, pos, "reconstruct(U)");
00070         surfaceVectorField rhoU_neg =
00071             fvc::interpolate(rhoU, neg, "reconstruct(U)");
00072 
00073         volScalarField rPsi = 1.0/psi;
00074         surfaceScalarField rPsi_pos =
00075             fvc::interpolate(rPsi, pos, "reconstruct(T)");
00076         surfaceScalarField rPsi_neg =
00077             fvc::interpolate(rPsi, neg, "reconstruct(T)");
00078 
00079         surfaceScalarField e_pos =
00080             fvc::interpolate(e, pos, "reconstruct(T)");
00081         surfaceScalarField e_neg =
00082             fvc::interpolate(e, neg, "reconstruct(T)");
00083 
00084         surfaceVectorField U_pos = rhoU_pos/rho_pos;
00085         surfaceVectorField U_neg = rhoU_neg/rho_neg;
00086 
00087         surfaceScalarField p_pos = rho_pos*rPsi_pos;
00088         surfaceScalarField p_neg = rho_neg*rPsi_neg;
00089 
00090         surfaceScalarField phiv_pos = U_pos & mesh.Sf();
00091         surfaceScalarField phiv_neg = U_neg & mesh.Sf();
00092 
00093         volScalarField c = sqrt(thermo.Cp()/thermo.Cv()*rPsi);
00094         surfaceScalarField cSf_pos = fvc::interpolate(c, pos, "reconstruct(T)")*mesh.magSf();
00095         surfaceScalarField cSf_neg = fvc::interpolate(c, neg, "reconstruct(T)")*mesh.magSf();
00096 
00097         surfaceScalarField ap = max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero);
00098         surfaceScalarField am = min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero);
00099 
00100         surfaceScalarField a_pos = ap/(ap - am);
00101 
00102         surfaceScalarField amaxSf("amaxSf", max(mag(am), mag(ap)));
00103 
00104         #include "compressibleCourantNo.H"
00105         #include "readTimeControls.H"
00106         #include "setDeltaT.H"
00107 
00108         runTime++;
00109 
00110         Info<< "Time = " << runTime.timeName() << nl << endl;
00111 
00112         surfaceScalarField aSf = am*a_pos;
00113 
00114         if (fluxScheme == "Tadmor")
00115         {
00116             aSf = -0.5*amaxSf;
00117             a_pos = 0.5;
00118         }
00119 
00120         surfaceScalarField a_neg = (1.0 - a_pos);
00121 
00122         phiv_pos *= a_pos;
00123         phiv_neg *= a_neg;
00124 
00125         surfaceScalarField aphiv_pos = phiv_pos - aSf;
00126         surfaceScalarField aphiv_neg = phiv_neg + aSf;
00127 
00128         surfaceScalarField phi("phi", aphiv_pos*rho_pos + aphiv_neg*rho_neg);
00129 
00130         surfaceVectorField phiUp =
00131             (aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg)
00132           + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf();
00133 
00134         surfaceScalarField phiEp =
00135             aphiv_pos*(rho_pos*(e_pos + 0.5*magSqr(U_pos)) + p_pos)
00136           + aphiv_neg*(rho_neg*(e_neg + 0.5*magSqr(U_neg)) + p_neg)
00137           + aSf*p_pos - aSf*p_neg;
00138 
00139         volTensorField tauMC("tauMC", mu*dev2(fvc::grad(U)().T()));
00140 
00141         // --- Solve density
00142         solve(fvm::ddt(rho) + fvc::div(phi));
00143 
00144         // --- Solve momentum
00145         solve(fvm::ddt(rhoU) + fvc::div(phiUp));
00146 
00147         U.dimensionedInternalField() =
00148             rhoU.dimensionedInternalField()
00149            /rho.dimensionedInternalField();
00150         U.correctBoundaryConditions();
00151         rhoU.boundaryField() = rho.boundaryField()*U.boundaryField();
00152 
00153         volScalarField rhoBydt(rho/runTime.deltaT());
00154 
00155         if (!inviscid)
00156         {
00157             solve
00158             (
00159                 fvm::ddt(rho, U) - fvc::ddt(rho, U)
00160               - fvm::laplacian(mu, U)
00161               - fvc::div(tauMC)
00162             );
00163             rhoU = rho*U;
00164         }
00165 
00166         // --- Solve energy
00167         surfaceScalarField sigmaDotU =
00168         (
00169             (
00170                 fvc::interpolate(mu)*mesh.magSf()*fvc::snGrad(U)
00171               + (mesh.Sf() & fvc::interpolate(tauMC))
00172             )
00173             & (a_pos*U_pos + a_neg*U_neg)
00174         );
00175 
00176         solve
00177         (
00178             fvm::ddt(rhoE)
00179           + fvc::div(phiEp)
00180           - fvc::div(sigmaDotU)
00181         );
00182 
00183         e = rhoE/rho - 0.5*magSqr(U);
00184         e.correctBoundaryConditions();
00185         thermo.correct();
00186         rhoE.boundaryField() =
00187             rho.boundaryField()*
00188             (
00189                 e.boundaryField() + 0.5*magSqr(U.boundaryField())
00190             );
00191 
00192         if (!inviscid)
00193         {
00194             volScalarField k("k", thermo.Cp()*mu/Pr);
00195             solve
00196             (
00197                 fvm::ddt(rho, e) - fvc::ddt(rho, e)
00198               - fvm::laplacian(thermo.alpha(), e)
00199               + fvc::laplacian(thermo.alpha(), e)
00200               - fvc::laplacian(k, T)
00201             );
00202             thermo.correct();
00203             rhoE = rho*(e + 0.5*magSqr(U));
00204         }
00205 
00206         p.dimensionedInternalField() =
00207             rho.dimensionedInternalField()
00208            /psi.dimensionedInternalField();
00209         p.correctBoundaryConditions();
00210         rho.boundaryField() = psi.boundaryField()*p.boundaryField();
00211 
00212         runTime.write();
00213 
00214         Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
00215             << "  ClockTime = " << runTime.elapsedClockTime() << " s"
00216             << nl << endl;
00217     }
00218 
00219     Info<< "End\n" << endl;
00220 
00221     return 0;
00222 }
00223 
00224 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd