示例#1
0
def calculate__one_dimensional__wave_equation__boundary_task(animation_plot, coef, y__x_tzero, dydt__x_tzero, external_influences, \
        boundary_function__xzero, boundary_function__xeql):

    y__x_tzero = calculate(y__x_tzero)
    dydt__x_tzero = calculate(dydt__x_tzero)
    external_influences = calculate(external_influences)
    sqrt_coef = coef**0.5

    def function(x, t, y_previous, y):
        n = len(x) - 1
        dx = x[1] - x[0]
        dt = 0.05
        gamma2 = (dt / dx * sqrt_coef)**2

        if y is None:
            y = [0] * (n + 1)
            for i in range(0, n + 1):
                y[i] = y__x_tzero(x[i],
                                  t) + dt**2 * external_influences(x[i], t)
            return y

        if y_previous is not None:
            y_next = [0] * (n + 1)
            for i in range(1, n):
                y_next[i] = 2 * y[i] - y_previous[i] + \
                                 gamma2 * (y[i + 1] - 2 * y[i] + y[i - 1]) + \
                                 dt ** 2 * external_influences(x[i], t)
        else:
            y_next = [0] * (n + 1)
            for i in range(1, n):
                y_next[i] = y[i] + \
                                 gamma2 / 2 * (y[i + 1] - 2 * y[i] + y[i - 1]) + \
                                 dt * dydt__x_tzero(x[i], t) + \
                                 dt ** 2 / 2 * external_influences(x[i], t)

        y_next[0] = boundary_function__xzero(x[0], t, dt, y[0])
        y_next[n] = boundary_function__xeql(x[n], t, dt, y[n])

        return y_next

    animation_plot.clean_result_part()
    y_previous = y = None

    for t in animation_plot.get_t():
        animation_plot.y.append(
            function(animation_plot.get_x(), t, y_previous, y))
        y_previous, y = y, animation_plot.y[-1]

    return animation_plot
示例#2
0
def get_first_boundary_function(y__x_t):
    y__x_t = calculate(y__x_t)

    def foo(x, t, dt, y):
        return y__x_t(x, t)

    return foo
示例#3
0
def get_second_boundary_function(dydx__x_t):
    dydx__x_t = calculate(dydx__x_t)

    def foo(x, t, dt, y):
        return dydx__x_t(x, t) * dt + y

    return foo
示例#4
0
def get_third_boundary_function(a__x, b__x, third_boundary_function__x):
    third_boundary_function__x = calculate(third_boundary_function__x)

    def foo(x, t, dt, y):
        return (third_boundary_function__x(x, t) * dt + y) / \
                (dt * a__x + b__x)

    return foo
示例#5
0
def calculate__one_dimensional__heat_equation__cauchy(animation_plot, coef,
                                                      y__x_tzero,
                                                      external_influences):

    y__x_tzero = calculate(y__x_tzero)
    external_influences = calculate(external_influences)
    sqrt_coef = coef**0.5

    def function(x, t, y):
        y_next = None
        n = len(x) - 1
        dx = x[1] - x[0]
        dt = 0.05
        gamma2 = dt * (1. / dx * sqrt_coef)**2

        if y is None:
            y = [0] * (n + 1)
            for i in range(0, n + 1):
                y[i] = y__x_tzero(x[i], t) + dt * external_influences(x[i], t)
            return y

        y_next = [0] * (n + 1)
        for i in range(1, n):
            y_next[i] = y[i] + \
                             gamma2 * (y[i + 1] - 2 * y[i] + y[i - 1]) + \
                             dt * external_influences(x[i], t)

        i = 0
        y_next[0] = y_next[1]

        i = n
        y_next[n] = y_next[n - 1]

        y = y_next
        return y_next

    animation_plot.clean_result_part()
    y = None
    for t in animation_plot.get_t():
        y = function(animation_plot.get_x(), t, y)
        animation_plot.y.append(y)

    return animation_plot
示例#6
0
def gui_main_one_dimensional__heat_equation__homogeneous(
        animation_plot, coef, y__x_tzero):
    function = calculate(
        one_dimensional__heat_equation__homogeneous(coef, y__x_tzero))

    animation_plot.clean_result_part()
    for t in animation_plot.get_t():
        next_y = function(animation_plot.get_x(), t)
        animation_plot.y.append(next_y)

    return animation_plot
示例#7
0
def gui_main_one_dimensional__wave_equation__homogeneous(
        animation_plot, coef, y__x_tzero, dydt__x_tzero):
    coef, y__x_tzero, dydt__x_tzero = input_to_sympy(coef, y__x_tzero,
                                                     dydt__x_tzero)
    function = calculate(
        one_dimensional__wave_equation__homogeneous(coef, y__x_tzero,
                                                    dydt__x_tzero))

    animation_plot.clean_result_part()
    for t in animation_plot.get_t():
        animation_plot.y.append(function(animation_plot.get_x(), t))

    return animation_plot