trimem.core module¶
C++ library with python bindings for trimem.
This module encapsulates the heavy lifting involved in the energy/gradient evaluations associated with trimem in a C++ library offering bindings to be called from python.
- class trimem.core.BondParams¶
Tether regularization parameters.
- __init__()¶
- property a0¶
Reference face area (for BondType::Area).
- Type:
float
- property lc0¶
Onset distance for attracting force (for BondType::Edge).
- Type:
float
- property lc1¶
Onset distance for repelling force (for BondType::Edge).
- Type:
float
- property r¶
Steepness of regularization potential (must be >=1).
- Type:
int.
- class trimem.core.BondType¶
Types for the tether potential.
Members:
Edge : Smoothed well/box potential on edges.
Area : Harmonic potential on face area.
None : None
- __init__()¶
- class trimem.core.ContinuationParams¶
Parameters used for smooth continuation.
- __init__()¶
- property delta¶
Interpolation blending time step.
- property lam¶
Interpolation state.
- class trimem.core.EnergyManager¶
Helfrich functional evaluation.
Manages a particular parametrization of the Helfrich functional with additional penalties and tether-regularization. At its core it provides methods
energy()andgradient()for the evaluation of the full Hamiltonian and its gradient.- __init__(self: trimem.core.EnergyManager, mesh: trimem.core.TriMesh, eparams: trimem.core.EnergyParams) None¶
Initialization.
Initializes the EnergyManager’s state from the initial
meshand the parametrization provided byeparams. This comprises the setup of the initial state of the parameter continuation, the set up of the reference properties for area, volume and curvature (seeinitial_props) according to the current state of the parameter continuation as well as the construction of the neighbour list structures for the repulsion penalty.
- energy(*args, **kwargs)¶
Overloaded function.
energy(self: trimem.core.EnergyManager, mesh: trimem.core.TriMesh) -> float
Evaluation of the Hamiltonian.
- Args:
- mesh (TriMesh): mesh representing the state to be evaluated
defined by vertex positions as well as connectivity.
- Returns:
The value of the nonlinear Hamiltonian by computing the vector of VertexProperties and reducing it to the value of the Hamiltonian.
energy(self: trimem.core.EnergyManager, vprops: trimem.core.VertexProperties) -> float
Evaluation of the Hamiltonian.
- Args:
- vprops (VertexProperties): vector of VertexProperties that has
already been evaluated beforehand by
properties().
- Returns:
The value of the nonlinear Hamiltonian by directly reducing on the provided VertexProperties
vprops.
- property eparams¶
Parametrization of the Hamiltonian.
- Type:
- gradient(self: trimem.core.EnergyManager, mesh: trimem.core.TriMesh) numpy.ndarray[numpy.float64]¶
Evaluate gradient of the Hamiltonian.
- property initial_props¶
Initial reference properties.
Initial reference properties computed from the definition of the target properties for area, volume and curvature. Created upon construction.
- print_info(self: trimem.core.EnergyManager, mesh: trimem.core.TriMesh) None¶
Print energy information evaluated on the state given by
mesh.
- properties(self: trimem.core.EnergyManager, mesh: trimem.core.TriMesh) trimem.core.VertexProperties¶
Evaluation of vertex averaged properties.
Triggers the evaluation of a vector of vertex-averaged properties
VertexPropertiesthat comprises the basic per-vertex quantities.- Parameters:
mesh (TriMesh) – mesh representing the state to be evaluated defined by vertex positions as well as connectivity.
- Returns:
(N,1) array of
VertexPropertieswith N being the number of vertices.
- update_reference_properties(self: trimem.core.EnergyManager) None¶
Update reference configurations.
Uses the parameter continuation defined in the parametrization
eparamsto update reference values for area, volume and curvature from the target configuration.
- update_repulsion(self: trimem.core.EnergyManager, arg0: trimem.core.TriMesh) None¶
Update repulsion penalty.
Updates internal references to neighbour lists and repulsion penalties based on the state of the mesh passed in as
arg0.
- class trimem.core.EnergyParams¶
Parametrization of the Helfrich functional.
Modularized POD structure containing parameters for the Helfrich functional, the area, volume and area-difference penalties, the repulsion penalty and the tether regularization.
- __init__()¶
- property area_frac¶
Target surface area fraction wrt. the initial geometry.
- Type:
float
- property bond_params¶
Parameters for the tether regularization.
- Type:
- property continuation_params¶
Parameters for the parameter continuation.
- Type:
- property curvature_frac¶
Target curvature fraction wrt. the initial geometry.
- Type:
float
- property kappa_a¶
Weight of the surface area penalty.
- Type:
float
- property kappa_b¶
Weight of the Helfrich functional.
- Type:
float
- property kappa_c¶
Weight of the area-difference penalty.
- Type:
float
- property kappa_r¶
Weight of the surface repulsion penalty.
- Type:
float
- property kappa_t¶
Weight of the tether regularization.
- Type:
float
- property kappa_v¶
Weight of the volume penalty.
- Type:
float
- property repulse_params¶
Parameters for the surface repulsion.
- Type:
- property volume_frac¶
Target volume fraction wrt. the initial geometry.
- Type:
float
- class trimem.core.HalfedgeHandle¶
OpenMesh::HalfedgeHandle.Handle/Reference to halfedges used by several functions within trimem.
- __init__(self: trimem.core.HalfedgeHandle) None¶
- class trimem.core.NeighbourList¶
Neighbour list interface
Abstract representation of a neighbour list data structure operating on a
TriMesh. Can be either acell_listor averlet_list. Seemake_nlist()for its construction.- __init__(*args, **kwargs)¶
- distance_matrix(self: trimem.core.NeighbourList, mesh: trimem.core.TriMesh, rdist: float) Tuple[List[float], List[int], List[int]]¶
Compute sparse distance matrix.
- Parameters:
mesh (TriMesh) – mesh subject to pair-wise vertex distance compuation
rdist (float) – distance cutoff. This cutoff is additional to the cutoff that was used during list creation! That is, it is meaningful to specify a smaller cutoff than the cutoff used at list creation but a larger cutoff has no effect.
- Returns:
A sparse distance matrix (as a tuple of lists) containing all vertices within a distance
< rdist.
- point_distances(self: trimem.core.NeighbourList, mesh: trimem.core.TriMesh, pid: int, rdist: float) Tuple[List[trimem.core.Point], List[int]]¶
Compute distances for vertex pid.
- Parameters:
mesh (TriMesh) – mesh containing vertices to be tested against
pid.pid (int) – vertex in
meshfor which distances to other vertices are to be found.rdist (float) – distance cutoff. This cutoff is additional to the cutoff that was used during list creation! That is, it is meaningful to specify a smaller cutoff than the cutoff used at list creation but a larger cutoff has no effect.
- Returns:
A tuple (
distances,ids) of vectors of distance components (in 3D) betweenpidand vertices inidswith distance< rdist.
- class trimem.core.Point¶
OpenMesh::TriMesh::PointTypedef of a vector-like quantity describing vertices/points in 3D.
- __init__(*args, **kwargs)¶
- class trimem.core.SurfaceRepulsionParams¶
Parameters for the surface repulsion penalty.
- __init__()¶
- property exclusion_level¶
Connected neighbourhood exclusion for neighbour lists.
- Type:
int
- Levels of exclusion are inclusive, i.e. 0<1<2. Can be one of:
0: exclude self
1: exclude directly connected neighbourhood (1 edge)
2: exclude indirectly connected neighbourhood (2 edges)
- property lc1¶
Onset distance for repelling force.
- Type:
float
- property n_search¶
Type of neighbour list structures.
- Type:
str
Can be
cell_listorverlet_list.
- property r¶
Steepness of repelling potential (must be >=1).
- Type:
int.
- property rlist¶
Neighbour search distance cutoff.
- class trimem.core.TriMesh¶
Triangulation.
Specialization of
OpenMesh::TriMesh_ArrayKernelT<MeshTraits>.- __init__(*args, **kwargs)¶
Overloaded function.
__init__(self: trimem.core.TriMesh) -> None
Initialize empty mesh.
- Returns:
TriMesh with zero vertices and no faces.
__init__(self: trimem.core.TriMesh, points: numpy.ndarray[numpy.float64], faces: numpy.ndarray[numpy.int32]) -> None
Initialize from arrays of vertices and faces.
- Args:
points ((N,3) float-array): array of vertices in 3 dimensions. faces ((N,3) int-array): array of face indices.
- Returns:
TriMesh with vertices and faces defined by the input.
- fv_indices(self: trimem.core.TriMesh) numpy.ndarray[numpy.int32]¶
Get face-vertex indices.
- Returns:
An (N,3) array of type int with N being the number of faces that contains the vertex indices defining each face.
- halfedge_handle(self: trimem.core.TriMesh, edge: int) trimem.core.HalfedgeHandle¶
Returns handle to first halfedge of
edgei.
- n_edges(self: trimem.core.TriMesh) int¶
Number of edges in the mesh.
- n_vertices(self: trimem.core.TriMesh) int¶
Number of vertices in the mesh.
- next_halfedge_handle(self: trimem.core.TriMesh, edge: trimem.core.HalfedgeHandle) trimem.core.HalfedgeHandle¶
Returns handle to
halfedgenext tohalfedgehe.
- opposite_halfedge_handle(self: trimem.core.TriMesh, edge: trimem.core.HalfedgeHandle) trimem.core.HalfedgeHandle¶
Returns handle to the opposite of
halfedgehe.
- points(self: trimem.core.TriMesh) numpy.ndarray[numpy.float64]¶
Get vertex positions.
- Returns:
An (N,3) array of type float with N being the number of vertices.
- class trimem.core.VertexProperties¶
Container for vertex-averaged properties.
The vertex averaged quantities area, volume, curvature and bending energy are at the core of the evaluations involved in the Helfrich functional that is represented by
EnergyManager. class:VertexProperties encapsulates access to these quantities. It further allows for the automatic reduction on vectors ofVertexPropertiesby implementing the operators+=and-=.Its current usage in trimem implies an AoS approach that might be replaced by an SoA approach if required by performance considerations. In this case the idea is to still keep the container ‘interface’ as is and manage the data layout behind the scenes.
- __init__(self: trimem.core.VertexProperties) None¶
- property area¶
Face area
- property bending¶
Bending energy
- property curvature¶
Edge curvature
- property repulsion¶
Repulsion penalty
- property tethering¶
Tether regularization
- property volume¶
Face volume
- trimem.core.area(mesh: trimem.core.TriMesh) float¶
Compute surface area.
- Parameters:
mesh (TriMesh) – input mesh to be evaluated
- Returns:
The value of the surface area of
mesh.
- trimem.core.avg_tri_props(mesh: trimem.core.TriMesh) Tuple[float, float]¶
Average triangle area and edge length
- Parameters:
mesh (TriMesh) – mesh to process.
- Returns:
A tuple (a, l) with a being the
mesh’s average face area and l being the mesh’s average edge length. (Used for automatic detection of the characteristic lengths involved in the tether and repulsion penalties.)
- trimem.core.dihedral_angle(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) float¶
Evaluate dihedral angle.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The dihedral angle between the face associated to
halfedge_handleand the face associated to the opposite halfedge_handle.
- trimem.core.dihedral_angle_grad(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) numpy.ndarray[numpy.float64]¶
Evaluate gradient of dihedral angle.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The gradient of the dihedral angle between the face associated to
halfedge_handleand the face associated to the opposite halfedge_handle wrt to the coordinates of both faces.
- trimem.core.edge_length(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) float¶
Evaluate edge length.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The lenght of the edge referred to by
halfedge_handle.
- trimem.core.edge_length_grad(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) numpy.ndarray[numpy.float64]¶
Evaluate gradient of edge length.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The gradient of the edge length referred to by
halfedge_handlewrt.the coordinates of the vertices that are connected tohalfedge_handle.
- trimem.core.edges_length(mesh: trimem.core.TriMesh) float¶
Compute cumulative edge length.
- Parameters:
mesh (TriMesh) – input mesh to be evaluated
- Returns:
The cumulated value of the length of all edges in
mesh.
- trimem.core.face_area(arg0: trimem.core.TriMesh, arg1: trimem.core.HalfedgeHandle) float¶
Evaluate face area.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The area of the face associated to
halfedge_handle.
- trimem.core.face_area_grad(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) numpy.ndarray[numpy.float64]¶
Evaluate gradient of face area.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The gradient of the area of the face that is associated to
halfedge_handlewrt. the coordinates of the vertices of that face.
- trimem.core.face_volume(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) float¶
Evaluate face volume.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The volume of the tetrahedron given by the face associated to
halfedge_handleand the origin.
- trimem.core.face_volume_grad(mesh: trimem.core.TriMesh, halfedge_handle: trimem.core.HalfedgeHandle) numpy.ndarray[numpy.float64]¶
Evaluate gradient of face volume.
- Parameters:
mesh (TriMesh) – mesh containing
halfedge_handle.halfedge_handle (HalfedgeHandle) – handle to halfedge of interest.
- Returns:
The gradient of the volume of the tetrahedron given by the face associated to
halfedge_handleand the origin wrt to the coordinates of the face’s vertices.
- trimem.core.flip(mesh: trimem.core.TriMesh, estore: trimem.core.EnergyManager, flip_ratio: float) int¶
Serial flip sweep.
Performs a sweep over a fraction
flip_ratioof edges inmeshtrying to flip each edge sequentially and evaluating the energies associated to the flip against the Metropolis criterion.- Parameters:
mesh (TriMesh) – input mesh to be used
estore (EnergyManager) – instance of
EnergyManagerused in combination with themeshto evaluate energy differences necessary for flip acceptance/rejection.flip_ratio (float) – ratio of edges to test (must be in [0,1]).
- trimem.core.gradient(mesh: trimem.core.TriMesh, estore: trimem.core.EnergyManager, gradient: numpy.ndarray[numpy.float64], epsilon: float) None¶
Finite difference gradient of energy.
This is merely for testing/debugging. Use the gradient function exposed by the
EnergyManagerclass.- Parameters:
mesh (TriMesh) – mesh instance.
estore (EnergyManager) – energy evaluation.
gradient (numpy.ndarray) – (N,3) array filled with the gradient.
epsilon (float) – finite difference perturbation magnitude.
- trimem.core.make_nlist(mesh: trimem.core.TriMesh, eparams: trimem.core.EnergyParams) trimem.core.NeighbourList¶
Neighbour list factory
- Parameters:
mesh (TriMesh) – a mesh whose vertices are subject to neighbour search
eparams (EnergyParams) – parametrization of the list structure. Parameters are extracted from the sub-structure
SurfaceRepulsionParams.
- Returns:
An interface of type
NeighbourListrepresenting either a cell list or a verlet-list.
- trimem.core.pflip(mesh: trimem.core.TriMesh, estore: trimem.core.EnergyManager, flip_ratio: float) int¶
Batch parallel flip sweep.
Performs a sweep over a fraction
flip_ratioof edges inmeshin a batch parallel fashion albeit maintaining chain ergodicity. To this end, a batch of edges is selected at random. If an edge is free to be flipped independently, i.e., no overlap of its patch with the patch of other edges (realized by a locking mechanism), it is flipped and its differential contribution to the Hamiltonian is evaluated in parallel for the whole batch. Ergodicity is maintained by subsequently evaluating the Metropolis criterion for each edge in the batch sequentially. This is repeated for a number offlip_ratio / batch_size * mesh.n_edgestimes.- Parameters:
mesh (TriMesh) – input mesh to be used
estore (EnergyManager) – instance of
EnergyManagerused in combination with themeshto evaluate energy differences necessary for flip acceptance/rejection.flip_ratio (float) – ratio of edges to test (must be in [0,1]).
- trimem.core.read_mesh(fname: str) trimem.core.TriMesh¶
Read mesh from fname
Uses
OpenMesh::IO::read_mesh.- Parameters:
fname (str) – file name to read mesh from
- Returns:
An instance of TriMesh read from fname.