ModelsDict

class ModelsDict(*args, **kwargs)[source]

Bases: openpnm.utils.misc.PrintableDict

This subclassed dictionary is assigned to the models attribute of all objects that inherit from the ModelsMixin class. Each dictionary entry corresponds to an entry in the target object’s dictionary, and contains the models and associated parameters for generating the model.

The main features of this subclass are three methods the help resolve the order in which models should be called: dependency_list, dependency_graph, and dependency_map.

dependency_graph(deep=False)[source]

Returns a NetworkX graph object of the dependencies

Parameters

deep (bool, optional) – Defines whether intra- or inter-object dependency graph is desired. Default is False, i.e. only returns dependencies within the object.

Notes

To visualize the dependencies, the following NetworkX function and settings is helpful:

>>> import openpnm as op
>>> net = op.network.Cubic(shape=[3, 3, 3])
>>> geo = op.geometry.StickAndBall(network=net,
...                                pores=net.Ps,
...                                throats=net.Ts)
>>> dtree = geo.models.dependency_graph()
>>> import networkx as nx
>>> nx.draw_spectral(dtree,
...                  arrowsize=50,
...                  font_size=32,
...                  with_labels=True,
...                  node_size=2000,
...                  width=3.0,
...                  edge_color='lightgrey',
...                  font_weight='bold')
dependency_list()[source]

Returns a list of dependencies in the order with which they should be called to ensure data is calculated by one model before it’s asked for by another.

Notes

This raises an exception if the graph has cycles which means the dependencies are unresolvable (i.e. there is no order which the models can be called that will work). In this case it is possible to visually inspect the graph using dependency_graph.

dependency_map(ax=None, figsize=None, deep=False, style='shell')[source]

Create a graph of the dependency graph in a decent format

Parameters
  • ax (matplotlib.axis, optional) – Matplotlib axis object on which dependency map is to be drawn.

  • figsize (tuple, optional) – Tuple containing frame size.