modifying buoyantpimplefoam for the simulation of solid
TRANSCRIPT
Theory Solver Thermophysical Models Tutorial Case References
Modifying buoyantPimpleFoam for the Simulation ofSolid-Liquid Phase Change with
Temperature-dependent Thermophysical Properties
Daniel Hummel
Ostbayerische Technische Hochschule (OTH) Amberg-WeidenFriedrich-Alexander Universitat (FAU) Erlangen-Nurnberg
2017-11-22
Daniel Hummel 2017-11-22 1 / 81
Theory Solver Thermophysical Models Tutorial Case References
In this tutorial
The theory behind the enthalpy method for solid-liquid phase changeis briefly introduced,
the implementation of a new solver for the transient simulation ofsolid-liquid phase change problems is described,
new thermophysical models for temperature-dependentthermophysical properties, read from tables, are implemented and
a tutorial case for the melting of a phase change material is set up
Daniel Hummel 2017-11-22 2 / 81
Theory Solver Thermophysical Models Tutorial Case References
The Enthalpy Method for Solid-Liquid Phase Change
The enthalpy (or enthalpy-porosity) method is a widespread fixed gridmethod for solid-liquid phase change
Prominent contributions by Voller and co-authors, see Voller [7]for a good overview
Enthalpy of a pure substance with distinct melting temperature canbe approximated by
H =
{csT T < Tm
cl + (cs − cl)Tm + L T > Tm(1)
Daniel Hummel 2017-11-22 3 / 81
Theory Solver Thermophysical Models Tutorial Case References
The Enthalpy Method for Solid-Liquid Phase Change
By defining the liquid volume fraction gl as step function
gl =
{0 TC < Tm
1 TC > Tm,(2)
the enthalpy can be expressed by
H = (1− gl)∫ T
T ref
ρcsdT + gl
∫ T
T ref
ρcldT + ρglL. (3)
The nonlinear term can be isolated into a source term (refer to Voller[7] for details)
ρc∂T
∂t= k∇2T − ∂ρ
∂tglL. (4)
Daniel Hummel 2017-11-22 4 / 81
Theory Solver Thermophysical Models Tutorial Case References
The Enthalpy Method for Solid-Liquid Phase Change
In phase change problems that involve fluid flow, the conservation of mass,momentum and energy has to be considered – the set of equations to besolved then reads
∂ρ
∂t+∇~u = 0, (5)
ρ∂~u
∂t= µ∇2~u− ~u(∇~u)−∇P + ~Ξ, (6)
ρc∂T
∂t= k∇2T − ρc~u∇T − ∂ρglL
∂t. (7)
Daniel Hummel 2017-11-22 5 / 81
Theory Solver Thermophysical Models Tutorial Case References
The Enthalpy Method for Solid-Liquid Phase Change
Buoyancy force term is incorporated in a source term ~Ξ in themomentum equation
For constant density but yet the consideration of natural convectiondue to temperature differences: Boussinesq approximation
Buoyancy is expressed by a linear function of the deviation oftemperature
~Γ = ρ~gb(T − Tref), (8)
Temperature-dependent density: no need for the Boussinesqapproximation
Buoyancy force due to density variations can be expressed by
~Γ = ~g(ρ− ρref). (9)
Daniel Hummel 2017-11-22 6 / 81
Theory Solver Thermophysical Models Tutorial Case References
The Enthalpy Method for Solid-Liquid Phase Change
Besides the buoyancy source term ~Γ, the source term in the momentumequation comprises an additional function
~Ξ = ~Γ + Z~u. (10)
Multiplied by the velocity vector, the velocity treatment function Zbecomes large if the liquid volume fraction tends to zero and therebyforces the velocity in the solid to zero. For isothermal phase changeproblems, Brent et al. [1] suggest the simple function
Z = C(1− gl), (11)
where constant C has an arbitrary large value.
Daniel Hummel 2017-11-22 7 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Properties
Example material for the project: n-octadecane (C18H38)
A parrafin that is frequently used as phase change material
According to experimental data, the thermophysical properties showstrong temperature dependence
Discontinuity at phase change temperature of roughly 300 K
Daniel Hummel 2017-11-22 8 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Properties
260 280 300 320 340
2
3
4
·10−3
T (K)
µ(P
as)
Figure: Dynamic viscosity (values originally from Ducoulombier et al. [3],modified)
Daniel Hummel 2017-11-22 9 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Properties
240 260 280 300 320 340 360
750
800
850
T (K)
ρ(kgm
−3)
Figure: Density (values originally from Seyer et al. [5] and Velez et al. [6],modified)
Daniel Hummel 2017-11-22 10 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Properties
240 260 280 300 320 340 360
1500
2000
2500
T (K)
c(J
kg−1K
−1)
Figure: Specific heat capacity (values originally from Marano et al. [4],modified)
Daniel Hummel 2017-11-22 11 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Properties
240 260 280 300 320 340 360
0.2
0.3
0.4
T (K)
k(W
m−1K
−1)
Figure: Thermal conductivity (values originally from Velez et al. [6], modified)
Daniel Hummel 2017-11-22 12 / 81
Theory Solver Thermophysical Models Tutorial Case References
Introduction and Preparation
Based on buoyantPimpleFoam
Only few modifications are required
solidLiquidPhaseChangeFoam
A solver for the transient simulation of isothermal solid-liquid phasechange with temperature-dependent thermophysical properties
Daniel Hummel 2017-11-22 13 / 81
Theory Solver Thermophysical Models Tutorial Case References
Introduction and Preparation
The entire directory of buoyantPimpleFoam is copied to the user directoryand renamed to solidLiquidPhaseChangeFoam. After renaming the .C fileand the entry in Make/files accordingly, the path where the executable iscompiled is changed to the user directory.cd $WM_PROJECT_USER_DIR
mkdir --parents applications/solvers/heatTransfer
cp -r $FOAM_SOLVERS/heatTransfer/buoyantPimpleFoam $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer/
cd $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer/
mv buoyantPimpleFoam solidLiquidPhaseChangeFoam
cd solidLiquidPhaseChangeFoam
mv buoyantPimpleFoam.C solidLiquidPhaseChangeFoam.C
sed -i s/"buoyantPimpleFoam"/"solidLiquidPhaseChangeFoam"/g Make/files
sed -i s/"FOAM_APPBIN"/"FOAM_USER_APPBIN"/g Make/files
wclean
wmake
Daniel Hummel 2017-11-22 14 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Momentum Equation
The buoyancy force and velocity treatment source terms are added to theleft hand side of the momentum equation.
vi UEqn.H
Listing 1: UEqn.H
10+ g*(rho-rhoRef)
11+ fvm::Sp(C*(1-gl),U)
Daniel Hummel 2017-11-22 15 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Energy Equation
The enthalpy source term is added to the right hand side of the energyequation.
vi EEqn.H
Listing 2: EEqn.H
22- L*(fvc::ddt(rho, gl))
Daniel Hummel 2017-11-22 16 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Energy Equation
The liquid volume fraction update is added to the bottom of the energyequation. The Cp values from the thermophysical model are stored in anew variable.
Listing 3: EEqn.H
38volScalarField glNew = gl + glRelax*(thermo.T()-Tmelt)*thermo.Cp()/L;
39gl = max(scalar(0), min(glNew, scalar(1)));
40}
41Cp = thermo.Cp();
The energy equation is iterated ten times by adding a simple for-loop atthe top of the energy equation:
Listing 4: EEqn.H
1for (int i=0; i<10; i++ )
Daniel Hummel 2017-11-22 17 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify createFields
Fields for the liquid volume fraction and the specific heat (only forpost-processing purposes) are created. All phase-change related constantsare read from the new dictionary phaseChangeProperties.
vi createFields.H
Listing 5: createFields.H
107volScalarField gl
108(
109IOobject
110(
111"gl",
112runTime.timeName(),
113mesh,
114IOobject::MUST_READ,
115IOobject::AUTO_WRITE
116),
117mesh
118);
119120IOdictionary phaseChangeProperties
Daniel Hummel 2017-11-22 18 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify createFields
Listing 6: createFields.H
121(
122IOobject
123(
124"phaseChangeProperties",
125runTime.constant(),
126mesh,
127IOobject::MUST_READ_IF_MODIFIED,
128IOobject::NO_WRITE
129)
130);
131132dimensionedScalar rhoRef
133(
134phaseChangeProperties.lookup("rhoRef")
135);
136137dimensionedScalar Tmelt
138(
139phaseChangeProperties.lookup("Tmelt")
140);
141142dimensionedScalar L
143(
144phaseChangeProperties.lookup("L")
145);
Daniel Hummel 2017-11-22 19 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify createFields
Listing 7: createFields.H
146147dimensionedScalar C
148(
149phaseChangeProperties.lookup("C")
150);
151152dimensionedScalar glRelax
153(
154phaseChangeProperties.lookup("glRelax")
155);
156157volScalarField Cp
158(
159IOobject
160(
161"Cp",
162runTime.timeName(),
163mesh,
164IOobject::NO_READ,
165IOobject::AUTO_WRITE
166),
167thermo.Cp()
168);
Daniel Hummel 2017-11-22 20 / 81
Theory Solver Thermophysical Models Tutorial Case References
Compile the solver
The new solver is compiled.
wclean
wmake
Daniel Hummel 2017-11-22 21 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
The implementation is mainly adopted from Choquet [2]
Extended by the implementation of a temperature-dependent viscosityand a modified temperature calculation
The Newton-Raphson solver for the temperature calculation inOpenFOAM is replaced by a temperature interpolation from tablevalues
Daniel Hummel 2017-11-22 22 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
The implementation requires that the original basic and specie foldersare copied to the user directory
Three main changes are done in the specie folder, where thetransport, equationOfState and thermo models are located.
For the transport model, the model const is copied an modified
The new equationOfState model is based on perfectGas
The new thermo model is derived from hConst
Daniel Hummel 2017-11-22 23 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
After some preparatory steps, the modification of const, perfectGas andhConst is similar:
1 Copy existing model and rename folders and files
2 In the .C, .H and I.H files, replace all instances of const with table
or perfectGas with rhoTable or hConst with hTable, respectively(for thermo and transport models, also replace the instantiated typenames in the .H files)
3 The member functions in the I.H files are modified
4 The interpolation files that are included in the I.H files are created
Daniel Hummel 2017-11-22 24 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
The temperature is calculated from enthalpy inspecie/thermo/thermo/thermoI.H
For the implementation of the temperature interpolation from tables,steps 4 and 5 also apply
After declaring the new thermophysical model inspecie/include/thermoPhysicsTypes.H andbasic/rhoThermo/rhoThermos.C, the table value files are inserted
Finally, the implementation is completed by compiling both specieand basic libraries
Daniel Hummel 2017-11-22 25 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
Interpolations as suggested by Choquet [2]
i = int floor
(fabs
(T − T0dT
))(12)
with T : current temperature, T0: temperature that refers to the firsttable value, dT : temperature difference between table valuesThe temperature at the calculated index is computed by
Ttabulated = T0 + i · dT (13)
Interpolation:
µ = µtabulated(i) + µtabulated(i+ 1)− µtabulated(i) ·(T − Ttabulated
dT
)(14)
µtabulated(i): ith value in the viscosity tableDaniel Hummel 2017-11-22 26 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
First, the basic and specie folders are copied into the user directory.
cd $WM_PROJECT_USER_DIR
rm -r src/thermophysicalModels
mkdir --parents src/thermophysicalModels
cp -r $WM_PROJECT_DIR/src/thermophysicalModels/specie $WM_PROJECT_USER_DIR/src/thermophysicalModels/specie
cp -r $WM_PROJECT_DIR/src/thermophysicalModels/basic $WM_PROJECT_USER_DIR/src/thermophysicalModels/basic
cd $WM_PROJECT_USER_DIR/src/thermophysicalModels
Daniel Hummel 2017-11-22 27 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
Analogous to the steps executed for the adaption of solver described inSection 1, the Make/files are adopted
sed -i s/"FOAM_LIBBIN"/"FOAM_USER_LIBBIN"/g basic/Make/files
sed -i s/"FOAM_LIBBIN"/"FOAM_USER_LIBBIN"/g specie/Make/files
Daniel Hummel 2017-11-22 28 / 81
Theory Solver Thermophysical Models Tutorial Case References
General Procedure
vi basic/Make/options
Delete the original path to the specie lnInclude3-I$(LIB_SRC)/thermophysicalModels/specie/lnInclude \
and add one that directs to the new specie model that will be created inthe user project directory.
Listing 8: basic/Make/options
2-I$(LIB_SRC)/transportModels/compressible/lnInclude \
3-I$(WM_PROJECT_USER_DIR)/src/thermophysicalModels/specie/lnInclude \
4-I$(LIB_SRC)/thermophysicalModels/thermophysicalProperties/lnInclude \
In order to direct the compiler to the libraries in the user directory first,add the lines
Listing 9: basic/Make/options
9LIB_LIBS = \
10-L$(FOAM_USER_LIBBIN) \
Daniel Hummel 2017-11-22 29 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
cp -r specie/transport/const/ specie/transport/table
mv specie/transport/table/constTransport.C specie/transport/table/tableTransport.C
mv specie/transport/table/constTransport.H specie/transport/table/tableTransport.H
mv specie/transport/table/constTransportI.H specie/transport/table/tableTransportI.H
sed -i s/"constTransport"/"tableTransport"/g specie/transport/table/*
sed -i s/"const<"/"table<"/g specie/transport/table/tableTransport.H
Daniel Hummel 2017-11-22 30 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
vi specie/transport/table/tableTransportI.H
Daniel Hummel 2017-11-22 31 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
Listing 10: specie/transport/table/tableTransportI.H
82template<class Thermo>
83inline Foam::scalar Foam::tableTransport<Thermo>::mu
84(
85const scalar p,
86const scalar T
87) const
88{
89//return mu_;
90#include "muInterpolation.H"
91}
Daniel Hummel 2017-11-22 32 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
Listing 11: specie/transport/table/tableTransportI.H
94template<class Thermo>
95inline Foam::scalar Foam::tableTransport<Thermo>::kappa
96(
97const scalar p,
98const scalar T
99) const
100{
101//return this->Cp(p, T)*mu(p, T)*rPr_;
102#include "kappaInterpolation.H"
103}
Daniel Hummel 2017-11-22 33 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
Listing 12: specie/transport/table/tableTransportI.H
106template<class Thermo>
107inline Foam::scalar Foam::tableTransport<Thermo>::alphah
108(
109const scalar p,
110const scalar T
111) const
112{
113//return mu(p, T)*rPr_;
114return kappa(p,T)/this->Cpv(p,T);
115}
Daniel Hummel 2017-11-22 34 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
vi specie/transport/table/muInterpolation.H
Listing 13: specie/transport/table/muInterpolation.H
1int i_index;
2scalar dT=1;
3scalar T0=250;
4scalar Temp_tabulated;
5scalar mu_T_tabulated;
67// Dynamic viscosity mus (Pa s):
89scalar mu_tabulated[101]=
10{
11#include "mu.H"
12};
1314// linear interpolation to calculate mu(T) (Pa s)
15i_index = int(floor(fabs((T-T0)/dT)));
16Temp_tabulated = T0+i_index*dT;
17mu_T_tabulated = mu_tabulated[i_index]
18+ (mu_tabulated[i_index+1]-mu_tabulated[i_index])*(T-Temp_tabulated)/dT;
1920return mu_T_tabulated;
Daniel Hummel 2017-11-22 35 / 81
Theory Solver Thermophysical Models Tutorial Case References
Transport
vi specie/transport/table/kappaInterpolation.H
Listing 14: specie/transport/table/kappaInterpolation.H
1int i_index;
2scalar dT=1;
3scalar T0=250;
4scalar Temp_tabulated;
5scalar kappa_T_tabulated;
67// Thermal conductivity kappa (W/(m.K)), tabulated :
89scalar kappa_tabulated[101]=
10{
11#include "kappa.H"
12};
1314// linear interpolation to calculate kappa(T) W/(m.K)
15i_index = int(floor(fabs((T-T0)/dT)));
16Temp_tabulated = T0+i_index*dT;
17kappa_T_tabulated = kappa_tabulated[i_index]
18+ (kappa_tabulated[i_index+1]-kappa_tabulated[i_index])*(T-Temp_tabulated)/dT;
1920return kappa_T_tabulated;
Daniel Hummel 2017-11-22 36 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
cp -r specie/equationOfState/perfectGas/ specie/equationOfState/rhoTable
mv specie/equationOfState/rhoTable/perfectGas.C specie/equationOfState/rhoTable/rhoTable.C
mv specie/equationOfState/rhoTable/perfectGas.H specie/equationOfState/rhoTable/rhoTable.H
mv specie/equationOfState/rhoTable/perfectGasI.H specie/equationOfState/rhoTable/rhoTableI.H
sed -i s/"perfectGas"/"rhoTable"/g specie/equationOfState/rhoTable/*
Daniel Hummel 2017-11-22 37 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
vi specie/equationOfState/rhoTable/rhoTableI.H
Listing 15: specie/equationOfState/rhoTable/rhoTableI.H
73template<class Specie>
74inline Foam::scalar Foam::rhoTable<Specie>::rho(scalar p, scalar T) const
75{
76//return p/(this->R()*T);
77#include "rhoInterpolation.H"
78}
Daniel Hummel 2017-11-22 38 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
Listing 16: specie/equationOfState/rhoTable/rhoTableI.H
102template<class Specie>
103inline Foam::scalar Foam::rhoTable<Specie>::psi(scalar p, scalar T) const
104{
105//return 1.0/(this->R()*T);
106return 0;
107}
Daniel Hummel 2017-11-22 39 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
Listing 17: specie/equationOfState/rhoTable/rhoTableI.H
110template<class Specie>
111inline Foam::scalar Foam::rhoTable<Specie>::Z(scalar p, scalar T) const
112{
113//return 1;
114return 0;
115}
Daniel Hummel 2017-11-22 40 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
Listing 18: specie/equationOfState/rhoTable/rhoTableI.H
118template<class Specie>
119inline Foam::scalar Foam::rhoTable<Specie>::CpMCv(scalar p, scalar T) const
120{
121//return this->R();
122return 0;
123}
Daniel Hummel 2017-11-22 41 / 81
Theory Solver Thermophysical Models Tutorial Case References
Equation of State
vi specie/equationOfState/rhoTable/rhoInterpolation.H
Listing 19: specie/equationOfState/rhoTable/rhoInterpolation.H
1int i_index;
2scalar dT=1;
3scalar T0=250;
4scalar Temp_tabulated;
5scalar rho_T_tabulated;
67// Density (kg/m^3), tabulated :
8910scalar rho_tabulated[101]=
11{
12#include "rho.H"
13};
1415// linear interpolation to calculate rho(T) in kg/m^3
16i_index = int(fabs(floor((T-T0)/dT)));
17Temp_tabulated = T0+i_index*dT;
18rho_T_tabulated = rho_tabulated[i_index]
19+ (rho_tabulated[i_index+1]-rho_tabulated[i_index])*(T-Temp_tabulated)/dT;
2021return rho_T_tabulated;
Daniel Hummel 2017-11-22 42 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
cp -r specie/thermo/hConst/ specie/thermo/hTable
mv specie/thermo/hTable/hConstThermo.C specie/thermo/hTable/hTableThermo.C
mv specie/thermo/hTable/hConstThermo.H specie/thermo/hTable/hTableThermo.H
mv specie/thermo/hTable/hConstThermoI.H specie/thermo/hTable/hTableThermoI.H
sed -i s/"hConstThermo"/"hTableThermo"/g specie/thermo/hTable/*
sed -i s/"hConst<"/"hTable<"/g specie/thermo/hTable/hTableThermo.H
Daniel Hummel 2017-11-22 43 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
vi specie/thermo/hTable/hTableThermoI.H
Listing 20: specie/thermo/hTable/hTableThermoI.H
91template<class EquationOfState>
92inline Foam::scalar Foam::hTableThermo<EquationOfState>::Cp
93(
94const scalar p,
95const scalar T
96) const
97{
98//return Cp_ + EquationOfState::Cp(p, T);
99#include "cpInterpolation.H"
100}
Daniel Hummel 2017-11-22 44 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
Listing 21: specie/thermo/hTable/hTableThermoI.H
103template<class EquationOfState>
104inline Foam::scalar Foam::hTableThermo<EquationOfState>::Ha
105(
106const scalar p, const scalar T
107) const
108{
109//return Cp_*T + Hf_ + EquationOfState::H(p, T);
110#include "haInterpolation.H"
111}
Daniel Hummel 2017-11-22 45 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
Listing 22: specie/thermo/hTable/hTableThermoI.H
114template<class EquationOfState>
115inline Foam::scalar Foam::hTableThermo<EquationOfState>::Hs
116(
117const scalar p, const scalar T
118) const
119{
120//return Cp_*T + EquationOfState::H(p, T);
121return Ha(p,T)-Hc();
122}
Daniel Hummel 2017-11-22 46 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
Listing 23: specie/thermo/hTable/hTableThermoI.H
125template<class EquationOfState>
126inline Foam::scalar Foam::hTableThermo<EquationOfState>::Hc() const
127{
128//return Hf_;
129return 0;
130}
Daniel Hummel 2017-11-22 47 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
vi specie/thermo/hTable/cpInterpolation.H
Listing 24: specie/thermo/hTable/cpInterpolation.H
1int i_index;
2scalar dT=1;
3scalar T0=250;
4scalar Temp_tabulated;
5scalar Cp_T_tabulated;
67// Specific heat at constant pressure (J/(kg K)), tabulated :
8scalar Cp_tabulated[101]=
9{
10#include "cp.H"
11};
1213// linear interpolation to calculate Cp(T) in J/(kg.K)
14i_index = int(floor(fabs((T-T0)/dT)));
15Temp_tabulated = T0+i_index*dT;
16Cp_T_tabulated = Cp_tabulated[i_index]
17+ (Cp_tabulated[i_index+1]-Cp_tabulated[i_index])*(T-Temp_tabulated)/dT;
1819// return cp(T) in J/(kmol.K)
20return Cp_T_tabulated*this->W();
Daniel Hummel 2017-11-22 48 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermo
vi specie/thermo/hTable/haInterpolation.H
Listing 25: specie/thermo/hTable/haInterpolation.H
1int i_index;
2scalar dT=1;
3scalar T0=250;
4scalar Temp_tabulated;
5scalar h_T_tabulated;
67// enthalpy (J/kg), tabulated:
89scalar h_tabulated[101] =
10{
11#include "ha.H"
12};
1314// linear interpolation to calculate h(T) in J/kg
15i_index = int(floor(fabs((T-T0)/dT)));
16Temp_tabulated = T0+i_index*dT;
17h_T_tabulated = h_tabulated[i_index]
18+ (h_tabulated[i_index+1]-h_tabulated[i_index])*(T-Temp_tabulated)/dT;
1920// return h(T) in J/kmol
21return h_T_tabulated*this->W();
Daniel Hummel 2017-11-22 49 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Temperature Calculation
vi specie/thermo/thermo/thermoI.H
Listing 26: specie/thermo/thermo/thermoI.H
30/*template<class Thermo, template<class> class Type>
31//inline Foam::species::thermo<Thermo, Type>::thermo
32//(
33// const Thermo& sp
34//)
35//:
36// Thermo(sp)
37//{}
38//
39//
40//template<class Thermo, template<class> class Type>
41//inline Foam::scalar Foam::species::thermo<Thermo, Type>::T
42//(
43// scalar f,
44// scalar p,
45// scalar T0,
46// scalar (thermo<Thermo, Type>::*F)(const scalar, const scalar) const,
47// scalar (thermo<Thermo, Type>::*dFdT)(const scalar, const scalar)
48// const,
49// scalar (thermo<Thermo, Type>::*limit)(const scalar) const
50//) const
Daniel Hummel 2017-11-22 50 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Temperature Calculation
Listing 27: specie/thermo/thermo/thermoI.H
51//{
52// if (T0 < 0)
53// {
54// FatalErrorInFunction
55// << "Negative initial temperature T0: " << T0
56// << abort(FatalError);
57// }
58//
59// scalar Test = T0;
60// scalar Tnew = T0;
61// scalar Ttol = T0*tol_;
62// int iter = 0;
63//
64// do
65// {
66// Test = Tnew;
67// Tnew =
68// (this->*limit)
69// (Test - ((this->*F)(p, Test) - f)/(this->*dFdT)(p, Test));
70//
71// if (iter++ > maxIter_)
Daniel Hummel 2017-11-22 51 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Temperature Calculation
Listing 28: specie/thermo/thermo/thermoI.H
72// {
73// FatalErrorInFunction
74// << "Maximum number of iterations exceeded: " << maxIter_
75// << abort(FatalError);
76// }
77//
78// } while (mag(Tnew - Test) > Ttol);
79//
80// return Tnew;
81//}*/
8283template<class Thermo, template<class> class Type>
84inline Foam::species::thermo<Thermo, Type>::thermo
85(
86const Thermo& sp
87)
88:
89Thermo(sp)
90{}
Daniel Hummel 2017-11-22 52 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Temperature Calculation
Listing 29: specie/thermo/thermo/thermoI.H
93template<class Thermo, template<class> class Type>
94inline Foam::scalar Foam::species::thermo<Thermo, Type>::T
95(
96scalar f,
97scalar p,
98scalar T0,
99scalar (thermo<Thermo, Type>::*F)(const scalar, const scalar) const,
100scalar (thermo<Thermo, Type>::*dFdT)(const scalar, const scalar) const,
101scalar (thermo<Thermo, Type>::*limit)(const scalar) const
102) const
103{
104#include "TInterpolation.H"
105}
Daniel Hummel 2017-11-22 53 / 81
Theory Solver Thermophysical Models Tutorial Case References
Modify Temperature Calculation
vi specie/thermo/thermo/TInterpolation.H
Listing 30: specie/thermo/thermo/TInterpolation.H
1int i_index;
2scalar dH=5916.4;
3scalar h0=3.1558e+05;
4scalar enth_tabulated;
5scalar Tnew;
6scalar h = f;
78// Temperature (K), tabulated :
910scalar T_tabulated[101]=
11{
12#include "Th.H"
13};
1415// linear interpolation to calculate T(h) (K)
16i_index = int(floor(fabs((h-h0)/dH)));
17enth_tabulated = h0+i_index*dH;
18Tnew = T_tabulated[i_index] + (T_tabulated[i_index+1]-T_tabulated[i_index])*(h-enth_tabulated)/dH;
1920return Tnew;
Daniel Hummel 2017-11-22 54 / 81
Theory Solver Thermophysical Models Tutorial Case References
Declaration, Table Insertion and Compilation
Include hTableThermo.H and rhoTable.H in thermoPhysicsTypes.H
vi specie/include/thermoPhysicsTypes.H
Listing 31: specie/include/thermoPhysicsTypes.H
51#include "tableTransport.H"
52#include "rhoTable.H"
53#include "hTableThermo.H"
Daniel Hummel 2017-11-22 55 / 81
Theory Solver Thermophysical Models Tutorial Case References
Declaration, Table Insertion and Compilation
Listing 32: specie/include/thermoPhysicsTypes.H
59typedef
60tableTransport
61<
62species::thermo
63<
64hTableThermo
65<
66rhoTable<specie>
67>,
68sensibleEnthalpy
69>
70> tableGasHThermoPhysics;
Daniel Hummel 2017-11-22 56 / 81
Theory Solver Thermophysical Models Tutorial Case References
Declaration, Table Insertion and Compilation
vi basic/rhoThermo/rhoThermos.C
Listing 33: basic/rhoThermo/rhoThermos.C
54#include "tableTransport.H"
55#include "hTableThermo.H"
56#include "rhoTable.H"
Listing 34: basic/rhoThermo/rhoThermos.C
64makeThermo
65(
66rhoThermo,
67heRhoThermo,
68pureMixture,
69tableTransport,
70sensibleEnthalpy,
71hTableThermo,
72rhoTable,
73specie
74);
Daniel Hummel 2017-11-22 57 / 81
Theory Solver Thermophysical Models Tutorial Case References
Declaration, Table Insertion and Compilation
cp ~/Downloads/hummelTables/rho ./specie/equationOfState/rhoTable/rho.H
cp ~/Downloads/hummelTables/ha ./specie/thermo/hTable/ha.H
cp ~/Downloads/hummelTables/cp ./specie/thermo/hTable/cp.H
cp ~/Downloads/hummelTables/mu ./specie/transport/table/mu.H
cp ~/Downloads/hummelTables/kappa ./specie/transport/table/kappa.H
cp ~/Downloads/hummelTables/Th ./specie/thermo/thermo/Th.H
Daniel Hummel 2017-11-22 58 / 81
Theory Solver Thermophysical Models Tutorial Case References
Declaration, Table Insertion and Compilation
cd specie
wclean libso
wmake libso
cd ..
cd basic
wclean libso
wmake libso
Daniel Hummel 2017-11-22 59 / 81
Theory Solver Thermophysical Models Tutorial Case References
Description and Preparation
hot
T = 333.15 K
top (adiabatic)
bottom (adiabatic)
cold
T = 293.15 KT0 = 293.15 K
88.9 mm
63.5 mm
Figure: Domain with temperature boundaries and dimensions
Daniel Hummel 2017-11-22 60 / 81
Theory Solver Thermophysical Models Tutorial Case References
Description and Preparation
cd $WM_PROJECT_USER_DIR/run
cp -r $FOAM_TUTORIALS/heatTransfer/buoyantSimpleFoam/buoyantCavity/ ./phaseChangeCavity/
cd phaseChangeCavity
cp $FOAM_TUTORIALS/heatTransfer/buoyantPimpleFoam/hotRoom/system/controlDict ./system/
cp $FOAM_TUTORIALS/heatTransfer/buoyantPimpleFoam/hotRoom/system/fvSolution ./system/
cp $FOAM_TUTORIALS/heatTransfer/buoyantPimpleFoam/hotRoom/system/fvSchemes ./system/
Daniel Hummel 2017-11-22 61 / 81
Theory Solver Thermophysical Models Tutorial Case References
0 folder
The boundary conditions of patch frontAndBack are changed to empty
for p, p rgh, T and U.
gedit 0/p 0/p_rgh 0/T 0/U
The temperature values are changed to fit the test case:
sed -i s/"293"/"293.15"/g 0/T
sed -i s/"288.15"/"293.15"/g 0/T
sed -i s/"307.75"/"333.15"/g 0/T
Daniel Hummel 2017-11-22 62 / 81
Theory Solver Thermophysical Models Tutorial Case References
0 folder
Boundary and initial conditions for the liquid volume fraction field gl aregenerated:
vi 0/gl
Listing 35: 0/gl
1FoamFile
2{
3version 2.0;
4format ascii;
5class volScalarField;
6object gl;
7}
8dimensions [0 0 0 0 0 0 0];
9internalField uniform 0;
10boundaryField
11{
12frontAndBack {type empty;}
13topAndBottom {type zeroGradient;}
14hot {type zeroGradient;}
15cold {type zeroGradient;}
16}
Daniel Hummel 2017-11-22 63 / 81
Theory Solver Thermophysical Models Tutorial Case References
Constant folder
As laminar flow is assumed, the turbulence model is disabled.
sed -i s/"simulationType RAS;"/"simulationType laminar;"/g constant/turbulenceProperties
The entries in thermophysicalProperties are replaced by the table values atthe initial temperature. The acceleration due to gravity is set in thenegative z coordinate.
sed -i s/"28.96"/"254.5"/g constant/thermophysicalProperties
sed -i s/"1004.4"/"1700"/g constant/thermophysicalProperties
sed -i s/"1.831e-05"/"0.0041058"/g constant/thermophysicalProperties
sed -i s/"0.705"/"23.794"/g constant/thermophysicalProperties
sed -i s/"(0 -9.81 0)"/"(0 0 -9.81)"/g constant/g
Daniel Hummel 2017-11-22 64 / 81
Theory Solver Thermophysical Models Tutorial Case References
Constant folder
The new thermophysical model is used by changing the keywords fortransport, equationOfState and thermo models.
sed -i s/"const"/"table"/g constant/thermophysicalProperties
sed -i s/"hConst"/"hTable"/g constant/thermophysicalProperties
sed -i s/"perfectGas"/"rhoTable"/g constant/thermophysicalProperties
Daniel Hummel 2017-11-22 65 / 81
Theory Solver Thermophysical Models Tutorial Case References
Constant folder
The values for latent heat of fusion, melting temperature, referencedensity, velocity treatment function constant and liquid volume updaterelaxation factor are set.
vi constant/phaseChangeProperties
Listing 36: constant/phaseChangeProperties
1FoamFile
2{
3version 2.0;
4format ascii;
5class dictionary;
6object transportProperties;
7}
8L L [0 2 -2 0 0 0 0] 212490;
9Tmelt Tmelt [0 0 0 1 0 0 0] 300;
10rhoRef rhoRef [1 -3 0 0 0 0 0] 755.05;
11C C [1 -3 -1 0 0 0 0] 5e4;
12glRelax glRelax [0 0 0 0 0 0 0] 0.9;
Daniel Hummel 2017-11-22 66 / 81
Theory Solver Thermophysical Models Tutorial Case References
System folder
sed -i s/"76"/"88.9"/g system/blockMeshDict
sed -i s/"260"/"31.75"/g system/blockMeshDict
sed -i s/"(35 150 15)"/"(40 1 30)"/g system/blockMeshDict
In blockMeshDict, the patch type of frontAndBack is changed to empty
and the mesh is created.
vi system/blockMeshDict
blockMesh
Daniel Hummel 2017-11-22 67 / 81
Theory Solver Thermophysical Models Tutorial Case References
System folder
The simulation is run for 1200 s. The first time step is set to 0.0001 andthen controlled by a Courant Number of 1. Solution directories are writtenfor every 60 seconds.
sed -i s/"2000;"/"1200;"/g system/controlDict
sed -i s/"2;"/"1e-4;"/g system/controlDict
sed -i s/"timeStep;"/"adjustableRunTime;"/g system/controlDict
sed -i s/"100;"/"60;"/g system/controlDict
sed -i s/"no;"/"yes;"/g system/controlDict
sed -i s/"0.5;"/"1;"/g system/controlDict
Daniel Hummel 2017-11-22 68 / 81
Theory Solver Thermophysical Models Tutorial Case References
System folder
Fields for density, thermal diffusivity, dynamic viscosity and compressibilityare written every 60 seconds.
vi system/controlDict
Listing 37: system/controlDict
52functions
53{
54writeThermophysicalProperties
55{
56type writeObjects;
57libs ("libutilityFunctionObjects.so");
58objects (thermo:alpha thermo:mu thermo:psi thermo:rho thermo:Cp);
59writeControl adjustableRunTime;
60writeInterval 60;
61}
62}
Daniel Hummel 2017-11-22 69 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
solidLiquidPhaseChangeFoam >log&
paraFoam -builtin
Daniel Hummel 2017-11-22 70 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Temperature Field after 1200 s
Daniel Hummel 2017-11-22 71 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Liquid Volume Fraction Field after 1200 s
Daniel Hummel 2017-11-22 72 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Density Field After 1200 s
Daniel Hummel 2017-11-22 73 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Specific Heat Capacity field after 1200 s
Daniel Hummel 2017-11-22 74 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Dynamic Viscosity Field after 1200 s
Daniel Hummel 2017-11-22 75 / 81
Theory Solver Thermophysical Models Tutorial Case References
Run Tutorial and View Results
Figure: Thermal Diffusivity Field after 1200 s
Daniel Hummel 2017-11-22 76 / 81
Theory Solver Thermophysical Models Tutorial Case References
Brent, A. D. et al. “Enthalpy-Porosity Technique for ModelingConvection-Diffusion Phase Change”. In: Numerical Heat Transfer13.3 (1988), 297–318.
Choquet, I. ThermophysicalModels library in OpenFOAM-2.3.x –How to implement a new thermophysical model. 2014. url:www.tfd.chalmers.se/~hani/kurser/OS_CFD_2014/
isabelleChoquet/thermophysicalModels-OF-2.3-
updated_HN141009.pdf.
Ducoulombier, D. et al. “Pressure (1-1000 bars) and Temperature(20-100 ◦C) Dependence of the Viscosity of Liquid Hydrocarbons”.In: The Journal of Physical Chemistry 90.8 (1986), 1692–1700.
Marano, J. J. and Holder, G. D. “A General Equation forCorrelating the Thermophysical Properties of n-Paraffins, n-Olefins,and other Homologous Series. 3. Asymptotic Behavior Correlations
Daniel Hummel 2017-11-22 76 / 81
Theory Solver Thermophysical Models Tutorial Case References
for Thermal and Transport Properties”. In: Industrial & EngineeringChemistry Research 36.6 (1997), 2399–2408.
Seyer, W. F. et al. “The Density and Transition Points of then-Paraffin Hydrocarbons”. In: Journal of the American ChemicalSociety 66.2 (1944), 179–182.
Velez, C. et al. “Temperature-Dependent Thermal Properties ofSolid/Liquid Phase Change Even-Numbered n-Alkanes:n-Hexadecane, n-Octadecane and n-Eicosane”. In: Applied Energy143 (2015), 383–394.
Voller, V. “An Overview of Numerical Methods for Solving PhaseChange Problems”. In: Advances in Numerical Heat Transfer. 1996.
Daniel Hummel 2017-11-22 77 / 81
Theory Solver Thermophysical Models Tutorial Case References
Solver
cp -r ~/Downloads/solidLiquidPhaseChangeFoam $WM_PROJECT_USER_DIR/applications/solvers/heatTransfer/
Daniel Hummel 2017-11-22 77 / 81
Theory Solver Thermophysical Models Tutorial Case References
Interpolation Files
cp -r ~/Downloads/hummelInterpolationFiles/rhoInterpolation.H /specie/equationOfState/rhoTable/
rhoInterpolation.H
cp -r ~/Downloads/hummelInterpolationFiles/cpInterpolation.H specie/thermo/hTable/cpInterpolation.H
cp -r ~/Downloads/hummelInterpolationFiles/haInterpolation.H specie/thermo/hTable/haInterpolation.H
cp -r ~/Downloads/hummelInterpolationFiles/TInterpolation.H specie/thermo/thermo/TInterpolation.H
cp -r ~/Downloads/hummelInterpolationFiles/kappaInterpolation.H specie/transport/table/kappaInterpolation.H
cp -r ~/Downloads/hummelInterpolationFiles/muInterpolation.H specie/transport/table/muInterpolation.H
Daniel Hummel 2017-11-22 78 / 81
Theory Solver Thermophysical Models Tutorial Case References
Tables
cp ~/Downloads/hummelTables/rho ./specie/equationOfState/rhoTable/rho.H
cp ~/Downloads/hummelTables/ha ./specie/thermo/hTable/ha.H
cp ~/Downloads/hummelTables/cp ./specie/thermo/hTable/cp.H
cp ~/Downloads/hummelTables/mu ./specie/transport/table/mu.H
cp ~/Downloads/hummelTables/kappa ./specie/transport/table/kappa.H
cp ~/Downloads/hummelTables/Th ./specie/thermo/thermo/Th.H
Daniel Hummel 2017-11-22 79 / 81
Theory Solver Thermophysical Models Tutorial Case References
Thermophysical Models
cp -r ~/Downloads/hummelThermophysicalModels/specie $WM_PROJECT_USER_DIR/src/thermophysicalModels/cp -r ~/Downloads/hummelThermophysicalModels/basic $WM_PROJECT_USER_DIR/src/thermophysicalModels/
Daniel Hummel 2017-11-22 80 / 81