本文整理汇总了Python中siconos.kernel.TimeStepping.computeOneStep方法的典型用法代码示例。如果您正苦于以下问题:Python TimeStepping.computeOneStep方法的具体用法?Python TimeStepping.computeOneStep怎么用?Python TimeStepping.computeOneStep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类siconos.kernel.TimeStepping
的用法示例。
在下文中一共展示了TimeStepping.computeOneStep方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_serialization4
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
#.........这里部分代码省略.........
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)
示例2:
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
#
# 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
s.nextStep()
#
# comparison with the reference file
#
from siconos.kernel import SimpleMatrix, getMatrix
from numpy.linalg import norm
示例3: empty
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
# 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()
processSimulation.nextStep()
# Resize matrix
dataPlot.resize(k, outputSize)
# Save to disk
savetxt('SMCExampleImplicitOT2-py.dat', dataPlot)
# Plot interesting data
subplot(411)
title('x1')
示例4: print
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
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]
k += 1
if k%1000==0:
print("step =", k, " < ", N)
aTS.nextStep()
示例5: test_diode_bridge
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
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()
#.........这里部分代码省略.........
示例6: test_smc1
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
def test_smc1():
from siconos.kernel import FirstOrderLinearDS, Model, 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.setb(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 = 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 = Model(t0, T)
process.nonSmoothDynamicalSystem().insertDynamicalSystem(processDS)
# time discretization
processTD = TimeDiscretisation(t0, h)
tSensor = TimeDiscretisation(t0, hControl)
tActuator = TimeDiscretisation(t0, hControl)
# Creation of the Simulation
processSimulation = TimeStepping(processTD, 0)
processSimulation.setName("plant simulation")
# Declaration of the integrator
processIntegrator = ZeroOrderHoldOSI()
process.nonSmoothDynamicalSystem().setOSI(processDS, processIntegrator)
processSimulation.insertIntegrator(processIntegrator)
# 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.
process.initialize(processSimulation)
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)
示例7: test_diodebridge1
# 需要导入模块: from siconos.kernel import TimeStepping [as 别名]
# 或者: from siconos.kernel.TimeStepping import computeOneStep [as 别名]
#.........这里部分代码省略.........
#
# 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