-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Visualize reactor networks using graphviz
#180
Comments
@Naikless ... thanks for the interesting enhancement request! I'm linking (somewhat) related issues: there was some discussion about NetworkX etc. rather than graphviz in #173, and there is a stub about a yaml summary of reactor networks in Cantera/cantera#694 that could potentially be leveraged. |
Thanks for the feedback! I'll check out NetworkX to see whether it might be more suitable. I would also be happy to extend my initial approach to an actual PR, but I believe the following questions would have to be answered before:
Edit: looking more into the cython source, it seems the answer to 2. is that the respective attributes that are currently only declared in the .pxd file would have to be included as properties in the pyx file as well. Is this correct? Any reasons not to implement this? |
I think C++ would be the preferred long-term home for a feature like this so it could be used from any interface. However, something is usually better than nothing, so if you're able to implement this in Python as a first pass, I think that'd still be super helpful! |
Alright. I'll try to come up with something that is mergeable then, so that it can be further reviewed. I also checked out NetworkX. From my perspective, it primarily does the job of defining the graph in terms of nodes and edges. However, the way I see it, this information is already present in the defined reactor net. Thus, implementing a NetworkX representation parallel to that feels redundant. For visualization, NetworkX also invokes graphviz, so I don't think much is gained by this additional abstraction level. I would then go ahead and try to make the above mentioned currently hidden network attributes accessible from the Python site, if nothing speaks against this. |
Abstract
Include the possibility to easily visualize reactor networks by making use of the
graphviz
dot
language.Motivation
Having recently started to work with Cantera's zero dimensional reactor networks, I feel like there is much potential to make it easier for semi-advanced (not even to mention new) Cantera users to get into this topic.
While the creation of arbitrarily complex networks with many reactors that are connected by flow controllers and walls is possible, it is often very hard to verify that what was created is actually what was intended without a visual representation.
Such a visualization should primarily indicate connections between individual reactors. This would help to keep track of mass and energy balances. It could also indicate the state of each reactor, helping in assessing whether the obtained overall state for the network is plausible.
A visual representation of the reactor network is also one of the key elements of CHEMKIN's implementation of reactor networks. Thus including this in Cantera would strengthen the latter's abilities as an open source alternative. Here is an example I found googling.
Possible Solutions
The dot language of the open source
graphviz
graph visualization library allows to easily create schemes of reactor networks automatically. Each reactor is a node, each connection is an edge. The created dot file can be rendered as a vector or raster graphic or kept as a text for further manual editing.A possible (but not flawless) implementation using the python interface of both graphviz and cantera could look like this:
One caveat is that the current python objects are very sparse regarding the saving of network relations:
ReactorNet
objects do not provide a list of all reactors (although their C++ counterpart certainly has it and there is even aself._reactors
attribute created at initialization. Can someone enlighten me why it disappears in Python later?). For this reason, the above implementation needs one to supply a list of all involved reactors instead.self._upstream
andself._downstream
), things would become a lot easier.It would also be useful to allow for dedicated
dot
attributes of reactors, reservoirs, flow controllers and walls to allow to specify things like color, shape and arrow style of the visualization.References
graphviz
referencegraphviz
Python interfaceThe text was updated successfully, but these errors were encountered: