Exemple #1
0
def test_sphere_1m():
    with MechanicsHdf5Runner() as io:
        io.add_occ_shape('sphere_r1_shp', sphere_r1_shape)

        ###############
        # Sphere 1m
        ###############

        obj = io.add_object('sphere_bdy', [
            Volume(shape_name='sphere_r1_shp',
                   instance_name='sphere_r1_shp_bdy',
                   parameters=steel)
        ],
                            translation=[0., 0., 0.],
                            velocity=[0., 0., 0., 0., 0., 0.])

        radius = 1.0
        volume = 4 / 3. * math.pi * radius**3
        mass = volume * steel.density

        inertia = 2 / 5 * mass * radius**2
        print('volume :', volume)
        print('mass :', mass)
        print('inertia :', inertia)

        # print(obj.attrs['id'])
        c_mass = obj.attrs['mass']
        c_inertia = obj.attrs['inertia'][0][0]
        assert (abs(mass - c_mass) < tol)
        assert (abs(inertia - c_inertia) < tol)
Exemple #2
0
def test_sphere_1cm():
    with MechanicsHdf5Runner() as io:
        io.add_occ_shape('sphere_r1_shp', sphere_r1_shape)
        ###############
        # Sphere 1 cm
        ###############

        # to compute the center of mass and perform the right translation
        print('############### sphere of Radius 1cm')
        obj = io.add_object('sphere_cm_bdy', [
            Volume(shape_name='sphere_r1_shp',
                   instance_name='sphere_r1_shp_bdy',
                   parameters=steel_cm)
        ],
                            translation=[0., 0., 0.],
                            velocity=[0., 0., 0., 0., 0., 0.])

        radius = 1.0
        volume = 4 / 3. * math.pi * radius**3
        mass = volume * steel_cm.density

        inertia = 2 / 5 * mass * radius**2  # * 1e-4 # Warning the inertia unit is kg.m^2, so it is not sufficient to scale to density.

        print('volume :', volume)
        print('mass :', mass)
        print('inertia :', inertia)
        c_mass = obj.attrs['mass']
        c_inertia = obj.attrs['inertia'][0][0]
        assert (abs(mass - c_mass) < tol)
        assert (abs(inertia - c_inertia) < tol)
Exemple #3
0
def test_sphere_001m():
    with MechanicsHdf5Runner() as io:

        io.add_occ_shape('sphere_r001_shp', sphere_r001_shape)

        ###############
        # Sphere 0.001 m
        ###############

        # to compute the center of mass and perform the right translation
        print('############### sphere of Radius 0.01 m')
        obj = io.add_object('Sphere001_com', [
            Volume(shape_name='sphere_r001_shp',
                   instance_name='sphere_r001_shp_bdy',
                   parameters=steel)
        ],
                            translation=[0., 0., 0.],
                            velocity=[0., 0., 0., 0., 0., 0.])

        radius = 0.001
        volume = 4 / 3. * math.pi * radius**3
        mass = volume * steel.density

        inertia = 2 / 5 * mass * radius**2
        print('volume :', volume)
        print('mass :', mass)
        print('inertia :', inertia)
        c_mass = obj.attrs['mass']
        c_inertia = obj.attrs['inertia'][0][0]
        assert (abs(mass - c_mass) < tol)
        assert (abs(inertia - c_inertia) < tol)
Exemple #4
0
def test_two_sphere_1m_steel_water():
    with MechanicsHdf5Runner() as io:
        io.add_occ_shape('sphere_r1_shp', sphere_r1_shape)

        #################
        # Two spheres 1m steel and water
        #################

        obj = io.add_object('two_spheres_bdy', [
            Volume(shape_name='sphere_r1_shp',
                   instance_name='sphere_r1_shp_bdy',
                   parameters=steel,
                   relative_translation=[0., -2., 0.]),
            Volume(shape_name='sphere_r1_shp',
                   instance_name='sphere_r1_shp_bdy',
                   parameters=water,
                   relative_translation=[0, +2., 0.])
        ],
                            translation=[0., 0., 0.],
                            velocity=[0., 0., 0., 0., 0., 0.])

        radius = 1.0
        volume = 4 / 3. * math.pi * radius**3
        mass1 = volume * steel.density
        mass2 = volume * water.density
        mass = mass1 + mass2

        print('volume :', volume)
        print('mass :', mass)
        inertia_y = 2 / 5 * mass * radius**2
        print('inertia (y) :', inertia_y)

        d1 = 2 - 1.54285714286
        d2 = 2 + 1.54285714286
        inertia_zx = mass1 * d1**2 + 2 / 5 * mass1 * radius**2 + mass2 * d2**2 + 2 / 5 * mass2 * radius**2
        print('inertia (z and x) :', inertia_zx)
        print(obj.attrs['id'])
        c_mass = obj.attrs['mass']
        c_inertia_zx = obj.attrs['inertia'][0][0]
        c_inertia_y = obj.attrs['inertia'][1][1]

        assert (abs(mass - c_mass) < 1e-08)
        assert (abs(inertia_y - c_inertia_y) < tol)
        assert (abs(inertia_zx - c_inertia_zx) < tol)
Exemple #5
0
def test_two_sphere_1m():
    with MechanicsHdf5Runner() as io:

        io.add_occ_shape('two_spheres_r1_shp', comp)

        #################
        # Two spheres 1m
        #################

        obj = io.add_object('two_spheres_comp', [
            Volume(shape_name='two_spheres_r1_shp',
                   instance_name='comp',
                   parameters=steel)
        ],
                            translation=[0., 0., 0.],
                            velocity=[0., 0., 0., 0., 0., 0.])

        # obj= io.add_object('Two_Sphere_com',
        #               [Volume(shape_name='two_sphere_R=1_shp',
        #                       instance_name='balance_wheel_shp_bdy',
        #                       parameters=steel)],
        #                translation=[0., 0., 0.],
        #                velocity=[0., 0., 0., 0., 0., 0.])
        radius = 1.0
        volume = 2 * 4 / 3. * math.pi * radius**3
        mass = volume * steel.density
        print('volume :', volume)
        print('mass :', mass)
        d = 2
        inertia_zy = 2 * (2 / 5 * mass / 2.0 * radius**2 + mass / 2.0 * d**2)
        print('inertia (z and y) :', inertia_zy)
        inertia_x = (2 / 5 * mass * radius**2)
        print('inertia (x) :', inertia_x)
        c_mass = obj.attrs['mass']
        c_inertia_zy = obj.attrs['inertia'][1][1]
        c_inertia_x = obj.attrs['inertia'][0][0]

        assert (abs(mass - c_mass) < tol)
        assert (abs(inertia_x - c_inertia_x) < tol)
        assert (abs(inertia_zy - c_inertia_zy) < tol)
    io.addShapeDataFromFile('Chamber',
                            '../Mechanisms/SliderCrank/CAD/chamber.step')

    io.addShapeDataFromFile('AxisBody',
                            '../Mechanisms/SliderCrank/CAD/AxisBody2.stp')

    io.addShapeDataFromFile('Artefact',
                            '../Mechanisms/SliderCrank/CAD/artefact2.step')

#    io.addObject('Artefact', [Shape(shape_data='Artefact',
#                                    instance_name='artefact')],
#                 translation=[0., 0., 0.])

    io.addObject('part1', [Volume(shape_data='body1',
                                  instance_name='Body1',
                                  relative_translation=[-0.5*l1, 0., 0.],
                                  relative_orientation=[(0, 1, 0), 0. ])],
                 translation=[0.5*l1, 0., 0.],
                 velocity=[0., 0., -0.5 * w10 * l1, 0., w10, 0.],
                 mass=0.038,
                 inertia=[7.4e-5, 1, 1.])

    io.addObject('part2', [Volume(shape_data='body2',
                                  instance_name='Body2',
                                  relative_translation=[-0.5 * l2, 0., 0.])],
                 translation=[l1 + 0.5*l2, 0., 0.],
                 orientation=[0., 0., 1., 0.],
                 velocity=[0., 0., -0.5 * w10 * l1, 0., w20, 0.],
                 mass=0.038,
                 inertia=[5.9e-4, 1., 1.])
Exemple #7
0
from OCC.BRepPrimAPI import BRepPrimAPI_MakeBox, BRepPrimAPI_MakeSphere
from OCC.gp import gp_Pnt

siconos.io.mechanics_run.set_backend('occ')

sphere = BRepPrimAPI_MakeSphere(1.).Shape()
ground = BRepPrimAPI_MakeBox(gp_Pnt(-50, -50, 0), 100., 100., .5).Shape()

# Creation of the hdf5 file for input/output
with MechanicsHdf5Runner() as io:

    io.add_occ_shape('Sphere', sphere)
    io.add_occ_shape('Ground', ground)

    io.add_object('sphere',
                  [Volume('Sphere'),
                   Contactor('Sphere', contact_type='Face', contact_index=0)],
                  mass=1, translation=[0, 0, 10], velocity=[0, 0, 0, 0, 0, 0])

    io.add_object('ground',
                  [Contactor('Ground', contact_type='Face', contact_index=5)],
                  mass=0, translation=[0, 0, 0])

    io.add_interaction('sphere-ground',
                       'sphere', 'Sphere-1',
                       'ground', 'Ground-0',
                       distance_calculator='occ',
                       offset1=0.01)

    io.add_Newton_impact_friction_nsl('contact', mu=0.3, e=0.9)
        #               mass = 100.0)
        balance_wheel_com = np.array([10.36290606, -3.90431343, -0.21335326])

        inertia = [
            .019661740055950054, 0.028171281786527207, 0.021165152882136887
        ]
        init_orientation = [0.97366047, 0., 0., -0.22800273]  #

        angle_init = math.asin(-0.22800273)
        print('angle_init =', angle_init)
        angle_init = math.pi / 4.0
        init_orientation = [math.sin(angle_init), 0., 0., math.cos(angle_init)]

        io.add_object('balance_wheel_body', [
            Volume(shape_name='balance_wheel_shp',
                   instance_name='balance_wheel_shp_bdy',
                   relative_translation=-1.0 * balance_wheel_com,
                   parameters=steel_mm),
            Contactor(instance_name='balance_wheel_contactor_shp_f0',
                      shape_name='balance_wheel_contactor_shp',
                      contact_type='Face',
                      contact_index=0,
                      relative_translation=-1.0 * balance_wheel_com),
            Contactor(instance_name='balance_wheel_contactor_shp_f1',
                      shape_name='balance_wheel_contactor_shp',
                      contact_type='Face',
                      contact_index=1,
                      relative_translation=-1.0 * balance_wheel_com)
        ],
                      translation=balance_wheel_com,
                      orientation=init_orientation,
                      velocity=[0., 0., 0., 0., 0., 0.])