예제 #1
0
def test_generic_kernel_1d():
    x, xi, xj = symbols('x xi xj')

    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 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))
예제 #2
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)
예제 #3
0
def test_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')

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

    #    expr = alpha * u
    #    expr = alpha * dx(u)
    #    expr = alpha * dy(u)
    #    expr = alpha * dz(u)
    #    expr = alpha * u + beta * dx(u)
    #    expr = alpha * u + beta * dy(u)
    #    expr = alpha * u + beta * dz(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 * dz(dz(u))
    expr = mu * u + alpha * dx(u) + beta * dy(dz(u)) + nu * dx(dz(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))))
예제 #4
0
def test_1d():
    x, xi, xj = symbols('x xi xj')

    u = Unknown('u')

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

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

    expr = mu * u + dx(u) + dx(dx(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))))
예제 #5
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))
예제 #6
0
from mlhiphy.templates import template_scalar, template_header_scalar

from sympy import expand
from sympy import Lambda
from sympy import symbols
from sympy import exp

x, xi, xj = symbols('x xi xj')

alpha = Constant('alpha')
beta = Constant('beta')

u = Unknown('u')
expr = alpha * u + dx(u)

print('> generic_kernel := ', expand(generic_kernel(expr, u, (xi, xj))))

xi, xj, theta = symbols('xi xj theta')
kuu = theta * exp(-0.5 * ((xi - xj)**2))

import os


def mkdir_p(dir):
    if os.path.isdir(dir):
        return
    os.makedirs(dir)


def write_code(name, code, ext='py', folder='.pyccel'):
    filename = '{name}.{ext}'.format(name=name, ext=ext)