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 | 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  rhoCentralDyMFoam
28 
29 Group
30  grpCompressibleSolvers grpMovingMeshSolvers
31 
32 Description
33  Density-based compressible flow solver based on central-upwind
34  schemes of Kurganov and Tadmor
35  with support for mesh-motion and topology changes.
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #include "fvCFD.H"
40 #include "dynamicFvMesh.H"
41 #include "psiThermo.H"
44 #include "directionInterpolate.H"
45 #include "localEulerDdtScheme.H"
46 #include "fvcSmooth.H"
47 #include "motionSolver.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 int main(int argc, char *argv[])
52 {
53  argList::addNote
54  (
55  "Density-based compressible flow solver based on central-upwind"
56  " schemes of Kurganov and Tadmor.\n"
57  "With support for mesh-motion and topology changes."
58  );
59 
60  #define NO_CONTROL
61  #include "postProcess.H"
62 
63  #include "setRootCaseLists.H"
64  #include "createTime.H"
65  #include "createDynamicFvMesh.H"
66  #include "createFields.H"
67  #include "createFieldRefs.H"
68  #include "createTimeControls.H"
69 
70  turbulence->validate();
71 
72  // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
73 
74  #include "readFluxScheme.H"
75 
76  const dimensionedScalar v_zero(dimVolume/dimTime, Zero);
77 
78  // Courant numbers used to adjust the time-step
79  scalar CoNum = 0.0;
80  scalar meanCoNum = 0.0;
81 
82  Info<< "\nStarting time loop\n" << endl;
83 
84  while (runTime.run())
85  {
86  #include "readTimeControls.H"
87  #include "setDeltaT.H"
88 
89  ++runTime;
90 
91  Info<< "Time = " << runTime.timeName() << nl << endl;
92 
93  // Do any mesh changes
94  mesh.update();
95 
96  // --- Directed interpolation of primitive fields onto faces
97 
100 
101  surfaceVectorField rhoU_pos(interpolate(rhoU, pos, U.name()));
102  surfaceVectorField rhoU_neg(interpolate(rhoU, neg, U.name()));
103 
104  volScalarField rPsi("rPsi", 1.0/psi);
105  surfaceScalarField rPsi_pos(interpolate(rPsi, pos, T.name()));
106  surfaceScalarField rPsi_neg(interpolate(rPsi, neg, T.name()));
107 
108  surfaceScalarField e_pos(interpolate(e, pos, T.name()));
109  surfaceScalarField e_neg(interpolate(e, neg, T.name()));
110 
111  surfaceVectorField U_pos("U_pos", rhoU_pos/rho_pos);
112  surfaceVectorField U_neg("U_neg", rhoU_neg/rho_neg);
113 
114  surfaceScalarField p_pos("p_pos", rho_pos*rPsi_pos);
115  surfaceScalarField p_neg("p_neg", rho_neg*rPsi_neg);
116 
117  surfaceScalarField phiv_pos("phiv_pos", U_pos & mesh.Sf());
118  surfaceScalarField phiv_neg("phiv_neg", U_neg & mesh.Sf());
119 
120  // Make fluxes relative to mesh-motion
121  if (mesh.moving())
122  {
123  phiv_pos -= mesh.phi();
124  phiv_neg -= mesh.phi();
125  }
126  // Note: extracted out the orientation so becomes unoriented
127  phiv_pos.setOriented(false);
128  phiv_neg.setOriented(false);
129 
130  volScalarField c("c", sqrt(thermo.Cp()/thermo.Cv()*rPsi));
131  surfaceScalarField cSf_pos
132  (
133  "cSf_pos",
134  interpolate(c, pos, T.name())*mesh.magSf()
135  );
136  surfaceScalarField cSf_neg
137  (
138  "cSf_neg",
139  interpolate(c, neg, T.name())*mesh.magSf()
140  );
141 
143  (
144  "ap",
145  max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)
146  );
148  (
149  "am",
150  min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero)
151  );
152 
153  surfaceScalarField a_pos("a_pos", ap/(ap - am));
154 
155  surfaceScalarField amaxSf("amaxSf", max(mag(am), mag(ap)));
156 
157  surfaceScalarField aSf("aSf", am*a_pos);
158 
159  if (fluxScheme == "Tadmor")
160  {
161  aSf = -0.5*amaxSf;
162  a_pos = 0.5;
163  }
164 
165  surfaceScalarField a_neg("a_neg", 1.0 - a_pos);
166 
167  phiv_pos *= a_pos;
168  phiv_neg *= a_neg;
169 
170  surfaceScalarField aphiv_pos("aphiv_pos", phiv_pos - aSf);
171  surfaceScalarField aphiv_neg("aphiv_neg", phiv_neg + aSf);
172 
173  // Reuse amaxSf for the maximum positive and negative fluxes
174  // estimated by the central scheme
175  amaxSf = max(mag(aphiv_pos), mag(aphiv_neg));
176 
177  #include "centralCourantNo.H"
178 
179  phi = aphiv_pos*rho_pos + aphiv_neg*rho_neg;
180 
181  surfaceVectorField phiU(aphiv_pos*rhoU_pos + aphiv_neg*rhoU_neg);
182  // Note: reassembled orientation from the pos and neg parts so becomes
183  // oriented
184  phiU.setOriented(true);
185 
186  surfaceVectorField phiUp(phiU + (a_pos*p_pos + a_neg*p_neg)*mesh.Sf());
187 
188  surfaceScalarField phiEp
189  (
190  "phiEp",
191  aphiv_pos*(rho_pos*(e_pos + 0.5*magSqr(U_pos)) + p_pos)
192  + aphiv_neg*(rho_neg*(e_neg + 0.5*magSqr(U_neg)) + p_neg)
193  + aSf*p_pos - aSf*p_neg
194  );
195 
196  // Make flux for pressure-work absolute
197  if (mesh.moving())
198  {
199  surfaceScalarField phia(a_pos*p_pos + a_neg*p_neg);
200  phia.setOriented(true);
201 
202  phiEp += mesh.phi()*phia;
203  }
204 
205  volScalarField muEff("muEff", turbulence->muEff());
206  volTensorField tauMC("tauMC", muEff*dev2(Foam::T(fvc::grad(U))));
207 
208  // --- Solve density
210 
211  // --- Solve momentum
212  solve(fvm::ddt(rhoU) + fvc::div(phiUp));
213 
214  U.ref() =
215  rhoU()
216  /rho();
217  U.correctBoundaryConditions();
218  rhoU.boundaryFieldRef() == rho.boundaryField()*U.boundaryField();
219 
220  if (!inviscid)
221  {
222  solve
223  (
224  fvm::ddt(rho, U) - fvc::ddt(rho, U)
225  - fvm::laplacian(muEff, U)
226  - fvc::div(tauMC)
227  );
228  rhoU = rho*U;
229  }
230 
231  // --- Solve energy
232  surfaceScalarField sigmaDotU
233  (
234  "sigmaDotU",
235  (
236  fvc::interpolate(muEff)*mesh.magSf()*fvc::snGrad(U)
237  + fvc::dotInterpolate(mesh.Sf(), tauMC)
238  )
239  & (a_pos*U_pos + a_neg*U_neg)
240  );
241 
242  solve
243  (
244  fvm::ddt(rhoE)
245  + fvc::div(phiEp)
246  - fvc::div(sigmaDotU)
247  );
248 
249  e = rhoE/rho - 0.5*magSqr(U);
250  e.correctBoundaryConditions();
251  thermo.correct();
252  rhoE.boundaryFieldRef() ==
253  rho.boundaryField()*
254  (
255  e.boundaryField() + 0.5*magSqr(U.boundaryField())
256  );
257 
258  if (!inviscid)
259  {
260  solve
261  (
262  fvm::ddt(rho, e) - fvc::ddt(rho, e)
263  - fvm::laplacian(turbulence->alphaEff(), e)
264  );
265  thermo.correct();
266  rhoE = rho*(e + 0.5*magSqr(U));
267  }
268 
269  p.ref() =
270  rho()
271  /psi();
272  p.correctBoundaryConditions();
273  rho.boundaryFieldRef() == psi.boundaryField()*p.boundaryField();
274 
275  turbulence->correct();
276 
277  runTime.write();
278 
279  runTime.printExecutionTime(Info);
280  }
281 
282  Info<< "End\n" << endl;
283 
284  return 0;
285 }
286 
287 
288 // ************************************************************************* //
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.
motionSolver.H
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
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
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
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition: createFields.H:11
createTime.H
dynamicFvMesh.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
createDynamicFvMesh.H
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