utils.py¶
Utilities for running reactors, storing CSP results and plotting them. This page is new in the v1.5 documentation.
Reactors¶
integrate_batch_constP(gas, temperature, pressure, eqratio, FuComp, OxComp, tend, rtol=1e-9, atol=1e-15)- Integrates a constant-pressure batch reactor from the given initial temperature, pressure and equivalence ratio (fuel and oxidizer compositions as Cantera strings) up to
tend. It setsgas.constPand returns a CanteraSolutionArraywith the extra columnstandrhsT(temperature source term). integrate_batch_constV(gas, temperature, pressure, eqratio, FuComp, OxComp, tend, rtol=1e-9, atol=1e-15)- The same for a constant-volume reactor;
gas.constRhois set to the initial mixture density. shared_reactor(reactor_class, gas)- Creates a Cantera reactor of class
reactor_class(e.g.ct.IdealGasConstPressureReactor) that shares thegasobject instead of cloning it, so thatgasfollows the integrated state. This is needed with Cantera > 3.2, which clones the phase by default. New in v1.5.
Data storage¶
TaggedDatabase()- A simple container for time series. Values are stored with
db.store(tag1=value1, tag2=value2, ...)at each step;db.to_arrays()converts the stored lists to numpy arrays; each series is then available asdb.tagordb['tag'].
Plotting¶
save_CSP_plots(db, gas, output_folder='CSP_Plots', threshold=0.05, xlim=None, xlabel='time [s]', species_threshold=1e-3)-
Generates and saves all the plots allowed by the content of a
TaggedDatabase. The tags it recognizes are:Tags Plots API,Ifast,Islow,Pointers,TPIone image per variable or mode, in the folders API/,Ifast/,Islow/,Pointers/,TPI/tsrApi,tsrTpiTSR participation indices evals,M,tsreigenvalues, \(\lambda_{M+1}\) and TSR Mexhausted modes, number of active modes fvecmode amplitudes statetemperature and major species frozenmodes map (slow / exhausted / frozen) ratesrates of progress rhs,splitrhssource term, and its \(\mathcal{S}\,\mathbf{r}\) reconstruction species_typespecies map (fast / slow) Every plot requires the tags
timeandstate(state vector \([\,Y_1,\dots,Y_{N_s},T\,]\)). Only the indices whose absolute value exceedsthresholdtimes the maximum are plotted, and only the species whose mass fraction exceedsspecies_threshold. plot_index_over_time(time, data, temp, threshold, names, output_path, ylabel, title=None, xlim=None, xlabel='time [s]', frozen=None)- Helper that plots the significant columns of an index time series together with the temperature.
Eigenvalues¶
select_eval(evals, indexes)- Given a time series of eigenvalues [N\(_t \times\) N\(_v\)] and an index per time step (e.g. \(M\)), returns the selected eigenvalue at each time step, e.g. \(\lambda_{M+1}\).
reorder_evals(ev, times)- Reorders a time series of eigenvalues so that each column varies continuously in time.
Mechanisms¶
find_duplicate_reactions(R)- Returns the groups of indices of duplicate reactions in the list of Cantera reactions
R.