Esempio n. 1
0
def test_first_order_ltids():
    """Build and test first order linear
    and time-invariant coeff. ds
    """
    time = 1.2
    ds_list = []
    b_vec = np.random.random((nn, ))
    ds_list.append(sk.FirstOrderLinearTIDS(x0, a_mat))
    ds_list.append(sk.FirstOrderLinearTIDS(x0, a_mat, b_vec))

    for ds in ds_list:
        assert ds.isLinear()
        assert ds.dimension() == nn
        assert np.allclose(ds.x0(), x0)
        assert np.allclose(ds.x(), x0)
        assert np.allclose(ds.r(), 0.)

        rhs = np.dot(a_mat, ds.x())
        if ds.b() is not None:
            rhs += ds.b()
        ds.initRhs(time)
        assert np.allclose(rhs, ds.rhs())
        assert np.allclose(ds.jacobianRhsx(), a_mat)
        assert np.allclose(ds.jacobianRhsx(), ds.jacobianfx())
Esempio n. 2
0
def compute_dt_matrices(A, B, h, TV=False):
    # variable declaration
    t0 = 0.0  # start time
    T = 1  # end time
    n, m = B.shape

    # Matrix declaration
    x0 = np.random.random(n)
    Csurface = np.random.random((m, n))

    # Declaration of the Dynamical System
    if TV:
        process_ds = SK.FirstOrderLinearDS(x0, A)
    else:
        process_ds = SK.FirstOrderLinearTIDS(x0, A)
    # Model
    process = SK.Model(t0, T)
    process.nonSmoothDynamicalSystem().insertDynamicalSystem(process_ds)
    # time discretisation
    process_time_discretisation = SK.TimeDiscretisation(t0, h)
    # Creation of the Simulation
    process_simu = SK.TimeStepping(process_time_discretisation, 0)
    process_simu.setName("plant simulation")
    # Declaration of the integrator
    process_integrator = SK.ZeroOrderHoldOSI()
    process_integrator.insertDynamicalSystem(process_ds)
    process_simu.insertIntegrator(process_integrator)

    rel = SK.FirstOrderLinearTIR(Csurface, B)
    nslaw = SK.RelayNSL(m)
    inter = SK.Interaction(m, nslaw, rel)

    #process.nonSmoothDynamicalSystem().insertInteraction(inter, True)
    process.nonSmoothDynamicalSystem().link(inter, process_ds)
    process.nonSmoothDynamicalSystem().setControlProperty(inter, True)
    # Initialization
    process.initialize(process_simu)

    # Main loop
    process_simu.computeOneStep()
    Ad = SK.getMatrix(process_integrator.Ad(process_ds)).copy()
    Bd = SK.getMatrix(process_integrator.Bd(process_ds)).copy()

    return (Ad, Bd)
Esempio n. 3
0
h = 0.05  # time step
xFinal = 0.0  # target position
theta = 0.5
N = int((T - t0) / h + 10)  # number of time steps
outputSize = 5  # number of variable to store at each time step

# Matrix declaration
A = zeros((2, 2))
A[0, 1] = 1
B = [[0], [1]]
x0 = [10., 10.]
C = [[1., 0]]  # we have to specify ndmin=2, so it's understood as
K = [.25, .125, 2]

# Declaration of the Dynamical System
doubleIntegrator = sk.FirstOrderLinearTIDS(x0, A)
# Model
process = sk.Model(t0, T)
process.nonSmoothDynamicalSystem().insertDynamicalSystem(doubleIntegrator)
# Declaration of the integrator
OSI = sk.EulerMoreauOSI(theta)
# time discretisation
t = sk.TimeDiscretisation(t0, h)
tSensor = sk.TimeDiscretisation(t0, h)
tActuator = sk.TimeDiscretisation(t0, h)
s = sk.TimeStepping(t, 0)
s.insertIntegrator(OSI)

# Actuator, Sensor & ControlManager
control = ControlManager(s)
sens = LinearSensor(doubleIntegrator, C)
Esempio n. 4
0
A[ndof - 1, ndof - 1] *= 0.5
# extra-diag values
for i in xrange(1, number_of_cars):
    A[i, i - 1] = A[i - 1, i] = 1. / (R * C)
    A[i, i + number_of_cars - 1] = A[i - 1, i + number_of_cars] = 1. / (R * C)
    A[i + number_of_cars, i - 1] = A[i + number_of_cars - 1, i] = 1. / (R * D)
    A[i + number_of_cars, i + number_of_cars - 1] = 1. / (R * D)
    A[i + number_of_cars - 1, i + number_of_cars] = 1. / (R * D)

b = np.zeros(ndof, np.float64)
b[0] = w0 / (R * C)
b[number_of_cars - 1] = -jn / C
b[number_of_cars] = w0 / (R * D)
b[ndof - 1] = -jn / D

RC = sk.FirstOrderLinearTIDS(q0, A, b)

# -- Interaction --
# *** Linear time invariant relation (LTIR) ***
# y = N.q + M.x and r = B.x
# y = [ -h_1 ... -h_n ]
# x = [ k_1 ... k_n ]
# + complementarity(x,y)

ninter = number_of_cars
B = np.zeros((ndof, ninter), dtype=np.float64)
np.fill_diagonal(B[number_of_cars:, :number_of_cars], -1. / D)

M = np.zeros((ninter, ninter), dtype=np.float64)
np.fill_diagonal(M[:number_of_cars, :number_of_cars], S)