OpenPNM
OpenPNM copied to clipboard
Add a property attribute to algorithm objects that retrieves a list of applied source terms
One possbiel solution is to subclass __getitem__
on ReactiveTransport
so that if a KeyError
occurs after calling super
, then is check for the special case of if key in ['pore.source']
return {}
, else re-raise KeyError
exception.
I am thinking this is too much magic just to avoid a few try/excepts. I can imagine a few ways to make this work, but in the name of keep the code simple and maintainable, I think it's more obvious and explicit to actually check if any source terms have been defined.
After some discussion is seems like a good refactor candidate to add sources
attribute (or get_sources
method) that returns a dict
with source names as the keys and locations as the values. This can be added in future though, since it won't change the user api, only enhance it. Hence we're moving this issue to "future" changes.
In the V3, the sources are now indicated in the algorithm dict as pore.source.<name>
...so just doing alg['pore.source']
will return a dict with all defined sources given in a dict. The only thing we might do is make it so that alg['pore.source']
returns {} if there are no sources defined yet. This would eliminate the need for any try/except checks.