mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[samples] Update samples
This commit is contained in:
parent
cdcc3dd06b
commit
6ccefab009
@ -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
|
enclosing scope. Also shows the use of a PressureController to create a constant
|
||||||
pressure reactor with a fixed volume.
|
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
|
Keywords: combustion, reactor network, well-stirred reactor, plotting
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@ -54,11 +54,11 @@ def mdot(t):
|
|||||||
|
|
||||||
inlet_mfc = ct.MassFlowController(inlet, combustor, mdot=mdot)
|
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
|
# MassFlowController, with an additional pressure-dependent term. By explicitly
|
||||||
# including the upstream mass flow rate, the pressure is kept constant without
|
# 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.
|
# 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
|
# the simulation only contains one reactor
|
||||||
sim = ct.ReactorNet([combustor])
|
sim = ct.ReactorNet([combustor])
|
||||||
@ -69,7 +69,7 @@ states = ct.SolutionArray(gas, extra=['tres'])
|
|||||||
|
|
||||||
residence_time = 0.1 # starting residence time
|
residence_time = 0.1 # starting residence time
|
||||||
while combustor.T > 500:
|
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()
|
sim.advance_to_steady_state()
|
||||||
print('tres = {:.2e}; T = {:.1f}'.format(residence_time, combustor.T))
|
print('tres = {:.2e}; T = {:.1f}'.format(residence_time, combustor.T))
|
||||||
states.append(combustor.thermo.state, tres=residence_time)
|
states.append(combustor.thermo.state, tres=residence_time)
|
||||||
|
@ -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
|
determined by integrating the equation of motion. This requires adding a new
|
||||||
variable to the reactor's state vector which represents the wall velocity.
|
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
|
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
|
# 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
|
# based on the new values for the state vector provided by the ODE solver
|
||||||
self.v_wall = y[self.i_wall]
|
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):
|
def after_eval(self, t, LHS, RHS):
|
||||||
# Calculate the time derivative for the additional equation
|
# Calculate the time derivative for the additional equation
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
Simulation of a (gaseous) Diesel-type internal combustion engine.
|
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
|
center. Note that this example uses numerous simplifying assumptions and
|
||||||
thus serves for illustration purposes only.
|
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,
|
Keywords: combustion, thermodynamics, internal combustion engine,
|
||||||
thermodynamic cycle, reactor network, plotting, pollutant formation
|
thermodynamic cycle, reactor network, plotting, pollutant formation
|
||||||
"""
|
"""
|
||||||
@ -110,7 +109,7 @@ inlet = ct.Reservoir(gas)
|
|||||||
inlet_valve = ct.Valve(inlet, cyl)
|
inlet_valve = ct.Valve(inlet, cyl)
|
||||||
inlet_delta = np.mod(inlet_close - inlet_open, 4 * np.pi)
|
inlet_delta = np.mod(inlet_close - inlet_open, 4 * np.pi)
|
||||||
inlet_valve.valve_coeff = inlet_valve_coeff
|
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)
|
lambda t: np.mod(crank_angle(t) - inlet_open, 4 * np.pi) < inlet_delta)
|
||||||
|
|
||||||
# define injector state (gaseous!)
|
# 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_delta = np.mod(injector_close - injector_open, 4 * np.pi)
|
||||||
injector_t_open = (injector_close - injector_open) / 2. / np.pi / f
|
injector_t_open = (injector_close - injector_open) / 2. / np.pi / f
|
||||||
injector_mfc.mass_flow_coeff = injector_mass / injector_t_open
|
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)
|
lambda t: np.mod(crank_angle(t) - injector_open, 4 * np.pi) < injector_delta)
|
||||||
|
|
||||||
# define outlet pressure (temperature and composition don't matter)
|
# define outlet pressure (temperature and composition don't matter)
|
||||||
@ -133,7 +132,7 @@ outlet = ct.Reservoir(gas)
|
|||||||
outlet_valve = ct.Valve(cyl, outlet)
|
outlet_valve = ct.Valve(cyl, outlet)
|
||||||
outlet_delta = np.mod(outlet_close - outlet_open, 4 * np.pi)
|
outlet_delta = np.mod(outlet_close - outlet_open, 4 * np.pi)
|
||||||
outlet_valve.valve_coeff = outlet_valve_coeff
|
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)
|
lambda t: np.mod(crank_angle(t) - outlet_open, 4 * np.pi) < outlet_delta)
|
||||||
|
|
||||||
# define ambient pressure (temperature and composition don't matter)
|
# 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 is modeled as a moving wall
|
||||||
piston = ct.Wall(ambient_air, cyl)
|
piston = ct.Wall(ambient_air, cyl)
|
||||||
piston.area = A_piston
|
piston.area = A_piston
|
||||||
piston.set_velocity(piston_speed)
|
piston.velocity = piston_speed
|
||||||
|
|
||||||
# create a reactor network containing the cylinder and limit advance step
|
# create a reactor network containing the cylinder and limit advance step
|
||||||
sim = ct.ReactorNet([cyl])
|
sim = ct.ReactorNet([cyl])
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
"""
|
"""
|
||||||
This example solves a plug-flow reactor problem of hydrogen-oxygen combustion.
|
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
|
The PFR is computed by two approaches: The simulation of a Lagrangian fluid
|
||||||
particle, and the simulation of a chain of reactors.
|
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
|
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
|
# 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 in the reactor. The value of K will only affect the transient
|
||||||
# pressure difference.
|
# 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])
|
sim2 = ct.ReactorNet([r2])
|
||||||
|
|
||||||
|
@ -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
|
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.
|
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,
|
Keywords: catalysis, reactor network, surface chemistry, plug flow reactor,
|
||||||
packed bed 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
|
# 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 in the reactor. The value of K will only affect the transient
|
||||||
# pressure difference.
|
# 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])
|
sim = ct.ReactorNet([r])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user