# Miscellaneous Tools for PySPH

## Input/Output of data files

The following functions are handy functions when processing output generated by PySPH or to generate new files.

## Interpolator

This module provides a convenient class called `interpolator.Interpolator` which can be used to interpolate any scalar values from the points onto either a mesh or a collection of other points. SPH interpolation is performed with a simple Shepard filtering.

## SPH Evaluator

This module provides a class that allows one to evaluate a set of equations on a collection of particle arrays. This is very handy for non-trivial post-processing that needs to be quick.

## GMsh input/output

Utility module to read input mesh files. This is primarily for meshes generated using Gmsh. This module also provides some simple classes that allow one to create extruded 3D surfaces by generating a gmsh file in Python.

There is also a function to read VTK dataset and produce points from them. This is very useful as Gmsh can generate VTK datasets from its meshes and thus the meshes can be imported as point clouds that may be used in an SPH simulation.

class pysph.tools.gmsh.Extrude(dx=0.0, dy=0.0, dz=1.0, surfaces=None)

  Extrude a given set of surfaces by the displacements given along each directions.

  Parameters:

    - dx (float) – Extrusion along x.

    - dy (float) – Extrusion along y.

    - dz (float) – Extrusion along z.

    - surfaces (list) – List of surfaces to extrude.

  write(fp, point_id_base=0, elem_id_base=0)

class pysph.tools.gmsh.Gmsh(gmsh=None)

  Construct a Gmsh helper object that can be used to mesh objects.

  Parameters:

    gmsh (str) – Path to gmsh executable.

  get_points(entities, vertices=True, cell_centers=False)

    Given a list of entities, return x, y, z arrays for the position.

    Parameters:

      - entities (list) – List of entities.

      - vertices (bool) – If True, it converts the vertices to points.

      - cell_centers (bool) – If True, converts the cell centers to points.

  get_points_from_geo(geo_file_name, vertices=True, cell_centers=False)

    Given a .geo file, generate a mesh and get the points from the mesh.

    Parameters:

      - geo_file_name (str) – Filename of the .geo file.

      - vertices (bool) – If True, it converts the vertices to points.

      - cell_centers (bool) – If True, converts the cell centers to points.

  write_geo(entities, fp)

    Write a list of given entities to the given file pointer.

  write_vtk_mesh(entities, fname)

    Write a list of given entities to the given file name.

class pysph.tools.gmsh.Loop(start, mesh_size=0.1)

  Create a Line Loop in Gmsh parlance but using a turtle-graphics like approach.

  Use this to create a 2D closed surface. The surface is always in the x-y plane.

  Examples

  Here is a simple example:

      >>> l1 = Loop((0.0, 0.0), mesh_size=0.1)
      >>> l1.move(1.0).turn(90).move(1.0).turn(90).move(1.0).turn(90).move(1.0)

  This will create a square shape.

  arc(radius, angle=180)

    Create a circular arc given the radius and for an angle as specified.

  move(dist)

    Move by given distance at the current angle.

  turn(angle)

    Turn by angle (in degrees).

  write(fp, point_id_base=0, elem_id_base=0)

    Write data to given file object fp.

class pysph.tools.gmsh.Surface(*loops)

  Constructor.

  Parameters:

    loops (tuple(Loop)) – Any additional positional arguments are treated as loop objects.

  write(fp, point_id_base=0, elem_id_base=0)

pysph.tools.gmsh.example_3d_p(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)

  Creates a 3D “P” with a hole inside it.

pysph.tools.gmsh.example_cube(fp=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)

  Simple example of a cube.

pysph.tools.gmsh.example_plot_3d_p(gmsh)

  Note: this will only work if you have gmsh installed.

pysph.tools.gmsh.transform_points(x, y, z, transform)

  Given the coordinates, x, y, z and the TVTK transform instance, return the transformed coordinates.

pysph.tools.gmsh.vtk_file_to_points(fname, vertices=True, cell_centers=True)

  Given a file containing a VTK dataset (currently only an old style .vtk file), convert it to a set of points that can be used for simulation with SPH.

  Parameters:

    - fname (str) – File name.

    - vertices (bool) – If True, it converts the vertices to points.

    - cell_centers (bool) – If True, converts the cell centers to points.

  Return type:

    x, y, z of the points.

## Mayavi Viewer

## Mesh Converter

The following functions can be used to convert a mesh file supported by meshio to a set of surface points.

## Particle Packer

The following functions can be used to create a domain with particle packed around a solid surface in both 2D and 3D.