Basic Examples
GUI Examples
Section titled “GUI Examples”Examples of using the simulation core API via the graphical user interface (gui).
1) Kepler orbits in phase portrait mode
Section titled “1) Kepler orbits in phase portrait mode”Generate Kepler style orbits in phase portrait mode.
local N = 512local dt = 0.05local ctx = ooc.create()
ooc.set_timestep(ctx, dt)ooc.set_visual_mode(ctx, "phase_portrait")
local field_1 = ooc.add_field(ctx, {N}, { type = "complex_double", fill = {0.0, 0.0}})
local field_2 = ooc.add_field(ctx, {N}, { type = "complex_double", fill = {0.0, 0.0}})
ooc.add_stimulus_operator(ctx, field_1, { type = "stimulus_sine", amplitude = 0.25, wavenumber = 0.025, omega = -0.3, phase = 0})
ooc.add_stimulus_operator(ctx, field_1, { type = "stimulus_sine", amplitude = 0.25, wavenumber = 0.05, omega = -0.3, phase = math.pi/2, rotation = math.pi/4,})
ooc.add_stimulus_operator(ctx, field_2, { type = "stimulus_spectral_lines", amplitude = 0.25, wavenumber = 0.03, omega = -0.2, phase = 0})
ooc.add_mixer_operator(ctx, field_2, field_1, field_1, { mode = "multiply", lhs_gain = 0.5, rhs_gain = 0.5})
local integrator = ooc.create_context_integrator(ctx, "euler")
ooc.set_integrator(ctx, integrator)
return ctx2) Gaussian pulse
Section titled “2) Gaussian pulse”Applies a moving Gaussian pulse stimulus to a real field.
local N = 768local dt = 0.025
local ctx = ooc.create()
ooc.set_timestep(ctx, dt)ooc.set_visual_mode(ctx, "polar")
local field = ooc.add_field(ctx, {N}, { type = "double", fill = {0.0}})
ooc.add_zero_field_operator(ctx, field)
ooc.add_stimulus_operator(ctx, field, { type = "stimulus_gaussian_pulse", amplitude = 0.25, sigma_x = 0.75, velocity_x = 1, coord_center_x = math.pi})
local integrator = ooc.create_context_integrator(ctx, "euler", { initial_dt = dt})
ooc.set_integrator(ctx, integrator)
return ctx3) Simple log hook
Section titled “3) Simple log hook”local N = 512local dt = 0.01local ctx = ooc.create()
ooc.set_timestep(ctx, dt)ooc.on_step(ctx, function(c) local t = ooc.get_time(c) ooc.log("t=%.3f", t)end)
return ctxExample output in log panel:
[INFO] t=0.000[INFO] t=0.010[INFO] t=0.020[INFO] t=0.030...CLI Examples
Section titled “CLI Examples”Examples of using the simulation core API via the command-line interface (cli).
1) Fixed-step sine stimulus
Section titled “1) Fixed-step sine stimulus”Applies to a real field and takes 120 integrator (RK4) steps, matching the forced oscillator
local ctx = ooc.create()local steps = 120local N = 256local dt = 0.02
ooc.log("Starting simulation with %d steps and dt = %.3f", steps, dt)
local field = ooc.add_field(ctx, {N}, { type = "double", fill = {0}})
ooc.add_stimulus_operator(ctx, field, { type = "stimulus_sine", amplitude = 0.1, wavenumber = 1.0, omega = 0.2})
local integrator = ooc.create_context_integrator(ctx, "rk4", { initial_dt = dt})
ooc.set_integrator(ctx, integrator)
for _ = 1, steps do ooc.integrator_step(ctx, integrator, dt) local values = field:values() ooc.log("Field sample value: %.6f", values[1])end
ooc.shutdown(ctx)
return ctxExample output:
oak@field % ./bin/cli --script fixed-step-sine.lua[INFO] Starting simulation with 120 steps and dt = 0.020...[INFO] Field sample value: -0.665682[INFO] Field sample value: -0.687690[INFO] Field sample value: -0.710105[INFO] Field sample value: -0.732928[INFO] Field sample value: -0.756163[INFO] Field sample value: -0.779813[INFO] Field sample value: -0.803878[INFO] Field sample value: -0.828362...