rhoCentralFoam.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 Application
27  rhoCentralFoam
28 
29 Group
30  grpCompressibleSolvers
31 
32 Description
33  Density-based compressible flow solver based on central-upwind
34  schemes of Kurganov and Tadmor.
35 
36 \*---------------------------------------------------------------------------*/
37 
38 #include "fvCFD.H"
39 #include "psiThermo.H"
42 #include "directionInterpolate.H"
43 #include "localEulerDdtScheme.H"
44 #include "fvcSmooth.H"
45 
46 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47 
48 int main(int argc, char *argv[])
49 {
50  argList::addNote
51  (
52  "Density-based compressible flow solver based on central-upwind"
53  " schemes of Kurganov and Tadmor."
54  );
55 
56  #define NO_CONTROL
57  #include "postProcess.H"
58 
59  #include "addCheckCaseOptions.H"
60  #include "setRootCaseLists.H"
61  #include "createTime.H"
62  #include "createMesh.H"
63  #include "createFields.H"
64  #include "createFieldRefs.H"
65  #include "createTimeControls.H"
66 
67  turbulence->validate();
68 
69  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
70 
71  #include "readFluxScheme.H"
72 
73  const dimensionedScalar v_zero(dimVolume/dimTime, Zero);
74 
75  // Courant numbers used to adjust the time-step
76  scalar CoNum = 0.0;
77  scalar meanCoNum = 0.0;
78 
79  Info<< "\nStarting time loop\n" << endl;
80 
81  while (runTime.run())
82  {
83  // --- Directed interpolation of primitive fields onto faces
84 
87 
88  surfaceVectorField rhoU_pos(interpolate(rhoU, pos, U.name()));
89  surfaceVectorField rhoU_neg(interpolate(rhoU, neg, U.name()));
90 
91  volScalarField rPsi("rPsi", 1.0/psi);
92  surfaceScalarField rPsi_pos(interpolate(rPsi, pos, T.name()));
93  surfaceScalarField rPsi_neg(interpolate(rPsi, neg, T.name()));
94 
95  surfaceScalarField e_pos(interpolate(e, pos, T.name()));
96  surfaceScalarField e_neg(interpolate(e, neg, T.name()));
97 
98  surfaceVectorField U_pos("U_pos", rhoU_pos/rho_pos);
99  surfaceVectorField U_neg("U_neg", rhoU_neg/rho_neg);
100 
101  surfaceScalarField p_pos("p_pos", rho_pos*rPsi_pos);
102  surfaceScalarField p_neg("p_neg", rho_neg*rPsi_neg);
103 
104  surfaceScalarField phiv_pos("phiv_pos", U_pos & mesh.Sf());
105  // Note: extracted out the orientation so becomes unoriented
106  phiv_pos.setOriented(false);
107  surfaceScalarField phiv_neg("phiv_neg", U_neg & mesh.Sf());
108  phiv_neg.setOriented(false);
109 
110  volScalarField c("c", sqrt(thermo.Cp()/thermo.Cv()*rPsi));
111  surfaceScalarField cSf_pos
112  (
113  "cSf_pos",
114  interpolate(c, pos, T.name())*mesh.magSf()
115  );
116 
117  surfaceScalarField cSf_neg
118  (
119  "cSf_neg",
120  interpolate(c, neg, T.name())*mesh.magSf()
121  );
122 
124  (
125  "ap",
126  max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)
127  );
128 
130  (
131  "am",
132  min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero)
133  );
134 
135  surfaceScalarField a_pos("a_pos", ap/(ap - am));
136 
137  surfaceScalarField amaxSf("amaxSf", max(mag(am), mag(ap)));
138 
139  surfaceScalarField aSf("aSf", am*a_pos);
140 
141  if (fluxScheme == "Tadmor")
142  {
143  aSf = -0.5*amaxSf;
144  a_pos = 0.5;
145  }
146 
147  surfaceScalarField a_neg("a_neg", 1.0 - a_pos);
148 
149  phiv_pos *= a_pos;
150  phiv_neg *= a_neg;
151 
152  surfaceScalarField aphiv_pos("aphiv_pos", phiv_pos - aSf);
153  surfaceScalarField aphiv_neg("aphiv_neg", phiv_neg + aSf);
154 
155  // Reuse amaxSf for the maximum positive and negative fluxes
156  // estimated by the central scheme
157  amaxSf = max(mag(aphiv_pos), mag(aphiv_neg));
158 
159  #include "centralCourantNo.H"
160  #include "readTimeControls.H"
161 
162  if (LTS)
163  {
164  #include "setRDeltaT.H"
165  }
166  else
167  {
168  #include "setDeltaT.H"
169  }
170 
171  ++runTime;
172 
173  Info<< "Time = " << runTime.timeName() << nl << endl;
174 
175  phi = aphiv_pos*rho_pos + aphiv_neg*rho_neg;
176 
177  surfaceVectorField phiU(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg);
178  // Note: reassembled orientation from the pos and neg parts so becomes
179  // oriented
180  phiU.setOriented(true);
181 
182  surfaceVectorField phiUp(phiU + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf());
183 
184  surfaceScalarField phiEp
185  (
186  "phiEp",
187  aphiv_pos*(rho_pos*(e_pos + 0.5*magSqr(U_pos)) + p_pos)
188  + aphiv_neg*(rho_neg*(e_neg + 0.5*magSqr(U_neg)) + p_neg)
189  + aSf*p_pos - aSf*p_neg
190  );
191 
192  volScalarField muEff("muEff", turbulence->muEff());
193  volTensorField tauMC("tauMC", muEff*dev2(Foam::T(fvc::grad(U))));
194 
195  // --- Solve density
197 
198  // --- Solve momentum
199  solve(fvm::ddt(rhoU) + fvc::div(phiUp));
200 
201  U.ref() =
202  rhoU()
203  /rho();
204  U.correctBoundaryConditions();
205  rhoU.boundaryFieldRef() == rho.boundaryField()*U.boundaryField();
206 
207  if (!inviscid)
208  {
209  solve
210  (
211  fvm::ddt(rho, U) - fvc::ddt(rho, U)
212  - fvm::laplacian(muEff, U)
213  - fvc::div(tauMC)
214  );
215  rhoU = rho*U;
216  }
217 
218  // --- Solve energy
219  surfaceScalarField sigmaDotU
220  (
221  "sigmaDotU",
222  (
223  fvc::interpolate(muEff)*mesh.magSf()*fvc::snGrad(U)
224  + fvc::dotInterpolate(mesh.Sf(), tauMC)
225  )
226  & (a_pos*U_pos + a_neg*U_neg)
227  );
228 
229  solve
230  (
231  fvm::ddt(rhoE)
232  + fvc::div(phiEp)
233  - fvc::div(sigmaDotU)
234  );
235 
236  e = rhoE/rho - 0.5*magSqr(U);
237  e.correctBoundaryConditions();
238  thermo.correct();
239  rhoE.boundaryFieldRef() ==
240  rho.boundaryField()*
241  (
242  e.boundaryField() + 0.5*magSqr(U.boundaryField())
243  );
244 
245  if (!inviscid)
246  {
247  solve
248  (
249  fvm::ddt(rho, e) - fvc::ddt(rho, e)
250  - fvm::laplacian(turbulence->alphaEff(), e)
251  );
252  thermo.correct();
253  rhoE = rho*(e + 0.5*magSqr(U));
254  }
255 
256  p.ref() =
257  rho()
258  /psi();
259  p.correctBoundaryConditions();
260  rho.boundaryFieldRef() == psi.boundaryField()*p.boundaryField();
261 
262  turbulence->correct();
263 
264  runTime.write();
265 
266  runTime.printExecutionTime(Info);
267  }
268 
269  Info<< "End\n" << endl;
270 
271  return 0;
272 }
273 
274 // ************************************************************************* //
runTime
engineTime & runTime
Definition: createEngineTime.H:13
Foam::fvc::snGrad
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:47
Foam::volTensorField
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Definition: volFieldsFwd.H:64
p
volScalarField & p
Definition: createFieldRefs.H:8
turbulence
Info<< "Reading field U\n"<< endl;volVectorField U(IOobject("U", runTime.timeName(), mesh, IOobject::MUST_READ, IOobject::AUTO_WRITE), mesh);volScalarField rho(IOobject("rho", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::AUTO_WRITE), thermo.rho());volVectorField rhoU(IOobject("rhoU", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), rho *U);volScalarField rhoE(IOobject("rhoE", runTime.timeName(), mesh, IOobject::NO_READ, IOobject::NO_WRITE), rho *(e+0.5 *magSqr(U)));surfaceScalarField pos(IOobject("pos", runTime.timeName(), mesh), mesh, dimensionedScalar("pos", dimless, 1.0));surfaceScalarField neg(IOobject("neg", runTime.timeName(), mesh), mesh, dimensionedScalar("neg", dimless, -1.0));surfaceScalarField phi("phi", fvc::flux(rhoU));Info<< "Creating turbulence model\n"<< endl;autoPtr< compressible::turbulenceModel > turbulence(compressible::turbulenceModel::New(rho, U, phi, thermo))
Definition: createFields.H:94
Foam::fvc::dotInterpolate
static tmp< GeometricField< typename innerProduct< vector, Type >::type, fvsPatchField, surfaceMesh > > dotInterpolate(const surfaceVectorField &Sf, const GeometricField< Type, fvPatchField, volMesh > &tvf)
Interpolate field onto faces.
Foam::Zero
static constexpr const zero Zero
Global zero (0)
Definition: zero.H:131
Foam::fac::grad
tmp< GeometricField< typename outerProduct< vector, Type >::type, faPatchField, areaMesh >> grad(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facGrad.C:56
thermo
Basic thermodynamics type based on the use of fitting functions for cp, h, s obtained from the templa...
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dev2
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
Definition: dimensionedSymmTensor.C:117
Foam::fac::div
tmp< GeometricField< Type, faPatchField, areaMesh > > div(const GeometricField< Type, faePatchField, edgeMesh > &ssf)
Definition: facDiv.C:50
rho
rho
Definition: readInitialConditions.H:88
Foam::min
label min(const labelHashSet &set, label minValue=labelMax)
Find the min value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:33
solve
CEqn solve()
centralCourantNo.H
Calculates the mean and maximum wave speed based Courant Numbers.
inviscid
bool inviscid(true)
Foam::magSqr
dimensioned< typename typeOfMag< Type >::type > magSqr(const dimensioned< Type > &dt)
directionInterpolate.H
Foam::dimTime
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:54
setRootCaseLists.H
addCheckCaseOptions.H
localEulerDdtScheme.H
Foam::Info
messageStream Info
Information stream (uses stdout - output is on the master only)
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::dimensionedScalar
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
Definition: dimensionedScalarFwd.H:43
phi
surfaceScalarField & phi
Definition: setRegionFluidFields.H:8
Foam::volScalarField
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:57
rhoE
volScalarField & rhoE
Definition: readMechanicalProperties.H:123
Foam::max
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
Definition: hashSets.C:47
fluxScheme
word fluxScheme("Kurganov")
fixedRhoFvPatchScalarField.H
LTS
bool LTS
Definition: createRDeltaT.H:1
mesh
dynamicFvMesh & mesh
Definition: createDynamicFvMesh.H:6
postProcess.H
Execute application functionObjects to post-process existing results.
T
const volScalarField & T
Definition: createFieldRefs.H:2
CoNum
scalar CoNum
Definition: compressibleCourantNo.H:31
U
U
Definition: pEqn.H:72
psiThermo.H
Foam::nl
constexpr char nl
Definition: Ostream.H:385
Foam::surfaceScalarField
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Definition: surfaceFieldsFwd.H:54
createTimeControls.H
Read the control parameters used by setDeltaT.
Foam::sqrt
dimensionedScalar sqrt(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:144
readTimeControls.H
Read the control parameters used by setDeltaT.
Foam::mag
dimensioned< typename typeOfMag< Type >::type > mag(const dimensioned< Type > &dt)
Foam::fac::ddt
tmp< GeometricField< Type, faPatchField, areaMesh > > ddt(const dimensioned< Type > dt, const faMesh &mesh)
Definition: facDdt.C:47
createMesh.H
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
createTime.H
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
meanCoNum
scalar meanCoNum
Definition: compressibleCourantNo.H:32
fvCFD.H
readFluxScheme.H
Foam::fac::laplacian
tmp< GeometricField< Type, faPatchField, areaMesh > > laplacian(const GeometricField< Type, faPatchField, areaMesh > &vf, const word &name)
Definition: facLaplacian.C:47
Foam::surfaceVectorField
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
Definition: surfaceFieldsFwd.H:57
Foam::dimVolume
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:61
psi
const volScalarField & psi
Definition: createFieldRefs.H:1
Foam::neg
dimensionedScalar neg(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:199
Foam::fac::interpolate
static tmp< GeometricField< Type, faePatchField, edgeMesh > > interpolate(const GeometricField< Type, faPatchField, areaMesh > &tvf, const edgeScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
turbulentFluidThermoModel.H
fvcSmooth.H
Provides functions smooth spread and sweep which use the FaceCellWave algorithm to smooth and redistr...
Foam::pos
dimensionedScalar pos(const dimensionedScalar &ds)
Definition: dimensionedScalar.C:177