From: W. Trevor King Date: Tue, 12 Feb 2013 22:00:20 +0000 (-0500) Subject: one_gaussian_bump.c: Prepare for alternative integrators X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=7f86ecf6f585b644cfe7b338aa9adca144fb9b6a;p=assignment-template.git one_gaussian_bump.c: Prepare for alternative integrators --- 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;