Solvers
Isentropic Solver
- pygasflow.solvers.isentropic.isentropic_solver(param_name, param_value, gamma=1.4, to_dict=False)[source]
Compute all isentropic ratios and Mach number given an input parameter.
- Parameters
- param_namestring
Name of the parameter given in input. Can be either one of:
'm'
: Mach number'pressure'
: Pressure Ratio \(\frac{P}{P_{0}}\)'density'
: Density Ratio \(\frac{\rho}{\rho_{0}}\)'temperature'
: Temperature Ratio \(\frac{T}{T_{0}}\)'crit_area_sub'
: Critical Area Ratio \(\frac{A}{A^{*}}\) for subsonic case.'crit_area_super'
: Critical Area Ratio \(\frac{A}{A^{*}}\) for supersonic case.'mach_angle'
: Mach Angle in degrees.'prandtl_meyer'
: Prandtl-Meyer Angle in degrees.
- param_valuefloat/list/array_like
Actual value of the parameter. If float, list, tuple is given as input, a conversion will be attempted.
- gammafloat, optional
Specific heats ratio. Default to 1.4. Must be > 1.
- to_dictbool, optional
If False, the function returns a list of results. If True, it returns a dictionary in which the keys are listed in the Returns section. Default to False (return a list of results).
- Returns
- marray_like
Mach number
- prarray_like
Pressure Ratio \(\frac{P}{P_{0}}\)
- drarray_like
Density Ratio \(\frac{\rho}{\rho_{0}}\)
- trarray_like
Temperature Ratio \(\frac{T}{T_{0}}\)
- prsarray_like
Critical Pressure Ratio \(\frac{P}{P^{*}}\)
- drsarray_like
Critical Density Ratio \(\frac{\rho}{\rho^{*}}\)
- trsarray_like
Critical Temperature Ratio \(\frac{T}{T^{*}}\)
- ursarray_like
Critical Velocity Ratio \(\frac{U}{U^{*}}\)
- arsarray_like
Critical Area Ratio \(\frac{A}{A^{*}}\)
- maarray_like
Mach Angle
- pmarray_like
Prandtl-Meyer Angle
Examples
Compute all ratios starting from a single Mach number:
>>> from pygasflow import isentropic_solver >>> isentropic_solver("m", 2) [2.0, 0.12780452546295096, 0.2300481458333117, 0.5555555555555556, 0.24192491286747442, 0.36288736930121157, 0.6666666666666667, 2.3515101530718505, 1.6875000000000002, 30.000000000000004, 26.379760813416457]
Compute all parameters starting from the pressure ratio:
>>> isentropic_solver("pressure", 0.12780452546295096) [1.9999999999999996, 0.12780452546295107, 0.23004814583331185, 0.5555555555555558, 0.24192491286747458, 0.3628873693012118, 0.6666666666666669, 2.3515101530718505, 1.6874999999999993, 30.00000000000001, 26.379760813416446]
Compute the Mach number starting from the Mach Angle:
>>> results = isentropic_solver("mach_angle", 25) >>> print(results[0]) 2.3662015831524985
Compute the pressure ratios starting from two Mach numbers:
>>> results = isentropic_solver("m", [2, 3]) >>> print(results[1]) [0.12780453 0.02722368]
Compute the pressure ratios starting from two Mach numbers, returning a dictionary:
>>> results = isentropic_solver("m", [2, 3], to_dict=True) >>> print(results["pr"]) [0.12780453 0.02722368]
Fanno Solver
- pygasflow.solvers.fanno.fanno_solver(param_name, param_value, gamma=1.4, to_dict=False)[source]
Compute all Fanno ratios and Mach number given an input parameter.
- Parameters
- param_namestring
Name of the parameter given in input. Can be either one of:
'm'
: Mach number'pressure'
: Critical Pressure Ratio \(\frac{P}{P^{*}}\)'density'
: Critical Density Ratio \(\frac{\rho}{\rho^{*}}\)'temperature'
: Critical Temperature Ratio \(\frac{T}{T^{*}}\)'total_pressure_sub'
: Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\) for subsonic case.'total_pressure_super'
: Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\) for supersonic case.'velocity'
: Critical Velocity Ratio \(\frac{U}{U^{*}}\).'friction_sub'
: Critical Friction parameter \(\frac{4 f L^{*}}{D}\) for subsonic case.'friction_super'
: Critical Friction parameter \(\frac{4 f L^{*}}{D}\) for supersonic case.'entropy_sub'
: Entropy parameter \(\frac{s^{*} - s}{R}\) for subsonic case.'entropy_super'
: Entropy parameter \(\frac{s^{*} - s}{R}\) for supersonic case.
- param_valuefloat/list/array_like
Actual value of the parameter. If float, list, tuple is given as input, a conversion will be attempted.
- gammafloat, optional
Specific heats ratio. Default to 1.4. Must be > 1.
- to_dictbool, optional
If False, the function returns a list of results. If True, it returns a dictionary in which the keys are listed in the Returns section. Default to False (return a list of results).
- Returns
- marray_like
Mach number
- prsarray_like
Critical Pressure Ratio \(\frac{P}{P^{*}}\)
- drsarray_like
Critical Density Ratio \(\frac{\rho}{\rho^{*}}\)
- trsarray_like
Critical Temperature Ratio \(\frac{T}{T^{*}}\)
- tprsarray_like
Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\)
- ursarray_like
Critical Velocity Ratio \(\frac{U}{U^{*}}\)
- fpsarray_like
Critical Friction Parameter \(\frac{4 f L^{*}}{D}\)
- epsarray_like
Critical Entropy Ratio \(\frac{s^{*} - s}{R}\)
Examples
Compute all ratios starting from a Mach number:
>>> from pygasflow import fanno_solver >>> fanno_solver("m", 2) [2.0, 0.408248290463863, 0.6123724356957945, 0.6666666666666667, 1.6875000000000002, 1.632993161855452, 0.3049965025814798, 0.523248143764548]
Compute the subsonic Mach number starting from the critical friction parameter:
>>> results = fanno_solver("friction_sub", 0.3049965025814798) >>> print(results[0]) 0.6572579935727846
Compute the critical temperature ratio starting from multiple Mach numbers for a gas having specific heat ratio gamma=1.2:
>>> results = fanno_solver("m", [0.5, 1.5], 1.2) >>> print(results[3]) [1.07317073 0.89795918]
Compute the critical temperature ratio starting from multiple Mach numbers for a gas having specific heat ratio gamma=1.2, returning a dictionary:
>>> results = fanno_solver("m", [0.5, 1.5], 1.2, to_dict=True) >>> print(results["trs"]) [1.07317073 0.89795918]
Rayleigh Solver
- pygasflow.solvers.rayleigh.rayleigh_solver(param_name, param_value, gamma=1.4, to_dict=False)[source]
Compute all Rayleigh ratios and Mach number given an input parameter.
- Parameters
- param_namestring
Name of the parameter given in input. Can be either one of:
'm'
: Mach number'pressure'
: Critical Pressure Ratio \(\frac{P}{P^{*}}\)'density'
: Critical Density Ratio \(\frac{\rho}{\rho^{*}}\)'velocity'
: Critical Velocity Ratio \(\frac{U}{U^{*}}\).'temperature_sub'
: Critical Temperature Ratio T/T for subsonic case.'temperature_super'
: Critical Temperature Ratio \(\frac{T}{T^{*}}\) for supersonic case.'total_pressure_sub'
: Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\) for subsonic case.'total_pressure_super'
: Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\) for supersonic case.'total_temperature_sub'
: Critical Total Temperature Ratio \(\frac{T_{0}}{T_{0}^{*}}\) for subsonic case.'total_temperature_super'
: Critical Total Temperature Ratio \(\frac{T_{0}}{T_{0}^{*}}\) for supersonic case.'entropy_sub'
: Entropy parameter \(\frac{s^{*} - s}{R}\) for subsonic case.'entropy_super'
: Entropy parameter \(\frac{s^{*} - s}{R}\) for supersonic case.
- param_valuefloat/list/array_like
Actual value of the parameter. If float, list, tuple is given as input, a conversion will be attempted.
- gammafloat, optional
Specific heats ratio. Default to 1.4. Must be > 1.
- to_dictbool, optional
If False, the function returns a list of results. If True, it returns a dictionary in which the keys are listed in the Returns section. Default to False (return a list of results).
- Returns
- marray_like
Mach number
- prsarray_like
Critical Pressure Ratio \(\frac{P}{P^{*}}\)
- drsarray_like
Critical Density Ratio \(\frac{\rho}{\rho^{*}}\)
- trsarray_like
Critical Temperature Ratio \(\frac{T}{T^{*}}\)
- tprsarray_like
Critical Total Pressure Ratio \(\frac{P_{0}}{P_{0}^{*}}\)
- ttrsarray_like
Critical Total Temperature Ratio \(\frac{T_{0}}{T_{0}^{*}}\)
- ursarray_like
Critical Velocity Ratio \(\frac{U}{U^{*}}\)
- epsarray_like
Critical Entropy Ratio \(\frac{s^{*} - s}{R}\)
Examples
Compute all ratios starting from a single Mach number:
>>> from pygasflow import rayleigh_solver >>> rayleigh_solver("m", 2) [2.0, 0.36363636363636365, 0.6875, 0.5289256198347108, 1.5030959785260414, 0.793388429752066, 1.4545454545454546, 1.2175752061512626]
Compute the subsonic Mach number starting from the critical entropy ratio:
>>> results = rayleigh_solver("entropy_sub", 0.5) >>> print(results[0]) 0.6634188478510624
Compute the critical temperature ratio starting from multiple Mach numbers for a gas having specific heat ratio gamma=1.2:
>>> results = rayleigh_solver("m", [0.5, 1.5], 1.2) >>> print(results[3]) [0.71597633 0.79547115]
Compute the critical temperature ratio starting from multiple Mach numbers for a gas having specific heat ratio gamma=1.2, returning a dictionary:
>>> results = rayleigh_solver("m", [0.5, 1.5], 1.2, to_dict=True) >>> print(results["trs"]) [0.71597633 0.79547115]
Shockwave Solvers
- pygasflow.solvers.shockwave.shockwave_solver(p1_name, p1_value, p2_name='beta', p2_value=90, gamma=1.4, flag='weak', to_dict=False)[source]
Try to compute all the ratios, angles and mach numbers across the shock wave.
Remember: a normal shock wave has a wave angle beta=90 deg.
- Parameters
- p1_namestring
Name of the first parameter given in input. Can be either one of:
'pressure'
: Pressure Ratio \(\frac{P_{2}}{P_{1}}\)'temperature'
: Temperature Ratio \(\frac{T_{2}}{T_{1}}\)'density'
: Density Ratio \(\frac{\rho_{2}}{\rho_{1}}\)'total_pressure'
: Total Pressure Ratio \(\frac{P_{2}^{0}}{P_{1}^{0}}\)'m1'
: Mach upstream of the shock wave'mn1'
: Normal Mach upstream of the shock wave'mn2'
: Normal Mach downstream of the shock wave'beta'
: The shock wave angle [in degrees]. It can only be used ifp2_name='theta'
.'theta'
: The deflection angle [in degrees]. It can only be used ifp2_name='beta'
.
If the parameter is a ratio, it is in the form downstream/upstream:
- p1_valuefloat
Actual value of the parameter.
- p2_namestring, optional
Name of the second parameter. It could either be:
'beta'
: Shock wave angle.'theta'
: Flow deflection angle.'mn1'
: Input Normal Mach number.
Default to
'beta'
.- p2_valuefloat, optional
Value of the angle in degrees. Default to 90 degrees (normal shock wave).
- gammafloat, optional
Specific heats ratio. Default to 1.4. Must be > 1.
- flagstring, optional
Chose what solution to compute if the angle ‘theta’ is provided. Can be either
'weak'
or'strong'
. Default to'weak'
.- to_dictbool, optional
If False, the function returns a list of results. If True, it returns a dictionary in which the keys are listed in the Returns section. Default to False (return a list of results).
- Returns
- m1float
Mach number upstream of the shock wave.
- mn1float
Normal Mach number upstream of the shock wave.
- m2float
Mach number downstream of the shock wave.
- mn2float
Normal Mach number downstream of the shock wave.
- betafloat
Shock wave angle in degrees.
- thetafloat
Flow deflection angle in degrees.
- prfloat
Pressure ratio across the shock wave.
- drfloat
Density ratio across the shock wave.
- trfloat
Temperature ratio across the shock wave.
- tprfloat
Total Pressure ratio across the shock wave.
Examples
Compute all ratios across a normal shockwave starting with the upstream Mach number:
>>> from pygasflow import shockwave_solver >>> shockwave_solver("m1", 2) [2.0, 2.0, 0.5773502691896257, 0.5773502691896257, 90.0, 5.847257748779064e-15, 4.5, 2.666666666666667, 1.6874999999999998, 0.7208738614847455]
Compute all ratios and parameters across an oblique shockwave starting from the shockwave angle and the deflection angle:
>>> shockwave_solver("theta", 8, "beta", 80) [1.511670289641015, 1.4887046212366817, 0.7414131402857721, 0.7051257983356364, 80.0, 7.999999999999998, 2.418948357506694, 1.84271116608139, 1.312711618636739, 0.9333272472012358]
Compute the Mach number downstream of an oblique shockwave starting with multiple upstream Mach numbers:
>>> results = shockwave_solver("m1", [1.5, 3], "beta", [60, 60]) >>> print(results[2]) [1.04454822 1.12256381]
Compute the Mach number downstream of an oblique shockwave starting with multiple upstream Mach numbers, returning a dictionary:
>>> results = shockwave_solver("m1", [1.5, 3], "beta", [60, 60], to_dict=True) >>> print(results["m2"]) [1.04454822 1.12256381]
- pygasflow.solvers.shockwave.conical_shockwave_solver(M1, param_name, param_value, gamma=1.4, flag='weak', to_dict=False)[source]
Try to compute all the ratios, angles and mach numbers across the conical shock wave.
- Parameters
- M1float
Upstream Mach number. Must be M1 > 1.
- param_namestring
Name of the parameter given in input. Can be either one of:
'mc'
: Mach number at the cone’s surface.'theta_c'
: Half cone angle.'beta'
: shock wave angle.
- param_valuefloat
Actual value of the parameter. Requirements:
Mc >= 0
0 < beta <= 90
\(0 < \theta_{c} < 90\)
- gammafloat, optional
Specific heats ratio. Default to 1.4. Must be > 1.
- flagstring, optional
Can be either
'weak'
or'strong'
. Default to'weak'
(in conical shockwaves, the strong solution is rarely encountered).- to_dictbool, optional
If False, the function returns a list of results. If True, it returns a dictionary in which the keys are listed in the Returns section. Default to False (return a list of results).
- Returns
- mfloat
Upstream Mach number.
- mcfloat
Mach number at the surface of the cone.
- theta_cfloat
Half cone angle.
- betafloat
Shock wave angle.
- deltafloat
Flow deflection angle.
- prfloat
Pressure ratio across the shock wave.
- drfloat
Density ratio across the shock wave.
- trfloat
Temperature ratio across the shock wave.
- tprfloat
Total Pressure ratio across the shock wave.
- pc_p1float
Pressure ratio between the cone’s surface and the upstream condition.
- rhoc_rho1float
Density ratio between the cone’s surface and the upstream condition.
- Tc_T1float
Temperature ratio between the cone’s surface and the upstream condition.
Examples
Compute all quantities across a conical shockwave starting from the upstream Mach number and the half cone angle:
>>> from pygasflow import conical_shockwave_solver >>> conical_shockwave_solver(2.5, "theta_c", 15) [2.5, 2.1179295900668067, 15.0, 28.45459370447941, 6.229019180107892, 1.488659699248579, 1.3262664608044694, 1.122443900410184, 0.9936173734022627, 1.8051864085591218, 1.5220731269187135, 1.186005045771711]
Compute the pressure ratio across a conical shockwave starting with multiple upstream Mach numbers and Mach numbers at the cone surface:
>>> results = conical_shockwave_solver([2.5, 5], "mc", 1.5) >>> print(results[5]) [ 3.42459174 18.60172442]
Compute the pressure ratio across a conical shockwave starting with multiple upstream Mach numbers and Mach numbers at the cone surface, but returning a dictionary:
>>> results = conical_shockwave_solver([2.5, 5], "mc", 1.5, to_dict=True) >>> print(results["pr"]) [ 3.42459174 18.60172442]
De Laval Solver
- pygasflow.solvers.de_laval.find_shockwave_area_ratio(Ae_At_ratio, Pe_P0_ratio, R, gamma)[source]
Iterative procedure to find the critical area ratio where the shock wave happens.
- Parameters
- Ae_At_ratiofloat
Area ratio between the exit section of the divergent and the throat section.
- Pe_P0_ratiofloat
Pressure ratio between the back (= exit) pressure to the reservoir pressure.
- Rfloat
Specific Gas Constant.
- gammafloat
Specific Heats ratio.
- Returns
- Asw/Atfloat
The critical area ratio Asw/At
Examples
>>> from pygasflow.solvers import find_shockwave_area_ratio >>> find_shockwave_area_ratio(20, 0.1, 287, 1.4) 14.247517873372033
- class pygasflow.solvers.de_laval.De_Laval_Solver(gas, geometry, input_state, Pb_P0_ratio=None)[source]
Solve a De Laval Nozzle (Convergent-Divergent nozzle), starting from stagnation conditions and the geometry type.
Examples
Visualize all the quantities along the length of a TOP nozzle using air and a back-to-stagnation pressure ratio of 0.12.
from pygasflow.nozzles import CD_TOP_Nozzle from pygasflow.solvers import De_Laval_Solver from pygasflow.utils import Ideal_Gas, Flow_State # Set air as the gas to use in the nozzle gas = Ideal_Gas(287, 1.4) # stagnation condition upstream_state = Flow_State(p0=8 * 101325, t0 = 303.15) Ri = 0.4 # Inlet Radius Rt = 0.2 # Throat Radius Re = 1.2 # Exit (outlet) Radius theta_c = 40 # half cone angle of the divergent theta_N = 15 # half cone angle of the convergent Rbt = 0.75 * Rt # Junction radius between the convergent and divergent Rbc = 1.5 * Rt # Junction radius between the "combustion chamber" and convergent K = 0.8 # Fractional Length of the TOP nozzle geom_type = "axisymmetric" # geometry type geom_top = CD_TOP_Nozzle(Ri, Re, Rt, Rbc, theta_c, K, geom_type, 1000) nozzle_top = De_Laval_Solver(gas, geom_top, upstream_state) nozzle_top.plot(0.12)
(Source code, png, hires.png, pdf)
Compute the critical area ratio where the shockwave is located:
>>> from pygasflow.nozzles import CD_TOP_Nozzle >>> from pygasflow.solvers import De_Laval_Solver >>> from pygasflow.utils import Ideal_Gas, Flow_State >>> gas = Ideal_Gas(287, 1.4) # Set air as the gas to use in the nozzle >>> upstream_state = Flow_State(p0=8 * 101325, t0 = 303.15) # stagnation condition >>> Ri, Rt, Re = 0.4, 0.2, 1.2 >>> theta_c, theta_N = 40, 15 >>> Rbt, Rbc = 0.75 * Rt, 1.5 * Rt >>> geom_top = CD_TOP_Nozzle(Ri, Re, Rt, Rbc, theta_c, 0.8, "axisymmetric") >>> nozzle_top = De_Laval_Solver(gas, geom_top, upstream_state) >>> results = nozzle_top.compute(0.12) >>> print(results[-1]) 12.329635184167444
- De_Laval_Solver.critical_area
Returns the critical area
- De_Laval_Solver.critical_density
Returns the critical density
- De_Laval_Solver.critical_pressure
Returns the critical pressure
- De_Laval_Solver.critical_temperature
Returns the critical temperature
- De_Laval_Solver.critical_velocity
Returns the critical velocity
- De_Laval_Solver.inlet_area
Returns the inlet area
- De_Laval_Solver.outlet_area
Returns the outlet area
- De_Laval_Solver.limit_pressure_ratios
- Returns
- r1float
Exit pressure ratio corresponding to fully subsonic flow in the divergent (when M=1 in A*).
- r2float
Exit pressure ratio corresponding to a normal shock wave at the exit section of the divergent.
- r3float
Exit pressure ratio corresponding to fully supersonic flow in the divergent and Pe = Pb (pressure at back). Design condition.
- pygasflow.solvers.de_laval.De_Laval_Solver.compute(self, Pe_P0_ratio)
Compute the flow quantities along the nozzle geometry.
- Parameters
- Pe_P0_ratiofloat
Back to Stagnation pressure ratio. The pressure at the exit plane coincide with the back pressure.
- Returns
- Lnp.ndarray
Lengths along the stream flow.
- area_ratiosnp.ndarray
Area ratios along the stream flow.
- Mnp.ndarray
Mach numbers.
- P_ratiosnp.ndarray
Pressure ratios.
- rho_ratiosnp.ndarray
Density ratios.
- T_ratiosnp.ndarray
Temperature ratios.
- flow_conditionstring
The flow condition given the input pressure ratio.
- Asw_At_ratiofloat
Area ratio of the shock wave location if present, otherwise return None.
- pygasflow.solvers.de_laval.De_Laval_Solver.flow_condition(self, gas, upstream_state, Pb_P0_ratio)
Return the flow condition inside the nozzle given the Back to Stagnation pressure ratio.
- Parameters
- Pb_P0_ratiofloat
Back to Stagnation pressure ratio.
- Returns
- Flow_Conditionstr
- pygasflow.solvers.de_laval.De_Laval_Solver.plot(self, Pb_P0_ratio=None, show=True, size=None, title=None)
Visualize the nozzle geometry, the Mach number and the ratios along the length of the nozzle.
- Parameters
- Pb_P0_ratiofloat, optional
Back to Stagnation pressure ratio. Default to None.
- size(width, height) or None, optional
Set the figure size, in inches.
- titlestr or None
Title of the overall plot. Default to None, in which case a default title will be added, showing the type of the geometry and the flow condition.