void *dx_dt_state; /* gaussian_state_t, etc. */
} system_t;
+/* function type for integration */
+typedef void (*step_fn_t)(state_t *state, system_t *system, double dt);
+
/* Potential: V(r) = 1/2 kb^2 exp(-r^2/b^2) */
double gaussian_energy(gaussian_state_t *state, double x, double y)
{
return kinetic + potential;
}
-void step(state_t *state, system_t *system, double dt)
+void euler_step(state_t *state, system_t *system, double dt)
{
double *dx_dt = NULL;
size_t i;
double x[4] = {3.5, 0, 0, 0};
system_t system = {};
gaussian_state_t gaussian = {};
+ step_fn_t step_fn = &euler_step;
state.x = (double *)x;
state.n = sizeof(x) / sizeof(double);
print_state(&state, &system);
while (state.t < t_max) {
- step(&state, &system, dt);
+ (*step_fn)(&state, &system, dt);
print_state(&state, &system);
}
return 0;