carputils.mesh.Block

class carputils.mesh.Block(centre=(0.0, 0.0, 0.0), size=(1.0, 1.0, 1.0), resolution=0.1, etype='tetra', periodic=0, periodic_tag=1234, pertb=0.0)

Generate a block mesh with the mesher command line utility.

This class describes a tissue block with optional additional bath region. For example, to define a 2x2x2mm block centred on the origin with 1mm bath on the positive z side:

>>> geom = Block(size=(2,2,2))
>>> geom.set_bath(thickness=(0,0,1), both_sides=False)

Regions may also be specified using the BoxRegion, SphereRegion and CylinderRegion objects:

>>> reg = BoxRegion((-1,-1,-1), (1,1,0), tag=10)
>>> geom.add_region(reg)

Generate a list of command line options to pass to mesher to generate the described mesh with the mesher_opts() method:

>>> opts = geom.mesher_opts('meshname') # meshname.pts, meshname.elem, etc.

Note

While the mesher executable takes arguments in centimetres and micrometres, this class expects all physical sizes to be specified in millimetres. Arguments are converted to the correct units when generating the mesher command line.

Args:
centre: array-like, optional
Coordinate of centre of Block, defaults to (0,0,0)
size: array-like, optional
Size of Block, defaults to (1,1,1)
resolution : float, optional
Resolution at which to tesselate block into mesh, defaults to 0.1
etype: str, optional
Element type to generate, either ‘tetra’ or ‘hexa’ in 3D, or ‘quad’ or ‘tri’ in 2D, defaults to ‘tetra’ in 3D and ‘quad’ in 2D
periodic: int, optional
If set, the edges along a given direction are connected by linear elements to implement periodic boundary conditions. The range of values spans 0 (none), 1 (X), 2 (Y) and 3 (XY)
periodic_tag: int, optional
Tag value assigned to the connecting linear elements. As default the value 1234 is used.
add_region(region)

Add a region definition.

Args:
region : BoxRegion or SphereRegion or CylinderRegion
The region description.
bath_limits()

Return the lower and upper limits of the block, including the bath.

Returns:
lower : array
The coordinate of the lower left corner of the block
upper : array
The coordinate of the upper right corner of the block
corner_at_origin()

Put the corner of the tissue block at the origin.

mesher_opts(meshname)

Generate a list of command line arguments for mesher.

Args:
meshname : str
The base name of the mesh to be generated.
Returns:
list
The mesher argument list.
resolution()

Return the currently set mesh resolution.

Returns:
float
The mesh resolution.
set_bath(thickness, both_sides=True)

Add a bath region of the specified thickness.

Note that this method does not use the mesher convention of positive bath size meaning bath on one side and negative bath size meaning bath on both sides. Instead always use positive thickness values and the optional both_sides parameter to control this behaviour.

Args:
thickness : array-like
The thickness of bath to add, one value per coordinate axis
both_side : bool or array-like of bools, optional
If True, generate bath on both sides of the object, if False only on one side. Pass an array of bools to control this behaviour for individual directions.
set_fibres(fibre_endo=None, fibre_epi=None, sheet_endo=None, sheet_epi=None)

Set the angles for generated fibres in the generated geometry.

Args:
fibre_endo : float, optional
Set the principal fibre direction on the endocardium
fibre_epi : float, optional
Set the principal fibre direction on the epicardium
sheet_endo : float, optional
Set the sheet direction on the endocardium
sheet_epi : float, optional
Set the shhet direction on the epicardium
shape(bath=True)

Determine the number of points in each dimension.

tissue_limits()

Return the lower and upper limits of the block, excluding the bath.

Returns:
lower : array
The coordinate of the lower left corner of the tissue block
upper : array
The coordinate of the upper right corner of the tissue block