class ModelsMixin[source]

Bases: object

This class is meant to be combined by the Base class in multiple inheritence. This approach is used since Network and Algorithm do not need to have any models attribute, while Phase, Geometry, and Physics do. By using a mixin class, all objects can inherit from Base while the model functionality can be added only where needed.


The following table gives a brief overview of the methods that are added to the object by this mixin. In addition to these methods, a models attribute is also added, which is a dictionary that contains all of the models and their parameters.

Method or Attribute



Add a given model and parameters to the object


Runs the model(s) to recalculate data


Removes specified model as well as it’s data


>>> import openpnm as op

Create a Demo class using Base and ModelsMixin:

>>> class Demo(op.core.Base, op.core.ModelsMixin):
...     pass
>>> temp = Demo(Np=3, Nt=2)

The new class has the normal Base methods:

>>> print(temp.num_pores())

But also has those needed for working with models. For instance, a simple model can be added as follows:

>>> temp.add_model(propname='pore.test',
...                model=op.models.misc.constant,
...                value=2)
>>> print(temp['pore.test'])
[2 2 2]

All the models and their respective parameters are stored in the models attribute:

>>> print(temp.models)
#   Property Name                       Parameter                 Value
1   pore.test                           model:                    constant
                                        value:                    2
                                        regeneration mode:        normal
add_model(propname, model, regen_mode='', **kwargs)[source]

Adds a new model to the models dictionary (object.models)

  • propname (string) – The name of the property to be calculated by the model.

  • model (function) – A reference (handle) to the function to be used.

  • regen_mode (string) –

    Controls how/when the model is run (See Notes for more details). Options are:

    ’normal’ - (default) The model is run directly upon being assiged, and also run every time regenerate_models is called.

    ’constant’ - The model is run directly upon being assigned, but is not called again, thus making it’s data act like a constant. If, however, the data is deleted from the object it will be regenerated again.

    ’deferred’ - Is not run upon being assigned, but is run the first time that regenerate_models is called.

    ’explicit’ - Is only run if the model name is explicitly passed to the regenerate_models method. This allows full control of when the model is run.

regenerate_models(propnames=None, exclude=[], deep=False)[source]

Re-runs the specified model or models.

  • propnames (string or list of strings) – The list of property names to be regenerated. If None are given then ALL models are re-run (except for those whose regen_mode is ‘constant’).

  • exclude (list of strings) – Since the default behavior is to run ALL models, this can be used to exclude specific models. It may be more convenient to supply as list of 2 models to exclude than to specify 8 models to include.

  • deep (boolean) – Specifies whether or not to regenerate models on all associated objects. For instance, if True, then all Physics models will be regenerated when method is called on the corresponding Phase. The default is False. The method does not work in reverse, so regenerating models on a Physics will not update a Phase.

remove_model(propname=None, mode=['model', 'data'])[source]

Removes model and data from object.

  • propname (string or list of strings) – The property or list of properties to remove

  • mode (list of strings) –

    Controls what is removed. Options are:

    ’model’ : Removes the model but not any numerical data that may already exist.

    ’data’ : Removes the data but leaves the model.

  • default is both. (The) –