zoomy_core.transformation.to_glsl module

zoomy_core.transformation.to_glsl module#

Module zoomy_core.transformation.to_glsl.

SymPy → GLSL ES 3.00 (WebGL2) code printer for generating kernels from any Zoomy symbolic model.

Subclasses OutParamCodePrinter — generated kernels return void and write their result through a trailing out float res[N] parameter, so the body generation, Piecewise handling and kernel/BC wrapping are shared with the JS printer. Only the GLSL-specific output formatting lives here.

Two GLSL ES 3.00 facts shape the output:

  • No array return types. Kernels write through out float res[N]. The result is laid out row-major in the natural shape of the symbolic definition (e.g. flux is (n_variables, dimension)res[var * dimension + dim]).

  • No implicit int→float conversion. Every numeric literal is emitted in float form (00.0). The one exception is comparisons between integer quantities (e.g. a boundary-condition index), which are detected and printed with plain int literals.

Usage:

from zoomy_core.transformation.to_glsl import GlslModel
print(GlslModel(model).generate())
class zoomy_core.transformation.to_glsl.GenericGlslBase(*args, **kwargs)#

Bases: OutParamCodePrinter

GLSL ES 3.00 code printer.

Inherits the out-parameter body generation, Piecewise handling and kernel / boundary-condition wrapping from OutParamCodePrinter; overrides the GLSL-specific output: static types, a bare math namespace, explicit float literals and out float res[N] result parameters.

math_namespace = ''#
real_type = 'float'#
gpu_enabled = False#
c_functions = {'Abs': <function GenericGlslBase.<lambda>>, 'Max': <function GenericGlslBase.<lambda>>, 'Min': <function GenericGlslBase.<lambda>>, 'clamp_momentum': <function GenericGlslBase.<lambda>>, 'clamp_positive': <function GenericGlslBase.<lambda>>, 'conditional': <function GenericGlslBase.<lambda>>, 'max_wavespeed': <function GenericGlslBase.<lambda>>}#
wrap_function_signature(name, args_str, body_str, shape)#

Wrap a GLSL body in a void function declaration.

get_includes()#

No includes needed for GLSL.

get_simple_array_def()#

No SimpleArray struct needed for GLSL.

class zoomy_core.transformation.to_glsl.GlslModel(model)#

Bases: GenericGlslBase

Generate GLSL ES 3.00 kernels from a Zoomy symbolic model.

Produces standalone void functions for flux, source, eigenvalues, etc. Each takes the model’s flat float[] argument arrays plus an out float res[N] result parameter. Mirrors zoomy_core.transformation.to_js.JsModel.

KERNEL_NAMES = ['flux', 'source', 'eigenvalues', 'source_jacobian_wrt_variables', 'quasilinear_matrix']#
generate()#

Generate all GLSL kernels as a single code string.

class zoomy_core.transformation.to_glsl.GlslNumerics(numerics)#

Bases: GenericGlslBase

Generate GLSL ES 3.00 kernels from a Zoomy symbolic Numerics.

Produces numerical_flux (and numerical_fluctuations / local_max_abs_eigenvalue) as void functions taking the per-face Q_minus / Q_plus states plus an out float res[N] result. Mirrors zoomy_core.transformation.generic_c.GenericCppNumerics.

generate()#

Generate all numerics kernels as a single GLSL code string.