PyLaGriT

class pylagrit.PyLaGriT(lagrit_exe=None, verbose=True, batch=False, batchfile='pylagrit.lgi', gmv_exe=None, paraview_exe=None, timeout=300, *args, **kwargs)

Python lagrit class

Parameters:
  • lagrit_exe (str) – Path to LaGriT executable
  • verbose (bool) – If True, LaGriT terminal output will be displayed
  • batch (bool) – If True, PyLaGriT will be run in batch mode, collecting LaGriT commands until the run_batch method is called.
  • batchfile (str) – Name of batch file to use if batch is True
  • gmv_exe (str) – Path to GMV executable
  • paraview_exe (str) – Path to ParaView executable
  • timeout – Number of seconds to wait for response from LaGriT
convert(pattern, new_ft)

Convert File(s)

For each file of the pattern, creates a new file in the new_ft format. The new files will be inside the directory that the LaGriT object was instantiated. The name of each file will be the same as the original file with the extension changed to new_ft.

Supports conversion from avs, and gmv files. Supports conversion to avs, exo, and gmv files.

Parameters:
  • pattern (str) – Path, name or unix style file pattern of files to be converted.
  • new_ft (str) – New format to convert files.
Example:
>>> #To use pylagrit, import the module.
>>> import pylagrit
>>>
>>> #Create your pylagrit session.
>>> lg = pylagrit.PyLaGriT()
>>>
>>> #Create a mesh object and dump it to a gmv file 'test.gmv'.
>>> mo = lg.create(name='test')
>>> mo.createpts_brick_xyz((5,5,5), (0,0,0), (5,5,5,))
>>> mo.dump('gmv', 'test.gmv')
>>>
>>> #Convert test.gmv to exoduce and contour files.
>>> lg.convert('test.gmv', 'exo')
>>> lg.convert('test.gmv', 'avs')
copy(mo, name=None)

Copy Mesh Object

Copies a mesh object, mo, and returns the MO object.

create(elem_type='tet', name=None, npoints=0, nelements=0)

Create a Mesh Object

Creates a mesh object in lagrit and an MO in the LaGriT object. Returns the mesh object.

Parameters:
  • name (str) – Name to be given to the mesh object.
  • mesh (str) – The type of mesh object to create.
  • npoints (int) – The number of points.
  • nelements (int) – The number of elements.

Returns: MO

create_hex(name=None, npoints=0, nelements=0)

Create a hexagon mesh object.

create_hyb(name=None, npoints=0, nelements=0)

Create a hybrid mesh object.

create_line(npoints=0, mins=[], maxs=[], rz_switch=(1, 1, 1), name=None)

Create a line mesh object.

create_pri(name=None, npoints=0, nelements=0)

Create a prism mesh object.

create_pyr(name=None, npoints=0, nelements=0)

Create a pyramid mesh object.

create_qua(name=None, npoints=0, nelements=0)

Create a quadrilateral mesh object.

create_tet(name=None, npoints=0, nelements=0)

Create a tetrahedron mesh object.

create_tri(name=None, npoints=0, nelements=0)

Create a triangle mesh object.

create_triplane(name=None, npoints=0, nelements=0)

Create a triplane mesh object.

createpts(crd, npts, mins, maxs, elem_type, rz_switch=(1, 1, 1), rz_value=(1, 1, 1), connect=False, name=None)

Create and Connect Points

Parameters:
  • crd (str) – Coordinate type of either ‘xyz’ (cartesian coordinates), ‘rtz’ (cylindrical coordinates), or ‘rtp’ (spherical coordinates).
  • npts (tuple(int)) – The number of points to create in line
  • mins (tuple(int, int, int)) – The starting value for each dimension.
  • maxs (tuple(int, int, int)) – The ending value for each dimension.
  • elem_type (str) – The type of mesh object to create
  • rz_switch (tuple(int, int, int)) – Determines true or false (1 or 0) for using ratio zoning values.
Returns:

MO

createpts_dxyz(dxyz, mins, maxs, elem_type, clip='under', hard_bound='min', rz_switch=(1, 1, 1), rz_value=(1, 1, 1), connect=True, name=None)

Create and Connect Points to create an orthogonal hexahedral mesh. The vertex spacing is based on dxyz and the mins and maxs specified. mins (default, see hard_bound option) or maxs will be adhered to, while maxs (default) or mins will be modified based on the clip option to be truncated at the nearest value ‘under’ (default) or ‘over’ the range maxs-mins. clip and hard_bound options can be mixed by specifying tuples (see description below).

Parameters:
  • dxyz (tuple(float,float,float)) – The spacing between points in x, y, and z directions
  • mins (tuple(float,float,float)) – The starting value for each dimension.
  • maxs (tuple(float,float,float)) – The ending value for each dimension.
  • mesh (str) – The type of mesh object to create, automatically set to ‘triplane’ if 2d or ‘tet’ if 3d.
  • clip (string or tuple(string,string,string)) – How to handle bounds if range does not divide by dxyz, either clip ‘under’ or ‘over’ range
  • hard_bound (string or tuple(string,string,string)) – Whether to use the “min” or “max” as the hard constraint on dimension
  • rz_switch (tuple(int, int, int)) – Determines true or false (1 or 0) for using ratio zoning values.
  • connect (boolean) – Whether or not to connect points
Example:
>>> from pylagrit import PyLaGriT
>>> l = PyLaGriT()
>>> 
>>> # Create 2x2x2 cell mesh
>>> m = l.create()
>>> m.createpts_dxyz((0.5,0.5,0.5),(0.,0.,0.),(1.,1.,1.),rz_switch=[1,1,1],connect=True)
>>> m.paraview()
>>> #m.gmv()
>>> 
>>> # Create 2x2x2 mesh where maxs will be truncated to nearest value under given maxs
>>> m_under = l.create()
>>> m_under.createpts_dxyz((0.4,0.4,0.4),(0.,0.,0.),(1.,1.,1.),rz_switch=[1,1,1],connect=True)
>>> m_under.paraview()
>>> #m_under.gmv()
>>> 
>>> # Create 3x3x3 mesh where maxs will be truncated to nearest value over given maxs
>>> m_over = l.create()
>>> m_over.createpts_dxyz((0.4,0.4,0.4),(0.,0.,0.),(1.,1.,1.),clip='over',rz_switch=[1,1,1],connect=True)
>>> m_over.paraview()
>>> #m_over.gmv()
>>> 
>>> # Create 3x3x3 mesh where x and y maxs will be truncated to nearest value over given maxs
>>> # and z min will be truncated  to nearest value
>>> m_mixed = l.create()
>>> m_mixed.createpts_dxyz((0.4,0.4,0.4),(0.,0.,-1.),(1.,1.,0.),hard_bound=('min','min','max'),clip=('under','under','over'),rz_switch=[1,1,1],connect=True)
>>> m_mixed.paraview()
>>> #m_mixed.gmv()
createpts_line(npts, mins, maxs, elem_type='line', rz_switch=(1, 1, 1), name=None)

Create and Connect Points in a line

Parameters:
  • npts (int) – The number of points to create in line
  • mins (tuple(int, int, int)) – The starting value for each dimension.
  • maxs (tuple(int, int, int)) – The ending value for each dimension.
  • rz_switch (tuple(int, int, int)) – Determines true or false (1 or 0) for using ratio zoning values.
dump(filename, mos=[], filetype='binary')

Dump lagrit binary file :arg filename: name of lagrit binary file to create :type filename: string :arg mos: List of mesh objects to include, default is all :type mos: list(MO) :arg filetype: Filetype to dump, ‘binary’ or ‘ascii’ :type mos: string

gridder(x=None, y=None, z=None, connect=False, elem_type='tet', filename='gridder.inp')

Generate a logically rectangular orthogonal mesh corresponding to vectors of nodal positions.

Parameters:
  • x (array(floats)) – x node locations
  • y (array(floats)) – y node locations
  • z (array(floats)) – z node locations
  • connect (bool) – Should the points be connected
  • elem_type (string) – Type of element for created mesh object
  • filename (string) – Name of avs file created with nodal coordinates
Returns:

MO

Example:
>>> from pylagrit import PyLaGriT
>>> import numpy
>>> lg = PyLaGriT()
>>> x0 = -numpy.logspace(1,2,15,endpoint=True)
>>> x1 = numpy.arange(-10,10,1)
>>> x2 = -x0
>>> x = numpy.concatenate([x0,x1,x2])
>>> y = x
>>> mqua = lg.gridder(x,y,elem_type='quad',connect=True)
>>> mqua.paraview()
merge(mesh_objs)

Merge Mesh Objects

Merges two or more mesh objects together and returns the combined mesh object.

Parameters:mesh_objs (MO list) – An argument list of mesh objects.

Returns: MO.

Example:
>>> #To use pylagrit, import the module.
>>> import pylagrit
>>> import numpy
>>> #Instantiate the lagrit object.
>>> lg = pylagrit.PyLaGriT()
>>> # Create list with mesh object as first element
>>> dxyz = numpy.array([0.25]*3)
>>> mins = numpy.array([0.]*3)
>>> maxs = numpy.array([1.]*3)
>>> ms = [lg.createpts_dxyz(dxyz,mins,maxs,'tet',connect=True)]
>>> # Create three new mesh objects, each one directly above the other
>>> for i in range(3):
>>>     ms.append(ms[-1].copy())
>>>     ms[-1].trans(ms[-1].mins,ms[-1].mins+numpy.array([0.,0.,1.]))
>>> # Merge list of mesh objects and clean up
>>> mo_merge = lg.merge(ms)
>>> for mo in ms: mo.delete()
>>> mo_merge.rmpoint_compress(filter_bool=True,resetpts_itp=True)
>>> mo_merge.paraview(filename='mo_merge.inp')
read(filename, filetype=None, name=None, binary=False)

Read in mesh

Parameters:
  • filename (str) – Name of mesh file to read in
  • filetype (str) – Type of file, automatically detected if not specified
  • name (str) – Internal Lagrit name of new mesh object, automatically created if None
  • binary (bool) – Indicates that file is binary if True, ascii if False
Returns:

MO

Example 1:
>>> #To use pylagrit, import the module.
>>> import pylagrit
>>> #Create your pylagrit session.
>>> lg = pylagrit.PyLaGriT()
>>> #Create a mesh object and dump it to a gmv file 'test.gmv'.
>>> mo = lg.create(name='test')
>>> mo.createpts_brick_xyz((5,5,5), (0,0,0), (5,5,5,))
>>> mo.dump('test.gmv')
>>> mo.dump('test.avs')
>>> mo.dump('test.lg')
>>> mo1 = lg.read('test.gmv')
>>> mo2 = lg.read('test.avs')
>>> mo3 = lg.read('test.lg',name='test')
Example 2 - Reading in LaGriT binary file, autodetect mesh object name
>>> #To use pylagrit, import the module.
>>> import pylagrit
>>> import numpy
>>> #Instantiate the lagrit object.
>>> lg = pylagrit.PyLaGriT()
>>> # Create list with mesh object as first element
>>> dxyz = numpy.array([0.25]*3)
>>> mins = numpy.array([0.]*3)
>>> maxs = numpy.array([1.]*3)
>>> ms = [lg.createpts_dxyz(dxyz,mins,maxs,'tet',connect=True,name='testmo')]
>>> # Create three new mesh objects, each one directly above the other
>>> for i in range(3):
>>>     ms.append(ms[-1].copy())
>>>     ms[-1].trans(ms[-1].mins,ms[-1].mins+numpy.array([0.,0.,1.]))
>>> lg.dump('lagrit_binary.lg')
>>> lg.close()
>>> lg = pylagrit.PyLaGriT()
>>> ms_read = lg.read('lagrit_binary.lg')
>>> print 'Name of mesh object read in should be testmo, is: ', ms_read.name
read_script(fname)

Read a LaGriT Script

Given a script name, executes the script in LaGriT.

Parameters:fname (str) – The name or path to the lagrit script.
region_bool(bool, name=None)

Create region using boolean string

Parameters:
  • bool (str) – String of boolean operations
  • name (string) – Internal lagrit name for mesh object
Returns:

Region

Example:
>>> from pylagrit import PyLaGriT
>>> import numpy
>>> lg = PyLaGriT()
>>> # Read in mesh
>>> motet = lg.read('tet_matclr.inp')
>>> # fault coordinates in feet
>>> cs = [[498000.,381946.,0.],
>>>       [497197.,381946.,0.],
>>>       [494019.,384890.,0.],
>>>       [490326.,386959.,0.],
>>>       [487822.,388599.,0.],
>>>       [486337.,390755.,0.],
>>>       [486337.,392000.,0.]]
>>> # Convert to meters
>>> cs = numpy.array(cs)/3.28
>>> # Create surfaces of fault
>>> ss = []
>>> for p1,p2 in zip(cs[:-1],cs[1:]):
>>>     p3 = p1.copy()
>>>     p3[2] = -4000.
>>>     ss.append(lg.surface_plane(p1,p2,p3))
>>> # Create region by boolean operations of fault surfaces
>>> boolstr = ''
>>> for i,s in enumerate(ss):
>>>     if not i == 0: boolstr += ' and '
>>>     boolstr += 'le '+s.name
>>> r = lg.region_bool(boolstr)
>>> # Create pset from region
>>> p = motet.pset_region(r)
>>> # Change imt value for pset
>>> p.setatt('imt',21)
>>> motet.dump_zone_imt('tet_nefault',21)
tri_mo_from_polyline(coords, order='clockwise', filename='polyline.inp', name=None)

Create polygon tri mesh object from points Points are expected to be defined clockwise by default

Parameters:
  • coords (lst(floats) or ndarray(floats)) – x,y,z coordinates defined in npoints by 3 array, points expected to be ordered clockwise by default
  • order (string) – ordering of points, clockwise by default
  • filename (string) – Name of avs polyline file to create
  • name (string) – Internal lagrit name for mesh object
Returns:

PyLaGriT Mesh Object

Example:
>>> from pylagrit import PyLaGriT
>>> lg = PyLaGriT()
>>> mo = lg.tri_mo_from_polyline([[0.,0.],[0.,1.],[1.,1.],[1.,0.]])