Пример #1
0
ball = LagrangianLinearTIDS(x, v, mass)

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

#
# Interactions
#

# ball-floor
H = [[1, 0, 0]]

nslaw = NewtonImpactNSL(e)
relation = LagrangianLinearTIR(H)
inter = Interaction(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
Пример #2
0
#
# Interactions
#

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
#
Пример #3
0
#
# Interactions
#

C = [[0., 0.], [0, 0.], [-1., 0.], [1., 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(4, nslaw, LTIRDiodeBridge, 1)

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

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

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

#
# Simulation
#
Пример #4
0
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)
Пример #5
0
def test_serialization4():
    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
    #
    first_bouncingBall = Model(t0, T)

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

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

    # end of model definition

    #
    # computation
    #

    # simulation initialization
    first_bouncingBall.setSimulation(s)
    first_bouncingBall.initialize()

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

    bouncingBall = load("bouncingBall.xml")

    # 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)
     [-1.,  0.],
     [1.,   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(4, nslaw, LTIRDiodeBridge, 1)
InterDiodeBridge.insert(LSDiodeBridge)

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

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

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

#
# Simulation
Пример #7
0
A = zeros((2,2))
A[0, 1] = 1

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)

Пример #8
0
#
# Interactions
#

C = [[-1.,   0.]]

D = [[Rvalue]]

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

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

nslaw = ComplementarityConditionNSL(1)
InterCircuitRLCD = Interaction(1, nslaw, LTIRCircuitRLCD, 1)


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

#   add the dynamical system in the non smooth dynamical system
CircuitRLCD.nonSmoothDynamicalSystem().insertDynamicalSystem(LSCircuitRLCD)

#   link the interaction and the dynamical system
CircuitRLCD.nonSmoothDynamicalSystem().link(InterCircuitRLCD, LSCircuitRLCD)

#
# Simulation
     [-1.,  0.],
     [1.,   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(4, nslaw, LTIRDiodeBridge, 1)


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

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

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

#
# Simulation
Пример #10
0
# Interactions
#

C = [[0., 0., 1.0], [0, 0., 0.0], [-1., 0., 1.0], [1., 0., 0.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)

#
     [1.,   0., 0.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(4, nslaw, LTIRDiodeBridgeCapFilter, 1)

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

#   add the dynamical system in the non smooth dynamical system
DiodeBridgeCapFilter.nonSmoothDynamicalSystem().insertDynamicalSystem(LS1DiodeBridgeCapFilter)
DiodeBridgeCapFilter.nonSmoothDynamicalSystem().insertDynamicalSystem(LS2DiodeBridgeCapFilter)

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

#
# Simulation
Пример #12
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(4, nslaw, diode_bridge_relation, 1)

    # Model
    diode_bridge = Model(t0, total_time, model_title)

    #  add the dynamical system in the non smooth dynamical system
    diode_bridge.nonSmoothDynamicalSystem().insertDynamicalSystem(bridge_ds)

    #   link the interaction and the dynamical system
    diode_bridge.nonSmoothDynamicalSystem().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(time_discretisation,
                                     integrator, non_smooth_problem)

    # simulation initialization
    diode_bridge.setSimulation(bridge_simulation)
    diode_bridge.initialize()
    k = 0
    h = bridge_simulation.timeStep()
    # Number of time steps
    N = (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
Пример #13
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(4, nslaw, diode_bridge_relation, 1)

    # Model
    diode_bridge = Model(t0, total_time, model_title)

    #  add the dynamical system in the non smooth dynamical system
    diode_bridge.nonSmoothDynamicalSystem().insertDynamicalSystem(bridge_ds)

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

    # Simulation

    # (1) OneStepIntegrators
    theta = 0.5
    integrator = EulerMoreauOSI(theta)
    integrator.insertDynamicalSystem(bridge_ds)

    # (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(time_discretisation, integrator,
                                     non_smooth_problem)

    # simulation initialization
    diode_bridge.initialize(bridge_simulation)
    k = 0
    h = bridge_simulation.timeStep()
    # Number of time steps
    N = (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
Пример #14
0
#
# Interactions
#

C = [[-1., 0.]]

D = [[Rvalue]]

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

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

nslaw = ComplementarityConditionNSL(1)
InterCircuitRLCD = Interaction(1, nslaw, LTIRCircuitRLCD, 1)

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

#   add the dynamical system in the non smooth dynamical system
CircuitRLCD.nonSmoothDynamicalSystem().insertDynamicalSystem(LSCircuitRLCD)

#   link the interaction and the dynamical system
CircuitRLCD.nonSmoothDynamicalSystem().link(InterCircuitRLCD, LSCircuitRLCD)

#
# Simulation
#
Пример #15
0
A = zeros((2, 2))
A[0, 1] = 1

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()
Пример #16
0
# Interactions
#

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(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)
Пример #17
0
bar = LagrangianLinearTIDS(q0,v0,M)
bar.setKPtr(K)
#bar.display()

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 ---
Пример #18
0
def test_diodebridge1():
    from siconos.kernel import FirstOrderLinearDS, FirstOrderLinearTIR, \
                               ComplementarityConditionNSL, Interaction,\
                               Model, EulerMoreauOSI, TimeDiscretisation, LCP,  \
                               TimeStepping
    from numpy import empty
    from siconos.kernel import SimpleMatrix, getMatrix
    from numpy.linalg import norm

    t0 = 0.0
    T = 5.0e-3       # Total simulation time
    h_step = 1.0e-6  # Time step
    Lvalue = 1e-2  # inductance
    Cvalue = 1e-6   # capacitance
    Rvalue = 1e3    # resistance
    Vinit = 10.0    # initial voltage
    Modeltitle = "DiodeBridge"

    #
    # dynamical system
    #

    init_state = [Vinit, 0]

    A = [[0,          -1.0/Cvalue],
         [1.0/Lvalue, 0          ]]

    LSDiodeBridge=FirstOrderLinearDS(init_state, A)

    #
    # Interactions
    #

    C = [[0.,   0.],
         [0,    0.],
         [-1.,  0.],
         [1.,   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)

    LTIRDiodeBridge.display()
    nslaw=ComplementarityConditionNSL(4)
    InterDiodeBridge=Interaction(4, nslaw, LTIRDiodeBridge, 1)


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

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

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

    #
    # Simulation
    #

    # (1) OneStepIntegrators
    theta = 0.5
    aOSI = EulerMoreauOSI(LSDiodeBridge, theta)

    # (2) Time discretisation
    aTiDisc = TimeDiscretisation(t0, h_step)

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

    # (4) Simulation setup with (1) (2) (3)
    aTS = TimeStepping(aTiDisc, aOSI, aLCP)

    # end of model definition

    #
    # computation
    #

    # simulation initialization
    DiodeBridge.initialize(aTS)

    k = 0
    h = aTS.timeStep()
    print("Timestep : ", h)
    # Number of time steps
    N = (T-t0)/h
    print("Number of steps : ", N)

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

    dataPlot = empty([N, 8])

    x = LSDiodeBridge.x()
    print("Initial state : ", x)
    y = InterDiodeBridge.y(0)
    print("First y : ", y)
    lambda_ = InterDiodeBridge.lambda_(0)

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

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

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

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

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

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

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

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

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

    #
    # comparison with the reference file
    #
    ref = getMatrix(SimpleMatrix(os.path.join(working_dir,"data/diode_bridge.ref")))

    print(norm(dataPlot - ref))
    assert (norm(dataPlot - ref) < 1e-12)
    return ref, dataPlot