예제 #1
0
#TODO python <- SICONOS_RELAY_LEMKE
# access dparam

osnspb = Relay()
s.insertNonSmoothProblem(osnspb)
s.setComputeResiduY(True)
s.setComputeResiduR(True)
s.setNewtonMaxIteration(30)
s.setNewtonTolerance(1e-14)

# matrix to save data
dataPlot = empty((N + 1, 5))
control = empty((N + 1, ))
dataPlot[0, 0] = t0
dataPlot[0, 1:3] = process.x()
dataPlot[0, 3] = myProcessInteraction.lambda_(0)[0]
dataPlot[0, 4] = myProcessInteraction.lambda_(0)[1]
# time loop
k = 1
while (s.hasNextEvent()):
    s.advanceToEvent()
    dataPlot[k, 0] = s.nextTime()
    dataPlot[k, 1] = process.x()[0]
    dataPlot[k, 2] = process.x()[1]
    dataPlot[k, 3] = myProcessInteraction.lambda_(0)[0]
    dataPlot[k, 4] = myProcessInteraction.lambda_(0)[1]
    control[k] = process.r()[1]
    k += 1
    s.nextStep()
    #print s.nextTime()
예제 #2
0
#

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

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

from numpy import empty
dataPlot = empty([N + 1, 8])

x = LSRelayOscillator.x()
print("Initial state : ", x)
y = InterRelayOscillator.y(0)
print("First y : ", y)
lambda_ = InterRelayOscillator.lambda_(0)

while (k < N):
    aTS.computeOneStep()
    #aLCP.display()
    dataPlot[k, 0] = aTS.nextTime()
    #  inductor voltage
    dataPlot[k, 1] = x[0]
    dataPlot[k, 2] = x[1]
    dataPlot[k, 3] = x[2]
    dataPlot[k, 4] = y[0]
    dataPlot[k, 5] = lambda_[0]
예제 #3
0
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

from numpy import zeros
dataPlot = zeros([N, 10])

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

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

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

# diode R1 current
예제 #4
0
#TODO python <- SICONOS_RELAY_LEMKE
# access dparam

osnspb = Relay()
s.insertNonSmoothProblem(osnspb)
s.setComputeResiduY(True)
s.setComputeResiduR(True)

filippov.initialize(s);

# matrix to save data
dataPlot = empty((N+1,5))
control = empty((N+1,))
dataPlot[0, 0] = t0
dataPlot[0, 1:3] = process.x()
dataPlot[0, 3] = myProcessInteraction.lambda_(0)[0]
dataPlot[0, 4] = myProcessInteraction.lambda_(0)[1]
# time loop
k = 1
while(s.hasNextEvent()):
     s.newtonSolve(1e-14, 30)
     dataPlot[k, 0] = s.nextTime()
     dataPlot[k, 1] = process.x()[0]
     dataPlot[k, 2] = process.x()[1]
     dataPlot[k, 3] = myProcessInteraction.lambda_(0)[0]
     dataPlot[k, 4] = myProcessInteraction.lambda_(0)[1]
     control[k] = process.r()[1]
     k += 1
     s.nextStep()
     #print s.nextTime()
예제 #5
0
act = LinearSMCOT2(tActuator, processDS)
act.setCsurfacePtr(Csurface)
act.addSensorPtr(sens)
control.addActuatorPtr(act)

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

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

# Main loop
k = 1
while(processSimulation.hasNextEvent()):
    processSimulation.computeOneStep()
    dataPlot[k, 0] = processSimulation.nextTime()
    dataPlot[k, 1] = processDS.x()[0]
    dataPlot[k, 2] = processDS.x()[1]
    dataPlot[k, 3] = processDS.z()[0]
    dataPlot[k, 4] = processDS.z()[1]
    k += 1
    print processSimulation.nextTime()
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

from numpy import zeros
dataPlot = zeros([N, 10])

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

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

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

# diode R1 current
예제 #7
0
RelayOscillator.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

from numpy import empty
dataPlot = empty([N+1,8])

x = LSRelayOscillator.x()
print("Initial state : ",x)
y = InterRelayOscillator.y(0)
print("First y : ",y)
lambda_ = InterRelayOscillator.lambda_(0)

while (k < N):
    aTS.computeOneStep()
    #aLCP.display()
    dataPlot[k, 0] = aTS.nextTime()
    #  inductor voltage
    dataPlot[k, 1] = x[0]
    dataPlot[k, 2] = x[1]
    dataPlot[k, 3] = x[2]
    dataPlot[k, 4] = y[0]
    dataPlot[k, 5] = lambda_[0]
DiodeBridgeCapFilter.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

from numpy import zeros
dataPlot = zeros([N-1, 10])

x = LS1DiodeBridgeCapFilter.x()
print "Initial state : ", x
y = InterDiodeBridgeCapFilter.y(0)
print "First y : ", y
lambda_ = InterDiodeBridgeCapFilter.lambda_(0)

# For the initial time step:
# time

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

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

# diode R1 current
예제 #9
0
파일: CircuitRLCD.py 프로젝트: xhub/siconos
CircuitRLCD.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

from numpy import zeros
dataPlot = zeros([N+1, 6])

x = LSCircuitRLCD.x()
print "Initial state : ", x
y = InterCircuitRLCD.y(0)
print "First y : ", y
lambda_ = InterCircuitRLCD.lambda_(0)

# For the initial time step:
# time

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

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

# diode voltage
예제 #10
0
#

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

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

from numpy import zeros
dataPlot = zeros([N - 1, 10])

x = LS1DiodeBridgeCapFilter.x()
print("Initial state : ", x)
y = InterDiodeBridgeCapFilter.y(0)
print("First y : ", y)
lambda_ = InterDiodeBridgeCapFilter.lambda_(0)

# For the initial time step:
# time

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

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

# diode R1 current
예제 #11
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
예제 #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)
    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
예제 #13
0
CircuitRLCD.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

from numpy import zeros
dataPlot = zeros([N + 1, 6])

x = LSCircuitRLCD.x()
print("Initial state : ", x)
y = InterCircuitRLCD.y(0)
print("First y : ", y)
lambda_ = InterCircuitRLCD.lambda_(0)

# For the initial time step:
# time

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

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

# diode voltage
예제 #14
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