-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
1,262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
# ------------------------------------------------------------------------------ | ||
# Programmer(s): David J. Gardner @ LLNL | ||
# ------------------------------------------------------------------------------ | ||
# SUNDIALS Copyright Start | ||
# Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
# and Southern Methodist University. | ||
# All rights reserved. | ||
# | ||
# See the top-level LICENSE and NOTICE files for details. | ||
# | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
# SUNDIALS Copyright End | ||
# ------------------------------------------------------------------------------ | ||
|
||
# List of test tuples of the form "name\;args" | ||
set(unit_tests) | ||
|
||
# if(BUILD_ARKODE) | ||
# list(APPEND unit_tests "test_logging_arkode.cpp\;") | ||
# endif() | ||
|
||
if(BUILD_CVODE) | ||
list(APPEND unit_tests "test_logging_cvode.cpp\;1 1") # Newton + Dense | ||
list(APPEND unit_tests "test_logging_cvode.cpp\;1 0") # Newton + GMRES | ||
list(APPEND unit_tests "test_logging_cvode.cpp\;0") # Fixed-point | ||
endif() | ||
|
||
# if(BUILD_CVODES) | ||
# list(APPEND unit_tests "test_logging_cvodes.cpp\;") | ||
# endif() | ||
|
||
# if(BUILD_IDA) | ||
# list(APPEND unit_tests "test_logging_ida.cpp\;") | ||
# endif() | ||
|
||
# if(BUILD_IDAS) | ||
# list(APPEND unit_tests "test_logging_idas.cpp\;") | ||
# endif() | ||
|
||
# if(BUILD_KINSOL) | ||
# list(APPEND unit_tests "test_logging_kinsol.cpp\;") | ||
# endif() | ||
|
||
# Add the build and install targets for each test | ||
foreach(test_tuple ${unit_tests}) | ||
|
||
# parse the test tuple | ||
list(GET test_tuple 0 test_src) | ||
list(GET test_tuple 1 test_args) | ||
|
||
# extract the file name without extension | ||
get_filename_component(test_target ${test_src} NAME_WE) | ||
|
||
string(REGEX MATCH "arkode|cvode|cvodes|ida|idas|kinsol" _pkg ${test_target}) | ||
|
||
# check if this test has already been added, only need to add test source | ||
# files once for testing with different inputs | ||
if(NOT TARGET ${test_target}) | ||
|
||
# test source files | ||
add_executable(${test_target} ${test_src}) | ||
|
||
set_target_properties(${test_target} PROPERTIES FOLDER "unit_tests") | ||
|
||
# include location of public and private header files | ||
target_include_directories( | ||
${test_target} PRIVATE | ||
${CMAKE_SOURCE_DIR}/include | ||
${CMAKE_SOURCE_DIR}/test/unit_tests) | ||
|
||
# libraries to link against | ||
target_link_libraries(${test_target} sundials_${_pkg} sundials_nvecserial | ||
${EXE_EXTRA_LINK_LIBS}) | ||
|
||
endif() | ||
|
||
# Set the test name | ||
if(${SUNDIALS_LOGGING_LEVEL} GREATER 2) | ||
set(test_name "${test_target}_lvl${SUNDIALS_LOGGING_LEVEL}") | ||
else() | ||
set(test_name "${test_target}") | ||
endif() | ||
|
||
if("${test_args}" STREQUAL "") | ||
set(test_name ${test_name}) | ||
else() | ||
string(REPLACE " " "_" test_name "${test_name}_${test_args}") | ||
string(REPLACE " " ";" test_args "${test_args}") | ||
endif() | ||
|
||
# For now, only diff results with double precision | ||
# TODO(DJG): Update Jenkins diff handling for testing single/extended | ||
if(SUNDIALS_PRECISION MATCHES "DOUBLE") | ||
set(diff_output "") | ||
else() | ||
set(diff_output "NODIFF") | ||
endif() | ||
|
||
# add test to regression tests | ||
sundials_add_test( | ||
${test_name} ${test_target} | ||
TEST_ARGS ${test_args} | ||
ANSWER_DIR ${CMAKE_CURRENT_SOURCE_DIR} | ||
ANSWER_FILE ${test_name}.out | ||
EXAMPLE_TYPE "develop" | ||
LABELS "UnitTest" "Logging" | ||
${diff_output}) | ||
|
||
endforeach() | ||
|
||
message(STATUS "Added logging units tests") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* ----------------------------------------------------------------------------- | ||
* Programmer(s): David J. Gardner @ LLNL | ||
* ----------------------------------------------------------------------------- | ||
* SUNDIALS Copyright Start | ||
* Copyright (c) 2002-2024, Lawrence Livermore National Security | ||
* and Southern Methodist University. | ||
* All rights reserved. | ||
* | ||
* See the top-level LICENSE and NOTICE files for details. | ||
* | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
* SUNDIALS Copyright End | ||
* ----------------------------------------------------------------------------- | ||
* Test logging output | ||
* ---------------------------------------------------------------------------*/ | ||
|
||
#include <cmath> | ||
#include <cstdio> | ||
#include <iomanip> | ||
#include <iostream> | ||
#include <limits> | ||
|
||
// Include desired integrators, vectors, linear solvers, and nonlinear solvers | ||
#include "cvode/cvode.h" | ||
#include "nvector/nvector_serial.h" | ||
#include "sundials/sundials_context.hpp" | ||
#include "sundials/sundials_iterative.h" | ||
#include "sundials/sundials_logger.h" | ||
#include "sundials/sundials_matrix.h" | ||
#include "sundials/sundials_nonlinearsolver.h" | ||
#include "sunlinsol/sunlinsol_dense.h" | ||
#include "sunmatrix/sunmatrix_dense.h" | ||
#include "sunlinsol/sunlinsol_spgmr.h" | ||
#include "sunnonlinsol/sunnonlinsol_fixedpoint.h" | ||
|
||
#include "problems/kpr.hpp" | ||
#include "utilities/check_return.hpp" | ||
|
||
using namespace std; | ||
|
||
int main(int argc, char* argv[]) | ||
{ | ||
cout << "Start CVODE Logging test" << endl; | ||
|
||
// SUNDIALS context object for this simulation | ||
sundials::Context sunctx; | ||
|
||
// Use Newton (1) otherwise use fixed-point | ||
bool newton = true; | ||
if (argc > 1) { newton = stoi(argv[1]); } | ||
|
||
// Use direct dense solver (1) otherwise use GMRES | ||
bool direct = true; | ||
if (argc > 2) { direct = stoi(argv[2]); } | ||
|
||
// Ensure logging output goes to stdout | ||
SUNLogger logger; | ||
int flag = SUNContext_GetLogger(sunctx, &logger); | ||
if (check_flag(flag, "SUNContext_GetLogger")) { return 1; } | ||
|
||
SUNLogger_SetErrorFilename(logger, "stdout"); | ||
SUNLogger_SetWarningFilename(logger, "stdout"); | ||
SUNLogger_SetInfoFilename(logger, "stdout"); | ||
SUNLogger_SetDebugFilename(logger, "stdout"); | ||
|
||
// Create initial condition | ||
N_Vector y = N_VNew_Serial(2, sunctx); | ||
if (check_ptr(y, "N_VNew_Serial")) { return 1; } | ||
|
||
sunrealtype utrue, vtrue; | ||
flag = kpr_true_sol(ZERO, &utrue, &vtrue); | ||
if (check_flag(flag, "true_sol")) { return 1; } | ||
|
||
sunrealtype* ydata = N_VGetArrayPointer(y); | ||
ydata[0] = utrue; | ||
ydata[1] = vtrue; | ||
|
||
// Create CVODE memory structure | ||
void* cvode_mem = CVodeCreate(CV_BDF, sunctx); | ||
if (check_ptr(cvode_mem, "CVodeCreate")) { return 1; } | ||
|
||
flag = CVodeInit(cvode_mem, kpr_rhs, ZERO, y); | ||
if (check_flag(flag, "CVodeInit")) { return 1; } | ||
|
||
flag = CVodeSetUserData(cvode_mem, &kpr_udata); | ||
if (check_flag(flag, "CVodeSetUserData")) { return 1; } | ||
|
||
// Relative and absolute tolerances | ||
const sunrealtype rtol = SUN_RCONST(1.0e-6); | ||
const sunrealtype atol = SUN_RCONST(1.0e-10); | ||
|
||
flag = CVodeSStolerances(cvode_mem, rtol, atol); | ||
if (check_flag(flag, "CVodeSStolerances")) { return 1; } | ||
|
||
SUNNonlinearSolver NLS = nullptr; | ||
|
||
if (!newton) | ||
{ | ||
cout << "Using fixed-point nonlinear solver" << endl; | ||
|
||
NLS = SUNNonlinSol_FixedPoint(y, 0, sunctx); | ||
if (check_ptr(NLS, "SUNNonlinSol_FixedPoint")) { return 1; } | ||
|
||
flag = CVodeSetNonlinearSolver(cvode_mem, NLS); | ||
if (check_flag(flag, "CVodeSetLinearSolver")) { return 1; } | ||
} | ||
else | ||
{ | ||
cout << "Using Newton nonlinear solver" << endl; | ||
} | ||
|
||
SUNMatrix A = nullptr; | ||
SUNLinearSolver LS = nullptr; | ||
|
||
if (newton && direct) | ||
{ | ||
cout << "Using dense direct linear solver" << endl; | ||
|
||
A = SUNDenseMatrix(2, 2, sunctx); | ||
if (check_ptr(A, "SUNDenseMatrix")) { return 1; } | ||
|
||
LS = SUNLinSol_Dense(y, A, sunctx); | ||
if (check_ptr(LS, "SUNLinSol_Dense")) { return 1; } | ||
|
||
flag = CVodeSetLinearSolver(cvode_mem, LS, A); | ||
if (check_flag(flag, "CVodeSetLinearSolver")) { return 1; } | ||
|
||
flag = CVodeSetJacFn(cvode_mem, kpr_rhs_jac); | ||
if (check_flag(flag, "CVodeSetJacFn")) { return 1; } | ||
} | ||
else if (newton) | ||
{ | ||
cout << "Using GMRES iterative linear solver" << endl; | ||
|
||
LS = SUNLinSol_SPGMR(y, SUN_PREC_NONE, 0, sunctx); | ||
if (check_ptr(LS, "SUNLinSol_SPGMR")) { return 1; } | ||
|
||
flag = CVodeSetLinearSolver(cvode_mem, LS, A); | ||
if (check_flag(flag, "CVodeSetLinearSolver")) { return 1; } | ||
} | ||
|
||
// Initial time and fist output time | ||
const sunrealtype dtout = ONE; // output interval | ||
const int nout = 3; // number of outputs | ||
sunrealtype tret = ZERO; | ||
sunrealtype tout = tret + dtout; | ||
|
||
// Output initial contion | ||
cout << scientific; | ||
cout << setprecision(numeric_limits<sunrealtype>::digits10); | ||
cout << " t "; | ||
cout << " u "; | ||
cout << " v "; | ||
cout << " u err "; | ||
cout << " v err " << endl; | ||
for (int i = 0; i < 9; i++) { cout << "--------------"; } | ||
cout << endl; | ||
|
||
cout << setw(22) << tret << setw(25) << ydata[0] << setw(25) << ydata[1] | ||
<< setw(25) << abs(ydata[0] - utrue) << setw(25) << abs(ydata[1] - vtrue) | ||
<< endl; | ||
|
||
// Advance in time | ||
for (int i = 0; i < nout; i++) | ||
{ | ||
flag = CVode(cvode_mem, tout, y, &tret, CV_ONE_STEP); | ||
if (check_flag(flag, "CVode")) { return 1; } | ||
|
||
flag = kpr_true_sol(tret, &utrue, &vtrue); | ||
if (check_flag(flag, "true_sol")) { return 1; } | ||
|
||
cout << setw(22) << tret << setw(25) << ydata[0] << setw(25) << ydata[1] | ||
<< setw(25) << abs(ydata[0] - utrue) << setw(25) | ||
<< abs(ydata[1] - vtrue) << endl; | ||
|
||
// update output time | ||
tout += dtout; | ||
} | ||
for (int i = 0; i < 9; i++) { cout << "--------------"; } | ||
cout << endl; | ||
|
||
// Print some final statistics | ||
flag = CVodePrintAllStats(cvode_mem, stdout, SUN_OUTPUTFORMAT_TABLE); | ||
if (check_flag(flag, "CVodePrintAllStats")) { return 1; } | ||
|
||
// Clean up and return with successful completion | ||
N_VDestroy(y); | ||
SUNMatDestroy(A); | ||
SUNLinSolFree(LS); | ||
SUNNonlinSolFree(NLS); | ||
CVodeFree(&cvode_mem); | ||
|
||
cout << "End CVODE Logging test" << endl; | ||
|
||
return 0; | ||
} | ||
|
||
/*---- end of file ----*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
Start CVODE Logging test | ||
Using fixed-point nonlinear solver | ||
t u v u err v err | ||
------------------------------------------------------------------------------------------------------------------------------ | ||
0.000000000000000e+00 1.224744871391589e+00 1.732050807568877e+00 0.000000000000000e+00 0.000000000000000e+00 | ||
[INFO][rank 0][cvStep][begin-step-attempt] step = 1, t_n = 0, h = 0.0001029860256095084, q = 1 | ||
[INFO][rank 0][cvNls][begin-nonlinear-solve] tol = 0.2 | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][nonlinear-solver] solver = Fixed-Point | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = continue | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = success | ||
[INFO][rank 0][cvNls][end-nonlinear-solve] status = success, iters = 2 | ||
[INFO][rank 0][cvStep][end-step-attempt] status = success, dsm = 0.2499621899552651 | ||
1.029860256095084e-04 1.224744869195305e+00 1.732049582942475e+00 1.113801051388918e-09 6.122818017040288e-07 | ||
[INFO][rank 0][cvStep][begin-step-attempt] step = 2, t_n = 0.0001029860256095084, h = 0.0001029860256095084, q = 1 | ||
[INFO][rank 0][cvNls][begin-nonlinear-solve] tol = 0.2 | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][nonlinear-solver] solver = Fixed-Point | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = continue | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = success | ||
[INFO][rank 0][cvNls][end-nonlinear-solve] status = success, iters = 2 | ||
[INFO][rank 0][cvStep][end-step-attempt] status = success, dsm = 0.249962018079078 | ||
2.059720512190168e-04 1.224744864802767e+00 1.732047133691379e+00 2.258890852147033e-09 1.224500395968775e-06 | ||
[INFO][rank 0][cvStep][begin-step-attempt] step = 3, t_n = 0.0002059720512190168, h = 0.001029860256095084, q = 2 | ||
[INFO][rank 0][cvNls][begin-nonlinear-solve] tol = 0.4064516129032258 | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][nonlinear-solver] solver = Fixed-Point | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = continue | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = success | ||
[INFO][rank 0][cvNls][end-nonlinear-solve] status = success, iters = 2 | ||
[INFO][rank 0][cvStep][end-step-attempt] status = failed error test, dsm = 8.198472955140451, eflag = 5 | ||
[INFO][rank 0][cvStep][begin-step-attempt] step = 3, t_n = 0.0002059720512190168, h = 0.0002810714755410129, q = 2 | ||
[INFO][rank 0][cvNls][begin-nonlinear-solve] tol = 0.4217683315129505 | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][nonlinear-solver] solver = Fixed-Point | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = continue | ||
[INFO][rank 0][SUNNonlinSolSolve_FixedPoint][end-nonlinear-iterate] status = success | ||
[INFO][rank 0][cvNls][end-nonlinear-solve] status = success, iters = 2 | ||
[INFO][rank 0][cvStep][end-step-attempt] status = success, dsm = 0.5885921138418445 | ||
4.870435267600296e-04 1.224744841922327e+00 1.732034367982330e+00 5.258975033228808e-09 2.744234303353466e-06 | ||
------------------------------------------------------------------------------------------------------------------------------ | ||
Current time = 0.0004870435267600296 | ||
Steps = 3 | ||
Error test fails = 1 | ||
NLS step fails = 0 | ||
Initial step size = 0.0001029860256095084 | ||
Last step size = 0.0002810714755410129 | ||
Current step size = 0.0002810714755410129 | ||
Last method order = 2 | ||
Current method order = 2 | ||
Stab. lim. order reductions = 0 | ||
RHS fn evals = 11 | ||
NLS iters = 8 | ||
NLS fails = 0 | ||
NLS iters per step = 2.666666666666667 | ||
LS setups = 0 | ||
Root fn evals = 0 | ||
End CVODE Logging test |
Oops, something went wrong.