pystella/multigrid/transfer.py
def InterpolationBase(even_coefs, odd_coefs, StencilKernel, halo_shape, **kwargs):
    """
    A base function for generating a restriction kernel.

    :arg even_coefs: The coefficients representing the interpolation formula
        for gridpoints on the coarse and fine grid which coincide in space.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :arg odd_coefs: Same as ``even_coefs``, but for points on the fine grid which
        lie between points on the coarse grid.

    :arg StencilKernel: The stencil mapper to create an instance of.
        Defaults to :class:`~pystella.Stencil`.

    :arg halo_shape: The number of halo layers on (both sides of) each axis of
        the computational grid.
        Currently must be an :class:`int`.

    :arg correct: A :class:`bool` determining whether to produce a kernel which
        corrects an output array by the interpolated array, or to only perform
        strict interpolation.
        Defaults to *False*.

    :returns: An instance of ``StencilKernel`` which executes the requested
        interpolation.
    """

    from pymbolic import parse, var
    i, j, k = parse("i, j, k")
    f1 = Field("f1", offset="h")

    tmp_insns = {}
    tmp = var("tmp")

    import itertools
    for parity in tuple(itertools.product((0, 1), (0, 1), (0, 1))):
        result = 0
        for a, c_a in odd_coefs.items() if parity[0] else even_coefs.items():
            for b, c_b in odd_coefs.items() if parity[1] else even_coefs.items():
                for c, c_c in odd_coefs.items() if parity[2] else even_coefs.items():
                    f2 = Field("f2", offset="h",
                               indices=((i+a)//2, (j+b)//2, (k+c)//2))
                    result += c_a * c_b * c_c * f2

        tmp_insns[tmp[parity]] = result

    from pymbolic.primitives import Remainder
    a, b, c = (Remainder(ind, 2) for ind in (i, j, k))

    if kwargs.pop("correct", False):
        interp_dict = {f1: f1 + tmp[a, b, c]}
    else:
        interp_dict = {f1: tmp[a, b, c]}

    args = [lp.GlobalArg("f1", shape="(Nx+2*h, Ny+2*h, Nz+2*h)"),
            lp.GlobalArg("f2", shape="(Nx//2+2*h, Ny//2+2*h, Nz//2+2*h)")]

    return StencilKernel(interp_dict, tmp_instructions=tmp_insns, args=args,
                         prefetch_args=["f2"], halo_shape=halo_shape, **kwargs)

    A base function for generating a restriction kernel.

    :arg even_coefs: The coefficients representing the interpolation formula
        for gridpoints on the coarse and fine grid which coincide in space.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :arg odd_coefs: Same as ``even_coefs``, but for points on the fine grid which
        lie between points on the coarse grid.

    :arg StencilKernel: The stencil mapper to create an instance of.
        Defaults to :class:`~pystella.Stencil`.

    :arg halo_shape: The number of halo layers on (both sides of) each axis of
        the computational grid.
        Currently must be an :class:`int`.

    :arg correct: A :class:`bool` determining whether to produce a kernel which
        corrects an output array by the interpolated array, or to only perform
        strict interpolation.
        Defaults to *False*.

    :returns: An instance of ``StencilKernel`` which executes the requested
        interpolation.
    
A base function for generating a restriction kernel.
A base function for generating a restriction kernel .
def InterpolationBase(even_coefs, odd_coefs, StencilKernel, halo_shape, **kwargs):
    from pymbolic import parse, var
    i, j, k = parse("i, j, k")
    f1 = Field("f1", offset="h")
    tmp_insns = {}
    tmp = var("tmp")
    import itertools
    for parity in tuple(itertools.product((0, 1), (0, 1), (0, 1))):
        result = 0
        for a, c_a in odd_coefs.items() if parity[0] else even_coefs.items():
            for b, c_b in odd_coefs.items() if parity[1] else even_coefs.items():
                for c, c_c in odd_coefs.items() if parity[2] else even_coefs.items():
                    f2 = Field("f2", offset="h",
                               indices=((i+a)//2, (j+b)//2, (k+c)//2))
                    result += c_a * c_b * c_c * f2
        tmp_insns[tmp[parity]] = result
    from pymbolic.primitives import Remainder
    a, b, c = (Remainder(ind, 2) for ind in (i, j, k))
    if kwargs.pop("correct", False):
        interp_dict = {f1: f1 + tmp[a, b, c]}
    else:
        interp_dict = {f1: tmp[a, b, c]}
    args = [lp.GlobalArg("f1", shape="(Nx+2*h, Ny+2*h, Nz+2*h)"),
            lp.GlobalArg("f2", shape="(Nx//2+2*h, Ny//2+2*h, Nz//2+2*h)")]
    return StencilKernel(interp_dict, tmp_instructions=tmp_insns, args=args,
                         prefetch_args=["f2"], halo_shape=halo_shape, **kwargs)
def InterpolationBase ( even_coefs , odd_coefs , StencilKernel , halo_shape , ** kwargs ) : from pymbolic import parse , var i , j , k = parse ( "i, j, k" ) f1 = Field ( "f1" , offset = "h" ) tmp_insns = { } tmp = var ( "tmp" ) import itertools for parity in tuple ( itertools . product ( ( 0 , 1 ) , ( 0 , 1 ) , ( 0 , 1 ) ) ) : result = 0 for a , c_a in odd_coefs . items ( ) if parity [ 0 ] else even_coefs . items ( ) : for b , c_b in odd_coefs . items ( ) if parity [ 1 ] else even_coefs . items ( ) : for c , c_c in odd_coefs . items ( ) if parity [ 2 ] else even_coefs . items ( ) : f2 = Field ( "f2" , offset = "h" , indices = ( ( i + a ) // 2 , ( j + b ) // 2 , ( k + c ) // 2 ) ) result += c_a * c_b * c_c * f2 tmp_insns [ tmp [ parity ] ] = result from pymbolic . primitives import Remainder a , b , c = ( Remainder ( ind , 2 ) for ind in ( i , j , k ) ) if kwargs . pop ( "correct" , False ) : interp_dict = { f1 : f1 + tmp [ a , b , c ] } else : interp_dict = { f1 : tmp [ a , b , c ] } args = [ lp . GlobalArg ( "f1" , shape = "(Nx+2*h, Ny+2*h, Nz+2*h)" ) , lp . GlobalArg ( "f2" , shape = "(Nx//2+2*h, Ny//2+2*h, Nz//2+2*h)" ) ] return StencilKernel ( interp_dict , tmp_instructions = tmp_insns , args = args , prefetch_args = [ "f2" ] , halo_shape = halo_shape , ** kwargs )
A base function for generating a restriction kernel.
A base function for generating a restriction kernel .
"""
    A base function for generating a restriction kernel.

    :arg even_coefs: The coefficients representing the interpolation formula
        for gridpoints on the coarse and fine grid which coincide in space.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :arg odd_coefs: Same as ``even_coefs``, but for points on the fine grid which
        lie between points on the coarse grid.

    :arg StencilKernel: The stencil mapper to create an instance of.
        Defaults to :class:`~pystella.Stencil`.

    :arg halo_shape: The number of halo layers on (both sides of) each axis of
        the computational grid.
        Currently must be an :class:`int`.

    :arg correct: A :class:`bool` determining whether to produce a kernel which
        corrects an output array by the interpolated array, or to only perform
        strict interpolation.
        Defaults to *False*.

    :returns: An instance of ``StencilKernel`` which executes the requested
        interpolation.
    """
An instance of ``StencilKernel`` which executes the requested
interpolation.
An instance of ` ` StencilKernel ` ` which executes the requested interpolation .
even_coefs
The coefficients representing the interpolation formula
for gridpoints on the coarse and fine grid which coincide in space.
Follows the convention of :func:`pystella.derivs.centered_diff`
(since the restriction is applied recursively in each dimension).
The coefficients representing the interpolation formula for gridpoints on the coarse and fine grid which coincide in space . Follows the convention of : func : ` pystella . derivs . centered_diff ` ( since the restriction is applied recursively in each dimension ) .
odd_coefs
Same as ``even_coefs``, but for points on the fine grid which
lie between points on the coarse grid.
Same as ` ` even_coefs ` ` but for points on the fine grid which lie between points on the coarse grid .
StencilKernel
The stencil mapper to create an instance of.
Defaults to :class:`~pystella.Stencil`.
The stencil mapper to create an instance of . Defaults to : class : ` ~pystella . Stencil ` .
halo_shape
The number of halo layers on (both sides of) each axis of
the computational grid.
Currently must be an :class:`int`.
The number of halo layers on ( both sides of ) each axis of the computational grid . Currently must be an : class : ` int ` .
correct
A :class:`bool` determining whether to produce a kernel which
corrects an output array by the interpolated array, or to only perform
strict interpolation.
Defaults to *False*.
A : class : ` bool ` determining whether to produce a kernel which corrects an output array by the interpolated array or to only perform strict interpolation . Defaults to * False * .