Exemplo n.º 1
0
def createSceneReal(rootNode, dt, fixed_const_lst, moving_const_lst):
    length_scale = sys.argv[1]
    block_msh = 'block_' + length_scale + '.msh'

    rootNode = Scene(rootNode, gravity=[0.0, -0.0, 1000.0], dt=dt)
    rootNode.createObject('RequiredPlugin', pluginName='SoftRobots')
    rootNode.createObject(
        'VisualStyle',
        displayFlags=
        'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe'
    )

    rootNode.createObject('RequiredPlugin', pluginName='SoftRobots')
    rootNode.createObject(
        'VisualStyle',
        displayFlags=
        'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe'
    )
    rootNode.dt = dt

    rootNode.createObject('FreeMotionAnimationLoop')
    rootNode.createObject('GenericConstraintSolver',
                          name='gencs',
                          maxIterations='500',
                          printLog='0',
                          tolerance='0.0000001')

    rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765')
    YoungModulus = 1800
    InitialValue = 0.01
    Translation = None
    Block = ElasticMaterialObject(name="block",
                                  attachedTo=rootNode,
                                  volumeMeshFileName=meshpath + block_msh,
                                  surfaceMeshFileName=None,
                                  youngModulus=YoungModulus,
                                  withConstrain=True,
                                  totalMass=1.0,
                                  translation=None)

    fixed_const_str = ""
    for i in fixed_const_lst:
        fixed_const_str = fixed_const_str + " " + str(i)

    moving_const_str = ""
    for i in moving_const_lst:
        moving_const_str = moving_const_str + " " + str(i)

    print 'moving', moving_const_str
    print 'fixed ', fixed_const_str

    Block.createObject("FixedConstraint", indices=fixed_const_str)

    inds = "7 63 62 60 5 254 240 206 236 47 68 69 253"

    Block.createObject('PartialLinearMovementConstraint',
                       indices=moving_const_str,
                       keyTimes='0 ' + str(dt) + " 10",
                       template='Vec3d',
                       movements='0. 0. 0. 0. -1 0. 0. -1 0.')
    #cavity = PneumaticCavity(name='Cavity', attachedAsAChildOf=Block,
    #                         surfaceMeshFileName=meshpath + block_inside_stl, valueType='pressureGrowth',
    #                         initialValue=InitialValue, translation=Translation)

    BlockVisu = Block.createChild('visu')
    BlockVisu.createObject('TriangleSetTopologyContainer', name='container')
    BlockVisu.createObject('TriangleSetTopologyModifier')
    BlockVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d')
    BlockVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d')
    BlockVisu.createObject('Tetra2TriangleTopologicalMapping',
                           name='Mapping',
                           input="@../container",
                           output="@container")
    BlockVisu.createObject('OglModel',
                           template='ExtVec3f',
                           color='0.3 0.2 0.2 0.6',
                           translation=Translation)
    BlockVisu.createObject('IdentityMapping')

    return Block
def createSceneReal(rootNode, dt, L):
    length_scale = L
    disk_msh = 'disk_' + length_scale + '.msh'
    disk_inside_stl = 'disk_inside' + length_scale + '.stl'
    '''
    # find point closest to zero (with positive z valu) 
    vector, mid_ind = point_finder.nth_smallest_point(disk_msh, 0)
    i = 0
    while vector[-1] < 1.0:
        i += 1
        vector, mid_ind = point_finder.nth_smallest_point(disk_msh, i)

    print(vector, mid_ind)'''

    rootNode = Scene(rootNode, gravity=[0.0, -0.0, 9.8], dt=dt)
    rootNode.createObject('RequiredPlugin', pluginName='SoftRobots')
    rootNode.createObject(
        'VisualStyle',
        displayFlags=
        'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe'
    )

    rootNode.createObject('RequiredPlugin', pluginName='SoftRobots')
    rootNode.createObject(
        'VisualStyle',
        displayFlags=
        'showVisualModels hideBehaviorModels showCollisionModels hideBoundingCollisionModels hideForceFields showInteractionForceFields hideWireframe'
    )
    rootNode.dt = 0.001

    rootNode.createObject('FreeMotionAnimationLoop')
    rootNode.createObject('GenericConstraintSolver',
                          name='gencs',
                          maxIterations='500',
                          printLog='0',
                          tolerance='0.0000001')
    #disksolver = rootNode.add('SparseLDLSolver', name="solver")
    rootNode.createObject('BackgroundSetting', color='0 0.168627 0.211765')
    YoungModulus = 1800
    InitialValue = 0.01
    Translation = None
    Bunny = ElasticMaterialObject(name="disk",
                                  attachedTo=rootNode,
                                  volumeMeshFileName=meshpath + disk_msh,
                                  surfaceMeshFileName=meshpath +
                                  disk_inside_stl,
                                  youngModulus=YoungModulus,
                                  withConstrain=True,
                                  totalMass=1.0,
                                  translation=None)

    fixed_const_str = ""
    fixed_const_lst = point_finder.all_nodes_within_and_below_zero(
        disk_msh, 2.0)
    for i in fixed_const_lst:
        fixed_const_str = fixed_const_str + " " + str(i)

    print "hell", fixed_const_lst, fixed_const_str

    Bunny.createObject("FixedConstraint", indices=fixed_const_str)

    cavity = PneumaticCavity(name='Cavity',
                             attachedAsAChildOf=Bunny,
                             surfaceMeshFileName=meshpath + disk_inside_stl,
                             valueType='pressureGrowth',
                             initialValue=InitialValue,
                             translation=Translation)

    BunnyVisu = Bunny.createChild('visu')
    BunnyVisu.createObject('TriangleSetTopologyContainer', name='container')
    BunnyVisu.createObject('TriangleSetTopologyModifier')
    BunnyVisu.createObject('TriangleSetTopologyAlgorithms', template='Vec3d')
    BunnyVisu.createObject('TriangleSetGeometryAlgorithms', template='Vec3d')
    BunnyVisu.createObject('Tetra2TriangleTopologicalMapping',
                           name='Mapping',
                           input="@../container",
                           output="@container")
    BunnyVisu.createObject('OglModel',
                           template='ExtVec3f',
                           color='0.3 0.2 0.2 0.6',
                           translation=Translation)
    BunnyVisu.createObject('IdentityMapping')

    return Bunny