# pycbg.preprocessing.Mesh

class `pycbg.preprocessing.``Mesh`(dimensions, ncells, 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 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.

    - 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', 'ED3H64'}, 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

  `filename`

    Path to the mesh file from the current working directory.

    Type

      str

  `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

  `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’, ‘ED3H64’}

  Notes

  - The mesh file is written upon creating the object.

  - The nodes’ coordinates are always positive.

  - The point (0,0,0) will always be a node of the mesh.

  - The maximum coordinates are `self.l0`, `self.l1` and `self.l2` on the axis 0, 1 and 2 respectively.

  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, directory='', check_duplicates=True, cell_type='ED3H8')

    Initialize self. See help(type(self)) for accurate signature.

  Methods

  `__init__` | Initialize self.
  `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.

  `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)

    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.

  `write_file`()

    Write the mesh file formated for CB-Geo.