System Class#
PyMembrane uses a modular design where different components act as autonomously as possible. The System class manages the mesh (vertices, edges, and faces), exposes compute geometrical properties, and provides data export for visualization and analysis through System.dumper.
Before you start#
# import pymembrane
import pymembrane as mb
# create a new system instance
system = mb.System()
Loading my first mesh#
Pymembrane works with meshes in _inp_ format. For example, a vertex file for a hexagon looks like:
Vertex File (id x y z type):
0 0.0 0.0 0.0 1
1 1.0 0.0 0.0 1
2 0.5 0.8660254038 0.0 1
3 -0.5 0.8660254038 0.0 1
4 -1.0 0.0 0.0 1
5 -0.5 -0.8660254038 0.0 1
6 0.5 -0.8660254038 0.0 1
and the corresponding face file:
Face File (id v1 v2 v3 normal):
0 0 1 2 1
1 0 2 3 1
2 0 3 4 1
3 0 4 5 1
4 0 5 6 1
5 0 6 1 1
Now that we have the faces and vertices files we can create a mesh as follows:
vertex_file = 'vertices.inp'
face_file = 'faces.inp'
system.read_mesh_from_files(files={'vertices':vertex_file, 'faces':face_file})
Visualization#
PyMembrane can export meshes to vtk and ply files through the default Python dumper attached to each system:
dump = system.dumper
dump.ply("hexagon") #for ply
dump.vtk("hexagon") #for vtk
For backward compatibility, older scripts may still call:
dump.setvtkLegacyFormat(True)
Note
setvtkLegacyFormat() is retained for compatibility. The Python dumper already writes legacy ASCII VTK output by default.
Visualization#
PyMembrane offers various mesh-related computations using the compute class. To execute computations for a given mesh, follow the steps:
mesh_compute = system.compute()
edge_lengths = mesh_compute.edge_lengths()
face_areas = mesh_compute.face_areas()
face_normals = mesh_compute.face_normals() #to be stored in the face class
Additionally, compute class can be used to compute thermodynamic properties of the mesh. For example, the following code computes the pressure of a given mesh:
mesh_compute.pressure(evolver)
Note
To calculate thermodynamic quantities, one must define an Evolver class. This necessity arises because thermodynamic properties are intrinsically linked to the force potentials in the system. Although the compute<compute> class operates independently and isn’t a subset of the system class, it has been integrated with the system class for user convenience. This setup facilitates the computation of various properties for a specified mesh.