pyjac.functional_tester.test module

Module for testing function (accuracy) of pyJac.

class pyjac.functional_tester.test.ReactorConstPres(gas)[source]

Bases: object

Object for constant pressure ODE system.

Parameters:gas (cantera.Solution) – cantera.Solution object with the kinetic system
Returns:
Return type:None
class pyjac.functional_tester.test.ReactorConstVol(gas)[source]

Bases: object

Object for constant volume ODE system.

Initialize ReactorConstVol

Parameters:gas (cantera.Solution) – cantera.Solution object with the kinetic system
Returns:
Return type:None
pyjac.functional_tester.test.convert_mech(mech_filename, therm_filename=None)[source]

Convert a mechanism and return a string with the filename.

Convert a CHEMKIN format mechanism to the Cantera CTI format using the Cantera built-in script ck2cti.

Parameters:
  • mech_filename (str) – Filename of the input CHEMKIN format mechanism. The converted CTI file will have the same name, but with .cti extension.
  • thermo_filename (str) – Filename of the thermodynamic database. Optional, if the thermodynamic database is present in the mechanism input.
Returns:

mech_filename – Filename of converted mechanism in Cantera .cti format.

Return type:

str

class pyjac.functional_tester.test.AutodiffJacob(pressure, fwd_spec_map)[source]

Bases: object

Class for

Initialize autodifferentation object.

Parameters:
  • pressure (float) – Pressure in Pascals
  • fwd_spec_map (numpy.array) – Map of original species indices to new indices
Returns:

Return type:

None

eval_jacobian(gas)[source]

Evaluate finite difference Jacobian using Adept autodifferentiation package.

Parameters:gas (cantera.Solution) – cantera.Solution object with the kinetic system
Returns:jacob – Jacobian matrix evaluated using autodifferentiation
Return type:numpy.array
pyjac.functional_tester.test.is_pdep(rxn)[source]

Check if reaction is traditionally pressure dependent

Parameters:rxn (ReacInfo) – Reaction object of interest
Returns:
Return type:True if third-body, falloff, or chemically activated reaction.
pyjac.functional_tester.test.run_pasr(pasr_input_file, mech_filename, pasr_output_file=None)[source]

Run PaSR simulation to get thermochemical data for testing.

Parameters:
  • pasr_input_file (str) – Name of PaSR input file in YAML format
  • mech_filename (str) – Name of Cantera-format mechanism file
  • pasr_output_file (str) – Optional; filename for saving PaSR output data
Returns:

state_data – Array with state data (time, temperature, pressure, mass fractions)

Return type:

numpy.array

class pyjac.functional_tester.test.cpyjac_evaluator(build_dir, gas, module_name='pyjacob', filename='mechanism.h')[source]

Bases: object

Class for pyJac-based Jacobian matrix evaluator

check_numbers(build_dir, gas, filename='mechanism.h')[source]

Ensure numbers of species and forward reaction match.

Parameters:
  • build_dir (str) – Path of directory for build objects
  • gas (cantera.Solution) – Object with kinetic system
  • filename (str) – Optional; filename of header with mechanism information
Returns:

Return type:

None

check_optimized(build_dir, gas, filename='mechanism.h')[source]

Check if pyJac files were cache-optimized (and thus rearranged)

Parameters:
  • build_dir (str) – Path of directory for build objects
  • gas (cantera.Solution) – Object with kinetic system
  • filename (str) – Optional; filename of header with mechanism information
Returns:

Return type:

None

eval_conc(temp, pres, mass_frac, conc)[source]

Evaluate species concentrations at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • mass_frac (numpy.array) – Species mass fractions
  • conc (numpy.array) – Species concentrations, in kmol/m^3
Returns:

Return type:

None

eval_rxn_rates(temp, pres, conc, fwd_rates, rev_rates)[source]

Evaluate reaction rates of progress at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • conc (numpy.array) – Species concentrations, in kmol/m^3
  • fwd_rates (numpy.array) – Reaction forward rates of progress, in kmol/m^3/s
  • rev_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:

Return type:

None

get_rxn_pres_mod(temp, pres, conc, pres_mod)[source]

Evaluate reaction rate pressure modifications at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • conc (numpy.array) – Species concentrations, in kmol/m^3
  • pres_mod (numpy.array) – Reaction rate pressure modification
Returns:

Return type:

None

eval_spec_rates(fwd_rates, rev_rates, pres_mod, spec_rates)[source]

Evaluate species overall production rates at current state.

Parameters:
  • fwd_rates (numpy.array) – Reaction forward rates of progress, in kmol/m^3/s
  • rev_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
  • pres_mod (numpy.array) – Reaction rate pressure modification
  • spec_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:

Return type:

None

dydt(t, pres, y, dydt)[source]

Evaluate derivative

Parameters:
  • t (float) – Time, in seconds
  • pres (float) – Pressure, in Pascals
  • y (numpy.array) – State vector (temperature + species mass fractions)
  • dydt (numpy.array) – Derivative of state vector
Returns:

Return type:

None

eval_jacobian(t, pres, y, jacob)[source]

Evaluate the Jacobian matrix

Parameters:
  • t (float) – Time, in seconds
  • pres (float) – Pressure, in Pascals
  • y (numpy.array) – State vector (temperature + species mass fractions)
  • jacob (numpy.array) – Jacobian matrix
Returns:

Return type:

None

update(index)[source]

Updates evaluator index

Parameters:index (int) – Index of data for evaluating quantities
Returns:
Return type:None
clean()[source]
class pyjac.functional_tester.test.cupyjac_evaluator(build_dir, gas, state_data)[source]

Bases: pyjac.functional_tester.test.cpyjac_evaluator

Class for CUDA-based pyJac Jacobian matrix evaluator

clean()[source]
update(index)[source]

Updates evaluator index

Parameters:index (int) – Index of data for evaluating quantities
Returns:
Return type:None
czeros(shape)[source]

Return array of zeros in C ordering.

Parameters:shape (int) – Shape of array
Returns:
Return type:numpy.array of zeros with shape shape in C ordering
reshaper(arr, shape, reorder=None)[source]
eval_conc(temp, pres, mass_frac, conc)[source]

Evaluate species concentrations at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • mass_frac (numpy.array) – Species mass fractions
  • conc (numpy.array) – Species concentrations, in kmol/m^3
Returns:

Return type:

None

eval_rxn_rates(temp, pres, conc, fwd_rates, rev_rates)[source]

Evaluate reaction rates of progress at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • conc (numpy.array) – Species concentrations, in kmol/m^3
  • fwd_rates (numpy.array) – Reaction forward rates of progress, in kmol/m^3/s
  • rev_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:

Return type:

None

get_rxn_pres_mod(temp, pres, conc, pres_mod)[source]

Evaluate reaction rate pressure modifications at current state.

Parameters:
  • temp (float) – Temperature, in Kelvin
  • pres (float) – Pressure, in Pascals
  • conc (numpy.array) – Species concentrations, in kmol/m^3
  • pres_mod (numpy.array) – Reaction rate pressure modification
Returns:

Return type:

None

eval_spec_rates(fwd_rates, rev_rates, pres_mod, spec_rates)[source]

Evaluate species overall production rates at current state.

Parameters:
  • fwd_rates (numpy.array) – Reaction forward rates of progress, in kmol/m^3/s
  • rev_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
  • pres_mod (numpy.array) – Reaction rate pressure modification
  • spec_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:

Return type:

None

dydt(t, pres, y, dydt)[source]

Evaluate derivative

Parameters:
  • t (float) – Time, in seconds
  • pres (float) – Pressure, in Pascals
  • y (numpy.array) – State vector (temperature + species mass fractions)
  • dydt (numpy.array) – Derivative of state vector
Returns:

Return type:

None

eval_jacobian(t, pres, y, jacob)[source]

Evaluate the Jacobian matrix

Parameters:
  • t (float) – Time, in seconds
  • pres (float) – Pressure, in Pascals
  • y (numpy.array) – State vector (temperature + species mass fractions)
  • jacob (numpy.array) – Jacobian matrix
Returns:

Return type:

None

class pyjac.functional_tester.test.tchem_evaluator(build_dir, gas, state_data, mechfile, thermofile, module_name='py_tchem', filename='mechanism.h')[source]

Bases: pyjac.functional_tester.test.cpyjac_evaluator

Class for TChem-based Jacobian matrix evaluator

get_conc(conc)[source]

Evaluate species concentrations at current state.

Parameters:conc (numpy.array) – Species concentrations, in kmol/m^3
Returns:
Return type:None
get_rxn_rates(fwd_rates, rev_rates)[source]

Evaluate reaction rates of progress at current state.

Parameters:
  • fwd_rates (numpy.array) – Reaction forward rates of progress, in kmol/m^3/s
  • rev_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:

Return type:

None

get_spec_rates(spec_rates)[source]

Evaluate species overall production rates at current state.

Parameters:spec_rates (numpy.array) – Reaction reverse rates of progress, in kmol/m^3/s
Returns:
Return type:None
get_dydt(dydt)[source]

Evaluate derivative

Parameters:dydt (numpy.array) – Derivative of state vector
Returns:
Return type:None
get_jacobian(jacob)[source]

Evaluate the Jacobian matrix

Parameters:jacob (numpy.array) – Jacobian matrix
Returns:
Return type:None
pyjac.functional_tester.test.safe_remove(file)[source]

Try to safely remove a file

Parameters:file (str) – Path for file to be removed
Returns:
Return type:None
pyjac.functional_tester.test.test(lang, home_dir, build_dir, mech_filename, therm_filename=None, pasr_input_file='pasr_input.yaml', generate_jacob=True, compile_jacob=True, seed=None, pasr_output_file=None, last_spec=None, cache_optimization=False, no_shared=False, tchem_flag=False, only_rxn=None, do_not_remove=False, condition_numbers=None)[source]

Compares pyJac results against Cantera (and optionally TChem) using state data from PaSR simulations.

Parameters:
  • lang ({'c', 'cuda'}) – Programming language
  • home_dir (str) – Path to home directory for testing and data
  • build_dir (str) – Path to directory for building Jacobian files
  • mech_filename (str) – Chemkin- or Cantera-format mechanism file
  • therm_filename (str) – Optional; name of thermodynamic database file (if needed)
  • pasr_input_file (str) – Optional; name of YAML-formatted file with PaSR test input
  • generate_jacob (bool) – Optional; if True, generate Jacobian files. Otherwise, use existing files.
  • compile_jacob (bool) – Optional; if True, compile Jacobian files. Otherwise, using existing.
  • seed (int) – Optional; random seed for PaSR
  • pasr_output_file (str) – Optional; name of output file for saving PaSR results
  • last_spec (str) – Optional; name of species to move to last position. If not specified, will try searching for N2, Ar, or He.
  • cache_optimization (bool) – If True, enable reordering to optimize cache usage
  • no_shared (bool) – If True, do not use GPU shared memory
  • tchem_flag (bool) – If True, compare with TChem results
  • only_rxn (str) – Optional; string with list of reaction numbers to retain. All other reactions removed.
  • do_not_remove (bool) – If True, keep all generated files.
  • condition_numbers (int) – Optional; string with list of conditions numbers to use.
Returns:

Return type:

None