rhoCentralDyMFoam.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 | Copyright (C) 2011-2016 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
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.
15 
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
19  for more details.
20 
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/>.
23 
24 Application
25  rhoCentralDyMFoam
26 
27 Description
28  Density-based compressible flow solver based on central-upwind schemes of
29  Kurganov and Tadmor with support for mesh-motion and topology changes.
30 
31 \*---------------------------------------------------------------------------*/
32 
33 #include "fvCFD.H"
34 #include "dynamicFvMesh.H"
35 #include "psiThermo.H"
38 #include "directionInterpolate.H"
39 #include "localEulerDdtScheme.H"
40 #include "fvcSmooth.H"
41 #include "motionSolver.H"
42 
43 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44 
45 int main(int argc, char *argv[])
46 {
47  #define NO_CONTROL
48  #include "postProcess.H"
49 
50  #include "setRootCase.H"
51  #include "createTime.H"
52  #include "createDynamicFvMesh.H"
53  #include "createFields.H"
54  #include "createFieldRefs.H"
55  #include "createTimeControls.H"
56 
57  turbulence->validate();
58 
59  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60 
61  #include "readFluxScheme.H"
62 
63  dimensionedScalar v_zero("v_zero", dimVolume/dimTime, 0.0);
64 
65  // Courant numbers used to adjust the time-step
66  scalar CoNum = 0.0;
67  scalar meanCoNum = 0.0;
68 
69  Info<< "\nStarting time loop\n" << endl;
70 
71  while (runTime.run())
72  {
73  #include "readTimeControls.H"
74  #include "setDeltaT.H"
75 
76  runTime++;
77 
78  Info<< "Time = " << runTime.timeName() << nl << endl;
79 
80  // Do any mesh changes
81  mesh.update();
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  surfaceScalarField phiv_neg("phiv_neg", U_neg & mesh.Sf());
106 
107  // Make fluxes relative to mesh-motion
108  if (mesh.moving())
109  {
110  phiv_pos -= mesh.phi();
111  phiv_neg -= mesh.phi();
112  }
113 
114  volScalarField c("c", sqrt(thermo.Cp()/thermo.Cv()*rPsi));
115  surfaceScalarField cSf_pos
116  (
117  "cSf_pos",
118  interpolate(c, pos, T.name())*mesh.magSf()
119  );
120  surfaceScalarField cSf_neg
121  (
122  "cSf_neg",
123  interpolate(c, neg, T.name())*mesh.magSf()
124  );
125 
127  (
128  "ap",
129  max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)
130  );
132  (
133  "am",
134  min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero)
135  );
136 
137  surfaceScalarField a_pos("a_pos", ap/(ap - am));
138 
139  surfaceScalarField amaxSf("amaxSf", max(mag(am), mag(ap)));
140 
141  surfaceScalarField aSf("aSf", am*a_pos);
142 
143  if (fluxScheme == "Tadmor")
144  {
145  aSf = -0.5*amaxSf;
146  a_pos = 0.5;
147  }
148 
149  surfaceScalarField a_neg("a_neg", 1.0 - a_pos);
150 
151  phiv_pos *= a_pos;
152  phiv_neg *= a_neg;
153 
154  surfaceScalarField aphiv_pos("aphiv_pos", phiv_pos - aSf);
155  surfaceScalarField aphiv_neg("aphiv_neg", phiv_neg + aSf);
156 
157  // Reuse amaxSf for the maximum positive and negative fluxes
158  // estimated by the central scheme
159  amaxSf = max(mag(aphiv_pos), mag(aphiv_neg));
160 
161  #include "centralCourantNo.H"
162 
163  phi = aphiv_pos*rho_pos + aphiv_neg*rho_neg;
164 
165  surfaceVectorField phiUp
166  (
167  (aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg)
168  + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf()
169  );
170 
171  surfaceScalarField phiEp
172  (
173  "phiEp",
174  aphiv_pos*(rho_pos*(e_pos + 0.5*magSqr(U_pos)) + p_pos)
175  + aphiv_neg*(rho_neg*(e_neg + 0.5*magSqr(U_neg)) + p_neg)
176  + aSf*p_pos - aSf*p_neg
177  );
178 
179  // Make flux for pressure-work absolute
180  if (mesh.moving())
181  {
182  phiEp += mesh.phi()*(a_pos*p_pos + a_neg*p_neg);
183  }
184 
185  volScalarField muEff("muEff", turbulence->muEff());
186  volTensorField tauMC("tauMC", muEff*dev2(Foam::T(fvc::grad(U))));
187 
188  // --- Solve density
190 
191  // --- Solve momentum
192  solve(fvm::ddt(rhoU) + fvc::div(phiUp));
193 
194  U.ref() =
195  rhoU()
196  /rho();
197  U.correctBoundaryConditions();
198  rhoU.boundaryFieldRef() == rho.boundaryField()*U.boundaryField();
199 
200  if (!inviscid)
201  {
202  solve
203  (
204  fvm::ddt(rho, U) - fvc::ddt(rho, U)
205  - fvm::laplacian(muEff, U)
206  - fvc::div(tauMC)
207  );
208  rhoU = rho*U;
209  }
210 
211  // --- Solve energy
212  surfaceScalarField sigmaDotU
213  (
214  "sigmaDotU",
215  (
216  fvc::interpolate(muEff)*mesh.magSf()*fvc::snGrad(U)
217  + fvc::dotInterpolate(mesh.Sf(), tauMC)
218  )
219  & (a_pos*U_pos + a_neg*U_neg)
220  );
221 
222  solve
223  (
224  fvm::ddt(rhoE)
225  + fvc::div(phiEp)
226  - fvc::div(sigmaDotU)
227  );
228 
229  e = rhoE/rho - 0.5*magSqr(U);
230  e.correctBoundaryConditions();
231  thermo.correct();
232  rhoE.boundaryFieldRef() ==
233  rho.boundaryField()*
234  (
235  e.boundaryField() + 0.5*magSqr(U.boundaryField())
236  );
237 
238  if (!inviscid)
239  {
240  solve
241  (
242  fvm::ddt(rho, e) - fvc::ddt(rho, e)
243  - fvm::laplacian(turbulence->alphaEff(), e)
244  );
245  thermo.correct();
246  rhoE = rho*(e + 0.5*magSqr(U));
247  }
248 
249  p.ref() =
250  rho()
251  /psi();
252  p.correctBoundaryConditions();
253  rho.boundaryFieldRef() == psi.boundaryField()*p.boundaryField();
254 
255  turbulence->correct();
256 
257  runTime.write();
258 
259  Info<< "ExecutionTime = " << runTime.elapsedCpuTime() << " s"
260  << " ClockTime = " << runTime.elapsedClockTime() << " s"
261  << nl << endl;
262  }
263 
264  Info<< "End\n" << endl;
265 
266  return 0;
267 }
268 
269 // ************************************************************************* //
surfaceScalarField & phi
tmp< GeometricField< typename outerProduct< vector, Type >::type, fvPatchField, volMesh >> grad(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcGrad.C:52
U
Definition: pEqn.H:83
volScalarField & rhoE
dimensioned< Type > max(const dimensioned< Type > &, const dimensioned< Type > &)
GeometricField< tensor, fvPatchField, volMesh > volTensorField
Definition: volFieldsFwd.H:59
tmp< GeometricField< Type, fvPatchField, volMesh > > div(const GeometricField< Type, fvsPatchField, surfaceMesh > &ssf)
Definition: fvcDiv.C:47
static tmp< GeometricField< typename innerProduct< vector, Type >::type, fvsPatchField, surfaceMesh > > dotInterpolate(const surfaceVectorField &Sf, const GeometricField< Type, fvPatchField, volMesh > &tvf)
Interpolate field onto faces.
GeometricField< vector, fvsPatchField, surfaceMesh > surfaceVectorField
dimensionedScalar sqrt(const dimensionedScalar &ds)
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:253
Read the control parameters used by setDeltaT.
tmp< GeometricField< Type, fvPatchField, volMesh > > laplacian(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcLaplacian.C:45
dimensionedScalar neg(const dimensionedScalar &ds)
tmp< GeometricField< Type, fvPatchField, volMesh > > ddt(const dimensioned< Type > dt, const fvMesh &mesh)
Definition: fvcDdt.C:45
GeometricField< scalar, fvPatchField, volMesh > volScalarField
Definition: volFieldsFwd.H:52
psiReactionThermo & thermo
Definition: createFields.H:31
dimensionedScalar pos(const dimensionedScalar &ds)
const dimensionSet dimVolume(pow3(dimLength))
Definition: dimensionSets.H:58
const dimensionedScalar e
Elementary charge.
Definition: doubleFloat.H:78
dynamicFvMesh & mesh
rhoEqn solve()
dimensioned< scalar > magSqr(const dimensioned< Type > &)
static const char nl
Definition: Ostream.H:262
Info<< "Reading field U\"<< 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\"<< endl;autoPtr< compressible::turbulenceModel > turbulence(compressible::turbulenceModel::New(rho, U, phi, thermo))
Definition: createFields.H:94
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
dimensioned< Type > min(const dimensioned< Type > &, const dimensioned< Type > &)
const volScalarField & T
static tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > interpolate(const GeometricField< Type, fvPatchField, volMesh > &tvf, const surfaceScalarField &faceFlux, Istream &schemeData)
Interpolate field onto faces using scheme given by Istream.
dimensionedSymmTensor dev2(const dimensionedSymmTensor &dt)
bool inviscid(true)
dimensioned< scalar > dimensionedScalar
Dimensioned scalar obtained from generic dimensioned type.
const dimensionedScalar c
Speed of light in a vacuum.
Calculates the mean and maximum wave speed based Courant Numbers.
const dimensionSet dimTime(0, 0, 1, 0, 0, 0, 0)
Definition: dimensionSets.H:51
messageStream Info
dimensioned< scalar > mag(const dimensioned< Type > &)
const volScalarField & psi
volScalarField & p
GeometricField< scalar, fvsPatchField, surfaceMesh > surfaceScalarField
Execute application functionObjects to post-process existing results.
word fluxScheme("Kurganov")
Provides functions smooth spread and sweep which use the FaceCellWave algorithm to smooth and redistr...
Read the control parameters used by setDeltaT.
tmp< GeometricField< Type, fvsPatchField, surfaceMesh > > snGrad(const GeometricField< Type, fvPatchField, volMesh > &vf, const word &name)
Definition: fvcSnGrad.C:45