Module voltrace.mesher

Classes

class GeometricObject

The Mesh class (and the classes defined in voltrace.geometry) are subclasses of GeometricObject. This means that they all can be moved, rotated, mirrored.

Ancestors

  • abc.ABC

Subclasses

Methods

def map_points(self, fun)

Create a new geometric object, by mapping each point by a function.

Parameters

fun : (3,) float -> (3,) float
Function taking a three dimensional point and returning a three dimensional point.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def mirror_xy(self)

Mirror object in the XY plane.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def mirror_xz(self)

Mirror object in the XZ plane.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def mirror_yz(self)

Mirror object in the YZ plane.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def move(self, dx=0.0, dy=0.0, dz=0.0)

Move along x, y or z axis.

Parameters

dx : float
Amount to move along the x-axis.
dy : float
Amount to move along the y-axis.
dz : float
Amount to move along the z-axis.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def rotate(self, Rx=0.0, Ry=0.0, Rz=0.0, origin=(0, 0, 0))

Rotate counterclockwise around the x, y or z axis. Only one axis supported at the same time (rotations do not commute).

Parameters

Rx : float
Amount to rotate around the x-axis (radians).
Ry : float
Amount to rotate around the y-axis (radians).
Rz : float
Amount to rotate around the z-axis (radians).
origin : (3,) float
Point around which to rotate, which is the origin by default.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

def rotate_around_axis(self, axis=(0, 0, 1), angle=0.0, origin=(0, 0, 0))

Rotate counterclockwise around a general axis defined by a vector.

Parameters

axis : (3,) float
Vector defining the axis of rotation. Must be non-zero.
angle : float
Amount to rotate around the axis (radians).
origin : (3,) float
Point around which to rotate, which is the origin by default.

Returns

GeometricObject
 

This function returns the same type as the object on which this method was called.

class Mesh (points=None,
lines=None,
triangles=None,
physical_to_lines=None,
physical_to_triangles=None,
ensure_outward_normals=True)

Mesh containing lines and triangles. Groups of lines or triangles can be named. These names are later used to apply the correct excitation. Line elements can be curved (or 'higher order'), in which case they are represented by four points per element. Note that Mesh is a subclass of GeometricObject, and therefore can be easily moved and rotated.

Ancestors

Static methods

def from_meshio(mesh, name=None)

Create a Voltrace mesh from a meshio.Mesh object.

Parameters

mesh : meshio.Mesh
The mesh to convert to a Voltrace mesh
name : str
(optional) name to assign to all elements (lines and triangles)

Returns

Mesh
 
def read_file(filename, name=None)

Create a mesh from a given file. All formats supported by meshio are accepted.

Parameters

filename : str
Path of the file to convert to Mesh
name : str
(optional) name to assign to all elements (lines and triangles)

Returns

Mesh
 

Methods

def __add__(self, other)

Add meshes together, using the + operator (mesh1 + mesh2).

Returns

Mesh
 
A new mesh consisting of the elements of the added meshes
 
def ensure_inward_normals(self, electrode)
def ensure_outward_normals(self, electrode)
def extract_physical_group(self, name)

Extract a named group from the mesh.

Parameters

name : str
Name of the group of elements

Returns

Mesh
 

Subset of the mesh consisting only of the elements with the given name.

def flip_normals(self)

Flip the normals in the mesh by inverting the 'orientation' of the elements.

Returns

Mesh
 
def get_electrodes(self)

Get the names of all the named groups (i.e. electrodes) in the mesh

Returns

str iterable
 
Names
 
def is_2d(self)

Check if the mesh is two dimensional, by checking that all z coordinates are zero.

Returns

bool
 
Whether the mesh is two dimensional
 
def is_3d(self)

Check if the mesh is three dimensional by checking whether any z coordinate is non-zero.

Returns

bool
 
Whether the mesh is three dimensional
 
def is_higher_order(self)

Whether the mesh contains higher order elements.

Returns

bool
 
def map_points(self, fun)
def remove_lines(self)

Remove all the lines from the mesh.

Returns

Mesh
 
def remove_triangles(self)

Remove all triangles from the mesh.

Returns

Mesh
 
def set_name(self, name)

Assign the given name to all the lines and triangles in the mesh

Parameters

name : str
Name to assign to all lines, triangles
def split_into_connected_meshes(self)

Split the mesh into multiple meshes based on whether the elements are connected.

Returns

list[Mesh]
List of meshes, each containing one connected component.

Notes

  • Physical groups (physical_to_lines and physical_to_triangles) are not retained
  • Normal orientations are preserved (ensure_outward_normals=False is used)
  • Works separately for line and triangle elements
def to_meshio(self)

Convert the Mesh to a meshio object.

Returns

meshio.Mesh
 
def write(self, filename)
def write_file(self, filename)

Write a mesh to a given file. The format is determined from the file extension. All formats supported by meshio are supported.

Parameters

filename : str
The name of the file to write the mesh to.

Inherited members