Sweep Generation#

The Sweep Generator#

class sweepgen.sweep.Sweep(name, symbolic_kernel, config=None)#

Generate a waLBerla sweep from a pystencils kernel.

Parameters:
  • name (str) – Name of the sweep class

  • assignments – Assignment collection defining the pystencils kernel

  • config (CreateKernelConfig | None) – Optional code generator configuration. Options specified in this configuration override options from the WalberlaBuildConfig.

  • symbolic_kernel (SymbolicKernel)

static use_v8core_fields(use=True)#

Generate code for the experimental field system in walberla::v8::memory.

Parameters:

use (bool)

property sparse: bool#

If set to True, the sweep is generated as a sparse sweep.

Instead of iterating over all cells on a block, sparse sweeps process only cells from a given index vector. They can be used to implement phenomena that should only be applied in small regions of the simulation space, such as boundary conditions.

If the config argument passed to the constructor has an index_field set, the sweep is automatically marked sparse.

swap_fields(field, shadow_field)#

Register two fields as a swapping pair.

The generated sweep will treat shadow_field as a temporary shadow of field. The shadow field will not occur in the sweep’s public API, but me managed internally. The data arrays of field and shadow_field will be swapped after each invocation of the sweep, such that data written to the shadow field overwrites the old content of field.

Parameters:

Code-Generation Decorators for ps.flow#

The following are decorators wrapping the equations block decorator from pystencils.flow, to immediately generate sweeps from flowgraph equation blocks:

sweepgen.flow.sweep(*, config: CreateKernelConfig | None = None, preds: Iterable[FlowgraphNode] | None = None, name: str | None = None) Callable[[Callable[[EquationsBlockBuilder], None]], Sweep]#
sweepgen.flow.sweep(func: Callable[[EquationsBlockBuilder], None], /) Sweep

Create a Sweep generator directly from a pystencils.flow equations block.

This function behaves like ps.flow.block, but in addition immediately creates a Sweep code generator object from the given equations block.

Example: The following example creates the generator for a sweep called FieldCopy copying all values from one field g to another field f, and then invokes code generation via sfg.generate:

import sweepgen as sg

...

cfg = ps.CreateKernelConfig()

@sg.flow.sweep(config=cfg)
def FieldCopy(_eq):
    _eq.store[f()] = g()

sfg.generate(FieldCopy)
Parameters:
sweepgen.flow.generate_sweep(sfg, *, config=None, preds=None, name=None)#

Generate a sweep directly from a pystencils.flow equations block.

This function behaves like ps.flow.block, but in addition immediately generates code for a sweep from the given equations block.

Example: The following example generates a sweep called FieldCopy copying all values from one field g to another field f:

import sweepgen as sg

...

cfg = ps.CreateKernelConfig()

@sg.flow.generate_sweep(sfg, config=cfg)
def FieldCopy(_eq):
    _eq.store[f()] = g()
Parameters:
Return type:

Callable[[Callable[[EquationsBlockBuilder], None]], None]