Skip to content

Commit

Permalink
Added logic to mriStep_Init to handle checks for various adaptivity a…
Browse files Browse the repository at this point in the history
…pproaches, and to estimate slow/fast initial steps if needed
  • Loading branch information
drreynolds committed Jul 12, 2023
1 parent 4208369 commit 4a9f5d6
Show file tree
Hide file tree
Showing 4 changed files with 306 additions and 87 deletions.
82 changes: 42 additions & 40 deletions src/arkode/arkode.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,8 @@ int arkEvolve(ARKodeMem ark_mem, realtype tout, N_Vector yout,
ark_mem->root_mem->taskc = itask;
}

/* store copy of tout, in case it is required for stepper initialization */
ark_mem->tout = tout;

/* perform first-step-specific initializations:
- initialize tret values to initialization time
Expand Down Expand Up @@ -1802,8 +1804,8 @@ void arkFreeVectors(ARKodeMem ark_mem)
the first internal step after initialization, reinitialization,
a reset() call, or a resize() call, including:
- input consistency checks
- (re)initializes the stepper
- computes error and residual weights
- (re)initializes the stepper
- (re)initialize the interpolation structure
- checks for valid initial step input or estimates first step
- checks for approach to tstop
Expand All @@ -1815,26 +1817,6 @@ int arkInitialSetup(ARKodeMem ark_mem, realtype tout)
realtype tout_hin, htmp;
booleantype conOK;

/* Set up the time stepper module */
if (ark_mem->step_init == NULL) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE",
"arkInitialSetup", "Time stepper module is missing");
return(ARK_ILL_INPUT);
}
retval = ark_mem->step_init(ark_mem, ark_mem->init_type);
if (retval != ARK_SUCCESS) {
arkProcessError(ark_mem, retval, "ARKODE", "arkInitialSetup",
"Error in initialization of time stepper module");
return(retval);
}

/* Check that user has supplied an initial step size if fixedstep mode is on */
if ( (ark_mem->fixedstep) && (ark_mem->hin == ZERO) ) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup",
"Fixed step mode enabled, but no step size set");
return(ARK_ILL_INPUT);
}

/* If using a built-in routine for error/residual weights with abstol==0,
ensure that N_VMin is available */
if ((!ark_mem->user_efun) && (ark_mem->atolmin0) && (!ark_mem->yn->ops->nvmin)) {
Expand All @@ -1849,25 +1831,6 @@ int arkInitialSetup(ARKodeMem ark_mem, realtype tout)
return(ARK_ILL_INPUT);
}

/* Test input tstop for legality (correct direction of integration) */
if ( ark_mem->tstopset ) {
htmp = (ark_mem->h == ZERO) ? tout - ark_mem->tcur : ark_mem->h;
if ( (ark_mem->tstop - ark_mem->tcur) * htmp <= ZERO ) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup",
MSG_ARK_BAD_TSTOP, ark_mem->tstop, ark_mem->tcur);
return(ARK_ILL_INPUT);
}
}

/* Check to see if y0 satisfies constraints */
if (ark_mem->constraintsSet) {
conOK = N_VConstrMask(ark_mem->constraints, ark_mem->yn, ark_mem->tempv1);
if (!conOK) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup", MSG_ARK_Y0_FAIL_CONSTR);
return(ARK_ILL_INPUT);
}
}

/* Load initial error weights */
retval = ark_mem->efun(ark_mem->yn, ark_mem->ewt, ark_mem->e_data);
if (retval != 0) {
Expand Down Expand Up @@ -1896,6 +1859,45 @@ int arkInitialSetup(ARKodeMem ark_mem, realtype tout)
}
}

/* Set up the time stepper module */
if (ark_mem->step_init == NULL) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE",
"arkInitialSetup", "Time stepper module is missing");
return(ARK_ILL_INPUT);
}
retval = ark_mem->step_init(ark_mem, ark_mem->init_type);
if (retval != ARK_SUCCESS) {
arkProcessError(ark_mem, retval, "ARKODE", "arkInitialSetup",
"Error in initialization of time stepper module");
return(retval);
}

/* Check that user has supplied an initial step size if fixedstep mode is on */
if ( (ark_mem->fixedstep) && (ark_mem->hin == ZERO) ) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup",
"Fixed step mode enabled, but no step size set");
return(ARK_ILL_INPUT);
}

/* Test input tstop for legality (correct direction of integration) */
if ( ark_mem->tstopset ) {
htmp = (ark_mem->h == ZERO) ? tout - ark_mem->tcur : ark_mem->h;
if ( (ark_mem->tstop - ark_mem->tcur) * htmp <= ZERO ) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup",
MSG_ARK_BAD_TSTOP, ark_mem->tstop, ark_mem->tcur);
return(ARK_ILL_INPUT);
}
}

/* Check to see if y0 satisfies constraints */
if (ark_mem->constraintsSet) {
conOK = N_VConstrMask(ark_mem->constraints, ark_mem->yn, ark_mem->tempv1);
if (!conOK) {
arkProcessError(ark_mem, ARK_ILL_INPUT, "ARKODE", "arkInitialSetup", MSG_ARK_Y0_FAIL_CONSTR);
return(ARK_ILL_INPUT);
}
}

/* If necessary, temporarily set h as it is used to compute the tolerance in a
potential mass matrix solve when computing the full rhs */
if (ark_mem->h == ZERO) ark_mem->h = ONE;
Expand Down
1 change: 1 addition & 0 deletions src/arkode/arkode_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ typedef struct ARKodeMemRec {
realtype eta; /* eta = hprime / h */
realtype tcur; /* current internal value of t
(changes with each stage) */
realtype tout; /* user's requested output time */
realtype tretlast; /* value of tret last returned by ARKODE */
booleantype fixedstep; /* flag to disable temporal adaptivity */
SUNControl hcontroller; /* temporal error controller */
Expand Down
Loading

0 comments on commit 4a9f5d6

Please sign in to comment.