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(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
C = eye(2) #C = 1 D = zeros((2,2)) #D = 0 # dynamical systems process = FirstOrderNonLinearDS(x0) process.setComputeFFunction('PluginF', 'computef1') process.setComputeJacobianfxFunction('PluginF', 'computeJacf1') #process = FirstOrderNonLinearDS(x0,'PluginF:computef1','PluginF:computeJacf1' ) process.display() myProcessRelation = FirstOrderLinearTIR(C,B) myProcessRelation.setDPtr = D myNslaw = RelayNSL(2) myNslaw.display() nameInter = 'processInteraction' myProcessInteraction = Interaction(ninter, myNslaw, myProcessRelation) myNSDS = NonSmoothDynamicalSystem() myNSDS.insertDynamicalSystem(process) myNSDS.link(myProcessInteraction,process) filippov = Model(t0,T) filippov.setNonSmoothDynamicalSystemPtr(myNSDS)
# 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) 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
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("diode_bridge.ref")) print(norm(dataPlot - ref)) assert (norm(dataPlot - ref) < 1e-12) return ref, dataPlot
numInter = 2 ninter = 2 theta = 0.5 alpha = .01 N = ceil((T-t0)/h) # matrices A = zeros((2,2)) x0 = array([10.,10.]) B = 500*array([[alpha,1-alpha],[-(1-alpha),alpha]]) C = eye(2) D = zeros((2,2)) # dynamical systems process = FirstOrderLinearDS(x0, A) myProcessRelation = FirstOrderLinearTIR(C,B) myProcessRelation.setDPtr(D) 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)
A = [[0, -1.0/Cvalue], [1.0/Lvalue, 0 ]] LSCircuitRLCD = FirstOrderLinearDS(init_state, A) # # 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
A = [[0, 1.0, 0.0], [0.0, 0.0, 1.0], [0.0, -3.0, -2.0]] LSRelayOscillator = FirstOrderLinearDS(init_state, A) # # 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) InterRelayOscillator.insert(LSRelayOscillator) # # Model # RelayOscillator = Model(t0, T, Modeltitle) # add the dynamical system in the non smooth dynamical system RelayOscillator.nonSmoothDynamicalSystem().insertDynamicalSystem(LSRelayOscillator) # link the interaction and the dynamical system