[samples] Update samples

This commit is contained in:
Ingmar Schoegl 2023-06-24 20:30:58 -06:00 committed by Ray Speth
parent cdcc3dd06b
commit 6ccefab009
5 changed files with 15 additions and 17 deletions

View File

@ -11,7 +11,7 @@ depends on variables other than time by capturing these variables from the
enclosing scope. Also shows the use of a PressureController to create a constant
pressure reactor with a fixed volume.
Requires: cantera >= 2.5.0, matplotlib >= 2.0
Requires: cantera >= 3.0, matplotlib >= 2.0
Keywords: combustion, reactor network, well-stirred reactor, plotting
"""
@ -54,11 +54,11 @@ def mdot(t):
inlet_mfc = ct.MassFlowController(inlet, combustor, mdot=mdot)
# A PressureController has a baseline mass flow rate matching the 'master'
# A PressureController has a baseline mass flow rate matching the 'primary'
# MassFlowController, with an additional pressure-dependent term. By explicitly
# including the upstream mass flow rate, the pressure is kept constant without
# needing to use a large value for 'K', which can introduce undesired stiffness.
outlet_mfc = ct.PressureController(combustor, exhaust, master=inlet_mfc, K=0.01)
outlet_mfc = ct.PressureController(combustor, exhaust, primary=inlet_mfc, K=0.01)
# the simulation only contains one reactor
sim = ct.ReactorNet([combustor])
@ -69,7 +69,7 @@ states = ct.SolutionArray(gas, extra=['tres'])
residence_time = 0.1 # starting residence time
while combustor.T > 500:
sim.set_initial_time(0.0) # reset the integrator
sim.initial_time = 0.0 # reset the integrator
sim.advance_to_steady_state()
print('tres = {:.2e}; T = {:.1f}'.format(residence_time, combustor.T))
states.append(combustor.thermo.state, tres=residence_time)

View File

@ -14,7 +14,7 @@ acceleration is proportional to the pressure difference, and the velocity is
determined by integrating the equation of motion. This requires adding a new
variable to the reactor's state vector which represents the wall velocity.
Requires: cantera >= 2.6.0, matplotlib >= 2.0
Requires: cantera >= 3.0, matplotlib >= 2.0
Keywords: combustion, reactor network, user-defined model, plotting
"""
@ -47,7 +47,7 @@ class InertialWallReactor(ct.ExtensibleIdealGasReactor):
# This method is used to set the state of the Reactor and Wall objects
# based on the new values for the state vector provided by the ODE solver
self.v_wall = y[self.i_wall]
self.walls[0].set_velocity(self.v_wall)
self.walls[0].velocity = self.v_wall
def after_eval(self, t, LHS, RHS):
# Calculate the time derivative for the additional equation

View File

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
"""
Simulation of a (gaseous) Diesel-type internal combustion engine.
@ -6,7 +5,7 @@ The simulation uses n-Dodecane as fuel, which is injected close to top dead
center. Note that this example uses numerous simplifying assumptions and
thus serves for illustration purposes only.
Requires: cantera >= 2.5.0, scipy >= 0.19, matplotlib >= 2.0
Requires: cantera >= 3.0, scipy >= 0.19, matplotlib >= 2.0
Keywords: combustion, thermodynamics, internal combustion engine,
thermodynamic cycle, reactor network, plotting, pollutant formation
"""
@ -110,7 +109,7 @@ inlet = ct.Reservoir(gas)
inlet_valve = ct.Valve(inlet, cyl)
inlet_delta = np.mod(inlet_close - inlet_open, 4 * np.pi)
inlet_valve.valve_coeff = inlet_valve_coeff
inlet_valve.set_time_function(
inlet_valve.time_function = (
lambda t: np.mod(crank_angle(t) - inlet_open, 4 * np.pi) < inlet_delta)
# define injector state (gaseous!)
@ -122,7 +121,7 @@ injector_mfc = ct.MassFlowController(injector, cyl)
injector_delta = np.mod(injector_close - injector_open, 4 * np.pi)
injector_t_open = (injector_close - injector_open) / 2. / np.pi / f
injector_mfc.mass_flow_coeff = injector_mass / injector_t_open
injector_mfc.set_time_function(
injector_mfc.time_function = (
lambda t: np.mod(crank_angle(t) - injector_open, 4 * np.pi) < injector_delta)
# define outlet pressure (temperature and composition don't matter)
@ -133,7 +132,7 @@ outlet = ct.Reservoir(gas)
outlet_valve = ct.Valve(cyl, outlet)
outlet_delta = np.mod(outlet_close - outlet_open, 4 * np.pi)
outlet_valve.valve_coeff = outlet_valve_coeff
outlet_valve.set_time_function(
outlet_valve.time_function = (
lambda t: np.mod(crank_angle(t) - outlet_open, 4 * np.pi) < outlet_delta)
# define ambient pressure (temperature and composition don't matter)
@ -143,7 +142,7 @@ ambient_air = ct.Reservoir(gas)
# piston is modeled as a moving wall
piston = ct.Wall(ambient_air, cyl)
piston.area = A_piston
piston.set_velocity(piston_speed)
piston.velocity = piston_speed
# create a reactor network containing the cylinder and limit advance step
sim = ct.ReactorNet([cyl])

View File

@ -1,10 +1,9 @@
# -*- coding: utf-8 -*-
"""
This example solves a plug-flow reactor problem of hydrogen-oxygen combustion.
The PFR is computed by two approaches: The simulation of a Lagrangian fluid
particle, and the simulation of a chain of reactors.
Requires: cantera >= 2.5.0, matplotlib >= 2.0
Requires: cantera >= 3.0, matplotlib >= 2.0
Keywords: combustion, reactor network, plug flow reactor
"""
@ -109,7 +108,7 @@ m = ct.MassFlowController(upstream, r2, mdot=mass_flow_rate2)
# We need an outlet to the downstream reservoir. This will determine the
# pressure in the reactor. The value of K will only affect the transient
# pressure difference.
v = ct.PressureController(r2, downstream, master=m, K=1e-5)
v = ct.PressureController(r2, downstream, primary=m, K=1e-5)
sim2 = ct.ReactorNet([r2])

View File

@ -5,7 +5,7 @@ methane over a platinum catalyst in a packed bed reactor. To avoid needing to so
DAE system, the PFR is approximated as a chain of successive WSRs. See surf_pfr.py
for a more advanced implementation that solves the DAE system directly.
Requires: cantera >= 2.5.0
Requires: cantera >= 3.0
Keywords: catalysis, reactor network, surface chemistry, plug flow reactor,
packed bed reactor
"""
@ -95,7 +95,7 @@ m = ct.MassFlowController(upstream, r, mdot=mass_flow_rate)
# We need an outlet to the downstream reservoir. This will determine the
# pressure in the reactor. The value of K will only affect the transient
# pressure difference.
v = ct.PressureController(r, downstream, master=m, K=1e-5)
v = ct.PressureController(r, downstream, primary=m, K=1e-5)
sim = ct.ReactorNet([r])