Esempio n. 1
0
x0 = array([1.,10.])
B = 500*array([[alpha,1-alpha],[-(1-alpha),alpha]])
C = eye(2)
D = zeros((2,2))

# dynamical systems
process = FirstOrderLinearDS(x0, A)
myProcessRelation = ZhuravlevTwistingR(C,B)

myNslaw = RelayNSL(2)
myNslaw.display()

myProcessInteraction = Interaction(ninter, myNslaw,
        myProcessRelation)
myNSDS = NonSmoothDynamicalSystem()
myNSDS.insertDynamicalSystem(process)
myNSDS.link(myProcessInteraction,process)


filippov = Model(t0,T)
filippov.setNonSmoothDynamicalSystemPtr(myNSDS)

td = TimeDiscretisation(t0, h)
s = TimeStepping(td)

myIntegrator = EulerMoreauOSI(process, theta)
s.insertIntegrator(myIntegrator)


#TODO python <- SICONOS_RELAY_LEMKE
Esempio n. 2
0
    body.contactors().push_back(SiconosContactor(box))

    return body


# Initial box body
body = makeBox()

# set external forces
weight = [0, 0, -body.scalarMass() * g]
body.setFExtPtr(weight)

#
# Model
#
bouncingBox = NonSmoothDynamicalSystem(t0, T)

# add the dynamical system to the non smooth dynamical system
bouncingBox.insertDynamicalSystem(body)

#
# Simulation
#

# (1) OneStepIntegrators
osi = MoreauJeanOSI(theta)

ground = SiconosPlane()
groundOffset = [0, 0, -0.5, 1, 0, 0, 0]

# (2) Time discretisation --
Esempio n. 3
0
     [1.0]]

LTIRRelayOscillator=FirstOrderLinearTIR(C,B)
LTIRRelayOscillator.setDPtr(D)

nslaw=RelayNSL(1)
InterRelayOscillator=Interaction(1, nslaw,LTIRRelayOscillator,1)


#
# Model
#
RelayOscillator=Model(t0,T,Modeltitle)

#   add the dynamical system in the non smooth dynamical system
myNSDS = NonSmoothDynamicalSystem()
myNSDS.insertDynamicalSystem(LSRelayOscillator)


#   link the interaction and the dynamical system
myNSDS.link(InterRelayOscillator,LSRelayOscillator)

RelayOscillator.setNonSmoothDynamicalSystemPtr(myNSDS)


#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
print('Compilation of the C plugin with siconos')
from subprocess import call

call(['siconos', '--noexec', '.'], stdout=open(os.devnull, 'wb'))

# dynamical systems
process = FirstOrderLinearDS(x0, A)
process.setComputebFunction('plugins', 'computeB')
myNslaw = RelayNSL(2)
myProcessRelation = FirstOrderLinearR(C, B)
myProcessRelation.setComputeEFunction('plugins', 'computeE')
#myProcessRelation.setDPtr(D)

myProcessInteraction = Interaction(myNslaw, myProcessRelation)

simplerelay = NonSmoothDynamicalSystem(t0, T)
simplerelay.insertDynamicalSystem(process)
simplerelay.link(myProcessInteraction, process)

#myProcessRelation.computeJachx(0, x0, x0 , x0, C)

td = TimeDiscretisation(t0, h)
s = TimeStepping(simplerelay, td)

myIntegrator = EulerMoreauOSI(theta)

s.insertIntegrator(myIntegrator)

osnspb = Relay()
s.insertNonSmoothProblem(osnspb)
#s.setComputeResiduY(True)
Esempio n. 5
0
x0 = array([1.,10.])
B = 500*array([[alpha,1-alpha],[-(1-alpha),alpha]])
C = eye(2)
D = zeros((2,2))

# dynamical systems
process = FirstOrderLinearDS(x0, A)
myProcessRelation = ZhuravlevTwistingR(C,B)

myNslaw = RelayNSL(2)
myNslaw.display()

myProcessInteraction = Interaction(ninter, myNslaw,
        myProcessRelation)
myNSDS = NonSmoothDynamicalSystem()
myNSDS.insertDynamicalSystem(process)
myNSDS.link(myProcessInteraction,process)


filippov = Model(t0,T)
filippov.setNonSmoothDynamicalSystemPtr(myNSDS)

td = TimeDiscretisation(t0, h)
s = TimeStepping(td)

myIntegrator = EulerMoreauOSI(theta)
myIntegrator.insertDynamicalSystem(process)
s.insertIntegrator(myIntegrator)

Esempio n. 6
0
x0 = array([1., 10.])
B = 500 * array([[alpha, 1 - alpha], [-(1 - alpha), alpha]])
C = eye(2)
D = zeros((2, 2))

# dynamical systems
process = FirstOrderLinearDS(x0, A)
myProcessRelation = ZhuravlevTwistingR(C, B)

myNslaw = RelayNSL(2)
myNslaw.display()

myProcessInteraction = Interaction(myNslaw, myProcessRelation)

filippov = NonSmoothDynamicalSystem(t0, T)
filippov.insertDynamicalSystem(process)
filippov.link(myProcessInteraction, process)

td = TimeDiscretisation(t0, h)
s = TimeStepping(filippov, td)

myIntegrator = EulerMoreauOSI(theta)
s.insertIntegrator(myIntegrator)

#TODO python <- SICONOS_RELAY_LEMKE
# access dparam

osnspb = Relay()
s.insertNonSmoothProblem(osnspb)
s.setComputeResiduY(True)
Esempio n. 7
0
def test_diode_bridge():
    """Build diode bridge model"""
    # dynamical system
    bridge_ds = FirstOrderLinearDS(init_state, A)
    # interaction
    diode_bridge_relation = FirstOrderLinearTIR(C, B)
    diode_bridge_relation.setDPtr(D)

    nslaw = ComplementarityConditionNSL(4)
    bridge_interaction = Interaction(nslaw, diode_bridge_relation)

    # Model
    diode_bridge = NonSmoothDynamicalSystem(t0, total_time)
    diode_bridge.setTitle(model_title)
    #  add the dynamical system in the non smooth dynamical system
    diode_bridge.insertDynamicalSystem(bridge_ds)

    #   link the interaction and the dynamical system
    diode_bridge.link(bridge_interaction, bridge_ds)

    # Simulation

    # (1) OneStepIntegrators
    theta = 0.5
    integrator = EulerMoreauOSI(theta)
    # (2) Time discretisation
    time_discretisation = TimeDiscretisation(t0, time_step)

    # (3) Non smooth problem
    non_smooth_problem = LCP()

    # (4) Simulation setup with (1) (2) (3)
    bridge_simulation = TimeStepping(diode_bridge, time_discretisation,
                                     integrator, non_smooth_problem)

    k = 0
    h = bridge_simulation.timeStep()
    # Number of time steps
    N = int((total_time - t0) / h)

    # Get the values to be plotted
    # ->saved in a matrix dataPlot
    data_plot = empty([N, 8])

    x = bridge_ds.x()
    print("Initial state : ", x)
    y = bridge_interaction.y(0)
    print("First y : ", y)
    lambda_ = bridge_interaction.lambda_(0)

    # For the initial time step:
    # time
    data_plot[k, 0] = t0

    #  inductor voltage
    data_plot[k, 1] = x[0]

    # inductor current
    data_plot[k, 2] = x[1]

    # diode R1 current
    data_plot[k, 3] = y[0]

    # diode R1 voltage
    data_plot[k, 4] = -lambda_[0]

    # diode F2 voltage
    data_plot[k, 5] = -lambda_[1]

    # diode F1 current
    data_plot[k, 6] = lambda_[2]

    # resistor current
    data_plot[k, 7] = y[0] + lambda_[2]

    k += 1
    while k < N:
        bridge_simulation.computeOneStep()
        #non_smooth_problem.display()
        data_plot[k, 0] = bridge_simulation.nextTime()
        #  inductor voltage
        data_plot[k, 1] = x[0]
        # inductor current
        data_plot[k, 2] = x[1]
        # diode R1 current
        data_plot[k, 3] = y[0]
        # diode R1 voltage
        data_plot[k, 4] = -lambda_[0]
        # diode F2 voltage
        data_plot[k, 5] = -lambda_[1]
        # diode F1 current
        data_plot[k, 6] = lambda_[2]
        # resistor current
        data_plot[k, 7] = y[0] + lambda_[2]
        k += 1
        bridge_simulation.nextStep()

    #
    # comparison with the reference file
    #
    ref = getMatrix(
        SimpleMatrix(os.path.join(working_dir, "data/diode_bridge.ref")))
    assert norm(data_plot - ref) < 1e-12
    return ref, data_plot
Esempio n. 8
0
ball.setFExtPtr(weight)

#
# Interactions
#

# ball-floor
nslaw = NewtonImpactNSL(e)
relation = BouncingBallR(r)

inter = Interaction(nslaw, relation)

#
# 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 --
Esempio n. 9
0
D = [[0.0, -1.0, 0., 0.], [1.0, 0.0, 1., -1.], [0.0, -1., 0., 0.],
     [0., 1., 0., 0.]]

B = [[0., 0., -1. / Cvalue, 1. / Cvalue], [0., 0., 0., 0.],
     [1.0 / Cfilt, 0., 1.0 / Cfilt, 0.]]

LTIRDiodeBridgeCapFilter = FirstOrderLinearTIR(C, B)
LTIRDiodeBridgeCapFilter.setDPtr(D)

nslaw = ComplementarityConditionNSL(4)
InterDiodeBridgeCapFilter = Interaction(nslaw, LTIRDiodeBridgeCapFilter)

#
# Model
#
DiodeBridgeCapFilter = NonSmoothDynamicalSystem(t0, T)
DiodeBridgeCapFilter.setTitle(Modeltitle)
#   add the dynamical system in the non smooth dynamical system
DiodeBridgeCapFilter.insertDynamicalSystem(LS1DiodeBridgeCapFilter)
DiodeBridgeCapFilter.insertDynamicalSystem(LS2DiodeBridgeCapFilter)

#   link the interaction and the dynamical system
DiodeBridgeCapFilter.link(InterDiodeBridgeCapFilter, LS1DiodeBridgeCapFilter,
                          LS2DiodeBridgeCapFilter)

#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
Esempio n. 10
0
def test_smc1():
    from siconos.kernel import FirstOrderLinearDS, NonSmoothDynamicalSystem, TimeDiscretisation, \
        TimeStepping, ZeroOrderHoldOSI, TD_EVENT
    from siconos.control.simulation import ControlManager
    from siconos.control.sensor import LinearSensor
    from siconos.control.controller import LinearSMCOT2
    from numpy import eye, empty, zeros
    import numpy as np
    from math import ceil, sin

    # Derive our own version of FirstOrderLinearDS
    class MyFOLDS(FirstOrderLinearDS):
        def computeb(self, time):
            t = sin(50 * time)
            # XXX fix this !
            u = [t, -t]
            self.setbPtr(u)

    # variable declaration
    ndof = 2  # Number of degrees of freedom of your system
    t0 = 0.0  # start time
    T = 1  # end time
    h = 1.0e-4  # time step for simulation
    hControl = 1.0e-2  # time step for control
    Xinit = 1.0  # initial position
    N = int(ceil((T - t0) / h + 10))  # number of time steps
    outputSize = 4  # number of variable to store at each time step

    # Matrix declaration
    A = zeros((ndof, ndof))
    x0 = [Xinit, -Xinit]
    Brel = np.array([[0], [1]])
    sensorC = eye(ndof)
    sensorD = zeros((ndof, ndof))
    Csurface = [[0, 1.0]]

    # Simple check
    if h > hControl:
        print("hControl must be bigger than h")
        exit(1)

    # Declaration of the Dynamical System
    processDS = MyFOLDS(x0, A)
    # XXX b is not automatically created ...
    #    processDS.setb([0, 0])
    # Model
    process = NonSmoothDynamicalSystem(t0, T)
    process.insertDynamicalSystem(processDS)
    # time discretization
    processTD = TimeDiscretisation(t0, h)
    tSensor = TimeDiscretisation(t0, hControl)
    tActuator = TimeDiscretisation(t0, hControl)
    # Creation of the Simulation
    processSimulation = TimeStepping(process, processTD, 0)
    processSimulation.setName("plant simulation")

    # Declaration of the integrator
    processIntegrator = ZeroOrderHoldOSI()
    processSimulation.associate(processIntegrator, processDS)
    # Actuator, Sensor & ControlManager
    control = ControlManager(processSimulation)
    sens = LinearSensor(processDS, sensorC, sensorD)

    control.addSensorPtr(sens, tSensor)
    act = LinearSMCOT2(sens)
    act.setCsurface(Csurface)
    act.setB(Brel)
    control.addActuatorPtr(act, tActuator)

    # Initialization.
    control.initialize(process)
    # This is not working right now
    # eventsManager = s.eventsManager()

    # Matrix for data storage
    dataPlot = empty((3 * (N + 1), outputSize))
    dataPlot[0, 0] = t0
    dataPlot[0, 1] = processDS.x()[0]
    dataPlot[0, 2] = processDS.x()[1]
    dataPlot[0, 3] = act.u()[0]

    # Main loop
    k = 1
    while processSimulation.hasNextEvent():
        if processSimulation.eventsManager().nextEvent().getType() == TD_EVENT:
            processSimulation.computeOneStep()
        dataPlot[k, 0] = processSimulation.nextTime()
        dataPlot[k, 1] = processDS.x()[0]
        dataPlot[k, 2] = processDS.x()[1]
        dataPlot[k, 3] = act.u()[0]
        k += 1
        processSimulation.nextStep()
    #    print processSimulation.nextTime()
    # Resize matrix
    dataPlot.resize(k, outputSize)
# test swig director
# ds.computeMInt(1,x,v)
# ds._mInt.display()
# m=SiconosVector(3)
# ds.computeMInt(1,x,v,m)
# m.display()
# m=np.zeros(3)
# ds.computeMInt(1,x,v,m)
# print m
# raw_input()


# Non-Smooth Dynamical System
#
nsds = NonSmoothDynamicalSystem(t0, T)

# add the dynamical system to the non smooth dynamical system
nsds.insertDynamicalSystem(ds)

#
# Simulation
#

# (1) OneStepIntegrators
OSI = MoreauJeanOSI(theta)

# (2) Time discretisation --
t = TimeDiscretisation(t0, h)

# (3) one step non smooth problem
Esempio n. 12
0
B = [[0.0], [0.0], [1.0]]

LTIRRelayOscillator = FirstOrderLinearTIR(C, B)
LTIRRelayOscillator.setDPtr(D)

nslaw = RelayNSL(1)
InterRelayOscillator = Interaction(nslaw, LTIRRelayOscillator)

#
# Model
#
RelayOscillator = Model(t0, T, Modeltitle)

#   add the dynamical system in the non smooth dynamical system
myNSDS = NonSmoothDynamicalSystem()
myNSDS.insertDynamicalSystem(LSRelayOscillator)

#   link the interaction and the dynamical system
myNSDS.link(InterRelayOscillator, LSRelayOscillator)

RelayOscillator.setNonSmoothDynamicalSystemPtr(myNSDS)

#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
aOSI = EulerMoreauOSI(theta)
# (2) Time discretisation
Esempio n. 13
0
def test_smc1():
    from siconos.kernel import FirstOrderLinearDS, NonSmoothDynamicalSystem, TimeDiscretisation, \
        TimeStepping, ZeroOrderHoldOSI, TD_EVENT
    from siconos.control.simulation import ControlManager
    from siconos.control.sensor import LinearSensor
    from siconos.control.controller import LinearSMCOT2
    from numpy import eye, empty, zeros
    import numpy as np
    from math import ceil, sin

    # Derive our own version of FirstOrderLinearDS
    class MyFOLDS(FirstOrderLinearDS):
        def computeb(self, time):
            t = sin(50*time)
            # XXX fix this !
            u = [t, -t]
            self.setbPtr(u)

    # variable declaration
    ndof = 2   # Number of degrees of freedom of your system
    t0 = 0.0   # start time
    T = 1    # end time
    h = 1.0e-4  # time step for simulation
    hControl = 1.0e-2  # time step for control
    Xinit = 1.0  # initial position
    N = int(ceil((T-t0)/h + 10))  # number of time steps
    outputSize = 4  # number of variable to store at each time step

    # Matrix declaration
    A = zeros((ndof, ndof))
    x0 = [Xinit, -Xinit]
    Brel = np.array([[0], [1]])
    sensorC = eye(ndof)
    sensorD = zeros((ndof, ndof))
    Csurface = [[0, 1.0]]

    # Simple check
    if h > hControl:
        print("hControl must be bigger than h")
        exit(1)

    # Declaration of the Dynamical System
    processDS = MyFOLDS(x0, A)
    # XXX b is not automatically created ...
#    processDS.setb([0, 0])
    # Model
    process = NonSmoothDynamicalSystem(t0, T)
    process.insertDynamicalSystem(processDS)
    # time discretization
    processTD = TimeDiscretisation(t0, h)
    tSensor = TimeDiscretisation(t0, hControl)
    tActuator = TimeDiscretisation(t0, hControl)
    # Creation of the Simulation
    processSimulation = TimeStepping(process,processTD, 0)
    processSimulation.setName("plant simulation")

    # Declaration of the integrator
    processIntegrator = ZeroOrderHoldOSI()
    processSimulation.associate(processIntegrator, processDS)
    # Actuator, Sensor & ControlManager
    control = ControlManager(processSimulation)
    sens = LinearSensor(processDS, sensorC, sensorD)

    control.addSensorPtr(sens, tSensor)
    act = LinearSMCOT2(sens)
    act.setCsurface(Csurface)
    act.setB(Brel)
    control.addActuatorPtr(act, tActuator)

    # Initialization.
    control.initialize(process)
    # This is not working right now
    # eventsManager = s.eventsManager()

    # Matrix for data storage
    dataPlot = empty((3*(N+1), outputSize))
    dataPlot[0, 0] = t0
    dataPlot[0, 1] = processDS.x()[0]
    dataPlot[0, 2] = processDS.x()[1]
    dataPlot[0, 3] = act.u()[0]

    # Main loop
    k = 1
    while processSimulation.hasNextEvent():
        if processSimulation.eventsManager().nextEvent().getType() == TD_EVENT:
            processSimulation.computeOneStep()
        dataPlot[k, 0] = processSimulation.nextTime()
        dataPlot[k, 1] = processDS.x()[0]
        dataPlot[k, 2] = processDS.x()[1]
        dataPlot[k, 3] = act.u()[0]
        k += 1
        processSimulation.nextStep()
    #    print processSimulation.nextTime()
    # Resize matrix
    dataPlot.resize(k, outputSize)
Esempio n. 14
0
def test_serialization4():
    from siconos.kernel import LagrangianLinearTIDS, NewtonImpactNSL, \
        LagrangianLinearTIR, Interaction, NonSmoothDynamicalSystem, \
        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(nslaw, relation)

    #
    # Model
    #
    first_bouncingBall = NonSmoothDynamicalSystem(t0, T)

    # add the dynamical system to the non smooth dynamical system
    first_bouncingBall.insertDynamicalSystem(ball)

    # link the interaction and the dynamical system
    first_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(first_bouncingBall, t)
    s.insertIntegrator(OSI)
    s.insertNonSmoothProblem(osnspb)

    # end of model definition

    #
    # save and load data from xml and .dat
    #
    from siconos.io.io_base import save, load
    save(s, "bouncingBall.xml")

    s = load("bouncingBall.xml")
    bouncingBall = s.nonSmoothDynamicalSystem()
    ball = bouncingBall.dynamicalSystem(ball.number())
    inter = bouncingBall.interaction(inter.number())

    # the number of time steps
    N = int((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)
Esempio n. 15
0
D = [[1. / Rvalue, 1. / Rvalue, -1., 0.], [1. / Rvalue, 1. / Rvalue, 0., -1.],
     [1., 0., 0., 0.], [0., 1., 0., 0.]]

B = [[0., 0., -1. / Cvalue, 1. / Cvalue], [0., 0., 0., 0.]]

LTIRDiodeBridge = FirstOrderLinearTIR(C, B)
LTIRDiodeBridge.setDPtr(D)

nslaw = ComplementarityConditionNSL(4)
InterDiodeBridge = Interaction(nslaw, LTIRDiodeBridge)

#
# Model
#
DiodeBridge = NonSmoothDynamicalSystem(t0, T)
DiodeBridge.setTitle(Modeltitle)

#   add the dynamical system in the non smooth dynamical system
DiodeBridge.insertDynamicalSystem(LSDiodeBridge)

#   link the interaction and the dynamical system
DiodeBridge.link(InterDiodeBridge, LSDiodeBridge)

#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
gamma = 0.5
Esempio n. 16
0
def test_serialization4():
    from siconos.kernel import LagrangianLinearTIDS, NewtonImpactNSL, \
        LagrangianLinearTIR, Interaction, NonSmoothDynamicalSystem, \
        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(nslaw, relation)

    #
    # Model
    #
    first_bouncingBall = NonSmoothDynamicalSystem(t0, T)

    # add the dynamical system to the non smooth dynamical system
    first_bouncingBall.insertDynamicalSystem(ball)

    # link the interaction and the dynamical system
    first_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(first_bouncingBall, t)
    s.insertIntegrator(OSI)
    s.insertNonSmoothProblem(osnspb)

    # end of model definition

    #
    # save and load data from xml and .dat
    #
    from siconos.io.io_base import save, load
    save(s, "bouncingBall.xml")

    s = load("bouncingBall.xml")
    bouncingBall = s.nonSmoothDynamicalSystem()
    ball = bouncingBall.dynamicalSystem(ball.number())
    inter = bouncingBall.interaction(inter.number())

    # the number of time steps
    N = int((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)
Esempio n. 17
0
C = [[1.0, 0.0, 0.0]]

D = [[0.0]]

B = [[0.0], [0.0], [1.0]]

LTIRRelayOscillator = FirstOrderLinearTIR(C, B)
LTIRRelayOscillator.setDPtr(D)

nslaw = RelayNSL(1)
InterRelayOscillator = Interaction(nslaw, LTIRRelayOscillator)

#
# Model
#
relayOscillator = NonSmoothDynamicalSystem(t0, T)
relayOscillator.setTitle(Modeltitle)
#   add the dynamical system in the non smooth dynamical system
relayOscillator.insertDynamicalSystem(LSRelayOscillator)

#   link the interaction and the dynamical system
relayOscillator.link(InterRelayOscillator, LSRelayOscillator)

#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
aOSI = EulerMoreauOSI(theta)
# (2) Time discretisation
Esempio n. 18
0
t0 = 0.0

print(' -- build dynamical system -- ')

body = LagrangianLinearTIDS(q_0, v_0, M)
body.setKPtr(K)

applied_force = np.zeros(n_dof)
applied_force[n_dof - 1] = 1.
body.setFExtPtr(applied_force)

# -------------
# --- Model ---
# -------------
impactingBar = NonSmoothDynamicalSystem(t0, T)

# add the dynamical system in the non smooth dynamical system
impactingBar.insertDynamicalSystem(body)

# link the interaction and the dynamical system
#impactingBar.link(inter,bar);

# ------------------
# --- Simulation ---
# ------------------

theta = 0.5
h = 0.01
# -- (1) OneStepIntegrators --
OSI = MoreauJeanOSI(theta, 0.5)
Esempio n. 19
0
weight = np.full((nDof),-g*rho*S/l)
bar.setFExtPtr(weight)

e=0.0

H = np.zeros((1,nDof))
H[0,0]=1.

nslaw = NewtonImpactNSL(e)
relation = LagrangianLinearTIR(H)
inter = Interaction(nslaw, relation)

# -------------
# --- Model ---
# -------------
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)
Esempio n. 20
0
def test_diode_bridge():
    """Build diode bridge model"""
    # dynamical system
    bridge_ds = FirstOrderLinearDS(init_state, A)
    # interaction
    diode_bridge_relation = FirstOrderLinearTIR(C, B)
    diode_bridge_relation.setDPtr(D)

    nslaw = ComplementarityConditionNSL(4)
    bridge_interaction = Interaction(nslaw, diode_bridge_relation)

    # Model
    diode_bridge = NonSmoothDynamicalSystem(t0, total_time)
    diode_bridge.setTitle(model_title)
    #  add the dynamical system in the non smooth dynamical system
    diode_bridge.insertDynamicalSystem(bridge_ds)

    #   link the interaction and the dynamical system
    diode_bridge.link(bridge_interaction, bridge_ds)

    # Simulation

    # (1) OneStepIntegrators
    theta = 0.5
    integrator = EulerMoreauOSI(theta)
    # (2) Time discretisation
    time_discretisation = TimeDiscretisation(t0, time_step)

    # (3) Non smooth problem
    non_smooth_problem = LCP()

    # (4) Simulation setup with (1) (2) (3)
    bridge_simulation = TimeStepping(diode_bridge,time_discretisation,
                                     integrator, non_smooth_problem)


    k = 0
    h = bridge_simulation.timeStep()
    # Number of time steps
    N = int((total_time - t0) / h)

    # Get the values to be plotted
    # ->saved in a matrix dataPlot
    data_plot = empty([N, 8])

    x = bridge_ds.x()
    print("Initial state : ", x)
    y = bridge_interaction.y(0)
    print("First y : ", y)
    lambda_ = bridge_interaction.lambda_(0)

    # For the initial time step:
    # time
    data_plot[k, 0] = t0

    #  inductor voltage
    data_plot[k, 1] = x[0]

    # inductor current
    data_plot[k, 2] = x[1]

    # diode R1 current
    data_plot[k, 3] = y[0]

    # diode R1 voltage
    data_plot[k, 4] = - lambda_[0]

    # diode F2 voltage
    data_plot[k, 5] = - lambda_[1]

    # diode F1 current
    data_plot[k, 6] = lambda_[2]

    # resistor current
    data_plot[k, 7] = y[0] + lambda_[2]

    k += 1
    while k < N:
        bridge_simulation.computeOneStep()
        #non_smooth_problem.display()
        data_plot[k, 0] = bridge_simulation.nextTime()
        #  inductor voltage
        data_plot[k, 1] = x[0]
        # inductor current
        data_plot[k, 2] = x[1]
        # diode R1 current
        data_plot[k, 3] = y[0]
        # diode R1 voltage
        data_plot[k, 4] = - lambda_[0]
        # diode F2 voltage
        data_plot[k, 5] = - lambda_[1]
        # diode F1 current
        data_plot[k, 6] = lambda_[2]
        # resistor current
        data_plot[k, 7] = y[0] + lambda_[2]
        k += 1
        bridge_simulation.nextStep()

    #
    # comparison with the reference file
    #
    ref = getMatrix(SimpleMatrix(os.path.join(working_dir,
                                              "data/diode_bridge.ref")))
    assert norm(data_plot - ref) < 1e-12
    return ref, data_plot