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
#!/usr/bin/env python3

#
# Differentiation by integration:
#
# This circuit uses the "trick" from page 95ff / section 5.14 from
# Bernds ap2.pdf Book "Analog Computing II"
#

import numpy as np
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)
# This circuit tests the limiting or "self-healing" of an oscillator
# ODE y'' = -y which is contamined with a linear term which should
# result in an exponential answer. Thanks to the limiter, this does
# not happen.
#
# The dead_lower/dead_upper combination models what is typically
# archived with two diodes on an electric level.
#
# This works like a charm!
#


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))
Exemple #4
0
ic_mdy = -np.cos(phase) * norm

# oscillator damping and amplification
D = 0
A = 0

# oscillator frqeuency variation
#FREQS = [ 0.95, 1.00, 1.05  ]
freqvarianz = 1.0

# oscillator gain variation
GAINS = [0.95, 1.00, 1.05]
N = len(GAINS)

ddavars = [[Symbol(f"{x}{n}") for n in range(N)]
           for x in symbols("y, limu, limd, mdy, my")]

for y, limu, limd, mdy, my, gain in zip(*ddavars, GAINS):
    s[y] = dda.mult(
        gain,
        dda.int(dda.mult(freqvarianz, mdy), dda.mult(A, my), limu, limd, dt,
                ic_dy))
    s[limu] = dda.mult(stabilization, dda.dead_upper(y, norm))
    s[limd] = dda.mult(stabilization, dda.dead_lower(y, -norm))
    s[mdy] = dda.int(dda.mult(freqvarianz, my), dda.mult(D, mdy), dt, ic_mdy)
    s[my] = dda.sum(y)

runtime_args = {
    'max_iterations': t_final / dt,
    "rk_order": 3,
    "modulo_write": modulo_write,
"""
This test tests the differentiation capabilities by DDA.

Differentiation stands next to integration in this time
evolution code.

This text is rather lax and does NOT test the exact
validity of the integration, cf. test_exponential_solution.py.
"""

from dda import State, symbols, dda
import dda.cpp_exporter as cpp
# postprocessing:
import numpy as np

diff_in, diff_out, int_diff, int_out  = symbols("diff_in, diff_out, int_diff, int_out")
dt = 0.01
t_final = 5

alpha  = 0.9
ic     = 0


def run(s):
    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)
    
    return xtime, data

def plot_simulation(time, data):
Exemple #6
0
# for further agreements.
# ANABRID_END_LICENSE
#
"""
Roche-Attraktor
"""

from dda import symbols, State
from dda.computing_elements import int, mult, neg
from numpy import *

# numbers of iterations and time step size
iterations = 100_000_000
dt = 0.0005

x, y, z = symbols("x,y,z")
a = [NaN, 5, 2, 0.5, 1, 4, 1]
x0, y0, z0 = -5, 0, 5

state = State()

state[x] = int(mult(a[1], x), neg(mult(mult(a[2], y), z)), dt, x0)
state[y] = int(neg(mult(a[3], y)), mult(mult(a[4], x), z), dt, y0)
state[z] = int(mult(a[5], z), neg(mult(mult(a[6], x), y)), dt, z0)

if 0:
    # solve with naive explicit RK
    results = state.export(to="CppSolver").run(max_iterations=iterations,
                                               modulo_write=300,
                                               binary=True).as_recarray()
else: