Beispiel #1
0
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)
s.setComputeResiduR(True)
s.setNewtonMaxIteration(30)
s.setNewtonTolerance(1e-14)

# matrix to save data
dataPlot = empty((N + 1, 5))
control = empty((N + 1, ))
#
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
aTiDisc = TimeDiscretisation(t0, h_step)

# (3) Non smooth problem
aRelay = Relay()

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

# end of model definition

#
# computation
#
Beispiel #3
0
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
gamma = 0.5
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.insertDynamicalSystem(LSDiodeBridge)
#aOSI.setUseGammaForRelation(True)

# (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

#
Beispiel #4
0
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)
aOSI.insertDynamicalSystem(LSRelayOscillator)
# (2) Time discretisation
aTiDisc = TimeDiscretisation(t0,h_step)

# (3) Non smooth problem
aRelay = Relay()

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

# end of model definition

#
# computation
#
Beispiel #5
0
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
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.setUseGammaForRelation(True)

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

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

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

# end of model definition

#
# computation
Beispiel #6
0
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)


#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
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
gamma = 0.5
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.insertDynamicalSystem(LSDiodeBridge)
#aOSI.setUseGammaForRelation(True)

# (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

#
Beispiel #8
0
#
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) OneStepIntegrators
theta = 0.5
aOSI = EulerMoreauOSI(theta)
aOSI.insertDynamicalSystem(LSCircuitRLCD)

# (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
Beispiel #9
0
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
gamma = 0.5
aOSI = EulerMoreauOSI(theta, gamma)
#aOSI.setUseGammaForRelation(True)

# (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
DiodeBridgeCapFilter.nonSmoothDynamicalSystem().insertDynamicalSystem(
    LS2DiodeBridgeCapFilter)

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

#
# Simulation
#

# (1) OneStepIntegrators
theta = 0.5
gamma = 1.0
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.insertDynamicalSystem(LS1DiodeBridgeCapFilter)
aOSI.insertDynamicalSystem(LS2DiodeBridgeCapFilter)
aOSI.setUseGammaForRelation(True)

# (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
#   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
#

# (1) OneStepIntegrators
theta = 0.5
gamma = 1.0
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.insertDynamicalSystem(LS1DiodeBridgeCapFilter)
aOSI.insertDynamicalSystem(LS2DiodeBridgeCapFilter)
aOSI.setUseGammaForRelation(True)

# (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
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
Beispiel #13
0
#
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) OneStepIntegrators
theta = 0.5
aOSI = EulerMoreauOSI(theta)
aOSI.insertDynamicalSystem(LSCircuitRLCD)

# (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
#   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
#

# (1) OneStepIntegrators
theta = 0.5
gamma = 1.0
aOSI = EulerMoreauOSI(theta, gamma)
aOSI.setUseGammaForRelation(True)

# (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
Beispiel #15
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
Beispiel #16
0
#   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)
aOSI.insertDynamicalSystem(LSRelayOscillator)
# (2) Time discretisation
aTiDisc = TimeDiscretisation(t0, h_step)

# (3) Non smooth problem
aRelay = Relay()

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

# end of model definition

#
# computation
#