Exemplo n.º 1
0
    elif o == '--output_filename':
        out_filename = a

    elif o == '--cf-scale':
        scale_factor = float(a)

if len(args) > 0:
    io_filename = args[0]
    if output_filename == None:
        out_filename = ''.join(io_filename.rsplit('.')[:-1]) + '-filtered.hdf5'
else:
    usage()
    exit(1)

with MechanicsHdf5(io_filename=io_filename, mode='r') as io:
    with MechanicsHdf5(io_filename=out_filename, mode='w') as out:

        hdf1 = io._out
        hdf2 = out._out

        # copy /data/input
        hdf2.__delitem__('data/input')
        h5py.h5o.copy(hdf1.id, "data/input", hdf2.id, "data/input")
        # copy /data/nslaws
        hdf2.__delitem__('data/nslaws')
        h5py.h5o.copy(hdf1.id, "data/nslaws", hdf2.id, "data/nslaws")
        # copy /data/ref
        hdf2.__delitem__('data/ref')
        h5py.h5o.copy(hdf1.id, "data/ref", hdf2.id, "data/ref")
Exemplo n.º 2
0
def list_contactors(io):
    print('')
    print('Contactors:')
    print('')
    print('{0:>5} {1:>15} {2:>9} {3:>9}'.format('Id', 'Name', 'Type',
                                                'Primitive'))
    print('{0:->5} {0:->15} {0:->9} {0:->9}'.format(''))
    for name, obj in io.shapes().items():
        print('{0:>5} {1:>15} {2:>9} {3:>9}'.format(
            obj.attrs['id'], name, obj.attrs['type'],
            obj.attrs['primitive'] if 'primitive' in obj.attrs else ''))


if __name__ == '__main__':
    try:
        with MechanicsHdf5(mode='r', io_filename=args.file[0]) as io:
            if io.dynamic_data() is None or len(io.dynamic_data()) == 0:
                print('Empty simulation found.')
            else:
                print('')
                print('Filename: "{0}"'.format(args.file[0]))
                summarize(io)
                if args.list_objects:
                    list_objects(io)
                if args.list_contactors:
                    list_contactors(io)
    except IOError as e:
        print('Error reading "{0}"'.format(args.file[0]))
        print(e)
Exemplo n.º 3
0
#!/usr/bin/env @PYTHON_EXECUTABLE@
"""
Description: Viewer for Siconos mechanics-IO HDF5 files based on VTK.
"""

from siconos.io.vview import VView, VViewConfig, VViewOptions
from siconos.io.mechanics_hdf5 import MechanicsHdf5

if __name__ == '__main__':
    ## Persistent configuration
    config = VViewConfig()

    # Load it immediately
    config.load_configuration()

    # Parse command-line
    opts = VViewOptions()
    opts.parse()

    ## Options and config already loaded above
    with MechanicsHdf5(io_filename=opts.io_filename, mode='r') as io:
        vview = VView(io, opts, config)
        vview.run()

    # Update configuration and save it
    config['window_size'] = vview.renderer_window.GetSize()
    config.save_configuration(force=False)
Exemplo n.º 4
0
#!/usr/bin/env python
from __future__ import print_function

#
# Example of one object under gravity with one contactor and a ground
#

from siconos.mechanics.collision.tools import Contactor
from siconos.io.mechanics_hdf5 import MechanicsHdf5

# Creation of the hdf5 file for input/output
with MechanicsHdf5(io_filename='cube_scene.hdf5') as io:

    # Definition of a cube as a convex shape
    io.add_convex_shape('Cube', [(-1.0, 1.0, -1.0), (-1.0, -1.0, -1.0),
                                 (-1.0, -1.0, 1.0), (-1.0, 1.0, 1.0),
                                 (1.0, 1.0, 1.0), (1.0, 1.0, -1.0),
                                 (1.0, -1.0, -1.0), (1.0, -1.0, 1.0)])

    # Alternative to the previous convex shape definition.
    # io.add_primitive_shape('Cube1', 'Box', (2, 2, 2))

    # Definition of the ground shape
    io.add_primitive_shape('Ground', 'Box', (100, 100, .5))

    # Definition of a non smooth law. As no group ids are specified it
    # is between contactors of group id 0.
    io.add_Newton_impact_friction_nsl('contact', mu=0.3)

    # The cube object made with an unique Contactor : the cube shape.
    # As a mass is given, it is a dynamic system involved in contact