From 9cf20c780ae6ecd3d1c75abd929cbbe14a13daba Mon Sep 17 00:00:00 2001 From: Ingmar Schoegl Date: Sat, 24 Jun 2023 20:30:58 -0600 Subject: [PATCH] [samples] Update samples --- samples/python/reactors/combustor.py | 8 ++++---- samples/python/reactors/custom2.py | 4 ++-- samples/python/reactors/ic_engine.py | 11 +++++------ samples/python/reactors/pfr.py | 5 ++--- samples/python/reactors/surf_pfr_chain.py | 4 ++-- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/samples/python/reactors/combustor.py b/samples/python/reactors/combustor.py index 08e12d55952..89df4c5bd40 100644 --- a/samples/python/reactors/combustor.py +++ b/samples/python/reactors/combustor.py @@ -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 """ @@ -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 @@ 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) diff --git a/samples/python/reactors/custom2.py b/samples/python/reactors/custom2.py index c418df53bb2..9c519f32748 100644 --- a/samples/python/reactors/custom2.py +++ b/samples/python/reactors/custom2.py @@ -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 """ @@ -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 diff --git a/samples/python/reactors/ic_engine.py b/samples/python/reactors/ic_engine.py index caf5c939760..a8c6624e1b8 100644 --- a/samples/python/reactors/ic_engine.py +++ b/samples/python/reactors/ic_engine.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Simulation of a (gaseous) Diesel-type internal combustion engine. @@ -6,7 +5,7 @@ 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 @@ 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!) @@ -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) @@ -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) @@ -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]) diff --git a/samples/python/reactors/pfr.py b/samples/python/reactors/pfr.py index abc8f3fb20f..84ea319a28a 100644 --- a/samples/python/reactors/pfr.py +++ b/samples/python/reactors/pfr.py @@ -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 @@ # 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]) diff --git a/samples/python/reactors/surf_pfr_chain.py b/samples/python/reactors/surf_pfr_chain.py index 3c8f8039679..85e40e766fa 100644 --- a/samples/python/reactors/surf_pfr_chain.py +++ b/samples/python/reactors/surf_pfr_chain.py @@ -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 """ @@ -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])