mirror of
https://github.com/Cantera/cantera.git
synced 2025-02-25 18:55:29 -06:00
[Reactor] Allow drawing contents for full ReactorNet
This commit is contained in:
parent
e2c6d7f640
commit
37fd15b9c7
@ -92,7 +92,8 @@ def draw_reactor(r, graph=None, graph_attr=None, node_attr=None, print_state=Fal
|
||||
def draw_reactor_net(n, graph_attr=None, node_attr=None, edge_attr=None,
|
||||
heat_flow_attr=None, mass_flow_attr=None,
|
||||
moving_wall_edge_attr=None, surface_edge_attr=None,
|
||||
print_state=False, show_wall_velocity=True, **kwargs):
|
||||
show_wall_velocity=True, print_state=False, species=None,
|
||||
species_units="percent"):
|
||||
"""
|
||||
See `.ReactorNet.draw`.
|
||||
|
||||
@ -119,22 +120,26 @@ def draw_reactor_net(n, graph_attr=None, node_attr=None, edge_attr=None,
|
||||
for name, group in reactor_groups.items():
|
||||
sub = _graphviz.Digraph(name=f"cluster_{name}", graph_attr=graph_attr)
|
||||
for r in group:
|
||||
draw_reactor(r, sub, print_state=print_state, **kwargs)
|
||||
draw_reactor(r, sub, print_state=print_state, species=species,
|
||||
species_units=species_units)
|
||||
drawn_reactors.add(r)
|
||||
flow_controllers.update(r.inlets + r.outlets)
|
||||
walls.update(r.walls)
|
||||
for surface in r.surfaces:
|
||||
draw_surface(surface, sub, print_state=print_state, **kwargs)
|
||||
draw_surface(surface, sub, print_state=print_state, species=species,
|
||||
species_units=species_units)
|
||||
sub.attr(label=name)
|
||||
graph.subgraph(sub)
|
||||
reactors -= drawn_reactors
|
||||
|
||||
for r in reactors:
|
||||
draw_reactor(r, graph, print_state=print_state, **kwargs)
|
||||
draw_reactor(r, graph, print_state=print_state, species=species,
|
||||
species_units=species_units)
|
||||
flow_controllers.update(r.inlets + r.outlets)
|
||||
walls.update(r.walls)
|
||||
for surface in r.surfaces:
|
||||
draw_surface(surface, graph, print_state=print_state, **kwargs)
|
||||
draw_surface(surface, graph, print_state=print_state, species=species,
|
||||
species_units=species_units)
|
||||
|
||||
# some Reactors or Reservoirs only exist as connecting nodes
|
||||
connected_reactors = set()
|
||||
@ -151,21 +156,23 @@ def draw_reactor_net(n, graph_attr=None, node_attr=None, edge_attr=None,
|
||||
# remove already drawn reactors and draw new reactors
|
||||
connected_reactors -= drawn_reactors
|
||||
for r in connected_reactors:
|
||||
draw_reactor(r, graph, print_state=print_state, **kwargs)
|
||||
draw_reactor(r, graph, print_state=print_state, species=species,
|
||||
species_units=species_units)
|
||||
|
||||
fc_edge_attr = {**(edge_attr or {}), **(mass_flow_attr or {})}
|
||||
draw_flow_controllers(flow_controllers, graph, edge_attr=fc_edge_attr, **kwargs)
|
||||
draw_flow_controllers(flow_controllers, graph, edge_attr=fc_edge_attr)
|
||||
w_edge_attr = {**(edge_attr or {}), "color": "red", "style": "dashed",
|
||||
**(heat_flow_attr or {})}
|
||||
draw_walls(walls, graph, edge_attr=w_edge_attr,
|
||||
moving_wall_edge_attr=moving_wall_edge_attr,
|
||||
show_wall_velocity=show_wall_velocity, **kwargs)
|
||||
show_wall_velocity=show_wall_velocity)
|
||||
|
||||
return graph
|
||||
|
||||
|
||||
def draw_surface(surface, graph=None, graph_attr=None, node_attr=None,
|
||||
surface_edge_attr=None, print_state=False, **kwargs):
|
||||
surface_edge_attr=None, print_state=False, species=None,
|
||||
species_units="percent"):
|
||||
"""
|
||||
See `.ReactorSurface.draw`.
|
||||
|
||||
@ -173,7 +180,8 @@ def draw_surface(surface, graph=None, graph_attr=None, node_attr=None,
|
||||
"""
|
||||
|
||||
r = surface.reactor
|
||||
graph = draw_reactor(r, graph, graph_attr, node_attr, print_state, **kwargs)
|
||||
graph = draw_reactor(r, graph, graph_attr, node_attr, print_state, species=species,
|
||||
species_units=species_units)
|
||||
name = f"{r.name} surface"
|
||||
edge_attr = {"style": "dotted", "arrowhead": "none",
|
||||
**(surface_edge_attr or {})}
|
||||
|
@ -884,8 +884,9 @@ cdef class ReactorSurface:
|
||||
"""
|
||||
return self._reactor
|
||||
|
||||
def draw(self, graph=None, *, graph_attr=None, node_attr=None, surface_edge_attr=None,
|
||||
print_state=False, **kwargs):
|
||||
def draw(self, graph=None, *, graph_attr=None, node_attr=None,
|
||||
surface_edge_attr=None, print_state=False, species=None,
|
||||
species_units="percent"):
|
||||
"""
|
||||
Draw the surface as a ``graphviz`` ``dot`` node connected to its reactor.
|
||||
The node is added to an existing ``graph`` if provided.
|
||||
@ -908,8 +909,14 @@ cdef class ReactorSurface:
|
||||
:param print_state:
|
||||
Whether state information of the reactor is printed into its node.
|
||||
Defaults to ``False``
|
||||
:param kwargs:
|
||||
Additional keywords are passed on to ``~.drawnetwork.draw_reactor``.
|
||||
:param species:
|
||||
If ``print_state`` is ``True``, define how species are to be printed.
|
||||
Options are ``'X'`` and ``'Y'`` for mole and mass fractions of all species,
|
||||
respectively, or an iterable that contains the desired species names as
|
||||
strings. Defaults to ``None``.
|
||||
:param species_units:
|
||||
Defines the units the species are displayed in as either ``"percent"`` or
|
||||
``"ppm"``. Defaults to ``"percent"``.
|
||||
:return:
|
||||
``graphviz.graphs.BaseGraph`` object with surface and connected
|
||||
reactor.
|
||||
@ -917,7 +924,7 @@ cdef class ReactorSurface:
|
||||
.. versionadded:: 3.1
|
||||
"""
|
||||
return draw_surface(self, graph, graph_attr, node_attr, surface_edge_attr,
|
||||
print_state, **kwargs)
|
||||
print_state, species, species_units)
|
||||
|
||||
def add_sensitivity_reaction(self, int m):
|
||||
"""
|
||||
@ -2017,8 +2024,8 @@ cdef class ReactorNet:
|
||||
|
||||
def draw(self, *, graph_attr=None, node_attr=None, edge_attr=None,
|
||||
heat_flow_attr=None, mass_flow_attr=None, moving_wall_edge_attr=None,
|
||||
surface_edge_attr=None, print_state=False, show_wall_velocity=True,
|
||||
**kwargs):
|
||||
surface_edge_attr=None, show_wall_velocity=True, print_state=False,
|
||||
species=None, species_units="percent"):
|
||||
"""
|
||||
Draw as ``graphviz.graphs.DiGraph``. Connecting flow controllers and
|
||||
walls are depicted as arrows.
|
||||
@ -2050,18 +2057,25 @@ cdef class ReactorNet:
|
||||
Same as ``edge_attr`` but only applied to edges representing connections
|
||||
between `ReactorSurface` objects and reactors.
|
||||
Default is ``{"style": "dotted", "arrowhead": "none"}``.
|
||||
:param show_wall_velocity:
|
||||
If ``True``, wall movement will be indicated by additional arrows with the
|
||||
corresponding wall velocity as a label.
|
||||
:param print_state:
|
||||
Whether state information of the reactors is printed into each node.
|
||||
Defaults to ``False``.
|
||||
:param kwargs:
|
||||
Additional keywords are passed on to each call of
|
||||
`~.drawnetwork.draw_reactor`, `~.drawnetwork.draw_surface`,
|
||||
`~.drawnetwork.draw_flow_controllers`, and `~.drawnetwork.draw_walls`.
|
||||
:param species:
|
||||
If ``print_state`` is ``True``, define how species are to be printed.
|
||||
Options are ``'X'`` and ``'Y'`` for mole and mass fractions of all species,
|
||||
respectively, or an iterable that contains the desired species names as
|
||||
strings. Defaults to ``None``.
|
||||
:param species_units:
|
||||
Defines the units the species are displayed in as either ``"percent"`` or
|
||||
``"ppm"``. Defaults to ``"percent"``.
|
||||
:return:
|
||||
``graphviz.graphs.BaseGraph`` object with reactor net.
|
||||
|
||||
.. versionadded:: 3.1
|
||||
"""
|
||||
return draw_reactor_net(self, graph_attr, node_attr, edge_attr, heat_flow_attr,
|
||||
mass_flow_attr, moving_wall_edge_attr, surface_edge_attr, print_state,
|
||||
**kwargs)
|
||||
mass_flow_attr, moving_wall_edge_attr, surface_edge_attr,
|
||||
show_wall_velocity, print_state, species, species_units)
|
||||
|
Loading…
Reference in New Issue
Block a user