From 7f86ecf6f585b644cfe7b338aa9adca144fb9b6a Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 12 Feb 2013 17:00:20 -0500 Subject: [PATCH] one_gaussian_bump.c: Prepare for alternative integrators --- one_gaussian_bump.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/one_gaussian_bump.c b/one_gaussian_bump.c index 792ca64..bc67e44 100644 --- a/one_gaussian_bump.c +++ b/one_gaussian_bump.c @@ -68,6 +68,9 @@ typedef struct system_struct { 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) { @@ -123,7 +126,7 @@ double single_gaussian_energy(state_t *state, void *system) 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; @@ -213,6 +216,7 @@ int main(int argc, char **argv) { 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); @@ -228,7 +232,7 @@ int main(int argc, char **argv) { print_state(&state, &system); while (state.t < t_max) { - step(&state, &system, dt); + (*step_fn)(&state, &system, dt); print_state(&state, &system); } return 0; -- 2.26.2