sampling

Module for sampling thermochemical data and global metrics

class pymars.sampling.InputIgnition(kind: str, temperature: float, pressure: float, end_time: float = 0.0, max_steps: int = 10000, equivalence_ratio: float = 0.0, fuel: Dict = {}, oxidizer: Dict = {}, reactants: Dict = {}, composition_type: str = 'mole')

Holds input parameters for a single autoignition case.

composition_type: str

Alias for field number 9

end_time: float

Alias for field number 3

equivalence_ratio: float

Alias for field number 5

fuel: Dict

Alias for field number 6

kind: str

Alias for field number 0

max_steps: int

Alias for field number 4

oxidizer: Dict

Alias for field number 7

pressure: float

Alias for field number 2

reactants: Dict

Alias for field number 8

temperature: float

Alias for field number 1

class pymars.sampling.InputLaminarFlame(temperature: float, pressure: float, width: float = 0.1, equivalence_ratio: float = 0.0, fuel: Dict = {}, oxidizer: Dict = {}, reactants: Dict = {}, composition_type: str = 'mole')

Holds input parameters for single laminar flame simulation.

Freely-propagating laminar flames are inherently constant pressure.

composition_type: str

Alias for field number 7

equivalence_ratio: float

Alias for field number 3

fuel: Dict

Alias for field number 4

oxidizer: Dict

Alias for field number 5

pressure: float

Alias for field number 1

reactants: Dict

Alias for field number 6

temperature: float

Alias for field number 0

width: float

Alias for field number 2

class pymars.sampling.InputPSR(temperature: float, pressure: float, equivalence_ratio: float = 0.0, fuel: Dict = {}, oxidizer: Dict = {}, reactants: Dict = {}, composition_type: str = 'mole')

Holds input parameters for a single perfectly stirred reactor (PSR) case.

PSR cases are modeled as adiabatic and constant-pressure. temperature is the inlet temperature.

composition_type: str

Alias for field number 6

equivalence_ratio: float

Alias for field number 2

fuel: Dict

Alias for field number 3

oxidizer: Dict

Alias for field number 4

pressure: float

Alias for field number 1

reactants: Dict

Alias for field number 5

temperature: float

Alias for field number 0

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.flame_sample_worker(flamesim_tuple)

Worker for multiprocessing of laminar flame cases with data sampling.

Parameters:

flamesim_tuple (tuple) – Tuple of FlameSimulation object to be run and identifier

Returns:

Case identifier mapped to a tuple of the flame speed and sampled data

Return type:

dict

pymars.sampling.flame_worker(flamesim_tuple)

Worker for multiprocessing of laminar flame speed only cases.

Parameters:

flamesim_tuple (tuple) – Tuple of FlameSimulation object to be run and identifier

Returns:

Case identifier and calculated laminar flame speed

Return type:

dict

pymars.sampling.ignition_sample_worker(sim_tuple)

Worker for multiprocessing of autoignition cases with data sampling.

Runs, processes, and cleans up the case entirely within the worker, returning only the (picklable) metric and sampled data – mirroring flame_sample_worker. The intermediate HDF5 file written by run_case is read by process_results and removed by clean here, so the live (unpicklable) reactor never needs to cross the process boundary.

Parameters:

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

Returns:

Case identifier mapped to a tuple of the ignition delay and sampled data

Return type:

dict

pymars.sampling.ignition_worker(sim_tuple)

Worker for multiprocessing of ignition delay only cases.

Parameters:

sim_tuple (tuple) – Tuple of IgnitionSimulation 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.psr_sample_worker(sim_tuple)

Worker for multiprocessing of PSR cases with data sampling.

Runs, processes, and samples the case entirely within the worker (the PSR solver writes no intermediate file), returning the (picklable) metric vector and sampled data.

Parameters:

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

Returns:

Case identifier mapped to a tuple of the PSR metric vector and sampled data

Return type:

dict

pymars.sampling.psr_worker(sim_tuple)

Worker for multiprocessing of PSR metric-only cases.

Parameters:

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

Returns:

Case identifier mapped to the PSR metric vector

Return type:

dict

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:

Combined metrics for the model (ignition delays followed by flame speeds), used for evaluating error

Return type:

numpy.ndarray

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

Samples thermochemical data and generates metrics for various phenomena.

Supports autoignition delay, PSR, and laminar flame speed metrics.

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 YAML 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, min_flame_speed=None)

Evaluates metrics used for determining error of reduced model

Supports autoignition delay, laminar flame speed, and PSR temperature response curve metrics.

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 YAML 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:

Combined metrics for the model (ignition delays, PSR temperature response curve, flame speeds), used for evaluating error

Return type:

numpy.ndarray