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
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) data = s.export(to="CppSolver").run(max_iterations= t_final / dt, rk_order=1).as_recarray() xtime = np.arange(0, t_final, dt) assert len(data) == len(xtime) from matplotlib.pylab import * ion(); clf() #cols = data.dtype.names cols = "y y2 y2ohne".split()
def setup_constant(): s = State() #s[diff_in] = dda.const(1) # TODO: Such an expression does no more work!! s[diff_out] = dda.diff(1, dt, 0) s[int_diff] = dda.int(diff_out, dt, 1) # integrates over 0, should do it. return s
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
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) from matplotlib.pylab import * ion(); clf() #cols = data.dtype.names cols = "diff_in diff_out".split()