49 for (
int i = 0; i <
NSP; ++i) {
50 nrm1 += (y[i] * y[i]);
51 nrm2 += (v[i] * v[i]);
57 if ((nrm1 !=
ZERO) && (nrm2 !=
ZERO)) {
58 dynrm = nrm1 * sqrt(
UROUND);
59 for (
int i = 0; i <
NSP; ++i) {
60 v[i] = y[i] + v[i] * (dynrm / nrm2);
62 }
else if (nrm1 !=
ZERO) {
63 dynrm = nrm1 * sqrt(
UROUND);
64 for (
int i = 0; i <
NSP; ++i) {
67 }
else if (nrm2 !=
ZERO) {
69 for (
int i = 0; i <
NSP; ++i) {
70 v[i] *= (dynrm / nrm2);
74 for (
int i = 0; i <
NSP; ++i) {
81 for (
int iter = 1; iter <= itmax; ++iter) {
86 for (
int i = 0; i <
NSP; ++i) {
87 nrm1 += ((Fv[i] - F[i]) * (Fv[i] - F[i]));
92 if ((iter >= 2) && (fabs(sigma - nrm2) <= (fmax(sigma, small) *
P01))) {
93 for (
int i = 0; i <
NSP; ++i) {
96 return (
ONEP2 * sigma);
100 for (
int i = 0; i <
NSP; ++i) {
101 v[i] = y[i] + ((Fv[i] - F[i]) * (dynrm / nrm1));
104 int ind = (iter %
NSP);
105 v[ind] = y[ind] - (v[ind] - y[ind]);
109 return (
ONEP2 * sigma);
126 const int s,
Real* y_j) {
130 Real temp2 = sqrt(temp1);
131 Real arg = (
Real)(s) * log(w0 + temp2);
132 const Real w1 = sinh(arg) * temp1 / (cosh(arg) * (
Real)(s) * temp2 - w0 * sinh(arg));
141 Real mu_t = w1 * b_jm1;
142 for (
int i = 0; i <
NSP; ++i) {
144 y_jm1[i] = y_0[i] + (mu_t * h * F_0[i]);
156 for (
int j = 2; j <= s; ++j) {
158 Real zj =
TWO * w0 * zjm1 - zjm2;
159 Real dzj =
TWO * w0 * dzjm1 - dzjm2 +
TWO * zjm1;
160 Real d2zj =
TWO * w0 * d2zjm1 - d2zjm2 +
FOUR * dzjm1;
161 Real b_j = d2zj / (dzj * dzj);
162 Real gamma_t =
ONE - (zjm1 * b_jm1);
164 Real nu = -b_j / b_jm2;
165 Real mu =
TWO * b_j * w0 / b_jm1;
169 dydt (t + (h * c_jm1), pr, y_jm1, y_j);
171 for (
int i = 0; i <
NSP; ++i) {
172 y_j[i] = (
ONE - mu - nu) * y_0[i] + (mu * y_jm1[i]) + (nu * y_jm2[i])
173 + h * mu_t * (y_j[i] - (gamma_t * F_0[i]));
175 Real c_j = (mu * c_jm1) + (nu * c_jm2) + mu_t * (
ONE - gamma_t);
178 for (
int i = 0; i <
NSP; ++i) {
214 int m_max = (int)(round(sqrt(
RTOL / (10.0 *
UROUND))));
221 for (
int i = 0; i <
NSP; ++i) {
227 dydt (t, pr, y_n, F_n);
231 for (
int i = 0; i <
NSP; ++i) {
232 work[4 + i] = F_n[i];
236 const Real hmax = fabs(tEnd - t);
248 if ((nstep % 25) == 0) {
249 work[3] =
rkc_spec_rad (t, pr, hmax, y_n, F_n, &work[4], temp_arr2);
255 if ((work[3] * work[2]) >
ONE) {
256 work[2] =
ONE / work[3];
258 work[2] = fmax(work[2], hmin);
260 for (
int i = 0; i <
NSP; ++i) {
261 temp_arr[i] = y_n[i] + (work[2] * F_n[i]);
263 dydt (t + work[2], pr, temp_arr, temp_arr2);
266 for (
int i = 0; i <
NSP; ++i) {
267 Real est = (temp_arr2[i] - F_n[i]) / (
ATOL +
RTOL * fabs(y_n[i]));
270 err = work[2] * sqrt(err /
NSP);
272 if ((
P1 * work[2]) < (hmax * sqrt(err))) {
273 work[2] = fmax(
P1 * work[2] / sqrt(err), hmin);
280 if ((
ONEP1 * work[2]) >= fabs(tEnd - t)) {
281 work[2] = fabs(tEnd - t);
285 int m = 1 + (int)(sqrt(
ONEP54 * work[2] * work[3] +
ONE));
289 work[2] = (
Real)(m * m - 1) / (
ONEP54 * work[3]);
292 hmin =
TEN *
UROUND * fmax(fabs(t), fabs(t + work[2]));
295 rkc_step (t, pr, work[2], y_n, F_n, m, y);
298 dydt (t + work[2], pr, y, temp_arr);
302 for (
int i = 0; i <
NSP; ++i) {
303 Real est =
P8 * (y_n[i] - y[i]) +
P4 * work[2] * (F_n[i] + temp_arr[i]);
304 est /= (
ATOL +
RTOL * fmax(fabs(y[i]), fabs(y_n[i])));
313 work[2] =
P8 * work[2] / (pow(err,
ONE3RD));
316 work[3] =
rkc_spec_rad (t, pr, hmax, y_n, F_n, &work[4], temp_arr2);
327 if (
P8 < (fac * temp2)) {
331 temp1 =
P8 * work[2] * pow(work[0],
ONE3RD);
332 temp2 = work[1] * pow(err,
TWO3RD);
333 if (temp1 < (fac * temp2)) {
342 for (
int i = 0; i <
NSP; ++i) {
344 F_n[i] = temp_arr[i];
348 work[2] *= fmax(
P1, fac);
349 work[2] = fmax(hmin, fmin(hmax, work[2]));
Contains header definitions for the RHS function for the van der Pol example.
void dydt(const double t, const double mu, const double *__restrict__ y, double *__restrict__ dy)
An implementation of the RHS of the van der Pol equation.
A file generated by Scons that specifies various options to the solvers.
__device__ Real rkc_spec_rad(const Real t, const Real pr, const Real hmax, const Real *y, const Real *F, Real *v, Real *Fv, mechanism_memory const *const __restrict__ mech)
#define EC_success
Successful time step.
__device__ void integrate(const double, const double, const double, double *const __restrict__, mechanism_memory const *const __restrict__, solver_memory const *const __restrict__)
__device__ void rkc_step(const Real t, const Real pr, const Real h, const Real *y_0, const Real *F_0, const int s, Real *y_j, Real *y_jm1, Real *y_jm2, mechanism_memory const *const __restrict__ mech)