pyjac.core.create_jacobian module¶
Creates source code for calculating analytical Jacobian matrix.
Estimates usage of the various variables for a given reaction
Parameters: - rxn_ind (into) – Index of reaction of interest.
- rxn (
ReacInfo
) – Reaction of interest. - specs (list of
SpecInfo
) – List of species. - reacs (list of
ReacInfo
) – Full list of reactions. - rev_reacs (list of
ReacInfo
) – List of reversible reactions. - pdep_reacs (list of
ReacInfo
) – List of pressure-dependent reactions.
Returns: - variable_list
- usages
-
pyjac.core.create_jacobian.
write_dr_dy
(file, lang, rev_reacs, rxn, rxn_ind, pres_rxn_ind, get_array)[source]¶ Writes evaluation of the (non-pressure dependent part) of the reaction rate R that is independent of species
Parameters: - file (
File
) – The open file object to write to - lang (str) – The Programming language
- rev_reacs (list of
ReacInfo
) – The list of reverisble reactions - rxn (
ReacInfo
) – The reaction to consider - rxn_ind (int) – The index of the reaction in the mechanism
- pres_rxn_ind (int) – The index of the reaction in the pressure dependent reactions
- get_array (function) – The SMM binded get_array function (or utils.get_array) as required
Returns: Return type: None
- file (
-
pyjac.core.create_jacobian.
write_rates
(file, lang, rxn)[source]¶ Write evaluation of the forward/reverse rate constant
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
write_dr_dy_species
(lang, specs, rxn, pres_rxn_ind, j_sp, sp_j, rxn_ind, rev_reacs, get_array)[source]¶ Returns string for evaluation of the (non-pressure dependent part) of the reaction rate R with respect to a species
j
Parameters: - lang (str) – The Programming language
- specs (list of
SpecInfo
) – The species in the mechanism - rxn (
ReacInfo
) – The reaction to consider - pres_rxn_ind (int) – The index of the reaction in the pressure dependent reactions
- j_sp (int) – The species index
- sp_j (
SpecInfo
) – The species to consider - rxn_ind (int) – The index of the reaction in the mechanism
- rev_reacs (list of
ReacInfo
) – The list of reverisble reactions - get_array (function) – The SMM binded get_array function (or utils.get_array) as required
Returns: jline – Jacobian evaluation line with non-pressure-dependent part of species derivative added.
Return type:
-
pyjac.core.create_jacobian.
write_kc
(file, lang, specs, rxn)[source]¶ Write evaluation of the reaction rate equilibrium constant
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
get_infs
(rxn)[source]¶ Returns the reaction rate parameters for a pressure-dependent reaction
Parameters: rxn ( ReacInfo
) – Reaction object for pressure-dependent reaction (falloff or chemically activated bimolecular)Returns: - beta_0minf (float) – Low-pressure limit temperature exponent minus high-pressure value.
- E_0minf (float) – Low-pressure limit activation energy minus high-pressure value.
- k0kinf (float) – Low-pressure limit reaction coefficient divided by high-pressure value.
-
pyjac.core.create_jacobian.
write_dt_comment
(file, lang, rxn_ind)[source]¶ Writes comment line for temperature partial derivatives of reactions
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
write_dy_comment
(file, lang, rxn_ind)[source]¶ Writes comment line for species mass fraction partial derivatives
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
write_dy_y_finish_comment
(file, lang)[source]¶ Writes comment line for finishing species mass fraction derivatives
Parameters: - file (
File
) – Open file object - lang (str) – Programming language
Returns: Return type: None
- file (
-
pyjac.core.create_jacobian.
get_rxn_params_dt
(rxn, rev=False)[source]¶ Write evaluation of the forward/reverse reaction rate constant
Parameters: Returns: jline – String containing evaluation of forward/reverse reaction rate constant
Return type:
-
pyjac.core.create_jacobian.
write_db_dt_def
(file, lang, specs, reacs, rev_reacs, dBdT_flag, do_unroll)[source]¶ Write definition of dB/dT terms for each species
Parameters: - file (
File
) – The open file object to write to - lang ({'c', 'cuda'}) – The programming language
- specs (list of
SpecInfo
) – The species in the mechanism - reacs (list of
ReacInfo
) – The reactions in the mechanism - rev_reacs (list of
ReacInfo
) – The reversible reactions in the mechanism - dBdT_flag (list of bool) – Upon completion of this method this list contains
True
for the index of all species with non-zero dB/dT entries - do_unroll (bool) – If
True
, turn on Jacobian unrolling
Returns: Return type: None
- file (
-
pyjac.core.create_jacobian.
get_db_dt
(lang, specs, rxn, do_unroll)[source]¶ Write evaluation of dB/dT term
Parameters: Returns: jline – String containing evaluation of dB/dT term
Return type:
-
pyjac.core.create_jacobian.
write_pr
(file, lang, specs, reacs, pdep_reacs, rxn, get_array, last_conc_temp=None)[source]¶ Write the evaluation of the reduced pressure
Parameters: - file (
File
) – The open file object to write to - lang (str) – The Programming language
- specs (list of
SpecInfo
) – The species in the mechanism - reacs (list of
ReacInfo
) – The reactions in the mechanism - pdep_reacs (list of
ReacInfo
) – The pressure dependent reactions (not including PLOG/Chebyshev) reactions in the mechanism - rxn (
ReacInfo
) – The reactio to consider - get_array (function) – The SMM binded get_array function (or utils.get_array) as required
- last_conc_temp (list of tuples) – If specified, the non-unity third body efficiencies and corresponding species for the last pressure dependent reaction
Returns: conc_temp_log – List with (species index, efficiency) for third-body efficiencies.
Return type: - file (
-
pyjac.core.create_jacobian.
write_troe
(file, lang, rxn)[source]¶ Write the evaluation of the Troe falloff terms
Parameters: - file (
File
) – The open file object to write to - lang ({'c', 'cuda'}) – The programming language
- rxn (
ReacInfo
) – The reaction to consider
Returns: Return type: None
- file (
-
pyjac.core.create_jacobian.
write_sri
(file, lang)[source]¶ Write the valuation of the SRI exponent
Parameters: - file (
File
) – The open file object to write to - lang (str) – The programming language
Returns: Return type: None
- file (
-
pyjac.core.create_jacobian.
get_pdep_dt
(lang, rxn, rev_reacs, rxn_ind, pres_rxn_ind, get_array)[source]¶ Write contribution from temperature derivative of reaction rate for a pressure dependent reaction
Parameters: - lang (str) – The Programming language
- rxn (
ReacInfo
) – The reaction to consider - rev_reacs (list of
ReacInfo
) – The list of reverisble reactions - rxn_ind (int) – The index of the reaction in the reaction list
- pres_rxn_ind (int) – The index of the reaction in the pressure dependent reaction list
- get_array (function) – The SMM binded get_array function (or utils.get_array) as required
Returns: Return type: None
-
pyjac.core.create_jacobian.
write_sri_dt
(lang, rxn, beta_0minf, E_0minf, k0kinf)[source]¶ Writes section of line for temperature partial derivative of Troe falloff.
Parameters: Returns: jline – Line fragment with SRI temperature derivative
Return type:
-
pyjac.core.create_jacobian.
write_troe_dt
(lang, rxn, beta_0minf, E_0minf, k0kinf)[source]¶ Writes section of line for temperature partial derivative of Troe falloff.
Parameters: - lang (str) – Programming language, {‘c’, ‘cuda’}
- rxn (
ReacInfo
) – Reaction of interest; pressure dependence expressed with Troe falloff. - beta_0minf (float) – Low-pressure limit temperature exponent minus high-pressure value.
- E_0minf (float) – Low-pressure limit activation energy minus high-pressure value.
- k0kinf (float) – Low-pressure limit reaction coefficient divided by high-pressure value.
Returns: jline – Line fragment with Troe temperature derivative
Return type:
-
pyjac.core.create_jacobian.
write_dcp_dt
(file, lang, specs)[source]¶ Write derivative of cp w.r.t. temperature for each species
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
get_elementary_rxn_dt
(lang, specs, rxn, rxn_ind, rev_idx, get_array, do_unroll)[source]¶ Write contribution from temperature derivative of reaction rate for elementary reaction.
Parameters: - lang (str) – The programming language
- rxn (
ReacInfo
) – The reaction to consider - rxn_ind (int) – The reaction index
- rev_idx (int) – The index of the reaction in the reverse reaction list (if applicable)
- get_array (function) – The SMM binded get_array function (or
utils.get_array
) as required - do_unroll (bool) – If true, Jacobian unrolling is turned on
Returns: jline – Jacobian entry substring with temperature derivative contribution.
Return type:
-
pyjac.core.create_jacobian.
write_cheb_ut
(file, lang, rxn)[source]¶ Computes the derivative of the chebyshev polynomial recursively w.r.t T
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
write_cheb_rxn_dt
(file, lang, jline, rxn, rxn_ind, rev_idx, specs, get_array, do_unroll)[source]¶ Writes the code for the temperature derivative of Chebyshev reactions
Parameters: - file (
File
) – The open file object to write to - lang (str) – The Programming language
- jline (str) – The current jacobian line (containing the non-Chebyshev part of the derivative)
- specs (list of
SpecInfo
) – The species in the mechanism - rxn (
ReacInfo
) – The reaction to consider - rxn_ind (int) – The reaction index
- rev_idx (int) – The index of the reaction in the reverse reaction list (if applicable)
- get_array (function) – The SMM binded get_array function (or utils.get_array) as required
- do_unroll (bool) – If true, Jacobian unrolling is turned on
- file (
-
pyjac.core.create_jacobian.
write_plog_rxn_dt
(file, lang, jline, specs, rxn, rxn_ind, rev_idx, get_array, do_unroll)[source]¶ Writes the code for the temperature derivative of PLog reactions
Parameters: - file (
File
) – The open file object to write to - lang (str) – The Programming language
- jline (str) – The current jacobian line (containing the non-PLog part of the derivative)
- specs (list of
SpecInfo
) – The species in the mechanism - rxn (
ReacInfo
) – The reaction to consider - rxn_ind (int) – The reaction index
- rev_idx (int) – The index of the reaction in the reverse reaction list (if applicable)
- get_array (function) – The SMM binded get_array function (or utils.get_array) as required
- do_unroll (bool) – If true, Jacobian unrolling is turned on
- file (
-
pyjac.core.create_jacobian.
write_dt_completion
(file, lang, specs, J_nplusone_touched, get_array)[source]¶ Finishes calculation of d(partial T / partial t)/dT
Parameters: - file (
File
) – Open file object to write to - lang (str) – The Programming language
- specs (list of
SpecInfo
) – The species in this mechanism - J_nplusone_touched (bool) – If true, the last species has a non-zero contribution to d(partial T / partial t)
- get_array (function) – The SMM binded get_array function (or utils.get_array) as required
- file (
-
pyjac.core.create_jacobian.
write_sub_intro
(path, lang, number, rate_list, this_rev, this_pdep, have_pres_mod_temp, batch_has_m, this_thd, this_troe, this_sri, this_cheb, cheb_dim, this_plog, no_shared, has_nsp)[source]¶ Writes the header and definitions for the Jacobian reaction update subfiles
Parameters: - path (str) – Path to build directory for file.
- lang (str {'c', 'cuda'}) – Programming language
- number (int) – Jacobian subfile number
- rate_list (str) – The required reaction/species rate strings needed for the intro
- this_rev (bool) – If
True
, batch contains a reversible reaction - this_pdep (bool) – If
True
, batch contains pressure dependent (falloff/bimolecular) reaction - have_pres_mod_temp (bool) – If
True
, batch requires definition ofpres_mod_temp
- batch_has_m (bool) – If
True
, batch requires the overall concentration ‘m’ - this_thd (bool) – If
True
, batch has a third-body reaction - this_troe (bool) – If
True
, batch contains a Troe reaction - this_sri (bool) – If
True
, batch contains an SRI reaction - this_cheb (bool) – If
True
, batch contains a Chebyshev reaction - cheb_dim (int) – If
this_cheb
isTrue
, the largest Chebyshev dimension required - this_plog (bool) – If
True
, batch contains a PLOG reaction - no_shared (bool) – If
True
, do not use CUDA shared memory - has_nsp (bool) – If
True
, >=1 reaction has nonzero contribution from the last species
Returns: file – Opened Jacobian file
Return type: File
object
-
pyjac.core.create_jacobian.
write_dy_intros
(path, lang, number, have_jnplus_jplus)[source]¶ Writes the header and definitions for the various Jacobian species update subfiles
Parameters: Returns: file – Jacobian file object
Return type: File
-
pyjac.core.create_jacobian.
write_jacobian
(path, lang, specs, reacs, seen_sp, smm=None)[source]¶ Write Jacobian subroutine in desired language.
Parameters: - path (str) – Path to build directory for file.
- lang (str {'c', 'cuda', 'fortran', 'matlab'}) – Programming language.
- specs (list of SpecInfo) – List of species in the mechanism.
- reacs (list of ReacInfo) – List of reactions in the mechanism.
- seen_sp (list of bool) – List of
bool
;False
if species has (identically) zero rate - smm (shared_memory_manager, optional) – If not
None
, use this to manage shared memory optimization
Returns: Return type: None
-
pyjac.core.create_jacobian.
write_sparse_multiplier
(path, lang, touched, nvars)[source]¶ Write a subroutine that multiplies the non-zero entries of the Jacobian with a column ‘j’ of another matrix.
Parameters: Returns: Return type: None
-
pyjac.core.create_jacobian.
create_jacobian
(lang, mech_name=None, therm_name=None, gas=None, optimize_cache=False, initial_state='', num_blocks=8, num_threads=64, no_shared=False, L1_preferred=True, multi_thread=None, force_optimize=False, build_path='./out/', last_spec=None, skip_jac=False, auto_diff=False)[source]¶ Create Jacobian subroutine from mechanism.
Parameters: - lang ({'c', 'cuda', 'fortran', 'matlab'}) – Language type.
- mech_name (str, optional) – Reaction mechanism filename (e.g. ‘mech.dat’). This or gas must be specified
- therm_name (str, optional) – Thermodynamic database filename (e.g. ‘therm.dat’) or nothing if info in mechanism file.
- gas (cantera.Solution, optional) – The mechanism to generate the Jacobian for. This or
mech_name
must be specified - optimize_cache (bool, optional) – If
True
, use the greedy optimizer to attempt to improve cache hit rates - initial_state (str, optional) – A comma separated list of the initial conditions to use in form T,P,X (e.g. ‘800,1,H2=1.0,O2=0.5’). Temperature in K, P in atm
- num_blocks (int, optional) – The target number of blocks / sm to achieve for cuda
- num_threads (int, optional) – The target number of threads / block to achieve for cuda
- no_shared (bool, optional) – If
True
, do not use the shared_memory_manager to attempt to optimize for CUDA - L1_preferred (bool, optional) – If
True
, prefer a larger L1 cache and a smaller shared memory size for CUDA - multi_thread (int, optional) – The number of threads to use during optimization
- force_optimize (bool, optional) – If
True
, redo the cache optimization even if the same mechanism - build_path (str, optional) – The output directory for the jacobian files
- last_spec (str, optional) – If specified, the species to assign to the last index. Typically should be N2, Ar, He or another inert bath gas
- skip_jac (bool, optional) – If
True
, only the reaction rate subroutines will be generated - auto_diff (bool, optional) – If
True
, generate files for use with the Adept autodifferention library.
Returns: Return type: None