# ------------- impactingBar = NonSmoothDynamicalSystem(t0, T) # add the dynamical system in the non smooth dynamical system impactingBar.insertDynamicalSystem(bar); # link the interaction and the dynamical system impactingBar.link(inter,bar); # ------------------ # --- Simulation --- # ------------------ # -- (1) OneStepIntegrators -- OSI = MoreauJeanOSI(theta,0.5) # -- (2) Time discretisation -- t = TimeDiscretisation(t0,h) # -- (3) one step non smooth problem osnspb = LCP() s = TimeStepping(impactingBar, t,OSI,osnspb) k =0 N = int((T-t0)/h) dataPlot = np.zeros((N+1, 5)) q = bar.q()
# bouncingBall = Model(t0, T) # add the dynamical system to the non smooth dynamical system bouncingBall.nonSmoothDynamicalSystem().insertDynamicalSystem(ball) # link the interaction and the dynamical system bouncingBall.nonSmoothDynamicalSystem().link(inter, ball) # # Simulation # # (1) OneStepIntegrators OSI = MoreauJeanOSI(theta) OSI.insertDynamicalSystem(ball) # (2) Time discretisation -- t = TimeDiscretisation(t0, h) # (3) one step non smooth problem osnspb = LCP() # (4) Simulation setup with (1) (2) (3) s = TimeStepping(t, OSI, osnspb) # end of model definition #
body.setFExtPtr(weight) # # Model # bouncingBox = Model(t0, T) # add the dynamical system to the non smooth dynamical system bouncingBox.nonSmoothDynamicalSystem().insertDynamicalSystem(body) # # Simulation # # (1) OneStepIntegrators osi = MoreauJeanOSI(theta) ground = SiconosPlane() groundOffset = [0, 0, -0.5, 1, 0, 0, 0] # (2) Time discretisation -- timedisc = TimeDiscretisation(t0, h) # (3) one step non smooth problem osnspb = FrictionContact(3) osnspb.numericsSolverOptions().iparam[0] = 1000 osnspb.numericsSolverOptions().dparam[0] = 1e-5 osnspb.setMaxSize(16384) osnspb.setMStorageType(1) osnspb.setNumericsVerboseMode(False)
def test_bouncing_ball1(): from siconos.kernel import LagrangianLinearTIDS, NewtonImpactNSL, \ LagrangianLinearTIR, Interaction, Model, MoreauJeanOSI, TimeDiscretisation, LCP, TimeStepping from numpy import array, eye, empty t0 = 0 # start time T = 10 # end time h = 0.005 # time step r = 0.1 # ball radius g = 9.81 # gravity m = 1 # ball mass e = 0.9 # restitution coeficient theta = 0.5 # theta scheme # # dynamical system # x = array([1, 0, 0]) # initial position v = array([0, 0, 0]) # initial velocity mass = eye(3) # mass matrix mass[2, 2] = 3./5 * r * r # the dynamical system ball = LagrangianLinearTIDS(x, v, mass) # set external forces weight = array([-m * g, 0, 0]) ball.setFExtPtr(weight) # # Interactions # # ball-floor H = array([[1, 0, 0]]) nslaw = NewtonImpactNSL(e) relation = LagrangianLinearTIR(H) inter = Interaction(1, nslaw, relation) # # Model # bouncingBall = Model(t0, T) # add the dynamical system to the non smooth dynamical system bouncingBall.nonSmoothDynamicalSystem().insertDynamicalSystem(ball) # link the interaction and the dynamical system bouncingBall.nonSmoothDynamicalSystem().link(inter, ball) # # Simulation # # (1) OneStepIntegrators OSI = MoreauJeanOSI(theta) OSI.insertDynamicalSystem(ball) # (2) Time discretisation -- t = TimeDiscretisation(t0, h) # (3) one step non smooth problem osnspb = LCP() # (4) Simulation setup with (1) (2) (3) s = TimeStepping(t) s.insertIntegrator(OSI) s.insertNonSmoothProblem(osnspb) # end of model definition # # computation # # simulation initialization bouncingBall.initialize(s) # # save and load data from xml and .dat # try: from siconos.io import save save(bouncingBall, "bouncingBall.xml") save(bouncingBall, "bouncingBall.bin") except: print("Warning : could not import save from siconos.io") # the number of time steps N = (T-t0)/h+1 # Get the values to be plotted # ->saved in a matrix dataPlot dataPlot = empty((N, 5)) # # numpy pointers on dense Siconos vectors # q = ball.q() v = ball.velocity() p = ball.p(1) lambda_ = inter.lambda_(1) # # initial data # dataPlot[0, 0] = t0 dataPlot[0, 1] = q[0] dataPlot[0, 2] = v[0] dataPlot[0, 3] = p[0] dataPlot[0, 4] = lambda_[0] k = 1 # time loop while(s.hasNextEvent()): s.computeOneStep() dataPlot[k, 0] = s.nextTime() dataPlot[k, 1] = q[0] dataPlot[k, 2] = v[0] dataPlot[k, 3] = p[0] dataPlot[k, 4] = lambda_[0] k += 1 #print(s.nextTime()) s.nextStep() # # comparison with the reference file # from siconos.kernel import SimpleMatrix, getMatrix from numpy.linalg import norm ref = getMatrix(SimpleMatrix(os.path.join(working_dir, "data/result.ref"))) assert (norm(dataPlot - ref) < 1e-12)
# Model # bouncingBall = NonSmoothDynamicalSystem(t0, T) # add the dynamical system to the non smooth dynamical system bouncingBall.insertDynamicalSystem(ball) # link the interaction and the dynamical system bouncingBall.link(inter, ball) # # Simulation # # (1) OneStepIntegrators OSI = MoreauJeanOSI(theta) # (2) Time discretisation -- t = TimeDiscretisation(t0, h) # (3) one step non smooth problem osnspb = LCP() # (4) Simulation setup with (1) (2) (3) s = TimeStepping(bouncingBall, t, OSI, osnspb) # end of model definition # # computation #
body = makeBox() # # Model # bouncingBox = Model(t0, T) # add the dynamical system to the non smooth dynamical system bouncingBox.nonSmoothDynamicalSystem().insertDynamicalSystem(body) # # Simulation # # (1) OneStepIntegrators osi = MoreauJeanOSI(theta) osi.insertDynamicalSystem(body) ground = btCollisionObject() ground.setCollisionFlags(btCollisionObject.CF_STATIC_OBJECT) groundShape = btBoxShape(btVector3(30, 30, .5)) basis = btMatrix3x3() basis.setIdentity() ground.getWorldTransform().setBasis(basis) ground.setCollisionShape(groundShape) ground.getWorldTransform().getOrigin().setZ(-.5) # (2) Time discretisation -- timedisc = TimeDiscretisation(t0, h) # (3) one step non smooth problem