1 /*---------------------------------------------------------------------------*\
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
5 \\ / A nd | Copyright (C) 2009-2011 OpenCFD Ltd.
7 -------------------------------------------------------------------------------
9 This file is part of OpenFOAM.
11 OpenFOAM is free software: you can redistribute it and/or modify it
12 under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 You should have received a copy of the GNU General Public License
22 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
28 Density-based compressible flow solver based on central-upwind schemes of
31 \*---------------------------------------------------------------------------*/
34 #include "basicPsiThermo.H"
35 #include "turbulenceModel.H"
36 #include "zeroGradientFvPatchFields.H"
37 #include "fixedRhoFvPatchScalarField.H"
39 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
41 int main(int argc, char *argv[])
43 #include "setRootCase.H"
45 #include "createTime.H"
46 #include "createMesh.H"
47 #include "createFields.H"
48 #include "readThermophysicalProperties.H"
49 #include "readTimeControls.H"
51 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
53 #include "readFluxScheme.H"
55 dimensionedScalar v_zero("v_zero", dimVolume/dimTime, 0.0);
57 Info<< "\nStarting time loop\n" << endl;
61 // --- upwind interpolation of primitive fields on faces
63 surfaceScalarField rho_pos
65 fvc::interpolate(rho, pos, "reconstruct(rho)")
67 surfaceScalarField rho_neg
69 fvc::interpolate(rho, neg, "reconstruct(rho)")
72 surfaceVectorField rhoU_pos
74 fvc::interpolate(rhoU, pos, "reconstruct(U)")
76 surfaceVectorField rhoU_neg
78 fvc::interpolate(rhoU, neg, "reconstruct(U)")
81 volScalarField rPsi(1.0/psi);
82 surfaceScalarField rPsi_pos
84 fvc::interpolate(rPsi, pos, "reconstruct(T)")
86 surfaceScalarField rPsi_neg
88 fvc::interpolate(rPsi, neg, "reconstruct(T)")
91 surfaceScalarField e_pos
93 fvc::interpolate(e, pos, "reconstruct(T)")
95 surfaceScalarField e_neg
97 fvc::interpolate(e, neg, "reconstruct(T)")
100 surfaceVectorField U_pos(rhoU_pos/rho_pos);
101 surfaceVectorField U_neg(rhoU_neg/rho_neg);
103 surfaceScalarField p_pos(rho_pos*rPsi_pos);
104 surfaceScalarField p_neg(rho_neg*rPsi_neg);
106 surfaceScalarField phiv_pos(U_pos & mesh.Sf());
107 surfaceScalarField phiv_neg(U_neg & mesh.Sf());
109 volScalarField c(sqrt(thermo.Cp()/thermo.Cv()*rPsi));
110 surfaceScalarField cSf_pos
112 fvc::interpolate(c, pos, "reconstruct(T)")*mesh.magSf()
114 surfaceScalarField cSf_neg
116 fvc::interpolate(c, neg, "reconstruct(T)")*mesh.magSf()
119 surfaceScalarField ap
121 max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)
123 surfaceScalarField am
125 min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero)
128 surfaceScalarField a_pos(ap/(ap - am));
130 surfaceScalarField amaxSf("amaxSf", max(mag(am), mag(ap)));
132 surfaceScalarField aSf(am*a_pos);
134 if (fluxScheme == "Tadmor")
140 surfaceScalarField a_neg(1.0 - a_pos);
145 surfaceScalarField aphiv_pos(phiv_pos - aSf);
146 surfaceScalarField aphiv_neg(phiv_neg + aSf);
148 // Reuse amaxSf for the maximum positive and negative fluxes
149 // estimated by the central scheme
150 amaxSf = max(mag(aphiv_pos), mag(aphiv_neg));
152 #include "compressibleCourantNo.H"
153 #include "readTimeControls.H"
154 #include "setDeltaT.H"
158 Info<< "Time = " << runTime.timeName() << nl << endl;
160 surfaceScalarField phi("phi", aphiv_pos*rho_pos + aphiv_neg*rho_neg);
162 surfaceVectorField phiUp
164 (aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg)
165 + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf()
168 surfaceScalarField phiEp
170 aphiv_pos*(rho_pos*(e_pos + 0.5*magSqr(U_pos)) + p_pos)
171 + aphiv_neg*(rho_neg*(e_neg + 0.5*magSqr(U_neg)) + p_neg)
172 + aSf*p_pos - aSf*p_neg
175 volScalarField muEff(turbulence->muEff());
176 volTensorField tauMC("tauMC", muEff*dev2(Foam::T(fvc::grad(U))));
179 solve(fvm::ddt(rho) + fvc::div(phi));
181 // --- Solve momentum
182 solve(fvm::ddt(rhoU) + fvc::div(phiUp));
184 U.dimensionedInternalField() =
185 rhoU.dimensionedInternalField()
186 /rho.dimensionedInternalField();
187 U.correctBoundaryConditions();
188 rhoU.boundaryField() = rho.boundaryField()*U.boundaryField();
190 volScalarField rhoBydt(rho/runTime.deltaT());
196 fvm::ddt(rho, U) - fvc::ddt(rho, U)
197 - fvm::laplacian(muEff, U)
204 surfaceScalarField sigmaDotU
207 fvc::interpolate(muEff)*mesh.magSf()*fvc::snGrad(U)
208 + (mesh.Sf() & fvc::interpolate(tauMC))
210 & (a_pos*U_pos + a_neg*U_neg)
217 - fvc::div(sigmaDotU)
220 e = rhoE/rho - 0.5*magSqr(U);
221 e.correctBoundaryConditions();
223 rhoE.boundaryField() =
226 e.boundaryField() + 0.5*magSqr(U.boundaryField())
231 volScalarField k("k", thermo.Cp()*muEff/Pr);
234 fvm::ddt(rho, e) - fvc::ddt(rho, e)
235 - fvm::laplacian(turbulence->alphaEff(), e)
236 + fvc::laplacian(turbulence->alpha(), e)
237 - fvc::laplacian(k, T)
240 rhoE = rho*(e + 0.5*magSqr(U));
243 p.dimensionedInternalField() =
244 rho.dimensionedInternalField()
245 /psi.dimensionedInternalField();
246 p.correctBoundaryConditions();
247 rho.boundaryField() = psi.boundaryField()*p.boundaryField();
249 turbulence->correct();
253 Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
254 << " ClockTime = " << runTime.elapsedClockTime() << " s"
258 Info<< "End\n" << endl;
263 // ************************************************************************* //