Skip to content

Commit

Permalink
[samples] Update samples
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Jun 30, 2023
1 parent d1c8a98 commit 9cf20c7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 17 deletions.
8 changes: 4 additions & 4 deletions samples/python/reactors/combustor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
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
"""

Expand Down Expand Up @@ -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])
Expand All @@ -69,7 +69,7 @@ def mdot(t):

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)
Expand Down
4 changes: 2 additions & 2 deletions samples/python/reactors/custom2.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
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
"""

Expand Down Expand Up @@ -47,7 +47,7 @@ def after_update_state(self, y):
# 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
Expand Down
11 changes: 5 additions & 6 deletions samples/python/reactors/ic_engine.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
"""
Simulation of a (gaseous) Diesel-type internal combustion engine.
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
"""
Expand Down Expand Up @@ -110,7 +109,7 @@ def piston_speed(t):
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!)
Expand All @@ -122,7 +121,7 @@ def piston_speed(t):
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)
Expand All @@ -133,7 +132,7 @@ def piston_speed(t):
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)
Expand All @@ -143,7 +142,7 @@ def piston_speed(t):
# 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])
Expand Down
5 changes: 2 additions & 3 deletions samples/python/reactors/pfr.py
Original file line number Diff line number Diff line change
@@ -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
"""

Expand Down Expand Up @@ -109,7 +108,7 @@
# 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])

Expand Down
4 changes: 2 additions & 2 deletions samples/python/reactors/surf_pfr_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
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
"""
Expand Down Expand Up @@ -95,7 +95,7 @@
# 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])

Expand Down

0 comments on commit 9cf20c7

Please sign in to comment.