示例#1
0
def test_autocast():
    dsA = sk.LagrangianDS([0], [0], [[1]])
    dsB = sk.FirstOrderLinearDS([0], [[1]])
    nsds = sk.NonSmoothDynamicalSystem(0, 0)
    nsds.insertDynamicalSystem(dsA)
    nsds.insertDynamicalSystem(dsB)

    assert (type(nsds.dynamicalSystem(dsA.number())) == sk.LagrangianDS)
    assert (type(nsds.dynamicalSystem(dsB.number())) == sk.FirstOrderLinearDS)
示例#2
0
def test_autocast():
    dsA = K.LagrangianDS([0],[0],[[1]])
    dsB = K.FirstOrderLinearDS([0],[[1]])
    model = K.Model(0, 0)
    model.nonSmoothDynamicalSystem().insertDynamicalSystem(dsA)
    model.nonSmoothDynamicalSystem().insertDynamicalSystem(dsB)

    assert(type(model.nonSmoothDynamicalSystem().dynamicalSystem(dsA.number())) == K.LagrangianDS)
    assert(type(model.nonSmoothDynamicalSystem().dynamicalSystem(dsB.number())) == K.FirstOrderLinearDS)
示例#3
0
def test_first_order_lds():
    """Build and test first order linear
    and time-invariant coeff. ds
    """
    ndof = 3
    x0 = np.random.random(ndof)
    time = 1.2
    ds_list = []
    a_mat = np.random.random((ndof, ndof))
    b_vec = np.random.random((ndof, ))
    ds_list.append(sk.FirstOrderLinearDS(x0))
    ds_list.append(sk.FirstOrderLinearDS(x0, a_mat))
    ds_list.append(sk.FirstOrderLinearDS(x0, a_mat, b_vec))

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

        rhs = np.zeros_like(ds.x())
        jac_ref = np.zeros((ndof, ndof), dtype=np.float64)
        if isinstance(ds.A(), np.ndarray):
            jac_ref += a_mat
            rhs += np.dot(a_mat, ds.x())
        if isinstance(ds.b(), np.ndarray):
            rhs += ds.b()
        ds.computef(time, ds.x())
        if ds.f() is not None:
            assert np.allclose(rhs, ds.f())

        ds.initRhs(time)
        assert np.allclose(rhs, ds.rhs())
        if ds.A() is not None:
            assert np.allclose(ds.jacobianRhsx(), jac_ref)
            assert np.allclose(ds.jacobianRhsx(), ds.jacobianfx())
示例#4
0
def test_autocast():
    dsA = sk.LagrangianDS([0], [0], [[1]])
    dsB = sk.FirstOrderLinearDS([0], [[1]])
    nsds = sk.NonSmoothDynamicalSystem(0, 0)
    nsds.insertDynamicalSystem(dsA)
    nsds.insertDynamicalSystem(dsB)

    failed=0
    

    
    if not isinstance(nsds.dynamicalSystem(dsA.number()), sk.LagrangianDS):
        failed = 1
    if not isinstance(nsds.dynamicalSystem(dsB.number()), sk.FirstOrderLinearDS):
        failed = 1

    return failed
示例#5
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)
t0 = 0.0  # start time
T = 1.0  # end time
h = 1.0e-3  # time step
Vinit = 1.0
theta = 0.5
N = int((T - t0) / h)

# Dynamical systems
A = np.zeros((2, 2))
x0 = np.array([Vinit, -Vinit])
B = 2.0 * np.eye(2)
C = np.eye(2)
D = np.zeros((2, 2))

process = sk.FirstOrderLinearDS(x0, A)
process.setComputebFunction('plugins', 'computeB')

# Interactions
myNslaw = sk.RelayNSL(2)
myProcessRelation = sk.FirstOrderLinearR(C, B)
myProcessRelation.setComputeEFunction('plugins', 'computeE')
# myProcessRelation.setDPtr(D)

myProcessInteraction = sk.Interaction(myNslaw, myProcessRelation)

# NSDS
simplerelay = sk.NonSmoothDynamicalSystem(t0, T)
simplerelay.insertDynamicalSystem(process)
simplerelay.link(myProcessInteraction, process)
示例#7
0
withPlot = True
if (withPlot):
    import matplotlib
    matplotlib.use('Agg')
    from matplotlib.pyplot import subplot, title, plot, grid, savefig, show

#
# dynamical system
#
init_state = [-1, 0]

A = np.zeros((2, 2), dtype=np.float64)
A.flat[...] = [0., -1.0 / Cvalue, 1.0 / Lvalue, 0.]

LSCircuitRLCD = sk.FirstOrderLinearDS(init_state, A)

#
# Interactions
#

C = [[-1., 0.]]

D = [[Rvalue]]

B = [[-1. / Cvalue], [0.]]

LTIRCircuitRLCD = sk.FirstOrderLinearTIR(C, B)
LTIRCircuitRLCD.setDPtr(D)

nslaw = sk.ComplementarityConditionNSL(1)
示例#8
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 = np.zeros((2, 2), dtype=np.float64)
A.flat[...] = [0., -1.0 / Cvalue, 1.0 / Lvalue, 0.]

LSDiodeBridge = sk.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 = sk.FirstOrderLinearTIR(C, B)
LTIRDiodeBridge.setDPtr(D)
示例#9
0
rho = 10.0
x00 = rho  # Initial position
x01 = rho
x02 = 0.0
alpha = 0.05  # angle of the square helical
beta = 0.01  # thread of the helical
gamma = 0.  # thread variation

# -- Dynamical system --
# dx / dt = A.x + b + r
A = np.zeros((ndof, ndof), dtype=np.float64)
x0 = np.zeros(3, dtype=np.float64)
x0.flat[...] = [x00, x01, x02]
b = np.zeros_like(x0)
b[2] = beta
particle = sk.FirstOrderLinearDS(x0, A, b)

# -- Interaction --
# y = C.x + D.lambda
# r = B.lambda
ninter = 2
B = np.zeros((ndof, ninter), dtype=np.float64)
B[0, 0] = -alpha * 0.5
B[0, 1] = 1 + alpha * 0.5
B[1, 0] = -B[0, 1]
B[1, 1] = B[0, 0]
B[2, 0] = gamma * 0.5
B[2, 1] = gamma * 0.5

C = np.zeros((ninter, ndof), dtype=np.float64)
C[0, 0] = C[1, 1] = -1.