Beispiel #1
0
def test_xml3():
    ''' DryFriction '''
    # --- buildModelXML loading from xml file ---
    oscillator = buildModelXML(os.path.join(working_dir,
                                            'data/DryFriction.xml'))

    # --- Get the simulation ---
    s = oscillator.simulation()
    k = 0
    T = oscillator.finalT()
    t0 = oscillator.t0()
    h = s.timeStep()
    N = np.ceil((T - t0) / h)
    # --- Get the values to be plotted ---
    # . saved in a matrix dataPlot
    dataPlot = np.zeros((N + 1, 5))

    print("Prepare data for plotting ... ")
    # For the initial time step:
    # time
    dataPlot[k, 0] = t0
    # state q for the first dynamical system (ball)
    dsN = SK.dynamicalSystems(oscillator.nonSmoothDynamicalSystem().topology().dSG(0))[0].number()
    oscillo = oscillator.nonSmoothDynamicalSystem().dynamicalSystem(dsN)
    inter = SK.interactions(oscillator.nonSmoothDynamicalSystem().topology().indexSet(0))[0]

    dataPlot[k, 1] = oscillo.q()[0]
    # velocity for the oscillo
    dataPlot[k, 2] = oscillo.velocity()[0]
    dataPlot[k, 3] = inter.lambda_(1)[0]
    dataPlot[k, 4] = inter.lambda_(1)[1]

    # --- Compute elapsed time ---
    print("Computation ... ")
    # --- Time loop  ---
    while k < N:
        # get current time step
        k += 1
        #  print( " Pas " << k
        # solve ...
        s.computeOneStep()
        # --- Get values to be plotted ---
        # time
        dataPlot[k, 0] = s.nextTime()
        # Oscillo: state q
        dataPlot[k, 1] = oscillo.q()[0]
        # Oscillo: velocity
        dataPlot[k, 2] = oscillo.velocity()[0]

        dataPlot[k, 3] = inter.lambda_(1)[0]
        dataPlot[k, 4] = inter.lambda_(1)[1]
        # transfer of state i+1 into state i and time incrementation
        s.nextStep()

    # Number of time iterations
    print("Number of iterations done: {:}".format(k))

    # dataPlot (ascii) output
    np.savetxt("DryFriction.dat",  dataPlot)
        bouncingBox.nonSmoothDynamicalSystem().insertDynamicalSystem(ds)
        simulation.prepareIntegratorForDS(osi, ds, bouncingBox,
                                          simulation.nextTime())

    simulation.computeOneStep()

    dataPlot[k, 0] = simulation.nextTime()
    dataPlot[k, 1] = q[2]
    dataPlot[k, 2] = v[2]

    #if (broadphase.collisionWorld().getDispatcher().getNumManifolds() > 0):
    if (broadphase.statistics().new_interactions_created +
            broadphase.statistics().existing_interactions_processed) > 0:
        if bouncingBox.nonSmoothDynamicalSystem().topology().\
          numberOfIndexSet() == 2:
            index1 = sk.interactions(simulation.indexSet(1))
            if (len(index1) == 4):
                dataPlot[k, 3] = norm(index1[0].lambda_(1)) + \
                norm(index1[1].lambda_(1)) + norm(index1[2].lambda_(1)) + \
                norm(index1[3].lambda_(1))

    k += 1
    simulation.nextStep()

#
# comparison with the reference file
#
from siconos.kernel import SimpleMatrix, getMatrix
from numpy.linalg import norm

ref = getMatrix(SimpleMatrix("result_dynamic.ref"))
    # Add a second box dynamically to the simulation
    if k == 100:
        broadphase.addDynamicObject(makeBox(pos=3), simulation)

    broadphase.buildInteractions(bouncingBox.currentTime())
    simulation.computeOneStep()

    dataPlot[k, 0] = simulation.nextTime()
    dataPlot[k, 1] = q[2]
    dataPlot[k, 2] = v[2]

    if (broadphase.collisionWorld().getDispatcher().getNumManifolds() > 0):
        if bouncingBox.nonSmoothDynamicalSystem().topology().\
          numberOfIndexSet() > 1:
            index1 = sk.interactions(simulation.indexSet(1))
            if (len(index1) == 4):
                dataPlot[k, 3] = norm(index1[0].lambda_(1)) + \
                norm(index1[1].lambda_(1)) + norm(index1[2].lambda_(1)) + \
                norm(index1[3].lambda_(1))

    k += 1
    simulation.nextStep()

#
# comparison with the reference file
#
from siconos.kernel import SimpleMatrix, getMatrix
from numpy.linalg import norm

ref = getMatrix(SimpleMatrix("result_dynamic.ref"))