drgep¶
Module containing Directed Relation Graph with Error Propagation (DRGEP) reduction method.
-
pymars.drgep.
create_drgep_matrix
(state, solution)¶ Creates DRGEP graph adjacency matrix
- Parameters
state (tuple) – Tuple of state with temperature, pressure, and species mass fractions
solution (cantera.Solution) – Cantera object of the solution being analyzed
- Returns
adjacency_matrix – Adjacency matrix based on calculated direct interaction coefficients
- Return type
-
pymars.drgep.
get_importance_coeffs
(species_names, target_species, matrices)¶ Calculate importance coefficients for all species
- Parameters
species_names (list of str) – Species names
target_species (list of str) – List of target species
matrices (list of numpy.ndarray) – List of adjacency matrices
- Returns
importance_coefficients – Maximum coefficients over all sampled states
- Return type
-
pymars.drgep.
graph_search_drgep
(graph, target_species)¶ Searches graph to generate a dictionary of the greatest paths to all species from one of the targets.
- Parameters
graph (networkx.DiGraph) – Graph representing model
target_species (list of str) – List of target species to search from
- Returns
overall_coefficients – Overall interaction coefficients; maximum over all paths from all targets to each species
- Return type
-
pymars.drgep.
mod_dijkstra
(G, source, get_weight, pred=None, paths=None, cutoff=None, target=None)¶ Modified implementation of Dijkstra’s algorithm for DRGEP method.
Multiples values along graph pathways instead of adding and returns a dictionary with nodes as keys and values containing the greatest path to that node. Each edge weight must be <= 1 so that the further they are from the source, the less important they are.
- Parameters
G (networkx.Graph) – Graph to be considered
get_weight (function) – Function for getting edge weight
pred (list, optional) – List of predecessors of a node
paths (dict, optional) – Path from the source to a target node.
cutoff (int or float, optional) – Depth to stop the search. Only paths of length <= cutoff are returned.
- Returns
distance, path (dict) – Returns a tuple of two dictionaries keyed by node. The first dictionary stores distance from the source. The second stores the path from the source to that node.
pred, distance (dict) – Returns two dictionaries representing a list of predecessors of a node and the distance to each node.
distance (dict) – Dictionary of greatest lengths keyed by target.
-
pymars.drgep.
reduce_drgep
(model_file, species_safe, threshold, importance_coeffs, ignition_conditions, sampled_metrics, phase_name='', previous_model=None, num_threads=1, path='')¶ Given a threshold and DRGEP coefficients, reduce the model and determine the error.
- Parameters
model_file (str) – Filename for model being reduced
species_safe (list of str) – List of species to always be retained
threshold (float) – DRG threshold for trimming graph
importance_coeffs (dict) – Dictionary with species and their overall interaction coefficients.
ignition_conditions (list of InputIgnition) – List of autoignition initial conditions.
sampled_metrics (numpy.ndarray) – Global metrics from original model used to evaluate error
phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).
previous_model (ReducedModel, optional) – Model produced at previous threshold level; used to avoid repeated work.
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
- Returns
Return reduced model and associated metadata
- Return type
-
pymars.drgep.
run_drgep
(model_file, ignition_conditions, psr_conditions, flame_conditions, error_limit, species_targets, species_safe, phase_name='', threshold_upper=None, num_threads=1, path='')¶ Main function for running DRGEP reduction.
- Parameters
model_file (str) – Original model file
ignition_conditions (list of InputIgnition) – List of autoignition initial conditions.
psr_conditions (list of InputPSR) – List of PSR simulation conditions.
flame_conditions (list of InputLaminarFlame) – List of laminar flame simulation conditions.
error_limit (float) – Maximum allowable error level for reduced model
species_targets (list of str) – List of target species names
species_safe (list of str) – List of species names to always be retained
phase_name (str, optional) – Optional name for phase to load from CTI file (e.g., ‘gas’).
threshold_upper (float, optional) – Upper threshold (epsilon^*) to identify limbo species for sensitivity analysis
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
- Returns
Return reduced model and associated metadata
- Return type
-
pymars.drgep.
ss_dijkstra_path_length_modified
(G, source, cutoff=None, weight='weight')¶ Compute the greatest path length via multiplication between source and all other reachable nodes for a weighted graph with all weights <= 1.
- Parameters
G (networkx.Graph) – Graph to be considered
source (node label) – Starting node for path
weight (str, optional (default='weight')) – Edge data key corresponding to the edge weight.
cutoff (int or float, optional) – Depth to stop the search. Only paths of length <= cutoff are returned.
- Returns
length – Dictionary of shortest lengths keyed by target.
- Return type
dictionary
Examples
>>> G=networkx.path_graph(5) >>> length=networkx.ss_dijkstra_path_length_modified(G,0) >>> length[4] 1 >>> print(length) {0: 0, 1: 1, 2: 1, 3: 1, 4: 1}
Notes
Edge weight attributes must be numerical and <= 1. Distances are calculated as products of weighted edges traversed. Don’t use a cutoff.
See also
single_source_dijkstra()