ModelUse¶
Utilize the trained neural network to finish downstream tasks.
Created on Wed Jul 27 22:30:20 2022 @author: Yuxiao Yi
- class ModelUse.ModelUse¶
Bases:
object- initGas(mech_path)¶
Instantiate cantera.Solution object.
- Parameters
mech_path (str) – Mechanism input file, could be .yaml, .xml or .cti format.
- buildModel(args)¶
Create a neural network.
- loadModel(modelname, epoch)¶
Load a checkpoint, args and norm on cpu.
- static json2Parser(json_path)¶
Load json and return a parser-like object
- Parameters
json_path (str) – The json file path.
- Returns
args – A parser-like object.
- Return type
easydict.EasyDict
- ctOneStep(state, delta_t, reactor, builtin_t)¶
Use Cantera to advance the state of the reactor network from the current time \(t\) towards \(t+\Delta t\).
- Parameters
state (numpy.ndarray) – State vector organized as T,P(atm),Y.
delta_t (float) – Evolution time step (sec).
reactor (str) – The type of reactor, could be ‘constP’ or ‘constV’.
builtin_t (float) – Max time step for CVODE in Cantera.
- Returns
state_out – The output state vector after \(\Delta t\) which is organized as T,P(atm),Y.
- Return type
- netOneStep(state)¶
Use DNN to advance the state of the reactor network from the current time \(t\) towards \(t+\Delta t\).
- Parameters
state (numpy.ndarray) – State vector organized as T,P(atm),Y.
- Returns
output_bct – The output state vector after \(\Delta t\) which is organized as T,P(atm),Y.
- Return type
- static inverBCT(x, lamda)¶
- evolutionPredict(modelname, epoch, gas_condition, n_step, builtin_t, plotAll=False, dpi=200)¶
Temporal evolution simulation computed by DNN and Cantera, respectively. The simualtion will be saved as .png.
- Parameters
modelname (str) – The folder name of DNN model.
epoch (int) – Epoch for loading checkpoint.
gas_condition (list or tuple) – Initial conditions for zero dimensional ignition. Organized as [Phi,T,P(atm),fuel,reactor]. Phi: equivalence ratio. T: temperature (K). P: pressure (atm). fuel: fuel species name. reactor: reactor type.
n_step (int) – Simulation steps, time step = args.delta_t.
builtin_t (float) – Max time step for CVODES in Cantera.
plotAll (bool,optional) – Whether plot all the features (T,P,Yi), if True plot all else plot temperature. Default False.
dpi (int,optional) – The dpi used to save figure. Default 200.
- plotTemperature(modelname, epoch, gas_condition, state_net, state_cantera, dpi)¶
Draw and save the ignition curves simulated by Cantera and DNN.
- Parameters
modelname (str) – The folder name of DNN model.
epoch (int) – Epoch for loading checkpoint.
gas_condition (list or tuple) – Initial conditions for zero dimensional ignition. Organized as [Phi,T,P(atm),fuel,reactor]. Phi: equivalence ratio. T: temperature (K). P: pressure (atm). fuel: fuel species name. reactor: reactor type.
state_net (numpy.ndarray) – The n-step continuous evolution simulated by DNN.
state_cantera (numpy.ndarray) – The n-step continuous evolution simulated by Cantera.
dpi (int) – The dpi used to save figure.
- plotAll(modelname, epoch, gas_condition, state_net, state_cantera, dpi)¶
Draw and save the evolution of temperature, pressure and species mass fraction simulated by Cantera and DNN.
- Parameters
modelname (str) – The folder name of DNN model.
epoch (int) – Epoch for loading checkpoint.
gas_condition (list or tuple) – Initial conditions for zero dimensional ignition. Organized as [Phi,T,P(atm),fuel,reactor]. Phi: equivalence ratio. T: temperature (K). P: pressure (atm). fuel: fuel species name. reactor: reactor type.
state_net (numpy.ndarray) – The n-step continuous evolution simulated by DNN.
state_cantera (numpy.ndarray) – The n-step continuous evolution simulated by Cantera.
dpi (int) – The dpi used to save figure.
- oneStepPredict(modelname, epoch, input, label, data_name, plot_dims='all', dpi=200)¶
Draw and save single-step prediction of DNN w.r.t an chemical test dataset. The ordinate axis is DNN prediction while abscissa axis is the corresponding label. The scatter plot will be saved in .png format.
- Parameters
modelname (str) – The folder name of DNN model.
epoch (int) – Epoch for loading checkpoint.
input (str or numpy.ndarray) – Input dataset, could be file path or numpy.ndarray.
label (str or numpy.ndarray) – Label dataset, could be file path or numpy.ndarray.
data_name (str) – The data name suffix to save figure.
plot_dims (str,list or tuple,optional) – List of dimensions expected to be plotted e.g. [1,4,5,7] or Range(20) or [‘T’,’O’,’CH4’,’N2’]. Default string ‘all’ means plotting all the dimensions.
dpi (int) – The dpi used to save figure. Default 200.
- Returns
prediction – DNN model one-step prediction on the input dataset.
- Return type
- _oneStepPredPlot(modelname, epoch, label, prediction, dim, data_name, dpi)¶
The built-in function to plot and save one-step prediction.
- static _latexStyle(text)¶
Convert the given text to \(\LaTeX\) bold style e.g. T–>$\bf{T}$, CH4–>$\bf{CH_{4}}$, C10H18O8–>$\bf{C_{10}H_{18}O_{8}}$
- _latexStyleName(index)¶
For a chemical dataset (TPY), the state names could be denoted as [‘T’,’P’,…species names]. Convert state_names[index] to \(\LaTeX\) bold style if there exists \(\LaTeX\) enviroment.