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
configargument passed to the constructor has anindex_fieldset, the sweep is automatically marked sparse.
- swap_fields(field, shadow_field)#
Register two fields as a swapping pair.
The generated sweep will treat
shadow_fieldas a temporary shadow offield. The shadow field will not occur in the sweep’s public API, but me managed internally. The data arrays offieldandshadow_fieldwill be swapped after each invocation of the sweep, such that data written to the shadow field overwrites the old content offield.
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
Sweepgenerator directly from apystencils.flowequations block.This function behaves like
ps.flow.block, but in addition immediately creates aSweepcode generator object from the given equations block.Example: The following example creates the generator for a sweep called
FieldCopycopying all values from one fieldgto another fieldf, and then invokes code generation viasfg.generate:import sweepgen as sg ... cfg = ps.CreateKernelConfig() @sg.flow.sweep(config=cfg) def FieldCopy(_eq): _eq.store[f()] = g() sfg.generate(FieldCopy)
- Parameters:
config (CreateKernelConfig | None) – Code generation config for this sweep
preds (Iterable[FlowgraphNode] | None) – Predecessors to this
ps.flowblock; seeps.flow.blockname (str | None) – Name for this sweep; if none is given, the decorated function’s name is used
func (Callable[[EquationsBlockBuilder], None] | None)
- sweepgen.flow.generate_sweep(sfg, *, config=None, preds=None, name=None)#
Generate a sweep directly from a
pystencils.flowequations 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
FieldCopycopying all values from one fieldgto another fieldf:import sweepgen as sg ... cfg = ps.CreateKernelConfig() @sg.flow.generate_sweep(sfg, config=cfg) def FieldCopy(_eq): _eq.store[f()] = g()
Example Apps
- Parameters:
sfg (SfgBasicComposer) – Active SFG composer object
config (CreateKernelConfig | None) – Code generation config for this sweep
preds (Iterable[FlowgraphNode] | None) – Predecessors to this
ps.flowblock; seeps.flow.blockname (str | None) – Name for this sweep; if none is given, the decorated function’s name is used
- Return type:
Callable[[Callable[[EquationsBlockBuilder], None]], None]