Example #1
0
def test_est_2dkernel():
    """example from Harsha."""
    x, xi, xj = symbols('x xi xj')
    y, yi, yj = symbols('y yi yj')

    X = Tuple(x, y)
    Xi = Tuple(xi, yi)
    Xj = Tuple(xj, yj)

    u = Unknown('u')

    phi = Constant('phi')
    theta = Constant('theta')

    expr = phi * u + dx(u) + dy(dy(u))

    print('> generic_kernel := ', expand(generic_kernel(expr, u, (Xi, Xj))))
    print('')

    kuu = theta * exp(-0.5 * ((xi - xj)**2 + (yi - yj)**2))

    kuf = compute_kernel(expr, kuu, Xi)
    kfu = compute_kernel(expr, kuu, Xj)
    kff = compute_kernel(expr, kuu, (Xi, Xj))

    print('> kuf := ', kuf)
    print('> kfu := ', kfu)
    print('> kff := ', kff)
Example #2
0
def test_2d():
    x, xi, xj = symbols('x xi xj')
    y, yi, yj = symbols('y yi yj')

    X = Tuple(x, y)
    Xi = Tuple(xi, yi)
    Xj = Tuple(xj, yj)

    u = Unknown('u')

    alpha = Constant('alpha')
    beta = Constant('beta')
    mu = Constant('mu')
    nu = Constant('nu')
    zeta = Constant('zeta')
    theta = Constant('theta')

    #    expr = alpha * u
    #    expr = alpha * dx(u)
    #    expr = alpha * dy(u)
    #    expr = alpha * u + beta * dx(u)
    #    expr = alpha * u + beta * dy(u)
    #    expr = mu * u + alpha * dx(u) + beta * dx(dx(u))
    #    expr = mu * u + alpha * dx(u) + beta * dy(dy(u))
    expr = mu * u + alpha * dx(u) + beta * dx(dx(u)) + nu * dy(
        dy(u)) + zeta * dx(dy(u))

    #    print('> generic_kernel := ', expand(generic_kernel(expr, u, Xi)))
    #    print('> generic_kernel := ', expand(generic_kernel(expr, u, Xj)))
    print('> generic_kernel := ', expand(generic_kernel(expr, u, (Xi, Xj))))
Example #3
0
def test_generic_kernel_3d():
    x, xi, xj = symbols('x xi xj')
    y, yi, yj = symbols('y yi yj')
    z, zi, zj = symbols('z zi zj')

    X = Tuple(x, y, z)
    Xi = Tuple(xi, yi, zi)
    Xj = Tuple(xj, yj, zj)

    u = Unknown('u')

    # ... testing u
    assert (generic_kernel(u, u, xi) == Function('u')(xi))
    assert (generic_kernel(u, u, xj) == Function('u')(xj))
    assert (generic_kernel(u, u, (xi, xj)) == Function('u')(xi, xj))
    # ...

    # ... testing dx(u)
    assert (generic_kernel(dx(u), u, Xi) == Derivative(Function('u')(*Xi), xi))

    assert (generic_kernel(dx(u), u, Xj) == Derivative(Function('u')(*Xj), xj))

    assert (generic_kernel(dx(u), u, (Xi, Xj)) == Derivative(
        Function('u')(*Xi, *Xj), xi, xj))
    # ...

    # ... testing dy(u)
    assert (generic_kernel(dy(u), u, Xi) == Derivative(Function('u')(*Xi), yi))

    assert (generic_kernel(dy(u), u, Xj) == Derivative(Function('u')(*Xj), yj))

    assert (generic_kernel(dy(u), u, (Xi, Xj)) == Derivative(
        Function('u')(*Xi, *Xj), yi, yj))
    # ...

    # ... testing dz(u)
    assert (generic_kernel(dz(u), u, Xi) == Derivative(Function('u')(*Xi), zi))

    assert (generic_kernel(dz(u), u, Xj) == Derivative(Function('u')(*Xj), zj))

    assert (generic_kernel(dz(u), u, (Xi, Xj)) == Derivative(
        Function('u')(*Xi, *Xj), zi, zj))
    # ...

    # ... testing dx(dx(u))
    assert (generic_kernel(dx(dx(u)), u,
                           Xi) == Derivative(Function('u')(*Xi), xi, xi))

    assert (generic_kernel(dx(dx(u)), u,
                           Xj) == Derivative(Function('u')(*Xj), xj, xj))

    assert (generic_kernel(dx(dx(u)), u, (Xi, Xj)) == Derivative(
        Function('u')(*Xi, *Xj), xi, xi, xj, xj))