# from siconos.mechanics.collision.tools import Contactor from siconos.io.mechanics_io import Hdf5 import siconos.numerics as Numerics edge_length = 0.1 plane_length = 2.0 velocity_init = 0.0 angular_velocity_init = 0.0 # Creation of the hdf5 file for input/output with Hdf5() as io: # # Definition of a cube as a convex shape io.addConvexShape('CubeCS1', [(-edge_length, edge_length, -edge_length), (-edge_length, -edge_length, -edge_length), (-edge_length, -edge_length, edge_length), (-edge_length, edge_length, edge_length), (edge_length, edge_length, edge_length), (edge_length, edge_length, -edge_length), (edge_length, -edge_length, -edge_length), (edge_length, -edge_length, edge_length)]) io.addConvexShape('CubeCS2', [(-edge_length, edge_length, -edge_length), (-edge_length, -edge_length, -edge_length), (-edge_length, -edge_length, edge_length), (-edge_length, edge_length, edge_length),
bowl_mass = bowl_props.Mass() bowl_com = bowl_props.CentreOfMass() bowl_inertia = bowl_props.MatrixOfInertia() bowl_I1 = bowl_props.MomentOfInertia(gp_Ax1(bowl_com, gp_Dir(1, 0, 0))) bowl_I2 = bowl_props.MomentOfInertia(gp_Ax1(bowl_com, gp_Dir(0, 1, 0))) bowl_I3 = bowl_props.MomentOfInertia(gp_Ax1(bowl_com, gp_Dir(0, 0, 1))) print 'bowl mass:', bowl_mass print 'bowl center of mass:', (bowl_com.Coord(1), bowl_com.Coord(2), bowl_com.Coord(3)) print 'bowl moment of inertia:', (bowl_I1, bowl_I2, bowl_I3) # Creation of the hdf5 file for input/output with Hdf5() as io: io.addOccShape('Contact', bowl) io.addOccShape('Ground', ground) io.addOccShape('Ball', ball) io.addObject('bowl', [ Contactor( 'Contact', contact_type='Face', contact_index=0, ), Contactor( 'Contact',
#!/usr/bin/env python # # Example of one object under gravity with one contactor and a ground # from siconos.mechanics.collision.tools import Contactor from siconos.io.mechanics_io import Hdf5 import siconos.numerics as Numerics import pydoc # Creation of the hdf5 file for input/output with Hdf5() as io: # Definition of a cube as a convex shape io.addConvexShape('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.addPrimitiveShape('Cube1', 'Box', (2, 2, 2)) # Definition of the ground shape io.addPrimitiveShape('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.addNewtonImpactFrictionNSL('contact', mu=0.3) # The cube object made with an unique Contactor : the cube shape.
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 Hdf5(io_filename=io_filename, mode='r') as io: with Hdf5(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")
vector1[0] * vector2[1] - vector1[1] * vector2[0] ] a = cross_product[0] b = cross_product[1] c = cross_product[2] d = -(cross_product[0] * x1 + cross_product[1] * y1 + cross_product[2] * z1) return numpy.array([a, b, c]) / numpy.linalg.norm([a, b, c]) #create some bodies # Creation of the hdf5 file for input/output with Hdf5(use_compression=True) as io: ######### left_up id_plan = id_plan + 1 body_collection['plan_id']["left_up"] = id_plan v1 = numpy.array([0, 0, box_height - 1.200]) v2 = numpy.array([4.370 - 4.370 * 1.200 / box_height, 0.0, 1.200]) v3 = numpy.array([6.900, 0, 1.200]) left_up_normal = normal_plane(v1, v2, v3) print('left_up_normal=', left_up_normal) v1_extruded = v1 + numpy.dot(plan_thickness, left_up_normal) v2_extruded = v2 + numpy.dot(plan_thickness, left_up_normal) v3_extruded = v3 + numpy.dot(plan_thickness, left_up_normal) left_up_vertices = numpy.array(
reader = vtk.vtkSTLReader() reader.SetFileName(tmpf[1]) reader.Update() return reader refs = [] refs_attrs = [] shape = dict() pos = dict() instances = dict() with Hdf5(io_filename=io_filename, mode='r') as io: def load(): ispos_data = io.static_data() idpos_data = io.dynamic_data() ivelo_data = io.velocities_data() icf_data = io.contact_forces_data()[:] isolv_data = io.solver_data() return ispos_data, idpos_data, ivelo_data, icf_data, isolv_data spos_data, dpos_data, velo_data, cf_data, solv_data = load()
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 Hdf5(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, e: print('Error reading "{0}"'.format(args.file[0])) print(e)
#!/usr/bin/env python from siconos.io.mechanics_io import Hdf5 # Run the simulation from the inputs previously defined and add # results to the hdf5 file. The visualisation of the output may be done # with the vview command. with Hdf5(mode='r+', io_filename='cube_scene.hdf5') as io: # By default earth gravity is applied and the units are those # of the International System of Units. # Because of fixed collision margins used in the collision detection, # sizes of small objects may need to be expressed in cm or mm. io.run(output_frequency=100)
fn = 'chute_con_rocas_y_vibradores-{0}-mu-{1}.hdf5'.format(dist, mu) random.seed(0) numpy.random.seed(0) cube_size = 0.1 plan_thickness = cube_size density = 2500 box_height = 3.683 box_length = 6.900 box_width = 3.430 plane_thickness = 0.2 with Hdf5(mode='w', io_filename=fn) as io: io.addNewtonImpactFrictionNSL('contact_rocas', mu=float(mu), e=0.01, collision_group1=0, collision_group2=0) io.addNewtonImpactFrictionNSL('contact_chute_rocas', mu=float(mu), e=0.01, collision_group1=1, collision_group2=0) io.addNewtonImpactFrictionNSL('contact_vibratores_rocas', mu=float(mu), e=0.01, collision_group1=2,