yade.export module

Export (not only) geometry to various formats.

class yade.export.VTKExporter(inherits object)[source]

Class for exporting data to VTK Simple Legacy File (for example if, for some reason, you are not able to use VTKRecorder). Supported export of:

  • spheres
  • facets
  • polyhedra
  • PotentialBlocks
  • interactions
  • contact points
  • periodic cell

Usage:

  • create object vtkExporter = VTKExporter('baseFileName'),
  • add to O.engines a PyRunner with command='vtkExporter.exportSomething(...)'
  • alternatively, just use vtkExporter.exportSomething(...) at the end of the script for instance

Example: examples/test/vtk-exporter/vtkExporter.py, examples/test/unv-read/unvReadVTKExport.py.

Parameters:
  • baseName (string) – name of the exported files. The files would be named, e.g., baseName-spheres-snapNb.vtk or baseName-facets-snapNb.vtk
  • startSnap (int) – the numbering of files will start form startSnap
exportContactPoints(ids='all', what={}, useRef={}, comment='comment', numLabel=None)[source]

exports contact points (CPs) and defined properties.

Parameters:
exportFacets(ids='all', what={}, comment='comment', numLabel=None)[source]

exports facets (positions) and defined properties. Facets are exported with multiplicated nodes

Parameters:
  • ids ([int]|"all") – if “all”, then export all facets, otherwise only facets from integer list
  • what (dictionary) – see exportSpheres()
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
exportFacetsAsMesh(ids='all', connectivityTable=None, what={}, comment='comment', numLabel=None)[source]

exports facets (positions) and defined properties. Facets are exported as mesh (not with multiplicated nodes). Therefore additional parameters connectivityTable is needed

Parameters:
  • ids ([int]|"all") – if “all”, then export all facets, otherwise only facets from integer list
  • what (dictionary) – see exportSpheres()
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
  • nodes ([(float,float,float)|Vector3]) – list of coordinates of nodes
  • connectivityTable ([(int,int,int)]) – list of node ids of individual elements (facets)
exportInteractions(ids='all', what={}, verticesWhat={}, comment='comment', numLabel=None, useRef=False)[source]

exports interactions and defined properties.

Parameters:
  • ids ([(int,int)]|"all") – if “all”, then export all interactions, otherwise only interactions from (int,int) list
  • what (dictionary) – what to export. parameter is a name->command dictionary. Name is string under which it is saved to vtk, command is string to evaluate. Note that the interactions are labeled as i in this function. Scalar, vector and tensor variables are supported. For example, to export the stiffness difference (named as dStiff) from a certain value (1e9) you should write: what=dict(dStiff='i.phys.kn-1e9', ... )
  • verticesWhat (dictionary) – what to export on connected bodies. Bodies are labeled as b (or b1 and b2 if you need to treat both bodies differently)
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
  • useRef (bool) – if False (default), use current position of the bodies for export, use reference position otherwise
exportPeriodicCell(comment='comment', numLabel=None)[source]

exports the Cell geometry for periodic simulations.

Parameters:
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
exportPolyhedra(ids='all', what={}, comment='comment', numLabel=None, useRef=False)[source]

Exports polyhedrons and defined properties.

Parameters:
  • ids ([int] | "all") – if “all”, then export all polyhedrons, otherwise only polyhedrons from integer list
  • what (dictionary) – which additional quantities (in addition to the positions) to export. parameter is name->command dictionary. Name is string under which it is saved to vtk, command is string to evaluate. Note that the bodies are labeled as b in this function. Scalar, vector and tensor variables are supported. For example, to export velocity (named as particleVelocity) and the distance from point (0,0,0) (named as dist) you should write: what=dict(particleVelocity='b.state.vel',dist='b.state.pos.norm()', ... )
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
exportPotentialBlocks(ids='all', what={}, comment='comment', numLabel=None, useRef=False)[source]

Exports Potential Blocks and defined properties.

Parameters:
  • ids ([int] | "all") – if “all”, then export all Potential Blocks, otherwise only Potential Blocks from integer list
  • what (dictionary) – which additional quantities (in addition to the positions) to export. parameter is name->command dictionary. Name is string under which it is saved to vtk, command is string to evaluate. Note that the bodies are labeled as b in this function. Scalar, vector and tensor variables are supported. For example, to export velocity (named as particleVelocity) and the distance from point (0,0,0) (named as dist) you should write: what=dict(particleVelocity='b.state.vel',dist='b.state.pos.norm()', ... )
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
exportSpheres(ids='all', what={}, comment='comment', numLabel=None, useRef=False)[source]

exports spheres (positions and radius) and defined properties.

Parameters:
  • ids ([int]|"all") – if “all”, then export all spheres, otherwise only spheres from integer list
  • what (dictionary) – which additional quantities (other than the position and the radius) to export. parameter is name->command dictionary. Name is string under which it is save to vtk, command is string to evaluate. Note that the bodies are labeled as b in this function. Scalar, vector and tensor variables are supported. For example, to export velocity (with name particleVelocity) and the distance form point (0,0,0) (named as dist) you should write: what=dict(particleVelocity='b.state.vel',dist='b.state.pos.norm()', ... )
  • comment (string) – comment to add to vtk file
  • numLabel (int) – number of file (e.g. time step), if unspecified, the last used value + 1 will be used
  • useRef (bool) – if False (default), use current position of the spheres for export, use reference position otherwise
class yade.export.VTKWriter(inherits object)[source]

USAGE: create object vtk_writer = VTKWriter(‘base_file_name’), add to engines PyRunner with command=’vtk_writer.snapshot()’

snapshot()[source]
yade.export.gmshGeo(filename, comment='', mask=-1, accuracy=-1)[source]

Save spheres in geo-file for the following using in GMSH (http://www.geuz.org/gmsh/doc/texinfo/) program. The spheres can be there meshed.

Parameters:
  • filename (string) – the name of the file, where sphere coordinates will be exported.
  • mask (int) – export only spheres with the corresponding mask export only spheres with the corresponding mask
  • accuracy (float) – the accuracy parameter, which will be set for the poinst in geo-file. By default: 1./10. of the minimal sphere diameter.
Returns:

number of spheres which were exported.

Return type:

int

yade.export.text(filename, mask=-1)[source]

Save sphere coordinates into a text file; the format of the line is: x y z r. Non-spherical bodies are silently skipped. Example added to examples/regular-sphere-pack/regular-sphere-pack.py

Parameters:
  • filename (string) – the name of the file, where sphere coordinates will be exported.
  • mask (int) – export only spheres with the corresponding mask
Returns:

number of spheres which were written.

Return type:

int

yade.export.text2vtk(inFileName, outFileName, comment='comment')[source]

Converts text file (created by export.textExt function) into vtk file. See examples/test/paraview-spheres-solid-section/export_text.py example

Parameters:
  • inFileName (str) – name of input text file
  • outFileName (str) – name of output vtk file
  • comment (str) – optional comment in vtk file
yade.export.text2vtkSection(inFileName, outFileName, point, normal=(1, 0, 0))[source]

Converts section through spheres from text file (created by export.textExt function) into vtk file. See examples/test/paraview-spheres-solid-section/export_text.py example

Parameters:
  • inFileName (str) – name of input text file
  • outFileName (str) – name of output vtk file
  • point (Vector3|(float,float,float)) – coordinates of a point lying on the section plane
  • normal (Vector3|(float,float,float)) – normal vector of the section plane
yade.export.textClumps(filename, format='x_y_z_r_clumpId', comment='', mask=-1)[source]

Save clumps-members into a text file. Non-clumps members are bodies are silently skipped.

Parameters:
  • filename (string) – the name of the file, where sphere coordinates will be exported.
  • comment (string) – the text, which will be added as a comment at the top of file. If you want to create several lines of text, please use ‘\n#’ for next lines.
  • mask (int) – export only spheres with the corresponding mask export only spheres with the corresponding mask
Returns:

number of clumps, number of spheres which were written.

Return type:

int

yade.export.textExt(filename, format='x_y_z_r', comment='', mask=-1, attrs=[])[source]

Save sphere coordinates and other parameters into a text file in specific format. Non-spherical bodies are silently skipped. Users can add here their own specific format, giving meaningful names. The first file row will contain the format name. Be sure to add the same format specification in ymport.textExt.

Parameters:
  • filename (string) – the name of the file, where sphere coordinates will be exported.
  • format (string) – the name of output format. Supported ‘x_y_z_r’(default), ‘x_y_z_r_matId’, ‘x_y_z_r_attrs’ (use proper comment)
  • comment (string) – the text, which will be added as a comment at the top of file. If you want to create several lines of text, please use ‘\n#’ for next lines. With ‘x_y_z_r_attrs’ format, the last (or only) line should consist of column headers of quantities passed as attrs (1 comment word for scalars, 3 comment words for vectors and 9 comment words for matrices)
  • mask (int) – export only spheres with the corresponding mask export only spheres with the corresponding mask
  • attrs ([str]) – attributes to be exported with ‘x_y_z_r_attrs’ format. Each str in the list is evaluated for every body exported with body=b (i.e. ‘b.state.pos.norm()’ would stand for distance of body from coordinate system origin)
Returns:

number of spheres which were written.

Return type:

int

yade.export.textPolyhedra(fileName, comment='', mask=-1, explanationComment=True, attrs=[])[source]

Save polyhedra into a text file. Non-polyhedra bodies are silently skipped.

Parameters:
  • filename (string) – the name of the output file
  • comment (string) – the text, which will be added as a comment at the top of file. If you want to create several lines of text, please use ‘\n#’ for next lines.
  • mask (int) – export only polyhedra with the corresponding mask
  • explanationComment (str) – inclde explanation of format to the beginning of file
Returns:

number of polyhedra which were written.

Return type:

int