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

rhopSonicFoam.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     rhopSonicFoam
00027 
00028 Description
00029     Pressure-density-based compressible flow solver.
00030 
00031 \*---------------------------------------------------------------------------*/
00032 
00033 #include "fvCFD.H"
00034 #include "weighted.H"
00035 #include "gaussConvectionScheme.H"
00036 #include "multivariateGaussConvectionScheme.H"
00037 #include "MUSCL.H"
00038 #include "LimitedScheme.H"
00039 #include "boundaryTypes.H"
00040 
00041 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00042 
00043 int main(int argc, char *argv[])
00044 {
00045     #include "setRootCase.H"
00046     #include "createTime.H"
00047     #include "createMesh.H"
00048     #include "readThermodynamicProperties.H"
00049     #include "createFields.H"
00050 
00051     // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00052 
00053     Info<< "\nStarting time loop\n" << endl;
00054 
00055     while (runTime.loop())
00056     {
00057         Info<< "Time = " << runTime.value() << nl << endl;
00058 
00059         #include "readPISOControls.H"
00060         scalar HbyAblend = readScalar(piso.lookup("HbyAblend"));
00061 
00062         #include "readTimeControls.H"
00063 
00064         scalar CoNum = max
00065         (
00066             mesh.surfaceInterpolation::deltaCoeffs()
00067            *mag(phiv)/mesh.magSf()
00068         ).value()*runTime.deltaT().value();
00069 
00070         Info<< "Max Courant Number = " << CoNum << endl;
00071 
00072         #include "setDeltaT.H"
00073 
00074         for (int outerCorr=0; outerCorr<nOuterCorr; outerCorr++)
00075         {
00076             magRhoU = mag(rhoU);
00077             H = (rhoE + p)/rho;
00078 
00079             fv::multivariateGaussConvectionScheme<scalar> mvConvection
00080             (
00081                 mesh,
00082                 fields,
00083                 phiv,
00084                 mesh.divScheme("div(phiv,rhoUH)")
00085             );
00086 
00087             solve
00088             (
00089                 fvm::ddt(rho)
00090               + mvConvection.fvmDiv(phiv, rho)
00091             );
00092 
00093             surfaceScalarField rhoUWeights =
00094                 mvConvection.interpolationScheme()()(magRhoU)()
00095                .weights(magRhoU);
00096 
00097             weighted<vector> rhoUScheme(rhoUWeights);
00098 
00099             fvVectorMatrix rhoUEqn
00100             (
00101                 fvm::ddt(rhoU)
00102               + fv::gaussConvectionScheme<vector>(mesh, phiv, rhoUScheme)
00103                    .fvmDiv(phiv, rhoU)
00104             );
00105 
00106             solve(rhoUEqn == -fvc::grad(p));
00107 
00108             solve
00109             (
00110                 fvm::ddt(rhoE)
00111               + mvConvection.fvmDiv(phiv, rhoE)
00112              ==
00113               - mvConvection.fvcDiv(phiv, p)
00114             );
00115 
00116             T = (rhoE - 0.5*rho*magSqr(rhoU/rho))/Cv/rho;
00117             psi = 1.0/(R*T);
00118             p = rho/psi;
00119 
00120             for (int corr=0; corr<nCorr; corr++)
00121             {
00122                 volScalarField rrhoUA = 1.0/rhoUEqn.A();
00123                 surfaceScalarField rrhoUAf("rrhoUAf", fvc::interpolate(rrhoUA));
00124                 volVectorField HbyA = rrhoUA*rhoUEqn.H();
00125 
00126                 surfaceScalarField HbyAWeights =
00127                     HbyAblend*mesh.weights()
00128                   + (1.0 - HbyAblend)*
00129                     LimitedScheme
00130                         <vector, MUSCLLimiter<NVDTVD>, limitFuncs::magSqr>
00131                         (mesh, phi, IStringStream("HbyA")()).weights(HbyA);
00132 
00133                 phi =
00134                     (
00135                         surfaceInterpolationScheme<vector>::interpolate
00136                         (HbyA, HbyAWeights) & mesh.Sf()
00137                     )
00138                   + HbyAblend*fvc::ddtPhiCorr(rrhoUA, rho, rhoU, phi);
00139 
00140                 p.boundaryField().updateCoeffs();
00141 
00142                 surfaceScalarField phiGradp =
00143                     rrhoUAf*mesh.magSf()*fvc::snGrad(p);
00144 
00145                 phi -= phiGradp;
00146 
00147                 #include "resetPhiPatches.H"
00148 
00149                 surfaceScalarField rhof =
00150                     mvConvection.interpolationScheme()()(rho)()
00151                    .interpolate(rho);
00152 
00153                 phiv = phi/rhof;
00154 
00155                 fvScalarMatrix pEqn
00156                 (
00157                     fvm::ddt(psi, p)
00158                   + mvConvection.fvcDiv(phiv, rho)
00159                   + fvc::div(phiGradp)
00160                   - fvm::laplacian(rrhoUAf, p)
00161                 );
00162 
00163                 pEqn.solve();
00164 
00165                 phi += phiGradp + pEqn.flux();
00166                 rho = psi*p;
00167                 rhof =
00168                     mvConvection.interpolationScheme()()(rho)()
00169                    .interpolate(rho);
00170                 phiv = phi/rhof;
00171 
00172                 rhoU = HbyA - rrhoUA*fvc::grad(p);
00173                 rhoU.correctBoundaryConditions();
00174             }
00175         }
00176 
00177         U = rhoU/rho;
00178 
00179         runTime.write();
00180 
00181         Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
00182             << "  ClockTime = " << runTime.elapsedClockTime() << " s"
00183             << nl << endl;
00184     }
00185 
00186     Info<< "End\n" << endl;
00187 
00188     return 0;
00189 }
00190 
00191 
00192 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd