Skip to content
Oakfield Operator Calculus Function Reference Site

Oakfield API Documentation

Oakfield exposes a composable operator calculus through Lua. A script creates a SimContext, adds fields and operators, assigns an integrator, then advances time. All APIs documented here are verified against the current source.

Zero-Based Indexing

Field indices, operator indices, and integrator references inside the engine are zero-based.

One-Based Lua Tables

Lua tables returned to user (e.g. field:shape(), field:values()) are 1-based (Lua default).

Complex Number Representation

Complex numbers are passed either as real number or {re, im} table.

Enum Helpers

Enum values and modes exposed as integers also have string helpers where provided.

Data Layout

Fields are stored in row-major order, with the fastest-varying dimension last.

Coordinate Systems

Spatial coordinates follow a right-handed system, with positive axes defined per context.

Boundary Conditions

Default boundary conditions are periodic; others (Dirichlet, Neumann, Periodic, Reflective) can be set per field.

Userdata objects (contexts, fields, operators, integrators, loggers, profilers) are managed by Lua’s garbage collector (GC). Each userdata type has specific metamethods and GC behaviors:

TypeMetamethodsGC Behavior
Context (SimContext)__gc, __tostringDestroys context, releases managed integrators, frees native memory.
Field__gc, __tostring, methods: rank, shape, values, componentsGC detaches handle only (sets pointers NULL); underlying field owned by context until context GC.
Operator__gc, __tostring, methods: name, symbolic_formGC detaches handle only; operator lifetime owned by context.
Integrator__gc, __tostringGC destroys integrator and frees workspace.
Logger__gc, __tostring, methods: log, pop, clearGC destroys async logger and frees memory.
Profiler__gc, __tostring, methods: begin_frame, end_frame, record_operator, record_operator_delta, snapshotGC destroys profiler and frees memory.

Detaching (field/operator) means subsequent method calls on that handle error (expected Field userdata).