Skip to content

Commit d4607c0

Browse files
committed
[samples] Use Gaussian1 functor where applicable
1 parent 9a5527b commit d4607c0

File tree

3 files changed

+18
-22
lines changed

3 files changed

+18
-22
lines changed

samples/python/reactors/fuel_injection.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
a `MassFlowController`, and the use of the `SolutionArray` class to store results
1010
during reactor network integration and use these results to generate plots.
1111
12-
Requires: cantera >= 2.5.0, matplotlib >= 2.0
12+
Requires: cantera >= 3.1, matplotlib >= 2.0
1313
1414
.. tags:: Python, combustion, reactor network, kinetics, pollutant formation, plotting
1515
"""
@@ -33,17 +33,15 @@
3333
r = ct.IdealGasReactor(gas)
3434
r.volume = 0.001 # 1 liter
3535

36+
def fuel_mdot(total_mass=3.0e-3, std_dev=0.5, center_time=2.0):
37+
"""Create a Gaussian pulse function."""
38+
# units are kg for mass and seconds for times
39+
amplitude = total_mass / (std_dev * np.sqrt(2 * np.pi))
40+
fwhm = std_dev * 2 * np.sqrt(2 * np.log(2))
41+
return ct.Func1("Gaussian", [amplitude, center_time, fwhm])
3642

37-
def fuel_mdot(t):
38-
"""Create an inlet for the fuel, supplied as a Gaussian pulse"""
39-
total = 3.0e-3 # mass of fuel [kg]
40-
width = 0.5 # width of the pulse [s]
41-
t0 = 2.0 # time of fuel pulse peak [s]
42-
amplitude = total / (width * np.sqrt(2*np.pi))
43-
return amplitude * np.exp(-(t-t0)**2 / (2*width**2))
44-
45-
46-
mfc = ct.MassFlowController(inlet, r, mdot=fuel_mdot)
43+
# Create an inlet for the fuel, supplied as a Gaussian pulse
44+
mfc = ct.MassFlowController(inlet, r, mdot=fuel_mdot())
4745

4846
# Create the reactor network
4947
sim = ct.ReactorNet([r])

samples/python/reactors/nanosecond_pulse_discharge.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@
3434
EN_peak = 190 * 1e-21 # 190 Td
3535
pulse_center = 24e-9 # 24 ns
3636
pulse_width = 3e-9 # standard deviation (3 ns)
37-
38-
def gaussian_EN(t):
39-
return EN_peak * np.exp(-((t - pulse_center)**2) / (2 * pulse_width**2))
37+
pulse_fwhm = pulse_width * 2 * (2 * np.log(2))**.5
38+
gaussian_EN = ct.Func1("Gaussian", [EN_peak, pulse_center, pulse_fwhm])
4039

4140
# setup
4241
gas = ct.Solution('example_data/methane-plasma-pavan-2023.yaml')
@@ -55,7 +54,7 @@ def gaussian_EN(t):
5554
dt_chunk = 1e-9 # 1 ns chunk
5655
states = ct.SolutionArray(gas, extra=['t'])
5756

58-
print('{:>10} {:>10} {:>10} {:>14}'.format('t [s]', 'T [K]', 'P [Pa]', 'h [J/kg]'))
57+
print(f"{'t [s]':>10} {'T [K]':>10} {'P [Pa]':>10} {'h [J/kg]':>14}")
5958

6059
# simulate in 1 ns chunks
6160
t = 0.0
@@ -66,8 +65,7 @@ def gaussian_EN(t):
6665
while sim.time < t_end:
6766
sim.advance(sim.time + dt_max) #use sim.step
6867
states.append(r.thermo.state, t=sim.time)
69-
print('{:10.3e} {:10.3f} {:10.3f} {:14.6f}'.format(
70-
sim.time, r.T, r.thermo.P, r.thermo.h))
68+
print(f"{sim.time:10.3e} {r.T:10.3f} {r.thermo.P:10.3f} {r.thermo.h:14.6f}")
7169

7270
EN_t = gaussian_EN(t)
7371
gas.reduced_electric_field = EN_t

test/python/test_reactor.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2474,15 +2474,15 @@ def setup_combustor_tests(self):
24742474
fuel_mdot = factor * fuel_mw
24752475

24762476
# The igniter will use a time-dependent igniter mass flow rate.
2477-
def igniter_mdot(t, t0=0.1, fwhm=0.05, amplitude=0.1):
2478-
return amplitude * math.exp(-(t - t0) ** 2 * 4 * math.log(2) / fwhm ** 2)
2477+
def igniter_mdot(amplitude=0.1, t0=0.1, fwhm=0.05):
2478+
return ct.Func1("Gaussian", [amplitude, t0, fwhm])
24792479

24802480
# create and install the mass flow controllers. Controllers m1 and m2 provide
2481-
# constant mass flow rates, and m3 provides a short Gaussian pulse only to ignite
2482-
# the mixture
2481+
# constant mass flow rates, and m3 provides a short Gaussian pulse only to
2482+
# ignite the mixture
24832483
m1 = ct.MassFlowController(fuel_in, combustor, mdot=fuel_mdot)
24842484
m2 = ct.MassFlowController(oxidizer_in, combustor, mdot=oxidizer_mdot)
2485-
m3 = ct.MassFlowController(igniter, combustor, mdot=igniter_mdot)
2485+
m3 = ct.MassFlowController(igniter, combustor, mdot=igniter_mdot())
24862486

24872487
# put a valve on the exhaust line to regulate the pressure
24882488
valve = ct.Valve(combustor, exhaust, K=1.0)

0 commit comments

Comments
 (0)