pypbomb.sd
Pypbomb requires the use of some functionality from the shock and detonation
toolbox from the Explosion Dynamics Laboratory at Cal Tech [1]. SDToolbox is,
as yet, not installable via pip or conda, and not all of its functions are
needed for this package. Therefore, the functions needed for pypbomb’s
purposes are located here, in pypbomb.sd
. Some of these functions, such as
Detonation.cj_speed
, have been modified to speed up the calculation process.
If you are planning to do any sort of actual detonation work outside of tube
design it is recommended to use the full SDToolbox.
- [1] SDToolbox Numerical Tools for Shock and Detonation Wave Modeling,
Explosion Dynamics Laboratory, Contributors: S. Browne, J. Ziegler, N. Bitter, B. Schmidt, J. Lawson and J. E. Shepherd California Institute of Technology, Pasadena, CA USA http://shepherd.caltech.edu/EDL/PublicResources/sdt/
- class pypbomb.sd.Detonation
Bases:
object
Methods specifically relating to Chapman-Jouguet speed and state calculation
- classmethod cj_speed(initial_pressure, initial_temperature, species_mole_fractions, mechanism, use_multiprocessing=False, return_r_squared=False, return_state=False)
Calculates the Chapman-Jouguet detonation velocity of a gaseous mixture.
This is a modified version of
sdtoolbox.PostShock.CJspeed
. Specifically, it has been changed to allow for CJ state output, and to allow the use of multiprocessing to speed up the curve fit.- Parameters:
initial_pressure (float) – Initial pressure in Pascals
initial_temperature (float) – Initial temperature in Kelvin
species_mole_fractions (str or dict) – Reactant species mole fractions
mechanism (str) – Cti file containing mechanism data (e.g.
gri30.yaml
)use_multiprocessing (bool, optional) – Use multiprocessing to speed up CJ speed calculation
return_r_squared (bool, optional) – Return the \(R^2\) value of the CJ speed vs. density ratio fit
return_state (bool, optional) – Return the CJ state corresponding to the calculated velocity
- Returns:
Dictionary with the following keys:
"cj speed"
: Chapman-Jouguet wave speed (float)"R^2"
: R-squared value of the CJ speed vs. density ratio fit (float). Only exists if return_r_squared is set toTrue
."cj state"
: Cantera solution object describing the CJ state (ct.Solution). Only exists if return_state is set toTrue
.
- Return type:
dict
- classmethod cj_state(working_gas, initial_state_gas, error_tol_temperature, error_tol_velocity, density_ratio, max_iterations=500)
Calculates the Chapman-Jouguet state and wave speed using Reynolds’ iterative method.
This function corresponds to
sdtoolbox.PostShock.CJ_calc
- Parameters:
working_gas (cantera.Solution) – Working gas mixture used for calculations.
initial_state_gas (ct.Solution) – Working gas mixture in its initial, undetonated state.
error_tol_temperature (float) – Temperature error tolerance for iteration, in Kelvin.
error_tol_velocity (float) – Velocity error tolerance for iteration, in m/s.
density_ratio (float) – Density ratio.
max_iterations (int, optional) – Maximum number of loop iterations used to calculate output. Default is 500.
- Returns:
A tuple containing:
Gas mixture at equilibrium state (ct.Solution)
Initial velocity resulting in the input density ratio, in m/s (float)
- Return type:
tuple(ct.Solution, float)
- class pypbomb.sd.GetError
Bases:
object
Methods for calculating error in enthalpy and pressure from a given velocity.
- static equilibrium(working_gas, initial_state_gas, initial_velocity_guess)
This function uses the momentum and energy conservation equations to calculate error in current pressure and enthalpy guesses. In this case, working state is in equilibrium.
Original function:
FHFP_CJ in PostShock.py
- Parameters:
working_gas (ct.Solution) – Working gas mixture used for calculations.
initial_state_gas (ct.Solution) – Working gas mixture in its initial, undetonated state.
initial_velocity_guess (float) – A guess for the initial velocity in m/s
- Returns:
A tuple containing:
Enthalpy error (float)
Pressure error (float)
- Return type:
tuple (float, float)
- static reflected_shock_frozen(shock_speed, working_gas, post_shock_gas)
This function uses the momentum and energy conservation equations to calculate error in current pressure and enthalpy guesses during reflected shock calculations. In this case, working state is frozen.
Original function:
sdtoolbox.reflections.FHFP_reflected_fr
- Parameters:
shock_speed (float) – Current post-incident-shock lab frame particle speed
working_gas (ct.Solution) – Working gas mixture used for calculations.
post_shock_gas (ct.Solution) – Working gas mixture in its post-incident-shock state.
- Returns:
A tuple containing:
Enthalpy error (float)
Pressure error (float)
- Return type:
tuple (float, float)
- class pypbomb.sd.Properties
Bases:
object
- static equilibrium(gas, density, temperature)
This function calculates the equilibrium pressure and enthalpy given temperature and density.
Original function:
sdtoolbox.Thermo.eq_state
- Parameters:
gas (ct.Solution) – Working gas object.
density (float) – Mixture density in kg/m^3.
temperature (float) – Mixture temperature in K.
- Returns:
Dictionary containing pressure and temperature values. Keys:
"pressure"
(float)"enthalpy"
(float)
- Return type:
dict
- class pypbomb.sd.Reflection
Bases:
object
- static get_eq_state(particle_speed, post_shock_gas, working_gas, error_tol_temperature=0.0001, error_tol_specific_volume=0.0001, max_iterations=500)
This function calculates equilibrium post-reflected-shock state for a specified shock velocity
Original function:
sdtoolbox.reflections.PostReflectedShock_eq
- Parameters:
particle_speed (float) – current post-incident-shock lab frame particle speed
post_shock_gas (ct.Solution) – Working gas mixture in its post-incident-shock state.
working_gas (ct.Solution) – Working gas mixture used for calculations.
error_tol_temperature (float, optional) – Temperature error tolerance for iteration.
error_tol_specific_volume (float, optional) – Specific volume error tolerance for iteration.
max_iterations (int, optional) – Maximum number of loop iterations
- Returns:
working_gas – gas object at equilibrium post-reflected-shock state
- Return type:
ct.Solution
- classmethod reflect(initial_state_gas, post_shock_gas, working_gas, incident_shock_speed)
This function calculates equilibrium post-reflected-shock state assuming u1 = 0.
Original function:
sdtoolbox.reflections.reflected_eq
- Parameters:
initial_state_gas (ct.Solution) – Working gas mixture in its initial, undetonated state.
post_shock_gas (ct.Solution) – Working gas mixture in its post-incident-shock state.
working_gas (ct.Solution) – Working gas mixture used for calculations.
incident_shock_speed (float) – Incident shock speed in m/s.
- Returns:
A tuple containing:
post-reflected-shock pressure in Pascals (float),
reflected shock speed in m/s (float),
Gas object at equilibrium post-reflected-shock state (ct.Solution)
- Return type:
tuple of (float, float, ct.Solution)
- pypbomb.sd.cj_curve_fit(x, y)
Determines least squares fit of parabolic data. This is a vectorized version of
sdtoolbox.PostShock.LSQ_CJspeed
usingnp.linalg.lstsq
.- Parameters:
x (np.array) – Independent data points for curve fitting
y (np.array) – Dependent data points for curve fitting
- Returns:
A tuple containing
(a, b, c, r_squared)
wherea
,b
, andc
are the coefficients of quadratic function \(ax^2 + bx + c = 0\) andr_squared
is the \(R^2\) value of the curve fit.- Return type:
tuple