openpnm.models.misc.generic_function(target, prop, func, **kwargs)[source]

Runs an arbitrary function on the given data

This allows users to place a customized calculation into the automatated model regeneration pipeline.

  • target (Base) – The object which this model is associated with. This controls the length of the calculated array, and also provides access to other necessary properties.

  • prop (str) – The dictionary key containing the array to be operated on

  • func (Numpy function) – A handle to the function to apply

  • kwargs (keyward arguments) – All arguments required by the specific Numpy function


result – Array containing func(target[prop], **kwargs).

Return type



The following example shows how to use a Numpy function, but any function can be used, as long as it returns an array object:

>>> import openpnm as op
>>> import numpy as np
>>> pn =[5, 5, 5])
>>> geo = op.geometry.GenericGeometry(network=pn, pores=pn.Ps, throats=pn.Ts)
>>> geo['pore.rand'] = np.random.rand(geo.Np)
>>> geo.add_model(propname='pore.cos',
...               model=op.models.misc.generic_function,
...               func=np.cos,
...               prop='pore.rand')