<commit_before>#!/usr/bin/env python

# Siconos-sample, Copyright INRIA 2005-2011.
# Siconos is a program dedicated to modeling, simulation and control
# of non smooth dynamical systems.
# Siconos is a free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# Siconos is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Siconos; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contact: <NAME>, <EMAIL>
#


from matplotlib.pyplot import subplot, title, plot, grid, show

from Siconos.Kernel import LagrangianLinearTIDS, NewtonImpactNSL,\
     LagrangianLinearTIR, Interaction, Model, Moreau, TimeDiscretisation, LCP, TimeStepping

from numpy import array, eye, empty

t0 = 0      # start time
T = 5      # 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 = Moreau(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)


# the number of time steps
N = (T-t0)/h

# Get the values to be plotted 
# ->saved in a matrix dataPlot

dataPlot = empty((N+1,5))

lambda_ = inter.lambda_(1)

dataPlot[0, 0] = t0
dataPlot[0, 1] = ball.q()[0]
dataPlot[0, 2] = ball.velocity()[0]
dataPlot[0, 3] = ball.p(1)[0]
dataPlot[0, 4] = inter.lambda_(1)

k = 1

# time loop
while(s.nextTime() < T):
    s.computeOneStep()

    dataPlot[k, 0] = s.nextTime()
    dataPlot[k, 1] = ball.q()[0]
    dataPlot[k, 2] = ball.velocity()[0]
    dataPlot[k, 3] = ball.p(1)[0]
    dataPlot[k, 4] = inter.lambda_(1)[0]

    k += 1
    s.nextStep()
    print s.nextTime()
#
# plots
#
subplot(411)
title('position')
plot(dataPlot[:,0], dataPlot[:,1])
grid()
subplot(412)
title('velocity')
plot(dataPlot[:,0], dataPlot[:,2])
grid()
subplot(413)<commit_msg>with q,v,p,lambda_ as numpy pointers<commit_after>#!/usr/bin/env python

# Siconos-sample, Copyright INRIA 2005-2011.
# Siconos is a program dedicated to modeling, simulation and control
# of non smooth dynamical systems.
# Siconos is a free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# Siconos is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Siconos; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#
# Contact: <NAME>, <EMAIL>
#


from matplotlib.pyplot import subplot, title, plot, grid, show

from Siconos.Kernel import LagrangianLinearTIDS, NewtonImpactNSL,\
     LagrangianLinearTIR, Interaction, Model, Moreau, TimeDiscretisation, LCP, TimeStepping

from numpy import array, eye, empty

t0 = 0      # start time
T = 5      # 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 = Moreau(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)


# the number of time steps
N = (T-t0)/h

# Get the values to be plotted 
# ->saved in a matrix dataPlot

dataPlot = empty((N+1,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.nextTime() < T):
    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
    s.nextStep()
    print s.nextTime()
#
# plots
#
subplot(411)
title('position')
plot(dataPlot[:,0], dataPlot[:,1])
grid()
subplot(412)
title('velocity')
plot(dataPlot[:,0], dataPlot[:,2])
grid()
subplot(413)
{'fraction_non_alphanumeric': 0.12232461355529133, 'fraction_numerical': 0.03210463733650416, 'mean_word_length': 4.117110266159695, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6098673', 'n_tokens_mistral': 2550, 'n_tokens_neox': 2335, 'n_words': 763}