16 #include <gsl/gsl_odeiv2.h>
18 #define DIVERGENCE_THRESHOLD 100
20 #define ABORT_ON_OVERFLOW 0
21 #define RETURN_ON_OVERFLOW 1
22 #define NORMALIZE_ON_OVERFLOW 2
50 double xg[],
int N,
double h,
double yg[][2],
51 int (*
derivs) (
double,
const double [2],
double [2],
void*),
55 size_t ntrial = 100000000;
56 double x0 = xg[0], x1 = xg[N - 2];
58 int status = GSL_SUCCESS, first_status = GSL_SUCCESS;
63 const gsl_odeiv2_step_type * step_type = gsl_odeiv2_step_rkck;
64 gsl_odeiv2_step * step = gsl_odeiv2_step_alloc(step_type, 2);
65 gsl_odeiv2_control * control = gsl_odeiv2_control_y_new(1
e-6, 0.0);
66 gsl_odeiv2_evolve * evolve = gsl_odeiv2_evolve_alloc(2);
69 gsl_odeiv2_system sys;
71 sys.jacobian =
nullptr;
76 for(
int i = 1; i < N - 1 and status == GSL_SUCCESS; i++)
78 xnext = x0 + (x1 - x0) * ((
double)i)/((
double)(N - 2));
79 double (& y_row) [2] = yg[i];
80 y_row[0] = yg[i-1][0];
81 y_row[1] = yg[i-1][1];
85 while (not done and status == GSL_SUCCESS)
87 status = gsl_odeiv2_evolve_apply (
98 if (not std::isfinite(y_row[0]))
99 throw exception(
"[solve2] Infinite result (%g) for i = %d", y_row[0], i);
103 if (status != GSL_SUCCESS and first_status != GSL_SUCCESS)
104 first_status = status;
106 std::cerr <<
"[solve2] Too many steps required (ntrial=" << ntrial <<
", x=" << x <<
").";
113 double inverse_norm = 1./fabs(y_row[0]);
114 for (
int j = 0; j <= i; j++)
116 yg[j][0] *= inverse_norm;
117 yg[j][1] *= inverse_norm;
126 throw exception (
"[solve2] Overflow error.");
145 gsl_odeiv2_evolve_free(evolve);
146 gsl_odeiv2_control_free(control);
147 gsl_odeiv2_step_free(step);
DistortingPotential exception
#define ABORT_ON_OVERFLOW
Definition: ode.h:20
#define NORMALIZE_ON_OVERFLOW
Definition: ode.h:22
const double e
Definition: special.h:44
int solve2(double xg[], int N, double h, double yg[][2], int(*derivs)(double, const double[2], double[2], void *), void *data, int flag)
Second-order differential equation solver.
Definition: ode.h:49
#define RETURN_ON_OVERFLOW
Definition: ode.h:21
int derivs(double x, const double y[2], double dydx[2], void *data)
Definition: wave_distort.cpp:67
#define DIVERGENCE_THRESHOLD
Definition: ode.h:18