Skip to content

Commit

Permalink
[samples] Avoid import errors for graphviz draw
Browse files Browse the repository at this point in the history
  • Loading branch information
ischoegl committed Sep 1, 2024
1 parent d276bb0 commit dd20fb8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
20 changes: 12 additions & 8 deletions samples/python/reactors/mix1.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,27 @@
# replaced with a reactor with no outlet, if it is desired to integrate the
# composition leaving the mixer in time, or by an arbitrary network of
# downstream reactors.
res_a = ct.Reservoir(gas_a, name='air')
res_b = ct.Reservoir(gas_b, name='fuel')
downstream = ct.Reservoir(gas_b, name='outlet')
res_a = ct.Reservoir(gas_a, name='Air Reservoir')
res_b = ct.Reservoir(gas_b, name='Fuel Reservoir')
downstream = ct.Reservoir(gas_a, name='Outlet Reservoir')

# %%
# Create a reactor for the mixer. A reactor is required instead of a
# reservoir, since the state will change with time if the inlet mass flow
# rates change or if there is chemistry occurring.
gas_b.TPX = 300.0, ct.one_atm, 'O2:0.21, N2:0.78, AR:0.01'
mixer = ct.IdealGasReactor(gas_b, name='mixer')
mixer = ct.IdealGasReactor(gas_b, name='Mixer')

# %%
# Create two mass flow controllers connecting the upstream reservoirs to the
# mixer, and set their mass flow rates to values corresponding to
# stoichiometric combustion.
mfc1 = ct.MassFlowController(res_a, mixer, mdot=rho_a*2.5/0.21)
mfc2 = ct.MassFlowController(res_b, mixer, mdot=rho_b*1.0)
mfc1 = ct.MassFlowController(res_a, mixer, mdot=rho_a*2.5/0.21, name="Air Inlet")
mfc2 = ct.MassFlowController(res_b, mixer, mdot=rho_b*1.0, name="Fuel Inlet")

# %%
# Connect the mixer to the downstream reservoir with a valve.
outlet = ct.Valve(mixer, downstream, K=10.0)
outlet = ct.Valve(mixer, downstream, K=10.0, name="Valve")

sim = ct.ReactorNet([mixer])

Expand All @@ -84,4 +84,8 @@
# %%
# Show the network structure
# --------------------------
diagram = sim.draw(print_state=True, species="X")
try:
diagram = sim.draw(print_state=True, species="X")
diagram.view("mix1.gv")
except ImportError as err:
print(f"Unable to show network structure:\n{err}")
10 changes: 7 additions & 3 deletions samples/python/reactors/reactor2.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@
# conduct heat

# add a flexible wall (a piston) between r2 and r1
w = ct.Wall(r2, r1, A=1.0, K=0.5e-4, U=100.0)
w = ct.Wall(r2, r1, A=1.0, K=0.5e-4, U=100.0, name="Piston")

# heat loss to the environment. Heat loss always occur through walls, so we
# create a wall separating r2 from the environment, give it a non-zero area,
# and specify the overall heat transfer coefficient through the wall.
w2 = ct.Wall(r2, env, A=1.0, U=500.0)
w2 = ct.Wall(r2, env, A=1.0, U=500.0, name="External Wall")

sim = ct.ReactorNet([r1, r2])

Expand Down Expand Up @@ -118,4 +118,8 @@
# %%
# Show the final state
# --------------------
sim.draw(print_state=True, species="X")
try:
diagram = sim.draw(print_state=True, species="X")
diagram.view("reactor2.gv")
except ImportError as err:
print(f"Unable to show network structure:\n{err}")

0 comments on commit dd20fb8

Please sign in to comment.