combining a density-based compressible solver with a

65
Cite as: Harvey, E.: Combining a density-based compressible solver with a multiphase model. In Proceedings of CFD with OpenSource Software, 2020, Edited by Nilsson. H., http://dx.doi.org/10.17196/OS_CFD#YEAR_2020 CFD with OpenSource software A course at Chalmers University of Technology Taught by H˚ akan Nilsson Combining a density-based compressible solver with a multiphase model Developed for OpenFOAM-v2006 Author: Eleanor Harvey University of Leeds [email protected] Peer reviewed by: Eduardo Iraola Saeed Salehi Harvey Thompson Licensed under CC-BY-NC-SA, https://creativecommons.org/licenses/ Disclaimer: This is a student project work, done as part of a course where OpenFOAM and some other OpenSource software are introduced to the students. Any reader should be aware that it might not be free of errors. Still, it might be useful for someone who would like to learn some details similar to the ones presented in the report and in the accompanying files. The material has gone through a review process. The role of the reviewer is to go through the tutorial and make sure that it works, that it is possible to follow, and to some extent correct the writing. The reviewer has no responsibility for the contents. December 20, 2020

Upload: others

Post on 27-Oct-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Cite as: Harvey, E.: Combining a density-based compressible solver with a multiphase model. In

Proceedings of CFD with OpenSource Software, 2020, Edited by Nilsson. H.,

http://dx.doi.org/10.17196/OS_CFD#YEAR_2020

CFD with OpenSource software

A course at Chalmers University of TechnologyTaught by Hakan Nilsson

Combining a density-based compressiblesolver with a multiphase model

Developed for OpenFOAM-v2006

Author:Eleanor HarveyUniversity of [email protected]

Peer reviewed by:Eduardo Iraola

Saeed SalehiHarvey Thompson

Licensed under CC-BY-NC-SA, https://creativecommons.org/licenses/

Disclaimer: This is a student project work, done as part of a course where OpenFOAM and someother OpenSource software are introduced to the students. Any reader should be aware that itmight not be free of errors. Still, it might be useful for someone who would like to learn some

details similar to the ones presented in the report and in the accompanying files. The material hasgone through a review process. The role of the reviewer is to go through the tutorial and make

sure that it works, that it is possible to follow, and to some extent correct the writing. Thereviewer has no responsibility for the contents.

December 20, 2020

Learning outcomes

The reader will learn:

How to use it:

• how to use density-based compressible solver rhoCentralFoam on the Ladenburg Jet tutorial

The theory of it:

• The theory of the HEM model

• The theory of density-based compressible solver: rhoCentralFoam

• A comparison between density-based and pressure-based solvers.

How it is implemented:

• A thorough insight into the implementation of rhoCentralFoam for compressible flows

• Implementation of a combination of the HEM model and the rhoCentralFoam solver to modelboth compressible and multiphase effects.

How to modify it:

• How to modify the rhoCentralFoam solver to include a liquid vapour equilibrium multiphaseflow by incorporating the HEM model

• How to extend the compressibility and speed of sound to represent the mixture correctly.

1

Prerequisites

The reader is expected to know the following in order to get maximum benefit out of this report:

• How to run standard document tutorials such as the LadenburgJet60psi tutorial for rhoCentralFoam.

• Fundamentals of Computational Methods for Fluid Dynamics, Book by J. H. Ferziger and M.Peric

• Have a basic awareness of the structure of OpenFOAM and how it utilises applications andlibraries.

• How to customise a solver and do top-level application programming.

2

Contents

1 Introduction 5

2 rhoCentralFoam 72.1 Governing Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.2 createFields.H . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82.3 rhoCentralFoam.C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.4 Tutorial Case: Ladenburg Jet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

3 Homogeneous Equilibrium Model (HEM) 223.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.2 cavitatingFoam . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223.3 barotropicCompressibilityModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3.3.1 Linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3.2 Wallis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.3.3 Chung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

4 rhoCentralFoamHEM 264.1 Addition of a multiphase thermophysical library . . . . . . . . . . . . . . . . . . . . 264.2 Utilising two phase library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.3 Speed of Sound and compressibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32

4.3.1 barotropicCompressibilityModel Modifications . . . . . . . . . . . . . . . . . 324.3.2 Speed of sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4 Temperature calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

5 Multi-phase jet tutorial case 405.1 Domain configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 415.2 Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.3 ThermophysicalProperties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.4 Saturation densities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.5 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

A Modified barotropicCompressibilityModel 49A.1 barotropicCompressibilityModel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49A.2 linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54A.3 Wallis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57A.4 Chung . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

3

Nomenclature

AcronymsCFD Computational Fluid DynamicsHEM Homogeneous Equilibrium ModelVLE Vapour Liquid Equilibrium

English symbolsc Speed of sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .m/sK Bulk modulus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Pak Thermal conductivity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . W/(mK)p Pressure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .PaT Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . KU Velocity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .m/sD Diameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .mL Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . m

Greek symbolsα Phase fractionν Fluid kinematic viscosity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .m2/sψ Compressibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . s2/m2

ρ Fluid density . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . kg/m3

Subscriptsl liquidsat saturationv vapour

4

Chapter 1

Introduction

Almost all fluid flow has some element of compressibility. A huge number of numerical studiesassume incompressibility in their flows as this drastically reduces complexity and computation time.While in many cases this assumption has little to no effect, in some studies it could result incompromising the validity of the results. In these situations it is critical, therefore, to consider theappropriate physics and take compressibility into account where necessary. Examples of flows wherecompressibility is important are aerodynamics, turbomachinery and pipe gas flows among others.The Mach number,

Ma =U

c, (1.1)

a dimensionless number relating the velocity to the local speed of sound, is often used to determinewhether compressible effects should be considered. A value of Ma>0.3 is often taken as a loosethreshold at which compressibility becomes important.

When applying Computational Fluid Dynamics (CFD) to compressible flow problems, either apressure-based or density-based approach can be used to solve the governing equations. Pressure-based methods calculate the pressure field through the solution of a pressure equation or pressurecorrection equation obtained through combining the continuity and momentum equations. Density-based methods solve for the density in the continuity equation and calculate pressure from theequation of state. Historically, pressure-based solvers have been more prevalent in incompressible orweakly compressible cases, with density-based solvers developed for high speed, compressible cases.In more recent work both methods have been extended to cover a broad range of conditions withsuccess. In some highly compressible cases with shock waves, however, there is still thought tobe a numerical accuracy advantage when using the density-based approaches. The density-basedcompressible solver available in OpenFOAM, rhoCentralFoam has been widely applied to a range ofcompressible flow and has been validated successfully over a range of highly compressible fluid flowcases including shock tube tests, under-expanded jets and supersonic forward facing step problems.

Figure 1.1: Typical under-expanded jet structure

5

Chapter 1. Introduction

An example of highly compressible flow is in the study of highly-under-expanded and supersonicjets. These jets usually result from sudden releases of fluid from high pressure reservoirs, or areattained using specific nozzle designs. A typical under-expanded jet structure, seen in Figure 1.1,can exhibit many shock features which are often challenging to model numerically.

In certain circumstances, such as in high pressure pipelines, a sudden rupture or release mayoccur with the fluid initially in liquid or supercritical state. In such a case the significant pressuredrop, as ambient pressure is reached by the jet flow, can cause a dramatic phase change as cavitationoccurs. The multiphase aspect of these releases is often critical in the prediction of the flow field inboth the near-field and far-field regions of the jet. The aim of this report is to study the implemen-tation of the rhoCentralFoam solver and make modifications to include a multiphase library andsimple multiphase model. The combination of the density-based solver and this multiphase model,which is currently not available in OpenFOAM, could provide a means to study highly compressiblesupersonic flow with both liquid and vapour phases present.

6

Chapter 2

rhoCentralFoam

In this chapter a description of the theory of the solver rhoCentralFoam, summarising that givenin full by Greenshields et al. [1], is presented alongside the solver source code to work throughthe implementation. The solver is located in $FOAM_SOLVERS/compressible/rhoCentralFoam. De-scribed as a “density-based compressible flow solver based on central-upwind schemes of Kurganovand Tadmor”, rhoCentralFoam is also a transient solver with both turbulence and heat transfercapability.

The solver includes governing equations for the continuity, which solves for density; the momen-tum, which provides the velocity field; and the energy of the system. Inside the solver directory wefind the main source file, rhoCentralFoam.C, a library of solver boundary conditions and severalheader files as seen here with brief descriptions.

rhoCentralFoam

Allwclean % Script to clean the solver and BC library

Allwmake % Script to compile the solver and BC library

BCs % Solver specific boundary conditions for rho, U and T

centralCourantNo.H % Calculates mean and max wave speed based Courant numbers

createFieldRefs.H % a createFields file for reference variables

createFields.H % Header to create fields for simulation

directionInterpolate.H % Interpolation code which takes dimension as additional input

Make % Directory containing all compilation information

files

options

readFluxScheme.H % Reads in the flux scheme for the case (Kurganov or Tadmor)

rhoCentralFoam.C % Main solver file

setRDeltaT.H % Set reciprocal timestep from the local Courant number

7

2.1. Governing Equations Chapter 2. rhoCentralFoam

2.1 Governing Equations

The governing equations solved by rhoCentralFoam are the continuity, momentum and energyequations,

∂ρ

∂t+∇ · [Uρ] = 0, (2.1)

∂(ρU)

∂t+∇ · [U(ρU)] +∇p+∇ · σ = 0, (2.2)

∂(ρE)

∂t+∇ · [U(ρE)] +∇ · [Up] +∇ · (σ · U) +∇ · j = 0, (2.3)

for density, ρ, velocity, U , pressure, p, and the total energy E = e+ |U |2/2. The term e is the specificinternal energy or enthalpy, σ is the viscous stress tensor, defined as positive in compression,

σ = −µ[∇U + (∇U)T − 2/3(∇ · U)I

](2.4)

with dynamic viscosity µ and j is the diffusive flux of heat with thermal conductivity k,

j = −k∇T. (2.5)

2.2 createFields.H

The createFields.H file, included with all solvers, is used to read in information and initialisevariables used in the simulation and setup the necessary turbulence and thermophysical models.The solver rhoCentalFoam is somewhat unusual in that it has two such files, createFields.H andcreateFieldRefs.H. We work through both codes in this section.

The createFields.H file begins by including the createRDeltaT.H file, located at$FOAM_SRC/finiteVolume/cfdTools/general/include/createRDeltaT.H which sets up avolScalarField for local reciprocal time step if local time stepping is enabled for the case. Theboolean variable which determines the use of local time stepping is checked on the first line:bool LTS = fv::localEulerDdt::enabled(mesh);

The cases considered in this tutorial do not make use of the local time stepping feature or codeso it is not considered in detail here. For those interested, it is enabled in the solver by using thelocalEuler as the chosen ddtScheme in the fvSchemes file in a case and can be seen in some of thestandard tutorials available such as the biconic25-55Run35 case available for this rhoCentralFoamsolver.

Returning to the createFields.H file, thermophysical properties are then created from thepsiThermo model, which is based on compressibility. The thermophysical libraries in OpenFOAMare extensive and provide the framework and structure for the thermophysical properties such asspecific heat capacity, the equations of state that are used to calculate some of these properties andtransport models, among other things. The library is not considered in detail here, for a detailedreview see Choquet [2].

createFields.H: Part 1

1 #include "createRDeltaT.H"

2

3 Info<< "Reading thermophysical properties\n" << endl;

4

5 autoPtr<psiThermo> pThermo

6 (

7 psiThermo::New(mesh)

8 );

9 psiThermo& thermo = pThermo();

10

11 volScalarField& e = thermo.he();

8

2.2. createFields.H Chapter 2. rhoCentralFoam

Following the setting of the thermo model, the scalar field for the internal energy/enthalpy, e, isinitialised. Most other thermophysical variables are instead created in the file createFieldRefs.H

as they are created as references seen below (created using the ampersand symbol following C++conventions). The energy scalar field, e is initialised similarly as a reference but is then used laterwithin the createFields.H file to construct other variables so it is located here instead of withinthe createFieldRefs.H file.

createFieldRefs.H

1 volScalarField& p = thermo.p();

2 const volScalarField& T = thermo.T();

3 const volScalarField& psi = thermo.psi();

4 const volScalarField& mu = thermo.mu();

5

6 bool inviscid(true);

7 if (max(mu.primitiveField()) > 0.0)

8 {

9 inviscid = false;

10 }

The temperature, T, pressure, p, compressibility, psi, and viscosity, mu, are set up as references inthis file as seen above. A further boolean variable, inviscid, is created as true and then determinedbased on the viscosity - if the viscosity is read in as zero from the case file then this boolean remainsas true and a simplified set of the Navier-Stokes equations are solved. If a value of mu greater than0 is read in then the simulation is run with the inviscid variable set to false.

Returning and continuing with the createFields.H header file shows the reading of the velocityand density fields, with the U data read from the case setup and the density, rho, created from thethermophysical model

createFields.H: Part 2

13 Info<< "Reading field U\n" << endl;

14 volVectorField U

15 (

16 IOobject

17 (

18 "U",

19 runTime.timeName(),

20 mesh,

21 IOobject::MUST_READ,

22 IOobject::AUTO_WRITE

23 ),

24 mesh

25 );

26

27 volScalarField rho

28 (

29 IOobject

30 (

31 "rho",

32 runTime.timeName(),

33 mesh,

34 IOobject::NO_READ,

35 IOobject::AUTO_WRITE

36 ),

37 thermo.rho()

38 );

The solver implemented in OpenFOAM solves for density weighted fields, ρ, U = ρU , E = ρE.These fields are setup in the createFields.H file using the rho, U, e fields and formula for thetotal energy E = e+ |U |2/2 as seen below in createFields.H Part 3 where U , E are initialised.

createFields.H: Part 3

40 volVectorField rhoU

9

2.2. createFields.H Chapter 2. rhoCentralFoam

41 (

42 IOobject

43 (

44 "rhoU",

45 runTime.timeName(),

46 mesh,

47 IOobject::NO_READ,

48 IOobject::NO_WRITE

49 ),

50 rho*U

51 );

52

53 volScalarField rhoE

54 (

55 IOobject

56 (

57 "rhoE",

58 runTime.timeName(),

59 mesh,

60 IOobject::NO_READ,

61 IOobject::NO_WRITE

62 ),

63 rho*(e + 0.5*magSqr(U))

64 );

Also included in the header file are the creation of fields pos and neg, surface scalar fields whichare used in the solver as part of the stabilisation process. As described by Greenshields et al. (2001)[1], the convective terms in the governing equations, ∇ · [Uρ] ,∇ · [U(ρU)] ,∇ · [U(ρE)] ,∇ · [Up], areintegrated over a control volume in rhoCentralFoam.C as follows for a generic dependent tensorfield Ψ, ∫

V

∇ · [uΨ]dV =

∫S

dS · [uΨ] ≈∑f

Sf · UfΨf =∑f

φfΨf (2.6)

Often in incompressible flow, U is linearly interpolated using a central differencing method andΨf is interpolated according to a selected scheme that usually incorporates upwinding to somedegree to stabilise. In incompressible flow, the velocity and therefore the sign of φf determinesthe upwinding direction. However, in compressible flow propagation of waves also impact on thetransport of fluid properties. This means stabilisation must take into account that transport canoccur in any direction. Interpolation is therefore carried out in both directions for each face, inthe f+, f− directions. A weighting factor α and a diffusive volumetric flux ωf based on maximumspeeds at any discontinuity are used here to give the full discretisation,∑

f

φfΨf =∑f

[αφf+Ψf+ + (1− α)φf−Ψf− + ωf (Ψf− −Ψf+)] (2.7)

This process and implementation is discussed further in the rhoCentralFoam.C file but beloware the pos and neg variable definitions for positive and negative surface scalar fields on each face.

createFields.H: Part 4

66 surfaceScalarField pos

67 (

68 IOobject

69 (

70 "pos",

71 runTime.timeName(),

72 mesh

73 ),

74 mesh,

75 dimensionedScalar("pos", dimless, 1.0)

76 );

77

78 surfaceScalarField neg

10

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

79 (

80 IOobject

81 (

82 "neg",

83 runTime.timeName(),

84 mesh

85 ),

86 mesh,

87 dimensionedScalar("neg", dimless, -1.0)

88 );

The createFields.H file is completed with the creation of the necessary turbulence model anddeclaration of the phi variable, which in compressible solvers in OpenFOAM is the density weightedvolumetric flux through the cell faces. This differs from the incompressible solvers where phi is notdensity-weighted.

createFields.H: Part 5

90 surfaceScalarField phi("phi", fvc::flux(rhoU));

91

92 Info<< "Creating turbulence model\n" << endl;

93 autoPtr<compressible::turbulenceModel> turbulence

94 (

95 compressible::turbulenceModel::New

96 (

97 rho,

98 U,

99 phi,

100 thermo

101 )

102 );

2.3 rhoCentralFoam.C

The main C file for the solver, rhoCentralFoam.C is now studied below. It begins with the inclusionof a list of header files. Several of these files are fairly standard and included in many OpenFOAMsolvers such as fvCFD.H which contains many objects which form the basis of the mathematicaloperations such as the tensor and vector definitions. createMesh.H and createTime.H are alsocommonplace across OpenFOAM. The psiThermo class is included in order to build the neededthermophysical models we saw used in createFields.H.

rhoCentralFoam.C: Part 1

36 \*---------------------------------------------------------------------------*/

37

38 #include "fvCFD.H"

39 #include "psiThermo.H"

40 #include "turbulentFluidThermoModel.H"

41 #include "fixedRhoFvPatchScalarField.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

11

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

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;

Other header files included are more specific to this solver, the fixedRhoFvPatchScalarField.Hfile is a boundary condition class defined for this solver to provide a fixed density boundary con-structed from pressure, p, and compressibility, psi, found in the BCs/rho directory in the solver. Theline #define NO_CONTROL may also be unfamiliar. It is used here where in the pressure based solversother controls such as PimpleControls or PisoContols may be used. The readFluxScheme.H fileis also included. This file, found in the main solver directory, checks the case file for the presence ofa specified flux scheme. The two possibilities are either the Kurganov et al. KNP [3] or Kurganovand Tadmor KT [4] schemes and if neither is specified, the solver progresses using the KNP schemeas automatic first choice.

Inside the time loop which starts at line 81, the first step is to interpolate the key variables in bothpositive and negative directions (in and out of the cells) using the pos and neg variables. The rho andrhoU variables are interpolated to give surface scalar fields rho_pos, rho_neg, rhoU_pos, rhoU_neg.The reciprocal of compressibility, rPsi, is also interpolated, as is the energy, e.

rhoCentralFoam.C: Part 2

78

79 Info<< "\nStarting time loop\n" << endl;

80

81 while (runTime.run())

82 {

83 // --- Directed interpolation of primitive fields onto faces

84

85 surfaceScalarField rho_pos(interpolate(rho, pos));

86 surfaceScalarField rho_neg(interpolate(rho, neg));

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()));

The internal energy, e is interpolated instead of the total energy variable that is later used in theenergy equation, E. This is due to the findings by Greenshields et al. [1] that the direct interpolationof this total energy could cause stability issues and non bounded temperature since the temperatureis calculated from the internal energy and kinetic energy. The interpolation of the intermediatevariables e and U limited this effect and hence e is used here.

As with the total energy density, E, other variables such as velocity, U and pressure, p are actuallyconstructed from the interpolation of the key working variables instead of directly interpolatedthemselves.

12

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

From the U_pos,U_neg surfaceVectorFields, the phiv surfaceScalarFields are constructed φf =U · Sf

rhoCentralFoam.C: Part 3

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);

Next the speed of sound, c is calculated on line 110. The speed of sound is important in thesecompressible simulations as it is critical in determining the propagation of waves through the fluid.The speed of sound is calculated from the specific heat capacities at constant pressure, Cp andvolume, Cv and the compressibility, ψ (2.8)

c2 =CpCvψ

(2.8)

This equation for speed of sound is rooted in an ideal gas assumption. At a more general level speedof sound is given by the Newton-Laplace equation,

c2 =Ks

ρ(2.9)

for isentropic bulk modulus Ks. In an ideal gas, K is given by

K =CpCv

p (2.10)

and so

c2 =Cpp

Cvρ(2.11)

to give the equation implemented here in line 110 of Part 4. It should also be noted that althoughreferred to as compressibility in OpenFOAM, the variable psi has units s2m−2 instead of the usualcompressibility units which are Pa−1. This is due to the fact that many fields are density correctedin OpenFOAM.

rhoCentralFoam.C: Part 4

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 );

The positive and negative surfaceScalarFields for speed of sound are calculated on line 111-122 ina similar manner as the rho and rhoU variables. There is an interpolation using the reconstruction

13

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

of T and then the surfaceScalarFields cSf± = cf± · |Sf | are constructed. Once these local speeds ofpropagation have been calculated, their associated volumetric fluxes, Φf± can be found.

Φf+ = max(φf+ + cf+|Sf |, φf− + cf−|Sf |, 0) (2.12)

Φf− = min(φf+ − cf+|Sf |, φf− − cf−t|Sf |, 0) (2.13)

rhoCentralFoam.C: Part 5

122

123 surfaceScalarField ap

124 (

125 "ap",

126 max(max(phiv_pos + cSf_pos, phiv_neg + cSf_neg), v_zero)

127 );

128

129 surfaceScalarField am

130 (

131 "am",

132 min(min(phiv_pos - cSf_pos, phiv_neg - cSf_neg), v_zero)

133 );

A weighting factor α is used in the discretisation of Eq. (2.7). Built from the volumetric fluxesΦf± (ap,am), it determines the weighting of the contributions from the f+ and f− directions. TheKurganov scheme [3] is a central scheme and takes the contributions equally, however the Tadmor

scheme [4] is a central upwinding scheme and biases the weighting in favour of the upwind direction.

α =

{12 , for the Tadmor flux scheme,

Φf+

Φf+−Φf−, for the Kurganov flux scheme,

(2.14)

Another term is used in the discretisation of convective terms in the solver. It is a diffusive termwhich is based on the propagation of discontinuities in the flow and uses volumetric flux term, ωf ,which is also defined differently depending on the chosen scheme:

ωf =

{−α max(Φf+,Φf−), for the Tadmor flux scheme,

−α(1− α)(Φf+ − Φf−), for the Kurganov flux scheme,(2.15)

The code implementation of α and ωf are shown below, with the initial implementation set upfor the Kurganov flux scheme and a modification made to the variables if the flux scheme has beenread in as “Tadmor” by the readFluxScheme.H file.

rhoCentralFoam.C: Part 6

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);

The a pos term refers to α and the a neg to (1−α). The volumetric flux ωf is constructed in thesolver code as aSf. Now, with α defined the implementation of φf± is updated from φf± = Uf± ·Sfso that the f+ component is multiplied by α and the f− component by (1 − α). These modified

14

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

phiv pos,phiv neg fields are further combined with the ωf variable to give surfaceScalarFieldsaphiv pos and aphiv neg. It is these fields that are ultimately used to find the fluxes in eachdirection through the faces for the primitive variables. The two fields, aphiv pos and aphiv neg aresetup here to combine the α and ωf terms multiplied by generic tensors Ψf+ and Ψf− respectivelyin Eq. (2.7), with the terms grouped here below in Eq. (2.16).∑

f

φfΨf =∑f

[Ψf+[αφf+ − ωf ] + Ψf−[(1− α)φf− + ωf ]] (2.16)

rhoCentralFoam.C: Part 7

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);

At this point in the solver code the time-stepping is addressed, with the ωf reset and thecentralCourantNo.H file used to calculate the mean and max wave speed based Courant Num-bers. This differs from the usual process for calculating Courant number in OpenFOAM,

C =U∆t

∆h(2.17)

for the timestep length ∆t and characteristic size of the control volume, ∆h. As seen when calculatingfluxes through cell faces above, wave speed is also taken into account in rhoCentralFoam and thatapplies also to the calculation of Courant number. In place of U in the Eq. (2.17), a maximum ofthe positive and negative fluxes given by the central scheme is used, amaxSf.

These central scheme Courant number values are used to calculate the appropriate time step.This is either done by calculating reciprocal time step in the file setRDeltaT.H if local time stepping(LTS) is enabled or in the conventional manner using setDeltaT.H otherwise. After this calculationthe time is advanced.

rhoCentralFoam.C: Part 8

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;

After advancing the time, the fields which are convected are built using the fluxes implementedin terms phiv pos,phiv neg. Combinations of these convection terms, Uρ, U(ρU), U(ρE), Up ,are implemented here as part of the phi, phiU, phiUp and phiEp code. The simplest field phi iscreated substituting ρ± for Ψ± in Eq. (2.16) as seen on line 175. phiU is similarly constructed fromthe rhoU interpolations on line 177. In the momentum equation however two terms are combined -the ∇ · [U(ρU)] term and ∇p term. These are combined here to give the phiUp surfaceVectorFieldon line 182 using the field phiU and the f+ and f− directions of pressure. Finally the phiEp field

15

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

is built starting at line 184. This combines the two convective fields U(ρE), Up from the energyequation. The total energy, E = e + 1/2|U |2 is multiplied by density to give the density weightedfield E and added to the p before being weighted with the aphiv pos,aphiv neg fields. This is alsocorrected with a +ωfpf+−ωfpf to counteract the ωf terms applied through the aphiv fields for thepressure term. This modification is used since the additional diffusive flux terms with ωf are onlyneeded when the convective term is applied as part of a substative derivative, D

Dt . This has beentrue for all other fields but must be corrected for p.

rhoCentralFoam.C: Part 9

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 );

The last step to set up the variables before solving the governing equations is to set up some ofthe turbulence fields,

rhoCentralFoam.C: Part 10

192 volScalarField muEff("muEff", turbulence->muEff());

193 volTensorField tauMC("tauMC", muEff*dev2(Foam::T(fvc::grad(U))));

At this point in the code now that all interpolations and volumetric fluxes have been calculated,the governing equations are solved. Firstly, the continuity equation is solved on line 196 to updatethe density.

rhoCentralFoam.C: Part 11

195 // --- Solve density

196 solve(fvm::ddt(rho) + fvc::div(phi));

Secondly, the momentum equation is solved to calculate the velocity field. For the full Navier-Stokes solution with inclusion of the diffusion terms, this equation is solved in two steps. Thediffusive terms, which are functions of U and T for the momentum and heat diffusion respectivelycannot be simply evaluated implicitly with the other terms due to the working variables, U , E beingdensity weighted. To include them explicitly would mean a fully explicit solution which was foundby Greenshields et al. [1] to suffer a severe timestep limit. Instead the diffusive terms are appliedas implicit corrections to the original inviscid equations in the following manner.

• The inviscid momentum equation is solved for U

• U is updated from the solution and then both the U and rhoU boundary conditions are correctedin turn

• If a non zero viscosity value was read in for the case then the diffusive terms are solved for,with variable U

• Finally, rhoU is recalculated again in the non inviscid case

16

2.3. rhoCentralFoam.C Chapter 2. rhoCentralFoam

rhoCentralFoam.C: Part 12

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 }

The solution of the energy equation follows a largely similar method with the variable σ · Usetup on lines 219-227 the inviscid equation solved on lines 229-234 and the updating of the energy eand correcting of boundary conditions and thermophysical model on lines 236-243. Finally the noninviscid element is handled where appropriate on lines 245-254

rhoCentralFoam.C: Part 13

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 }

After solving all the governing equations the pressure field is updated from the density and

17

2.4. Tutorial Case: Ladenburg Jet Chapter 2. rhoCentralFoam

compressibility fields, rho and psi. The pressure boundary conditions are then corrected in orderto update the boundary conditions for rho again. Finally the time loop ends with the correcting ofthe turbulence model and the writing of relevant variables.

rhoCentralFoam.C: Part 14

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 // ************************************************************************* //

2.4 Tutorial Case: Ladenburg Jet

In this section an example tutorial case will be studied for the rhoCentralFoam solver. The casechosen is a supersonic jet problem, which is located in the\$FOAM_TUTORIALS/compressible/rhoCentralFoam/LadenburgJet60psi directory. This case formeda part of the validation process for the rhoCentralFoam solver in the original testing and publicationof the work by Greenshields et al. Replicating numerically experiments undertaken by Ladenburg[5], a study was carried out by Greenshields et al. on an under-expanded dry air jet. In the ex-periments a high pressure tank source is discharged into atmospheric pressure conditions througha circular nozzle and the resulting flow is supersonic with Mach disc features produced which areoften difficult to predict correctly using numerical methods.

To examine and run this case the tutorial is copied to our local work space from the OpenFOAMcollection:

run

cp -r $FOAM_TUTORIALS/compressible/rhoCentralFoam/LadenburgJet60psi .

cd LadenburgJet60psi

Examining the directory it should be observed that there is a README file present which explainsthat the results in the 0 directory are already fairly well converged for the case. The originalboundary and initial conditions can be found in the 0.orig directory instead.

The geometry of the simulation is a rectangular configuration with a height of 10mm and lengthof 30mm as seen in Figure 2.1. The inlet patch representing the nozzle orifice has height 5mmand the remaining boundary is named freestreamInlet. The top patch of the domain, furthestfrom the centre of the jet is labelled freestream and that running along the centre of the jet is asymmetry boundary. The boundary opposite the nozzle orifice is an outlet.

Since the case is axisymmetric a wedge condition is applied to the front and back boundaries, asillustrated in a geometry example in Figure 2.2. The Ladenburg case files have a much thinner wedgeslice which makes it difficult to see the feature when looking at the whole domain so this example hasan exaggerated wedge feature for clarity. The other boundaries are highlighted in colour for context,so the white boundary is the inlet, the green is the freestreamInlet and the blue the freestream.

The domain is very tightly focused on the near-field region of the under-expanded jet since thepurpose of the simulation is to validate the position of the Mach disc.

18

2.4. Tutorial Case: Ladenburg Jet Chapter 2. rhoCentralFoam

Figure 2.1: Geometry for LadenburgJet tutorial case

Figure 2.2: Wedge boundary example

The folder 0 contains the fields p, T and U at a fairly well converged state as mentioned above.The boundary condition types are outlined in Table 2.1.

p T U

inlet fixedValue fixedValue fixedValue

outlet waveTransmissive zeroGradient inletOutlet

freestream totalPressure totalTemperature zeroGradient

freestreamInlet zeroGradient fixedValue noSlip

Table 2.1: Boundary conditions: LadenburgJet case

Most of these boundary conditions are very common across OpenFOAM tutorials and shouldbe familiar. The waveTransmissive condition applied at the outlet is used to limit the reflectionof waves at boundaries such as outlets and inlets which can be a problem with high Mach numberflows. The totalPressure condition applied at the freestream boundary calculates pressure usingone of four methods depending on the simulation case. In these highly compressible flows a gamma

value which is the ration of specific heats is provided as part of the boundary condition and since itis greater than 1, the pressure at the patch is given by

pp =p0

(1 + 0.5ψG|U |2)1/G(2.18)

for total pressure p0 and a coefficient, G = 1−γγ . A similar boundary condition totalTemperature

is also applied at the freestream boundary where temperature at the patch, Tp is given by

Tp =T0

1 + 0.5ψG|U |2(2.19)

The noSlip condition applied for velocity at the freestreamInlet is used here since this boundaryrepresents the solid nozzle wall.

19

2.4. Tutorial Case: Ladenburg Jet Chapter 2. rhoCentralFoam

The constant directory contains the thermophysical and turbulence properties for the case. Alaminar model is specified here in the turbulence file and a hePsiThermo thermo type is used in thethermophysical file with a perfect gas equation of state and Sutherland viscosity model chosen.In the system directory, the fvSchemes file provides the flux scheme to be used by the solver todetermine the upwinding used. The Kurganov and Tadmor schemes introduced in section 2.3 arethe two options available, with the Kurganov chosen in this case

Interpolation schemes are also provided in the file. They utilise a vanLeer scheme for the recon-structed variables which we saw were used in rhoCentralFoam.C to calculate the fluxes in both thepositive and negative directions through cell faces.

Interpolation schemes in fvSchemes

41 interpolationSchemes

42 {

43 default linear;

44 reconstruct(rho) vanLeer;

45 reconstruct(U) vanLeerV;

46 reconstruct(T) vanLeer;

47 }

The fvSolution file with the case is short. The density weighted variables, ρ, U , E are solvedwith a diagonal solver for the invsicid case and the remaining parts of the Navier Stokes equationsare then included when U and e are solved for using a smoothSolver in this example.

Solvers in fvSolution

18 solvers

19 {

20 "(rho|rhoU|rhoE)"

21 {

22 solver diagonal;

23 }

24

25 U

26 {

27 solver smoothSolver;

28 smoother GaussSeidel;

29 nSweeps 2;

30 tolerance 1e-10;

31 relTol 0;

32 }

33

34 e

35 {

36 $U;37 tolerance 1e-10;

38 relTol 0;

39 }

40 }

The case is run by creating the mesh and running the application. The Mach number for thesimulation could also be calculated as shown below in post processing.

blockMesh

rhoCentralFoam

rhoCentralFoam -postProcess -func MachNo

The run time for the simulation should be short given the initial conditions at time 0. Resultsfor velocity, density and Mach number are seen in Figures 2.3, 2.4 and 2.5 respectively. Each of thefigures shows the jet structure and Mach disc location as a sharp change in values.

20

2.4. Tutorial Case: Ladenburg Jet Chapter 2. rhoCentralFoam

Figure 2.3: LadenburgJet results: Velocity

Figure 2.4: LadenburgJet results: Density

Figure 2.5: LadenburgJet results: Mach number

21

Chapter 3

Homogeneous Equilibrium Model(HEM)

3.1 Theory

One of the most popular multiphase models for fluid modelling of critical flows, cavitation problemsand flashing phenomena is the Homogeneous Equilibrium Mixture (HEM) model [6]. This is mostlydue to its simplicity; the HEM model assumes both thermal and mechanical equilibrium. Theseassumptions require the component phases of the system to share the same velocity, temperatureand pressure. Other quantities which differ between the phases are calculated for the mixture usinga weighted average with the phase volume fractions φi, which sum to 1.∑

i=l,v

φi = 1 (3.1)

The density of the mixture for example is calculated as

ρ =∑i=l,v

ρiφi (3.2)

where the phases considered are liquid and vapour, i = l, v and ρi is the density of the phase i.

In the case of sudden release from high pressure, which is a case where the HEM is often applied,the ignoring of phase slip and assumption of equal velocities between phases may be reasonable due tothe often near instantaneous pressure drop near to the release plane. There is also an assumption ofthermal equilibrium which means that any heat transfer between the phases occurs instantaneouslyto ensure that both maintain the same temperature and pressure.

p = pl = pv = psat(3.3)

T = Tl = Tv = Tsat(3.4)

This assumption may be violated near the liquid saturation point in very bubbly flow [7] and amodification could be made to adopt the Homogeneous relaxation model (HRM) or other thermalnon-equilibrium models if needed at a later date. What is often harder to justify is the assumptionof thermal equilibrium.

3.2 cavitatingFoam

The HEM is already implemented in OpenFOAM as part of the cavitatingFoam solver which is atransient cavitation solver. The pressure-based compressible solver can model isothermal cavitation

22

3.3. barotropicCompressibilityModel Chapter 3. Homogeneous Equilibrium Model (HEM)

by solving a density, momentum and pressure equation. The HEM model is incorporated throughthe calculation of the phase fractions, referred to as αl, alphal and αv, alphav in the solver for theliquid and vapour phase fractions respectively. They are calculated in the alphavPsi.H file as

αv =ρ− ρl

ρv − ρl(3.5)

αl = 1− αV (3.6)

and then confined so that 0 ≤ αi ≤ 1.

alphavPsi.C

1 {

2 alphav =

3 max

4 (

5 min

6 (

7 (rho - rholSat)/(rhovSat - rholSat),

8 scalar(1)

9 ),

10 scalar(0)

11 );

12 alphal = 1.0 - alphav;

13

14 Info<< "max-min alphav: " << max(alphav).value()

15 << " " << min(alphav).value() << endl;

16

17 psiModel->correct();

18

19 //Info<< "min a: " << 1.0/sqrt(max(psi)).value() << endl;

20 }

Also within this file psiModel is used. This model for compressibility is initially set up in thecreateFields.H file:

createFields.H

71 Info<< "Creating compressibilityModel\n" << endl;

72 autoPtr<barotropicCompressibilityModel> psiModel =

73 barotropicCompressibilityModel::New

74 (

75 thermodynamicProperties,

76 alphav

77 );

78

79 const volScalarField& psi = psiModel->psi();

The psiModel is set up using the barotropicCompressibilityModel. This model builds acompressibility field psi for the two phase mixture.

3.3 barotropicCompressibilityModel

The barotropicCompressibilityModel is located in the $FOAM_SRC/thermophysicalModels li-brary. It is used to calculate the compressibility for mixtures using one of three models: linear,Chung [8] or Wallis [9], which are discussed in further detail below. Unlike many of the fluid prop-erties in two phase mixture, the compressibility and speed of sound often have to be evaluateddifferently as there is not always a linear relation between the two property values of the liquid andvapour phases. The speed of sound of a two phase mixtures has been thoroughly investigated inthe literature and it has been shown to be much lower than the speed of sound observed in eitherof the components in a single phase case [10, 11, 12]. This phenomena occurs due to the propertiesof the two-phase mixture which takes on a near liquid density and a near gaseous compressibility

23

3.3. barotropicCompressibilityModel Chapter 3. Homogeneous Equilibrium Model (HEM)

for small vapour fractions. As an example, the speed of sound in an air water mixture can fall aslow as 20ms−1 despite the speeds of sound for air and water being roughly 340ms−1 and 1450ms−1

respectively.Usually compressibility is defined as, βs, the inverse of the bulk modulus, K. In OpenFOAM,

compressibility and density are combined as psi=βρ. For isentropic compressibility, the speed ofsound is given as

c2 = 1/ψ (3.7)

To calculate the field psi the barotropicCompressibilityModel reads in fixed values of compress-ibility for the liquid and vapour phases as psil,psiv respectively, along with a liquid saturationdensity, rholSat and saturation pressure psat. These values are often temperature dependent butsince the cavitatingFoam solver is isothermic they are read in as constant. From these values asaturation vapour density is also calculated, rhovSat = psiv/psat.

Three different models for the compressibility are implemented as follows. An entry in theconstant/thermophysicalProperties dictionary in the case files is used to determine which of thethree models is used to calculate psi.

3.3.1 Linear

The linear model creates ψ, psi, asψ = αvψv + αlψl (3.8)

The implementation is located with the file linear.C in the linear directory of the library.

linear.C

77 void Foam::compressibilityModels::linear::correct()

78 {

79 psi_ = gamma_*psiv_ + (scalar(1) - gamma_)*psil_;

80 }

3.3.2 Wallis

The Wallis model creates ψ, psi, as

ψ = (αvρv,sat + αlρl,sat)

(αv

1

psat+ αl

ψl

ρl,sat

)(3.9)

The implementation is located with the file Wallis.C in the Wallis directory of the library.

Wallis.C

89 void Foam::compressibilityModels::Wallis::correct()

90 {

91 psi_ =

92 (gamma_*rhovSat_ + (scalar(1) - gamma_)*rholSat_)

93 *(gamma_/pSat_ + (scalar(1) - gamma_)*psil_/rholSat_);

94 }

3.3.3 Chung

The Chung model creates ψ, psi, as

sfa =

√psat

αlpsat + αvρl,sat/ψl(3.10)

ψ =

[(αl√ψv

+αvsfa√ψl

)√ψlψv

sfa

]2

(3.11)

The implementation is located with the file Chung.C in the Chung directory of the library.

24

3.3. barotropicCompressibilityModel Chapter 3. Homogeneous Equilibrium Model (HEM)

Chung.C

88 void Foam::compressibilityModels::Chung::correct()

89 {

90 volScalarField sfa

91 (

92 sqrt

93 (

94 pSat_

95 /((scalar(1) - gamma_)*pSat_ + gamma_*rholSat_/psil_)

96 )

97 );

98

99 psi_ = sqr

100 (

101 ((scalar(1) - gamma_)/sqrt(psiv_) + gamma_*sfa/sqrt(psil_))

102 *sqrt(psiv_*psil_)/sfa

103 );

104 }

Speeds of sound for the three models have been calculated using equation (3.7) for density,compressibility and pressure values provided in the throttle case with cavitatingFoam in the Open-FOAM tutorial library. The results shown in Figure 3.1 highlight the differences between the linearmodel and the Chung and Wallis models which are share more similarity and describe the speed ofsound in a more physical way.

Figure 3.1: Sound speeds for different compressibility models

25

Chapter 4

rhoCentralFoamHEM

This chapter details the modifications which can be made to the rhoCentralFoam solver to enableto consideration of a two-phase vapour liquid flow by the implementing of the Homogeneous Equi-librium Model (HEM). This is carried out through a combination with a multiphase library fromanother solver, the implementation for a new compressibility and speed of sound calculation and themodification of the routines for the thermophysical correcting.

To begin, we copy the solver rhoCentralFoam to our own working directory in order to work ona modified version without risk to the original source code.

foam

cp -r --parents applications/solvers/compressible/rhoCentralFoam $WM_PROJECT_USER_DIR

We then navigate to our work space and move the solver to a modified name - rhoCentralFoamHEMand change the name of the main C source code file.

usol

cd compressible/

mv rhoCentralFoam rhoCentralFoamHEM

cd rhoCentralFoamHEM

mv rhoCentralFoam.C rhoCentralFoamHEM.C

Inside the solver directory we clean up by removing the rhoCentralDyMFoam which is another mod-ification of the solver with dynamic mesh capabilities and change the names from rhoCentralFoam

to rhoCentralFoamHEM throughout the main solver and Make/files file. The final changes to makebefore an initial compilation are the locations to compile to. In both he solver and boundary con-dition library these are modified with a _USER_ element added to create the code in our own workspace.

rm -r rhoCentralDyMFoam

sed -i s/rhoCentralFoam/rhoCentralFoamHEM/g rhoCentralFoamHEM.C

sed -i s/rhoCentralFoam/rhoCentralFoamHEM/g Make/files

sed -i s/FOAM_APPBIN/FOAM_USER_APPBIN/g Make/files

sed -i s/FOAM_LIBBIN/FOAM_USER_LIBBIN/g BCs/Make/files

We can now compile our copy of the code to ensure the first steps have been completed successfully.

wmake libso BCs

wmake

4.1 Copying, compiling and linking a multiphase thermo-physical library

The first major modification to make is to include the structure for two different thermophysicalmodels, so that each phase can be modelled according to its individual properties. In order to

26

4.1. Addition of a multiphase thermophysical library Chapter 4. rhoCentralFoamHEM

implement this here a two phase library from the solver compressibleInterFoam is copied to thedirectory. compressibleInterFoam is a pressure-based solver for two compressible fluids whichapplied a volume of fluid (VOF) method to capture the fluids’ interface. Although we will create aHEM model and will not work with an interface, this library is still well suited to the needs of thiscase.

The full original code for the library can be found in the$FOAM_SOLVERS/multiphase/compressibleInterFoam directory and as with the solver we beginthe modifications to the library with renaming files and text within to update to a new name.

cp -r $FOAM_SOLVERS/multiphase/compressibleInterFoam/twoPhaseMixtureThermo MytwoPhaseMixtureThermo

cd MytwoPhaseMixtureThermo

mv twoPhaseMixtureThermo.C MytwoPhaseMixtureThermo.C

mv twoPhaseMixtureThermo.H MytwoPhaseMixtureThermo.H

sed -i s/FOAM_LIBBIN/FOAM_USER_LIBBIN/g Make/files

sed -i s/twoPhaseMixtureThermo/MytwoPhaseMixtureThermo/g Make/files

sed -i s/twoPhaseMixtureThermo/MytwoPhaseMixtureThermo/g MytwoPhaseMixtureThermo.*

Once everything has been renamed we can begin to make modifications where necessary. The mixturemodel is created using U and phi as input. To construct phi in the rhoCentralFoam solver we takethe flux of rhoU which is constructed using rho. rho therefore needs to be available before we setphi. In this setup we will use the mixture model itself to create rho. For our implementation of themodel, the phi variable is not actually used and so it is removed or commented out in the C file asseen below so the only input is the field U.

Modified MytwoPhaseMixtureThermo.C constructor

44 Foam::MytwoPhaseMixtureThermo::MytwoPhaseMixtureThermo

45 (

46 const volVectorField& U

47 )

The equivalent change needs to be made in the header file.

Modified MytwoPhaseMixtureThermo.H constructor

76 // Constructors

77

78 //- Construct from components

79 MytwoPhaseMixtureThermo

80 (

81 const volVectorField& U

82 );

After phi is removed from both the MytwoPhaseMixtureThermo.C and MytwoPhaseMixtureThermo.H

files we can eliminate other elements which are not needed. On line 44 we remove the line#include "interfaceProperties" from the header file along with the associated functionality inboth the .H and .C files.

Modified MytwoPhaseMixtureThermo.H include section

41 #include "rhoThermo.H"

42 #include "psiThermo.H"

43 #include "twoPhaseMixture.H"

Also remove public interfaceProperties on line 58, and the comma before it on line 57 fromthe .H header file. Now remove interfaceProperties(alpha1(), U, *this) from line 51 inMytwoPhaseMixtureThermo.C. We need to remove accompanying functions from the .C file suchas theinterfaceProperties::correct(); from line 102 in the correct() function and the following func-tion at bottom of .C file

27

4.2. Utilising two phase library Chapter 4. rhoCentralFoamHEM

Interface properties function to be removed

1 bool Foam::MytwoPhaseMixtureThermo::read()

2 {

3 if (psiThermo::read())

4 {

5 return interfaceProperties::read();

6 }

7

8 return false;

9 }

along with its declaration in the .H file virtual bool read(); After these modifications we cancompile the library

wmake libso

We can now return to the solver in the directory above. In the main file rhoCentralFoam.C addthe line #include "MytwoPhaseMixtureThermo.H" with the other include files at the top to accessthe multiphase thermo library and include this in the Make/options file for the solver. This is doneby adding two lines to the EXE_INC and three to the EXE_LIBS sections. To the first add

Make/options EXE INC additions

1 -I$(LIB_SRC)/transportModels/twoPhaseMixture/lnInclude \

2 -IMytwoPhaseMixtureThermo \

and to the second,

Make/options EXE LIB additions

1 -L$(FOAM_USER_LIBBIN) \

2 -ltwoPhaseMixture \

3 -lMytwoPhaseMixtureThermo \

Compiling the solver with wmake now has the library linked to it.

4.2 Utilising two phase library

To use the new library, firstly the old thermophysical model initialisation in createFields is removedalong with the energy variable initialisation, e - so lines 3-11 are commented out or erased. Afterthe velocity vector field is created the new thermo model is used as seen below. These lines areadded under the U definition

Info<< "Constructing twoPhaseMixtureThermo\n" << endl;

MytwoPhaseMixtureThermo mixture(U);

Once the mixture is constructed, phase fraction fields are setup. alpha1 and alpha2 are the phasefractions of phase 1 and phase 2 respectively. Initial values are required to set up these fields. Theyare set in the 0 time directory in case files for the simulation and extracted by the twoPhaseMixturelibrary which is accessed using mixture. Add these lines of code under the twoPhaseMixtureThermois introduced.

volScalarField& alpha1(mixture.alpha1());

volScalarField& alpha2(mixture.alpha2());

As part of the HEM model quantities are calculated as weighted averages across the domainusing the phase fraction fields. The energy field e is initialised here then set up as

e = αev + (1− α)el (4.1)

Add these lines after the definition of the phase fractions alpha1, alpha2

28

4.2. Utilising two phase library Chapter 4. rhoCentralFoamHEM

volScalarField& e = mixture.thermo1().he();

e = alpha1*mixture.thermo1().he()+alpha2*mixture.thermo2().he();

Density is created also as a weighted average.

volScalarField rho

(

IOobject

(

"rho",

runTime.timeName(),

mesh,

IOobject::READ_IF_PRESENT,

IOobject::AUTO_WRITE

),

alpha1*mixture.thermo1().rho() + alpha2*(mixture.thermo2().rho())

);

Next in createFields.H the setup of the turbulence model is modified so that thermo is replaced withmixture.

In the createFieldRefs.H file we need to change thermo to mixture and the definition of T asshown below in the modified code. The psi is removed from the file too since this will be definedlater in createFields.H. We also modify mu so that if either of mu values in thermo properties is 0- then simulation runs as inviscid.

volScalarField& p = mixture.p();

volScalarField& T = mixture.T();

const volScalarField& mu = mixture.thermo1().mu()*mixture.thermo2().mu();

With the structure now in place for a multiphase thermophysical model we now need to evaluatethe phase fraction. This is done by considering density, rho. In the HEM model, we saw incavitatingFoam the phase fraction was calculated as

α =ρ− ρl

ρv − ρl(4.2)

with the density ρ, and the read in saturation densities for vapour and liquid phases ( ρv, rhovSatand ρl, rholSat). The isothermal nature of that solver meant constant values of saturation densityρv, ρl could be used. In this temperature varying solver the values will instead be temperaturedependent using a lookup table functionality.

Returning to modify createFields.H, first add the following fields for the liquid and vapoursaturation density field, ρv − ρl.

volScalarField rhovSat

(

IOobject

(

"rhovSat",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::AUTO_WRITE

),

mesh,

dimensionedScalar("rhovSat", dimDensity, 1.0)

29

4.2. Utilising two phase library Chapter 4. rhoCentralFoamHEM

);

volScalarField rholSat

(

IOobject

(

"rholSat",

runTime.timeName(),

mesh,

IOobject::NO_READ,

IOobject::AUTO_WRITE

),

mesh,

dimensionedScalar("rholSat", dimDensity, 1.0)

);

The fields will be calculated in each time-step as the temperature is updated using a lookup datatable provided in the constant directory for the simulation case files. A pair of two column .dattables are used to interpolate the saturation vapour and liquid densities using temperature as input.These are setup in create fields using the lines of code below which can be placed underneath thedefinitions of the saturation densities.

interpolationTable<scalar> tempSeriesRhovSat

(

runTime.path()/runTime.caseConstant()/"rhovSat.dat"

);

interpolationTable<scalar> tempSeriesRholSat

(

runTime.path()/runTime.caseConstant()/"rholSat.dat"

);

To use these interpolation tables, the line #include "interpolationTable.H" needs to be addedat the top of the rhoCentralFoamHEM.C file.

The tables need to contain the data for densities along the saturation line. This saturation lineruns between the critical point and triple point and so there is only a certain temperature rangewhich has the density data available. The minimum and maximum temperature values are read infrom the thermophysicalProperties file and are used to limit any extrapolation of the data lateron in the calculation of α. The following lines need to be added to createFields.H to read in thesevalues

Info<< "Reading thermophysical properties\n" << endl;

IOdictionary thermophysicalProperties

(

IOobject

(

"thermophysicalProperties",

runTime.constant(),

mesh,

IOobject::MUST_READ_IF_MODIFIED,

IOobject::NO_WRITE

)

);

scalar TmaxSat(readScalar(thermophysicalProperties.lookup("TmaxSat")));

scalar TminSat(readScalar(thermophysicalProperties.lookup("TminSat")));

We continue and add the calculation of the phase fraction. Create file calcAlpha.H to do this byfirst looping over all the cells and using the temperature in each to determine the saturation densitiesand then secondly addressing the boundaries of the domain in a similar manner.

30

4.2. Utilising two phase library Chapter 4. rhoCentralFoamHEM

calcAlpha.H

1 forAll ( alpha1, celli) //loop through cell centres

2 {

3 if(T[celli]>TmaxSat)

4 {

5 rhovSat[celli] = rho[celli];

6 rholSat[celli] = rhovSat[celli]*2;

7 }

8 else

9 {

10 if(T[celli]<TminSat)

11 {

12 rholSat[celli] = rho[celli]*2;

13 rhovSat[celli] = rho[celli];

14 }

15 else

16 {

17 rhovSat[celli] = tempSeriesRhovSat(T[celli]);

18 rholSat[celli] = tempSeriesRholSat(T[celli]);

19 }

20 }

21 alpha1[celli]=(rho[celli]-rholSat[celli])/(rhovSat[celli]-rholSat[celli]);

22 }

23

24 forAll ( mesh.boundaryMesh() , ipatch ) {

25

26 if(alpha1.boundaryField()[ipatch].type()!=fixedValueFvPatchScalarField::typeName)

27 {

28 fvPatchScalarField& faces_alpha = alpha1.boundaryFieldRef()[ipatch];

29

30 forAll(faces_alpha, faceI) // Loop over each face of the patch

31 {

32 if(T.boundaryField()[ipatch][faceI]>TmaxSat)

33 {

34 rhovSat.boundaryFieldRef()[ipatch][faceI] = rho.boundaryFieldRef()[ipatch][faceI];

35 rholSat.boundaryFieldRef()[ipatch][faceI] = rhovSat.boundaryFieldRef()[ipatch][faceI

]*2;

36 }

37 else

38 {

39 if(T.boundaryField()[ipatch][faceI]<TminSat)

40 {

41 rholSat.boundaryFieldRef()[ipatch][faceI] = rho.boundaryFieldRef()[ipatch][faceI

]*2;

42 rhovSat.boundaryFieldRef()[ipatch][faceI] = rho.boundaryFieldRef()[ipatch][faceI];

43 }

44 else

45 {

46 rhovSat.boundaryFieldRef()[ipatch][faceI] = tempSeriesRhovSat(T.boundaryField()[

ipatch][faceI]);

47 rholSat.boundaryFieldRef()[ipatch][faceI] = tempSeriesRholSat(T.boundaryField()[

ipatch][faceI]);

48 }

49 }

50 faces_alpha[faceI] = (rho.boundaryField()[ipatch][faceI]-rholSat.boundaryField()[ipatch][

faceI])/(rhovSat.boundaryField()[ipatch][faceI] - rholSat.boundaryField()[ipatch][faceI]);

51 faces_alpha[faceI] = min(1.0,max(faces_alpha[faceI],0.0));

52 }

53 }

54 }

55 alpha1 = min(1.0,max(alpha1,0.0));

56 alpha2 = 1-alpha1;

The saturation density fields are calculated by looping through the cells, checking if each one iswithin the temperature range [Tmin, Tmax]. For those cells outside the range, the density is setto create αv = 1 and no liquid fraction is observed. Other measures could be later introducedto account for the supercritical state at T>Tmax and at temperature underneath Tmin the phases

31

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

would likely consist of a gas state with small solid particles, since no liquid can exist at this condition,but for simplicity here a vapour phase is assumed in both cases. Inside of the range the saturationdensities are looked up from the tables using the temperature of the cell. The phase fractions arethen calculated using these fields. In the main solver file add the line #include "calcAlpha.H"

just after the solving of the density equation on line 196

4.3 Speed of Sound and compressibility

In the HEM model, the speed of sound is constructed from a combination of the compressibilities ofeach phase present. Unlike many of the thermal properties the speed of sound and compressibilityare not usually created as simple weighted averages using the phase fraction. Instead they are alteredto reflect a more complex physical effect arising in the multiphase mixture. A vapour liquid mixturemay exhibit a speed of sound lower than either of it’s components in single phase isolation [13].

4.3.1 barotropicCompressibilityModel Modifications

The barotropicComressibilityModel was examined in Chapter 3 with three different models tocalculate the compressibility of a mixture. That library will be copied to this solver and modifiedto account for some of the temperature dependent properties such as the saturation densities.

In the main solver directory, copy down the barotropic library as follows.

cp -r $FOAM_SRC/thermophysicalModels/barotropicCompressibilityModel .

cd barotropicCompressibilityModel

sed -i s/FOAM_LIBBIN/FOAM_USER_LIBBIN/g Make/files

sed -i s/libbarotropic/libMybarotropic/g Make/files

As seen in Chaper 3, the barotropicCompressibilityModel is set up to read constant scalarsrholSat, psil, psiv, pSat from the constant/thermophysicalProperties folder in the casefiles. To modify this library here we instead want to supply the saturation density fieldsrhovSat, rholSat to the model and only read in constant values for the compressibilities, psil, psiv.

This requires substantial changes to the constructors of the classes in the library. If we openthe file barotropicCompressibilityModel/barotropicCompressibilityModel.C we see the defi-nition of the constructor for the class -

barotropicCompressibilityModel.C

Foam::barotropicCompressibilityModel::barotropicCompressibilityModel

(

const dictionary& compressibilityProperties,

const volScalarField& gamma

const word& psiName

)

:

compressibilityProperties_(compressibilityProperties),

psi_

(

IOobject

(

psiName,

gamma.mesh().time().timeName(),

gamma.mesh()

),

gamma.mesh(),

dimensionedScalar(dimensionSet(0, -2, 2, 0, 0), Zero)

),

gamma_(gamma)

{}

We need to modify this file and many others in the library in a similar fashion - with the additionof the volScalarFields rhovSat and rholSat as inputs. Change the section to the code below.

32

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

Modified barotropicCompressibilityModel.C

Foam::barotropicCompressibilityModel::barotropicCompressibilityModel

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

)

:

compressibilityProperties_(compressibilityProperties),

psi_

(

IOobject

(

psiName,

gamma.mesh().time().timeName(),

gamma.mesh()

),

gamma.mesh(),

dimensionedScalar(dimensionSet(0, -2, 2, 0, 0), Zero)

),

gamma_(gamma),

rhovSat_(rhovSat),

rholSat_(rholSat)

{}

The header file barotropicCompressibilityModel/barotropicCompressibilityModel.H alsorequires extensive changes to update the model to accept the saturation densities. The protecteddata elements are extended to include these as is the declareRunTimeSelectionTable among otherthings. The full modified file is given below. Modify the header file to this:

Modified barotropicCompressibilityModel.H

\*---------------------------------------------------------------------------*/

#ifndef barotropicCompressibilityModel_H

#define barotropicCompressibilityModel_H

#include "IOdictionary.H"

#include "typeInfo.H"

#include "runTimeSelectionTables.H"

#include "volFields.H"

#include "dimensionedScalar.H"

#include "autoPtr.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

{

/*---------------------------------------------------------------------------*\

Class barotropicCompressibilityModel Declaration

\*---------------------------------------------------------------------------*/

class barotropicCompressibilityModel

{

protected:

// Protected data

dictionary compressibilityProperties_;

volScalarField psi_;

const volScalarField& gamma_;

const volScalarField& rhovSat_;

33

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

const volScalarField& rholSat_;

// Private Member Functions

//- No copy construct

barotropicCompressibilityModel

(

const barotropicCompressibilityModel&

) = delete;

//- No copy assignment

void operator=(const barotropicCompressibilityModel&) = delete;

public:

//- Runtime type information

TypeName("barotropicCompressibilityModel");

// Declare run-time constructor selection table

declareRunTimeSelectionTable

(

autoPtr,

barotropicCompressibilityModel,

dictionary,

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

),

(compressibilityProperties, gamma, rhovSat, rholSat, psiName)

);

// Selectors

//- Return a reference to the selected compressibility model

static autoPtr<barotropicCompressibilityModel> New

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

// Constructors

//- Construct from components

barotropicCompressibilityModel

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

//- Destructor

virtual ~barotropicCompressibilityModel() = default;

// Member Functions

//- Return the phase transport properties dictionary

34

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

const dictionary& compressibilityProperties() const

{

return compressibilityProperties_;

}

//- Return the compressibility

const volScalarField& psi() const

{

return psi_;

}

//- Correct the compressibility

virtual void correct() = 0;

//- Read compressibilityProperties dictionary

virtual bool read(const dictionary& compressibilityProperties) = 0;

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

Finally within the barotropicCompressibilityModel folder the filebarotropicCompressibilityModelNew is modified. The const volScalarField references are addedonce again for rhovSat and rholSat in the constructor at the top of the file, as seen inbarotropicCompressibilityModel.C and at the end the return function is modified to

return autoPtr<barotropicCompressibilityModel>

(

cstrIter()(dict, gamma, rhovSat, rholSat, psiName)

);

Each of the three compressibility models available (linear, Wallis and Chung) has its own folderwith files for the implementation. In each model, add the rholSat, rhovSat to the constructors asseen in the general barotropicCompressibilityModel files above. The full modified files can all befound in the appendix and in accompanying files for a fully implemented example to use/refer to.

In the linear model the compressibility field psi is a weighted average of the constants psil, psiv

however in the Chung and Wallis models the saturation density is used and a modification is madehere to no longer read it in from the case files. In the Wallis/Wallis.C file the following elementsare removed from the constructor,

To remove from Wallis/Wallis.C

pSat_

(

"pSat",

dimPressure,

compressibilityProperties_

),

.

.

rhovSat_(psiv_*pSat_),

rholSat_

(

"rholSat",

dimDensity,

compressibilityProperties_

)

35

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

When removing elements of a list such as these take care with commas which may end up hangingat the end of lists where previously another entry followed. So here take care to remove the commafollowing the psil entry since the list now finishes here. We have also removed the pSat entry fromthe variables to read in as seen above. Everywhere in the psi calculation therefore the pSat variableneeds to replaced with rhovSat/psiv from the rhovSat definition. Update the psi calculation online 89 to the following

Modified psi calculation in Wallis.C

void Foam::compressibilityModels::Wallis::correct()

{

psi_ =

(gamma_*rhovSat_ + (scalar(1) - gamma_)*rholSat_)

*(gamma_*psiv_/rhovSat_ + (scalar(1) - gamma_)*psil_/rholSat_);

}

Finally in the Wallis.C file update the read function at the bottom of the file by removing thelines regarding pSat, rholSat.

For the Chung model, follow the same outline as we have carried out for the Wallis files. Thepsi calculation for this model should match the following code.

Modified psi calculation in Chung.C

void Foam::compressibilityModels::Chung::correct()

{

volScalarField sfa

(

sqrt

(

rhovSat_/psiv_

/((scalar(1) - gamma_)*rhovSat_/psiv_ + gamma_*rholSat_/psil_)

)

);

psi_ = sqr

(

((scalar(1) - gamma_)/sqrt(psiv_) + gamma_*sfa/sqrt(psil_))

*sqrt(psiv_*psil_)/sfa

);

}

Once the library has been modified we need to compile it to test.

wmake libso

Return to the main solver directory and add the line#include "barotropicCompressibilityModel.H" to the top of rhoCentralFoamHEM.C. Modifythe Make/options file with these additions.

Additions to the solver Make/options file

EXE_INC = \

.

.

-IbarotropicCompressibilityModel/lnInclude \

.

EXE_LIBS = \

.

.

-lMybarotropicCompressibilityModel \

.

Once the library is linked to the solver we can now use it to create the compressibility model forpsi. Add the following code to the createFields.H

36

4.3. Speed of Sound and compressibility Chapter 4. rhoCentralFoamHEM

Info<< "Creating compressibilityModel\n" << endl;

autoPtr<barotropicCompressibilityModel> psiModel =

barotropicCompressibilityModel::New

(

thermophysicalProperties,

alpha1,

rhovSat,

rholSat

);

const volScalarField& psi = psiModel->psi();

After the calculation of the phase fraction at the top of the time loop, add the linepsiModel->correct();. This corrects the compressibility field when the phase fraction is recalcu-lated here.

#include "calcAlpha.H"

psiModel->correct();

4.3.2 Speed of sound

Also needing to be addressed is the speed of sound. This is defined based on psi for the originalsolver due to an assumption about speed of sound in gases. For liquids however, the higher valuesof psi found for liquids, which mean higher density according to rho = psi/p would give very lowspeed of sound values since c=sqrt(psi*cp/cv) using an ideal gas equation. The more generalequation 2.9 for speed of sound in liquids is used, with bulk modulus of the fluid and density used.Bulk modulus is read in as K from the liquid thermophysical properties directory for the liquidphase.

In the createFields.H add to the bottom of the file the following code which allows the solverto read in the thermophysicalProperties.liquid file in the constant directory and then read inthe bulk modulus, K.

IOdictionary thermophysicalPropertiesLiquid

(

IOobject

(

"thermophysicalProperties.liquid",

runTime.constant(),

mesh,

IOobject::MUST_READ_IF_MODIFIED,

IOobject::NO_WRITE

)

);

dimensionedScalar K(dimPressure,readScalar(thermophysicalPropertiesLiquid.lookup("K")));

Using this the speeds of sound in both the vapour and liquid can be added to the solver code.At the location in the code where the speed of sound, c, is created in each time step, we renamethis to cv and modify it to use the psiv value. Then a similar field is created for speed of sound inthe liquid. Finally the speed of sound of the mixture is initialised as a weighted average of the twovalues.

volScalarField cv("cv", sqrt(mixture.thermo1().Cp()/mixture.thermo1().Cv()/mixture.

thermo1().psi()));

volScalarField cl("cl", sqrt(K/rholSat));

volScalarField c("c", 1/sqrt((alpha1*rhovSat + alpha2*rholSat)*(alpha1/rhovSat/sqr(cv)

+ alpha2/rholSat/sqr(cl))));

37

4.4. Temperature calculation Chapter 4. rhoCentralFoamHEM

4.4 Temperature calculation

In the original solver we have thermo.correct, which updates the thermophysical model elementsincluding the temperature and thermal properties. The solver works in E, the energy variable, ande, which is either enthalpy or internal energy, depending on the configuration of the problem in thecase files. Temperature needs to be calculated and updated from this throughout the simulation inorder to update other quantities. The function thermo.correct calculates temperature using theTHE (Temperature (T) from enthalpy or internal energy (HE)) function to further access a chainof functions in the thermo library. The final function call is to a function called T which employsa Newton-Raphson routine to solve temperature to within a certain tolerance. The T function isfound in the\$FOAM_SRC/thermophysicalModels/specie/rhermo/thermo/thermoI.H file for reference.

In the twoPhaseMixtureThermo model we have used here we can see on line 164 that the THEfunction is not implemented and will simply return the old temperature and therefore not updateit.

MytwoPhaseMixtureThermo.C

164 Foam::tmp<Foam::scalarField> Foam::MytwoPhaseMixtureThermo::THE

165 (

166 const scalarField& h,

167 const scalarField& p,

168 const scalarField& T0,

169 const labelList& cells

170 ) const

171 {

172 NotImplemented;

173 return T0;

174 }

To rectify, a version of the function T is used here in a calcT.H file to solve and update thetemperature for the two phase mixture. Create the following file in the main solver directory.

calcT.H

1 Info << "calculating T for mixture" << endl;

2 // Code to solve for temperature T of mixture from internal energy e

3

4

5 const volScalarField T0 = T;

6 const volScalarField f = e;

7

8 volScalarField Test = T0;

9 volScalarField Tnew = T0;

10 volScalarField eTol = e*1.0e-4;

11

12 volScalarField F = mixture.he(p,T0);

13 volScalarField dFdT = mixture.Cp();

14

15 T = Test;

16

17 mixture.correctThermo();

18 mixture.correct();

19

20 int iter = 0;

21 do

22 {

23 Test = T;

24 F = mixture.he(p,Test);

25 dFdT = mixture.Cp();

26

27 Tnew = T - (F-f)/dFdT;

28 T = Tnew;

29

30 #include "calcAlpha.H"

38

4.4. Temperature calculation Chapter 4. rhoCentralFoamHEM

31

32 mixture.correctThermo();

33 mixture.correct();

34

35 if (iter++ > 200)

36 {

37 FatalErrorInFunction

38 << "Maximum number of iterations exceeded: 200" << abort(FatalError);

39 }

40 } while (max(mag(T - Test)).value() > 250*1e-4);

Include the solution in place of the two locations where thermo.correct appears in the mainsolver with the line #include "calcT.H"

39

Chapter 5

Multi-phase jet tutorial case

This chapter describes the set up for a tutorial using the modified solver rhoCentralFoamHEM.The tutorial case is similar in structure and application to the LadenburgJet tutorial from therhoCentralFoam tutorials which was examined in Chapter 2. A larger domain is used to capturemore features of the under-expanded jet and the release of the jet is now comprised of vapour-liquidmixture, making use of the multi-phase modifications to the original solver. Within the accompa-nying files the case HEMcase is provided with this tutorial and all the files needed to run the case.

In this chapter the additional files required by the solver and any extra features are discussedand examined and the case is run to observe the results for the multi-phase jet release. The out-line of the case structure is given below, and modifications needed from the Ladenburg jet case arethe introduction of an initial phase fraction condition, given in the 0 folder as alpha.vapour, anda change to the thermophysicalProperties files in the constant directory. In place of the one filefound previously there is now one very minimal general file, thermophysicalProperties, and twofurther files to give the detailed specifications and thermophysical model definitions for each phase -found in thermophysicalProperties.vapour and thermophysicalProperties.liquid here sincevapour and liquid are the two phases we work with. There are also two data tables provided inthe constant directory - for the temperature dependent saturation densities for liquid and vapour.These new files are the rholSat.dat, rhovSat.dat files that are used in the lookup table approachimplemented in the solver. The files in the system directory require no specific changes as a resultof the modifications to the solver, although as mentioned above small modifications to the domainsizing and mesh have been made from the standard tutorial in the blockMeshDict file. No changesare required in the fvSchemes or fvSolution files.

In the LadenburgJet tutorial the run times for the case are longer than desired for an examplecase and a well converged solution was included in the files in the 0 directory with the 0.orig folderproviding all the initial conditions. In the interest of time, the same process is used here since therun time remains long.

40

5.1. Domain configuration Chapter 5. Multi-phase jet tutorial case

HEMcase

0.orig % Initial conditions for the time 0

0 % Well advanced solution to shorten run time

p

U

T

alpha.vapour % Initial condition for the vapour phase fraction

constant

thermophysicalProperties % Short file with properties for both phases

thermophysicalProperties.liquid % Thermophysical properties for the liquid phase

thermophysicalProperties.vapour % Thermophysical properties for the vapour phase

turbulenceProperties

rhovSat.dat % Saturation data for the vapour phase

rholSat.dat % Saturation data for the liquid phase

system

blockMeshDict

controlDict

fvSchemes

fvSolution

5.1 Domain configuration

The domain is constructed for an axisymmetric case of 2D front/back face dimensions 5x15mm (Fig-ure 5.1. An inlet of height 0.5mm is used to represent the outlet of a nozzle or release with a 1mmdiameter, D. As seen in the LadenburgJet case the remaining boundaries are a symmetry boundarywhich runs along the centre of the jet and an outlet on right hand side patch. The boundary at thetop of the domain is labelled freestream and above the inlet the patch is labelled freestreamInlet

which completes the left hand side of the domain.

The enlargement of the domain to extend the length, L, to capture L/D=15 means more of thedownstream region of the jet is included than in the original case and an increased height of thedomain allows the expansion to free to fully develop in the region.

The mesh has been refined only a small amount for this example and is too course for any detailedstudy but allows short enough run times to illustrate the potential of the solver. The detail is moreimportant near to the core of the jet so refinement is focused these with larger cells at the edge ofthe domain towards the freestream boundary as seen in Figure 5.2

41

5.2. Boundary Conditions Chapter 5. Multi-phase jet tutorial case

Figure 5.1: Geometry for test case

Figure 5.2: Mesh for test case

5.2 Boundary Conditions

The boundary conditions applied for the fields, p, T, U are largely similar to those applied in theLadenburgJet case and are seen here in Table 5.1.

p T U

inlet fixedValue fixedValue fixedValue

outlet waveTransmissive zeroGradient inletOutlet

freestream totalPressure zeroGradient zeroGradient

freestreamInlet zeroGradient zeroGradient noSlip

Table 5.1: Boundary conditions: tutorial case

The new file required by the solver is for the phase fraction field. The alpha.vapour file in the0 directory provides the initial phase fraction and boundary conditions as seen here:

alpha.vapour

17 dimensions [0 0 0 0 0 0 0];

18

19 internalField uniform 1.0;

20

21 boundaryField

22 {

23 inlet

24 {

25 type fixedValue;

42

5.3. ThermophysicalProperties Chapter 5. Multi-phase jet tutorial case

26 value uniform 0.8;

27 }

28

29 outlet

30 {

31 type zeroGradient;

32 value uniform 1.0;

33 }

34

35 freestream

36 {

37 type zeroGradient;

38 value uniform 1.0;

39 }

40

41 freestreamInlet

42 {

43 type zeroGradient;

44 value uniform 1.0;

45 }

46

47 wedge1 {type wedge;}

48 wedge2 {type wedge;}

49 }

The domain is initially set with alpha.vapour=1.0 so that the composition is 100% vapour atthe beginning of the simulation. At the inlet the multiphase aspect of the solver is utilised and arelease comprising of 20% liquid and 80% vapour is fixed. Other boundaries take a zeroGradient

condition here to provide no fixed value or phase fraction across the domain.

5.3 ThermophysicalProperties

The main thermophysical properties is now a very simplified file compared to most cases. It containsthe list of phases working in the simulation, here chosen to be vapour and liquid. These namings areimportant and the other thermophysicalProperties files must be appended with these identificationsto be read in successfully, although as long as that structure is retained they could have othersuitable names.

thermophysicalProperties

17 phases (vapour liquid);

18 TminSat 216.59;

19 TmaxSat 304.13;

20

21 barotropicCompressibilityModel linear;

22

23 psil 6.7e-04;

24 psiv 3.3e-05;

For the lookup table approach used to calculate saturation densities there is a minimum and max-imum temperature needed in the solver which was used in the calcAlpha.H file which we intro-duced. These values for temperature are read in here from the thermophysicalProperties file asTmaxSat, TminSat.

Next the compressibility values, psiv and —psil—, are also read in from this file for both theliquid and vapour phases along with the choice of compressibility model. These psi values are oftentermed compressibility in OpenFOAM and have units s2/m.

The liquid and vapour thermophysicalProperties files look more conventional as they are usedas in other cases to construct a thermophysical model for each of the phases. Here for each of thephases very similar files are used since the bulk of the transport and thermodynamic modellingremains the same for simplicity. The key change between the two files is in the equation of state(EOS) which provides the closure between the thermophysical variables. The vapour phase utilises

43

5.4. Saturation densities Chapter 5. Multi-phase jet tutorial case

the perfectGas EOS (Eq. (5.1)) and the perfectFluid EOS (Eq. (5.2)) is used in the liquid phaseto ensure realistic density modelling. The equations are given by,

ρ =1

RTp (5.1)

ρ =1

RTp + ρ0 (5.2)

and only differ in the addition of a reference density ρ0 in the perfectFluid implementationwhich is the density at T=0.

A potentially preferable modification for future use would be the implementation of a full cubicEOS which could take into account the vapour and liquid phases of a material. Additionally in theliquid file a bulk modulus K is required for the construction of the speed of sound in the liquid.

thermophysicalProperties.liquid

17 thermoType

18 {

19 type heRhoThermo;

20 mixture pureMixture;

21 transport const;

22 thermo hConst;

23 equationOfState perfectFluid;

24 specie specie;

25 energy sensibleEnthalpy;

26 }

27

28 mixture

29 {

30 specie

31 {

32 molWeight 44.01;

33 }

34 thermodynamics

35 {

36 Cp 1040;

37 Hf 0;

38 }

39 transport

40 {

41 As 1.458e-06;

42 Ts 110.4;

43 Pr 0.7;

44 mu 0;

45 }

46 equationOfState

47 {

48 rho0 1100;

49 R 188.92;

50 }

51 }

5.4 Saturation densities

The density along the saturation line for both the liquid and vapour phases is critical in deter-mining the phase fraction of the flow throughout the simulation. The data files rhovSat.dat andrholSat.dat use data provided by the NIST database. Data for carbon dioxide is used since it isof frequent interest in these applications. The saturation densities can be seen in Figure 5.3 andare functions of the temperture along the saturation line. This data is provided between the triplepoint location (where all three phases of solid, liquid and gas can coexist) at ≈ 216K and the criticalpoint above which supercritical phase is exhibited at ≈ 304K

44

5.5. Results Chapter 5. Multi-phase jet tutorial case

Figure 5.3: Saturation densities for carbon dioxide

The structure of the data files can be seen here for the liquid phase as an example. The 2 columnformat contains temperatures in column one and corresponding liquid densities in column two.

Beginning of rholSat.dat

1 601 //Temperature (K) "//Density (l, kg/m3)"

2 (

3 ( 216.59 1178.5 )

4 ( 217.09 1176.7 )

5 ( 217.59 1174.9 )

6 ( 218.08 1173.1 )

7 ( 218.56 1171.4 )

8 ( 219.03 1169.7 )

9 .

10 .

5.5 Results

The tutorial case can simply be run using the commands blockMesh to construct the mesh andrhoCentraFoamHEM to use the modified solver. The case is for an under-expanded jet, whose structurecan be observed in Figures 5.4 and 5.5 which show the temperature and velocity of the multiphasejet. The results show a typical barrel shock associated with under-expanded flow and a clear shockdisc. The figure 5.6 shows the vapour phase fraction across the domain and the liquid fraction isfocused at the core of the jet near to the inlet. The region in the core of the jet where there is stillliquid fraction present corresponds with a warmer region in the temperature results in Figure 5.4.The significant expansion seen in the vapour phase region develops the low temperatures seen here.

45

5.5. Results Chapter 5. Multi-phase jet tutorial case

Figure 5.4: Temperature field

Figure 5.5: Velocity field

Figure 5.6: Vapour phase fraction

46

Bibliography

[1] C. J. Greenshields, H. G. Weller, L. Gasparini, and J. M. Reese, “Implementation of semi-discrete, non-staggered central schemes in a colocated, polyhedral, finite volume framework, forhigh-speed viscous flows,” International journal for numerical methods in fluids, vol. 63, no. 1,pp. 1–21, 2010.

[2] I. Choquet, “Thermophysicalmodels library in openfoam-2.3.x (or 2.4.x).”

[3] A. Kurganov, S. Noelle, and G. Petrova, “Semidiscrete central-upwind schemes for hyperbolicconservation laws and hamilton–jacobi equations,” SIAM Journal on Scientific Computing,vol. 23, no. 3, pp. 707–740, 2001.

[4] A. Kurganov and E. Tadmor, “New high-resolution central schemes for nonlinear conservationlaws and convection–diffusion equations,” Journal of Computational Physics, vol. 160, no. 1,pp. 241–282, 2000.

[5] R. Ladenburg, C. Van Voorhis, and J. Winckler, “Interferometric studies of faster than soundphenomena. part ii. analysis of supersonic air jets,” Physical Review, vol. 76, no. 5, p. 662, 1949.

[6] M. M. El-Wakil, “Nuclear heat transport.,” 1971.

[7] S. Brown, S. Martynov, H. Mahgerefteh, and C. Proust, “A homogeneous relaxation flow modelfor the full bore rupture of dense phase co2 pipelines,” International Journal of Greenhouse GasControl, vol. 17, pp. 349–356, 2013.

[8] M.-S. Chung, S.-B. Park, and H.-K. Lee, “Sound speed criterion for two-phase critical flow,”Journal of sound and vibration, vol. 276, no. 1-2, pp. 13–26, 2004.

[9] G. B. Wallis, One-dimensional two-phase flow. Dover Publications, 1967.

[10] S. W. Kieffer, “Sound speed in liquid-gas mixtures: Water-air and water-steam,” Journal ofGeophysical research, vol. 82, no. 20, pp. 2895–2904, 1977.

[11] H. R. A. Mallock, “The damping of sound by frothy liquids,” Proceedings of the Royal Societyof London. Series A, Containing Papers of a Mathematical and Physical Character, vol. 84,no. 572, pp. 391–395, 1910.

[12] F. Barclay, T. Ledwidge, and G. Cornfield, “Some experiments on sonic velocity in two-phaseone-component mixtures and some thoughts on the nature of two-phase critical flow,” in Pro-ceedings of the Institution of Mechanical Engineers, Conference Proceedings, vol. 184, pp. 185–194, SAGE Publications Sage UK: London, England, 1969.

[13] C. E. Brennen and C. E. Brennen, Fundamentals of multiphase flow. Cambridge universitypress, 2005.

47

Study questions

1. How does a density based solver differ from a compressible pressure based solver in Open-FOAM?

2. Why are primitive fields interpolated in both directions through cell faces in rhoCentralFoam?

3. Why are the momentum and energy equations solved in two stages for compressible viscousflows in rhoCentralFoam?

4. How is temperature calculated for the mixture in rhoCentralFoamHEM?

48

Appendix A

ModifiedbarotropicCompressibilityModel

A.1 barotropicCompressibilityModel

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011 OpenFOAM Foundation

Copyright (C) 2019 OpenCFD Ltd.

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Namespace

Foam::compressibilityModels

Description

Namespace for compressibility models.

Class

Foam::barotropicCompressibilityModel

Description

Abstract class for barotropic compressibility models

SourceFiles

barotropicCompressibilityModel.C

newbarotropicCompressibilityModel.C

49

A.1. barotropicCompressibilityModel Appendix A. Modified barotropicCompressibilityModel

\*---------------------------------------------------------------------------*/

#ifndef barotropicCompressibilityModel_H

#define barotropicCompressibilityModel_H

#include "IOdictionary.H"

#include "typeInfo.H"

#include "runTimeSelectionTables.H"

#include "volFields.H"

#include "dimensionedScalar.H"

#include "autoPtr.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

{

/*---------------------------------------------------------------------------*\

Class barotropicCompressibilityModel Declaration

\*---------------------------------------------------------------------------*/

class barotropicCompressibilityModel

{

protected:

// Protected data

dictionary compressibilityProperties_;

volScalarField psi_;

const volScalarField& gamma_;

const volScalarField& rhovSat_;

const volScalarField& rholSat_;

// Private Member Functions

//- No copy construct

barotropicCompressibilityModel

(

const barotropicCompressibilityModel&

) = delete;

//- No copy assignment

void operator=(const barotropicCompressibilityModel&) = delete;

public:

//- Runtime type information

TypeName("barotropicCompressibilityModel");

// Declare run-time constructor selection table

declareRunTimeSelectionTable

(

autoPtr,

barotropicCompressibilityModel,

dictionary,

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

),

(compressibilityProperties, gamma, rhovSat, rholSat, psiName)

50

A.1. barotropicCompressibilityModel Appendix A. Modified barotropicCompressibilityModel

);

// Selectors

//- Return a reference to the selected compressibility model

static autoPtr<barotropicCompressibilityModel> New

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

// Constructors

//- Construct from components

barotropicCompressibilityModel

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

//- Destructor

virtual ~barotropicCompressibilityModel() = default;

// Member Functions

//- Return the phase transport properties dictionary

const dictionary& compressibilityProperties() const

{

return compressibilityProperties_;

}

//- Return the compressibility

const volScalarField& psi() const

{

return psi_;

}

//- Correct the compressibility

virtual void correct() = 0;

//- Read compressibilityProperties dictionary

virtual bool read(const dictionary& compressibilityProperties) = 0;

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

barotropicCompressibilityModel.H

/*---------------------------------------------------------------------------*\

51

A.1. barotropicCompressibilityModel Appendix A. Modified barotropicCompressibilityModel

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

InClass

barotropicCompressibilityModel

\*---------------------------------------------------------------------------*/

#include "barotropicCompressibilityModel.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam

{

defineTypeNameAndDebug(barotropicCompressibilityModel, 0);

defineRunTimeSelectionTable(barotropicCompressibilityModel, dictionary);

}

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::barotropicCompressibilityModel::barotropicCompressibilityModel

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

)

:

compressibilityProperties_(compressibilityProperties),

psi_

(

IOobject

(

psiName,

gamma.mesh().time().timeName(),

gamma.mesh()

),

gamma.mesh(),

dimensionedScalar(dimensionSet(0, -2, 2, 0, 0), Zero)

),

gamma_(gamma),

rhovSat_(rhovSat),

rholSat_(rholSat)

{}

52

A.1. barotropicCompressibilityModel Appendix A. Modified barotropicCompressibilityModel

// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

bool Foam::barotropicCompressibilityModel::read

(

const dictionary& compressibilityProperties

)

{

compressibilityProperties_ = compressibilityProperties;

return true;

}

// ************************************************************************* //

barotropicCompressibilityModel.C

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

Copyright (C) 2019 OpenCFD Ltd.

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "barotropicCompressibilityModel.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

Foam::autoPtr<Foam::barotropicCompressibilityModel>

Foam::barotropicCompressibilityModel::New

(

const dictionary& dict,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

)

{

const word modelType

(

dict.get<word>("barotropicCompressibilityModel")

);

Info<< "Selecting compressibility model " << modelType << endl;

auto cstrIter = dictionaryConstructorTablePtr_->cfind(modelType);

53

A.2. linear Appendix A. Modified barotropicCompressibilityModel

if (!cstrIter.found())

{

FatalIOErrorInLookup

(

dict,

"barotropicCompressibilityModel",

modelType,

*dictionaryConstructorTablePtr_

) << exit(FatalIOError);

}

return autoPtr<barotropicCompressibilityModel>

(

cstrIter()(dict, gamma, rhovSat, rholSat, psiName)

);

}

// ************************************************************************* //

barotropicCompressibilityModelNew.C

A.2 linear

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Class

Foam::compressibilityModels::linear

Description

linear compressibility model.

SourceFiles

linear.C

\*---------------------------------------------------------------------------*/

#ifndef linear_H

#define linear_H

#include "barotropicCompressibilityModel.H"

#include "dimensionedScalar.H"

54

A.2. linear Appendix A. Modified barotropicCompressibilityModel

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

/*---------------------------------------------------------------------------*\

Class linear Declaration

\*---------------------------------------------------------------------------*/

class linear

:

public barotropicCompressibilityModel

{

// Private data

dimensionedScalar psiv_;

dimensionedScalar psil_;

public:

//- Runtime type information

TypeName("linear");

// Constructors

//- Construct from components

linear

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

//- Destructor

~linear()

{}

// Member Functions

//- Correct the linear compressibility

void correct();

//- Read transportProperties dictionary

bool read(const dictionary& compressibilityProperties);

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace compressibilityModels

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

linear.H

55

A.2. linear Appendix A. Modified barotropicCompressibilityModel

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "linear.H"

#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

defineTypeNameAndDebug(linear, 0);

addToRunTimeSelectionTable

(

barotropicCompressibilityModel,

linear,

dictionary

);

}

}

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::compressibilityModels::linear::linear

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

)

:

barotropicCompressibilityModel(compressibilityProperties, gamma, rhovSat, rholSat, psiName),

psiv_

(

"psiv",

dimCompressibility,

compressibilityProperties_

),

psil_

(

"psil",

56

A.3. Wallis Appendix A. Modified barotropicCompressibilityModel

dimCompressibility,

compressibilityProperties_

)

{

correct();

psi_.oldTime();

}

// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

void Foam::compressibilityModels::linear::correct()

{

psi_ = gamma_*psiv_ + (scalar(1) - gamma_)*psil_;

}

bool Foam::compressibilityModels::linear::read

(

const dictionary& compressibilityProperties

)

{

barotropicCompressibilityModel::read(compressibilityProperties);

compressibilityProperties_.readEntry("psiv", psiv_);

compressibilityProperties_.readEntry("psil", psil_);

return true;

}

// ************************************************************************* //

linear.C

A.3 Wallis

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Class

Foam::compressibilityModels::Wallis

57

A.3. Wallis Appendix A. Modified barotropicCompressibilityModel

Description

Wallis compressibility model.

SourceFiles

Wallis.C

\*---------------------------------------------------------------------------*/

#ifndef Wallis_H

#define Wallis_H

#include "barotropicCompressibilityModel.H"

#include "dimensionedScalar.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

/*---------------------------------------------------------------------------*\

Class Wallis Declaration

\*---------------------------------------------------------------------------*/

class Wallis

:

public barotropicCompressibilityModel

{

// Private data

dimensionedScalar psiv_;

dimensionedScalar psil_;

public:

//- Runtime type information

TypeName("Wallis");

// Constructors

//- Construct from components

Wallis

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

//- Destructor

~Wallis()

{}

// Member Functions

//- Correct the Wallis compressibility

void correct();

//- Read transportProperties dictionary

bool read(const dictionary& compressibilityProperties);

};

58

A.3. Wallis Appendix A. Modified barotropicCompressibilityModel

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace compressibilityModels

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

Wallis.H

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "Wallis.H"

#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

defineTypeNameAndDebug(Wallis, 0);

addToRunTimeSelectionTable

(

barotropicCompressibilityModel,

Wallis,

dictionary

);

}

}

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::compressibilityModels::Wallis::Wallis

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

59

A.4. Chung Appendix A. Modified barotropicCompressibilityModel

const volScalarField& rholSat,

const word& psiName

)

:

barotropicCompressibilityModel(compressibilityProperties, gamma, rhovSat, rholSat, psiName),

psiv_

(

"psiv",

dimCompressibility,

compressibilityProperties_

),

psil_

(

"psil",

dimCompressibility,

compressibilityProperties_

)

{

correct();

}

// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

void Foam::compressibilityModels::Wallis::correct()

{

psi_ =

(gamma_*rhovSat_ + (scalar(1) - gamma_)*rholSat_)

*(gamma_*psiv_/rhovSat_ + (scalar(1) - gamma_)*psil_/rholSat_);

}

bool Foam::compressibilityModels::Wallis::read

(

const dictionary& compressibilityProperties

)

{

barotropicCompressibilityModel::read(compressibilityProperties);

compressibilityProperties_.readEntry("psiv", psiv_);

compressibilityProperties_.readEntry("psil", psil_);

return true;

}

// ************************************************************************* //

Wallis.C

A.4 Chung

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

60

A.4. Chung Appendix A. Modified barotropicCompressibilityModel

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

Class

Foam::compressibilityModels::Chung

Description

Chung compressibility model.

SourceFiles

Chung.C

\*---------------------------------------------------------------------------*/

#ifndef Chung_H

#define Chung_H

#include "barotropicCompressibilityModel.H"

#include "dimensionedScalar.H"

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

/*---------------------------------------------------------------------------*\

Class Chung Declaration

\*---------------------------------------------------------------------------*/

class Chung

:

public barotropicCompressibilityModel

{

// Private data

dimensionedScalar psiv_;

dimensionedScalar psil_;

public:

//- Runtime type information

TypeName("Chung");

// Constructors

//- Construct from components

Chung

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName = "psi"

);

61

A.4. Chung Appendix A. Modified barotropicCompressibilityModel

//- Destructor

~Chung()

{}

// Member Functions

//- Correct the Chung compressibility

void correct();

//- Read transportProperties dictionary

bool read(const dictionary& compressibilityProperties);

};

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

} // End namespace compressibilityModels

} // End namespace Foam

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

#endif

// ************************************************************************* //

Chung.H

/*---------------------------------------------------------------------------*\

========= |

\\ / F ield | OpenFOAM: The Open Source CFD Toolbox

\\ / O peration |

\\ / A nd | www.openfoam.com

\\/ M anipulation |

-------------------------------------------------------------------------------

Copyright (C) 2011-2015 OpenFOAM Foundation

-------------------------------------------------------------------------------

License

This file is part of OpenFOAM.

OpenFOAM is free software: you can redistribute it and/or modify it

under the terms of the GNU General Public License as published by

the Free Software Foundation, either version 3 of the License, or

(at your option) any later version.

OpenFOAM is distributed in the hope that it will be useful, but WITHOUT

ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or

FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License

for more details.

You should have received a copy of the GNU General Public License

along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.

\*---------------------------------------------------------------------------*/

#include "Chung.H"

#include "addToRunTimeSelectionTable.H"

// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //

namespace Foam

{

namespace compressibilityModels

{

defineTypeNameAndDebug(Chung, 0);

addToRunTimeSelectionTable

62

A.4. Chung Appendix A. Modified barotropicCompressibilityModel

(

barotropicCompressibilityModel,

Chung,

dictionary

);

}

}

// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //

Foam::compressibilityModels::Chung::Chung

(

const dictionary& compressibilityProperties,

const volScalarField& gamma,

const volScalarField& rhovSat,

const volScalarField& rholSat,

const word& psiName

)

:

barotropicCompressibilityModel(compressibilityProperties, gamma, rhovSat, rholSat, psiName),

psiv_

(

"psiv",

dimCompressibility,

compressibilityProperties_

),

psil_

(

"psil",

dimCompressibility,

compressibilityProperties_

)

{

correct();

}

// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //

void Foam::compressibilityModels::Chung::correct()

{

volScalarField sfa

(

sqrt

(

rhovSat_/psiv_

/((scalar(1) - gamma_)*rhovSat_/psiv_ + gamma_*rholSat_/psil_)

)

);

psi_ = sqr

(

((scalar(1) - gamma_)/sqrt(psiv_) + gamma_*sfa/sqrt(psil_))

*sqrt(psiv_*psil_)/sfa

);

}

bool Foam::compressibilityModels::Chung::read

(

const dictionary& compressibilityProperties

)

{

barotropicCompressibilityModel::read(compressibilityProperties);

compressibilityProperties_.readEntry("psiv", psiv_);

compressibilityProperties_.readEntry("psil", psil_);

63

A.4. Chung Appendix A. Modified barotropicCompressibilityModel

return true;

}

// ************************************************************************* //

Chung.C

64