Add Matlab examples to sphinx-gallery

This commit is contained in:
Ray Speth
2023-10-03 11:23:39 -04:00
committed by Ray Speth
parent 6eb4f08907
commit faadf015ee
29 changed files with 203 additions and 158 deletions
+3 -1
View File
@@ -121,12 +121,14 @@ if localenv['sphinx_docs']:
copy_sphinx = localenv.RecursiveInstall("#build/doc/sphinx", "sphinx")
copy_python_samples = localenv.RecursiveInstall("#build/doc/samples/python",
"#samples/python")
copy_matlab_ex_samples = localenv.RecursiveInstall(
"#build/doc/samples/matlab_experimental", "#samples/matlab_experimental")
sphinxdocs = build(localenv.Command('build/doc/sphinx/html/index.html',
'sphinx/conf.py', build_sphinx))
env.Alias('sphinx', sphinxdocs)
env.Depends(sphinxdocs, copy_sphinx)
env.Depends(sphinxdocs, copy_python_samples)
env.Depends(sphinxdocs, [copy_python_samples, copy_matlab_ex_samples])
env.Depends(sphinxdocs, env['python_module'])
# Gather all C++ samples into a single directory so they can be presented a single
+6 -2
View File
@@ -49,20 +49,23 @@ extensions = [
sphinx_gallery_conf = {
'filename_pattern': '\.py',
'example_extensions': {'.py', '.cpp', '.h', '.c', '.f', '.f90'},
"filetype_parsers": {'.h': 'C++'},
'example_extensions': {'.py', '.cpp', '.h', '.c', '.f', '.f90', '.m'},
"filetype_parsers": {'.h': 'C++', '.m': 'Matlab'},
'ignore_pattern': r'(__.*__\.py|test_examples\.m)',
'image_srcset': ["2x"],
'examples_dirs': [
'../samples/python/',
'../samples/cxx/',
'../samples/clib/',
'../samples/fortran/',
'../samples/matlab_experimental/',
],
'gallery_dirs': [
'examples/python',
'examples/cxx',
'examples/clib',
'examples/fortran',
'examples/matlab_experimental',
],
'reference_url': {
'cantera': None, # 'None' means the locally-documented module
@@ -125,6 +128,7 @@ tags_badge_colors = {
"Python": "secondary",
"C++": "secondary",
"C": "secondary",
"Matlab": "secondary",
"Fortran 77": "secondary",
"Fortran 90": "secondary",
}
+1
View File
@@ -18,6 +18,7 @@ format.
examples/python/index
examples/cxx/index
examples/clib/index
examples/matlab_experimental/index
examples/fortran/index
_tags/tagsindex
+9 -5
View File
@@ -1,10 +1,14 @@
function F = PFR_Solver(x, soln_vector, gas, mdot, A_in, dAdx, k)
%% Plug flow reactor governing equations
%
% This function defines the spatial derivatives for an ideal gas plug-flow
% reactor, where the cross-sectional area and pressure are allowed to vary,
% axially. The model is set up by the example file 'PFR.m',
% which points the integrator to this function. The integrator integrates the
% derivatives spatially, to solve the density, temperature, and species mass
% fraction profiles as a function of distance x.
% reactor, where the cross-sectional area and pressure are allowed to vary
% axially.
%
% The model is set up by the example file :doc:`plug_flow_reactor.m
% <plug_flow_reactor>`, which points the integrator to this function. The integrator
% integrates the derivatives spatially, to solve the density, temperature, and
% species mass fraction profiles as a function of distance x.
rho = soln_vector(1);
T = soln_vector(2);
+5
View File
@@ -0,0 +1,5 @@
Matlab (experimental) Examples
==============================
These examples are written for use with the "experimental" version of the Cantera Matlab
toolbox that was introduced with Cantera 3.0.
+32 -26
View File
@@ -1,4 +1,4 @@
%% CATCOMB - Catalytic combustion of a stagnation flow on a platinum surface
%% Catalytic combustion of a stagnation flow on a platinum surface
%
% This script solves a catalytic combustion problem. A stagnation flow
% is set up, with a gas inlet 10 cm from a platinum surface at 900
@@ -10,7 +10,7 @@
% The catalytic combustion mechanism is from Deutschmann et al., 26th
% Symp. (Intl.) on Combustion,1996 pp. 1747-1754
%
% Keywords: combustion, catalysis, 1D flow, surface chemistry
% .. tags:: Matlab, combustion, catalysis, 1D flow, surface chemistry
%% Initialization
@@ -29,6 +29,7 @@ tsurf = 900.0; % surface temperature
mdot = 0.06; % kg/m^2/s
transport = 'mixture-averaged'; % transport model
%%
% Solve first for a hydrogen/air case for use as the initial estimate for
% the methane/air case.
@@ -45,19 +46,17 @@ initial_grid = [0.0, 0.02, 0.04, 0.06, 0.08, 0.1]; % m
tol_ss = {1.0e-8 1.0e-14}; % {rtol atol} for steady-state problem
tol_ts = {1.0e-4 1.0e-9}; % {rtol atol} for time stepping
loglevel = 1; % amount of diagnostic output
% (0 to 5)
loglevel = 1; % amount of diagnostic output (0 to 5)
refine_grid = 1; % 1 to enable refinement, 0 to
% disable
refine_grid = 1; % 1 to enable refinement, 0 to disable
%% Create the gas object
%
% This object will be used to evaluate all thermodynamic, kinetic,
% and transport properties
%
% The gas phase will be taken from the definition of phase 'gas' in
% input file 'ptcombust.yaml', which is a stripped-down version of
% The gas phase will be taken from the definition of phase ``gas`` in
% input file ``ptcombust.yaml``, which is a stripped-down version of
% GRI-Mech 3.0.
gas = Solution('ptcombust.yaml', 'gas', transport);
@@ -66,20 +65,22 @@ gas.TPX = {tinlet, p, comp1};
%% Create the interface object
%
% This object will be used to evaluate all surface chemical production
% rates. It will be created from the interface definition 'Pt_surf'
% in input file 'ptcombust.yaml,' which implements the reaction
% rates. It will be created from the interface definition ``Pt_surf``
% in input file ``ptcombust.yaml``, which implements the reaction
% mechanism of Deutschmann et al., 1995 for catalytic combustion on
% platinum.
surf_phase = Interface('ptcombust.yaml', 'Pt_surf', gas);
surf_phase.TP = {tsurf, surf_phase.P};
% integrate the coverage equations in time for 1 s, holding the gas
%%
% Integrate the coverage equations in time for 1 s, holding the gas
% composition fixed to generate a good starting estimate for the
% coverages.
surf_phase.advanceCoverages(1.0);
%%
% The two objects we just created are independent of the problem
% type -- they are useful in zero-D simulations, 1-D simulations,
% etc. Now we turn to creating the objects that are specifically
@@ -90,7 +91,7 @@ surf_phase.advanceCoverages(1.0);
%
% The flow object is responsible for evaluating the 1D governing
% equations for the flow. We will initialize it with the gas
% object, and assign it the name 'flow'.
% object, and assign it the name ``flow``.
flow = AxisymmetricFlow(gas, 'flow');
@@ -100,11 +101,11 @@ flow.setupGrid(initial_grid);
flow.setSteadyTolerances('default', tol_ss{:});
flow.setTransientTolerances('default', tol_ts{:});
%% create the inlet
%% Create the inlet
%
% The temperature, mass flux, and composition (relative molar) may be
% specified. This object provides the inlet boundary conditions for
% the flow equations.
% The temperature, mass flux, and composition (relative molar) may be
% specified. This object provides the inlet boundary conditions for
% the flow equations.
inlt = Inlet(gas, 'inlet');
@@ -113,10 +114,10 @@ inlt.T = tinlet;
inlt.massFlux = mdot;
inlt.setMoleFractions(comp1);
%% create the surface
%% Create the surface
%
% This object provides the surface boundary conditions for the flow
% equations. By supplying object surface_phase as an argument, the
% equations. By supplying object ``surface_phase`` as an argument, the
% coverage equations for its surface species will be added to the
% equation set, and used to compute the surface production rates of
% the gas-phase species.
@@ -124,7 +125,7 @@ inlt.setMoleFractions(comp1);
surf = ReactingSurface(surf_phase, 'surface');
surf.T = tsurf;
%% create the stack
%% Create the stack
%
% Once the component parts have been created, they can be assembled
% to create the 1D simulation.
@@ -148,21 +149,23 @@ stack.setTimeStep(1.0e-5, [1, 3, 6, 12]);
stack.setMaxJacAge(4, 5);
%% Solution
% start with the energy equation on
% Start with the energy equation on
flow.energyEnabled = true;
% disable the surface coverage equations, and turn off all gas and
%%
% Disable the surface coverage equations, and turn off all gas and
% surface chemistry
surf.coverageEnabled = false;
surf_phase.setMultiplier(0.0);
gas.setMultiplier(0.0);
% solve the problem, refining the grid if needed
%%
% Solve the problem, refining the grid if needed
stack.solve(1, refine_grid);
% now turn on the surface coverage equations, and turn the
%%
% Now turn on the surface coverage equations, and turn the
% chemistry on slowly
surf.coverageEnabled = true;
@@ -174,14 +177,17 @@ for iter = 1:6
stack.solve(1, refine_grid);
end
%%
% At this point, we should have the solution for the hydrogen/air
% problem. Now switch the inlet to the methane/air composition.
inlt.setMoleFractions(comp2);
% set more stringent grid refinement criteria
%%
% Set more stringent grid refinement criteria
stack.setRefineCriteria(2, 100.0, 0.15, 0.2);
% solve the problem for the final time
%%
% Solve the problem for the final time
stack.solve(loglevel, refine_grid);
%% Show statistics
+3 -3
View File
@@ -1,9 +1,9 @@
function dydt = conhp(t, y, gas, mw)
% CONHP - ODE system for a constant-pressure, adiabatic reactor.
%% ODE system for a constant-pressure, adiabatic reactor
%
% Function CONHP evaluates the system of ordinary differential equations
% Function ``CONHP`` evaluates the system of ordinary differential equations
% for an adiabatic, constant-pressure, zero-dimensional reactor.
% It assumes that the 'gas' object represents a reacting ideal gas mixture.
% It assumes that the ``gas`` object represents a reacting ideal gas mixture.
% Set the state of the gas, based on the current solution vector.
gas.Y = y(2:end);
+3 -3
View File
@@ -1,9 +1,9 @@
function dydt = conuv(t, y, gas, mw)
% CONUV ODE system for a constant-volume, adiabatic reactor.
%% ODE system for a constant-volume, adiabatic reactor
%
% Function CONUV evaluates the system of ordinary differential
% Function ``CONUV`` evaluates the system of ordinary differential
% equations for an adiabatic, constant-volume, zero-dimensional reactor.
% It assumes that the 'gas' object represents a reacting ideal gas mixture.
% It assumes that the ``gas`` object represents a reacting ideal gas mixture.
% Set the state of the gas, based on the current solution vector.
gas.Y = y(2:end);
+8 -6
View File
@@ -1,16 +1,18 @@
%% DIAMOND_CVD - A CVD example simulating growth of a diamond film
%% Simulating growth of a diamond film by CVD
%
% This example computes the growth rate of a diamond film according to a
% simplified version of a particular published growth mechanism (see file
% diamond.yaml for details). Only the surface coverage equations are solved
% ``diamond.yaml`` for details). Only the surface coverage equations are solved
% here; the gas composition is fixed. (For an example of coupled gas-phase
% and surface, see catalytic_combustion.py.) Atomic hydrogen plays an
% important role in diamond CVD, and this example computes the growth rate
% and surface coverages as a function of [H] at the surface for
% and surface, see :doc:`catcomb.m <catcomb>`).
%
% Atomic hydrogen plays an important role in diamond CVD, and this example computes the
% growth rate and surface coverages as a function of [H] at the surface for
% fixed temperature and [CH3].
%
% Requires: cantera >= 2.6.0, pandas >= 0.25.0, matplotlib >= 2.0
% Keywords: surface chemistry, kinetics
%
% .. tags:: Matlab, surface chemistry, kinetics
%% Initialization
+14 -13
View File
@@ -1,10 +1,11 @@
%% DIFF_FLAME - An opposed-flow diffusion flame.
%% Opposed-flow diffusion flame
%
% This example uses the CounterFlowDiffusionFlame function to solve an
% This example uses the ``CounterFlowDiffusionFlame`` function to solve an
% opposed-flow diffusion flame for Ethane in Air. This example is the same
% as the diffusion_flame.py example without radiation.
% as the :doc:`diffusion_flame.py <../python/onedim/diffusion_flame>`
% example without radiation.
%
% Keywords: combustion, 1D flow, diffusion flame, plotting
% .. tags:: Matlab, combustion, 1D flow, diffusion flame, plotting
%% Initialization
@@ -49,7 +50,7 @@ ox.TPX = {tin, p, oxcomp};
%% Set-up the flow object
%
% For this problem, the AxisymmetricFlow model is needed. Set the state of
% For this problem, the ``AxisymmetricFlow`` model is needed. Set the state of
% the flow as the fuel gas object. This is arbitrary and is only used to
% initialize the flow object. Set the grid to the initial grid defined
% prior, same for the tolerances.
@@ -76,11 +77,11 @@ inlet_f.T = tin;
inlet_f.massFlux = mdot_f;
inlet_f.setMoleFractions(fuelcomp);
%% Create the flame object.
%% Create the flame object
%
% Once the inlets have been created, they can be assembled
% to create the flame object. Function CounterFlorDiffusionFlame
% (in Cantera/1D) sets up the initial guess for the solution using a
% to create the flame object. Function ``CounterFlorDiffusionFlame``
% (in ``Cantera/1D``) sets up the initial guess for the solution using a
% Burke-Schumann flame. The input parameters are: fuel inlet object, flow
% object, oxidizer inlet object, fuel gas object, oxidizer gas object, and
% the name of the oxidizer species as in character format.
@@ -94,28 +95,28 @@ fl = CounterFlowDiffusionFlame(inlet_f, f, inlet_o, fuel, ox, 'O2');
fl.solve(loglevel, 0);
%% Enable the energy equation.
%% Enable the energy equation
%
% The energy equation will now be solved to compute the temperature profile.
% We also tighten the grid refinement criteria to get an accurate final
% solution. The explanation of the setRefineCriteria function is located
% solution. The explanation of the ``setRefineCriteria`` function is located
% on cantera.org in the Matlab User's Guide and can be accessed by
% help setRefineCriteria
% ``help setRefineCriteria``.
f.energyEnabled = true;
fl.setRefineCriteria(2, 200.0, 0.1, 0.2);
fl.solve(loglevel, refine_grid);
%% Show statistics of solution and elapsed time.
%% Show statistics of solution and elapsed time
fl.writeStats;
elapsed = cputime - runtime;
e = sprintf('Elapsed CPU time: %10.4g', elapsed);
disp(e);
%% Plot results
% Make a single plot showing temperature and mass fraction of select
% species along axial distance from fuel inlet to air inlet.
%
z = fl.grid('flow'); % Get grid points of flow
spec = fuel.speciesNames; % Get species names in gas
+2 -2
View File
@@ -1,10 +1,10 @@
function equil(g)
%% EQUIL - A chemical equilibrium example.
%% Methane/air chemical equilibrium
%
% This example computes the adiabatic flame temperature and equilibrium
% composition for a methane/air mixture as a function of equivalence ratio.
%
% Keywords: combustion, equilibrium, plotting
% .. tags:: Matlab, combustion, equilibrium, plotting
clear all
close all
+3 -1
View File
@@ -1,6 +1,8 @@
function f = flame(gas, left, flow, right)
% FLAME - create a flame object.
%% Utility for flame setup
%
% Used by the :doc:`flame1.m <flame1>` and :doc:`flame2.m <flame2>` examples.
% Check input parameters
if nargin ~= 4
error('wrong number of input arguments.');
+8 -7
View File
@@ -1,9 +1,9 @@
%% FLAME1 - A burner-stabilized flat flame
%% Burner-stabilized flat flame
%
% This script simulates a burner-stablized lean hydrogen-oxygen flame
% at low pressure.
%
% Keywords: combustion, 1D flow, burner-stabilized flame, plotting
% .. tags:: Matlab, combustion, 1D flow, burner-stabilized flame, plotting
%% Initialization
@@ -57,7 +57,7 @@ f.setTransientTolerances('default', tol_ts{:});
%% Create the burner
%
% The burner is an Inlet object. The temperature, mass flux,
% The burner is an ``Inlet`` object. The temperature, mass flux,
% and composition (relative molar) may be specified.
burner = Inlet(gas, 'burner');
burner.T = tburner;
@@ -67,7 +67,7 @@ burner.setMoleFractions(comp);
%% Create the outlet
%
% The type of flame is determined by the object that terminates
% the domain. An Outlet object imposes zero gradient boundary
% the domain. An ``Outlet`` object imposes zero gradient boundary
% conditions for the temperature and mass fractions, and zero
% radial velocity and radial pressure gradient.
@@ -76,14 +76,15 @@ s = Outlet(gas, 'out');
%% Create the flame object
%
% Once the component parts have been created, they can be assembled
% to create the flame object.
%
% to create the flame object (see :doc:`flame.m <flame>`).
fl = flame(gas, burner, f, s);
fl.setMaxJacAge(max_jacobian_age(1), max_jacobian_age(2));
%%
% if the starting solution is to be read from a previously-saved
% solution, uncomment this line and edit the file name and solution id.
%restore(fl,'h2flame2.xml', 'energy')
%restore(fl,'h2flame2.yaml', 'energy')
fl.solve(loglevel, refine_grid);
+11 -11
View File
@@ -1,8 +1,8 @@
%% FLAME2 - An axisymmetric stagnation-point non-premixed flame
%% Axisymmetric stagnation-point non-premixed flame
%
% This script simulates a stagnation-point ethane-air flame.
%
% Keywords: combustion, 1D flow, strained flame, diffusion flame, plotting
% .. tags:: Matlab, combustion, 1D flow, strained flame, diffusion flame, plotting
%% Initialization
@@ -27,8 +27,7 @@ comp2 = 'C2H6:1'; % fuel composition
initial_grid = 0.02 * [0.0, 0.2, 0.4, 0.6, 0.8, 1.0]; % m
tol_ss = {1.0e-5, 1.0e-13}; % {rtol atol} for steady-state
% problem
tol_ss = {1.0e-5, 1.0e-13}; % {rtol atol} for steady-state problem
tol_ts = {1.0e-4, 1.0e-13}; % {rtol atol} for time stepping
loglevel = 1; % amount of diagnostic output (0 to 5)
@@ -55,8 +54,8 @@ f.setTransientTolerances('default', tol_ts{:});
%% Create the air inlet
%
% The temperature, mass flux, and composition (relative molar) may be
% specified.
% The temperature, mass flux, and composition (relative molar) may be
% specified.
inlet_o = Inlet(gas, 'air_inlet');
inlet_o.T = tin;
@@ -77,18 +76,19 @@ inlet_f.setMoleFractions(comp2);
fl = flame(gas, inlet_o, f, inlet_f);
%%
% if the starting solution is to be read from a previously-saved
% solution, uncomment this line and edit the file name and solution id.
%restore(fl,'h2flame2.xml', 'energy')
% solve with fixed temperature profile first
%restore(fl,'h2flame2.yaml', 'energy')
% Solve with fixed temperature profile first
fl.solve(loglevel, refine_grid);
%% Enable the energy equation
%
% The energy equation will now be solved to compute the
% temperature profile. We also tighten the grid refinement
% criteria to get an accurate final solution.
% The energy equation will now be solved to compute the temperature profile. We also
% tighten the grid refinement criteria to get an accurate final solution.
f.energyEnabled = true;
fl.setRefineCriteria(2, 200.0, 0.1, 0.1);
+18 -15
View File
@@ -1,11 +1,12 @@
function plotdata = ignite(g)
%% IGNITE Zero-dimensional kinetics: adiabatic, constant pressure.
%% Adiabatic, constant pressure reactor
%
% This example solves the same problem as 'reactor1', but does
% it using one of MATLAB's ODE integrators, rather than using the
% Cantera Reactor class.
% This example solves the same problem as :doc:`reactor1.m <reactor1>`, but does it
% using one of MATLAB's ODE integrators, rather than using the Cantera Reactor
% class. See :doc:`reactor_ode.m <reactor_ode>` for the implementation of the
% governing equations.
%
% Keywords: combustion, reactor network, ignition delay, plotting
% .. tags:: Matlab, combustion, reactor network, ignition delay, plotting
clear all
close all
@@ -37,36 +38,38 @@ function plotdata = ignite(g)
plotdata = output(out, gas);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% the functions below may be defined arbitrarily to set the reactor
%% Time-varying boundary conditions
%
% The functions below may be defined arbitrarily to set the reactor
% boundary conditions - the rate of change of volume, the heat
% flux, and the area.
%
% Rate of change of volume. Any arbitrary function may be implemented.
%
% Input arguments:
% t time
% vol volume
% gas ideal gas object
% :t: time
% :vol: volume
% :gas: ideal gas object
function v = vdot(t, vol, gas)
%v = 0.0; %uncomment for constant volume
v = 1.e11 * (gas.P - 101325.0); % holds pressure very
% close to 1 atm
end
%%
% heat flux (W/m^2).
function q = heatflux(t, gas)
q = 0.0; % adiabatic
end
%%
% surface area (m^2). Used only to compute heat transfer.
function a = area(t, vol)
a = 1.0;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Since the solution variables used by the 'reactor' function are
%%
% Since the solution variables used by the ``reactor`` function are
% not necessarily those desired for output, this function is called
% after the integration is complete to generate the desired
% outputs.
+5 -3
View File
@@ -1,8 +1,10 @@
function ignite_hp(gas)
% IGNITE_HP Solves the same ignition problem as 'ignite', but uses
% function conhp instead of reactor.
%% Constant pressure ignition with user-specified equations
%
% Keywords: combustion, user-defined model, ignition delay, plotting
% Solves the same ignition problem as :doc:`reactor1.m <reactor1>`, but uses
% function :doc:`conhp.m <conhp>` to implement the governing equations.
%
% .. tags:: Matlab, combustion, user-defined model, ignition delay, plotting
clear all
close all
+5 -3
View File
@@ -1,8 +1,10 @@
function ignite_uv(gas)
% IGNITE_UV Solves the same ignition problem as 'ignite2', except
% function conuv is used instead of reactor.
%% Constant volume ignition with user-specified equations
%
% Keywords: combustion, user-defined model, ignition delay, plotting
% Solves the same ignition problem as :doc:`reactor2.m <reactor2>`, except using
% function :doc:`conuv.m <conuv>` to implement the governing equations.
%
% .. tags:: Matlab, combustion, user-defined model, ignition delay, plotting
clear all
close all
+2 -2
View File
@@ -1,10 +1,10 @@
function isentropic(g)
%% ISENTROPIC - isentropic, adiabatic flow example
%% Isentropic, adiabatic flow
%
% In this example, the area ratio vs. Mach number curve is computed for a
% hydrogen/nitrogen gas mixture.
%
% Keywords: thermodynamics, compressible flow, plotting
% .. tags:: Matlab, thermodynamics, compressible flow, plotting
clear all
close all
@@ -1,25 +1,26 @@
%% LITHIUM_ION_BATTERY
%% Lithium-ion battery
%
% This example file calculates the cell voltage of a lithium-ion battery
% at given temperature, pressure, current, and range of state of charge (SOC).
%
% The thermodynamics are based on a graphite anode and a LiCoO2 cathode,
% modeled using the 'BinarySolutionTabulatedThermo' class.
% modeled using the :ct:`BinarySolutionTabulatedThermo` class.
% Further required cell parameters are the electrolyte ionic resistance,
% the stoichiometry ranges of the active materials (electrode balancing),
% and the surface area of the active materials.
%
% The functionality of this example is presented in greater detail in the
% reference (which also describes the derivation of the
% BinarySolutionTabulatedThermo class):
% :ct:`BinarySolutionTabulatedThermo` class).
%
% Reference:
% M. Mayur, S. C. DeCaluwe, B. L. Kee, W. G. Bessler, Modeling and simulation
% of the thermodynamics of lithium-ion battery intercalation materials in the
% open-source software Cantera, Electrochim. Acta 323, 134797 (2019),
% https://doi.org/10.1016/j.electacta.2019.134797
%
% Keywords: surface chemistry, kinetics, electrochemistry, battery, plotting
% M. Mayur, S. C. DeCaluwe, B. L. Kee, W. G. Bessler, Modeling and simulation
% of the thermodynamics of lithium-ion battery intercalation materials in the
% open-source software Cantera, Electrochim. Acta 323, 134797 (2019),
% https://doi.org/10.1016/j.electacta.2019.134797
%
% .. tags:: Matlab, surface chemistry, kinetics, electrochemistry, battery, plotting
%% Initialization
@@ -43,6 +44,7 @@ R_elyt = 0.0384; % [Ohm] Electrolyte resistance
S_ca = 1.1167; % [m^2] Cathode total active material surface area
S_an = 0.7824; % [m^2] Anode total active material surface area
%%
% Electrode balancing: The "balancing" of the electrodes relates the chemical
% composition (lithium mole fraction in the active materials) to the macroscopic
% cell-level state of charge.
+11 -6
View File
@@ -1,23 +1,28 @@
function periodic_cstr
%% PERIODIC_CSTR - A CSTR with steady inputs but periodic interior state.
%% Continuously stirred tank reactor with periodic behavior
%
% This example illustrates a continuously stirred tank reactor (CSTR) with
% steady inputs but periodic interior state.
%
% A stoichiometric hydrogen/oxygen mixture is introduced and reacts to
% produce water. But since water has a large efficiency as a third body
% in the chain termination reaction
%
% H + O2 + M = HO2 + M
% .. math::
%
% \mathrm{ H + O_2 + M \rightleftharpoons HO_2 + M }
%
% as soon as a significant amount of water is produced the reaction stops.
% After enough time has passed that the water is exhausted from the reactor,
% the mixture explodes again and the process repeats. This explanation can be
% verified by decreasing the rate for reaction 7 in file 'h2o2.yaml' and
% verified by decreasing the rate for reaction 7 in file ``h2o2.yaml`` and
% re-running the example.
%
% Acknowledgments: The idea for this example and an estimate of the
% *Acknowledgments*: The idea for this example and an estimate of the
% conditions needed to see the oscillations came from Bob Kee,
% Colorado School of Mines
% Colorado School of Mines.
%
% Keywords: combustion, reactor network, well-stirred reactor, plotting
% .. tags:: Matlab, combustion, reactor network, well-stirred reactor, plotting
clear all
close all
+6 -7
View File
@@ -1,15 +1,14 @@
function plotSolution(s, domain, component)
% Plot a specified solution component. ::
%% Utility for plotting a specific solution component
%
% >> plotSolution(s, domain, component)
%
% :param s:
% :s:
% Instance of class :mat:class:`Sim1D`.
% :param domain:
% Name of domain from which the component should be
% retrieved.
% :param component:
% Name of the component to be plotted.
% :domain:
% Name of domain from which the component should be retrieved.
% :component:
% Name of the component to be plotted
n = s.stackIndex(domain);
d = s.domains{n};
@@ -1,4 +1,4 @@
%% Plug_Flow_Reactor (PFR) - to solve PFR equations for reactors
%% Nozzle with compressible flow
%
% This code snippet is to model a constant area and varying area
% (converging and diverging) nozzle as Plug Flow Reactor with given
@@ -8,19 +8,20 @@
%
% The reactor assumes that the flow follows the Ideal Gas Law.
%
% The governing equations used in this code can be referenced at:
% *S.R Turns, An Introduction to Combustion - Concepts and Applications,
% McGraw Hill Education, India, 2012, 206-210.*
% The governing equations used in this code (see :doc:`PFR_solver.m
% <PFR_solver>`) can be referenced at:
%
% *S.R Turns, An Introduction to Combustion - Concepts and Applications,
% McGraw Hill Education, India, 2012, 206-210.*
%
% The current example is written for methane combustion, but can be readily
% adapted for other chemistries.
%
% Developed by Ashwin Kumar/Dr.Joseph Meadows (mgak@vt.edu/jwm84@vt.edu) on 3-June-2020
% Research Assistant/Assistant Professor
% Advanced Propulsion and Power Laboratory
% Virginia Tech
% Example originally developed by Ashwin Kumar (Research Assistant, mgak@vt.edu) and
% Dr. Joseph Meadows (Assistant Professor, jwm84@vt.edu), Advanced Propulsion and Power
% Laboratory, Virginia Tech.
%
% Keywords: combustion, user-defined model, compressible flow, plotting
% .. tags:: Matlab, combustion, user-defined model, compressible flow, plotting
%% Initialization
+2 -2
View File
@@ -1,11 +1,11 @@
function prandtl1(g)
%% PRANDTL1 - Prandtl number for an equilibrium H/O gas mixture.
%% Prandtl number for an equilibrium H/O gas mixture
%
% This example computes and plots the Prandtl number for a hydrogen / oxygen
% mixture in chemical equilibrium for P = 1 atm and a range of temperatures
% and elemental O/(O+H) ratios.
%
% Keywords: equilibrium, transport, plotting
% .. tags:: Matlab, equilibrium, transport, plotting
clear all
close all
+3 -3
View File
@@ -1,10 +1,10 @@
function prandtl2(g)
%% PRANDTL2 - Prandtl number for an equilibrium H/O gas mixture.
%% Prandtl number for an equilibrium H/O gas mixture
%
% This example does the same thing as prandtl1, but using the
% This example does the same thing as :doc:`prandtl1.m <prandtl1>`, but using the
% multicomponent expression for the thermal conductivity.
%
% Keywords: transport, equilibrium, multicomponent transport, plotting
% .. tags:: Matlab, transport, equilibrium, multicomponent transport, plotting
clear all
close all
+5 -2
View File
@@ -1,6 +1,9 @@
% RANKINE - This example computes the efficiency of a simple vapor power cycle.
%% Rankine cycle
%
% Keywords: thermodynamics, thermodynamic cycle, non-ideal fluid
% Calculate the efficiency of a Rankine vapor power cycle using a pure fluid model
% for water.
%
% .. tags:: Matlab, thermodynamics, thermodynamic cycle, non-ideal fluid
clear all
close all
+3 -3
View File
@@ -1,11 +1,11 @@
function reactor1(g)
%% REACTOR1 Zero-dimensional kinetics: adiabatic, constant pressure.
%% Adiabatic, constant pressure reactor
%
% This example illustrates how to use class 'Reactor' for zero-dimensional
% This example illustrates how to use class ``Reactor`` for zero-dimensional
% kinetics simulations. Here the parameters are set so that the reactor is
% adiabatic and very close to constant pressure.
%
% Keywords: combustion, reactor network, ignition delay, plotting
% .. tags:: Matlab, combustion, reactor network, ignition delay, plotting
clear all
close all
+3 -3
View File
@@ -1,11 +1,11 @@
function reactor2(g)
%% REACTOR2 - Zero-dimensional kinetics: adiabatic, constant volume.
%% Adiabatic, constant volume reactor
%
% This example illustrates how to use class 'Reactor' for zero-dimensional
% This example illustrates how to use class ``Reactor`` for zero-dimensional
% kinetics simulations. Here the parameters are set so that the reactor is
% adiabatic and constant volume.
%
% Keywords: combustion, reactor network, ignition delay, plotting
% .. tags:: Matlab, combustion, reactor network, ignition delay, plotting
clear all
close all
+9 -9
View File
@@ -1,16 +1,16 @@
function dydt = reactor_ode(t, y, gas, vdot, area, heatflux)
%% REACTOR ODE - system for a generic zero-dimensional reactor.
%% ODE system for a generic zero-dimensional reactor
%
% Function REACTOR evaluates the system of ordinary differential equations
% for a zero-dimensional reactor with arbitrary heat transfer and
% volume change.
% Function ``REACTOR_ODE`` evaluates the system of ordinary differential equations
% for a zero-dimensional reactor with arbitrary heat transfer and volume change.
% Used in :doc:`ignite.m <ignite>`.
%
% Solution vector components:
% y(1) Total internal energy U
% y(2) Volume V
% y(3) Mass of species 1
% ....
% y(2+nsp) Mass of last species
% :y(1): Total internal energy U
% :y(2): Volume V
% :y(3): Mass of species 1
% :....:
% :y(2+nsp): Mass of last species
%
[m, n] = size(y);
+3 -3
View File
@@ -1,9 +1,9 @@
%% SURFREACTOR - Zero-dimensional reactor with surface chemistry
%% Zero-dimensional reactor with surface chemistry
%
% This example illustrates how to use class 'Reactor' for zero-dimensional
% This example illustrates how to use class ``Reactor`` for zero-dimensional
% simulations including both homogeneous and heterogeneous chemistry.
%
% Keywords: catalysis, combustion, reactor network, plotting
% .. tags:: Matlab, catalysis, combustion, reactor network, plotting
%% Initialization