OpenPNM V2.0 implemented new ways to manage and control objects, specifically a Workspace and Projects. The Workspace object is equivalent to a web browser window, while a Project object is like tabs inside the browser. Each Project is an isolated OpenPNM simulation with a single Network object and all associated objects. All Projects are stored in the same Workspace. There can be only 1 Workspace open at a given time, so all new projects are registered in the same Workspace. Projects and Workspaces can be saved and loaded.
In [1]:
import openpnm as op
In [2]:
#NBVAL_IGNORE_OUTPUT
ws = op.Workspace()
print(ws)
Next, create a new Project and print:
In [3]:
proj = ws.new_project()
proj
Out[3]:
The project is an empty list since there have been no objects created yet.
Now create a new network object with passing in proj
into the initialization:
In [4]:
pn = op.network.Cubic(shape=[4, 4, 4], project=proj)
Now printing the Project via print(proj)
will include the newly created network:
It is not necessary to create a project before creating a network. Since a project can only have one network, then a new project is created each time a network is created if not specified as we did above:
In [5]:
pn2 = op.network.Cubic(shape=[4, 4, 4])
The project that each object belongs to can be found since each object has a project
attribute. Run print(pn2.project)
:
Finally, you can view all active projects by printing the workspace via print(ws)
:
A project can be purged from the workspace via ws.close_project(proj)
. Let's print workspace again, print(ws)
:
It is worth describing the design of these classes to help explain how they work. The workspace is a dict
subclass while the project is a list
subclass. Each subclass has numerous methods added to aid in the management of the objects.
In the Workspace dict
each project object is stored by name in each 'key: value' pair. Printing the workspace gives a nicely formatted output as shown above, but the basic command-line representation gives its true structure via running ws
in the command-line:
Where the only project in the workspace is 'sim_02'
, and it is a list that contains only a single Cubic network object.