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

    :arg coefs: The coefficients representing the restriction formula.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :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 lsize: The shape of prefetched arrays in shared memory.
        See :class:`~pystella.ElementWiseMap`.
        Defaults to ``(4, 4, 4)``.

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

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

    lsize = kwargs.pop("lsize", (4, 4, 4))

    # ensure grid dimensions are *not* passed, as they will be misinterpreted
    for N in ["Nx", "Ny", "Nz"]:
        _ = kwargs.pop(N, None)

    restrict_coefs = {}
    for a, c_a in coefs.items():
        for b, c_b in coefs.items():
            for c, c_c in coefs.items():
                restrict_coefs[(a, b, c)] = c_a * c_b * c_c

    from pymbolic import parse, var
    i, j, k = parse("i, j, k")
    f1 = Field("f1", offset="h", indices=(2*i, 2*j, 2*k))
    f2 = Field("f2", offset="h")
    tmp = var("tmp")

    tmp_dict = {tmp: expand_stencil(f1, restrict_coefs)}

    if kwargs.pop("correct", False):
        restrict_dict = {f2: f2 - tmp}
    else:
        restrict_dict = {f2: tmp}

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

    if isinstance(StencilKernel, Stencil):
        return StencilKernel(restrict_dict, tmp_instructions=tmp_dict, args=args,
                             prefetch_args=["f1"], halo_shape=halo_shape,
                             lsize=lsize, **kwargs)
    else:
        return StencilKernel(restrict_dict, tmp_instructions=tmp_dict, args=args,
                             halo_shape=halo_shape, lsize=lsize, **kwargs)

    A base function for generating a restriction kernel.

    :arg coefs: The coefficients representing the restriction formula.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :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 lsize: The shape of prefetched arrays in shared memory.
        See :class:`~pystella.ElementWiseMap`.
        Defaults to ``(4, 4, 4)``.

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

    :returns: An instance of ``StencilKernel`` which executes the requested
        restriction.
    
A base function for generating a restriction kernel.
A base function for generating a restriction kernel .
def RestrictionBase(coefs, StencilKernel, halo_shape, **kwargs):
    lsize = kwargs.pop("lsize", (4, 4, 4))
    for N in ["Nx", "Ny", "Nz"]:
        _ = kwargs.pop(N, None)
    restrict_coefs = {}
    for a, c_a in coefs.items():
        for b, c_b in coefs.items():
            for c, c_c in coefs.items():
                restrict_coefs[(a, b, c)] = c_a * c_b * c_c
    from pymbolic import parse, var
    i, j, k = parse("i, j, k")
    f1 = Field("f1", offset="h", indices=(2*i, 2*j, 2*k))
    f2 = Field("f2", offset="h")
    tmp = var("tmp")
    tmp_dict = {tmp: expand_stencil(f1, restrict_coefs)}
    if kwargs.pop("correct", False):
        restrict_dict = {f2: f2 - tmp}
    else:
        restrict_dict = {f2: tmp}
    args = [lp.GlobalArg("f1", shape="(2*Nx+2*h, 2*Ny+2*h, 2*Nz+2*h)"),
            lp.GlobalArg("f2", shape="(Nx+2*h, Ny+2*h, Nz+2*h)")]
    if isinstance(StencilKernel, Stencil):
        return StencilKernel(restrict_dict, tmp_instructions=tmp_dict, args=args,
                             prefetch_args=["f1"], halo_shape=halo_shape,
                             lsize=lsize, **kwargs)
    else:
        return StencilKernel(restrict_dict, tmp_instructions=tmp_dict, args=args,
                             halo_shape=halo_shape, lsize=lsize, **kwargs)
def RestrictionBase ( coefs , StencilKernel , halo_shape , ** kwargs ) : lsize = kwargs . pop ( "lsize" , ( 4 , 4 , 4 ) ) for N in [ "Nx" , "Ny" , "Nz" ] : _ = kwargs . pop ( N , None ) restrict_coefs = { } for a , c_a in coefs . items ( ) : for b , c_b in coefs . items ( ) : for c , c_c in coefs . items ( ) : restrict_coefs [ ( a , b , c ) ] = c_a * c_b * c_c from pymbolic import parse , var i , j , k = parse ( "i, j, k" ) f1 = Field ( "f1" , offset = "h" , indices = ( 2 * i , 2 * j , 2 * k ) ) f2 = Field ( "f2" , offset = "h" ) tmp = var ( "tmp" ) tmp_dict = { tmp : expand_stencil ( f1 , restrict_coefs ) } if kwargs . pop ( "correct" , False ) : restrict_dict = { f2 : f2 - tmp } else : restrict_dict = { f2 : tmp } args = [ lp . GlobalArg ( "f1" , shape = "(2*Nx+2*h, 2*Ny+2*h, 2*Nz+2*h)" ) , lp . GlobalArg ( "f2" , shape = "(Nx+2*h, Ny+2*h, Nz+2*h)" ) ] if isinstance ( StencilKernel , Stencil ) : return StencilKernel ( restrict_dict , tmp_instructions = tmp_dict , args = args , prefetch_args = [ "f1" ] , halo_shape = halo_shape , lsize = lsize , ** kwargs ) else : return StencilKernel ( restrict_dict , tmp_instructions = tmp_dict , args = args , halo_shape = halo_shape , lsize = lsize , ** 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 coefs: The coefficients representing the restriction formula.
        Follows the convention of :func:`pystella.derivs.centered_diff`
        (since the restriction is applied recursively in each dimension).

    :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 lsize: The shape of prefetched arrays in shared memory.
        See :class:`~pystella.ElementWiseMap`.
        Defaults to ``(4, 4, 4)``.

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

    :returns: An instance of ``StencilKernel`` which executes the requested
        restriction.
    """ # ensure grid dimensions are *not* passed, as they will be misinterpreted

An instance of ``StencilKernel`` which executes the requested
restriction.
An instance of ` ` StencilKernel ` ` which executes the requested restriction .
coefs
The coefficients representing the restriction formula.
Follows the convention of :func:`pystella.derivs.centered_diff`
(since the restriction is applied recursively in each dimension).
The coefficients representing the restriction formula . Follows the convention of : func : ` pystella . derivs . centered_diff ` ( since the restriction is applied recursively in each dimension ) .
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 ` .
lsize
The shape of prefetched arrays in shared memory.
See :class:`~pystella.ElementWiseMap`.
The shape of prefetched arrays in shared memory . See : class : ` ~pystella . ElementWiseMap ` .
correct
A :class:`bool` determining whether to produce a kernel which
corrects an output array by the restricted array, or to only perform
strict restriction.
Defaults to *False*.
A : class : ` bool ` determining whether to produce a kernel which corrects an output array by the restricted array or to only perform strict restriction . Defaults to * False * .