API reference (docstrings)¶
This page is generated automatically from the docstrings of the source code. The hand-written description of the classes, in the same layout as the original PDF manual, is in Classes, attributes and methods.
PyCSP.ThermoKinetics
¶
@author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
CanteraThermoKinetics
¶
Bases: Solution
rhs_const_p()
¶
Computes chemical RHS [shape:(ns+1)] for a constant pressure reactor.
rhs_const_v()
¶
Computes chemical RHS [shape:(ns+1)] for a constant volume reactor.
generalized_Stoich_matrix_const_p()
¶
N_v x 2*N_r matrix containing the S components in column major format, such that S dot Rvec yields RHS
generalized_Stoich_matrix_const_v()
¶
N_v x 2*N_r matrix containing the S components in column major format, such that S dot Rvec yields RHS
Rates_vector()
¶
2*Nr-long vector containing the rates of progress in [Kmol/m3/s]
jacobian_const_p()
¶
Computes numerical Jacobian at constant pressure. Returns a N_s+1 x N_s+1 array [jac].
jacobian_const_v()
¶
Computes numerical Jacobian at constant density. Returns a N_s+1 x N_s+1 array [jac].
jac_contribution()
¶
Computes contributions of each reaction to numerical Jacobian. Given that g = Sr = Sum_k S_k r^k, it follows that J(g) = Sum_k^(2nr) J_k, where J_k = Jac(S_k r^k) S_k r^k is the product of the k-th column of the matrix S and the k-th component of the vector r. Returns a (2*Nr, nv, nv) array [jacK], whose sum over the first axis equals the (full or kinetic) Jacobian.
jacobian_diagonal_const_p()
¶
Computes (an approx. to) the diagonal of the numerical Jacobian at constant pressure. Returns a N_s+1 array [diagjac].
jacobian_diagonal_const_v()
¶
Computes (an approx. to) the diagonal of the numerical Jacobian at constant density. Returns a N_s+1 array [diagjac].
jacThermal()
¶
Correction that constrains the species Jacobian to the manifold of constant enthalpy (const_p) or constant internal energy (const_v): J_constrained = J_YY - jacThermal, with jacThermal[i,j] = dg_i/dT * e_j/c, where e_j = h_j, c = cp (const_p) or e_j = u_j, c = cv (const_v), mass-specific species properties.
PyCSP.Functions
¶
@author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
CanteraCSP
¶
Bases: CanteraThermoKinetics
get_kernel()
¶
Retrieves the stored CSP kernel. If any attributes changed before latest query, kernel is recomputed
calc_exhausted_modes(**kwargs)
¶
Computes number of exhausted modes (M). Optional arguments are rtol and atol for the calculation of M. If not provided, uses default or previously set values
calc_subspaces(**kwargs)
¶
Computes subspaces partitioning (M and H). Optional arguments are rtol and atol for the calculation of M, and rtol and atol for the calculation of H. If not provided, uses default or previously set values
calc_TSR(**kwargs)
¶
Computes number of exhausted modes (M) and the TSR. Optional arguments are rtol and atol for the calculation of M. If not provided, uses default or previously set values. The calculated value of M can be retrieved by passing the optional argument getM=True
calc_TSRindices(**kwargs)
¶
Computes number of exhausted modes (M), the TSR and its indices. Optional argument is type, which can be timescale or amplitude. Default value is amplitude. Other optional arguments are rtol and atol for the calculation of M. If not provided, uses default or previously set values. The TSR value can be retrieved by passing getTSR=True, in which case the method returns (TSR, indices). Optional norm_cut (scalar or nv-long array, default None): with index_norm='abs', modes whose CSP indices have a sum of absolute contributions smaller than norm_cut get zero indices (units of that sum: 1/s for type='timescale', the mode-amplitude units for type='amplitude').
calc_CSPindices(**kwargs)
¶
Computes number of exhausted modes (M) and the CSP Indices. Boolean keywords select the indices to compute (all default False): API (amplitude participation), TPI (timescale participation), Impo (fast/slow importance), species_type (fast/slow/trace species). Returns [API, TPI, Ifast, Islow, species_type] (None for those not requested), plus M if getM=True. Optional arguments are rtol and atol for the calculation of M. If not provided, uses default or previously set values. Optional norm_cut (scalar or nv-long array, default None): with index_norm='abs', rows (modes for API/TPI, variables for Ifast/Islow) whose sum of absolute contributions is smaller than norm_cut are set to zero instead of being normalized (units of that sum: the rate of the mode amplitude or variable, 1/s for TPI).
calc_extended_TSR(**kwargs)
¶
Computes number of Extended exhausted modes (Mext) and the extended TSR. Caller must provide either a diffusion rhs with the keyword diff or a convection rhs with the keyword conv, or both (nv-long arrays). Optional arguments are rtol and atol for the calculation of Mext. If not provided, uses default or previously set values. The calculated value of Mext can be retrieved by passing the optional argument getMext=True
calc_extended_TSRindices(**kwargs)
¶
Computes number of Extended exhausted modes (Mext), the extended TSR and its indices. Caller must provide either a diffusion rhs with the keyword diff or a convection rhs with the keyword conv, or both (nv-long arrays). Other optional arguments are rtol and atol for the calculation of Mext. If not provided, uses default or previously set values. The extended TSR can be retrieved by passing the optional argument getTSRext=True, in which case the method returns (TSR_ext, indices). Indices refer to the 2Nr reactions, then the nv convection and the nv diffusion terms.
kernel()
¶
Computes CSP kernel. Its dimension is Nspecies + 1. Returns [evals,Revec,Levec,amplitudes].
kernel_kinetic_only()
¶
Computes kinetic kernel. Its dimension is Nspecies. Returns [evals,Revec,Levec,amplitudes].
kernel_constrained_jac()
¶
Computes constrained kernel (constant enthalpy for const_p, constant internal energy for const_v). Its dimension is Nspecies. Returns [evals,Revec,Levec,amplitudes].
clean_conserved(evals)
¶
Zero-out conserved modes eigenvalues
detectFrozenModes(M, stateYT, Revec, Levec, Smat, rvec, rtol, atol)
¶
Identifies frozen modes among the M exhausted modes (or all modes, if needed). A mode is frozen if the sum of absolute projected reaction rates is small.
Parameters:
M : int Number of exhausted modes (returned by findM). stateYT : array State vector [Species... , T]. Revec : array Right eigenvectors (rows). Levec : array Left eigenvectors (rows). Smat : array Stoichiometric matrix. rvec : array Reaction rates vector. rtol : float Relative tolerance. atol : float Absolute tolerance.
Returns:
frozen_indices : list Indices of modes that are frozen.
TSRindices(weights, evals)
¶
Nv array containing participation index of mode i to TSR
TSR_participation_indices(TSRidx, CSPidx, normtype)
¶
2Nr array containing participation index of reaction k to TSR
eigsys(jac)
¶
Returns eigensystem (evals, Revec, Levec). Input must be a 2D array. Both Revec (since it is transposed) and Levec (naturally) contain row vectors, such that an eigenvector can be retrieved using R/Levec[index,:]
evec_pos_ampl(Revec, Levec, f)
¶
changes sign to eigenvectors based on sign of corresponding mode amplitude.
CSPIndices(Proj, Smat, rvec, normtype, norm_cut=None)
¶
Returns a Nv x 2Nr matrix of indexes, computed as Proj S r. Optional norm_cut (scalar or Nv-long array): rows whose sum of absolute contributions is below the cut are set to zero (only with normtype='abs').
CSPIndices_one_var(Proj_i, Smat, rvec, normtype, norm_cut=None)
¶
Given the i-th row of the projector, computes 2Nr indexes of reactions to variable i. Proj_i must be a nv-long array. Returns a 2Nr-long array
CSP_amplitude_participation_indices(B, Smat, rvec, normtype, norm_cut=None)
¶
Nv x 2Nr array containing participation index of reaction k to mode i
CSP_importance_indices(A, B, M, Smat, rvec, normtype, norm_cut=None)
¶
Nv x 2Nr arrays containing fast/slow importance index of reaction k to variable i
CSP_pointers(A, B)
¶
CSP pointers following Lam & Goussis. - pointers[m,k] = diag_k(Q_m) - Q_m = A_m B_m - m is the mode index - k is the species index
classify_species(stateYT, rhs, pointers, M, trace)
¶
CSP species classification following Lam & Goussis. - pointers[m,k] = diag_k(Q_m) - M = number of fast modes
CSP_participation_to_one_timescale(i, nr, JacK, evals, A, B, normtype, norm_cut=None)
¶
2Nr-long array of contributions of each reaction to the i-th eigenvalue (its real part for a complex-conjugate pair): lambda_i = sum_k b^i J_k a_i.
CSP_timescale_participation_indices(nr, JacK, evals, A, B, normtype, norm_cut=None)
¶
Nv x 2Nr array containing TPI of reaction k to mode i
PyCSP.Solver
¶
Created on Tue Jan 5 12:26:32 2021
@author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
PyCSP.GScheme
¶
Created on Mon Sep 11 15:41:22 2023 Last update on Wed Nov 20 2024 @author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
PyCSP.Simplify
¶
Created on Tue Jan 5 12:26:32 2021
@author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
CSPsimplify
¶
norm_cut
property
writable
¶
Optional scalar cut on the sum of absolute contributions below which CSP importance / TSR indices are set to zero (see CanteraCSP.calc_CSPindices).
merge_mechanisms(gasdtl, species1, species2)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gasdtl
|
Cantera's Solution object
|
Cantera's Solution object of the detailed mechanism. |
required |
species1
|
Python List
|
List object containing the species of first mech, e.g. mech.species_names. |
required |
species2
|
Python List
|
List object containing the species of first mech, e.g. mech.species_names. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
species |
Python List
|
List of the species of the merged mechanism. |
reactions |
Python List
|
List of the reactions of the merged mechanism.. |
PyCSP.utils
¶
Created on Wed Dec 23 17:51:37 2020
@author: Riccardo Malpica Galassi, Sapienza University, Roma, Italy
TaggedDatabase
¶
shared_reactor(reactor_class, gas)
¶
Creates a Cantera reactor that shares (does not clone) the gas object,
so that gas follows the integrated state and CSP quantities can be
queried directly on it. Cantera > 3.2 clones the phase by default.
select_eval(evals, indexes)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
evals
|
2D numpy array containing a series of eigenvalues.
|
|
required |
indexes
|
1D numpy array with integer indexes (e.g. M). Note that indexes start from zero!
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
eval |
1D numpy array with selected eigenvalues
|
|
reorder_evals(ev, times)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ev
|
2D numpy array containing a series of eigenvalues.
|
|
required |
times
|
1D numpy array containing the corresponding times
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
newev |
2D numpy array with continuous (along dim=0) eigenvalues
|
|
integrate_batch_constP(gas, temperature, pressure, eqratio, FuComp, OxComp, tend, rtol=1e-09, atol=1e-15)
¶
Integrates the constant-pressure batch reactor.
Parameters: gas (ct.Solution): Cantera gas object. temperature (float): Initial temperature [K]. pressure (float): Initial pressure [Pa]. eqratio (float): Equivalence ratio. FuComp (str): Fuel composition. OxComp (str): Oxidizer composition. tend (float): End time for the simulation [s]. rtol (float): Relative tolerance for the integrator. atol (float): Absolute tolerance for the integrator.
Returns: ct.SolutionArray: Solution array containing states and additional data.
integrate_batch_constV(gas, temperature, pressure, eqratio, FuComp, OxComp, tend, rtol=1e-09, atol=1e-15)
¶
Integrates the constant-volume batch reactor.
Parameters: gas (ct.Solution): Cantera gas object. temperature (float): Initial temperature [K]. pressure (float): Initial pressure [Pa]. eqratio (float): Equivalence ratio. FuComp (str): Fuel composition. OxComp (str): Oxidizer composition. tend (float): End time for the simulation [s]. rtol (float): Relative tolerance for the integrator. atol (float): Absolute tolerance for the integrator.
Returns: ct.SolutionArray: Solution array containing states and additional data.
find_duplicate_reactions(R)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
R
|
an instance of a Reaction object, e.g.:
|
|
required |
R
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
duplicates |
a list of lists of duplicate reactions
|
|
plot_index_over_time(time, data, temp, threshold, names, output_path, ylabel, title=None, xlim=None, xlabel='time [s]', frozen=None)
¶
Helper function to plot indices over time. data: 2D array (time, items) names: list of names for items threshold: relative threshold (fraction of max absolute value)
save_CSP_plots(db, gas, output_folder='CSP_Plots', threshold=0.05, xlim=None, xlabel='time [s]', species_threshold=0.001)
¶
Generates and saves all requested CSP plots.