Skip to content

Commit

Permalink
Ran code formatter; generated F2003 interfaces for draft LSRKStep module
Browse files Browse the repository at this point in the history
  • Loading branch information
drreynolds committed Jul 12, 2024
1 parent 62bccbd commit 897b233
Show file tree
Hide file tree
Showing 14 changed files with 1,721 additions and 205 deletions.
4 changes: 2 additions & 2 deletions examples/arkode/C_serial/ark_analytic.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ int main(void)
printf(" Total number of Jacobian evaluations = %li\n", nje);
printf(" Total number of Newton iterations = %li\n", nni);
printf(" Total number of linear solver convergence failures = %li\n", ncfn);
printf(" Total number of error test failures = %li\n\n", netf);
printf(" \n");
printf(" Total number of error test failures = %li\n\n", netf);
printf(" \n");

/* check the solution error */
flag = check_ans(y, t, reltol, abstol);
Expand Down
11 changes: 4 additions & 7 deletions examples/arkode/C_serial/erk_analytic.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol,
sunrealtype atol);

/* Private function to compute error */
static int compute_error(N_Vector y, sunrealtype t);
static int compute_error(N_Vector y, sunrealtype t);

/* Main Program */
int main(void)
Expand All @@ -69,7 +69,7 @@ int main(void)
sunindextype NEQ = 1; /* number of dependent vars. */
sunrealtype reltol = SUN_RCONST(1.0e-8); /* tolerances */
sunrealtype abstol = SUN_RCONST(1.0e-8);
sunrealtype lambda = SUN_RCONST(-1.0); /* stiffness parameter */
sunrealtype lambda = SUN_RCONST(-1.0); /* stiffness parameter */

/* general problem variables */
int flag; /* reusable error-checking flag */
Expand Down Expand Up @@ -172,8 +172,8 @@ int main(void)
static int f(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data)
{
sunrealtype* rdata = (sunrealtype*)user_data; /* cast user_data to sunrealtype */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */

/* fill in the RHS function: "NV_Ith_S" accesses the 0th entry of ydot */
NV_Ith_S(ydot, 0) = lambda * u + SUN_RCONST(1.0) / (SUN_RCONST(1.0) + t * t) -
Expand Down Expand Up @@ -251,7 +251,6 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype at
return (passfail);
}


/* check the error */
static int compute_error(N_Vector y, sunrealtype t)
{
Expand All @@ -265,5 +264,3 @@ static int compute_error(N_Vector y, sunrealtype t)
}

/*---- end of file ----*/


21 changes: 10 additions & 11 deletions examples/arkode/C_serial/lsrk_analytic.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#include <math.h>
#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
#include <stdio.h>
#include <sundials/sundials_math.h> /* def. of SUNRsqrt, etc. */
#include <sundials/sundials_math.h> /* def. of SUNRsqrt, etc. */
#include <sundials/sundials_types.h> /* definition of type sunrealtype */

#if defined(SUNDIALS_EXTENDED_PRECISION)
Expand All @@ -60,7 +60,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol,
sunrealtype atol);

/* Private function to compute error */
static int compute_error(N_Vector y, sunrealtype t);
static int compute_error(N_Vector y, sunrealtype t);

/* Main Program */
int main(void)
Expand All @@ -72,7 +72,7 @@ int main(void)
sunindextype NEQ = 1; /* number of dependent vars. */
sunrealtype reltol = SUN_RCONST(1.0e-8); /* tolerances */
sunrealtype abstol = SUN_RCONST(1.0e-8);
sunrealtype lambda = SUN_RCONST(-1000000.0); /* stiffness parameter */
sunrealtype lambda = SUN_RCONST(-1000000.0); /* stiffness parameter */

/* general problem variables */
int flag; /* reusable error-checking flag */
Expand Down Expand Up @@ -188,9 +188,9 @@ int main(void)
flag = compute_error(y, t);

/* Clean up and return */
N_VDestroy(y); /* Free y vector */
N_VDestroy(y); /* Free y vector */
ARKStepFree(&arkode_mem); /* Free integrator memory */
SUNContext_Free(&ctx); /* Free context */
SUNContext_Free(&ctx); /* Free context */

return flag;
}
Expand All @@ -203,8 +203,8 @@ int main(void)
static int f(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data)
{
sunrealtype* rdata = (sunrealtype*)user_data; /* cast user_data to sunrealtype */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */

/* fill in the RHS function: "NV_Ith_S" accesses the 0th entry of ydot */
NV_Ith_S(ydot, 0) = lambda * u + SUN_RCONST(1.0) / (SUN_RCONST(1.0) + t * t) -
Expand All @@ -217,9 +217,9 @@ static int f(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data)
static int spr(sunrealtype t, sunrealtype* extsprad, void* user_data)
{
sunrealtype* rdata = (sunrealtype*)user_data; /* cast user_data to sunrealtype */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
*extsprad = lambda; /* access current solution value */
return 0; /* return with success */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter */
*extsprad = lambda; /* access current solution value */
return 0; /* return with success */
}

/*-------------------------------
Expand Down Expand Up @@ -291,7 +291,6 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype at
return (passfail);
}


/* check the error */
static int compute_error(N_Vector y, sunrealtype t)
{
Expand Down
30 changes: 16 additions & 14 deletions examples/arkode/C_serial/lsrk_analytic_VarJac.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <math.h>
#include <nvector/nvector_serial.h> /* serial N_Vector types, fcts., macros */
#include <stdio.h>
#include <sundials/sundials_math.h> /* def. of SUNRsqrt, etc. */
#include <sundials/sundials_math.h> /* def. of SUNRsqrt, etc. */
#include <sundials/sundials_types.h> /* definition of type sunrealtype */

#if defined(SUNDIALS_EXTENDED_PRECISION)
Expand All @@ -61,7 +61,7 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol,
sunrealtype atol);

/* Private function to compute error */
static int compute_error(N_Vector y, sunrealtype t);
static int compute_error(N_Vector y, sunrealtype t);

/* Main Program */
int main(void)
Expand All @@ -76,7 +76,8 @@ int main(void)
sunrealtype lambda = SUN_RCONST(-1.0e+6); /* stiffness parameter 1*/
sunrealtype alpha = SUN_RCONST(1.0e+2); /* stiffness parameter 2*/
sunrealtype UserData[2];
UserData[0] = lambda; UserData[1] = alpha;
UserData[0] = lambda;
UserData[1] = alpha;

/* general problem variables */
int flag; /* reusable error-checking flag */
Expand Down Expand Up @@ -189,9 +190,9 @@ int main(void)
flag = compute_error(y, t);

/* Clean up and return */
N_VDestroy(y); /* Free y vector */
N_VDestroy(y); /* Free y vector */
ARKStepFree(&arkode_mem); /* Free integrator memory */
SUNContext_Free(&ctx); /* Free context */
SUNContext_Free(&ctx); /* Free context */

return flag;
}
Expand All @@ -204,13 +205,14 @@ int main(void)
static int f(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data)
{
sunrealtype* rdata = (sunrealtype*)user_data; /* cast user_data to sunrealtype */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter 1 */
sunrealtype alpha = rdata[1]; /* set shortcut for stiffness parameter 2 */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter 1 */
sunrealtype alpha = rdata[1]; /* set shortcut for stiffness parameter 2 */
sunrealtype u = NV_Ith_S(y, 0); /* access current solution value */

/* fill in the RHS function: "NV_Ith_S" accesses the 0th entry of ydot */
NV_Ith_S(ydot, 0) = (lambda - alpha*cos((10 - t)/10*acos(-1))) * u + SUN_RCONST(1.0) / (SUN_RCONST(1.0) + t * t) -
(lambda - alpha*cos((10 - t)/10*acos(-1))) * atan(t);
NV_Ith_S(ydot, 0) = (lambda - alpha * cos((10 - t) / 10 * acos(-1))) * u +
SUN_RCONST(1.0) / (SUN_RCONST(1.0) + t * t) -
(lambda - alpha * cos((10 - t) / 10 * acos(-1))) * atan(t);

return 0; /* return with success */
}
Expand All @@ -219,9 +221,10 @@ static int f(sunrealtype t, N_Vector y, N_Vector ydot, void* user_data)
static int spr(sunrealtype t, sunrealtype* extsprad, void* user_data)
{
sunrealtype* rdata = (sunrealtype*)user_data; /* cast user_data to sunrealtype */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter 1 */
sunrealtype alpha = rdata[1]; /* set shortcut for stiffness parameter 2 */
*extsprad = (lambda - alpha*cos((10 - t)/10*acos(-1))); /* access current solution value */
sunrealtype lambda = rdata[0]; /* set shortcut for stiffness parameter 1 */
sunrealtype alpha = rdata[1]; /* set shortcut for stiffness parameter 2 */
*extsprad = (lambda - alpha * cos((10 - t) / 10 *
acos(-1))); /* access current solution value */
return 0; /* return with success */
}

Expand Down Expand Up @@ -294,7 +297,6 @@ static int check_ans(N_Vector y, sunrealtype t, sunrealtype rtol, sunrealtype at
return (passfail);
}


/* check the error */
static int compute_error(N_Vector y, sunrealtype t)
{
Expand Down
26 changes: 12 additions & 14 deletions include/arkode/arkode_lsrkstep.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
extern "C" {
#endif

typedef int (*ARKSprFn)(sunrealtype t, sunrealtype* extsprad,
void* user_data);

typedef int (*ARKSprFn)(sunrealtype t, sunrealtype* extsprad, void* user_data);

/* ------------------
* LSRKStep Constants
* ------------------ */
Expand All @@ -36,8 +35,8 @@ typedef int (*ARKSprFn)(sunrealtype t, sunrealtype* extsprad,

/* Creation and Reinitialization functions */

SUNDIALS_EXPORT void* LSRKStepCreate(ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0, N_Vector y0,
SUNContext sunctx);
SUNDIALS_EXPORT void* LSRKStepCreate(ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0,
N_Vector y0, SUNContext sunctx);

SUNDIALS_EXPORT int LSRKodeSetMethod(void* arkode_mem, int method);

Expand All @@ -49,10 +48,11 @@ SUNDIALS_EXPORT int LSRKodeSetSprRadFrequency(void* arkode_mem, int nsteps);

SUNDIALS_EXPORT int LSRKodeSetMaxStageNum(void* arkode_mem, int stagemaxlimit);

SUNDIALS_EXPORT int LSRKodeSetSprRadSafetyFactor(void* arkode_mem, sunrealtype sprsfty);
SUNDIALS_EXPORT int LSRKodeSetSprRadSafetyFactor(void* arkode_mem,
sunrealtype sprsfty);

SUNDIALS_EXPORT int LSRKStepReInit(void* arkode_mem, ARKRhsFn fe, ARKRhsFn fi, sunrealtype t0,
N_Vector y0);
SUNDIALS_EXPORT int LSRKStepReInit(void* arkode_mem, ARKRhsFn fe, ARKRhsFn fi,
sunrealtype t0, N_Vector y0);

/* Optional input functions -- must be called AFTER a creation routine above */

Expand All @@ -63,12 +63,10 @@ SUNDIALS_EXPORT int LSRKStepReInit(void* arkode_mem, ARKRhsFn fe, ARKRhsFn fi, s
SUNDIALS_EXPORT int LSRKStepGetNumRhsEvals(void* arkode_mem, long int* nfevals);

/* Grouped optional output functions */
SUNDIALS_EXPORT int LSRKStepGetTimestepperStats(void* arkode_mem, long int* expsteps,
long int* accsteps, long int* attempts,
long int* fevals, long int* sprfevals,
long int* netfails, long int* stagemax,
long int* nsprupdates,
sunrealtype* sprmax, sunrealtype* sprmin);
SUNDIALS_EXPORT int LSRKStepGetTimestepperStats(
void* arkode_mem, long int* expsteps, long int* accsteps, long int* attempts,
long int* fevals, long int* sprfevals, long int* netfails, long int* stagemax,
long int* nsprupdates, sunrealtype* sprmax, sunrealtype* sprmin);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 897b233

Please sign in to comment.