diff --git a/doc/kinsol/guide/source/Introduction.rst b/doc/kinsol/guide/source/Introduction.rst index eb8183fba0..114273b07b 100644 --- a/doc/kinsol/guide/source/Introduction.rst +++ b/doc/kinsol/guide/source/Introduction.rst @@ -187,6 +187,12 @@ Users now need to link to ``sundials_core`` in addition to the libraries already This will be picked up automatically in projects that use the SUNDIALS CMake target. The library ``sundials_generic`` has been superceded by ``sundials_core`` and is no longer available. This fixes some duplicate symbol errors on Windows when linking to multiple SUNDIALS libraries. +**Breaking change** +The functions ``KINSetErrFile`` and ``KINSetHandlerErrFn`` have been removed. +Users of these functions can use the functions :c:func:`SUNContext_PushErrHandler`, +and :c:func:`SUNLogger_SetErrorFilename` instead. For further details see +Sections :numref:`SUNDIALS.Errors` and :numref:`SUNDIALS.Logging`. + Changes in v6.6.2 ----------------- diff --git a/doc/kinsol/guide/source/Usage/index.rst b/doc/kinsol/guide/source/Usage/index.rst index d32ccf69d8..294e9d72d3 100644 --- a/doc/kinsol/guide/source/Usage/index.rst +++ b/doc/kinsol/guide/source/Usage/index.rst @@ -458,10 +458,6 @@ negative, so a test ``retval`` :math:`<0` will catch any error. +========================================================+==================================+==============================+ | **KINSOL main solver** | | | +--------------------------------------------------------+----------------------------------+------------------------------+ - | Error handler function | :c:func:`KINSetErrHandlerFn` | internal fn. | - +--------------------------------------------------------+----------------------------------+------------------------------+ - | Pointer to an error file | :c:func:`KINSetErrFile` | ``stderr`` | - +--------------------------------------------------------+----------------------------------+------------------------------+ | Info handler function | :c:func:`KINSetInfoHandlerFn` | internal fn. | +--------------------------------------------------------+----------------------------------+------------------------------+ | Data for problem-defining function | :c:func:`KINSetUserData` | ``NULL`` | @@ -527,57 +523,6 @@ negative, so a test ``retval`` :math:`<0` will catch any error. +--------------------------------------------------------+----------------------------------+------------------------------+ -.. c:function:: int KINSetErrFile(void * kin_mem, FILE * errfp) - - The function :c:func:`KINSetErrFile` specifies the pointer to the file where - all KINSOL messages should be directed when the default KINSOL error handler - function is used. - - **Arguments:** - * ``kin_mem`` -- pointer to the KINSOL memory block. - * ``errfp`` -- pointer to output file. - - **Return value:** - * ``KIN_SUCCESS`` -- The optional value has been successfully set. - * ``KIN_MEM_NULL`` -- The ``kin_mem`` pointer is ``NULL``. - - **Notes:** - The default value for ``errfp`` is ``stderr``. - - Passing a value of - ``NULL`` disables all future error message output (except for the case in - which the KINSOL memory pointer is ``NULL``). This use of - :c:func:`KINSetErrFile` is strongly discouraged. - - .. warning:: - If :c:func:`KINSetErrFile` is to be called, it should be called before any - other optional input functions, in order to take effect for any later - error message. - - -.. c:function:: int KINSetErrHandlerFn(void * kin_mem, KINErrHandlerFn ehfun, void * eh_data) - - The function :c:func:`KINSetErrHandlerFn` specifies the optional user-defined - function to be used in handling error messages. - - **Arguments:** - * ``kin_mem`` -- pointer to the KINSOL memory block. - * ``ehfun`` -- is the user's CC error handler function (see :numref:`KINSOL.Usage.CC.user_fct_sim.ehFn`). - * ``eh_data`` -- pointer to user data passed to ``ehfun`` every time it is called. - - **Return value:** - * ``KIN_SUCCESS`` -- The function ``ehfun`` and data pointer ``eh_data`` have been successfully set. - * ``KIN_MEM_NULL`` -- The ``kin_mem`` pointer is ``NULL``. - - **Notes:** - The default internal error handler function directs error messages to the - file specified by the file pointer ``errfp`` (see :c:func:`KINSetErrFile` - above). - - Error messages indicating that the KINSOL solver memory is - ``NULL`` will always be directed to ``stderr``. - - .. c:function:: int KINSetUserData(void * kin_mem, void * user_data) The function :c:func:`KINSetUserData` specifies the pointer to user-defined @@ -1869,38 +1814,6 @@ The user must provide a function of type :c:type:`KINSysFn` defined as follows: Allocation of memory for ``fval`` is handled within KINSOL. -.. _KINSOL.Usage.CC.user_fct_sim.ehFn: - -Error message handler function -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -As an alternative to the default behavior of directing error and warning -messages to the file pointed to by ``errfp`` (see :c:func:`KINSetErrFile`), the -user may provide a function of type :c:type:`KINErrHandlerFn` to process any -such messages. The function type :c:type:`KINErrHandlerFn` is defined as -follows: - -.. c:type:: void (*KINErrHandlerFn)(int error_code, const char *module, const char *function, char *msg, void *user_data) - - This function processes error and warning messages from KINSOL and its - sub-modules. - - **Arguments:** - * ``error_code`` -- is the error code - * ``module`` -- is the name of the KINSOL module reporting the error - * ``function`` -- is the name of the function in which the error occurred - * ``eH_data`` -- is a pointer to user data, the same as the ``eh_data`` - parameter passed to :c:func:`KINSetErrHandlerFn` - - **Return value:** - This function has no return value. - - **Notes:** - ``error_code`` is negative for errors and positive (``KIN_WARNING``) for - warnings. If a function that returns a pointer to memory encounters an error, - it sets ``error_code`` to 0. - - .. _KINSOL.Usage.CC.user_fct_sim.jacFn: Jacobian construction (matrix-based linear solvers) diff --git a/include/kinsol/kinsol.h b/include/kinsol/kinsol.h index 9d9fc30eae..7d4a0131a8 100644 --- a/include/kinsol/kinsol.h +++ b/include/kinsol/kinsol.h @@ -82,9 +82,6 @@ extern "C" { typedef int (*KINSysFn)(N_Vector uu, N_Vector fval, void* user_data); -typedef void (*KINErrHandlerFn)(int error_code, const char* module, - const char* function, char* msg, void* user_data); - typedef void (*KINInfoHandlerFn)(const char* module, const char* function, char* msg, void* user_data); @@ -131,11 +128,6 @@ SUNDIALS_EXPORT int KINSetScaledStepTol(void* kinmem, sunrealtype scsteptol); SUNDIALS_EXPORT int KINSetConstraints(void* kinmem, N_Vector constraints); SUNDIALS_EXPORT int KINSetSysFunc(void* kinmem, KINSysFn func); -/* Optional input functions for handling error events */ -SUNDIALS_EXPORT int KINSetErrHandlerFn(void* kinmem, KINErrHandlerFn ehfun, - void* eh_data); -SUNDIALS_EXPORT int KINSetErrFile(void* kinmem, FILE* errfp); - /* Optional output functions */ SUNDIALS_EXPORT int KINGetWorkSpace(void* kinmem, long int* lenrw, long int* leniw); diff --git a/src/kinsol/fmod/fkinsol_mod.c b/src/kinsol/fmod/fkinsol_mod.c index f7ecc29115..8dbffc3c0d 100644 --- a/src/kinsol/fmod/fkinsol_mod.c +++ b/src/kinsol/fmod/fkinsol_mod.c @@ -637,36 +637,6 @@ SWIGEXPORT int _wrap_FKINSetSysFunc(void *farg1, KINSysFn farg2) { } -SWIGEXPORT int _wrap_FKINSetErrHandlerFn(void *farg1, KINErrHandlerFn farg2, void *farg3) { - int fresult ; - void *arg1 = (void *) 0 ; - KINErrHandlerFn arg2 = (KINErrHandlerFn) 0 ; - void *arg3 = (void *) 0 ; - int result; - - arg1 = (void *)(farg1); - arg2 = (KINErrHandlerFn)(farg2); - arg3 = (void *)(farg3); - result = (int)KINSetErrHandlerFn(arg1,arg2,arg3); - fresult = (int)(result); - return fresult; -} - - -SWIGEXPORT int _wrap_FKINSetErrFile(void *farg1, void *farg2) { - int fresult ; - void *arg1 = (void *) 0 ; - FILE *arg2 = (FILE *) 0 ; - int result; - - arg1 = (void *)(farg1); - arg2 = (FILE *)(farg2); - result = (int)KINSetErrFile(arg1,arg2); - fresult = (int)(result); - return fresult; -} - - SWIGEXPORT int _wrap_FKINGetWorkSpace(void *farg1, long *farg2, long *farg3) { int fresult ; void *arg1 = (void *) 0 ; diff --git a/src/kinsol/fmod/fkinsol_mod.f90 b/src/kinsol/fmod/fkinsol_mod.f90 index 7a3c23d6cf..7d93e718ae 100644 --- a/src/kinsol/fmod/fkinsol_mod.f90 +++ b/src/kinsol/fmod/fkinsol_mod.f90 @@ -99,8 +99,6 @@ module fkinsol_mod public :: FKINSetScaledStepTol public :: FKINSetConstraints public :: FKINSetSysFunc - public :: FKINSetErrHandlerFn - public :: FKINSetErrFile public :: FKINGetWorkSpace public :: FKINGetNumNonlinSolvIters public :: FKINGetNumFuncEvals @@ -408,25 +406,6 @@ function swigc_FKINSetSysFunc(farg1, farg2) & integer(C_INT) :: fresult end function -function swigc_FKINSetErrHandlerFn(farg1, farg2, farg3) & -bind(C, name="_wrap_FKINSetErrHandlerFn") & -result(fresult) -use, intrinsic :: ISO_C_BINDING -type(C_PTR), value :: farg1 -type(C_FUNPTR), value :: farg2 -type(C_PTR), value :: farg3 -integer(C_INT) :: fresult -end function - -function swigc_FKINSetErrFile(farg1, farg2) & -bind(C, name="_wrap_FKINSetErrFile") & -result(fresult) -use, intrinsic :: ISO_C_BINDING -type(C_PTR), value :: farg1 -type(C_PTR), value :: farg2 -integer(C_INT) :: fresult -end function - function swigc_FKINGetWorkSpace(farg1, farg2, farg3) & bind(C, name="_wrap_FKINGetWorkSpace") & result(fresult) @@ -1189,41 +1168,6 @@ function FKINSetSysFunc(kinmem, func) & swig_result = fresult end function -function FKINSetErrHandlerFn(kinmem, ehfun, eh_data) & -result(swig_result) -use, intrinsic :: ISO_C_BINDING -integer(C_INT) :: swig_result -type(C_PTR) :: kinmem -type(C_FUNPTR), intent(in), value :: ehfun -type(C_PTR) :: eh_data -integer(C_INT) :: fresult -type(C_PTR) :: farg1 -type(C_FUNPTR) :: farg2 -type(C_PTR) :: farg3 - -farg1 = kinmem -farg2 = ehfun -farg3 = eh_data -fresult = swigc_FKINSetErrHandlerFn(farg1, farg2, farg3) -swig_result = fresult -end function - -function FKINSetErrFile(kinmem, errfp) & -result(swig_result) -use, intrinsic :: ISO_C_BINDING -integer(C_INT) :: swig_result -type(C_PTR) :: kinmem -type(C_PTR) :: errfp -integer(C_INT) :: fresult -type(C_PTR) :: farg1 -type(C_PTR) :: farg2 - -farg1 = kinmem -farg2 = errfp -fresult = swigc_FKINSetErrFile(farg1, farg2) -swig_result = fresult -end function - function FKINGetWorkSpace(kinmem, lenrw, leniw) & result(swig_result) use, intrinsic :: ISO_C_BINDING diff --git a/src/kinsol/kinsol.c b/src/kinsol/kinsol.c index be8b841ace..d85b0fd702 100644 --- a/src/kinsol/kinsol.c +++ b/src/kinsol/kinsol.c @@ -51,7 +51,6 @@ * KINPrintInfo * KINSOL Error Handling functions * KINProcessError - * KINErrHandler * ---------------------------------------------------------------------------*/ /* @@ -60,6 +59,8 @@ * ================================================================= */ +#include "kinsol/kinsol.h" + #include #include #include @@ -68,6 +69,7 @@ #include #include "kinsol_impl.h" +#include "sundials/priv/sundials_errors_impl.h" /* * ================================================================= @@ -214,7 +216,7 @@ void* KINCreate(SUNContext sunctx) /* Test inputs */ if (sunctx == NULL) { - KINProcessError(NULL, 0, "KIN", "KINCreate", MSG_NULL_SUNCTX); + KINProcessError(NULL, 0, __LINE__, __func__, __FILE__, MSG_NULL_SUNCTX); return (NULL); } @@ -222,7 +224,7 @@ void* KINCreate(SUNContext sunctx) kin_mem = (KINMem)malloc(sizeof(struct KINMemRec)); if (kin_mem == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINCreate", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); return (NULL); } @@ -272,8 +274,6 @@ void* KINCreate(SUNContext sunctx) kin_mem->kin_beta_aa = ONE; kin_mem->kin_damping_aa = SUNFALSE; kin_mem->kin_constraintsSet = SUNFALSE; - kin_mem->kin_ehfun = KINErrHandler; - kin_mem->kin_eh_data = kin_mem; kin_mem->kin_ret_newest = SUNFALSE; kin_mem->kin_mxiter = MXITER_DEFAULT; kin_mem->kin_noInitSetup = SUNFALSE; @@ -298,11 +298,6 @@ void* KINCreate(SUNContext sunctx) kin_mem->kin_omega_min = OMEGA_MIN; kin_mem->kin_omega_max = OMEGA_MAX; - kin_mem->kin_errfp = stderr; -#if SUNDIALS_LOGGING_LEVEL > 0 - kin_mem->kin_errfp = (KIN_LOGGER->error_fp) ? KIN_LOGGER->error_fp : stderr; -#endif - /* initialize lrw and liw */ kin_mem->kin_lrw = 17; @@ -335,7 +330,7 @@ int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINInit", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } kin_mem = (KINMem)kinmem; @@ -344,7 +339,8 @@ int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl) if (func == NULL) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINInit", MSG_FUNC_NULL); + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_FUNC_NULL); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_ILL_INPUT); } @@ -354,7 +350,8 @@ int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl) nvectorOK = KINCheckNvector(tmpl); if (!nvectorOK) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINInit", MSG_BAD_NVECTOR); + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_NVECTOR); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_ILL_INPUT); } @@ -378,7 +375,8 @@ int KINInit(void* kinmem, KINSysFn func, N_Vector tmpl) allocOK = KINAllocVectors(kin_mem, tmpl); if (!allocOK) { - KINProcessError(kin_mem, KIN_MEM_FAIL, "KINSOL", "KINInit", MSG_MEM_FAIL); + KINProcessError(kin_mem, KIN_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); free(kin_mem); kin_mem = NULL; SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); @@ -495,7 +493,7 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSol", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } kin_mem = (KINMem)kinmem; @@ -504,7 +502,8 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, if (kin_mem->kin_MallocDone == SUNFALSE) { - KINProcessError(NULL, KIN_NO_MALLOC, "KINSOL", "KINSol", MSG_NO_MALLOC); + KINProcessError(kin_mem, KIN_NO_MALLOC, __LINE__, __func__, __FILE__, + MSG_NO_MALLOC); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_NO_MALLOC); } @@ -523,14 +522,15 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, { if (kin_mem->kin_uu == NULL) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSol", MSG_UU_NULL); + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_UU_NULL); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_ILL_INPUT); } if (kin_mem->kin_constraintsSet != SUNFALSE) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_CONSTRAINTS_NOTOK); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_ILL_INPUT); @@ -548,12 +548,12 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, switch (ret) { case KIN_SYSFUNC_FAIL: - KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_SYSFUNC_FAILED); break; case KIN_MAXITER_REACHED: - KINProcessError(kin_mem, KIN_MAXITER_REACHED, "KINSOL", "KINSol", - MSG_MAXITER_REACHED); + KINProcessError(kin_mem, KIN_MAXITER_REACHED, __LINE__, __func__, + __FILE__, MSG_MAXITER_REACHED); break; } @@ -602,7 +602,8 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, kin_mem->kin_gval = N_VClone(kin_mem->kin_unew); if (kin_mem->kin_gval == NULL) { - KINProcessError(kin_mem, KIN_MEM_FAIL, "KINSOL", "KINSol", MSG_MEM_FAIL); + KINProcessError(kin_mem, KIN_MEM_FAIL, __LINE__, __func__, __FILE__, + MSG_MEM_FAIL); SUNDIALS_MARK_FUNCTION_END(KIN_PROFILER); return (KIN_MEM_FAIL); } @@ -714,8 +715,6 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, if (ret != CONTINUE_ITERATIONS) { break; } - fflush(kin_mem->kin_errfp); - } /* end of loop; return */ #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGLEVEL_INFO @@ -725,40 +724,40 @@ int KINSol(void* kinmem, N_Vector u, int strategy_in, N_Vector u_scale, switch (ret) { case KIN_SYSFUNC_FAIL: - KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_SYSFUNC_FAILED); break; case KIN_REPTD_SYSFUNC_ERR: - KINProcessError(kin_mem, KIN_REPTD_SYSFUNC_ERR, "KINSOL", "KINSol", - MSG_SYSFUNC_REPTD); + KINProcessError(kin_mem, KIN_REPTD_SYSFUNC_ERR, __LINE__, __func__, + __FILE__, MSG_SYSFUNC_REPTD); break; case KIN_LSETUP_FAIL: - KINProcessError(kin_mem, KIN_LSETUP_FAIL, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_LSETUP_FAIL, __LINE__, __func__, __FILE__, MSG_LSETUP_FAILED); break; case KIN_LSOLVE_FAIL: - KINProcessError(kin_mem, KIN_LSOLVE_FAIL, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_LSOLVE_FAIL, __LINE__, __func__, __FILE__, MSG_LSOLVE_FAILED); break; case KIN_LINSOLV_NO_RECOVERY: - KINProcessError(kin_mem, KIN_LINSOLV_NO_RECOVERY, "KINSOL", "KINSol", - MSG_LINSOLV_NO_RECOVERY); + KINProcessError(kin_mem, KIN_LINSOLV_NO_RECOVERY, __LINE__, __func__, + __FILE__, MSG_LINSOLV_NO_RECOVERY); break; case KIN_LINESEARCH_NONCONV: - KINProcessError(kin_mem, KIN_LINESEARCH_NONCONV, "KINSOL", "KINSol", - MSG_LINESEARCH_NONCONV); + KINProcessError(kin_mem, KIN_LINESEARCH_NONCONV, __LINE__, __func__, + __FILE__, MSG_LINESEARCH_NONCONV); break; case KIN_LINESEARCH_BCFAIL: - KINProcessError(kin_mem, KIN_LINESEARCH_BCFAIL, "KINSOL", "KINSol", - MSG_LINESEARCH_BCFAIL); + KINProcessError(kin_mem, KIN_LINESEARCH_BCFAIL, __LINE__, __func__, + __FILE__, MSG_LINESEARCH_BCFAIL); break; case KIN_MAXITER_REACHED: - KINProcessError(kin_mem, KIN_MAXITER_REACHED, "KINSOL", "KINSol", + KINProcessError(kin_mem, KIN_MAXITER_REACHED, __LINE__, __func__, __FILE__, MSG_MAXITER_REACHED); break; case KIN_MXNEWT_5X_EXCEEDED: - KINProcessError(kin_mem, KIN_MXNEWT_5X_EXCEEDED, "KINSOL", "KINSol", - MSG_MXNEWT_5X_EXCEEDED); + KINProcessError(kin_mem, KIN_MXNEWT_5X_EXCEEDED, __LINE__, __func__, + __FILE__, MSG_MXNEWT_5X_EXCEEDED); break; } @@ -928,7 +927,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) (kin_mem->kin_m_aa * kin_mem->kin_m_aa) * sizeof(sunrealtype)); if (kin_mem->kin_R_aa == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); N_VDestroy(kin_mem->kin_pp); @@ -946,7 +945,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) (sunrealtype*)malloc(kin_mem->kin_m_aa * sizeof(sunrealtype)); if (kin_mem->kin_gamma_aa == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); N_VDestroy(kin_mem->kin_pp); @@ -965,7 +964,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) (long int*)malloc(kin_mem->kin_m_aa * sizeof(long int)); if (kin_mem->kin_ipt_map == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); N_VDestroy(kin_mem->kin_pp); @@ -985,7 +984,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) (sunrealtype*)malloc(2 * (kin_mem->kin_m_aa + 1) * sizeof(sunrealtype)); if (kin_mem->kin_cv == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); N_VDestroy(kin_mem->kin_pp); @@ -1006,7 +1005,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) (N_Vector*)malloc(2 * (kin_mem->kin_m_aa + 1) * sizeof(N_Vector)); if (kin_mem->kin_Xv == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", MSG_MEM_FAIL); + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); N_VDestroy(kin_mem->kin_pp); @@ -1214,7 +1213,7 @@ static sunbooleantype KINAllocVectors(KINMem kin_mem, N_Vector tmpl) ((kin_mem->kin_m_aa * kin_mem->kin_m_aa)) * sizeof(sunrealtype)); if (kin_mem->kin_T_aa == NULL) { - KINProcessError(kin_mem, 0, "KINSOL", "KINAllocVectors", + KINProcessError(kin_mem, 0, __LINE__, __func__, __FILE__, MSG_MEM_FAIL); N_VDestroy(kin_mem->kin_unew); N_VDestroy(kin_mem->kin_fval); @@ -1414,9 +1413,7 @@ static void KINFreeVectors(KINMem kin_mem) * * KINSolInit initializes the problem for the specific input * received in this call to KINSol (which calls KINSolInit). All - * problem specification inputs are checked for errors. If any error - * occurs during initialization, it is reported to the file whose - * file pointer is errfp. + * problem specification inputs are checked for errors. * * The possible return values for KINSolInit are: * KIN_SUCCESS : indicates a normal initialization @@ -1437,7 +1434,8 @@ static int KINSolInit(KINMem kin_mem) if (kin_mem->kin_uu == NULL) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", MSG_UU_NULL); + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_UU_NULL); return (KIN_ILL_INPUT); } @@ -1448,35 +1446,35 @@ static int KINSolInit(KINMem kin_mem) (kin_mem->kin_globalstrategy != KIN_PICARD) && (kin_mem->kin_globalstrategy != KIN_FP)) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_GLSTRAT); return (KIN_ILL_INPUT); } if (kin_mem->kin_uscale == NULL) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_USCALE); return (KIN_ILL_INPUT); } if (N_VMin(kin_mem->kin_uscale) <= ZERO) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_USCALE_NONPOSITIVE); return (KIN_ILL_INPUT); } if (kin_mem->kin_fscale == NULL) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_FSCALE); return (KIN_ILL_INPUT); } if (N_VMin(kin_mem->kin_fscale) <= ZERO) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_FSCALE_NONPOSITIVE); return (KIN_ILL_INPUT); } @@ -1485,7 +1483,7 @@ static int KINSolInit(KINMem kin_mem) ((kin_mem->kin_globalstrategy == KIN_PICARD) || (kin_mem->kin_globalstrategy == KIN_FP))) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_CONSTRAINTS_NOTOK); return (KIN_ILL_INPUT); } @@ -1502,7 +1500,7 @@ static int KINSolInit(KINMem kin_mem) if ((kin_mem->kin_constraints->ops->nvconstrmask == NULL) || (kin_mem->kin_constraints->ops->nvminquotient == NULL)) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_NVECTOR); return (KIN_ILL_INPUT); } @@ -1515,7 +1513,7 @@ static int KINSolInit(KINMem kin_mem) if (!N_VConstrMask(kin_mem->kin_constraints, kin_mem->kin_uu, kin_mem->kin_vtemp1)) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_INITIAL_CNSTRNT); return (KIN_ILL_INPUT); } @@ -1576,14 +1574,14 @@ static int KINSolInit(KINMem kin_mem) if (retval < 0) { - KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_SYSFUNC_FAIL, __LINE__, __func__, __FILE__, MSG_SYSFUNC_FAILED); return (KIN_SYSFUNC_FAIL); } else if (retval > 0) { - KINProcessError(kin_mem, KIN_FIRST_SYSFUNC_ERR, "KINSOL", "KINSolInit", - MSG_SYSFUNC_FIRST); + KINProcessError(kin_mem, KIN_FIRST_SYSFUNC_ERR, __LINE__, __func__, + __FILE__, MSG_SYSFUNC_FIRST); return (KIN_FIRST_SYSFUNC_ERR); } @@ -1605,7 +1603,7 @@ static int KINSolInit(KINMem kin_mem) retval = kin_mem->kin_linit(kin_mem); if (retval != 0) { - KINProcessError(kin_mem, KIN_LINIT_FAIL, "KINSOL", "KINSolInit", + KINProcessError(kin_mem, KIN_LINIT_FAIL, __LINE__, __func__, __FILE__, MSG_LINIT_FAIL); return (KIN_LINIT_FAIL); } @@ -2562,75 +2560,50 @@ void KINPrintInfo(KINMem kin_mem, int info_code, const char* module, * ================================================================= */ -/* - * KINProcessError - * - * KINProcessError is a high level error handling function. - * - If cv_mem==NULL it prints the error message to stderr. - * - Otherwise, it sets up and calls the error handling function - * pointed to by cv_ehfun. - */ - -void KINProcessError(KINMem kin_mem, int error_code, const char* module, - const char* fname, const char* msgfmt, ...) +void KINProcessError(KINMem kin_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...) { - va_list ap; - char msg[256]; + SUNFunctionBegin(kin_mem->kin_sunctx); /* Initialize the argument pointer variable (msgfmt is the last required argument to KINProcessError) */ - + va_list ap; va_start(ap, msgfmt); /* Compose the message */ + size_t msglen = vsnprintf(NULL, 0, msgfmt, ap) + 1; + char* msg = (char*)malloc(msglen); + vsnprintf(msg, msglen, msgfmt, ap); - vsprintf(msg, msgfmt, ap); + do { + if (kin_mem == NULL) + { + SUNGlobalFallbackErrHandler(line, func, file, msg, error_code); + break; + } - if (kin_mem == NULL) - { /* We write to stderr */ -#ifndef NO_FPRINTF_OUTPUT - fprintf(stderr, "\n[%s ERROR] %s\n ", module, fname); - fprintf(stderr, "%s\n\n", msg); + if (error_code == KIN_WARNING) + { +#if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_WARNING + char* file_and_line = sunCombineFileAndLine(line, file); + SUNLogger_QueueMsg(KIN_LOGGER, SUN_LOGLEVEL_WARNING, file_and_line, func, + msg); + free(file_and_line); #endif + break; + } + + /* Call the SUNDIALS main error handler */ + SUNHandleErrWithMsg(line, func, file, msg, error_code, SUNCTX_); + + /* Clear the last error value */ + (void)SUNContext_GetLastError(SUNCTX_); } - else - { /* We can call ehfun */ - kin_mem->kin_ehfun(error_code, module, fname, msg, kin_mem->kin_eh_data); - } + while (0); /* Finalize argument processing */ va_end(ap); - - return; -} - -/* - * KINErrHandler - * - * This is the default error handling function. - * It sends the error message to the stream pointed to by kin_errfp - */ - -void KINErrHandler(int error_code, const char* module, const char* function, - char* msg, void* data) -{ - KINMem kin_mem; - char err_type[10]; - - /* data points to kin_mem here */ - - kin_mem = (KINMem)data; - - if (error_code == KIN_WARNING) { sprintf(err_type, "WARNING"); } - else { sprintf(err_type, "ERROR"); } - -#ifndef NO_FPRINTF_OUTPUT - if (kin_mem->kin_errfp != NULL) - { - fprintf(kin_mem->kin_errfp, "\n[%s %s] %s\n", module, err_type, function); - fprintf(kin_mem->kin_errfp, " %s\n\n", msg); - } -#endif + free(msg); return; } @@ -2774,8 +2747,6 @@ static int KINPicardAA(KINMem kin_mem) KINForcingTerm(kin_mem, fnormp); } - fflush(kin_mem->kin_errfp); - } /* end of loop; return */ #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGLEVEL_INFO KINPrintInfo(kin_mem, PRNT_RETVAL, "KINSOL", "KINPicardAA", INFO_RETVAL, ret); @@ -2980,8 +2951,6 @@ static int KINFP(KINMem kin_mem) N_VScale(ONE, kin_mem->kin_unew, kin_mem->kin_uu); } - fflush(kin_mem->kin_errfp); - } /* end of loop; return */ #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGLEVEL_INFO diff --git a/src/kinsol/kinsol_bbdpre.c b/src/kinsol/kinsol_bbdpre.c index 634d03eca2..934a7fcf80 100644 --- a/src/kinsol/kinsol_bbdpre.c +++ b/src/kinsol/kinsol_bbdpre.c @@ -69,7 +69,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, __func__, __FILE__, MSGBBD_MEM_NULL); return (KINLS_MEM_NULL); } @@ -78,7 +78,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, /* Test if the LS linear solver interface has been created */ if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, MSGBBD_LMEM_NULL); return (KINLS_LMEM_NULL); } @@ -88,7 +88,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, /* Note: Do NOT need to check for N_VScale since has already been checked for in KINSOL */ if (kin_mem->kin_vtemp1->ops->nvgetarraypointer == NULL) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSGBBD_BAD_NVECTOR); return (KINLS_ILL_INPUT); } @@ -98,7 +98,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, pdata = (KBBDPrecData)malloc(sizeof *pdata); if (pdata == NULL) { - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -125,7 +125,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, { free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -138,7 +138,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -151,7 +151,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -165,7 +165,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -180,7 +180,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -196,7 +196,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -214,7 +214,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNMatDestroy(pdata->PP); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSGBBD_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -232,7 +232,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, SUNLinSolFree(pdata->LS); free(pdata); pdata = NULL; - KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINBBDPRE", "KINBBDPrecInit", + KINProcessError(kin_mem, KINLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, MSGBBD_SUNLS_FAIL); return (KINLS_SUNLS_FAIL); } @@ -304,7 +304,7 @@ int KINBBDPrecGetWorkSpace(void* kinmem, long int* lenrwBBDP, long int* leniwBBD if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINBBDPRE", "KINBBDPrecGetWorkSpace", + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, __func__, __FILE__, MSGBBD_MEM_NULL); return (KINLS_MEM_NULL); } @@ -312,16 +312,16 @@ int KINBBDPrecGetWorkSpace(void* kinmem, long int* lenrwBBDP, long int* leniwBBD if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINBBDPRE", - "KINBBDPrecGetWorkSpace", MSGBBD_LMEM_NULL); + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); return (KINLS_LMEM_NULL); } kinls_mem = (KINLsMem)kin_mem->kin_lmem; if (kinls_mem->pdata == NULL) { - KINProcessError(kin_mem, KINLS_PMEM_NULL, "KINBBDPRE", - "KINBBDPrecGetWorkSpace", MSGBBD_PMEM_NULL); + KINProcessError(kin_mem, KINLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); return (KINLS_PMEM_NULL); } pdata = (KBBDPrecData)kinls_mem->pdata; @@ -343,24 +343,24 @@ int KINBBDPrecGetNumGfnEvals(void* kinmem, long int* ngevalsBBDP) if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINBBDPRE", - "KINBBDPrecGetNumGfnEvals", MSGBBD_MEM_NULL); + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_MEM_NULL); return (KINLS_MEM_NULL); } kin_mem = (KINMem)kinmem; if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINBBDPRE", - "KINBBDPrecGetNumGfnEvals", MSGBBD_LMEM_NULL); + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_LMEM_NULL); return (KINLS_LMEM_NULL); } kinls_mem = (KINLsMem)kin_mem->kin_lmem; if (kinls_mem->pdata == NULL) { - KINProcessError(kin_mem, KINLS_PMEM_NULL, "KINBBDPRE", - "KINBBDPrecGetNumGfnEvals", MSGBBD_PMEM_NULL); + KINProcessError(kin_mem, KINLS_PMEM_NULL, __LINE__, __func__, __FILE__, + MSGBBD_PMEM_NULL); return (KINLS_PMEM_NULL); } pdata = (KBBDPrecData)kinls_mem->pdata; @@ -414,7 +414,7 @@ static int KINBBDPrecSetup(N_Vector uu, N_Vector uscale, N_Vector fval, retval = SUNMatZero(pdata->PP); if (retval != 0) { - KINProcessError(kin_mem, -1, "KINBBDPRE", "KINBBDPrecSetup", + KINProcessError(kin_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_SUNMAT_FAIL); return (-1); } @@ -423,7 +423,7 @@ static int KINBBDPrecSetup(N_Vector uu, N_Vector uscale, N_Vector fval, pdata->tempv3); if (retval != 0) { - KINProcessError(kin_mem, -1, "KINBBDPRE", "KINBBDPrecSetup", + KINProcessError(kin_mem, -1, __LINE__, __func__, __FILE__, MSGBBD_FUNC_FAILED); return (-1); } diff --git a/src/kinsol/kinsol_impl.h b/src/kinsol/kinsol_impl.h index 4fb8a7ae47..4d24981046 100644 --- a/src/kinsol/kinsol_impl.h +++ b/src/kinsol/kinsol_impl.h @@ -268,15 +268,6 @@ typedef struct KINMemRec sunbooleantype kin_MallocDone; /* flag indicating if KINMalloc has been called yet */ - /* message files */ - /*------------------------------------------- - Error handler function and error ouput file - -------------------------------------------*/ - - KINErrHandlerFn kin_ehfun; /* Error messages are handled by ehfun */ - void* kin_eh_data; /* dats pointer passed to ehfun */ - FILE* kin_errfp; /* KINSOL error messages are sent to errfp */ - }* KINMem; /* @@ -385,13 +376,8 @@ typedef struct KINMemRec /* High level error handler */ -void KINProcessError(KINMem kin_mem, int error_code, const char* module, - const char* fname, const char* msgfmt, ...); - -/* Prototype of internal errHandler function */ - -void KINErrHandler(int error_code, const char* module, const char* function, - char* msg, void* user_data); +void KINProcessError(KINMem kin_mem, int error_code, int line, const char* func, + const char* file, const char* msgfmt, ...); /* High level info handler */ diff --git a/src/kinsol/kinsol_io.c b/src/kinsol/kinsol_io.c index f137926d34..a34db22ac6 100644 --- a/src/kinsol/kinsol_io.c +++ b/src/kinsol/kinsol_io.c @@ -41,53 +41,6 @@ * ================================================================= */ -/* - * ----------------------------------------------------------------- - * KINSetErrHandlerFn - * ----------------------------------------------------------------- - */ - -int KINSetErrHandlerFn(void* kinmem, KINErrHandlerFn ehfun, void* eh_data) -{ - KINMem kin_mem; - - if (kinmem == NULL) - { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetErrHandlerFn", - MSG_NO_MEM); - return (KIN_MEM_NULL); - } - - kin_mem = (KINMem)kinmem; - - kin_mem->kin_ehfun = ehfun; - kin_mem->kin_eh_data = eh_data; - - return (KIN_SUCCESS); -} - -/* - * ----------------------------------------------------------------- - * Function : KINSetErrFile - * ----------------------------------------------------------------- - */ - -int KINSetErrFile(void* kinmem, FILE* errfp) -{ - KINMem kin_mem; - - if (kinmem == NULL) - { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetErrFile", MSG_NO_MEM); - return (KIN_MEM_NULL); - } - - kin_mem = (KINMem)kinmem; - kin_mem->kin_errfp = errfp; - - return (KIN_SUCCESS); -} - /* * ----------------------------------------------------------------- * Function : KINSetUserData @@ -100,7 +53,7 @@ int KINSetUserData(void* kinmem, void* user_data) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetUserData", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -122,7 +75,7 @@ int KINSetDamping(void* kinmem, sunrealtype beta) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetDamping", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -131,7 +84,7 @@ int KINSetDamping(void* kinmem, sunrealtype beta) /* check for illegal input value */ if (beta <= ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetDamping", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, "beta <= 0 illegal"); return (KIN_ILL_INPUT); } @@ -164,7 +117,7 @@ int KINSetMAA(void* kinmem, long int maa) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetMAA", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -172,7 +125,8 @@ int KINSetMAA(void* kinmem, long int maa) if (maa < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetMAA", MSG_BAD_MAA); + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, + MSG_BAD_MAA); return (KIN_ILL_INPUT); } @@ -195,7 +149,7 @@ int KINSetDelayAA(void* kinmem, long int delay) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetDelayAA", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -204,7 +158,7 @@ int KINSetDelayAA(void* kinmem, long int delay) /* check for illegal input value */ if (delay < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetDelayAA", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, "delay < 0 illegal"); return (KIN_ILL_INPUT); } @@ -226,7 +180,7 @@ int KINSetOrthAA(void* kinmem, int orthaa) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetOrthAA", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -234,7 +188,7 @@ int KINSetOrthAA(void* kinmem, int orthaa) if ((orthaa < KIN_ORTH_MGS) || (orthaa > KIN_ORTH_DCGS2)) { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINSetOrthAA", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_ORTHAA); return (KIN_ILL_INPUT); } @@ -256,7 +210,7 @@ int KINSetDampingAA(void* kinmem, sunrealtype beta) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetDampingAA", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -265,7 +219,7 @@ int KINSetDampingAA(void* kinmem, sunrealtype beta) /* check for illegal input value */ if (beta <= ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetDampingAA", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, "beta <= 0 illegal"); return (KIN_ILL_INPUT); } @@ -298,8 +252,7 @@ int KINSetReturnNewest(void* kinmem, sunbooleantype ret_newest) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetReturnNewest", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -322,8 +275,7 @@ int KINSetNumMaxIters(void* kinmem, long int mxiter) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetNumMaxIters", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -331,7 +283,7 @@ int KINSetNumMaxIters(void* kinmem, long int mxiter) if (mxiter < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetNumMaxIters", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_MXITER); return (KIN_ILL_INPUT); } @@ -354,8 +306,7 @@ int KINSetNoInitSetup(void* kinmem, sunbooleantype noInitSetup) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetNoInitSetup", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -377,7 +328,7 @@ int KINSetNoResMon(void* kinmem, sunbooleantype noResMon) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetNoResMon", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -399,8 +350,7 @@ int KINSetMaxSetupCalls(void* kinmem, long int msbset) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetMaxSetupCalls", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -408,7 +358,7 @@ int KINSetMaxSetupCalls(void* kinmem, long int msbset) if (msbset < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetMaxSetupCalls", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_MSBSET); return (KIN_ILL_INPUT); } @@ -431,8 +381,7 @@ int KINSetMaxSubSetupCalls(void* kinmem, long int msbsetsub) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetMaxSubSetupCalls", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -440,7 +389,7 @@ int KINSetMaxSubSetupCalls(void* kinmem, long int msbsetsub) if (msbsetsub < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetMaxSubSetupCalls", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_MSBSETSUB); return (KIN_ILL_INPUT); } @@ -463,7 +412,7 @@ int KINSetEtaForm(void* kinmem, int etachoice) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetEtaForm", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -472,7 +421,7 @@ int KINSetEtaForm(void* kinmem, int etachoice) if ((etachoice != KIN_ETACONSTANT) && (etachoice != KIN_ETACHOICE1) && (etachoice != KIN_ETACHOICE2)) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetEtaForm", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_ETACHOICE); return (KIN_ILL_INPUT); } @@ -494,8 +443,7 @@ int KINSetEtaConstValue(void* kinmem, sunrealtype eta) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetEtaConstValue", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -503,7 +451,7 @@ int KINSetEtaConstValue(void* kinmem, sunrealtype eta) if ((eta < ZERO) || (eta > ONE)) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetEtaConstValue", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_ETACONST); return (KIN_ILL_INPUT); } @@ -526,7 +474,7 @@ int KINSetEtaParams(void* kinmem, sunrealtype egamma, sunrealtype ealpha) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetEtaParams", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -536,7 +484,7 @@ int KINSetEtaParams(void* kinmem, sunrealtype egamma, sunrealtype ealpha) { if (ealpha != ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetEtaParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_ALPHA); return (KIN_ILL_INPUT); } @@ -549,7 +497,7 @@ int KINSetEtaParams(void* kinmem, sunrealtype egamma, sunrealtype ealpha) { if (egamma != ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetEtaParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_GAMMA); return (KIN_ILL_INPUT); } @@ -573,8 +521,7 @@ int KINSetResMonParams(void* kinmem, sunrealtype omegamin, sunrealtype omegamax) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetResMonParams", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -584,7 +531,7 @@ int KINSetResMonParams(void* kinmem, sunrealtype omegamin, sunrealtype omegamax) if (omegamin < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetResMonParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_OMEGA); return (KIN_ILL_INPUT); } @@ -596,7 +543,7 @@ int KINSetResMonParams(void* kinmem, sunrealtype omegamin, sunrealtype omegamax) if (omegamax < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetResMonParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_OMEGA); return (KIN_ILL_INPUT); } @@ -605,7 +552,7 @@ int KINSetResMonParams(void* kinmem, sunrealtype omegamin, sunrealtype omegamax) { if (kin_mem->kin_omega_min > OMEGA_MAX) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetResMonParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_OMEGA); return (KIN_ILL_INPUT); } @@ -615,7 +562,7 @@ int KINSetResMonParams(void* kinmem, sunrealtype omegamin, sunrealtype omegamax) { if (kin_mem->kin_omega_min > omegamax) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetResMonParams", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_OMEGA); return (KIN_ILL_INPUT); } @@ -637,8 +584,7 @@ int KINSetResMonConstValue(void* kinmem, sunrealtype omegaconst) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetResMonConstValue", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -648,7 +594,7 @@ int KINSetResMonConstValue(void* kinmem, sunrealtype omegaconst) if (omegaconst < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetResMonConstValue", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_OMEGA); return (KIN_ILL_INPUT); } @@ -671,7 +617,7 @@ int KINSetNoMinEps(void* kinmem, sunbooleantype noMinEps) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetNoMinEps", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -693,8 +639,7 @@ int KINSetMaxNewtonStep(void* kinmem, sunrealtype mxnewtstep) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetMaxNewtonStep", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -702,7 +647,7 @@ int KINSetMaxNewtonStep(void* kinmem, sunrealtype mxnewtstep) if (mxnewtstep < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetMaxNewtonStep", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_MXNEWTSTEP); return (KIN_ILL_INPUT); } @@ -727,8 +672,7 @@ int KINSetMaxBetaFails(void* kinmem, long int mxnbcf) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetMaxBetaFails", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -736,7 +680,7 @@ int KINSetMaxBetaFails(void* kinmem, long int mxnbcf) if (mxnbcf < 0) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetMaxBetaFails", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_MXNBCF); return (KIN_ILL_INPUT); } @@ -760,7 +704,7 @@ int KINSetRelErrFunc(void* kinmem, sunrealtype relfunc) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetRelErrFunc", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -768,7 +712,7 @@ int KINSetRelErrFunc(void* kinmem, sunrealtype relfunc) if (relfunc < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetRelErrFunc", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_RELFUNC); return (KIN_ILL_INPUT); } @@ -796,8 +740,7 @@ int KINSetFuncNormTol(void* kinmem, sunrealtype fnormtol) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetFuncNormTol", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -805,7 +748,7 @@ int KINSetFuncNormTol(void* kinmem, sunrealtype fnormtol) if (fnormtol < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetFuncNormTol", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_FNORMTOL); return (KIN_ILL_INPUT); } @@ -833,8 +776,7 @@ int KINSetScaledStepTol(void* kinmem, sunrealtype scsteptol) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetScaledStepTol", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -842,7 +784,7 @@ int KINSetScaledStepTol(void* kinmem, sunrealtype scsteptol) if (scsteptol < ZERO) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetScaledStepTol", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_SCSTEPTOL); return (KIN_ILL_INPUT); } @@ -870,8 +812,7 @@ int KINSetConstraints(void* kinmem, N_Vector constraints) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetConstraints", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -894,7 +835,7 @@ int KINSetConstraints(void* kinmem, N_Vector constraints) temptest = N_VMaxNorm(constraints); if (temptest > TWOPT5) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetConstraints", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_BAD_CONSTRAINTS); return (KIN_ILL_INPUT); } @@ -926,7 +867,7 @@ int KINSetSysFunc(void* kinmem, KINSysFn func) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINSetSysFunc", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -934,7 +875,7 @@ int KINSetSysFunc(void* kinmem, KINSysFn func) if (func == NULL) { - KINProcessError(NULL, KIN_ILL_INPUT, "KINSOL", "KINSetSysFunc", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_FUNC_NULL); return (KIN_ILL_INPUT); } @@ -962,7 +903,7 @@ int KINGetWorkSpace(void* kinmem, long int* lenrw, long int* leniw) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetWorkSpace", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -986,8 +927,7 @@ int KINGetNumNonlinSolvIters(void* kinmem, long int* nniters) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetNumNonlinSolvIters", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1009,8 +949,7 @@ int KINGetNumFuncEvals(void* kinmem, long int* nfevals) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetNumFuncEvals", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1032,8 +971,7 @@ int KINGetNumBetaCondFails(void* kinmem, long int* nbcfails) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetNumBetaCondFails", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1055,8 +993,7 @@ int KINGetNumBacktrackOps(void* kinmem, long int* nbacktr) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetNumBacktrackOps", - MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1078,7 +1015,7 @@ int KINGetFuncNorm(void* kinmem, sunrealtype* funcnorm) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetFuncNorm", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1100,7 +1037,7 @@ int KINGetStepLength(void* kinmem, sunrealtype* steplength) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetStepLength", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1122,7 +1059,7 @@ int KINGetUserData(void* kinmem, void** user_data) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINGetUserData", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1146,7 +1083,7 @@ int KINPrintAllStats(void* kinmem, FILE* outfile, SUNOutputFormat fmt) if (kinmem == NULL) { - KINProcessError(NULL, KIN_MEM_NULL, "KINSOL", "KINPrintAllStats", MSG_NO_MEM); + KINProcessError(NULL, KIN_MEM_NULL, __LINE__, __func__, __FILE__, MSG_NO_MEM); return (KIN_MEM_NULL); } @@ -1225,7 +1162,7 @@ int KINPrintAllStats(void* kinmem, FILE* outfile, SUNOutputFormat fmt) fprintf(outfile, "\n"); break; default: - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINSOL", "KINPrintAllStats", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, "Invalid formatting option."); return (KIN_ILL_INPUT); } diff --git a/src/kinsol/kinsol_ls.c b/src/kinsol/kinsol_ls.c index cb00517bd5..bbb5f9732e 100644 --- a/src/kinsol/kinsol_ls.c +++ b/src/kinsol/kinsol_ls.c @@ -51,13 +51,13 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) /* Return immediately if either kinmem or LS inputs are NULL */ if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINLS", "KINSetLinearSolver", + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_KINMEM_NULL); return (KINLS_MEM_NULL); } if (LS == NULL) { - KINProcessError(NULL, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(NULL, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "LS must be non-NULL"); return (KINLS_ILL_INPUT); } @@ -66,7 +66,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) /* Test if solver is compatible with LS interface */ if ((LS->ops->gettype == NULL) || (LS->ops->solve == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "LS object is missing a required operation"); return (KINLS_ILL_INPUT); } @@ -77,7 +77,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) /* Return with error if LS has 'matrix-embedded' type */ if (LSType == SUNLINEARSOLVER_MATRIX_EMBEDDED) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "KINSOL is incompatible with MATRIX_EMBEDDED LS objects"); return (KINLS_ILL_INPUT); } @@ -90,7 +90,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) if ((kin_mem->kin_vtemp1->ops->nvconst == NULL) || (kin_mem->kin_vtemp1->ops->nvdotprod == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_LS_BAD_NVECTOR); return (KINLS_ILL_INPUT); } @@ -101,28 +101,28 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) if ((LS->ops->setscalingvectors == NULL) && (kin_mem->kin_vtemp1->ops->nvgetlength == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_LS_BAD_NVECTOR); return (KINLS_ILL_INPUT); } if (!matrixbased && (LS->ops->setatimes == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", - "KINSetLinearSolver", "Incompatible inputs: iterative LS must support ATimes routine"); + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: iterative LS must support ATimes routine"); return (KINLS_ILL_INPUT); } if (matrixbased && A == NULL) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", - "KINSetLinearSolver", "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Incompatible inputs: matrix-iterative LS requires non-NULL matrix"); return (KINLS_ILL_INPUT); } } else if (A == NULL) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "Incompatible inputs: direct LS requires non-NULL matrix"); return (KINLS_ILL_INPUT); } @@ -144,7 +144,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) kinls_mem = (KINLsMem)malloc(sizeof(struct KINLsMemRec)); if (kinls_mem == NULL) { - KINProcessError(kin_mem, KINLS_MEM_FAIL, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_MEM_FAIL, __LINE__, __func__, __FILE__, MSG_LS_MEM_FAIL); return (KINLS_MEM_FAIL); } @@ -189,7 +189,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) retval = SUNLinSolSetATimes(LS, kin_mem, kinLsATimes); if (retval != SUNLS_SUCCESS) { - KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetATimes"); free(kinls_mem); kinls_mem = NULL; @@ -203,7 +203,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) retval = SUNLinSolSetPreconditioner(LS, kin_mem, NULL, NULL); if (retval != SUNLS_SUCCESS) { - KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetLinearSolver", + KINProcessError(kin_mem, KINLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); free(kinls_mem); kinls_mem = NULL; @@ -237,13 +237,13 @@ int KINSetJacFn(void* kinmem, KINLsJacFn jac) int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "KINSetJacFn", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* return with failure if jac cannot be used */ if ((jac != NULL) && (kinls_mem->J == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetJacFn", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "Jacobian routine cannot be supplied for NULL SUNMatrix"); return (KINLS_ILL_INPUT); } @@ -278,7 +278,7 @@ int KINSetPreconditioner(void* kinmem, KINLsPrecSetupFn psetup, int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "KINSetPreconditioner", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* store function pointers for user-supplied routines in KINLS interface */ @@ -288,7 +288,7 @@ int KINSetPreconditioner(void* kinmem, KINLsPrecSetupFn psetup, /* issue error if LS object does not support user-supplied preconditioning */ if (kinls_mem->LS->ops->setpreconditioner == NULL) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetPreconditioner", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "SUNLinearSolver object does not support user-supplied " "preconditioning"); return (KINLS_ILL_INPUT); @@ -301,7 +301,7 @@ int KINSetPreconditioner(void* kinmem, KINLsPrecSetupFn psetup, kinls_psolve); if (retval != SUNLS_SUCCESS) { - KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetPreconditioner", + KINProcessError(kin_mem, KINLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetPreconditioner"); return (KINLS_SUNLS_FAIL); } @@ -319,13 +319,13 @@ int KINSetJacTimesVecFn(void* kinmem, KINLsJacTimesVecFn jtv) KINLsMem kinls_mem; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "KINSetJacTimesVecFn", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* issue error if LS object does not support user-supplied ATimes */ if (kinls_mem->LS->ops->setatimes == NULL) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "KINSetJacTimesVecFn", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "SUNLinearSolver object does not support user-supplied " "ATimes routine"); return (KINLS_ILL_INPUT); @@ -359,15 +359,14 @@ int KINSetJacTimesVecSysFn(void* kinmem, KINSysFn jtimesSysFn) KINLsMem kinls_mem = NULL; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kin_mem, "KINSetJacTimesVecSysFn", &kin_mem, - &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* check if using internal finite difference approximation */ if (!(kinls_mem->jtimesDQ)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", - "KINSetJacTimesVecSysFn", "Internal finite-difference Jacobian-vector product is disabled."); + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, + __FILE__, "Internal finite-difference Jacobian-vector product is disabled."); return (KINLS_ILL_INPUT); } @@ -389,7 +388,7 @@ int KINGetJac(void* kinmem, SUNMatrix* J) int retval; /* access KINLsMem structure; set output and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetJac", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KINLS_SUCCESS) { return retval; } *J = kinls_mem->J; return KINLS_SUCCESS; @@ -402,7 +401,7 @@ int KINGetJacNumIters(void* kinmem, long int* nni_J) int retval; /* access KINLsMem structure; set output and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetJacNumIters", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KINLS_SUCCESS) { return retval; } *nni_J = kin_mem->kin_nnilset; return KINLS_SUCCESS; @@ -420,7 +419,7 @@ int KINGetLinWorkSpace(void* kinmem, long int* lenrwLS, long int* leniwLS) int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "KINGetLinWorkSpace", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* start with fixed sizes plus vector/matrix pointers */ @@ -459,7 +458,7 @@ int KINGetNumJacEvals(void* kinmem, long int* njevals) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumJacEvals", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *njevals = kinls_mem->nje; return (KINLS_SUCCESS); @@ -476,7 +475,7 @@ int KINGetNumPrecEvals(void* kinmem, long int* npevals) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumPrecEvals", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *npevals = kinls_mem->npe; return (KINLS_SUCCESS); @@ -493,7 +492,7 @@ int KINGetNumPrecSolves(void* kinmem, long int* npsolves) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumPrecSolves", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *npsolves = kinls_mem->nps; return (KINLS_SUCCESS); @@ -510,7 +509,7 @@ int KINGetNumLinIters(void* kinmem, long int* nliters) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumLinIters", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *nliters = kinls_mem->nli; return (KINLS_SUCCESS); @@ -527,8 +526,7 @@ int KINGetNumLinConvFails(void* kinmem, long int* nlcfails) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumLinConvFails", &kin_mem, - &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *nlcfails = kinls_mem->ncfl; return (KINLS_SUCCESS); @@ -545,7 +543,7 @@ int KINGetNumJtimesEvals(void* kinmem, long int* njvevals) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumJtimesEvals", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *njvevals = kinls_mem->njtimes; return (KINLS_SUCCESS); @@ -562,8 +560,7 @@ int KINGetNumLinFuncEvals(void* kinmem, long int* nfevals) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetNumLinFuncEvals", &kin_mem, - &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *nfevals = kinls_mem->nfeDQ; return (KINLS_SUCCESS); @@ -580,7 +577,7 @@ int KINGetLastLinFlag(void* kinmem, long int* flag) int retval; /* access KINLsMem structure; set output value and return */ - retval = kinLs_AccessLMem(kinmem, "KINGetLastLinFlag", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } *flag = kinls_mem->last_flag; return (KINLS_SUCCESS); @@ -631,7 +628,7 @@ int kinLsATimes(void* kinmem, N_Vector v, N_Vector z) int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "kinLsATimes", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* call Jacobian-times-vector product routine @@ -659,7 +656,7 @@ int kinLsPSetup(void* kinmem) int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "kinLsPSetup", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* Call user pset routine to update preconditioner */ @@ -688,7 +685,7 @@ int kinLsPSolve(void* kinmem, N_Vector r, N_Vector z, sunrealtype tol, int lr) int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "kinLsPSolve", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* copy the rhs into z before the psolve call */ @@ -719,7 +716,7 @@ int kinLsDQJac(N_Vector u, N_Vector fu, SUNMatrix Jac, void* kinmem, /* access KINMem structure */ if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINLS", "kinLsDQJac", + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_KINMEM_NULL); return (KINLS_MEM_NULL); } @@ -728,7 +725,7 @@ int kinLsDQJac(N_Vector u, N_Vector fu, SUNMatrix Jac, void* kinmem, /* verify that Jac is non-NULL */ if (Jac == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINLS", "kinLsDQJac", + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_LMEM_NULL); return (KINLS_LMEM_NULL); } @@ -744,7 +741,7 @@ int kinLsDQJac(N_Vector u, N_Vector fu, SUNMatrix Jac, void* kinmem, } else { - KINProcessError(kin_mem, KIN_ILL_INPUT, "KINLS", "kinLsDQJac", + KINProcessError(kin_mem, KIN_ILL_INPUT, __LINE__, __func__, __FILE__, "unrecognized matrix type for kinLsDQJac"); retval = KIN_ILL_INPUT; } @@ -953,14 +950,14 @@ int kinLsDQJtimes(N_Vector v, N_Vector Jv, N_Vector u, sunbooleantype* new_u, int retval; /* access KINLsMem structure */ - retval = kinLs_AccessLMem(kinmem, "kinLsDQJtimes", &kin_mem, &kinls_mem); + retval = kinLs_AccessLMem(kinmem, __func__, &kin_mem, &kinls_mem); if (retval != KIN_SUCCESS) { return (retval); } /* ensure that NVector supplies requisite routines */ if ((v->ops->nvprod == NULL) || (v->ops->nvdotprod == NULL) || (v->ops->nvl1norm == NULL) || (v->ops->nvlinearsum == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "kinLsDQJtimes", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_LS_BAD_NVECTOR); return (KINLS_ILL_INPUT); } @@ -1011,7 +1008,7 @@ int kinLsInitialize(KINMem kin_mem) /* Access KINLsMem structure */ if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINLS", "kinLsInitialize", + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_LMEM_NULL); return (KINLS_LMEM_NULL); } @@ -1044,7 +1041,7 @@ int kinLsInitialize(KINMem kin_mem) else { retval++; } if (retval) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "kinLsInitialize", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, "No Jacobian constructor available for SUNMatrix type"); kinls_mem->last_flag = KINLS_ILL_INPUT; return (KINLS_ILL_INPUT); @@ -1056,7 +1053,7 @@ int kinLsInitialize(KINMem kin_mem) (kin_mem->kin_vtemp1->ops->nvgetarraypointer == NULL) || (kin_mem->kin_vtemp1->ops->nvsetarraypointer == NULL)) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "kinLsInitialize", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_LS_BAD_NVECTOR); return (KINLS_ILL_INPUT); } @@ -1072,7 +1069,7 @@ int kinLsInitialize(KINMem kin_mem) if ((kin_mem->kin_globalstrategy == KIN_PICARD) && kinls_mem->jacDQ && kinls_mem->jtimesDQ) { - KINProcessError(kin_mem, KINLS_ILL_INPUT, "KINLS", "kinLsInitialize", + KINProcessError(kin_mem, KINLS_ILL_INPUT, __LINE__, __func__, __FILE__, MSG_NOL_FAIL); return (KINLS_ILL_INPUT); } @@ -1108,7 +1105,7 @@ int kinLsInitialize(KINMem kin_mem) kin_mem->kin_fscale); if (retval != SUNLS_SUCCESS) { - KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "kinLsInitialize", + KINProcessError(kin_mem, KINLS_SUNLS_FAIL, __LINE__, __func__, __FILE__, "Error in calling SUNLinSolSetScalingVectors"); return (KINLS_SUNLS_FAIL); } @@ -1153,7 +1150,7 @@ int kinLsSetup(KINMem kin_mem) /* Access KINLsMem structure */ if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINLS", "kinLsSetup", + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_LMEM_NULL); return (KINLS_LMEM_NULL); } @@ -1171,8 +1168,8 @@ int kinLsSetup(KINMem kin_mem) retval = SUNMatZero(kinls_mem->J); if (retval != 0) { - KINProcessError(kin_mem, KINLS_SUNMAT_FAIL, "KINLS", "kinLsSetup", - MSG_LS_MATZERO_FAILED); + KINProcessError(kin_mem, KINLS_SUNMAT_FAIL, __LINE__, __func__, + __FILE__, MSG_LS_MATZERO_FAILED); kinls_mem->last_flag = KINLS_SUNMAT_FAIL; return (kinls_mem->last_flag); } @@ -1184,7 +1181,7 @@ int kinLsSetup(KINMem kin_mem) kin_mem->kin_vtemp2); if (retval != 0) { - KINProcessError(kin_mem, KINLS_JACFUNC_ERR, "KINLS", "kinLsSetup", + KINProcessError(kin_mem, KINLS_JACFUNC_ERR, __LINE__, __func__, __FILE__, MSG_LS_JACFUNC_FAILED); kinls_mem->last_flag = KINLS_JACFUNC_ERR; return (kinls_mem->last_flag); @@ -1214,7 +1211,7 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, /* Access KINLsMem structure */ if (kin_mem->kin_lmem == NULL) { - KINProcessError(kin_mem, KINLS_LMEM_NULL, "KINLS", "kinLsSolve", + KINProcessError(kin_mem, KINLS_LMEM_NULL, __LINE__, __func__, __FILE__, MSG_LS_LMEM_NULL); return (KINLS_LMEM_NULL); } @@ -1279,20 +1276,20 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, case SUNLS_LUFACT_FAIL: case SUNLS_QRSOL_FAIL: break; case SUNLS_PACKAGE_FAIL_REC: - KINProcessError(kin_mem, SUNLS_PACKAGE_FAIL_REC, "KINLS", "kinLsSolve", - "Failure in SUNLinSol external package"); + KINProcessError(kin_mem, SUNLS_PACKAGE_FAIL_REC, __LINE__, __func__, + __FILE__, "Failure in SUNLinSol external package"); break; case SUNLS_PACKAGE_FAIL_UNREC: - KINProcessError(kin_mem, SUNLS_PACKAGE_FAIL_UNREC, "KINLS", "kinLsSolve", - "Failure in SUNLinSol external package"); + KINProcessError(kin_mem, SUNLS_PACKAGE_FAIL_UNREC, __LINE__, __func__, + __FILE__, "Failure in SUNLinSol external package"); break; case SUNLS_ATIMES_FAIL_UNREC: - KINProcessError(kin_mem, SUNLS_ATIMES_FAIL_UNREC, "KINLS", "kinLsSolve", - MSG_LS_JTIMES_FAILED); + KINProcessError(kin_mem, SUNLS_ATIMES_FAIL_UNREC, __LINE__, __func__, + __FILE__, MSG_LS_JTIMES_FAILED); break; case SUNLS_PSOLVE_FAIL_UNREC: - KINProcessError(kin_mem, SUNLS_PSOLVE_FAIL_UNREC, "KINLS", "kinLsSolve", - MSG_LS_PSOLVE_FAILED); + KINProcessError(kin_mem, SUNLS_PSOLVE_FAIL_UNREC, __LINE__, __func__, + __FILE__, MSG_LS_PSOLVE_FAILED); break; } return (retval); @@ -1397,13 +1394,15 @@ int kinLs_AccessLMem(void* kinmem, const char* fname, KINMem* kin_mem, { if (kinmem == NULL) { - KINProcessError(NULL, KINLS_MEM_NULL, "KINLS", fname, MSG_LS_KINMEM_NULL); + KINProcessError(NULL, KINLS_MEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_KINMEM_NULL); return (KINLS_MEM_NULL); } *kin_mem = (KINMem)kinmem; if ((*kin_mem)->kin_lmem == NULL) { - KINProcessError(*kin_mem, KINLS_LMEM_NULL, "KINLS", fname, MSG_LS_LMEM_NULL); + KINProcessError(*kin_mem, KINLS_LMEM_NULL, __LINE__, fname, __FILE__, + MSG_LS_LMEM_NULL); return (KINLS_LMEM_NULL); } *kinls_mem = (KINLsMem)(*kin_mem)->kin_lmem; diff --git a/test/unit_tests/kinsol/CMakeLists.txt b/test/unit_tests/kinsol/CMakeLists.txt index 8f18597d56..606b9d3fb4 100644 --- a/test/unit_tests/kinsol/CMakeLists.txt +++ b/test/unit_tests/kinsol/CMakeLists.txt @@ -20,4 +20,7 @@ add_subdirectory(C_serial) # C++ unit tests if(CXX_FOUND) add_subdirectory(CXX_serial) + if(SUNDIALS_TEST_ENABLE_GTEST) + add_subdirectory(gtest) + endif() endif() diff --git a/test/unit_tests/kinsol/gtest/CMakeLists.txt b/test/unit_tests/kinsol/gtest/CMakeLists.txt new file mode 100644 index 0000000000..99c6c53983 --- /dev/null +++ b/test/unit_tests/kinsol/gtest/CMakeLists.txt @@ -0,0 +1,47 @@ +# --------------------------------------------------------------- +# SUNDIALS Copyright Start +# Copyright (c) 2002-2023, 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 +# --------------------------------------------------------------- + +# include location of public and private header files + +add_executable(test_kinsol_error_handling test_kinsol_error_handling.cpp) +target_include_directories(test_kinsol_error_handling + PRIVATE + $ + ${CMAKE_SOURCE_DIR}/include + ${CMAKE_SOURCE_DIR}/src +) + +# We explicitly choose which object libraries to link to and link in the +# KINSOL objects so that we have access to private functions w/o changing +# their visibility in the installed libraries. +target_link_libraries(test_kinsol_error_handling + PRIVATE + $ + sundials_sunmemsys_obj + sundials_nvecserial_obj + sundials_sunlinsolband_obj + sundials_sunlinsoldense_obj + sundials_sunnonlinsolnewton_obj + ${EXE_EXTRA_LINK_LIBS} +) + +# Tell CMake that we depend on the KINSOL library since it does not pick +# that up from $. +add_dependencies(test_kinsol_error_handling sundials_kinsol_obj) + +target_link_libraries(test_kinsol_error_handling + PRIVATE + GTest::gtest_main + GTest::gmock +) + +gtest_discover_tests(test_kinsol_error_handling) diff --git a/test/unit_tests/kinsol/gtest/test_kinsol_error_handling.cpp b/test/unit_tests/kinsol/gtest/test_kinsol_error_handling.cpp new file mode 100644 index 0000000000..fe35c2d092 --- /dev/null +++ b/test/unit_tests/kinsol/gtest/test_kinsol_error_handling.cpp @@ -0,0 +1,63 @@ +/* ----------------------------------------------------------------- + * SUNDIALS Copyright Start + * Copyright (c) 2002-2023, 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 + * -----------------------------------------------------------------*/ + +#include +#include +#include +#include + +#include "../../utilities/dumpstderr.hpp" +#include "kinsol/kinsol_impl.h" +#include "sundials/sundials_context.hpp" + +static const std::string errfile{"test_error_handling.err"}; + +class KINErrConditionTest : public testing::Test +{ +protected: + KINErrConditionTest() + { + SUNContext_ClearErrHandlers(sunctx); + SUNContext_PushErrHandler(sunctx, SUNLogErrHandlerFn, NULL); + SUNContext_GetLogger(sunctx, &logger); + kinmem = KINCreate(sunctx); + } + + ~KINErrConditionTest() { KINFree(&kinmem); } + + void* kinmem; + SUNLogger logger; + sundials::Context sunctx; +}; + +TEST_F(KINErrConditionTest, WarningIsPrinted) +{ + SUNLogger_SetWarningFilename(logger, errfile.c_str()); + KINMemRec* kin_mem = (KINMemRec*)kinmem; + KINProcessError(kin_mem, KIN_WARNING, __LINE__, __func__, __FILE__, "test"); + SUNLogger_Flush(logger, SUN_LOGLEVEL_WARNING); + std::string output = dumpstderr(sunctx, errfile); + EXPECT_THAT(output, testing::AllOf(testing::StartsWith("[WARNING]"), + testing::HasSubstr("[rank 0]"), + testing::HasSubstr("test"))); +} + +TEST_F(KINErrConditionTest, ErrorIsPrinted) +{ + SUNLogger_SetErrorFilename(logger, errfile.c_str()); + // -1 is an illegal value + KINSetNumMaxIters(kinmem, -1); + std::string output = dumpstderr(sunctx, errfile); + EXPECT_THAT(output, testing::AllOf(testing::StartsWith("[ERROR]"), + testing::HasSubstr("[rank 0]"), + testing::HasSubstr(MSG_BAD_MXITER))); +}