sampling

Module for sampling thermochemical data and global metrics

class pymars.sampling.InputIgnition

Holds input parameters for a single autoignition case.

property composition_type

Alias for field number 9

property end_time

Alias for field number 3

property equivalence_ratio

Alias for field number 5

property fuel

Alias for field number 6

property kind

Alias for field number 0

property max_steps

Alias for field number 4

property oxidizer

Alias for field number 7

property pressure

Alias for field number 2

property reactants

Alias for field number 8

property temperature

Alias for field number 1

class pymars.sampling.InputLaminarFlame

Holds input parameters for single laminar flame simulation.

class pymars.sampling.InputPSR

Holds input parameters for single PSR simulation.

pymars.sampling.calculate_error(metrics_original, metrics_test)

Calculates error of global metrics between test and original model.

Parameters
  • metrics_original (numpy.ndarray) – Metrics serving as basis of error calculation

  • metrics_test (numpy.ndarray) – Metrics for which error is being calculated with respect to metrics_original

Returns

error – Maximum error over all metrics

Return type

float

pymars.sampling.ignition_worker(sim_tuple)

Worker for multiprocessing of ignition delay only cases.

Parameters

sim_tuple (tuple) – Tuple of Simulation object to be run and identifier

Returns

Case identifier and calculated ignition delay

Return type

dict

pymars.sampling.parse_flame_inputs(model, conditions, phase_name='')

Parses input for laminar flame simulations, raising an error on any errors.

Parameters
  • model (str) – Name of Cantera-format kinetic model

  • conditions (dict) – Dictionary with list of laminar flame inputs

  • phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).

Returns

List of validated objects with laminar flame input parameters

Return type

list of InputLaminarFlame

pymars.sampling.parse_ignition_inputs(model, conditions, phase_name='')

Parses input for autoignition simulations, raising an error on any errors.

Parameters
  • model (str) – Name of Cantera-format kinetic model

  • conditions (dict) – Dictionary with list of autoignition inputs

  • phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).

Returns

List of validated objects with autoignition input parameters

Return type

list of InputIgnition

pymars.sampling.parse_psr_inputs(model, conditions, phase_name='')

Parses input for PSR simulations, raising an error on any errors.

Parameters
  • model (str) – Name of Cantera-format kinetic model

  • conditions (dict) – Dictionary with list of PSR inputs

  • phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).

Returns

List of validated objects with PSR input parameters

Return type

list of InputPSR

pymars.sampling.read_metrics(ignition_conditions, psr_conditions=[], flame_conditions=[])

Reads in stored already-sampled metrics.

Parameters
  • ignition_conditions (list of InputIgnition) – List of autoignition initial conditions.

  • psr_conditions (list of InputPSR, optional) – List of PSR simulation conditions.

  • flame_conditions (list of InputLaminarFlame, optional) – List of laminar flame simulation conditions.

Returns

ignition_delays – Calculated metrics for model, used for evaluating error

Return type

numpy.ndarray

pymars.sampling.sample(model, ignition_conditions, psr_conditions=[], flame_conditions=[], phase_name='', num_threads=1, path='')

Samples thermochemical data and generates metrics for various phenomena.

Initially, supports autoignition delay only.

Parameters
  • model (str) – Filename for Cantera model for performing simulations

  • ignition_conditions (list of InputIgnition) – List of autoignition initial conditions.

  • psr_conditions (list of InputPSR, optional) – List of PSR simulation conditions.

  • flame_conditions (list of InputLaminarFlame, optional) – List of laminar flame simulation conditions.

  • phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).

  • num_threads (int) – Number of CPU threads to use for performing simulations in parallel. Optional; default = 1, in which the multiprocessing module is not used. If 0, then use the available number of cores minus one. Otherwise, use the specified number of threads.

  • path (str, optional) – Optional path for writing files

Returns

Metrics, and sampled data

Return type

tuple of numpy.ndarray

pymars.sampling.sample_metrics(model, ignition_conditions, psr_conditions=[], flame_conditions=[], phase_name='', num_threads=1, path='', reuse_saved=False)

Evaluates metrics used for determining error of reduced model

Initially, supports autoignition delay only.

Parameters
  • model (str) – Filename for Cantera model for performing simulations

  • ignition_conditions (list of InputIgnition) – List of autoignition initial conditions.

  • psr_conditions (list of InputPSR, optional) – List of PSR simulation conditions.

  • flame_conditions (list of InputLaminarFlame, optional) – List of laminar flame simulation conditions.

  • phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).

  • num_threads (int, optional) – Number of CPU threads to use for performing simulations in parallel. Optional; default = 1, in which the multiprocessing module is not used. If 0, then use the available number of cores minus one. Otherwise, use the specified number of threads.

  • path (str, optional) – Optional path for writing files

  • reuse_saved (bool, optional) – Flag to reuse saved output

Returns

ignition_delays – Calculated metrics for model, used for evaluating error

Return type

numpy.ndarray

pymars.sampling.simulation_worker(sim_tuple)

Worker for multiprocessing of simulation cases.

Parameters

sim_tuple (tuple) – Contains Simulation object and other parameters needed to setup and run case.

Returns

sim – Object with simulation metadata

Return type

Simulation