Project

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

Bases: list

This class provides a container for all OpenPNM objects in a given simulation.

A simulation is defined as a Network and all of it’s associated objects. When instantiating a Network, a Project can be passed as an argument, but if not given one is created. When instantiating any other object either a Network or a Project can be supplied. In the former case, the Network’s Project is retrieved and used. The end result is that all objects are stored in a specific Project.

The Project to which any object belongs can be retrieved with obj.project. Conversely, printing a Project displays a list of all objects it contains.

Moreover, all Projects are registered with the Workspace. Since there can be only instance of the Workspace it is possible to view all open Projects by printing the Workspace.

See also

Workspace

append(obj)[source]

The Project (a list) must be kept as a flat list, so the append function, which can normally be used to insert a list into a list, is overloaded to basically prevent the normal append operation and simply calls extend.

check_data_health(obj)[source]

Check the health of pore and throat data arrays.

Parameters

obj (OpenPNM object) – A handle of the object to be checked

Returns

health – Returns a HealthDict object which a basic dictionary with an added health attribute that is True is all entries in the dict are deemed healthy (empty lists), or False otherwise.

Return type

dict

check_geometry_health()[source]

Perform a check to find pores with overlapping or undefined Geometries

Returns

Return type

A HealthDict

check_network_health()[source]

This method check the network topological health by checking for:

  1. Isolated pores

  2. Islands or isolated clusters of pores

  3. Duplicate throats

  4. Bidirectional throats (ie. symmetrical adjacency matrix)

  5. Headless throats

Returns

health – A dictionary containing the offending pores or throat numbers under each named key.

Return type

dict

Notes

It also returns a list of which pores and throats should be trimmed from the network to restore health. This list is a suggestion only, and is based on keeping the largest cluster and trimming the others.

Notes

  • Does not yet check for duplicate pores

  • Does not yet suggest which throats to remove

  • This is just a ‘check’ and does not ‘fix’ the problems it finds

check_physics_health(phase)[source]

Perform a check to find pores which have overlapping or missing Physics

Parameters

phase (OpenPNM Phase object) – The Phase whose Physics should be checked

Returns

Return type

A HealthDict

clear(objtype=[])[source]

Clears objects from the project entirely or selectively, depdening on the received arguments.

Parameters

objtype (list of strings) – A list containing the object type(s) to be removed. If no types are specified, then all objects are removed. To clear only objects of a specific type, use ‘network’, ‘geometry’, ‘phase’, ‘physics’, or ‘algorithm’. It’s also possible to use abbreviations, like ‘geom’.

copy(name=None)[source]

Creates a deep copy of the current project

A deep copy means that new, unique versions of all the objects are created but with identical data and properties.

Parameters

name (string) – The name to give to the new project. If not supplied, a name is automatically generated.

Returns

proj – A new Project object containing copies of all objects

Return type

list

Notes

Because they are new objects, they are given a new uuid (obj.settings['_uuid']), but the uuid of the original object is also stored (obj.settings['_uuid_old']) for reference.

export_data(phases=[], filename=None, filetype=None)[source]

Export the pore and throat data from the given object(s) into the specified file and format.

Parameters
  • phases (list of OpenPNM Phase Objects) – The data on each supplied phase will be added to file

  • filename (string) – The file name to use. If none is supplied then one will be automatically generated based on the name of the project containing the supplied Network, with the date and time appended.

  • filetype (string) –

    Which file format to store the data. If a valid extension is included in the filename, this is ignored. Option are:

    ’vtk’ : (default) The Visualization Toolkit format, used by various softwares such as Paraview. This actually produces a ‘vtp’ file. NOTE: This can be quite slow since all the data is written to a simple text file. For large data simulations consider ‘xdmf’.

    ’csv’ : The comma-separated values format, which is easily openned in any spreadsheet program. The column names represent the property name, including the type and name of the object to which they belonged, all separated by the pipe character.

    ’xdmf’ : The extensible data markup format, is a very efficient format for large data sets. This actually results in the creation of two files, the xmf file and an associated hdf file. The xmf file contains instructions for looking into the hdf file where the data is stored. Paraview opens the xmf format natively, and is very fast.

    ’mat’ : Matlab ‘mat-file’, which can be openned in Matlab.

Notes

This is a helper function for the actual functions in the io module. For more control over the format of the output, and more information about the format refer to openpnm.io.

extend(obj)[source]

This function is used to add objects to the project. Arguments can be single OpenPNM objects, an OpenPNM project list, or a plain list of OpenPNM objects. Note that if an object has the same name as one already existing on the project, the it will be renamed automatically.

find_full_domain(obj)[source]

Find the full domain object associated with a given object. For geometry the network is found, for physics the phase is found and for all other objects which are defined for for the full domain, themselves are found.

Parameters

obj (OpenPNM Object) – Can be any object

Returns

obj

Return type

An OpenPNM object

find_geometry(physics)[source]

Find the Geometry associated with a given Physics

Parameters

physics (OpenPNM Physics Object) – Must be a Physics object

Returns

geom

Return type

OpenPNM Geometry object

Raises

If no Geometry object can be found, then an Exception is raised.

find_phase(obj)[source]

Find the Phase associated with a given object.

Parameters

obj (OpenPNM Object) – Can either be a Physics or Algorithm object

Returns

phase

Return type

OpenPNM Phase object

Raises

If no Phase object can be found, then an Exception is raised.

find_physics(geometry=None, phase=None)[source]

Find the Physics object(s) associated with a given Geometry, Phase, or combination.

Parameters
  • geometry (OpenPNM Geometry Object) – The Geometry object for which the Physics object(s) are sought

  • phase (OpenPNM Phase Object) – The Phase object for which the Physics object(s) are sought

Returns

physics – A list containing the Physics object(s). If only a geometry is specified the the Physics for all Phases is returned. If only a phase is specified, then the Physics for all Geometries is returned. If both geometry and phase is specified then the list only contains a single Physics. If no Physics is found, the the list will be empty. See the Notes section for more information.

Return type

list

See also

grid

Notes

The Project has an grid attribute that shows the association of all objects. If each Geometry represents a row and each Phase is a column, then each row/col intersection represents a Physics. This method finds the PHysics’ at each intersection

insert(index, obj)[source]

Inserts the supplied object at the specified index in the Project list

Notes

The order of the objects in an OpenPNM Project lists do not matter, so it is recommended to just use append instead.

See also

append, extend

inspect_locations(element, indices, objs=[], mode='all')[source]

Shows the values of all props and/or labels for a given subset of pores or throats.

Parameters
  • element (str) – The type of locations to inspect, either ‘pores’, or ‘throats’

  • indices (array_like) – The pore or throat indices to inspect

  • objs (list of OpenPNM Objects) – If given, then only the properties on the recieved object are inspected. If not given, then all objects are inspected (default).

  • mode (list of strings) – Indicates whether to inspect ‘props’, ‘labels’, or ‘all’. The default is all

Returns

df – A data frame object with each location as a column and each row as a property and/or label.

Return type

Pandas DataFrame

load_object(filename)[source]

Loads a single object from a pickle file

Parameters

filename (string or path object) – The name of the file containing the saved object. Can include an absolute or relative path as well. If only a filename is given it will be saved in the current working directory. The object type is inferred from

pop(index)[source]

The object at the given index is removed from the list and returned.

Notes

This method uses purge_object to perform the actual removal of the object. It is reommended to just use that directly instead.

See also

purge_object

purge_object(obj, deep=False)[source]

Remove an object from the Project. This removes all references to the object from all other objects (i.e. removes labels)

Parameters
  • obj (OpenPNM Object or list of objects) – The object(s) to purge

  • deep (boolean) – A flag that indicates whether to remove associated objects. If True, then removing a Geometry or Phase also removes the associated Physics objects. If False (default) then only the given object is removed, along with its labels in all associated objects. Removing a Physics always keeps associated Geometry and Phases since they might also be associated with other Physics objects.

Raises

An Exception is raised if the object is a Network.

Notes

For a clearer picture of this logic, type print(project.grid) at the console. A deep purge of a Geometry is like removing a row, while a Phase is like removing a column.

remove(obj)[source]

The given object is removed from the project

This removes the object, along with all it’s labels in associated objects, but does NOT remove the associated objects.

See also

purge_object

save_object(obj)[source]

Saves the given object or list of objects to a pickle file

Parameters

obj (OpenPNM object or list of objects) – The objects to be saved. Depending on the object type, the file extension will be one of ‘net’, ‘geo’, ‘phase’, ‘phys’ or ‘alg’.

save_project(filename=None)[source]

Save the current project to a pnm file.

Parameters

filename (string or path object) – The name of the file. Can include an absolute or relative path as well. If only a filename is given it will be saved in the current working directory.

show_model_dependencies(prop, obj)[source]