pycbg.preprocessing.Mesh

class pycbg.preprocessing.Mesh(dimensions, ncells, origin=(0.0, 0.0, 0.0), directory='', check_duplicates=True, cell_type='ED3H8')

Create and write to a file a mesh using gmsh.

Parameters
  • dimensions (tuple of floats) – Dimensions of the mesh. Its length should be 3, with dimensions[n] the space dimension of the mesh on the axis n.

  • ncells (tuple of ints) – Number of cells in each direction. Its length should be 3, with ncells[n] the number of cells on the axis n.

  • origin (tuple of floats) – Origin of the mesh. Default is (0.,0.,0.).

  • directory (str, optional) – Directory in which the mesh file will be saved. If the directory doesn’t already exist, it will be created. It is set by default to the current working directory.

  • check_duplicates (bool, optional) – See CB-Geo documentation for informations on this parameter. Default is True.

  • cell_type ({'ED3H8', 'ED3H20', 'ED3H64G'}, optional) – Type of cell. Only 3D Hexahedrons are supported. The number of nodes can be 8, 20 or 64. Default is ‘ED3H8’.

nodes

Positions of all nodes in the mesh. The id of a node is the index of its line in this array. Noting nnodes the number of nodes, the shape of nodes is (nnodes,3).

Type

numpy array

cells

Connections between cells and nodes. Each line corresponds to a cell, its index is the cell’s id. The columns correspond to the ids of the nodes composing a cell. Noting nnode_pcell the number of nodes per cell (8, 20 or 64), the shape of cells is (ncells,nnode_pcell).

Type

numpy array

dimensions

Dimensions of the mesh.

Type

tuple of floats

l0, l1, l2

Dimensions of the mesh (self.l0, self.l1, self.l2 = self.dimensions).

Type

floats

ncells

Number of cells in each direction.

Type

tuple of ints

nc1, nc2, nc3

Number of cells in each direction (self.nc0, self.nc1, self.nc2 = self.ncells).

Type

ints

origin

Origin of the mesh.

Type

tuple of floats

directory

Directory in which the mesh file will be saved.

Type

str

check_duplicates

See CB-Geo documentation.

Type

bool

cell_type

Type of cell.

Type

{‘ED3H8’, ‘ED3H20’, ‘ED3H64G’}

Notes

  • The mesh file is written upon creating the object.

Examples

Creating a cubic mesh of 1000 cells :

>>> mesh = Mesh((1.,1.,1.), (10,10,10))
>>> mesh.nc0 * mesh.nc1 * mesh.nc2
1000
__init__(dimensions, ncells, origin=(0.0, 0.0, 0.0), directory='', check_duplicates=True, cell_type='ED3H8')

Methods

__init__

create_mesh

Create the mesh in gmsh.

set_parameters

Set the dimensions and number of cells of the mesh.

write_file

Write the mesh file formated for CB-Geo MPM.

create_mesh()

Create the mesh in gmsh.

Notes

  • This method calls gmsh.initialize but doesn’t call gmsh.finalize`

  • cells and nodes attributes are not created by this method

  • User shouldn’t have to use this method as it is called by write_file

set_parameters(dimensions, ncells, origin)

Set the dimensions and number of cells of the mesh.

Parameters
  • dimensions (tuple of floats) – Dimensions of the mesh. Its length should be 3, with dimensions[n] the dimension of the mesh on the axis n.

  • ncells (tuple of ints) – Number of cells in each direction. Its length should be 3, with ncells[n] the number of cells on the axis n.

  • origin (tuple of floats) – Origin of the mesh. Default is (0.,0.,0.).

write_file(filename='mesh')

Write the mesh file formated for CB-Geo MPM.

Parameters

filename (str, optional) – Name of the mesh file, the extension ‘.txt’ is automatically added. Default is ‘mesh’.