Skip to content

Commit

Permalink
remove old testing code
Browse files Browse the repository at this point in the history
  • Loading branch information
gardner48 committed Jul 7, 2023
1 parent 8ccad30 commit bef4d6f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 165 deletions.
79 changes: 1 addition & 78 deletions src/cvode/cvode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ int CVodeResizeHistory(void *cvode_mem, sunrealtype* t_hist, N_Vector* y_hist,
* Construct Nordsieck Array (new) *
* ------------------------------- */

/* >>>>> NOTE use use qprime + 1 not n_hist, so the interpolation order is
/* >>>>> NOTE use use q + 1 not n_hist, so the interpolation order is
correct even if more history than desired is provided <<<<< */

/* Compute interpolation coefficients */
Expand Down Expand Up @@ -1066,83 +1066,6 @@ int CVodeResizeHistory(void *cvode_mem, sunrealtype* t_hist, N_Vector* y_hist,
/* N_VPrint(cv_mem->cv_zn[ord]); */
/* } */

/* ------------------------------- *
* Construct Nordsieck Array (old) *
* ------------------------------- */

/* Test 0: Input y_hist is actually a copy of zn. Output should match that
from the problem without resizing except for the duplicated values. */
/* for (int j = 0; j <= maxord; j++) */
/* { */
/* N_VScale(ONE, y_hist[j], cv_mem->cv_zn[j]); */
/* } */

/* Test 1: Copy history but re-evaluate f */
/* for (int j = 0; j <= maxord; j++) */
/* { */
/* N_VScale(ONE, y_hist[j], cv_mem->cv_zn[j]); */
/* } */

/* retval = cv_mem->cv_f(t_hist[0], y_hist[0], */
/* cv_mem->cv_zn[1], cv_mem->cv_user_data); */
/* cv_mem->cv_nfe++; */
/* if (retval) */
/* { */
/* cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODE", "CVode", */
/* MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); */
/* return CV_RHSFUNC_FAIL; */
/* } */
/* N_VScale(cv_mem->cv_hscale, cv_mem->cv_zn[1], cv_mem->cv_zn[1]); */

/* Test 3: Copy yn, evaluate fn, and limit to first order (externally) */

/* /\* zn[0] = y_n-1 *\/ */
/* N_VScale(ONE, y_hist[0], cv_mem->cv_zn[0]); */

/* /\* zn[1] = h_n-1 * y'(t_n-1, y_n-1) *\/ */
/* retval = cv_mem->cv_f(t_hist[0], y_hist[0], */
/* cv_mem->cv_zn[1], cv_mem->cv_user_data); */
/* cv_mem->cv_nfe++; */
/* if (retval) */
/* { */
/* cvProcessError(cv_mem, CV_RHSFUNC_FAIL, "CVODE", "CVode", */
/* MSGCV_RHSFUNC_FAILED, cv_mem->cv_tn); */
/* return CV_RHSFUNC_FAIL; */
/* } */
/* N_VScale(cv_mem->cv_hscale, cv_mem->cv_zn[1], cv_mem->cv_zn[1]); */

/* for (int j = 2; j < maxord; j++) */
/* { */
/* N_VScale(ONE, y_hist[j], cv_mem->cv_zn[j]); */
/* } */

/* Test 3: Copy yn and evaluate fn (like above). Compute higher order
derivatives from polynomial interpolant */
/* sunrealtype a[4]; */

/* /\* (>= 2nd order) zn[2] = ((h_n-1)^2 / 2) * y''(t_n-1, y_n-1) *\/ */
/* if (cv_mem->cv_qprime >= 2) */
/* { */
/* for (int j = 0; j < 3; j++) a[j] = LBasisD2(j, t_hist[0], t_hist); */
/* N_VLinearCombination(3, a, y_hist, cv_mem->cv_zn[2]); */
/* N_VScale((cv_mem->cv_hscale * cv_mem->cv_hscale) / TWO, */
/* cv_mem->cv_zn[2], cv_mem->cv_zn[2]); */
/* } */

/* /\* (>= 3rd order) zn[3] = ((h_n-1)^3 / 6) * y'''(t_n-1, y_n-1) *\/ */
/* if (cv_mem->cv_qprime >= 3) */
/* { */
/* for (int j = 0; j < 4; j++) a[j] = LBasisD3(j, t_hist[0], t_hist); */
/* N_VLinearCombination(4, a, y_hist, cv_mem->cv_zn[3]); */
/* N_VScale((cv_mem->cv_hscale * cv_mem->cv_hscale * cv_mem->cv_hscale) / SUN_RCONST(6.0), */
/* cv_mem->cv_zn[3], cv_mem->cv_zn[3]); */
/* } */

/* >>>
Do we need to adjust q and qprime and not apply order change update?
Or should we just update Z and allow CVODE to proceed like normal?
<<< */

if (cv_mem->cv_VabstolMallocDone)
{
N_VDestroy(cv_mem->cv_Vabstol);
Expand Down
130 changes: 43 additions & 87 deletions test/unit_tests/cvode/CXX_serial/cv_test_resize_history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,6 @@ int main(int argc, char* argv[])
std::cout << "CVODE -- NO RESIZE" << std::endl;
}
else if (resize == 1)
{
std::cout << "CVODE -- COPY RESIZE" << std::endl;
}
else if (resize == 2)
{
std::cout << "CVODE -- RESIZE" << std::endl;
}
Expand Down Expand Up @@ -303,103 +299,63 @@ int main(int argc, char* argv[])

std::cout << "\n========== End Step " << i << " ==========\n";

if (resize == 1)
std::cout << "\n========== Start Resize " << i << " ==========\n";
// Update saved history
if (i < 6)
{
// Test 1: Copy and expand the Nordsieck array
N_VDestroy(y);
N_VDestroy(ytmp);
y = N_VNew_Serial(i + 1, sunctx);
ytmp = N_VClone(y);
N_Vector* znew = N_VCloneVectorArray(6, y);

for (int j = 0; j <= 5; j++)
{
sunrealtype* zdata = N_VGetArrayPointer(cv_mem->cv_zn[j]);
sunrealtype* znewdata = N_VGetArrayPointer(znew[j]);
for (int k = 0; k < i + 1; k++)
{
znewdata[k] = zdata[0];
}
}

flag = CVodeResizeHistory(cvode_mem, thist, znew, 6, resize_vec);
if (check_flag(flag, "CVodeResizeHistory")) return 1;
N_VDestroyVectorArray(znew, 6);

// "Resize" the nonlinear solver
SUNNonlinSolFree(NLS);
NLS = SUNNonlinSol_FixedPoint(y, 2, sunctx);
if (check_ptr(NLS, "SUNNonlinSol_FixedPoint")) return 1;

flag = CVodeSetNonlinearSolver(cvode_mem, NLS);
if (check_flag(flag, "CVodeSetNonlinearSolver")) return 1;

flag = CVodeSetMaxNonlinIters(cvode_mem, 10);
if (check_flag(flag, "CVodeSetMaxNonlinIters")) return 1;
hist_size++;
}
else if (resize == 2)
else
{
std::cout << "\n========== Start Resize " << i << " ==========\n";
// Test 2: Copy and expand the state
hist_size = 6;
}

// Update saved history
if (i < 6)
{
hist_size++;
}
else
{
hist_size = 6;
}
for (int j = 5; j > 0; j--)
{
thist[j] = thist[j - 1];
}
thist[0] = tret;

for (int j = 5; j > 0; j--)
{
thist[j] = thist[j - 1];
}
thist[0] = tret;
for (int j = 5; j > 0; j--)
{
N_VScale(ONE, yhist[j - 1], yhist[j]);
}
N_VScale(ONE, y, yhist[0]);

for (int j = 5; j > 0; j--)
{
N_VScale(ONE, yhist[j - 1], yhist[j]);
}
N_VScale(ONE, y, yhist[0]);
// Resize all vectors
for (int j = 0; j < 6; j++)
{
sunrealtype* old_data = N_VGetArrayPointer(yhist[j]);

// Resize all vectors
for (int j = 0; j < 6; j++)
N_Vector new_vec = N_VNew_Serial(i + 1, sunctx);
sunrealtype* new_data = N_VGetArrayPointer(new_vec);
for (int k = 0; k < i + 1; k++)
{
sunrealtype* old_data = N_VGetArrayPointer(yhist[j]);

N_Vector new_vec = N_VNew_Serial(i + 1, sunctx);
sunrealtype* new_data = N_VGetArrayPointer(new_vec);
for (int k = 0; k < i + 1; k++)
{
new_data[k] = old_data[0];
}
N_VDestroy(yhist[j]);
yhist[j] = new_vec;
new_data[k] = old_data[0];
}
N_VDestroy(yhist[j]);
yhist[j] = new_vec;
}

N_VDestroy(y);
N_VDestroy(ytmp);
y = N_VNew_Serial(i + 1, sunctx);
ytmp = N_VClone(y);

flag = CVodeResizeHistory(cvode_mem, thist, yhist, hist_size, resize_vec);
if (check_flag(flag, "CVodeResizeHistory")) return 1;
N_VDestroy(y);
N_VDestroy(ytmp);
y = N_VNew_Serial(i + 1, sunctx);
ytmp = N_VClone(y);

// "Resize" the nonlinear solver
SUNNonlinSolFree(NLS);
NLS = SUNNonlinSol_FixedPoint(y, 2, sunctx);
if (check_ptr(NLS, "SUNNonlinSol_FixedPoint")) return 1;
flag = CVodeResizeHistory(cvode_mem, thist, yhist, hist_size, resize_vec);
if (check_flag(flag, "CVodeResizeHistory")) return 1;

flag = CVodeSetNonlinearSolver(cvode_mem, NLS);
if (check_flag(flag, "CVodeSetNonlinearSolver")) return 1;
// "Resize" the nonlinear solver
SUNNonlinSolFree(NLS);
NLS = SUNNonlinSol_FixedPoint(y, 2, sunctx);
if (check_ptr(NLS, "SUNNonlinSol_FixedPoint")) return 1;

flag = CVodeSetMaxNonlinIters(cvode_mem, 10);
if (check_flag(flag, "CVodeSetMaxNonlinIters")) return 1;
std::cout << "\n========== End Resize " << i << " ==========\n";
}
flag = CVodeSetNonlinearSolver(cvode_mem, NLS);
if (check_flag(flag, "CVodeSetNonlinearSolver")) return 1;

flag = CVodeSetMaxNonlinIters(cvode_mem, 10);
if (check_flag(flag, "CVodeSetMaxNonlinIters")) return 1;
std::cout << "\n========== End Resize " << i << " ==========\n";
}
std::cout << std::endl;

Expand Down

0 comments on commit bef4d6f

Please sign in to comment.