Ejemplo n.º 1
0
def setup_sinusodial():
    # sinusodial test signal:
    s = State()
    y, my, mdy = symbols("y, my, mdy")
    s[my]  = dda.neg(y)
    s[y]   = dda.int(mdy, dt, 0)
    s[mdy] = dda.int(my, dt, 1)
    s[diff_in]     = y # diff_in = cos(t)
    s[diff_out]    = dda.neg(dda.diff(diff_in, dt, 0)) #  0 = sin(0)
    s[int_out]     = dda.neg(dda.int(diff_in, dt, +1)) # -1 = cos(0), but negated
    return s
from dda import State, symbols, dda

diff_in, diff_out, diff_loop = symbols("diff_in, diff_out, diff_loop")
s = State()
dt = 0.05
t_final = 10

alpha = 0.9
ic = 0

# test signal:
#s[diff_in]        = dda.int(dda.int(1, dt, 0), dt, 0)   # diff_in = t^2

# sinusodial test signal:
y, my, mdy = symbols("y, my, mdy")
s[my] = dda.neg(y)
s[y] = dda.int(mdy, dt, 0)
s[mdy] = dda.int(my, dt, 1)

s[diff_in] = y  # diff_in = cos(t)

s[diff_out] = dda.neg(dda.sum(diff_in, diff_loop, dda.mult(alpha, diff_out)))
s[diff_loop] = dda.int(diff_out, dt, ic)

data = s.export(to="CppSolver").run(max_iterations=t_final / dt,
                                    rk_order=4).as_recarray()
xtime = np.arange(0, t_final, dt)
assert len(data) == len(xtime)

from matplotlib.pylab import *
ion()
Ejemplo n.º 3
0

import numpy as np
from dda import State, symbols, dda

ddy, y, mdy, my, lu, ld, y2, y2ohne = symbols("ddy, y, mdy, my, lu, ld, y2, y2ohne")
s = State()
dt = 0.1
t_final = 50

err = 0.5

ic_y   = 1.0
ic_mdy = 0.0

s[my]  = dda.neg(y)
s[y]   = dda.int(lu, mdy, ld, dda.mult(err,my), dt, ic_y)
s[mdy] = dda.int(my, dt, ic_mdy) # my = ddy

s[lu]  = dda.mult(1, dda.dead_upper(y, +1))
s[ld]  = dda.mult(1, dda.dead_lower(y, -1))

# count zero crossings:
ys, yd, yi = symbols("ys, yd, yi")
s[ys]  = dda.sign(y)
s[yd]  = dda.max(0, dda.min(1, dda.diff(ys, dt, 0)))
s[yi]  = dda.neg(dda.int(dda.mult(yd,1/dt), dt, 0))

# Frequenzverdopplung ohne linearem Offset
s[y2]  = dda.mult(y,y)
s[y2ohne] = dda.diff(y2, dt, 0)
Ejemplo n.º 4
0
def setup_polynomial():
    s = State()
    s[diff_in]        = dda.mult(2,dda.int(dda.int(1, dt, 0), dt, 0))   # diff_in = 2*int(1) = t^2
    s[diff_out]       = dda.neg(dda.diff(diff_in, dt, 0))  # 2*t
    s[int_diff]       = dda.neg(dda.int(diff_out, dt, 0)) # t^2 but with increasing deviations due to dt
    return s
Ejemplo n.º 5
0
from dda import State, symbols, dda

diff_in, diff_out, diff_loop  = symbols("diff_in, diff_out, diff_loop")
s = State()
dt = 0.01
t_final = 5

alpha  = 0.9
ic     = 0

# test signal:
#s[diff_in]        = dda.int(dda.int(1, dt, 0), dt, 0)   # diff_in = t^2

# sinusodial test signal:
y, my, mdy = symbols("y, my, mdy")
s[my]  = dda.neg(y)
s[y]   = dda.int(mdy, dt, 0)
s[mdy] = dda.int(my, dt, 1)

s[diff_in]  = y # diff_in = cos(t)

s[diff_out] = dda.diff(diff_in, dt, 0)



from dda.cpp_exporter import compile, run
compile(s.export(to="C"))
data = run(arguments={'max_iterations': t_final / dt, "rk_order": 4} )# return_recarray=True)
xtime = np.arange(0, t_final, dt)
assert len(data) == len(xtime)