Ejemplo n.º 1
0
from pyccel.epyccel import ContextPyccel
from pyccel.epyccel import epyccel
from pyccel.decorators import types

import initialiser_func
from mod_initialiser_funcs import fEq, perturbation

context = ContextPyccel(name='initialiser_funcs')
context.insert_function(fEq, ['double[:]', 'int', 'double'])
context.insert_function(perturbation,
                        ['double[:]', 'int', 'double', 'int', 'double[:]'])

initialiser_func = epyccel(initialiser_func, context=context)
Ejemplo n.º 2
0
def test_2d_scalar_3():
    print('============== test_2d_scalar_3 ================')

    # ... define the weak formulation
    x, y = symbols('x y')

    u = Symbol('u')
    v = Symbol('v')

    b = Function('b')

    a = Lambda((x, y, v, u), Dot(Grad(u), Grad(v)) + b(x, y) * u * v)
    # ...

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    ne1 = 8
    ne2 = 8

    print('> Grid   :: [{ne1},{ne2}]'.format(ne1=ne1, ne2=ne2))
    print('> Degree :: [{p1},{p2}]'.format(p1=p1, p2=p2))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)

    V = TensorFemSpace(V1, V2)

    # ...

    # ... user defined function
    def b(x, y):
        r = 1. + x * (1. - x) + y * (1. - y)
        return r

    # ...

    # ... create an interactive pyccel context
    from pyccel.epyccel import ContextPyccel

    context = ContextPyccel(name='context_3')
    context.insert_function(b, ['double', 'double'],
                            kind='function',
                            results=['double'])

    context.compile()
    # ...

    # ...
    kernel_py = compile_kernel('kernel_scalar_3',
                               a,
                               V,
                               context=context,
                               verbose=True,
                               backend='python')

    kernel_f90 = compile_kernel('kernel_scalar_3',
                                a,
                                V,
                                context=context,
                                verbose=True,
                                backend='fortran')
    # ...

    # ...
    M_py = assemble_matrix(V, kernel_py)
    M_f90 = assemble_matrix(V, kernel_f90)
    # ...

    assert_identical_coo(M_py, M_f90)
Ejemplo n.º 3
0
def test_2d_scalar_4():
    print('============== test_2d_scalar_4 ================')

    # ... define the weak formulation
    x, y = symbols('x y')

    u = Symbol('u')
    v = Symbol('v')

    b0 = Function('b0')
    b1 = Function('b1')

    a = Lambda((x, y, v, u), (b0(x, y) * dx(v) + b1(x, y) * dy(v)) *
               (b0(x, y) * dx(u) + b1(x, y) * dy(u)))
    # ...

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    ne1 = 8
    ne2 = 8

    print('> Grid   :: [{ne1},{ne2}]'.format(ne1=ne1, ne2=ne2))
    print('> Degree :: [{p1},{p2}]'.format(p1=p1, p2=p2))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)

    V = TensorFemSpace(V1, V2)

    # ...

    # ... user defined function
    def b0(x, y):
        from numpy import sin
        from scipy import pi

        r = 1.1659397624413860850012270020670 * (1.0 + 0.1 * sin(2 * pi * y))
        return r

    def b1(x, y):
        from numpy import sin
        from scipy import pi

        r = 1.0 * (1.0 + 0.1 * sin(2 * pi * y))
        return r

    # ...

    # ... create an interactive pyccel context
    from pyccel.epyccel import ContextPyccel

    context = ContextPyccel(name='context_4')
    context.insert_function(b0, ['double', 'double'],
                            kind='function',
                            results=['double'])
    context.insert_function(b1, ['double', 'double'],
                            kind='function',
                            results=['double'])

    context.compile()
    # ...

    # ...
    kernel_py = compile_kernel('kernel_scalar_4',
                               a,
                               V,
                               context=context,
                               verbose=True,
                               backend='python')

    kernel_f90 = compile_kernel('kernel_scalar_4',
                                a,
                                V,
                                context=context,
                                verbose=True,
                                backend='fortran')
    # ...

    # ...
    M_py = assemble_matrix(V, kernel_py)
    M_f90 = assemble_matrix(V, kernel_f90)
    # ...

    assert_identical_coo(M_py, M_f90)
Ejemplo n.º 4
0
def test_1d_scalar_3():
    print('============== test_1d_scalar_3 ================')

    x = Symbol('x')

    u = Symbol('u')
    v = Symbol('v')

    b = Function('b')

    a = Lambda((x, v, u), Dot(Grad(u), Grad(v)) + b(x) * u * v)
    print('> input     := {0}'.format(a))

    # ...  create a finite element space
    p = 3
    ne = 64

    print('> Grid   :: {ne}'.format(ne=ne))
    print('> Degree :: {p}'.format(p=p))

    grid = linspace(0., 1., ne + 1)

    V = SplineSpace(p, grid=grid)

    # ...

    # ... user defined function
    def b(s):
        r = 1. + s * (1. - s)
        return r

    # ...

    # ... create an interactive pyccel context
    from pyccel.epyccel import ContextPyccel

    context = ContextPyccel(name='context_3')
    context.insert_function(b, ['double'], kind='function', results=['double'])

    context.compile()
    # ...

    # ...
    kernel_py = compile_kernel('kernel_scalar_3',
                               a,
                               V,
                               context=context,
                               verbose=True,
                               backend='python')

    kernel_f90 = compile_kernel('kernel_scalar_3',
                                a,
                                V,
                                context=context,
                                verbose=True,
                                backend='fortran')
    # ...

    # ...
    M_py = assemble_matrix(V, kernel_py)
    M_f90 = assemble_matrix(V, kernel_f90)
    # ...

    assert_identical_coo(M_py, M_f90)

    print('')
Ejemplo n.º 5
0
def test_2d_scalar_3():
    print('============== test_2d_scalar_3 ================')

    x, y = symbols('x y')

    u = Symbol('u')
    v = Symbol('v')

    b = Function('b')

    a = Lambda((x, y, v, u), Dot(Grad(u), Grad(v)) + b(x, y) * u * v)
    print('> input       := {0}'.format(a))

    # ...  create a finite element space
    p1 = 2
    p2 = 2
    ne1 = 8
    ne2 = 8

    print('> Grid   :: [{ne1},{ne2}]'.format(ne1=ne1, ne2=ne2))
    print('> Degree :: [{p1},{p2}]'.format(p1=p1, p2=p2))

    grid_1 = linspace(0., 1., ne1 + 1)
    grid_2 = linspace(0., 1., ne2 + 1)

    V1 = SplineSpace(p1, grid=grid_1)
    V2 = SplineSpace(p2, grid=grid_2)

    V = TensorFemSpace(V1, V2)
    # ...

    # ... create a glt symbol from a string without evaluation
    expr = glt_symbol(a, space=V)
    print('> glt symbol  := {0}'.format(expr))

    # ...

    # ... user defined function
    def b(x, y):
        r = 1. + x * y
        return r

    # ...

    # ... create an interactive pyccel context
    from pyccel.epyccel import ContextPyccel

    context = ContextPyccel(name='context_scalar_3')
    context.insert_function(b, ['double', 'double'],
                            kind='function',
                            results=['double'])

    context.compile()
    # ...

    # ...
    symbol_f90 = compile_symbol('symbol_scalar_3',
                                a,
                                V,
                                context=context,
                                backend='fortran')
    # ...

    # ... example of symbol evaluation
    t1 = linspace(-pi, pi, ne1 + 1)
    t2 = linspace(-pi, pi, ne2 + 1)
    x1 = linspace(0., 1., ne1 + 1)
    x2 = linspace(0., 1., ne2 + 1)
    e = zeros((ne1 + 1, ne2 + 1), order='F')
    symbol_f90(x1, x2, t1, t2, e)
    # ...

    print('')
Ejemplo n.º 6
0
def test_1d_scalar_3():
    print('============== test_1d_scalar_3 ================')

    x = Symbol('x')

    u = Symbol('u')
    v = Symbol('v')

    b = Function('b')

    a = Lambda((x, v, u), Dot(Grad(u), Grad(v)) + b(x) * u * v)
    print('> input     := {0}'.format(a))

    # ...  create a finite element space
    p = 3
    ne = 64

    print('> Grid   :: {ne}'.format(ne=ne))
    print('> Degree :: {p}'.format(p=p))

    grid = linspace(0., 1., ne + 1)

    V = SplineSpace(p, grid=grid)
    # ...

    # ... create a glt symbol from a string without evaluation
    expr = glt_symbol(a, space=V)
    print('> glt symbol  := {0}'.format(expr))

    # ...

    # ... user defined function
    def b(s):
        r = 1. + s * (1. - s)
        return r

    # ...

    # ... create an interactive pyccel context
    from pyccel.epyccel import ContextPyccel

    context = ContextPyccel(name='context_scalar_3')
    context.insert_function(b, ['double'], kind='function', results=['double'])

    context.compile()
    # ...

    # ...
    symbol_f90 = compile_symbol('symbol_scalar_3',
                                a,
                                V,
                                context=context,
                                backend='fortran')
    # ...

    # ... example of symbol evaluation
    t1 = linspace(-pi, pi, ne + 1)
    x1 = linspace(0., 1., ne + 1)
    e = zeros(ne + 1)
    symbol_f90(x1, t1, e)
    # ...

    print('')
Ejemplo n.º 7
0
from pyccel.epyccel import ContextPyccel
from pyccel.epyccel import epyccel

import pygyro.splines.spline_eval_funcs
from pygyro.splines.mod_context_1 import find_span, basis_funs, basis_funs_1st_der

spline_context = ContextPyccel(name='context_1',
                               context_folder='pygyro.splines',
                               output_folder='pygyro.splines')
spline_context.insert_function(find_span, ['double[:]', 'int', 'double'])
spline_context.insert_function(
    basis_funs, ['double[:]', 'int', 'double', 'int', 'double[:]'])
spline_context.insert_function(
    basis_funs_1st_der, ['double[:]', 'int', 'double', 'int', 'double[:]'])

spline_eval_funcs = epyccel(pygyro.splines.spline_eval_funcs,
                            context=spline_context)

import pygyro.initialisation.initialiser_func
from pygyro.initialisation.mod_initialiser_funcs import fEq, perturbation

init_context = ContextPyccel(name='initialiser_funcs',
                             context_folder='pygyro.initialisation',
                             output_folder='pygyro.initialisation')
init_context.insert_function(fEq, [
    'double', 'double', 'double', 'double', 'double', 'double', 'double',
    'double', 'double'
])
init_context.insert_function(
    perturbation,
    ['double', 'double', 'double', 'int', 'int', 'double', 'double', 'double'])
Ejemplo n.º 8
0
from pyccel.epyccel import ContextPyccel
from pyccel.epyccel import epyccel
from pyccel.decorators import types

import spline_eval_funcs
from mod_context_1 import find_span, basis_funs, basis_funs_1st_der

context = ContextPyccel(name='context_1')
context.insert_function(find_span, ['double[:]', 'int', 'double'])
context.insert_function(basis_funs,
                        ['double[:]', 'int', 'double', 'int', 'double[:]'])
context.insert_function(basis_funs_1st_der,
                        ['double[:]', 'int', 'double', 'int', 'double[:]'])

spline_eval_funcs = epyccel(spline_eval_funcs, context=context)