A numerical simulation needs several elements to run. One of them is the initial solution. In AVBP, the solutions are saved in HDF format, a powerful yet delicate to handle format. In this tutorial, we will see how to create an AVBP solution from scratch with PyAVBP and Ms-thermo.
The solution
Imagine you need to create an initial solution according to this scheme:
We have in the background two horizontal zones, one with air at standard conditions (T=300K, P=1atm) and the other one with T=700K and P=1atm. Superimposed on these two zones, we have three circles, two with a stoechiometric mixture of Kero and air and the third one with burnt gases at a stoichiometric mixture of air and Kero.
PyAVBP package
Most of the “ready-to-use” tools of PyAVBP are in the tools/
package. To create a solution, the module to use is thermo_avbp.py
. It contains the AvbpSolution
class which gathers several useful features.
The mesh
In this example we create a mesh my_mesh.h5
with hip:
ge 0 0 1 1 100 100
copy 3d 0 0.01 1
wr hd my_mesh
The script
Some imports
In our script, we need to import the package pyavbp.tools
. To manipulate te mesh, we will need functions in the io/
package. We import ms_thermo
in order to make a simple calculation of the adiabatic flame temperature. We also need numpy:
from pyavbp.tools import AvbpSolution
import numpy as np
import pyavbp.io as io
import ms_thermo as ms
Defining some constants
We create a variable for our mesh. We will deal with three kinds of mixtures so we define them at the beginning of our script too. For the last zone, we know that it is made of the burnt gases of air + kero mixture at stoichiometric ratio. We need to calculate the mass fractions and the temperature of the burnt gases (the Kero is supposed to be a C10H20 molecule). Ms_thermo can do it for us. We also correct the dict of species at the output of yk_from_phi
and tadia_table
:
meshfile = './MESH/my_mesh.mesh.h5'
Y_mixture_air = {'N2':0.77,'O2':0.23}
Y_mixture_kero = ms.yk_from_phi(phi=1, c_x=10, h_y=20)
Y_mixture_kero['KERO_LUCHE'] = Y_mixture_kero.pop('fuel')
T_burnt, Y_mixture_burnt = ms.tadia_table(t_fresh_gases=300,
p_fresh_gases=101325,
phi=1)
Y_mixture_burnt['KERO_LUCHE'] = Y_mixture_burnt.pop('fuel')
Instantiating the solution
In the module thermo_avbp.py
, in the AvbpSolution
class, the class method init_from_mesh
allows us to attach to an existing mesh all the properties needed to define a solution. So we use it to instanciate our solution at the standard conditions (Zone 1):
solution = AvbpSolution.init_from_mesh(meshfile,
mixture=Y_mixture_air)
Editing zones
Now, we want to specify a temperature depending on a vertical location in the mesh. To do so, we need to read the coordinates of the mesh and change the state of the gas according to them. To get the coordinates, we will use the get_mesh_bulk
function in the pyavbp.io
package. We will change the temperature according to the coordinate directly in the State object:
coord = np.array(io.get_mesh_bulk(meshfile)[:,1])
inf_bound = np.where(coord<=0.3, 1, 0)
sup_bound = np.where(coord>=0,1,0)
mask = np.multiply(inf_bound, sup_bound)
solution.state.temperature += (700 - solution.state.temperature) * mask
Now, the method spherical_gasout
of the class Solution
will be very straightforward to use and add the “mickey mouse” shaped circles. We can easily add the two upper circles of the scheme (Zone 3):
solution.spherical_gasout(meshfile,
position=[0.75, 0.75, 0.0],
radius=0.2,
temp=300.0,
mixture_dict=Y_mixture_kero,)
solution.spherical_gasout(meshfile,
position=[0.25, 0.75, 0.0],
radius=0.2,
temp=300.0,
mixture_dict=Y_mixture_kero)
Last zone, the burnt gases:
solution.spherical_gasout(meshfile,
position=[0.5, 0.4, 0.0],
radius=0.3,
temp=T_burnt,
mixture_dict=Y_mixture_burnt)
Now, all we have to do is to dump our solution in a HDF file with the method dump
:
solution.dump('my_sol.h5')
That’s it, your solution is created:
The full code
from pyavbp.tools import AvbpSolution
import numpy as np
import pyavbp.io as io
import ms_thermo as ms
#Some constants
meshfile = './MESH/my_mesh.mesh.h5'
Y_mixture_air = {'N2':0.77,'O2':0.23}
Y_mixture_kero = ms.yk_from_phi(phi=1, c_x=10, h_y=20)
Y_mixture_kero['KERO_LUCHE'] = Y_mixture_kero.pop('fuel')
T_burnt, Y_mixture_burnt = ms.tadia_table(t_fresh_gases=300,
p_fresh_gases=101325,
phi=1)
Y_mixture_burnt['KERO_LUCHE'] = Y_mixture_burnt.pop('fuel')
#Solution instantiation
solution = AvbpSolution.init_from_mesh(meshfile,
mixture=Y_mixture_air)
#Creating a mask based on the y coordinate
coord = np.array(io.get_mesh_bulk(meshfile)[:,1])
inf_bound = np.where(coord<=0.3, 1, 0)
sup_bound = np.where(coord>=0,1,0)
mask = np.multiply(inf_bound, sup_bound)
solution.state.temperature += (700 - solution.state.temperature) * mask
#The two upper circles with stoechiometric kero/air mixture
solution.spherical_gasout(meshfile,
position=[0.75, 0.75, 0.0],
radius=0.2,
temp=300.0,
mixture_dict=Y_mixture_kero,)
solution.spherical_gasout(meshfile,
position=[0.25, 0.75, 0.0],
radius=0.2,
temp=300.0,
mixture_dict=Y_mixture_kero)
#The lower circle with burnt gases
solution.spherical_gasout(meshfile,
position=[0.5, 0.4, 0.0],
radius=0.3,
temp=T_burnt,
mixture_dict=Y_mixture_burnt,
press=101325)
#Dump the new solution
solution.dump('my_sol.h5')