diff --git a/CHANGELOG.md b/CHANGELOG.md index ec7da53047..56e1ea4033 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -130,7 +130,22 @@ accordingly. **Breaking change** Functions, types and header files that were previously deprecated have been -removed. +removed. In addittion the following names/symbols were replaced by ``SUN_ERR_*`` +codes instead: + +``` +SUNLS_UNRECOV_FAILURE --> no replacement (this value was unused) +SUN_ERR_ARG_CORRUPT --> SUN_ERR_ARG_CORRUPT +SUN_ERR_ARG_INCOMPATIBLE --> SUN_ERR_ARG_INCOMPATIBLE +SUN_ERR_MEM_FAIL --> SUN_ERR_MEM_FAIL +SUNLS_VECTOROP_ERR --> SUN_ERR_OP_FAIL +SUN_NLS_SUCCESS --> SUN_SUCCESS +SUN_NLS_MEM_NULL --> SUN_ERR_ARG_CORRUPT +SUN_NLS_MEM_FAIL --> SUN_ERR_MEM_FAIL +SUN_NLS_ILL_INPUT --> SUN_ERR_ARG_INCOMPATIBLE +SUN_NLS_VECTOROP_ERR --> SUN_ERR_OP_FAIL +SUN_NLS_EXT_FAIL --> SUN_ERR_EXT_FAIL +``` **Breaking change** Users now need to link to `sundials_core` in addition to the libraries already linked to. diff --git a/benchmarks/advection_reaction_3D/kokkos/arkode_driver.cpp b/benchmarks/advection_reaction_3D/kokkos/arkode_driver.cpp index 7c000f71b3..cfd0f28e8e 100644 --- a/benchmarks/advection_reaction_3D/kokkos/arkode_driver.cpp +++ b/benchmarks/advection_reaction_3D/kokkos/arkode_driver.cpp @@ -635,7 +635,7 @@ SUNNonlinearSolver_Type TaskLocalNewton_GetType(SUNNonlinearSolver NLS) int TaskLocalNewton_Initialize(SUNNonlinearSolver NLS) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* override default system and lsolve functions with local versions */ SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), TaskLocalNlsResidual); @@ -656,7 +656,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || (mem == NULL)) { - return SUN_NLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } /* shortcuts */ @@ -683,7 +683,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, int TaskLocalNewton_Free(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return SUN_NLS_SUCCESS; } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from contents, then the generic structure */ if (NLS->content) @@ -703,13 +703,13 @@ int TaskLocalNewton_Free(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } int TaskLocalNewton_SetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), SysFn)); } @@ -719,7 +719,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, void* ctest_data) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetConvTestFn(LOCAL_NLS(NLS), CTestFn, ctest_data)); } @@ -727,7 +727,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, int TaskLocalNewton_GetNumConvFails(SUNNonlinearSolver NLS, long int* nconvfails) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } *nconvfails = GET_NLS_CONTENT(NLS)->ncnf; return (0); diff --git a/benchmarks/advection_reaction_3D/raja/arkode_driver.cpp b/benchmarks/advection_reaction_3D/raja/arkode_driver.cpp index 7c000f71b3..cfd0f28e8e 100644 --- a/benchmarks/advection_reaction_3D/raja/arkode_driver.cpp +++ b/benchmarks/advection_reaction_3D/raja/arkode_driver.cpp @@ -635,7 +635,7 @@ SUNNonlinearSolver_Type TaskLocalNewton_GetType(SUNNonlinearSolver NLS) int TaskLocalNewton_Initialize(SUNNonlinearSolver NLS) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* override default system and lsolve functions with local versions */ SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), TaskLocalNlsResidual); @@ -656,7 +656,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || (mem == NULL)) { - return SUN_NLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } /* shortcuts */ @@ -683,7 +683,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, int TaskLocalNewton_Free(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return SUN_NLS_SUCCESS; } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from contents, then the generic structure */ if (NLS->content) @@ -703,13 +703,13 @@ int TaskLocalNewton_Free(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } int TaskLocalNewton_SetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), SysFn)); } @@ -719,7 +719,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, void* ctest_data) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetConvTestFn(LOCAL_NLS(NLS), CTestFn, ctest_data)); } @@ -727,7 +727,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, int TaskLocalNewton_GetNumConvFails(SUNNonlinearSolver NLS, long int* nconvfails) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } *nconvfails = GET_NLS_CONTENT(NLS)->ncnf; return (0); diff --git a/doc/shared/sunlinsol/SUNLinSol_API.rst b/doc/shared/sunlinsol/SUNLinSol_API.rst index 200bbee338..ea05b266a8 100644 --- a/doc/shared/sunlinsol/SUNLinSol_API.rst +++ b/doc/shared/sunlinsol/SUNLinSol_API.rst @@ -523,14 +523,7 @@ provide additional information to the user in case of a linear solver failure. +------------------------------+-------+---------------------------------------------------+ | Error code | Value | Meaning | +==============================+=======+===================================================+ - | ``SUNLS_SUCCESS`` | 0 | successful call or converged solve | - +------------------------------+-------+---------------------------------------------------+ - | ``SUNLS_MEM_NULL`` | -801 | the memory argument to the function is ``NULL`` | - +------------------------------+-------+---------------------------------------------------+ - | ``SUNLS_ILL_INPUT`` | -802 | an illegal input has been provided to the | - | | | function | - +------------------------------+-------+---------------------------------------------------+ - | ``SUNLS_MEM_FAIL`` | -803 | failed memory access or allocation | + | ``SUN_SUCCESS`` | 0 | successful call or converged solve | +------------------------------+-------+---------------------------------------------------+ | ``SUNLS_ATIMES_NULL`` | -804 | the ``Atimes`` function is ``NULL`` | +------------------------------+-------+---------------------------------------------------+ @@ -554,8 +547,6 @@ provide additional information to the user in case of a linear solver failure. | ``SUNLS_QRSOL_FAIL`` | -811 | a singular $R$ matrix was encountered in a QR | | | | factorization (SPGMR/SPFGMR) | +------------------------------+-------+---------------------------------------------------+ - | ``SUNLS_VECTOROP_ERR`` | -812 | a vector operation error occurred | - +------------------------------+-------+---------------------------------------------------+ | ``SUNLS_RES_REDUCED`` | 801 | an iterative solver reduced the residual, but did | | | | not converge to the desired tolerance | +------------------------------+-------+---------------------------------------------------+ diff --git a/doc/shared/sunlinsol/SUNLinSol_KLU.rst b/doc/shared/sunlinsol/SUNLinSol_KLU.rst index 5fa33140c7..24c1ee7397 100644 --- a/doc/shared/sunlinsol/SUNLinSol_KLU.rst +++ b/doc/shared/sunlinsol/SUNLinSol_KLU.rst @@ -88,7 +88,7 @@ user-callable routines: constructor routine (or the previous ``SUNKLUReInit`` call). **Return value:** - * ``SUNLS_SUCCESS`` -- reinitialization successful. + * ``SUN_SUCCESS`` -- reinitialization successful. * ``SUNLS_MEM_NULL`` -- either ``S`` or ``A`` are ``NULL``. * ``SUNLS_ILL_INPUT`` -- ``A`` does not have type ``SUNMATRIX_SPARSE`` or ``reinit_type`` is invalid. @@ -116,7 +116,7 @@ user-callable routines: The default is 1 for COLAMD. **Return value:** - * ``SUNLS_SUCCESS`` -- ordering choice successfully updated. + * ``SUN_SUCCESS`` -- ordering choice successfully updated. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL``. * ``SUNLS_ILL_INPUT`` -- ``ordering_choice``. diff --git a/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst b/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst index 37efe8681b..9b981c3626 100644 --- a/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst +++ b/doc/shared/sunlinsol/SUNLinSol_MagmaDense.rst @@ -95,7 +95,7 @@ In addition, the module provides the following user-callable routines: * *onoff* -- 0 for synchronous mode or 1 for asynchronous mode (default 1) **Return value:** - * ``SUNLS_SUCCESS`` if successful + * ``SUN_SUCCESS`` if successful * ``SUNLS_MEM_NULL`` if *LS* is ``NULL`` diff --git a/doc/shared/sunlinsol/SUNLinSol_PCG.rst b/doc/shared/sunlinsol/SUNLinSol_PCG.rst index 4620aeb5d3..bc6d6e9db9 100644 --- a/doc/shared/sunlinsol/SUNLinSol_PCG.rst +++ b/doc/shared/sunlinsol/SUNLinSol_PCG.rst @@ -149,7 +149,7 @@ The module SUNLinSol_PCG provides the following user-callable routines: * ``SUN_PREC_BOTH`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``pretype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -170,7 +170,7 @@ The module SUNLinSol_PCG provides the following user-callable routines: non-positive input will result in the default value (5). **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -186,7 +186,7 @@ The module SUNLinSol_PCG provides the following user-callable routines: a ``NULL`` input will disable output **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled @@ -219,7 +219,7 @@ The module SUNLinSol_PCG provides the following user-callable routines: * 1, for each linear iteration the residual norm is printed **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled, or if the print level value was invalid diff --git a/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst b/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst index 9fd930ad7f..7f1ad4109a 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPBCGS.rst @@ -99,7 +99,7 @@ user-callable routines: * ``SUN_PREC_BOTH`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``pretype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -114,7 +114,7 @@ user-callable routines: non-positive input will result in the default value (5). **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -129,7 +129,7 @@ user-callable routines: a ``NULL`` input will disable output **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled @@ -160,7 +160,7 @@ user-callable routines: * 1, for each linear iteration the residual norm is printed **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled, or if the print level value was invalid diff --git a/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst index b864dab057..89f1418f27 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPFGMR.rst @@ -98,7 +98,7 @@ user-callable routines: * ``SUN_PREC_BOTH`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``pretype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -122,7 +122,7 @@ user-callable routines: * ``SUN_CLASSICAL_GS`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``gstype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -137,7 +137,7 @@ user-callable routines: result in the default of 0. **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -152,7 +152,7 @@ user-callable routines: a ``NULL`` input will disable output **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled @@ -185,7 +185,7 @@ user-callable routines: * 1, for each linear iteration the residual norm is printed **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled, or if the print level value was invalid diff --git a/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst index 4e665edf93..a3bc594577 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPGMR.rst @@ -92,7 +92,7 @@ user-callable routines: * ``SUN_PREC_BOTH`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``pretype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -109,7 +109,7 @@ user-callable routines: * ``SUN_CLASSICAL_GS`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``gstype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -124,7 +124,7 @@ user-callable routines: result in the default of 0. **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -139,7 +139,7 @@ user-callable routines: a ``NULL`` input will disable output **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled @@ -172,7 +172,7 @@ user-callable routines: * 1, for each linear iteration the residual norm is printed **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled, or if the print level value was invalid diff --git a/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst b/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst index 3513f66a41..c89e38ec6d 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SPTFQMR.rst @@ -99,7 +99,7 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: * ``SUN_PREC_BOTH`` **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_ILL_INPUT`` -- illegal ``pretype`` * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -114,7 +114,7 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: non-positive input will result in the default value (5). **Return value:** - * ``SUNLS_SUCCESS`` -- successful update. + * ``SUN_SUCCESS`` -- successful update. * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` @@ -129,7 +129,7 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: a ``NULL`` input will disable output **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled @@ -162,7 +162,7 @@ The module SUNLinSol_SPTFQMR provides the following user-callable routines: * 1, for each linear iteration the residual norm is printed **Return value:** - * *SUNLS_SUCCESS* if successful + * *SUN_SUCCESS* if successful * *SUNLS_MEM_NULL* if the SUNLinearSolver memory was ``NULL`` * *SUNLS_ILL_INPUT* if SUNDIALS was not built with monitoring enabled, or if the print level value was invalid diff --git a/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst b/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst index 371159d84f..e6de73fc4c 100644 --- a/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst +++ b/doc/shared/sunlinsol/SUNLinSol_SuperLUMT.rst @@ -93,7 +93,7 @@ The module SUNLinSol_SuperLUMT provides the following user-callable routines: The default is 3 for COLAMD. **Return value:** - * ``SUNLS_SUCCESS`` -- option successfully set + * ``SUN_SUCCESS`` -- option successfully set * ``SUNLS_MEM_NULL`` -- ``S`` is ``NULL`` * ``SUNLS_ILL_INPUT`` -- invalid ``ordering_choice`` diff --git a/doc/shared/sunnonlinsol/SUNNonlinSol_API.rst b/doc/shared/sunnonlinsol/SUNNonlinSol_API.rst index 60dd19a2d5..f3af6e1fbf 100644 --- a/doc/shared/sunnonlinsol/SUNNonlinSol_API.rst +++ b/doc/shared/sunnonlinsol/SUNNonlinSol_API.rst @@ -458,7 +458,7 @@ module have types defined in the header file The return value of this routine will be a negative value if an unrecoverable error occurred or one of the following: - * ``SUN_NLS_SUCCESS`` -- the iteration is converged. + * ``SUN_SUCCESS`` -- the iteration is converged. * ``SUN_NLS_CONTINUE`` -- the iteration has not converged, keep iterating. @@ -493,22 +493,12 @@ successful call. +-----------------------+---------+---------------------------------------------------------------+ | Name | Value | Description | +=======================+=========+===============================================================+ - | SUN_NLS_SUCCESS | 0 | successful call or converged solve | + | SUN_SUCCESS | 0 | successful call or converged solve | +-----------------------+---------+---------------------------------------------------------------+ | SUN_NLS_CONTINUE | 901 | the nonlinear solver is not converged, keep iterating | +-----------------------+---------+---------------------------------------------------------------+ | SUN_NLS_CONV_RECVR | 902 | the nonlinear solver appears to be diverging, try to recover | +-----------------------+---------+---------------------------------------------------------------+ - | SUN_NLS_MEM_NULL | -901 | a memory argument is ``NULL`` | - +-----------------------+---------+---------------------------------------------------------------+ - | SUN_NLS_MEM_FAIL | -902 | a memory access or allocation failed | - +-----------------------+---------+---------------------------------------------------------------+ - | SUN_NLS_ILL_INPUT | -903 | an illegal input option was provided | - +-----------------------+---------+---------------------------------------------------------------+ - | SUN_NLS_VECTOROP_ERR | -904 | a NVECTOR operation failed | - +-----------------------+---------+---------------------------------------------------------------+ - | SUN_NLS_EXT_FAIL | -905 | an external library call returned an error | - +-----------------------+---------+---------------------------------------------------------------+ diff --git a/doc/shared/sunnonlinsol/SUNNonlinSol_FixedPoint.rst b/doc/shared/sunnonlinsol/SUNNonlinSol_FixedPoint.rst index 8e0ed3ecf4..5b3c45c113 100644 --- a/doc/shared/sunnonlinsol/SUNNonlinSol_FixedPoint.rst +++ b/doc/shared/sunnonlinsol/SUNNonlinSol_FixedPoint.rst @@ -182,9 +182,9 @@ user-callable functions. * *beta* -- the damping parameter :math:`0 < \beta \leq 1`. **Return value:** - * ``SUN_NLS_SUCCESS`` if successful. - * ``SUN_NLS_MEM_NULL`` if ``NLS`` was ``NULL``. - * ``SUN_NLS_ILL_INPUT`` if ``beta`` was negative. + * ``SUN_SUCCESS`` if successful. + * ``SUN_ERR_ARG_CORRUPT`` if ``NLS`` was ``NULL``. + * ``SUN_ERR_ARG_INCOMPATIBLE`` if ``beta`` was negative. **Notes:** A ``beta`` value should satisfy :math:`0 < \beta < 1` if @@ -202,9 +202,9 @@ user-callable functions. a ``NULL`` input will disable output. **Return value:** - * ``SUN_NLS_SUCCESS`` if successful. - * ``SUN_NLS_MEM_NULL`` if ``NLS`` was ``NULL``. - * ``SUN_NLS_ILL_INPUT`` if SUNDIALS was not built with monitoring enabled. + * ``SUN_SUCCESS`` if successful. + * ``SUN_ERR_ARG_CORRUPT`` if ``NLS`` was ``NULL``. + * ``SUN_ERR_ARG_INCOMPATIBLE`` if SUNDIALS was not built with monitoring enabled. **Notes:** This function is intended for users that wish to monitor the nonlinear @@ -234,9 +234,9 @@ user-callable functions. * 1, for each nonlinear iteration the residual norm is printed. **Return value:** - * ``SUN_NLS_SUCCESS`` if successful. - * ``SUN_NLS_MEM_NULL`` if ``NLS`` was ``NULL``. - * ``SUN_NLS_ILL_INPUT`` if SUNDIALS was not built with monitoring enabled, + * ``SUN_SUCCESS`` if successful. + * ``SUN_ERR_ARG_CORRUPT`` if ``NLS`` was ``NULL``. + * ``SUN_ERR_ARG_INCOMPATIBLE`` if SUNDIALS was not built with monitoring enabled, or the print level value was invalid. **Notes:** diff --git a/doc/shared/sunnonlinsol/SUNNonlinSol_Newton.rst b/doc/shared/sunnonlinsol/SUNNonlinSol_Newton.rst index 3d7077f769..6113807214 100644 --- a/doc/shared/sunnonlinsol/SUNNonlinSol_Newton.rst +++ b/doc/shared/sunnonlinsol/SUNNonlinSol_Newton.rst @@ -160,9 +160,9 @@ user-callable function. a ``NULL`` input will disable output. **Return value:** - * ``SUN_NLS_SUCCESS`` if successful. - * ``SUN_NLS_MEM_NULL`` if the SUNNonlinSol memory was ``NULL``. - * ``SUN_NLS_ILL_INPUT`` if SUNDIALS was not built with monitoring enabled. + * ``SUN_SUCCESS`` if successful. + * ``SUN_ERR_ARG_CORRUPT`` if the SUNNonlinSol memory was ``NULL``. + * ``SUN_ERR_ARG_INCOMPATIBLE`` if SUNDIALS was not built with monitoring enabled. **Notes:** This function is intended for users that wish to monitor the nonlinear @@ -192,9 +192,9 @@ user-callable function. * 1, for each nonlinear iteration the residual norm is printed. **Return value:** - * ``SUN_NLS_SUCCESS`` if successful. - * ``SUN_NLS_MEM_NULL`` if the SUNNonlinearSolver memory was ``NULL``. - * ``SUN_NLS_ILL_INPUT`` if SUNDIALS was not built with monitoring enabled, + * ``SUN_SUCCESS`` if successful. + * ``SUN_ERR_ARG_CORRUPT`` if the SUNNonlinearSolver memory was ``NULL``. + * ``SUN_ERR_ARG_INCOMPATIBLE`` if SUNDIALS was not built with monitoring enabled, or the print level value was invalid. **Notes:** diff --git a/doc/superbuild/source/developers/style_guide/SourceCode.rst b/doc/superbuild/source/developers/style_guide/SourceCode.rst index a86a21cdd7..5c2cfb6ca4 100644 --- a/doc/superbuild/source/developers/style_guide/SourceCode.rst +++ b/doc/superbuild/source/developers/style_guide/SourceCode.rst @@ -226,7 +226,7 @@ Coding Conventions and Rules { auto solver{static_cast*>(S->content)}; delete solver; // NOLINT - return SUNLS_SUCCESS; + return SUN_SUCCESS } class BaseObject { @@ -425,7 +425,7 @@ It may be necessary to override clang-tidy at times. This can be done with the { auto solver{static_cast*>(S->content)}; delete solver; // NOLINT - return SUNLS_SUCCESS; + return SUN_SUCCESS } class BaseObject { diff --git a/examples/arkode/CXX_parallel/ark_brusselator1D_task_local_nls.cpp b/examples/arkode/CXX_parallel/ark_brusselator1D_task_local_nls.cpp index b413475428..c411730783 100644 --- a/examples/arkode/CXX_parallel/ark_brusselator1D_task_local_nls.cpp +++ b/examples/arkode/CXX_parallel/ark_brusselator1D_task_local_nls.cpp @@ -986,7 +986,7 @@ SUNNonlinearSolver_Type TaskLocalNewton_GetType(SUNNonlinearSolver NLS) int TaskLocalNewton_Initialize(SUNNonlinearSolver NLS) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* override default system and lsolve functions with local versions */ SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), TaskLocalNlsResidual); @@ -1007,7 +1007,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || (mem == NULL)) { - return SUN_NLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } /* shortcuts */ @@ -1034,7 +1034,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, int TaskLocalNewton_Free(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return SUN_NLS_SUCCESS; } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from contents, then the generic structure */ if (NLS->content) @@ -1054,13 +1054,13 @@ int TaskLocalNewton_Free(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } int TaskLocalNewton_SetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), SysFn)); } @@ -1070,7 +1070,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, void* ctest_data) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetConvTestFn(LOCAL_NLS(NLS), CTestFn, ctest_data)); } @@ -1078,7 +1078,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, int TaskLocalNewton_GetNumConvFails(SUNNonlinearSolver NLS, long int* nconvfails) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } *nconvfails = GET_NLS_CONTENT(NLS)->ncnf; return (0); diff --git a/examples/arkode/CXX_parhyp/ark_heat2D_hypre_ls.cpp b/examples/arkode/CXX_parhyp/ark_heat2D_hypre_ls.cpp index b36d81c8c8..00e05ce734 100644 --- a/examples/arkode/CXX_parhyp/ark_heat2D_hypre_ls.cpp +++ b/examples/arkode/CXX_parhyp/ark_heat2D_hypre_ls.cpp @@ -2703,7 +2703,7 @@ int HypreLS_Setup(SUNLinearSolver LS, SUNMatrix A) udata->setuptime += t2 - t1; // Return success - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int HypreLS_Solve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, @@ -2800,14 +2800,14 @@ int HypreLS_Solve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, udata->solvetime += t2 - t1; // Return success - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int HypreLS_NumIters(SUNLinearSolver LS) { return ((int)HLS_ITERS(LS)); } int HypreLS_Free(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } if (LS->content != NULL) { if (HLS_SOLVER(LS)) @@ -2822,7 +2822,7 @@ int HypreLS_Free(SUNLinearSolver LS) LS->content = NULL; } SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } //---- end of file ---- diff --git a/examples/arkode/C_parallel/ark_brusselator1D_task_local_nls.c b/examples/arkode/C_parallel/ark_brusselator1D_task_local_nls.c index 8a097e1afc..b81bcf3c5d 100644 --- a/examples/arkode/C_parallel/ark_brusselator1D_task_local_nls.c +++ b/examples/arkode/C_parallel/ark_brusselator1D_task_local_nls.c @@ -1035,7 +1035,7 @@ SUNNonlinearSolver_Type TaskLocalNewton_GetType(SUNNonlinearSolver NLS) int TaskLocalNewton_Initialize(SUNNonlinearSolver NLS) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* override default system and lsolve functions with local versions */ SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), TaskLocalNlsResidual); @@ -1056,7 +1056,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || (mem == NULL)) { - return SUN_NLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } /* shortcuts */ @@ -1083,7 +1083,7 @@ int TaskLocalNewton_Solve(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, int TaskLocalNewton_Free(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return SUN_NLS_SUCCESS; } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from contents, then the generic structure */ if (NLS->content) @@ -1103,13 +1103,13 @@ int TaskLocalNewton_Free(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } int TaskLocalNewton_SetSysFn(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetSysFn(LOCAL_NLS(NLS), SysFn)); } @@ -1119,7 +1119,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, void* ctest_data) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (SUNNonlinSolSetConvTestFn(LOCAL_NLS(NLS), CTestFn, ctest_data)); } @@ -1127,7 +1127,7 @@ int TaskLocalNewton_SetConvTestFn(SUNNonlinearSolver NLS, int TaskLocalNewton_GetNumConvFails(SUNNonlinearSolver NLS, long int* nconvfails) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } return (GET_NLS_CONTENT(NLS)->ncnf); } diff --git a/examples/arkode/C_serial/ark_analytic_mels.c b/examples/arkode/C_serial/ark_analytic_mels.c index 13f771d2e0..46fd93eb38 100644 --- a/examples/arkode/C_serial/ark_analytic_mels.c +++ b/examples/arkode/C_serial/ark_analytic_mels.c @@ -266,16 +266,16 @@ static int MatrixEmbeddedLSSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, NV_Ith_S(x, 0) = NV_Ith_S(b, 0) / (1 - gamma * lamda); /* return with success */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /* destructor */ static int MatrixEmbeddedLSFree(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } LS->content = NULL; SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /*------------------------------- diff --git a/examples/arkode/F2003_custom/test_fsunlinsol_fortran_mod.f90 b/examples/arkode/F2003_custom/test_fsunlinsol_fortran_mod.f90 index 1496141b70..a84be7c197 100644 --- a/examples/arkode/F2003_custom/test_fsunlinsol_fortran_mod.f90 +++ b/examples/arkode/F2003_custom/test_fsunlinsol_fortran_mod.f90 @@ -167,7 +167,7 @@ program main ! test SUNLinSolSetup retval = FSUNLinSolSetup(LS, sA) - if (retval /= SUNLS_SUCCESS) then + if (retval /= SUN_SUCCESS) then fails = fails + 1 print *, '>>> FAILED test -- FSUNLinSolSetup' else @@ -178,7 +178,7 @@ program main call FN_VConst(0.d0, sY) retval = FSUNLinSolSolve(LS, sA, sY, sB, 1.d-9) if ( (check_vector(sX, sY, 1.d-15*Nvar*Nvar, Nvar, N) /= 0) & - .or. (retval /= SUNLS_SUCCESS) ) then + .or. (retval /= SUN_SUCCESS) ) then fails = fails + 1 print *, '>>> FAILED test -- FSUNLinSolSolve' else diff --git a/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls.cpp b/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls.cpp index 636778f83d..39456fb8ba 100644 --- a/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls.cpp +++ b/examples/cvode/CXX_parhyp/cv_heat2D_hypre_ls.cpp @@ -2611,7 +2611,7 @@ int HypreLS_Setup(SUNLinearSolver LS, SUNMatrix A) udata->setuptime += t2 - t1; // Return success - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int HypreLS_Solve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, @@ -2708,14 +2708,14 @@ int HypreLS_Solve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, N_Vector b, udata->solvetime += t2 - t1; // Return success - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int HypreLS_NumIters(SUNLinearSolver LS) { return ((int)HLS_ITERS(LS)); } int HypreLS_Free(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } if (LS->content != NULL) { if (HLS_SOLVER(LS)) @@ -2730,7 +2730,7 @@ int HypreLS_Free(SUNLinearSolver LS) LS->content = NULL; } SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } //---- end of file ---- diff --git a/examples/cvode/serial/cvAnalytic_mels.c b/examples/cvode/serial/cvAnalytic_mels.c index a0d6880ce1..9776cb1528 100644 --- a/examples/cvode/serial/cvAnalytic_mels.c +++ b/examples/cvode/serial/cvAnalytic_mels.c @@ -267,16 +267,16 @@ static int MatrixEmbeddedLSSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, NV_Ith_S(x, 0) = NV_Ith_S(b, 0) / (1 - gamma * lamda); /* return with success */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /* destructor */ static int MatrixEmbeddedLSFree(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } LS->content = NULL; SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /*------------------------------- diff --git a/examples/cvodes/serial/cvsAnalytic_mels.c b/examples/cvodes/serial/cvsAnalytic_mels.c index e2bcfd779d..d798ace807 100644 --- a/examples/cvodes/serial/cvsAnalytic_mels.c +++ b/examples/cvodes/serial/cvsAnalytic_mels.c @@ -267,16 +267,16 @@ static int MatrixEmbeddedLSSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, NV_Ith_S(x, 0) = NV_Ith_S(b, 0) / (1 - gamma * lamda); /* return with success */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /* destructor */ static int MatrixEmbeddedLSFree(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } LS->content = NULL; SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /*------------------------------- diff --git a/examples/ida/serial/idaAnalytic_mels.c b/examples/ida/serial/idaAnalytic_mels.c index d8093226eb..6ade175738 100644 --- a/examples/ida/serial/idaAnalytic_mels.c +++ b/examples/ida/serial/idaAnalytic_mels.c @@ -280,16 +280,16 @@ static int MatrixEmbeddedLSSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, NV_Ith_S(x, 1) = -(a11 * b2 - a21 * b1) / (a12 * a21); /* return with success */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /* destructor */ static int MatrixEmbeddedLSFree(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } LS->content = NULL; SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /*------------------------------- diff --git a/examples/idas/serial/idasAnalytic_mels.c b/examples/idas/serial/idasAnalytic_mels.c index a412da6a1a..76754f7d75 100644 --- a/examples/idas/serial/idasAnalytic_mels.c +++ b/examples/idas/serial/idasAnalytic_mels.c @@ -280,16 +280,16 @@ static int MatrixEmbeddedLSSolve(SUNLinearSolver LS, SUNMatrix A, N_Vector x, NV_Ith_S(x, 1) = -(a11 * b2 - a21 * b1) / (a12 * a21); /* return with success */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /* destructor */ static int MatrixEmbeddedLSFree(SUNLinearSolver LS) { - if (LS == NULL) { return (SUNLS_SUCCESS); } + if (LS == NULL) { return (SUN_SUCCESS); } LS->content = NULL; SUNLinSolFreeEmpty(LS); - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } /*------------------------------- diff --git a/examples/sunnonlinsol/fixedpoint/test_fsunnonlinsol_fixedpoint_mod.f90 b/examples/sunnonlinsol/fixedpoint/test_fsunnonlinsol_fixedpoint_mod.f90 index dd3b4d4529..3e6d872052 100644 --- a/examples/sunnonlinsol/fixedpoint/test_fsunnonlinsol_fixedpoint_mod.f90 +++ b/examples/sunnonlinsol/fixedpoint/test_fsunnonlinsol_fixedpoint_mod.f90 @@ -140,7 +140,7 @@ integer(C_INT) function ConvTest(NLS, y, del, tol, ewt, mem) & delnrm = FN_VMaxNorm(del) if (delnrm <= tol) then - retval = SUN_NLS_SUCCESS ! converged + retval = SUN_SUCCESS ! converged else retval = SUN_NLS_CONTINUE ! not converged end if diff --git a/examples/sunnonlinsol/fixedpoint/test_sunnonlinsol_fixedpoint.c b/examples/sunnonlinsol/fixedpoint/test_sunnonlinsol_fixedpoint.c index 5bac2f6fb1..1e81703cd2 100644 --- a/examples/sunnonlinsol/fixedpoint/test_sunnonlinsol_fixedpoint.c +++ b/examples/sunnonlinsol/fixedpoint/test_sunnonlinsol_fixedpoint.c @@ -238,7 +238,7 @@ int ConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, sunrealtype tol, /* compute the norm of the correction */ delnrm = N_VMaxNorm(del); - if (delnrm <= tol) { return (SUN_NLS_SUCCESS); /* success */ } + if (delnrm <= tol) { return (SUN_SUCCESS); /* success */ } else { return (SUN_NLS_CONTINUE); /* not converged */ } } diff --git a/examples/sunnonlinsol/newton/test_fsunnonlinsol_newton_mod.f90 b/examples/sunnonlinsol/newton/test_fsunnonlinsol_newton_mod.f90 index e428b365cc..bbc21e9506 100644 --- a/examples/sunnonlinsol/newton/test_fsunnonlinsol_newton_mod.f90 +++ b/examples/sunnonlinsol/newton/test_fsunnonlinsol_newton_mod.f90 @@ -246,7 +246,7 @@ integer(C_INT) function ConvTest(NLS, y, del, tol, ewt, mem) & delnrm = FN_VWrmsNorm(del, ewt) if (delnrm <= tol) then - retval = SUN_NLS_SUCCESS ! converged + retval = SUN_SUCCESS ! converged else retval = SUN_NLS_CONTINUE ! not converged end if diff --git a/examples/sunnonlinsol/newton/test_sunnonlinsol_newton.c b/examples/sunnonlinsol/newton/test_sunnonlinsol_newton.c index 8fef2a1d18..709450dfcb 100644 --- a/examples/sunnonlinsol/newton/test_sunnonlinsol_newton.c +++ b/examples/sunnonlinsol/newton/test_sunnonlinsol_newton.c @@ -268,7 +268,7 @@ int ConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, sunrealtype tol, /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); - if (delnrm <= tol) { return (SUN_NLS_SUCCESS); /* success */ } + if (delnrm <= tol) { return (SUN_SUCCESS); /* success */ } else { return (SUN_NLS_CONTINUE); /* not converged */ } } diff --git a/include/sundials/sundials_errors.h b/include/sundials/sundials_errors.h index ae491a9577..10c138646e 100644 --- a/include/sundials/sundials_errors.h +++ b/include/sundials/sundials_errors.h @@ -40,6 +40,7 @@ ENTRY(SUN_ERR_MEM_FAIL, "a memory operation failed") \ ENTRY(SUN_ERR_MALLOC_FAIL, "malloc returned NULL") \ ENTRY(SUN_ERR_DESTROY_FAIL, "a destroy function returned an error") \ + ENTRY(SUN_ERR_EXT_FAIL, "a failure occured in an external library") \ ENTRY(SUN_ERR_NOT_IMPLEMENTED, \ "operation is not implemented: function pointer is NULL") \ \ diff --git a/include/sundials/sundials_linearsolver.h b/include/sundials/sundials_linearsolver.h index de119cd1f7..a26f7b5bdb 100644 --- a/include/sundials/sundials_linearsolver.h +++ b/include/sundials/sundials_linearsolver.h @@ -214,33 +214,14 @@ SUNErrCode SUNLinSolFree(SUNLinearSolver S); * SUNLinearSolver return values * ----------------------------------------------------------------- */ -/* TODO(CJB): We should remove all codes which are not associated - with recoverable errors. Typically these are 'convergence' - or 'numerical' in nature. Do not remove errors which - unrecoverable but have a recoverable dual. */ - -#define SUNLS_SUCCESS 0 /* successful/converged */ - -#define SUNLS_UNRECOV_FAILURE -800 /* generic unrecoverable failure */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_MEM_NULL -801 /* mem argument is NULL */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_ILL_INPUT -802 /* illegal function input */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_MEM_FAIL -803 /* failed memory access */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_ATIMES_NULL -804 /* atimes function is NULL */ -#define SUNLS_ATIMES_FAIL_UNREC -805 /* atimes unrecoverable failure */ -#define SUNLS_PSET_FAIL_UNREC -806 /* pset unrecoverable failure */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_PSOLVE_NULL -807 /* psolve function is NULL */ -#define SUNLS_PSOLVE_FAIL_UNREC -808 /* psolve unrecoverable failure */ -/* DEPRECATED: use SUNErrCode instead */ +#define SUNLS_ATIMES_NULL -804 /* atimes function is NULL */ +#define SUNLS_ATIMES_FAIL_UNREC -805 /* atimes unrecoverable failure */ +#define SUNLS_PSET_FAIL_UNREC -806 /* pset unrecoverable failure */ +#define SUNLS_PSOLVE_NULL -807 /* psolve function is NULL */ +#define SUNLS_PSOLVE_FAIL_UNREC -808 /* psolve unrecoverable failure */ #define SUNLS_PACKAGE_FAIL_UNREC -809 /* external package unrec. fail */ #define SUNLS_GS_FAIL -810 /* Gram-Schmidt failure */ #define SUNLS_QRSOL_FAIL -811 /* QRsol found singular R */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUNLS_VECTOROP_ERR -812 /* vector operation error */ #define SUNLS_RECOV_FAILURE 800 /* generic recoverable failure */ #define SUNLS_RES_REDUCED 801 /* nonconv. solve, resid reduced */ diff --git a/include/sundials/sundials_nonlinearsolver.h b/include/sundials/sundials_nonlinearsolver.h index 80cad26091..759b40e172 100644 --- a/include/sundials/sundials_nonlinearsolver.h +++ b/include/sundials/sundials_nonlinearsolver.h @@ -194,25 +194,10 @@ SUNErrCode SUNNonlinSolGetNumConvFails(SUNNonlinearSolver NLS, * SUNNonlinearSolver return values * ---------------------------------------------------------------------------*/ -#define SUN_NLS_SUCCESS 0 /* successful / converged */ - /* Recoverable */ #define SUN_NLS_CONTINUE +901 /* not converged, keep iterating */ #define SUN_NLS_CONV_RECVR +902 /* convergece failure, try to recover */ -/* Unrecoverable */ - -/* DEPRECATED: use SUNErrCode instead */ -#define SUN_NLS_MEM_NULL -901 /* memory argument is NULL */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUN_NLS_MEM_FAIL -902 /* failed memory access / allocation */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUN_NLS_ILL_INPUT -903 /* illegal function input */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUN_NLS_VECTOROP_ERR -904 /* failed NVector operation */ -/* DEPRECATED: use SUNErrCode instead */ -#define SUN_NLS_EXT_FAIL -905 /* failed in external library call */ - /* ----------------------------------------------------------------------------- * SUNNonlinearSolver messages * ---------------------------------------------------------------------------*/ diff --git a/include/sunlinsol/sunlinsol_band.h b/include/sunlinsol/sunlinsol_band.h index fffa0777c2..6ddc79ec2c 100644 --- a/include/sunlinsol/sunlinsol_band.h +++ b/include/sunlinsol/sunlinsol_band.h @@ -51,18 +51,34 @@ typedef struct _SUNLinearSolverContent_Band* SUNLinearSolverContent_Band; * Exported Functions for SUNLINSOL_BAND * -------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, - SUNContext sunctx); -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A); -SUNDIALS_EXPORT int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, sunrealtype tol); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_Band(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Band(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_cusolversp_batchqr.h b/include/sunlinsol/sunlinsol_cusolversp_batchqr.h index f6f6c77fcf..358a8a9b90 100644 --- a/include/sunlinsol/sunlinsol_cusolversp_batchqr.h +++ b/include/sunlinsol/sunlinsol_cusolversp_batchqr.h @@ -71,7 +71,7 @@ SUNLinSolGetType_cuSolverSp_batchQR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_cuSolverSp_batchQR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_cuSolverSp_batchQR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_cuSolverSp_batchQR(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_cuSolverSp_batchQR(SUNLinearSolver S, SUNMatrix A); @@ -83,7 +83,7 @@ SUNDIALS_EXPORT int SUNLinSolSolve_cuSolverSp_batchQR(SUNLinearSolver S, SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_cuSolverSp_batchQR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolFree_cuSolverSp_batchQR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_cuSolverSp_batchQR(SUNLinearSolver S); /* * ---------------------------------------------------------------------------- diff --git a/include/sunlinsol/sunlinsol_dense.h b/include/sunlinsol/sunlinsol_dense.h index bcac0a520c..877c524e2a 100644 --- a/include/sunlinsol/sunlinsol_dense.h +++ b/include/sunlinsol/sunlinsol_dense.h @@ -56,18 +56,34 @@ typedef struct _SUNLinearSolverContent_Dense* SUNLinearSolverContent_Dense; * Exported Functions for SUNLINSOL_DENSE * ---------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, - SUNContext sunctx); -SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A); -SUNDIALS_EXPORT int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, - N_Vector x, N_Vector b, sunrealtype tol); -SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_Dense(SUNLinearSolver S); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A); + +SUNDIALS_EXPORT +int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_Dense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_ginkgo.hpp b/include/sunlinsol/sunlinsol_ginkgo.hpp index 57ff2bc5b7..283d6d51a6 100644 --- a/include/sunlinsol/sunlinsol_ginkgo.hpp +++ b/include/sunlinsol/sunlinsol_ginkgo.hpp @@ -53,7 +53,7 @@ int SUNLinSolSetup_Ginkgo(SUNLinearSolver S, SUNMatrix A) auto solver{ static_cast*>(S->content)}; solver->Setup(static_cast*>(A->content)); - return SUNLS_SUCCESS; + return SUN_SUCCESS; } template @@ -63,16 +63,16 @@ int SUNLinSolSolve_Ginkgo(SUNLinearSolver S, SUNMatrix A, N_Vector x, auto solver{ static_cast*>(S->content)}; solver->Solve(b, x, tol); - return SUNLS_SUCCESS; + return SUN_SUCCESS; } template -int SUNLinSolFree_Ginkgo(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_Ginkgo(SUNLinearSolver S) { auto solver{ static_cast*>(S->content)}; delete solver; // NOLINT - return SUNLS_SUCCESS; + return SUN_SUCCESS; } template diff --git a/include/sunlinsol/sunlinsol_klu.h b/include/sunlinsol/sunlinsol_klu.h index 85d4d8b6d6..9657742508 100644 --- a/include/sunlinsol/sunlinsol_klu.h +++ b/include/sunlinsol/sunlinsol_klu.h @@ -125,14 +125,15 @@ SUNDIALS_EXPORT sun_klu_common* SUNLinSol_KLUGetCommon(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_KLU(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_KLU(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_KLU(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_KLU(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_KLU(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_KLU(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_KLU(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_KLU(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_KLU(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_KLU(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_kokkosdense.hpp b/include/sunlinsol/sunlinsol_kokkosdense.hpp index 0729d016f2..e952da1c0d 100644 --- a/include/sunlinsol/sunlinsol_kokkosdense.hpp +++ b/include/sunlinsol/sunlinsol_kokkosdense.hpp @@ -76,7 +76,7 @@ int SUNLinSolSetup_KokkosDense(SUNLinearSolver S, SUNMatrix A) A_subdata); }); - return SUNLS_SUCCESS; + return SUN_SUCCESS; } template @@ -128,15 +128,15 @@ int SUNLinSolSolve_KokkosDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, A_subdata, x_subdata); }); - return SUNLS_SUCCESS; + return SUN_SUCCESS; } template -int SUNLinSolFree_KokkosDense(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_KokkosDense(SUNLinearSolver S) { auto S_ls{static_cast(S->content)}; delete S_ls; // NOLINT - return SUNLS_SUCCESS; + return SUN_SUCCESS; } } // namespace impl diff --git a/include/sunlinsol/sunlinsol_lapackband.h b/include/sunlinsol/sunlinsol_lapackband.h index d60d14f00e..0094504c8b 100644 --- a/include/sunlinsol/sunlinsol_lapackband.h +++ b/include/sunlinsol/sunlinsol_lapackband.h @@ -54,16 +54,16 @@ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackBand(N_Vector y, SUNMatrix A, SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackBand(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_LapackBand(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_LapackBand(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_LapackBand(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_LapackBand(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_LapackBand(SUNLinearSolver S, - long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_LapackBand(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_LapackBand(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_LapackBand(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_lapackdense.h b/include/sunlinsol/sunlinsol_lapackdense.h index 03420556b3..a61fb6d965 100644 --- a/include/sunlinsol/sunlinsol_lapackdense.h +++ b/include/sunlinsol/sunlinsol_lapackdense.h @@ -54,16 +54,16 @@ SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_LapackDense(N_Vector y, SUNMatrix A, SUNContext sunctx); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_LapackDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_LapackDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_LapackDense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_LapackDense(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_LapackDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_LapackDense(SUNLinearSolver S, - long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_LapackDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_LapackDense(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_LapackDense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_magmadense.h b/include/sunlinsol/sunlinsol_magmadense.h index b75d03b204..0b0825a415 100644 --- a/include/sunlinsol/sunlinsol_magmadense.h +++ b/include/sunlinsol/sunlinsol_magmadense.h @@ -64,16 +64,16 @@ SUNDIALS_EXPORT int SUNLinSol_MagmaDense_SetAsync(SUNLinearSolver S, SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_MagmaDense(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_MagmaDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_MagmaDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_MagmaDense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_MagmaDense(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_MagmaDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_MagmaDense(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_MagmaDense(SUNLinearSolver S, - long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_MagmaDense(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_MagmaDense(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_MagmaDense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_onemkldense.h b/include/sunlinsol/sunlinsol_onemkldense.h index 8951831dd6..5927aced8b 100644 --- a/include/sunlinsol/sunlinsol_onemkldense.h +++ b/include/sunlinsol/sunlinsol_onemkldense.h @@ -64,7 +64,7 @@ SUNLinearSolver_ID SUNLinSolGetID_OneMklDense(SUNLinearSolver S) }; SUNDIALS_EXPORT -int SUNLinSolInitialize_OneMklDense(SUNLinearSolver S); +SUNErrCode SUNLinSolInitialize_OneMklDense(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A); @@ -77,11 +77,11 @@ SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_OneMklDense(SUNLinearSolver S); SUNDIALS_EXPORT -int SUNLinSolSpace_OneMklDense(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); +SUNErrCode SUNLinSolSpace_OneMklDense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); SUNDIALS_EXPORT -int SUNLinSolFree_OneMklDense(SUNLinearSolver S); +SUNErrCode SUNLinSolFree_OneMklDense(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_pcg.h b/include/sunlinsol/sunlinsol_pcg.h index 2106b59f2c..f9f66df3b4 100644 --- a/include/sunlinsol/sunlinsol_pcg.h +++ b/include/sunlinsol/sunlinsol_pcg.h @@ -71,23 +71,80 @@ typedef struct _SUNLinearSolverContent_PCG* SUNLinearSolverContent_PCG; * Exported Functions for SUNLINSOL_PCG * ------------------------------------- */ -SUNDIALS_EXPORT SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, - SUNContext sunctx); -SUNDIALS_EXPORT int SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype); -SUNDIALS_EXPORT int SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl); +SUNDIALS_EXPORT +SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, + SUNContext sunctx); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl); + +SUNDIALS_EXPORT +SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* P_data, + SUNPSetupFn Pset, SUNPSolveFn Psol); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, + N_Vector nul); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, sunbooleantype onoff); + +SUNDIALS_EXPORT +int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul); + +SUNDIALS_EXPORT +int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, + sunrealtype tol); + +SUNDIALS_EXPORT +int SUNLinSolNumIters_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunrealtype SUNLinSolResNorm_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +N_Vector SUNLinSolResid_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS); + +SUNDIALS_EXPORT +SUNErrCode SUNLinSolFree_PCG(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_PCG(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, - SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, - void* P_data, SUNPSetupFn Pset, - SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, - N_Vector s, N_Vector nul); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, - sunbooleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, + N_Vector s, + N_Vector nul); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul); SUNDIALS_EXPORT int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, sunrealtype tol); @@ -95,9 +152,10 @@ SUNDIALS_EXPORT int SUNLinSolNumIters_PCG(SUNLinearSolver S); SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_PCG(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_PCG(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_PCG(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_PCG(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_PCG(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_spbcgs.h b/include/sunlinsol/sunlinsol_spbcgs.h index 80c090f52e..99a1a038fa 100644 --- a/include/sunlinsol/sunlinsol_spbcgs.h +++ b/include/sunlinsol/sunlinsol_spbcgs.h @@ -84,17 +84,19 @@ SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, int pretype); SUNDIALS_EXPORT int SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* A_data, - SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, - void* P_data, - SUNPSetupFn Pset, - SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, - N_Vector s1, N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, - sunbooleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPBCGS(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, @@ -103,9 +105,10 @@ SUNDIALS_EXPORT int SUNLinSolNumIters_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPBCGS(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPBCGS(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPBCGS(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPBCGS(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPBCGS(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPBCGS(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_spfgmr.h b/include/sunlinsol/sunlinsol_spfgmr.h index 3fed249e16..923e3135b7 100644 --- a/include/sunlinsol/sunlinsol_spfgmr.h +++ b/include/sunlinsol/sunlinsol_spfgmr.h @@ -92,17 +92,19 @@ SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, int gstype); SUNDIALS_EXPORT int SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* A_data, - SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, - void* P_data, - SUNPSetupFn Pset, - SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, - N_Vector s1, N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, - sunbooleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, @@ -111,9 +113,10 @@ SUNDIALS_EXPORT int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPFGMR(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPFGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPFGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPFGMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_spgmr.h b/include/sunlinsol/sunlinsol_spgmr.h index 0efb61fb18..a85ecc2484 100644 --- a/include/sunlinsol/sunlinsol_spgmr.h +++ b/include/sunlinsol/sunlinsol_spgmr.h @@ -92,17 +92,19 @@ SUNDIALS_EXPORT int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, int gstype); SUNDIALS_EXPORT int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* A_data, - SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, - void* P_data, - SUNPSetupFn Pset, - SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, - N_Vector s1, N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, - sunbooleantype onff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, + sunbooleantype onff); SUNDIALS_EXPORT int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); @@ -110,9 +112,10 @@ SUNDIALS_EXPORT int SUNLinSolNumIters_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPGMR(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPGMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPGMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPGMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_sptfqmr.h b/include/sunlinsol/sunlinsol_sptfqmr.h index 813381cbf4..70bebb55d1 100644 --- a/include/sunlinsol/sunlinsol_sptfqmr.h +++ b/include/sunlinsol/sunlinsol_sptfqmr.h @@ -86,17 +86,19 @@ SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, int pretype) SUNDIALS_EXPORT int SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* A_data, - SUNATimesFn ATimes); -SUNDIALS_EXPORT int SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, - void* P_data, - SUNPSetupFn Pset, - SUNPSolveFn Psol); -SUNDIALS_EXPORT int SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, - N_Vector s1, N_Vector s2); -SUNDIALS_EXPORT int SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, - sunbooleantype onoff); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, + void* A_data, + SUNATimesFn ATimes); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, + void* P_data, + SUNPSetupFn Pset, + SUNPSolveFn Psol); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, + N_Vector s1, + N_Vector s2); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, + sunbooleantype onoff); SUNDIALS_EXPORT int SUNLinSolSetup_SPTFQMR(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, @@ -105,9 +107,10 @@ SUNDIALS_EXPORT int SUNLinSolNumIters_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT sunrealtype SUNLinSolResNorm_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT N_Vector SUNLinSolResid_SPTFQMR(SUNLinearSolver S); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SPTFQMR(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SPTFQMR(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SPTFQMR(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_superludist.h b/include/sunlinsol/sunlinsol_superludist.h index 50bdfeca28..f0f6e6299c 100644 --- a/include/sunlinsol/sunlinsol_superludist.h +++ b/include/sunlinsol/sunlinsol_superludist.h @@ -110,16 +110,16 @@ SUNDIALS_EXPORT SuperLUStat_t* SUNLinSol_SuperLUDIST_GetSuperLUStat( SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUDIST(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SuperLUDIST(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_SuperLUDIST(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SuperLUDIST(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SuperLUDIST(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, - long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SuperLUDIST(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SuperLUDIST(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunlinsol/sunlinsol_superlumt.h b/include/sunlinsol/sunlinsol_superlumt.h index e878b3a1e6..6c5414b3a9 100644 --- a/include/sunlinsol/sunlinsol_superlumt.h +++ b/include/sunlinsol/sunlinsol_superlumt.h @@ -99,15 +99,16 @@ SUNDIALS_EXPORT int SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, int ordering_choice); SUNDIALS_EXPORT SUNLinearSolver_Type SUNLinSolGetType_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT SUNLinearSolver_ID SUNLinSolGetID_SuperLUMT(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S); SUNDIALS_EXPORT int SUNLinSolSetup_SuperLUMT(SUNLinearSolver S, SUNMatrix A); SUNDIALS_EXPORT int SUNLinSolSolve_SuperLUMT(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol); SUNDIALS_EXPORT sunindextype SUNLinSolLastFlag_SuperLUMT(SUNLinearSolver S); -SUNDIALS_EXPORT int SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS); -SUNDIALS_EXPORT int SUNLinSolFree_SuperLUMT(SUNLinearSolver S); +SUNDIALS_EXPORT SUNErrCode SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, + long int* lenrwLS, + long int* leniwLS); +SUNDIALS_EXPORT SUNErrCode SUNLinSolFree_SuperLUMT(SUNLinearSolver S); #ifdef __cplusplus } diff --git a/include/sunnonlinsol/sunnonlinsol_fixedpoint.h b/include/sunnonlinsol/sunnonlinsol_fixedpoint.h index d65cc0462f..88782009a2 100644 --- a/include/sunnonlinsol/sunnonlinsol_fixedpoint.h +++ b/include/sunnonlinsol/sunnonlinsol_fixedpoint.h @@ -22,8 +22,8 @@ #ifndef _SUNNONLINSOL_FIXEDPOINT_H #define _SUNNONLINSOL_FIXEDPOINT_H -#include "sundials/sundials_nonlinearsolver.h" -#include "sundials/sundials_nvector.h" +#include + #include "sundials/sundials_types.h" #ifdef __cplusplus /* wrapper to enable C++ usage */ @@ -63,7 +63,8 @@ struct _SUNNonlinearSolverContent_FixedPoint long int nconvfails; /* total number of convergence failures */ void* ctest_data; /* data to pass to convergence test function */ - /* if 0 (default) nothing is printed, if 1 the residual is printed every iteration */ + /* if 0 (default) nothing is printed, if 1 the residual is printed every + * iteration */ int print_level; /* if NULL nothing is printed, if 1 the residual is printed every iteration */ FILE* info_file; @@ -84,44 +85,53 @@ SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, SUNContext sunctx); /* core functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type -SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, sunrealtype tol, - sunbooleantype callSetup, - void* mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, + N_Vector y, N_Vector w, sunrealtype tol, + sunbooleantype callSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS); /* set functions */ -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn_FixedPoint( - SUNNonlinearSolver NLS, SUNNonlinSolConvTestFn CTestFn, void* ctest_data); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); -SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, - int maxiters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, + int maxiters); -SUNDIALS_EXPORT int SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, - sunrealtype beta); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, + sunrealtype beta); /* get functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, - long int* niters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, + long int* niters); -SUNDIALS_EXPORT int SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, - int* iter); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, int* iter); -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, - long int* nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, + long int* nconvfails); -SUNDIALS_EXPORT int SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn* SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); #ifdef __cplusplus } diff --git a/include/sunnonlinsol/sunnonlinsol_newton.h b/include/sunnonlinsol/sunnonlinsol_newton.h index ca426c6c19..4268b4bc76 100644 --- a/include/sunnonlinsol/sunnonlinsol_newton.h +++ b/include/sunnonlinsol/sunnonlinsol_newton.h @@ -48,10 +48,12 @@ struct _SUNNonlinearSolverContent_Newton int curiter; /* current number of iterations in a solve attempt */ int maxiters; /* maximum number of iterations in a solve attempt */ long int niters; /* total number of nonlinear iterations across all solves */ - long int nconvfails; /* total number of convergence failures across all solves */ + long int nconvfails; /* total number of convergence failures across all solves + */ void* ctest_data; /* data to pass to convergence test function */ - /* if 0 (default) nothing is printed, if 1 the residual is printed every iteration */ + /* if 0 (default) nothing is printed, if 1 the residual is printed every + * iteration */ int print_level; /* if NULL nothing is printed, if 1 the residual is printed every iteration */ FILE* info_file; @@ -72,47 +74,56 @@ SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, SUNContext sunctx); /* core functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type -SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, sunrealtype tol, - sunbooleantype callLSetup, - void* mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, + N_Vector w, sunrealtype tol, + sunbooleantype callLSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS); /* set functions */ -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSetupFn LSetupFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn LSetupFn); -SUNDIALS_EXPORT int SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSolveFn LSolveFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn LSolveFn); -SUNDIALS_EXPORT int SUNNonlinSolSetConvTestFn_Newton( - SUNNonlinearSolver NLS, SUNNonlinSolConvTestFn CTestFn, void* ctest_data); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data); -SUNDIALS_EXPORT int SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, - int maxiters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, int maxiters); /* get functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, - long int* niters); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, + long int* niters); -SUNDIALS_EXPORT int SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, - int* iter); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, int* iter); -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, - long int* nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, + long int* nconvfails); -SUNDIALS_EXPORT int SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn* SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); #ifdef __cplusplus } diff --git a/include/sunnonlinsol/sunnonlinsol_petscsnes.h b/include/sunnonlinsol/sunnonlinsol_petscsnes.h index c93886b16b..bb58ab9fa1 100644 --- a/include/sunnonlinsol/sunnonlinsol_petscsnes.h +++ b/include/sunnonlinsol/sunnonlinsol_petscsnes.h @@ -64,38 +64,44 @@ SUNNonlinearSolver SUNNonlinSol_PetscSNES(N_Vector y, SNES snes, /* SUNNonlinearSolver API functions */ -SUNDIALS_EXPORT SUNNonlinearSolver_Type -SUNNonlinSolGetType_PetscSNES(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNNonlinearSolver_Type SUNNonlinSolGetType_PetscSNES(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolInitialize_PetscSNES(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolInitialize_PetscSNES(SUNNonlinearSolver NLS); -SUNDIALS_EXPORT int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, - N_Vector y0, N_Vector y, - N_Vector w, sunrealtype tol, - sunbooleantype callLSetup, - void* mem); +SUNDIALS_EXPORT +int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, + N_Vector w, sunrealtype tol, + sunbooleantype callLSetup, void* mem); -SUNDIALS_EXPORT int SUNNonlinSolSetSysFn_PetscSNES(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolSetSysFn_PetscSNES(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn); -SUNDIALS_EXPORT int SUNNonlinSolGetNumIters_PetscSNES(SUNNonlinearSolver NLS, - long int* nni); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumIters_PetscSNES(SUNNonlinearSolver NLS, + long int* nni); -SUNDIALS_EXPORT int SUNNonlinSolGetNumConvFails_PetscSNES(SUNNonlinearSolver NLS, - long int* nconvfails); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetNumConvFails_PetscSNES(SUNNonlinearSolver NLS, + long int* nconvfails); -SUNDIALS_EXPORT int SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS); /* Implementation specific functions */ -SUNDIALS_EXPORT int SUNNonlinSolGetSNES_PetscSNES(SUNNonlinearSolver NLS, - SNES* snes); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSNES_PetscSNES(SUNNonlinearSolver NLS, SNES* snes); -SUNDIALS_EXPORT int SUNNonlinSolGetPetscError_PetscSNES(SUNNonlinearSolver NLS, - PetscErrorCode* err); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetPetscError_PetscSNES(SUNNonlinearSolver NLS, + PetscErrorCode* err); -SUNDIALS_EXPORT int SUNNonlinSolGetSysFn_PetscSNES(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn* SysFn); +SUNDIALS_EXPORT +SUNErrCode SUNNonlinSolGetSysFn_PetscSNES(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn); #ifdef __cplusplus } diff --git a/src/arkode/arkode_arkstep_io.c b/src/arkode/arkode_arkstep_io.c index 4ea7a7e9e3..d49d39d734 100644 --- a/src/arkode/arkode_arkstep_io.c +++ b/src/arkode/arkode_arkstep_io.c @@ -1813,7 +1813,7 @@ int ARKStepSetMaxNonlinIters(void* arkode_mem, int maxcor) /* send argument to NLS structure */ retval = SUNNonlinSolSetMaxIters(step_mem->NLS, step_mem->maxcor); - if (retval != SUN_NLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_NLS_OP_ERR, "ARKODE::ARKStep", "ARKStepSetMaxNonlinIters", diff --git a/src/arkode/arkode_arkstep_nls.c b/src/arkode/arkode_arkstep_nls.c index 0bc12e5ada..de6a71abec 100644 --- a/src/arkode/arkode_arkstep_nls.c +++ b/src/arkode/arkode_arkstep_nls.c @@ -382,7 +382,7 @@ int arkStep_Nls(ARKodeMem ark_mem, int nflag) step_mem->nls_fails += nls_fails_inc; /* successful solve -- reset jcur flag and apply correction */ - if (retval == SUN_NLS_SUCCESS) + if (retval == SUN_SUCCESS) { step_mem->jcur = SUNFALSE; N_VLinearSum(ONE, step_mem->zcor, ONE, step_mem->zpred, ark_mem->ycur); @@ -461,7 +461,7 @@ int arkStep_NlsLSolve(N_Vector b, void* arkode_mem) /* retrieve nonlinear solver iteration from module */ retval = SUNNonlinSolGetCurIter(step_mem->NLS, &nonlin_iter); - if (retval != SUN_NLS_SUCCESS) { return (ARK_NLS_OP_ERR); } + if (retval != SUN_SUCCESS) { return (ARK_NLS_OP_ERR); } /* call linear solver interface, and handle return value */ retval = step_mem->lsolve(ark_mem, b, ark_mem->tcur, ark_mem->ycur, @@ -905,7 +905,7 @@ int arkStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, if (retval != ARK_SUCCESS) { return (retval); } /* if the problem is linearly implicit, just return success */ - if (step_mem->linear) { return (SUN_NLS_SUCCESS); } + if (step_mem->linear) { return (SUN_SUCCESS); } /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); @@ -925,7 +925,7 @@ int arkStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, dcon = SUNMIN(step_mem->crate, ONE) * delnrm / tol; /* check for convergence; if so return with success */ - if (dcon <= ONE) { return (SUN_NLS_SUCCESS); } + if (dcon <= ONE) { return (SUN_SUCCESS); } /* check for divergence */ if ((m >= 1) && (delnrm > step_mem->rdiv * step_mem->delp)) diff --git a/src/arkode/arkode_bandpre.c b/src/arkode/arkode_bandpre.c index 9a6e529a8d..6c59a37001 100644 --- a/src/arkode/arkode_bandpre.c +++ b/src/arkode/arkode_bandpre.c @@ -163,7 +163,7 @@ int ARKBandPrecInit(void* arkode_mem, sunindextype N, sunindextype mu, /* initialize band linear solver object */ retval = SUNLinSolInitialize(pdata->LS); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); @@ -244,7 +244,7 @@ int ARKBandPrecGetWorkSpace(void* arkode_mem, long int* lenrwBP, long int* leniw if (pdata->LS->ops->space) { retval = SUNLinSolSpace(pdata->LS, &lrw, &liw); - if (retval == SUNLS_SUCCESS) + if (retval == SUN_SUCCESS) { *leniwBP += liw; *lenrwBP += lrw; diff --git a/src/arkode/arkode_ls.c b/src/arkode/arkode_ls.c index 710e5430d7..84d1867835 100644 --- a/src/arkode/arkode_ls.c +++ b/src/arkode/arkode_ls.c @@ -215,7 +215,7 @@ int arkLSSetLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, ark_mem, arkLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -229,7 +229,7 @@ int arkLSSetLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, ark_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -444,7 +444,7 @@ int arkLSSetMassLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix M, if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, ark_mem, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetMassLinearSolver", @@ -459,7 +459,7 @@ int arkLSSetMassLinearSolver(void* arkode_mem, SUNLinearSolver LS, SUNMatrix M, if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, ark_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetMassLinearSolver", @@ -738,7 +738,7 @@ int arkLSSetPreconditioner(void* arkode_mem, ARKLsPrecSetupFn psetup, arkls_psolve = (psolve == NULL) ? NULL : arkLsPSolve; retval = SUNLinSolSetPreconditioner(arkls_mem->LS, ark_mem, arkls_psetup, arkls_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -993,7 +993,7 @@ int arkLSGetWorkSpace(void* arkode_mem, long int* lenrw, long int* leniw) if (arkls_mem->LS->ops->space) { retval = SUNLinSolSpace(arkls_mem->LS, &lrw, &liw); - if (retval == SUNLS_SUCCESS) + if (retval == SUN_SUCCESS) { *lenrw += lrw; *leniw += liw; @@ -1303,7 +1303,7 @@ int arkLSSetMassPreconditioner(void* arkode_mem, ARKLsMassPrecSetupFn psetup, arkls_mpsolve = (psolve == NULL) ? NULL : arkLsMPSolve; retval = SUNLinSolSetPreconditioner(arkls_mem->LS, ark_mem, arkls_mpsetup, arkls_mpsolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetMassPreconditioner", @@ -1354,7 +1354,7 @@ int arkLSSetMassTimes(void* arkode_mem, ARKLsMassTimesSetupFn mtsetup, /* notify linear solver to call ARKLs interface routine */ retval = SUNLinSolSetATimes(arkls_mem->LS, ark_mem, arkLsMTimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLSSetMassTimes", "Error in calling SUNLinSolSetATimes"); @@ -1433,7 +1433,7 @@ int arkLSGetMassWorkSpace(void* arkode_mem, long int* lenrw, long int* leniw) if (arkls_mem->LS->ops->space) { retval = SUNLinSolSpace(arkls_mem->LS, &lrw, &liw); - if (retval == SUNLS_SUCCESS) + if (retval == SUN_SUCCESS) { *lenrw += lrw; *leniw += liw; @@ -2673,7 +2673,7 @@ int arkLsSolve(void* arkode_mem, N_Vector b, sunrealtype tnow, N_Vector ynow, { retval = SUNLinSolSetScalingVectors(arkls_mem->LS, ark_mem->rwt, ark_mem->ewt); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLsSolve", "Error in call to SUNLinSolSetScalingVectors"); @@ -2708,7 +2708,7 @@ int arkLsSolve(void* arkode_mem, N_Vector b, sunrealtype tnow, N_Vector ynow, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(arkls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } /* Store previous nps value in nps_inc */ nps_inc = arkls_mem->nps; @@ -2763,7 +2763,7 @@ int arkLsSolve(void* arkode_mem, N_Vector b, sunrealtype tnow, N_Vector ynow, /* Increment counters nli and ncfl */ arkls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) { arkls_mem->ncfl++; } + if (retval != SUN_SUCCESS) { arkls_mem->ncfl++; } /* Log solver statistics to diagnostics file (if requested) */ #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG @@ -2783,7 +2783,7 @@ int arkLsSolve(void* arkode_mem, N_Vector b, sunrealtype tnow, N_Vector ynow, switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: /* allow reduction but not solution on first nonlinear iteration, otherwise return with a recoverable failure */ @@ -2796,9 +2796,9 @@ int arkLsSolve(void* arkode_mem, N_Vector b, sunrealtype tnow, N_Vector ynow, case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: @@ -3137,7 +3137,7 @@ int arkLsMassSolve(void* arkode_mem, N_Vector b, sunrealtype nlscoef) { retval = SUNLinSolSetScalingVectors(arkls_mem->LS, ark_mem->rwt, ark_mem->ewt); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARKLS_SUNLS_FAIL, "ARKLS", "arkLsMassSolve", "Error in call to SUNLinSolSetScalingVectors"); @@ -3172,7 +3172,7 @@ int arkLsMassSolve(void* arkode_mem, N_Vector b, sunrealtype nlscoef) /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(arkls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } /* Store previous nps value in nps_inc */ nps_inc = arkls_mem->nps; @@ -3199,7 +3199,7 @@ int arkLsMassSolve(void* arkode_mem, N_Vector b, sunrealtype nlscoef) /* Increment counters nli and ncfl */ arkls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) { arkls_mem->ncfl++; } + if (retval != SUN_SUCCESS) { arkls_mem->ncfl++; } /* Log solver statistics to diagnostics file (if requested) */ #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG @@ -3218,7 +3218,7 @@ int arkLsMassSolve(void* arkode_mem, N_Vector b, sunrealtype nlscoef) switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: case SUNLS_CONV_FAIL: case SUNLS_ATIMES_FAIL_REC: @@ -3226,9 +3226,9 @@ int arkLsMassSolve(void* arkode_mem, N_Vector b, sunrealtype nlscoef) case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: diff --git a/src/arkode/arkode_mristep_io.c b/src/arkode/arkode_mristep_io.c index b599863e73..a808ad80c4 100644 --- a/src/arkode/arkode_mristep_io.c +++ b/src/arkode/arkode_mristep_io.c @@ -749,7 +749,7 @@ int MRIStepSetMaxNonlinIters(void* arkode_mem, int maxcor) /* send argument to NLS structure */ retval = SUNNonlinSolSetMaxIters(step_mem->NLS, step_mem->maxcor); - if (retval != SUN_NLS_SUCCESS) + if (retval != SUN_SUCCESS) { arkProcessError(ark_mem, ARK_NLS_OP_ERR, "ARKODE::MRIStep", "MRIStepSetMaxNonlinIters", diff --git a/src/arkode/arkode_mristep_nls.c b/src/arkode/arkode_mristep_nls.c index 267ea665db..6f6c9d2152 100644 --- a/src/arkode/arkode_mristep_nls.c +++ b/src/arkode/arkode_mristep_nls.c @@ -351,7 +351,7 @@ int mriStep_Nls(ARKodeMem ark_mem, int nflag) step_mem->nls_fails += nls_fails_inc; /* successful solve -- reset the jcur flag and apply correction */ - if (retval == SUN_NLS_SUCCESS) + if (retval == SUN_SUCCESS) { step_mem->jcur = SUNFALSE; N_VLinearSum(ONE, step_mem->zcor, ONE, step_mem->zpred, ark_mem->ycur); @@ -431,7 +431,7 @@ int mriStep_NlsLSolve(N_Vector b, void* arkode_mem) /* retrieve nonlinear solver iteration from module */ retval = SUNNonlinSolGetCurIter(step_mem->NLS, &nonlin_iter); - if (retval != SUN_NLS_SUCCESS) { return (ARK_NLS_OP_ERR); } + if (retval != SUN_SUCCESS) { return (ARK_NLS_OP_ERR); } /* call linear solver interface, and handle return value */ retval = step_mem->lsolve(ark_mem, b, ark_mem->tcur, ark_mem->ycur, @@ -586,7 +586,7 @@ int mriStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, if (retval != ARK_SUCCESS) { return (retval); } /* if the problem is linearly implicit, just return success */ - if (step_mem->linear) { return (SUN_NLS_SUCCESS); } + if (step_mem->linear) { return (SUN_SUCCESS); } /* compute the norm of the correction */ delnrm = N_VWrmsNorm(del, ewt); @@ -606,7 +606,7 @@ int mriStep_NlsConvTest(SUNNonlinearSolver NLS, N_Vector y, N_Vector del, dcon = SUNMIN(step_mem->crate, ONE) * delnrm / tol; /* check for convergence; if so return with success */ - if (dcon <= ONE) { return (SUN_NLS_SUCCESS); } + if (dcon <= ONE) { return (SUN_SUCCESS); } /* check for divergence */ if ((m >= 1) && (delnrm > step_mem->rdiv * step_mem->delp)) diff --git a/src/cvode/cvode.c b/src/cvode/cvode.c index 76acb86274..211ce01ff7 100644 --- a/src/cvode/cvode.c +++ b/src/cvode/cvode.c @@ -3049,7 +3049,7 @@ static int cvNls(CVodeMem cv_mem, int nflag) cv_mem->cv_nnf += nnf_inc; /* if the solve failed return */ - if (flag != SUN_NLS_SUCCESS) { return (flag); } + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ @@ -3709,7 +3709,7 @@ static int cvHandleFailure(CVodeMem cv_mem, int flag) case CV_MEM_NULL: cvProcessError(NULL, CV_MEM_NULL, "CVODE", "CVode", MSGCV_NO_MEM); break; - case SUN_NLS_MEM_NULL: + case SUN_ERR_ARG_CORRUPT: cvProcessError(cv_mem, CV_MEM_NULL, "CVODE", "CVode", MSGCV_NLS_INPUT_NULL, cv_mem->cv_tn); break; diff --git a/src/cvode/cvode_bandpre.c b/src/cvode/cvode_bandpre.c index c9c5d76625..3c6ebd76e7 100644 --- a/src/cvode/cvode_bandpre.c +++ b/src/cvode/cvode_bandpre.c @@ -180,7 +180,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); diff --git a/src/cvode/cvode_bbdpre.c b/src/cvode/cvode_bbdpre.c index e28e14e72a..9f5322f7b5 100644 --- a/src/cvode/cvode_bbdpre.c +++ b/src/cvode/cvode_bbdpre.c @@ -229,7 +229,7 @@ int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, sunindextype mudq, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); diff --git a/src/cvode/cvode_ls.c b/src/cvode/cvode_ls.c index 38d5e94b65..a79502f9fe 100644 --- a/src/cvode/cvode_ls.c +++ b/src/cvode/cvode_ls.c @@ -209,7 +209,7 @@ int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, cv_mem, cvLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVLS", "CVodeSetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -223,7 +223,7 @@ int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, cv_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVLS", "CVodeSetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -482,7 +482,7 @@ int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn psetup, cvls_psolve = (psolve == NULL) ? NULL : cvLsPSolve; retval = SUNLinSolSetPreconditioner(cvls_mem->LS, cv_mem, cvls_psetup, cvls_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVLS", "CVLsSetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -1696,7 +1696,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, if (cvls_mem->LS->ops->setscalingvectors) { retval = SUNLinSolSetScalingVectors(cvls_mem->LS, weight, weight); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVLS", "cvLsSolve", "Error in calling SUNLinSolSetScalingVectors"); @@ -1731,7 +1731,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(cvls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG /* Store previous nps value in nps_inc */ @@ -1780,7 +1780,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, /* Increment counters nli and ncfl */ cvls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) { cvls_mem->ncfl++; } + if (retval != SUN_SUCCESS) { cvls_mem->ncfl++; } /* Interpret solver return value */ cvls_mem->last_flag = retval; @@ -1793,7 +1793,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: /* allow reduction but not solution on first Newton iteration, otherwise return with a recoverable failure */ @@ -1806,9 +1806,9 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: diff --git a/src/cvodes/cvodes.c b/src/cvodes/cvodes.c index 04c1c72b82..9839f691db 100644 --- a/src/cvodes/cvodes.c +++ b/src/cvodes/cvodes.c @@ -6985,7 +6985,7 @@ static int cvNls(CVodeMem cv_mem, int nflag) } /* if the solve failed return */ - if (flag != SUN_NLS_SUCCESS) { return (flag); } + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ @@ -7207,7 +7207,7 @@ static int cvStgrNls(CVodeMem cv_mem) cv_mem->sens_solve = SUNFALSE; /* if the solve failed return */ - if (flag != SUN_NLS_SUCCESS) { return (flag); } + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ @@ -7261,7 +7261,7 @@ static int cvStgr1Nls(CVodeMem cv_mem, int is) cv_mem->sens_solve = SUNFALSE; /* if the solve failed return */ - if (flag != SUN_NLS_SUCCESS) { return (flag); } + if (flag != SUN_SUCCESS) { return (flag); } /* solve successful */ @@ -8110,7 +8110,7 @@ static int cvHandleFailure(CVodeMem cv_mem, int flag) case CV_MEM_NULL: cvProcessError(NULL, CV_MEM_NULL, "CVODES", "CVode", MSGCV_NO_MEM); break; - case SUN_NLS_MEM_NULL: + case SUN_ERR_ARG_CORRUPT: cvProcessError(cv_mem, CV_MEM_NULL, "CVODES", "CVode", MSGCV_NLS_INPUT_NULL, cv_mem->cv_tn); break; diff --git a/src/cvodes/cvodes_bandpre.c b/src/cvodes/cvodes_bandpre.c index e30bc5b057..7b3e658f88 100644 --- a/src/cvodes/cvodes_bandpre.c +++ b/src/cvodes/cvodes_bandpre.c @@ -183,7 +183,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { SUNLinSolFree(pdata->LS); SUNMatDestroy(pdata->savedP); diff --git a/src/cvodes/cvodes_bbdpre.c b/src/cvodes/cvodes_bbdpre.c index f868b06d7c..83e46fc378 100644 --- a/src/cvodes/cvodes_bbdpre.c +++ b/src/cvodes/cvodes_bbdpre.c @@ -241,7 +241,7 @@ int CVBBDPrecInit(void* cvode_mem, sunindextype Nlocal, sunindextype mudq, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { N_VDestroy(pdata->tmp1); N_VDestroy(pdata->tmp2); diff --git a/src/cvodes/cvodes_ls.c b/src/cvodes/cvodes_ls.c index 0a76911aff..a767631668 100644 --- a/src/cvodes/cvodes_ls.c +++ b/src/cvodes/cvodes_ls.c @@ -285,7 +285,7 @@ int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, cv_mem, cvLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", "CVodeSetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -299,7 +299,7 @@ int CVodeSetLinearSolver(void* cvode_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, cv_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", "CVodeSetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -558,7 +558,7 @@ int CVodeSetPreconditioner(void* cvode_mem, CVLsPrecSetupFn psetup, cvls_psolve = (psolve == NULL) ? NULL : cvLsPSolve; retval = SUNLinSolSetPreconditioner(cvls_mem->LS, cv_mem, cvls_psetup, cvls_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", "CVLsSetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -1795,7 +1795,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, if (cvls_mem->LS->ops->setscalingvectors) { retval = SUNLinSolSetScalingVectors(cvls_mem->LS, weight, weight); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSLS", "cvLsSolve", "Error in calling SUNLinSolSetScalingVectors"); @@ -1830,7 +1830,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(cvls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_DEBUG /* Store previous nps value in nps_inc */ @@ -1879,7 +1879,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, /* Increment counters nli and ncfl */ cvls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) { cvls_mem->ncfl++; } + if (retval != SUN_SUCCESS) { cvls_mem->ncfl++; } /* Interpret solver return value */ cvls_mem->last_flag = retval; @@ -1892,7 +1892,7 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: /* allow reduction but not solution on first Newton iteration, otherwise return with a recoverable failure */ @@ -1905,9 +1905,9 @@ int cvLsSolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ynow, case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: diff --git a/src/ida/ida.c b/src/ida/ida.c index 7682d3db71..cc51f8067d 100644 --- a/src/ida/ida.c +++ b/src/ida/ida.c @@ -2375,7 +2375,7 @@ static int IDAHandleFailure(IDAMem IDA_mem, int sflag) IDAProcessError(NULL, IDA_MEM_NULL, "IDA", "IDASolve", MSG_NO_MEM); return (IDA_MEM_NULL); - case SUN_NLS_MEM_NULL: + case SUN_ERR_ARG_CORRUPT: IDAProcessError(IDA_mem, IDA_MEM_NULL, "IDA", "IDASolve", MSG_NLS_INPUT_NULL, IDA_mem->ida_tn); return (IDA_MEM_NULL); @@ -2734,7 +2734,7 @@ static int IDANls(IDAMem IDA_mem) #endif /* return if nonlinear solver failed */ - if (retval != SUN_NLS_SUCCESS) { return (retval); } + if (retval != SUN_SUCCESS) { return (retval); } /* update yy and yp based on the final correction from the nonlinear solver */ N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, IDA_mem->ida_ee, diff --git a/src/ida/ida_bbdpre.c b/src/ida/ida_bbdpre.c index c8b1aaf180..5503f3edd3 100644 --- a/src/ida/ida_bbdpre.c +++ b/src/ida/ida_bbdpre.c @@ -232,7 +232,7 @@ int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, sunindextype mudq, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); diff --git a/src/ida/ida_ls.c b/src/ida/ida_ls.c index 3ecb4a8a0d..245bafc127 100644 --- a/src/ida/ida_ls.c +++ b/src/ida/ida_ls.c @@ -209,7 +209,7 @@ int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, IDA_mem, idaLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDALS", "IDASetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -223,7 +223,7 @@ int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, IDA_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDALS", "IDASetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -459,7 +459,7 @@ int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn psetup, idals_psolve = (psolve == NULL) ? NULL : idaLsPSolve; retval = SUNLinSolSetPreconditioner(idals_mem->LS, IDA_mem, idals_psetup, idals_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDALS", "IDASetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -1474,7 +1474,7 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, if (idals_mem->LS->ops->setscalingvectors) { retval = SUNLinSolSetScalingVectors(idals_mem->LS, weight, weight); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDALS", "idaLsSolve", "Error in calling SUNLinSolSetScalingVectors"); @@ -1509,7 +1509,7 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(idals_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } /* If a user-provided jtsetup routine is supplied, call that here */ if (idals_mem->jtsetup) @@ -1560,23 +1560,23 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, } /* Increment ncfl counter */ - if (retval != SUNLS_SUCCESS) { idals_mem->ncfl++; } + if (retval != SUN_SUCCESS) { idals_mem->ncfl++; } /* Interpret solver return value */ idals_mem->last_flag = retval; switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: case SUNLS_CONV_FAIL: case SUNLS_PSOLVE_FAIL_REC: case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: diff --git a/src/ida/ida_nls.c b/src/ida/ida_nls.c index 57a3d6cf1e..e58773f9b6 100644 --- a/src/ida/ida_nls.c +++ b/src/ida/ida_nls.c @@ -346,7 +346,7 @@ static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, if (m == 0) { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_NLS_SUCCESS); } + if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_SUCCESS); } } else { @@ -355,7 +355,7 @@ static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, IDA_mem->ida_ss = rate / (ONE - rate); } - if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_NLS_SUCCESS); } + if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ return (SUN_NLS_CONTINUE); diff --git a/src/idas/idas.c b/src/idas/idas.c index 3b0ce47490..d8203411e1 100644 --- a/src/idas/idas.c +++ b/src/idas/idas.c @@ -5756,7 +5756,7 @@ static int IDAHandleFailure(IDAMem IDA_mem, int sflag) IDAProcessError(NULL, IDA_MEM_NULL, "IDAS", "IDASolve", MSG_NO_MEM); return (IDA_MEM_NULL); - case SUN_NLS_MEM_NULL: + case SUN_ERR_ARG_CORRUPT: IDAProcessError(IDA_mem, IDA_MEM_NULL, "IDAS", "IDASolve", MSG_NLS_INPUT_NULL, IDA_mem->ida_tn); return (IDA_MEM_NULL); @@ -6324,7 +6324,7 @@ static int IDANls(IDAMem IDA_mem) #endif /* return if nonlinear solver failed */ - if (retval != SUN_NLS_SUCCESS) { return (retval); } + if (retval != SUN_SUCCESS) { return (retval); } /* update the state using the final correction from the nonlinear solver */ N_VLinearSum(ONE, IDA_mem->ida_yypredict, ONE, IDA_mem->ida_ee, @@ -6503,7 +6503,7 @@ static int IDASensNls(IDAMem IDA_mem) (void)SUNNonlinSolGetNumConvFails(IDA_mem->NLSstg, &nnfS_inc); IDA_mem->ida_nnfS += nnfS_inc; - if (retval != SUN_NLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDA_mem->ida_ncfnS++; return (retval); diff --git a/src/idas/idas_bbdpre.c b/src/idas/idas_bbdpre.c index a212278631..cce737a4a2 100644 --- a/src/idas/idas_bbdpre.c +++ b/src/idas/idas_bbdpre.c @@ -246,7 +246,7 @@ int IDABBDPrecInit(void* ida_mem, sunindextype Nlocal, sunindextype mudq, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); diff --git a/src/idas/idas_ls.c b/src/idas/idas_ls.c index c21e98afe8..1285fe3b38 100644 --- a/src/idas/idas_ls.c +++ b/src/idas/idas_ls.c @@ -250,7 +250,7 @@ int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, IDA_mem, idaLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", "IDASetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -264,7 +264,7 @@ int IDASetLinearSolver(void* ida_mem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, IDA_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", "IDASetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -500,7 +500,7 @@ int IDASetPreconditioner(void* ida_mem, IDALsPrecSetupFn psetup, idals_psolve = (psolve == NULL) ? NULL : idaLsPSolve; retval = SUNLinSolSetPreconditioner(idals_mem->LS, IDA_mem, idals_psetup, idals_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", "IDASetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -1515,7 +1515,7 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, if (idals_mem->LS->ops->setscalingvectors) { retval = SUNLinSolSetScalingVectors(idals_mem->LS, weight, weight); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { IDAProcessError(IDA_mem, IDALS_SUNLS_FAIL, "IDASLS", "idaLsSolve", "Error in calling SUNLinSolSetScalingVectors"); @@ -1550,7 +1550,7 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(idals_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } /* If a user-provided jtsetup routine is supplied, call that here */ if (idals_mem->jtsetup) @@ -1601,23 +1601,23 @@ int idaLsSolve(IDAMem IDA_mem, N_Vector b, N_Vector weight, N_Vector ycur, } /* Increment ncfl counter */ - if (retval != SUNLS_SUCCESS) { idals_mem->ncfl++; } + if (retval != SUN_SUCCESS) { idals_mem->ncfl++; } /* Interpret solver return value */ idals_mem->last_flag = retval; switch (retval) { - case SUNLS_SUCCESS: return (0); break; + case SUN_SUCCESS: return (0); break; case SUNLS_RES_REDUCED: case SUNLS_CONV_FAIL: case SUNLS_PSOLVE_FAIL_REC: case SUNLS_PACKAGE_FAIL_REC: case SUNLS_QRFACT_FAIL: case SUNLS_LUFACT_FAIL: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_QRSOL_FAIL: return (-1); break; case SUNLS_PACKAGE_FAIL_UNREC: diff --git a/src/idas/idas_nls.c b/src/idas/idas_nls.c index f5ade5150e..5555106430 100644 --- a/src/idas/idas_nls.c +++ b/src/idas/idas_nls.c @@ -349,7 +349,7 @@ static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, if (m == 0) { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_NLS_SUCCESS); } + if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_SUCCESS); } } else { @@ -358,7 +358,7 @@ static int idaNlsConvTest(SUNNonlinearSolver NLS, N_Vector ycor, N_Vector del, IDA_mem->ida_ss = rate / (ONE - rate); } - if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_NLS_SUCCESS); } + if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ return (SUN_NLS_CONTINUE); diff --git a/src/idas/idas_nls_sim.c b/src/idas/idas_nls_sim.c index bc20b0ee75..88b00e4568 100644 --- a/src/idas/idas_nls_sim.c +++ b/src/idas/idas_nls_sim.c @@ -455,7 +455,7 @@ static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycor, if (m == 0) { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_NLS_SUCCESS); } + if (delnrm <= PT0001 * IDA_mem->ida_toldel) { return (SUN_SUCCESS); } } else { @@ -464,7 +464,7 @@ static int idaNlsConvTestSensSim(SUNNonlinearSolver NLS, N_Vector ycor, IDA_mem->ida_ss = rate / (ONE - rate); } - if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_NLS_SUCCESS); } + if (IDA_mem->ida_ss * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ return (SUN_NLS_CONTINUE); diff --git a/src/idas/idas_nls_stg.c b/src/idas/idas_nls_stg.c index dd7182f60c..ef4a0cc459 100644 --- a/src/idas/idas_nls_stg.c +++ b/src/idas/idas_nls_stg.c @@ -364,7 +364,7 @@ static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycor, if (m == 0) { IDA_mem->ida_oldnrm = delnrm; - if (delnrm <= IDA_mem->ida_toldel) { return (SUN_NLS_SUCCESS); } + if (delnrm <= IDA_mem->ida_toldel) { return (SUN_SUCCESS); } } else { @@ -373,7 +373,7 @@ static int idaNlsConvTestSensStg(SUNNonlinearSolver NLS, N_Vector ycor, IDA_mem->ida_ssS = rate / (ONE - rate); } - if (IDA_mem->ida_ssS * delnrm <= tol) { return (SUN_NLS_SUCCESS); } + if (IDA_mem->ida_ssS * delnrm <= tol) { return (SUN_SUCCESS); } /* not yet converged */ return (SUN_NLS_CONTINUE); diff --git a/src/kinsol/kinsol_bbdpre.c b/src/kinsol/kinsol_bbdpre.c index 634d03eca2..93f91e70b8 100644 --- a/src/kinsol/kinsol_bbdpre.c +++ b/src/kinsol/kinsol_bbdpre.c @@ -221,7 +221,7 @@ int KINBBDPrecInit(void* kinmem, sunindextype Nlocal, sunindextype mudq, /* initialize band linear solver object */ flag = SUNLinSolInitialize(pdata->LS); - if (flag != SUNLS_SUCCESS) + if (flag != SUN_SUCCESS) { N_VDestroy(pdata->zlocal); N_VDestroy(pdata->rlocal); diff --git a/src/kinsol/kinsol_ls.c b/src/kinsol/kinsol_ls.c index cb00517bd5..9abbf37c06 100644 --- a/src/kinsol/kinsol_ls.c +++ b/src/kinsol/kinsol_ls.c @@ -187,7 +187,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setatimes) { retval = SUNLinSolSetATimes(LS, kin_mem, kinLsATimes); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetLinearSolver", "Error in calling SUNLinSolSetATimes"); @@ -201,7 +201,7 @@ int KINSetLinearSolver(void* kinmem, SUNLinearSolver LS, SUNMatrix A) if (LS->ops->setpreconditioner) { retval = SUNLinSolSetPreconditioner(LS, kin_mem, NULL, NULL); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetLinearSolver", "Error in calling SUNLinSolSetPreconditioner"); @@ -299,7 +299,7 @@ int KINSetPreconditioner(void* kinmem, KINLsPrecSetupFn psetup, kinls_psolve = (psolve == NULL) ? NULL : kinLsPSolve; retval = SUNLinSolSetPreconditioner(kinls_mem->LS, kin_mem, kinls_psetup, kinls_psolve); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "KINSetPreconditioner", "Error in calling SUNLinSolSetPreconditioner"); @@ -1106,7 +1106,7 @@ int kinLsInitialize(KINMem kin_mem) { retval = SUNLinSolSetScalingVectors(kinls_mem->LS, kin_mem->kin_fscale, kin_mem->kin_fscale); - if (retval != SUNLS_SUCCESS) + if (retval != SUN_SUCCESS) { KINProcessError(kin_mem, KINLS_SUNLS_FAIL, "KINLS", "kinLsInitialize", "Error in calling SUNLinSolSetScalingVectors"); @@ -1230,7 +1230,7 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, /* Set zero initial guess flag */ retval = SUNLinSolSetZeroGuess(kinls_mem->LS, SUNTRUE); - if (retval != SUNLS_SUCCESS) { return (-1); } + if (retval != SUN_SUCCESS) { return (-1); } /* set flag required for user-supplied J*v routine */ kinls_mem->new_uu = SUNTRUE; @@ -1259,7 +1259,7 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, /* Increment counters nli and ncfl */ kinls_mem->nli += nli_inc; - if (retval != SUNLS_SUCCESS) { kinls_mem->ncfl++; } + if (retval != SUN_SUCCESS) { kinls_mem->ncfl++; } /* Interpret solver return value */ kinls_mem->last_flag = retval; @@ -1270,9 +1270,9 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, { case SUNLS_ATIMES_FAIL_REC: case SUNLS_PSOLVE_FAIL_REC: return (1); break; - case SUNLS_MEM_NULL: - case SUNLS_ILL_INPUT: - case SUNLS_MEM_FAIL: + case SUN_ERR_ARG_CORRUPT: + case SUN_ERR_ARG_INCOMPATIBLE: + case SUN_ERR_MEM_FAIL: case SUNLS_GS_FAIL: case SUNLS_CONV_FAIL: case SUNLS_QRFACT_FAIL: @@ -1298,7 +1298,7 @@ int kinLsSolve(KINMem kin_mem, N_Vector xx, N_Vector bb, sunrealtype* sJpnorm, return (retval); } - /* SUNLinSolSolve returned SUNLS_SUCCESS or SUNLS_RES_REDUCED */ + /* SUNLinSolSolve returned SUN_SUCCESS or SUNLS_RES_REDUCED */ /* Compute auxiliary values for use in the linesearch and in KINForcingTerm. These will be subsequently corrected if the step is reduced by constraints diff --git a/src/sundials/fmod/fsundials_context_mod.f90 b/src/sundials/fmod/fsundials_context_mod.f90 index b0778ea9f9..6a5a0ffcbe 100644 --- a/src/sundials/fmod/fsundials_context_mod.f90 +++ b/src/sundials/fmod/fsundials_context_mod.f90 @@ -38,6 +38,7 @@ module fsundials_context_mod enumerator :: SUN_ERR_MEM_FAIL enumerator :: SUN_ERR_MALLOC_FAIL enumerator :: SUN_ERR_DESTROY_FAIL + enumerator :: SUN_ERR_EXT_FAIL enumerator :: SUN_ERR_NOT_IMPLEMENTED enumerator :: SUN_ERR_PROFILER_MAPFULL enumerator :: SUN_ERR_PROFILER_MAPGET @@ -53,7 +54,7 @@ module fsundials_context_mod end enum public :: SUN_ERR_MINIMUM, SUN_ERR_ARG_CORRUPT, SUN_ERR_ARG_INCOMPATIBLE, SUN_ERR_ARG_OUTOFRANGE, SUN_ERR_ARG_WRONGTYPE, & SUN_ERR_ARG_DIMSMISMATCH, SUN_ERR_CORRUPT, SUN_ERR_FILE_OPEN, SUN_ERR_MEM_FAIL, SUN_ERR_MALLOC_FAIL, SUN_ERR_DESTROY_FAIL, & - SUN_ERR_NOT_IMPLEMENTED, SUN_ERR_PROFILER_MAPFULL, SUN_ERR_PROFILER_MAPGET, SUN_ERR_PROFILER_MAPINSERT, & + SUN_ERR_EXT_FAIL, SUN_ERR_NOT_IMPLEMENTED, SUN_ERR_PROFILER_MAPFULL, SUN_ERR_PROFILER_MAPGET, SUN_ERR_PROFILER_MAPINSERT, & SUN_ERR_PROFILER_MAPKEYNOTFOUND, SUN_ERR_PROFILER_MAPSORT, SUN_ERR_SUNCTX_CORRUPT, SUN_ERR_MPI_FAIL, SUN_ERR_UNREACHABLE, & SUN_ERR_UNKNOWN, SUN_ERR_MAXIMUM, SUN_SUCCESS type, bind(C) :: SwigArrayWrapper diff --git a/src/sundials/fmod/fsundials_linearsolver_mod.f90 b/src/sundials/fmod/fsundials_linearsolver_mod.f90 index 68014c7805..68586b7c74 100644 --- a/src/sundials/fmod/fsundials_linearsolver_mod.f90 +++ b/src/sundials/fmod/fsundials_linearsolver_mod.f90 @@ -135,11 +135,6 @@ module fsundials_linearsolver_mod public :: FSUNLinSolLastFlag public :: FSUNLinSolSpace public :: FSUNLinSolFree - integer(C_INT), parameter, public :: SUNLS_SUCCESS = 0_C_INT - integer(C_INT), parameter, public :: SUNLS_UNRECOV_FAILURE = -800_C_INT - integer(C_INT), parameter, public :: SUNLS_MEM_NULL = -801_C_INT - integer(C_INT), parameter, public :: SUNLS_ILL_INPUT = -802_C_INT - integer(C_INT), parameter, public :: SUNLS_MEM_FAIL = -803_C_INT integer(C_INT), parameter, public :: SUNLS_ATIMES_NULL = -804_C_INT integer(C_INT), parameter, public :: SUNLS_ATIMES_FAIL_UNREC = -805_C_INT integer(C_INT), parameter, public :: SUNLS_PSET_FAIL_UNREC = -806_C_INT @@ -148,7 +143,6 @@ module fsundials_linearsolver_mod integer(C_INT), parameter, public :: SUNLS_PACKAGE_FAIL_UNREC = -809_C_INT integer(C_INT), parameter, public :: SUNLS_GS_FAIL = -810_C_INT integer(C_INT), parameter, public :: SUNLS_QRSOL_FAIL = -811_C_INT - integer(C_INT), parameter, public :: SUNLS_VECTOROP_ERR = -812_C_INT integer(C_INT), parameter, public :: SUNLS_RECOV_FAILURE = 800_C_INT integer(C_INT), parameter, public :: SUNLS_RES_REDUCED = 801_C_INT integer(C_INT), parameter, public :: SUNLS_CONV_FAIL = 802_C_INT diff --git a/src/sundials/fmod/fsundials_nonlinearsolver_mod.f90 b/src/sundials/fmod/fsundials_nonlinearsolver_mod.f90 index 6deb7aaa84..c645cebe08 100644 --- a/src/sundials/fmod/fsundials_nonlinearsolver_mod.f90 +++ b/src/sundials/fmod/fsundials_nonlinearsolver_mod.f90 @@ -75,14 +75,8 @@ module fsundials_nonlinearsolver_mod public :: FSUNNonlinSolGetNumIters public :: FSUNNonlinSolGetCurIter public :: FSUNNonlinSolGetNumConvFails - integer(C_INT), parameter, public :: SUN_NLS_SUCCESS = 0_C_INT integer(C_INT), parameter, public :: SUN_NLS_CONTINUE = +901_C_INT integer(C_INT), parameter, public :: SUN_NLS_CONV_RECVR = +902_C_INT - integer(C_INT), parameter, public :: SUN_NLS_MEM_NULL = -901_C_INT - integer(C_INT), parameter, public :: SUN_NLS_MEM_FAIL = -902_C_INT - integer(C_INT), parameter, public :: SUN_NLS_ILL_INPUT = -903_C_INT - integer(C_INT), parameter, public :: SUN_NLS_VECTOROP_ERR = -904_C_INT - integer(C_INT), parameter, public :: SUN_NLS_EXT_FAIL = -905_C_INT ! WRAPPER DECLARATIONS interface diff --git a/src/sundials/sundials_linearsolver.c b/src/sundials/sundials_linearsolver.c index b85ee88a22..0d02f6334a 100644 --- a/src/sundials/sundials_linearsolver.c +++ b/src/sundials/sundials_linearsolver.c @@ -168,7 +168,7 @@ int SUNLinSolSetup(SUNLinearSolver S, SUNMatrix A) SUNErrCode ier; SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(S)); if (S->ops->setup) { ier = S->ops->setup(S, A); } - else { ier = SUNLS_SUCCESS; } + else { ier = SUN_SUCCESS; } SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(S)); return (ier); } @@ -224,7 +224,7 @@ SUNErrCode SUNLinSolSpace(SUNLinearSolver S, long int* lenrwLS, long int* leniwL { *lenrwLS = 0; *leniwLS = 0; - return SUNLS_SUCCESS; + return SUN_SUCCESS; } } diff --git a/src/sundials/sundials_nonlinearsolver.c b/src/sundials/sundials_nonlinearsolver.c index f573f138d9..6e0455d5a6 100644 --- a/src/sundials/sundials_nonlinearsolver.c +++ b/src/sundials/sundials_nonlinearsolver.c @@ -117,7 +117,7 @@ int SUNNonlinSolSetup(SUNNonlinearSolver NLS, N_Vector y, void* mem) int ier; SUNDIALS_MARK_FUNCTION_BEGIN(getSUNProfiler(NLS)); if (NLS->ops->setup) { ier = NLS->ops->setup(NLS, y, mem); } - else { ier = SUN_NLS_SUCCESS; } + else { ier = SUN_SUCCESS; } SUNDIALS_MARK_FUNCTION_END(getSUNProfiler(NLS)); return (ier); } diff --git a/src/sunlinsol/band/fmod/fsunlinsol_band_mod.c b/src/sunlinsol/band/fmod/fsunlinsol_band_mod.c index 99f9a333c0..7a6cf4b4f6 100644 --- a/src/sunlinsol/band/fmod/fsunlinsol_band_mod.c +++ b/src/sunlinsol/band/fmod/fsunlinsol_band_mod.c @@ -251,11 +251,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_Band(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_Band(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_Band(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_Band(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -311,13 +311,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_Band(SUNLinearSolver farg1, long *farg2, lo SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_Band(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_Band(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -325,11 +325,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_Band(SUNLinearSolver farg1, long *farg2, lo SWIGEXPORT int _wrap_FSUNLinSolFree_Band(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_Band(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_Band(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/band/sunlinsol_band.c b/src/sunlinsol/band/sunlinsol_band.c index b34292f7f7..e3daf3fb4f 100644 --- a/src/sunlinsol/band/sunlinsol_band.c +++ b/src/sunlinsol/band/sunlinsol_band.c @@ -17,6 +17,7 @@ #include #include +#include #include #include @@ -46,38 +47,28 @@ SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_Band content; sunindextype MatrixRows; - /* Check compatibility with supplied SUNMatrix and N_Vector */ - if (SUNMatGetID(A) != SUNMATRIX_BAND) { return (NULL); } - - if (SUNBandMatrix_Rows(A) != SUNBandMatrix_Columns(A)) { return (NULL); } - - if ((N_VGetVectorID(y) != SUNDIALS_NVEC_SERIAL) && - (N_VGetVectorID(y) != SUNDIALS_NVEC_OPENMP) && - (N_VGetVectorID(y) != SUNDIALS_NVEC_PTHREADS)) - { - return (NULL); - } + SUNAssertNull(SUNMatGetID(A) == SUNMATRIX_BAND, SUN_ERR_ARG_WRONGTYPE); + SUNAssertNull(SUNBandMatrix_Rows(A) == SUNBandMatrix_Columns(A), + SUN_ERR_ARG_DIMSMISMATCH); + SUNAssertNull(y->ops->nvgetarraypointer, SUN_ERR_ARG_INCOMPATIBLE); /* Check that A has appropriate storage upper bandwidth for factorization */ MatrixRows = SUNBandMatrix_Rows(A); - - if (SUNBandMatrix_StoredUpperBandwidth(A) < - SUNMIN(MatrixRows - 1, - SUNBandMatrix_LowerBandwidth(A) + SUNBandMatrix_UpperBandwidth(A))) - { - return (NULL); - } - - if (MatrixRows != N_VGetLength(y)) { return (NULL); } + SUNAssertNull(SUNBandMatrix_StoredUpperBandwidth(A) >= + SUNMIN(MatrixRows - 1, SUNBandMatrix_LowerBandwidth(A) + + SUNBandMatrix_UpperBandwidth(A)), + SUN_ERR_ARG_INCOMPATIBLE); + SUNAssertNull(MatrixRows == N_VGetLength(y), SUN_ERR_ARG_DIMSMISMATCH); /* Create an empty linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_Band; @@ -92,11 +83,7 @@ SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx) /* Create content */ content = NULL; content = (SUNLinearSolverContent_Band)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -108,11 +95,7 @@ SUNLinearSolver SUNLinSol_Band(N_Vector y, SUNMatrix A, SUNContext sunctx) /* Allocate content */ content->pivots = (sunindextype*)malloc(MatrixRows * sizeof(sunindextype)); - if (content->pivots == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content->pivots, SUN_ERR_MALLOC_FAIL); return (S); } @@ -133,27 +116,23 @@ SUNLinearSolver_ID SUNLinSolGetID_Band(SUNLinearSolver S) return (SUNLINEARSOLVER_BAND); } -int SUNLinSolInitialize_Band(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_Band(SUNLinearSolver S) { /* all solver-specific memory has already been allocated */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); sunrealtype** A_cols; sunindextype* pivots; - /* check for valid inputs */ - if ((A == NULL) || (S == NULL)) { return (SUNLS_MEM_NULL); } - - /* Ensure that A is a band matrix */ - if (SUNMatGetID(A) != SUNMATRIX_BAND) - { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); - } + SUNAssertNoRet(SUNMatGetID(A) == SUNMATRIX_BAND, SUN_ERR_ARG_WRONGTYPE); /* access data pointers (return with failure on NULL) */ A_cols = NULL; @@ -162,15 +141,15 @@ int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A) pivots = PIVOTS(S); if ((A_cols == NULL) || (pivots == NULL)) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* ensure that storage upper bandwidth is sufficient for fill-in */ if (SM_SUBAND_B(A) < SUNMIN(SM_COLUMNS_B(A) - 1, SM_UBAND_B(A) + SM_LBAND_B(A))) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* perform LU factorization of input matrix */ @@ -179,62 +158,65 @@ int SUNLinSolSetup_Band(SUNLinearSolver S, SUNMatrix A) /* store error flag (if nonzero, that row encountered zero-valued pivod) */ if (LASTFLAG(S) > 0) { return (SUNLS_LUFACT_FAIL); } - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int SUNLinSolSolve_Band(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); sunrealtype **A_cols, *xdata; sunindextype* pivots; - /* check for valid inputs */ - if ((A == NULL) || (S == NULL) || (x == NULL) || (b == NULL)) - { - return (SUNLS_MEM_NULL); - } - /* copy b into x */ N_VScale(ONE, b, x); + SUNCheckLastErrNoRet(); /* access data pointers (return with failure on NULL) */ A_cols = NULL; xdata = NULL; pivots = NULL; A_cols = SUNBandMatrix_Cols(A); - xdata = N_VGetArrayPointer(x); + SUNCheckLastErrNoRet(); + xdata = N_VGetArrayPointer(x); + SUNCheckLastErrNoRet(); pivots = PIVOTS(S); if ((A_cols == NULL) || (xdata == NULL) || (pivots == NULL)) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* solve using LU factors */ SUNDlsMat_bandGBTRS(A_cols, SM_COLUMNS_B(A), SM_SUBAND_B(A), SM_LBAND_B(A), pivots, xdata); - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } sunindextype SUNLinSolLastFlag_Band(SUNLinearSolver S) { /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_Band(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); + SUNAssert(SUNLinSolGetID(S) == SUNLINEARSOLVER_BAND, SUN_ERR_ARG_WRONGTYPE); *leniwLS = 2 + BAND_CONTENT(S)->N; *lenrwLS = 0; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_Band(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_Band(SUNLinearSolver S) { /* return if S is already free */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return SUN_SUCCESS; } /* delete items from contents, then delete generic structure */ if (S->content) @@ -254,5 +236,5 @@ int SUNLinSolFree_Band(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/cusolversp/sunlinsol_cusolversp_batchqr.cu b/src/sunlinsol/cusolversp/sunlinsol_cusolversp_batchqr.cu index 07cb05667f..fd7a6db21d 100644 --- a/src/sunlinsol/cusolversp/sunlinsol_cusolversp_batchqr.cu +++ b/src/sunlinsol/cusolversp/sunlinsol_cusolversp_batchqr.cu @@ -121,7 +121,7 @@ SUNLinearSolver SUNLinSol_cuSolverSp_batchQR(N_Vector y, SUNMatrix A, S->content = content; /* Fill content */ - content->last_flag = SUNLS_SUCCESS; + content->last_flag = SUN_SUCCESS; content->first_factorize = SUNTRUE; content->internal_size = 0; content->workspace_size = 0; @@ -176,10 +176,10 @@ SUNLinearSolver_ID SUNLinSolGetID_cuSolverSp_batchQR(SUNLinearSolver S) return (SUNLINEARSOLVER_CUSOLVERSP_BATCHQR); } -int SUNLinSolInitialize_cuSolverSp_batchQR(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_cuSolverSp_batchQR(SUNLinearSolver S) { SUN_CUSP_FIRSTFACTORIZE(S) = SUNTRUE; - SUN_CUSP_LASTFLAG(S) = SUNLS_SUCCESS; + SUN_CUSP_LASTFLAG(S) = SUN_SUCCESS; return (SUN_CUSP_LASTFLAG(S)); } @@ -192,7 +192,7 @@ int SUNLinSolSetup_cuSolverSp_batchQR(SUNLinearSolver S, SUNMatrix A) cudaError_t cuerr; cusolverStatus_t status; - if (SUN_CUSP_LASTFLAG(S) != SUNLS_SUCCESS) { return SUN_CUSP_LASTFLAG(S); } + if (SUN_CUSP_LASTFLAG(S) != SUN_SUCCESS) { return SUN_CUSP_LASTFLAG(S); } if (SUN_CUSP_FIRSTFACTORIZE(S)) { @@ -258,7 +258,7 @@ int SUNLinSolSetup_cuSolverSp_batchQR(SUNLinearSolver S, SUNMatrix A) SUN_CUSP_FIRSTFACTORIZE(S) = SUNFALSE; } - SUN_CUSP_LASTFLAG(S) = SUNLS_SUCCESS; + SUN_CUSP_LASTFLAG(S) = SUN_SUCCESS; return (SUN_CUSP_LASTFLAG(S)); } @@ -273,15 +273,15 @@ int SUNLinSolSolve_cuSolverSp_batchQR(SUNLinearSolver S, SUNMatrix A, if ((S == NULL) || (A == NULL) || (x == NULL) || (b == NULL)) { - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } - SUN_CUSP_LASTFLAG(S) = SUNLS_SUCCESS; + SUN_CUSP_LASTFLAG(S) = SUN_SUCCESS; sunrealtype* device_b = N_VGetDeviceArrayPointer(b); sunrealtype* device_x = N_VGetDeviceArrayPointer(x); - if (SUN_CUSP_LASTFLAG(S) != SUNLS_SUCCESS) { return SUN_CUSP_LASTFLAG(S); } + if (SUN_CUSP_LASTFLAG(S) != SUN_SUCCESS) { return SUN_CUSP_LASTFLAG(S); } /* solve the system */ nblock = SUNMatrix_cuSparse_NumBlocks(A); @@ -314,10 +314,10 @@ sunindextype SUNLinSolLastFlag_cuSolverSp_batchQR(SUNLinearSolver S) return SUN_CUSP_LASTFLAG(S); } -int SUNLinSolFree_cuSolverSp_batchQR(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_cuSolverSp_batchQR(SUNLinearSolver S) { /* return with success if already freed */ - if (S == NULL) { return SUNLS_SUCCESS; } + if (S == NULL) { return SUN_SUCCESS; } /* free stuff in the content structure */ cusolverSpDestroyCsrqrInfo(SUN_CUSP_QRINFO(S)); @@ -341,5 +341,5 @@ int SUNLinSolFree_cuSolverSp_batchQR(SUNLinearSolver S) free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/dense/fmod/fsunlinsol_dense_mod.c b/src/sunlinsol/dense/fmod/fsunlinsol_dense_mod.c index 14a61798fe..336181473e 100644 --- a/src/sunlinsol/dense/fmod/fsunlinsol_dense_mod.c +++ b/src/sunlinsol/dense/fmod/fsunlinsol_dense_mod.c @@ -251,11 +251,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_Dense(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_Dense(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_Dense(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_Dense(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -311,13 +311,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_Dense(SUNLinearSolver farg1, long *farg2, l SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_Dense(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_Dense(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -325,11 +325,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_Dense(SUNLinearSolver farg1, long *farg2, l SWIGEXPORT int _wrap_FSUNLinSolFree_Dense(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_Dense(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_Dense(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/dense/sunlinsol_dense.c b/src/sunlinsol/dense/sunlinsol_dense.c index c9e1055206..4abc748f51 100644 --- a/src/sunlinsol/dense/sunlinsol_dense.c +++ b/src/sunlinsol/dense/sunlinsol_dense.c @@ -17,9 +17,12 @@ #include #include +#include #include #include +#include "sundials_logger_impl.h" + #define ONE SUN_RCONST(1.0) /* @@ -44,29 +47,23 @@ SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_Dense content; sunindextype MatrixRows; - /* Check compatibility with supplied SUNMatrix and N_Vector */ - if (SUNMatGetID(A) != SUNMATRIX_DENSE) { return (NULL); } - - if (SUNDenseMatrix_Rows(A) != SUNDenseMatrix_Columns(A)) { return (NULL); } - - if ((N_VGetVectorID(y) != SUNDIALS_NVEC_SERIAL) && - (N_VGetVectorID(y) != SUNDIALS_NVEC_OPENMP) && - (N_VGetVectorID(y) != SUNDIALS_NVEC_PTHREADS)) - { - return (NULL); - } + SUNAssertNull(SUNMatGetID(A) == SUNMATRIX_DENSE, SUN_ERR_ARG_WRONGTYPE); + SUNAssertNull(SUNDenseMatrix_Rows(A) == SUNDenseMatrix_Columns(A), + SUN_ERR_ARG_DIMSMISMATCH); + SUNAssertNull(y->ops->nvgetarraypointer, SUN_ERR_ARG_INCOMPATIBLE); MatrixRows = SUNDenseMatrix_Rows(A); - if (MatrixRows != N_VGetLength(y)) { return (NULL); } + SUNAssertNull(MatrixRows == N_VGetLength(y), SUN_ERR_ARG_DIMSMISMATCH); /* Create an empty linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_Dense; @@ -81,11 +78,7 @@ SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx) /* Create content */ content = NULL; content = (SUNLinearSolverContent_Dense)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -97,11 +90,7 @@ SUNLinearSolver SUNLinSol_Dense(N_Vector y, SUNMatrix A, SUNContext sunctx) /* Allocate content */ content->pivots = (sunindextype*)malloc(MatrixRows * sizeof(sunindextype)); - if (content->pivots == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content->pivots, SUN_ERR_MALLOC_FAIL); return (S); } @@ -122,27 +111,23 @@ SUNLinearSolver_ID SUNLinSolGetID_Dense(SUNLinearSolver S) return (SUNLINEARSOLVER_DENSE); } -int SUNLinSolInitialize_Dense(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_Dense(SUNLinearSolver S) { /* all solver-specific memory has already been allocated */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); sunrealtype** A_cols; sunindextype* pivots; - /* check for valid inputs */ - if ((A == NULL) || (S == NULL)) { return (SUNLS_MEM_NULL); } - - /* Ensure that A is a dense matrix */ - if (SUNMatGetID(A) != SUNMATRIX_DENSE) - { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); - } + SUNAssertNoRet(SUNMatGetID(A) == SUNMATRIX_DENSE, SUN_ERR_ARG_WRONGTYPE); /* access data pointers (return with failure on NULL) */ A_cols = NULL; @@ -151,8 +136,8 @@ int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A) pivots = PIVOTS(S); if ((A_cols == NULL) || (pivots == NULL)) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* perform LU factorization of input matrix */ @@ -161,60 +146,64 @@ int SUNLinSolSetup_Dense(SUNLinearSolver S, SUNMatrix A) /* store error flag (if nonzero, this row encountered zero-valued pivod) */ if (LASTFLAG(S) > 0) { return (SUNLS_LUFACT_FAIL); } - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int SUNLinSolSolve_Dense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); sunrealtype **A_cols, *xdata; sunindextype* pivots; - if ((A == NULL) || (S == NULL) || (x == NULL) || (b == NULL)) - { - return (SUNLS_MEM_NULL); - } - /* copy b into x */ N_VScale(ONE, b, x); + SUNCheckLastErrNoRet(); /* access data pointers (return with failure on NULL) */ A_cols = NULL; xdata = NULL; pivots = NULL; A_cols = SUNDenseMatrix_Cols(A); - xdata = N_VGetArrayPointer(x); + SUNCheckLastErrNoRet(); + xdata = N_VGetArrayPointer(x); + SUNCheckLastErrNoRet(); pivots = PIVOTS(S); if ((A_cols == NULL) || (xdata == NULL) || (pivots == NULL)) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* solve using LU factors */ SUNDlsMat_denseGETRS(A_cols, SUNDenseMatrix_Rows(A), pivots, xdata); - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } sunindextype SUNLinSolLastFlag_Dense(SUNLinearSolver S) { /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_Dense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); + SUNAssert(SUNLinSolGetID(S) == SUNLINEARSOLVER_DENSE, SUN_ERR_ARG_WRONGTYPE); *leniwLS = 2 + DENSE_CONTENT(S)->N; *lenrwLS = 0; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_Dense(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_Dense(SUNLinearSolver S) { /* return if S is already free */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return SUN_SUCCESS; } /* delete items from contents, then delete generic structure */ if (S->content) @@ -234,5 +223,5 @@ int SUNLinSolFree_Dense(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/klu/fmod/fsunlinsol_klu_mod.c b/src/sunlinsol/klu/fmod/fsunlinsol_klu_mod.c index 105aa042ed..751b9108bf 100644 --- a/src/sunlinsol/klu/fmod/fsunlinsol_klu_mod.c +++ b/src/sunlinsol/klu/fmod/fsunlinsol_klu_mod.c @@ -343,11 +343,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_KLU(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_KLU(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_KLU(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_KLU(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -403,13 +403,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_KLU(SUNLinearSolver farg1, long *farg2, lon SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_KLU(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_KLU(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -417,11 +417,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_KLU(SUNLinearSolver farg1, long *farg2, lon SWIGEXPORT int _wrap_FSUNLinSolFree_KLU(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_KLU(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_KLU(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/klu/sunlinsol_klu.c b/src/sunlinsol/klu/sunlinsol_klu.c index 6ad08b327e..e1d4695805 100644 --- a/src/sunlinsol/klu/sunlinsol_klu.c +++ b/src/sunlinsol/klu/sunlinsol_klu.c @@ -150,22 +150,22 @@ int SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, int reinit_type) { /* Check for non-NULL SUNLinearSolver */ - if ((S == NULL) || (A == NULL)) { return (SUNLS_MEM_NULL); } + if ((S == NULL) || (A == NULL)) { return (SUN_ERR_ARG_CORRUPT); } /* Check for valid SUNMatrix */ - if (SUNMatGetID(A) != SUNMATRIX_SPARSE) { return (SUNLS_ILL_INPUT); } + if (SUNMatGetID(A) != SUNMATRIX_SPARSE) { return (SUN_ERR_ARG_INCOMPATIBLE); } /* Check for valid reinit_type */ if ((reinit_type != SUNKLU_REINIT_FULL) && (reinit_type != SUNKLU_REINIT_PARTIAL)) { - return (SUNLS_ILL_INPUT); + return (SUN_ERR_ARG_INCOMPATIBLE); } /* Full re-initialization: reallocate matrix for updated storage */ if (reinit_type == SUNKLU_REINIT_FULL) { - if (SUNSparseMatrix_Reallocate(A, nnz) != 0) { return (SUNLS_MEM_FAIL); } + if (SUNSparseMatrix_Reallocate(A, nnz) != 0) { return (SUN_ERR_MEM_FAIL); } } /* Free the prior factorazation and reset for first factorization */ @@ -173,7 +173,7 @@ int SUNLinSol_KLUReInit(SUNLinearSolver S, SUNMatrix A, sunindextype nnz, if (NUMERIC(S) != NULL) { sun_klu_free_numeric(&NUMERIC(S), &COMMON(S)); } FIRSTFACTORIZE(S) = 1; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -186,16 +186,16 @@ int SUNLinSol_KLUSetOrdering(SUNLinearSolver S, int ordering_choice) /* Check for legal ordering_choice */ if ((ordering_choice < 0) || (ordering_choice > 2)) { - return (SUNLS_ILL_INPUT); + return (SUN_ERR_ARG_INCOMPATIBLE); } /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + if (S == NULL) { return (SUN_ERR_ARG_CORRUPT); } /* Set ordering_choice */ COMMON(S).ordering = ordering_choice; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -236,12 +236,12 @@ SUNLinearSolver_ID SUNLinSolGetID_KLU(SUNLinearSolver S) return (SUNLINEARSOLVER_KLU); } -int SUNLinSolInitialize_KLU(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_KLU(SUNLinearSolver S) { /* Force factorization */ FIRSTFACTORIZE(S) = 1; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -255,7 +255,7 @@ int SUNLinSolSetup_KLU(SUNLinearSolver S, SUNMatrix A) /* Ensure that A is a sparse matrix */ if (SUNMatGetID(A) != SUNMATRIX_SPARSE) { - LASTFLAG(S) = SUNLS_ILL_INPUT; + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; return (LASTFLAG(S)); } @@ -346,7 +346,7 @@ int SUNLinSolSetup_KLU(SUNLinearSolver S, SUNMatrix A) } } - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -359,7 +359,7 @@ int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, /* check for valid inputs */ if ((A == NULL) || (S == NULL) || (x == NULL) || (b == NULL)) { - return (SUNLS_MEM_NULL); + return (SUN_ERR_ARG_CORRUPT); } /* copy b into x */ @@ -369,7 +369,7 @@ int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, xdata = N_VGetArrayPointer(x); if (xdata == NULL) { - LASTFLAG(S) = SUNLS_MEM_FAIL; + LASTFLAG(S) = SUN_ERR_MEM_FAIL; return (LASTFLAG(S)); } @@ -382,7 +382,7 @@ int SUNLinSolSolve_KLU(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, return (LASTFLAG(S)); } - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -393,19 +393,20 @@ sunindextype SUNLinSolLastFlag_KLU(SUNLinearSolver S) return (LASTFLAG(S)); } -int SUNLinSolSpace_KLU(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_KLU(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { /* since the klu structures are opaque objects, we omit those from these results */ *leniwLS = 2; *lenrwLS = 0; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolFree_KLU(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_KLU(SUNLinearSolver S) { /* return with success if already freed */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* delete items from the contents structure (if it exists) */ if (S->content) @@ -424,5 +425,5 @@ int SUNLinSolFree_KLU(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/lapackband/sunlinsol_lapackband.c b/src/sunlinsol/lapackband/sunlinsol_lapackband.c index 4d12ee83f6..3858beda24 100644 --- a/src/sunlinsol/lapackband/sunlinsol_lapackband.c +++ b/src/sunlinsol/lapackband/sunlinsol_lapackband.c @@ -137,11 +137,11 @@ SUNLinearSolver_ID SUNLinSolGetID_LapackBand(SUNLinearSolver S) return (SUNLINEARSOLVER_LAPACKBAND); } -int SUNLinSolInitialize_LapackBand(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_LapackBand(SUNLinearSolver S) { /* all solver-specific memory has already been allocated */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSetup_LapackBand(SUNLinearSolver S, SUNMatrix A) @@ -149,13 +149,13 @@ int SUNLinSolSetup_LapackBand(SUNLinearSolver S, SUNMatrix A) sunindextype n, ml, mu, ldim, ier; /* check for valid inputs */ - if ((A == NULL) || (S == NULL)) { return (SUNLS_MEM_NULL); } + if ((A == NULL) || (S == NULL)) { return (SUN_ERR_ARG_CORRUPT); } /* Ensure that A is a band matrix */ if (SUNMatGetID(A) != SUNMATRIX_BAND) { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } /* Call LAPACK to do LU factorization of A */ @@ -169,7 +169,7 @@ int SUNLinSolSetup_LapackBand(SUNLinearSolver S, SUNMatrix A) LASTFLAG(S) = ier; if (ier > 0) { return (SUNLS_LUFACT_FAIL); } if (ier < 0) { return (SUNLS_PACKAGE_FAIL_UNREC); } - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, N_Vector x, @@ -181,7 +181,7 @@ int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* check for valid inputs */ if ((A == NULL) || (S == NULL) || (x == NULL) || (b == NULL)) { - return (SUNLS_MEM_NULL); + return (SUN_ERR_ARG_CORRUPT); } /* copy b into x */ @@ -191,8 +191,8 @@ int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, N_Vector x, xdata = N_VGetArrayPointer(x); if (xdata == NULL) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* Call LAPACK to solve the linear system */ @@ -207,8 +207,8 @@ int SUNLinSolSolve_LapackBand(SUNLinearSolver S, SUNMatrix A, N_Vector x, LASTFLAG(S) = ier; if (ier < 0) { return (SUNLS_PACKAGE_FAIL_UNREC); } - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } sunindextype SUNLinSolLastFlag_LapackBand(SUNLinearSolver S) @@ -218,18 +218,18 @@ sunindextype SUNLinSolLastFlag_LapackBand(SUNLinearSolver S) return (LASTFLAG(S)); } -int SUNLinSolSpace_LapackBand(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS) +SUNErrCode SUNLinSolSpace_LapackBand(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { *lenrwLS = 0; *leniwLS = 2 + LAPACKBAND_CONTENT(S)->N; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolFree_LapackBand(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_LapackBand(SUNLinearSolver S) { /* return with success if already freed */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* delete items from contents, then delete generic structure */ if (S->content) @@ -249,5 +249,5 @@ int SUNLinSolFree_LapackBand(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/lapackdense/fmod/fsunlinsol_lapackdense_mod.c b/src/sunlinsol/lapackdense/fmod/fsunlinsol_lapackdense_mod.c index f2b2b221d7..04186ddf8c 100644 --- a/src/sunlinsol/lapackdense/fmod/fsunlinsol_lapackdense_mod.c +++ b/src/sunlinsol/lapackdense/fmod/fsunlinsol_lapackdense_mod.c @@ -251,11 +251,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_LapackDense(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_LapackDense(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_LapackDense(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_LapackDense(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -311,13 +311,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_LapackDense(SUNLinearSolver farg1, long *fa SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_LapackDense(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_LapackDense(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -325,11 +325,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_LapackDense(SUNLinearSolver farg1, long *fa SWIGEXPORT int _wrap_FSUNLinSolFree_LapackDense(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_LapackDense(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_LapackDense(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/lapackdense/sunlinsol_lapackdense.c b/src/sunlinsol/lapackdense/sunlinsol_lapackdense.c index c70d3d413d..36d36fc9f0 100644 --- a/src/sunlinsol/lapackdense/sunlinsol_lapackdense.c +++ b/src/sunlinsol/lapackdense/sunlinsol_lapackdense.c @@ -138,11 +138,11 @@ SUNLinearSolver_ID SUNLinSolGetID_LapackDense(SUNLinearSolver S) return (SUNLINEARSOLVER_LAPACKDENSE); } -int SUNLinSolInitialize_LapackDense(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_LapackDense(SUNLinearSolver S) { /* all solver-specific memory has already been allocated */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSetup_LapackDense(SUNLinearSolver S, SUNMatrix A) @@ -150,13 +150,13 @@ int SUNLinSolSetup_LapackDense(SUNLinearSolver S, SUNMatrix A) sunindextype n, ier; /* check for valid inputs */ - if ((A == NULL) || (S == NULL)) { return (SUNLS_MEM_NULL); } + if ((A == NULL) || (S == NULL)) { return (SUN_ERR_ARG_CORRUPT); } /* Ensure that A is a dense matrix */ if (SUNMatGetID(A) != SUNMATRIX_DENSE) { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } /* Call LAPACK to do LU factorization of A */ @@ -166,7 +166,7 @@ int SUNLinSolSetup_LapackDense(SUNLinearSolver S, SUNMatrix A) LASTFLAG(S) = ier; if (ier > 0) { return (SUNLS_LUFACT_FAIL); } if (ier < 0) { return (SUNLS_PACKAGE_FAIL_UNREC); } - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, @@ -177,7 +177,7 @@ int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if ((A == NULL) || (S == NULL) || (x == NULL) || (b == NULL)) { - return (SUNLS_MEM_NULL); + return (SUN_ERR_ARG_CORRUPT); } /* copy b into x */ @@ -187,8 +187,8 @@ int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, xdata = N_VGetArrayPointer(x); if (xdata == NULL) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* Call LAPACK to solve the linear system */ @@ -200,8 +200,8 @@ int SUNLinSolSolve_LapackDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, LASTFLAG(S) = ier; if (ier < 0) { return (SUNLS_PACKAGE_FAIL_UNREC); } - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } sunindextype SUNLinSolLastFlag_LapackDense(SUNLinearSolver S) @@ -211,18 +211,18 @@ sunindextype SUNLinSolLastFlag_LapackDense(SUNLinearSolver S) return (LASTFLAG(S)); } -int SUNLinSolSpace_LapackDense(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS) +SUNErrCode SUNLinSolSpace_LapackDense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { *lenrwLS = 0; *leniwLS = 2 + LAPACKDENSE_CONTENT(S)->N; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolFree_LapackDense(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_LapackDense(SUNLinearSolver S) { /* return if S is already free */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* delete items from contents, then delete generic structure */ if (S->content) @@ -242,5 +242,5 @@ int SUNLinSolFree_LapackDense(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp b/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp index efed2654cb..5530a12448 100644 --- a/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp +++ b/src/sunlinsol/magmadense/sunlinsol_magmadense.cpp @@ -204,9 +204,9 @@ SUNLinearSolver SUNLinSol_MagmaDense(N_Vector y, SUNMatrix Amat, SUNContext sunc int SUNLinSol_MagmaDense_SetAsync(SUNLinearSolver S, sunbooleantype onoff) { - if (S == NULL) { return SUNLS_MEM_NULL; } + if (S == NULL) { return SUN_ERR_ARG_CORRUPT; } ASYNCHRONOUS(S) = onoff; - return SUNLS_SUCCESS; + return SUN_SUCCESS; } /* @@ -225,30 +225,30 @@ SUNLinearSolver_ID SUNLinSolGetID_MagmaDense(SUNLinearSolver S) return (SUNLINEARSOLVER_MAGMADENSE); } -int SUNLinSolInitialize_MagmaDense(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_MagmaDense(SUNLinearSolver S) { /* All solver-specific memory has already been allocated */ - if (S == NULL) { return SUNLS_MEM_NULL; } - LASTFLAG(S) = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + if (S == NULL) { return SUN_ERR_ARG_CORRUPT; } + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSetup_MagmaDense(SUNLinearSolver S, SUNMatrix A) { /* Check for valid inputs */ - if (S == NULL) { return SUNLS_MEM_NULL; } + if (S == NULL) { return SUN_ERR_ARG_CORRUPT; } if (A == NULL) { - LASTFLAG(S) = SUNLS_MEM_NULL; - return (SUNLS_MEM_NULL); + LASTFLAG(S) = SUN_ERR_ARG_CORRUPT; + return (SUN_ERR_ARG_CORRUPT); } /* Ensure that A is a magma dense matrix */ if (SUNMatGetID(A) != SUNMATRIX_MAGMADENSE) { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } sunindextype ier = 0; @@ -302,26 +302,26 @@ int SUNLinSolSetup_MagmaDense(SUNLinearSolver S, SUNMatrix A) LASTFLAG(S) = ier; if (ier > 0) { return (SUNLS_LUFACT_FAIL); } if (ier < 0) { return (SUNLS_PACKAGE_FAIL_UNREC); } - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } int SUNLinSolSolve_MagmaDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype tol) { /* Check for valid inputs */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + if (S == NULL) { return (SUN_ERR_ARG_CORRUPT); } if ((A == NULL) || (x == NULL) || (b == NULL)) { - LASTFLAG(S) = SUNLS_MEM_NULL; - return (SUNLS_MEM_NULL); + LASTFLAG(S) = SUN_ERR_ARG_CORRUPT; + return (SUN_ERR_ARG_CORRUPT); } /* Ensure that A is a magma dense matrix */ if (SUNMatGetID(A) != SUNMATRIX_MAGMADENSE) { - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } int ier = 0; @@ -335,8 +335,8 @@ int SUNLinSolSolve_MagmaDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, sunrealtype* xdata = N_VGetDeviceArrayPointer(x); if (xdata == NULL) { - LASTFLAG(S) = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); + LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return (SUN_ERR_MEM_FAIL); } /* Call MAGMA to solve the linear system */ @@ -373,7 +373,7 @@ int SUNLinSolSolve_MagmaDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (!ASYNCHRONOUS(S)) { magma_queue_sync(QUEUE(S)); } LASTFLAG(S) = ier; - return ((ier < 0) ? SUNLS_PACKAGE_FAIL_UNREC : SUNLS_SUCCESS); + return ((ier < 0) ? SUNLS_PACKAGE_FAIL_UNREC : SUN_SUCCESS); } sunindextype SUNLinSolLastFlag_MagmaDense(SUNLinearSolver S) @@ -383,18 +383,18 @@ sunindextype SUNLinSolLastFlag_MagmaDense(SUNLinearSolver S) return (LASTFLAG(S)); } -int SUNLinSolSpace_MagmaDense(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS) +SUNErrCode SUNLinSolSpace_MagmaDense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { *lenrwLS = 0; *leniwLS = 2 + MAGMADENSE_CONTENT(S)->N; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolFree_MagmaDense(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_MagmaDense(SUNLinearSolver S) { /* return if S is already free */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* delete items from contents, then delete generic structure */ if (S->content) @@ -426,5 +426,5 @@ int SUNLinSolFree_MagmaDense(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/onemkldense/sunlinsol_onemkldense.cpp b/src/sunlinsol/onemkldense/sunlinsol_onemkldense.cpp index d6f16a7f0f..281b214d8c 100644 --- a/src/sunlinsol/onemkldense/sunlinsol_onemkldense.cpp +++ b/src/sunlinsol/onemkldense/sunlinsol_onemkldense.cpp @@ -265,17 +265,17 @@ SUNLinearSolver SUNLinSol_OneMklDense(N_Vector y, SUNMatrix Amat, * Implementation of SUNLinearSolver operations * -------------------------------------------------------------------------- */ -int SUNLinSolInitialize_OneMklDense(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_OneMklDense(SUNLinearSolver S) { // All solver-specific memory has already been allocated if (!S) { SUNDIALS_DEBUG_ERROR("Linear solver is NULL\n"); - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } - LS_LASTFLAG(S) = SUNLS_SUCCESS; - return SUNLS_SUCCESS; + LS_LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A) @@ -284,22 +284,22 @@ int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A) if (!S) { SUNDIALS_DEBUG_ERROR("Linear solver is NULL\n"); - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } if (!A) { SUNDIALS_DEBUG_ERROR("Matrix is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_NULL; - return SUNLS_MEM_NULL; + LS_LASTFLAG(S) = SUN_ERR_ARG_CORRUPT; + return SUN_ERR_ARG_CORRUPT; } // Ensure that A is a oneMKL dense matrix if (SUNMatGetID(A) != SUNMATRIX_ONEMKLDENSE) { SUNDIALS_DEBUG_ERROR("Matrix is not the oneMKL matrix\n"); - LS_LASTFLAG(S) = SUNLS_ILL_INPUT; - return SUNLS_ILL_INPUT; + LS_LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return SUN_ERR_ARG_INCOMPATIBLE; } // Access A matrix data array @@ -307,8 +307,8 @@ int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A) if (!Adata) { SUNDIALS_DEBUG_ERROR("Matrix data array is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_FAIL; - return SUNLS_MEM_FAIL; + LS_LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return SUN_ERR_MEM_FAIL; } // Access pivots data array @@ -316,8 +316,8 @@ int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A) if (!pivots) { SUNDIALS_DEBUG_ERROR("Matrix data array is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_FAIL; - return SUNLS_MEM_FAIL; + LS_LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return SUN_ERR_MEM_FAIL; } // Call oneMKL to do LU factorization of A @@ -432,8 +432,8 @@ int SUNLinSolSetup_OneMklDense(SUNLinearSolver S, SUNMatrix A) return SUNLS_PACKAGE_FAIL_UNREC; } - LS_LASTFLAG(S) = SUNLS_SUCCESS; - return SUNLS_SUCCESS; + LS_LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, @@ -443,22 +443,22 @@ int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (!S) { SUNDIALS_DEBUG_ERROR("Linear solver is NULL\n"); - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } if (!A || !x || !b) { SUNDIALS_DEBUG_ERROR("A, x, or b is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_NULL; - return SUNLS_MEM_NULL; + LS_LASTFLAG(S) = SUN_ERR_ARG_CORRUPT; + return SUN_ERR_ARG_CORRUPT; } // Ensure that A is a onemkl dense matrix if (SUNMatGetID(A) != SUNMATRIX_ONEMKLDENSE) { SUNDIALS_DEBUG_ERROR("Matrix is not the oneMKL matrix\n"); - LS_LASTFLAG(S) = SUNLS_ILL_INPUT; - return SUNLS_ILL_INPUT; + LS_LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return SUN_ERR_ARG_INCOMPATIBLE; } // Copy b into x @@ -469,8 +469,8 @@ int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (!xdata) { SUNDIALS_DEBUG_ERROR("Vector data array is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_FAIL; - return SUNLS_MEM_FAIL; + LS_LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return SUN_ERR_MEM_FAIL; } // Access A matrix data array @@ -478,8 +478,8 @@ int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (!Adata) { SUNDIALS_DEBUG_ERROR("Matrix data array is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_FAIL; - return SUNLS_MEM_FAIL; + LS_LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return SUN_ERR_MEM_FAIL; } // Access pivots data array @@ -487,8 +487,8 @@ int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (!pivots) { SUNDIALS_DEBUG_ERROR("Matrix data array is NULL\n"); - LS_LASTFLAG(S) = SUNLS_MEM_FAIL; - return SUNLS_MEM_FAIL; + LS_LASTFLAG(S) = SUN_ERR_MEM_FAIL; + return SUN_ERR_MEM_FAIL; } // Call oneMKL to solve the linear system @@ -580,8 +580,8 @@ int SUNLinSolSolve_OneMklDense(SUNLinearSolver S, SUNMatrix A, N_Vector x, return SUNLS_PACKAGE_FAIL_UNREC; } - LS_LASTFLAG(S) = SUNLS_SUCCESS; - return SUNLS_SUCCESS; + LS_LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } sunindextype SUNLinSolLastFlag_OneMklDense(SUNLinearSolver S) @@ -590,32 +590,32 @@ sunindextype SUNLinSolLastFlag_OneMklDense(SUNLinearSolver S) if (!S) { SUNDIALS_DEBUG_ERROR("Linear solver is NULL\n"); - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } return LS_LASTFLAG(S); } -int SUNLinSolSpace_OneMklDense(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS) +SUNErrCode SUNLinSolSpace_OneMklDense(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { if (!S) { SUNDIALS_DEBUG_ERROR("Linear solver is NULL\n"); - return SUNLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } *lenrwLS = 0; *leniwLS = 2 + LS_CONTENT(S)->rows; - LS_LASTFLAG(S) = SUNLS_SUCCESS; - return SUNLS_SUCCESS; + LS_LASTFLAG(S) = SUN_SUCCESS; + return SUN_SUCCESS; } -int SUNLinSolFree_OneMklDense(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_OneMklDense(SUNLinearSolver S) { // return if S is already free - if (!S) { return SUNLS_SUCCESS; } + if (!S) { return SUN_SUCCESS; } // delete items from contents, then delete generic structure if (S->content) @@ -644,5 +644,5 @@ int SUNLinSolFree_OneMklDense(SUNLinearSolver S) SUNLinSolFreeEmpty(S); S = NULL; - return SUNLS_SUCCESS; + return SUN_SUCCESS; } diff --git a/src/sunlinsol/pcg/fmod/fsunlinsol_pcg_mod.c b/src/sunlinsol/pcg/fmod/fsunlinsol_pcg_mod.c index f2c3f51ee1..725319225d 100644 --- a/src/sunlinsol/pcg/fmod/fsunlinsol_pcg_mod.c +++ b/src/sunlinsol/pcg/fmod/fsunlinsol_pcg_mod.c @@ -230,12 +230,12 @@ SWIGEXPORT int _wrap_FSUNLinSol_PCGSetPrecType(SUNLinearSolver farg1, int const int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSol_PCGSetPrecType(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSol_PCGSetPrecType(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -244,12 +244,12 @@ SWIGEXPORT int _wrap_FSUNLinSol_PCGSetMaxl(SUNLinearSolver farg1, int const *far int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSol_PCGSetMaxl(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSol_PCGSetMaxl(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -281,11 +281,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_PCG(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_PCG(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_PCG(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_PCG(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -295,13 +295,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetATimes_PCG(SUNLinearSolver farg1, void *farg2, SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; void *arg2 = (void *) 0 ; SUNATimesFn arg3 = (SUNATimesFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNATimesFn)(farg3); - result = (int)SUNLinSolSetATimes_PCG(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetATimes_PCG(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -312,14 +312,14 @@ SWIGEXPORT int _wrap_FSUNLinSolSetPreconditioner_PCG(SUNLinearSolver farg1, void void *arg2 = (void *) 0 ; SUNPSetupFn arg3 = (SUNPSetupFn) 0 ; SUNPSolveFn arg4 = (SUNPSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNPSetupFn)(farg3); arg4 = (SUNPSolveFn)(farg4); - result = (int)SUNLinSolSetPreconditioner_PCG(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetPreconditioner_PCG(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -329,13 +329,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors_PCG(SUNLinearSolver farg1, N_Ve SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; N_Vector arg2 = (N_Vector) 0 ; N_Vector arg3 = (N_Vector) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (N_Vector)(farg2); arg3 = (N_Vector)(farg3); - result = (int)SUNLinSolSetScalingVectors_PCG(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetScalingVectors_PCG(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -344,12 +344,12 @@ SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess_PCG(SUNLinearSolver farg1, int const int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSolSetZeroGuess_PCG(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetZeroGuess_PCG(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -441,13 +441,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_PCG(SUNLinearSolver farg1, long *farg2, lon SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_PCG(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_PCG(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -455,11 +455,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_PCG(SUNLinearSolver farg1, long *farg2, lon SWIGEXPORT int _wrap_FSUNLinSolFree_PCG(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_PCG(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_PCG(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/pcg/sunlinsol_pcg.c b/src/sunlinsol/pcg/sunlinsol_pcg.c index 24a3f5e55b..1a589298b5 100644 --- a/src/sunlinsol/pcg/sunlinsol_pcg.c +++ b/src/sunlinsol/pcg/sunlinsol_pcg.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -49,6 +49,7 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_PCG content; @@ -63,7 +64,7 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc /* Create linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_PCG; @@ -85,11 +86,7 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc /* Create content */ content = NULL; content = (SUNLinearSolverContent_PCG)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -120,32 +117,16 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc /* Allocate content */ content->r = N_VClone(y); - if (content->r == NULL) - { - SUNLinSolFree(S); - return NULL; - } + SUNCheckLastErrNull(); content->p = N_VClone(y); - if (content->p == NULL) - { - SUNLinSolFree(S); - return NULL; - } + SUNCheckLastErrNull(); content->z = N_VClone(y); - if (content->z == NULL) - { - SUNLinSolFree(S); - return NULL; - } + SUNCheckLastErrNull(); content->Ap = N_VClone(y); - if (content->Ap == NULL) - { - SUNLinSolFree(S); - return NULL; - } + SUNCheckLastErrNull(); return (S); } @@ -154,38 +135,31 @@ SUNLinearSolver SUNLinSol_PCG(N_Vector y, int pretype, int maxl, SUNContext sunc * Function to set the type of preconditioning for PCG to use */ -int SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype) +SUNErrCode SUNLinSol_PCGSetPrecType(SUNLinearSolver S, int pretype) { + SUNFunctionBegin(S->sunctx); /* Check for legal pretype */ - if ((pretype != SUN_PREC_NONE) && (pretype != SUN_PREC_LEFT) && - (pretype != SUN_PREC_RIGHT) && (pretype != SUN_PREC_BOTH)) - { - return (SUNLS_ILL_INPUT); - } - - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNAssert((pretype == SUN_PREC_NONE) || (pretype == SUN_PREC_LEFT) || + (pretype == SUN_PREC_RIGHT) || (pretype == SUN_PREC_BOTH), + SUN_ERR_ARG_OUTOFRANGE); /* Set pretype */ PRETYPE(S) = pretype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the maximum number of iterations for PCG to use */ -int SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl) +SUNErrCode SUNLinSol_PCGSetMaxl(SUNLinearSolver S, int maxl) { - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Check for legal number of iters */ if (maxl <= 0) { maxl = SUNPCG_MAXL_DEFAULT; } /* Set max iters */ PCG_CONTENT(S)->maxl = maxl; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* @@ -204,18 +178,12 @@ SUNLinearSolver_ID SUNLinSolGetID_PCG(SUNLinearSolver S) return (SUNLINEARSOLVER_PCG); } -int SUNLinSolInitialize_PCG(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_PCG(SUNLinearSolver S) { - /* ensure valid options */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - + SUNFunctionBegin(S->sunctx); if (PCG_CONTENT(S)->maxl <= 0) { PCG_CONTENT(S)->maxl = SUNPCG_MAXL_DEFAULT; } - if (PCG_CONTENT(S)->ATimes == NULL) - { - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(PCG_CONTENT(S)->ATimes, SUN_ERR_ARG_CORRUPT); if ((PRETYPE(S) != SUN_PREC_LEFT) && (PRETYPE(S) != SUN_PREC_RIGHT) && (PRETYPE(S) != SUN_PREC_BOTH)) @@ -223,70 +191,62 @@ int SUNLinSolInitialize_PCG(SUNLinearSolver S) PRETYPE(S) = SUN_PREC_NONE; } - if ((PRETYPE(S) != SUN_PREC_NONE) && (PCG_CONTENT(S)->Psolve == NULL)) - { - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert((PCG_CONTENT(S)->pretype == SUN_PREC_NONE) || + (PCG_CONTENT(S)->Psolve != NULL), + SUN_ERR_ARG_CORRUPT); /* no additional memory to allocate */ - /* return with success */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* ATData, SUNATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes_PCG(SUNLinearSolver S, void* ATData, + SUNATimesFn ATimes) { /* set function pointers to integrator-supplied ATimes routine and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } PCG_CONTENT(S)->ATimes = ATimes; PCG_CONTENT(S)->ATData = ATData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* PData, - SUNPSetupFn Psetup, SUNPSolveFn Psolve) +SUNErrCode SUNLinSolSetPreconditioner_PCG(SUNLinearSolver S, void* PData, + SUNPSetupFn Psetup, SUNPSolveFn Psolve) { /* set function pointers to integrator-supplied Psetup and PSolve routines and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } PCG_CONTENT(S)->Psetup = Psetup; PCG_CONTENT(S)->Psolve = Psolve; PCG_CONTENT(S)->PData = PData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, N_Vector nul) +SUNErrCode SUNLinSolSetScalingVectors_PCG(SUNLinearSolver S, N_Vector s, + N_Vector nul) { /* set N_Vector pointer to integrator-supplied scaling vector (only use the first one), and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } PCG_CONTENT(S)->s = s; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, sunbooleantype onoff) +SUNErrCode SUNLinSolSetZeroGuess_PCG(SUNLinearSolver S, sunbooleantype onoff) { /* set flag indicating a zero initial guess */ - if (S == NULL) { return (SUNLS_MEM_NULL); } PCG_CONTENT(S)->zeroguess = onoff; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul) { - int ier; + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + int status; SUNPSetupFn Psetup; void* PData; /* Set shortcuts to PCG memory structures */ - if (S == NULL) { return (SUNLS_MEM_NULL); } Psetup = PCG_CONTENT(S)->Psetup; PData = PCG_CONTENT(S)->PData; @@ -294,36 +254,41 @@ int SUNLinSolSetup_PCG(SUNLinearSolver S, SUNMatrix nul) Psetup routine exists, call that here */ if (Psetup != NULL) { - ier = Psetup(PData); - if (ier != 0) + status = Psetup(PData); + if (status != 0) { - LASTFLAG(S) = (ier < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; return (LASTFLAG(S)); } } /* return with success */ - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, sunrealtype delta) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + /* local data and shortcut variables */ sunrealtype alpha, beta, r0_norm, rho, rz, rz_old; N_Vector r, p, z, Ap, w; sunbooleantype UsePrec, UseScaling, converged; sunbooleantype* zeroguess; - int l, l_max, pretype, ier; + int l, l_max, pretype; void *A_data, *P_data; SUNATimesFn atimes; SUNPSolveFn psolve; sunrealtype* res_norm; int* nli; + int status; /* Make local shorcuts to solver variables. */ - if (S == NULL) { return (SUNLS_MEM_NULL); } l_max = PCG_CONTENT(S)->maxl; r = PCG_CONTENT(S)->r; p = PCG_CONTENT(S)->p; @@ -355,39 +320,45 @@ int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, #endif /* Check if Atimes function has been set */ - if (atimes == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(atimes, SUN_ERR_ARG_CORRUPT); /* If preconditioning, check if psolve has been set */ - if (UsePrec && psolve == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(!UsePrec || psolve, SUN_ERR_ARG_CORRUPT); /* Set r to initial residual r_0 = b - A*x_0 */ - if (*zeroguess) { N_VScale(ONE, b, r); } + if (*zeroguess) + { + N_VScale(ONE, b, r); + SUNCheckLastErrNoRet(); + } else { - ier = atimes(A_data, x, r); - if (ier != 0) + status = atimes(A_data, x, r); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } N_VLinearSum(ONE, b, -ONE, r, r); + SUNCheckLastErrNoRet(); } /* Set rho to scaled L2 norm of r, and return if small */ - if (UseScaling) { N_VProd(r, w, Ap); } - else { N_VScale(ONE, r, Ap); } - *res_norm = r0_norm = rho = SUNRsqrt(N_VDotProd(Ap, Ap)); + if (UseScaling) + { + N_VProd(r, w, Ap); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, r, Ap); + SUNCheckLastErrNoRet(); + } + rho = N_VDotProd(Ap, Ap); + SUNCheckLastErrNoRet(); + *res_norm = r0_norm = rho = SUNRsqrt(rho); #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO /* print initial residual */ @@ -405,28 +376,35 @@ int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, if (rho <= delta) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } /* Apply preconditioner and b-scaling to r = r_0 */ if (UsePrec) { - ier = psolve(P_data, r, z, delta, SUN_PREC_LEFT); /* z = P^{-1}r */ - if (ier != 0) + status = psolve(P_data, r, z, delta, SUN_PREC_LEFT); /* z = P^{-1}r */ + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, r, z); } + else + { + N_VScale(ONE, r, z); + SUNCheckLastErrNoRet(); + } /* Initialize rz to */ rz = N_VDotProd(r, z); + SUNCheckLastErrNoRet(); /* Copy z to p */ N_VScale(ONE, z, p); + SUNCheckLastErrNoRet(); /* Begin main iteration loop */ for (l = 0; l < l_max; l++) @@ -435,28 +413,50 @@ int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, (*nli)++; /* Generate Ap = A*p */ - ier = atimes(A_data, p, Ap); - if (ier != 0) + status = atimes(A_data, p, Ap); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } /* Calculate alpha = / */ - alpha = rz / N_VDotProd(Ap, p); + alpha = N_VDotProd(Ap, p); + SUNCheckLastErrNoRet(); + alpha = rz / alpha; /* Update x = x + alpha*p */ - if (l == 0 && *zeroguess) { N_VScale(alpha, p, x); } - else { N_VLinearSum(ONE, x, alpha, p, x); } + if (l == 0 && *zeroguess) + { + N_VScale(alpha, p, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, alpha, p, x); + SUNCheckLastErrNoRet(); + } /* Update r = r - alpha*Ap */ N_VLinearSum(ONE, r, -alpha, Ap, r); + SUNCheckLastErrNoRet(); /* Set rho and check convergence */ - if (UseScaling) { N_VProd(r, w, Ap); } - else { N_VScale(ONE, r, Ap); } - *res_norm = rho = SUNRsqrt(N_VDotProd(Ap, Ap)); + if (UseScaling) + { + N_VProd(r, w, Ap); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, r, Ap); + SUNCheckLastErrNoRet(); + } + rho = N_VDotProd(Ap, Ap); + SUNCheckLastErrNoRet(); + *res_norm = rho = SUNRsqrt(rho); #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO /* print current iteration number and the residual */ @@ -483,30 +483,37 @@ int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, /* Apply preconditioner: z = P^{-1}*r */ if (UsePrec) { - ier = psolve(P_data, r, z, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, r, z, delta, SUN_PREC_LEFT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, r, z); } + else + { + N_VScale(ONE, r, z); + SUNCheckLastErrNoRet(); + } /* update rz */ rz_old = rz; rz = N_VDotProd(r, z); + SUNCheckLastErrNoRet(); /* Calculate beta = / */ beta = rz / rz_old; /* Update p = z + beta*p */ N_VLinearSum(ONE, z, beta, p, p); + SUNCheckLastErrNoRet(); } /* Main loop finished, return with result */ *zeroguess = SUNFALSE; - if (converged == SUNTRUE) { LASTFLAG(S) = SUNLS_SUCCESS; } + if (converged == SUNTRUE) { LASTFLAG(S) = SUN_SUCCESS; } else if (rho < r0_norm) { LASTFLAG(S) = SUNLS_RES_REDUCED; } else { LASTFLAG(S) = SUNLS_CONV_FAIL; } return (LASTFLAG(S)); @@ -515,14 +522,12 @@ int SUNLinSolSolve_PCG(SUNLinearSolver S, SUNMatrix nul, N_Vector x, N_Vector b, int SUNLinSolNumIters_PCG(SUNLinearSolver S) { /* return the stored 'numiters' value */ - if (S == NULL) { return (-1); } return (PCG_CONTENT(S)->numiters); } sunrealtype SUNLinSolResNorm_PCG(SUNLinearSolver S) { /* return the stored 'resnorm' value */ - if (S == NULL) { return (-ONE); } return (PCG_CONTENT(S)->resnorm); } @@ -535,22 +540,24 @@ N_Vector SUNLinSolResid_PCG(SUNLinearSolver S) sunindextype SUNLinSolLastFlag_PCG(SUNLinearSolver S) { /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_PCG(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); sunindextype liw1, lrw1; N_VSpace(PCG_CONTENT(S)->r, &lrw1, &liw1); + SUNCheckLastErrNoRet(); *lenrwLS = 1 + lrw1 * 4; *leniwLS = 4 + liw1 * 4; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_PCG(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_PCG(SUNLinearSolver S) { - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return SUN_SUCCESS; } if (S->content) { @@ -585,5 +592,5 @@ int SUNLinSolFree_PCG(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/spbcgs/fmod/fsunlinsol_spbcgs_mod.c b/src/sunlinsol/spbcgs/fmod/fsunlinsol_spbcgs_mod.c index 404d520680..003975de4b 100644 --- a/src/sunlinsol/spbcgs/fmod/fsunlinsol_spbcgs_mod.c +++ b/src/sunlinsol/spbcgs/fmod/fsunlinsol_spbcgs_mod.c @@ -281,11 +281,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_SPBCGS(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPBCGS(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_SPBCGS(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_SPBCGS(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -295,13 +295,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPBCGS(SUNLinearSolver farg1, void *far SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; void *arg2 = (void *) 0 ; SUNATimesFn arg3 = (SUNATimesFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNATimesFn)(farg3); - result = (int)SUNLinSolSetATimes_SPBCGS(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetATimes_SPBCGS(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -312,14 +312,14 @@ SWIGEXPORT int _wrap_FSUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver farg1, v void *arg2 = (void *) 0 ; SUNPSetupFn arg3 = (SUNPSetupFn) 0 ; SUNPSolveFn arg4 = (SUNPSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNPSetupFn)(farg3); arg4 = (SUNPSolveFn)(farg4); - result = (int)SUNLinSolSetPreconditioner_SPBCGS(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetPreconditioner_SPBCGS(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -329,13 +329,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver farg1, N SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; N_Vector arg2 = (N_Vector) 0 ; N_Vector arg3 = (N_Vector) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (N_Vector)(farg2); arg3 = (N_Vector)(farg3); - result = (int)SUNLinSolSetScalingVectors_SPBCGS(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetScalingVectors_SPBCGS(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -344,12 +344,12 @@ SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver farg1, int co int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSolSetZeroGuess_SPBCGS(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetZeroGuess_SPBCGS(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -441,13 +441,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPBCGS(SUNLinearSolver farg1, long *farg2, SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_SPBCGS(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_SPBCGS(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -455,11 +455,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPBCGS(SUNLinearSolver farg1, long *farg2, SWIGEXPORT int _wrap_FSUNLinSolFree_SPBCGS(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_SPBCGS(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_SPBCGS(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c b/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c index 67791136e1..f821dd5df3 100644 --- a/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c +++ b/src/sunlinsol/spbcgs/sunlinsol_spbcgs.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -51,6 +51,7 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_SPBCGS content; @@ -63,18 +64,15 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, if (maxl <= 0) { maxl = SUNSPBCGS_MAXL_DEFAULT; } /* check that the supplied N_Vector supports all requisite operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvlinearsum == NULL) || (y->ops->nvprod == NULL) || - (y->ops->nvdiv == NULL) || (y->ops->nvscale == NULL) || - (y->ops->nvdotprod == NULL)) - { - return (NULL); - } + SUNAssertNull((y->ops->nvclone) && (y->ops->nvdestroy) && + (y->ops->nvlinearsum) && (y->ops->nvprod) && + (y->ops->nvdiv) && (y->ops->nvscale) && (y->ops->nvdotprod), + SUN_ERR_ARG_OUTOFRANGE); /* Create linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_SPBCGS; @@ -96,11 +94,7 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, /* Create content */ content = NULL; content = (SUNLinearSolverContent_SPBCGS)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -135,53 +129,25 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, /* Allocate content */ content->r_star = N_VClone(y); - if (content->r_star == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->r = N_VClone(y); - if (content->r == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->p = N_VClone(y); - if (content->p == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->q = N_VClone(y); - if (content->q == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->u = N_VClone(y); - if (content->u == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->Ap = N_VClone(y); - if (content->Ap == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); content->vtemp = N_VClone(y); - if (content->vtemp == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); return (S); } @@ -190,38 +156,31 @@ SUNLinearSolver SUNLinSol_SPBCGS(N_Vector y, int pretype, int maxl, * Function to set the type of preconditioning for SPBCGS to use */ -int SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, int pretype) +SUNErrCode SUNLinSol_SPBCGSSetPrecType(SUNLinearSolver S, int pretype) { + SUNFunctionBegin(S->sunctx); /* Check for legal pretype */ - if ((pretype != SUN_PREC_NONE) && (pretype != SUN_PREC_LEFT) && - (pretype != SUN_PREC_RIGHT) && (pretype != SUN_PREC_BOTH)) - { - return (SUNLS_ILL_INPUT); - } - - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNAssert((pretype == SUN_PREC_NONE) || (pretype == SUN_PREC_LEFT) || + (pretype == SUN_PREC_RIGHT) || (pretype == SUN_PREC_BOTH), + SUN_ERR_ARG_CORRUPT); /* Set pretype */ PRETYPE(S) = pretype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the maximum number of iterations for SPBCGS to use */ -int SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl) +SUNErrCode SUNLinSol_SPBCGSSetMaxl(SUNLinearSolver S, int maxl) { - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Check for legal pretype */ if (maxl <= 0) { maxl = SUNSPBCGS_MAXL_DEFAULT; } /* Set pretype */ SPBCGS_CONTENT(S)->maxl = maxl; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* @@ -240,21 +199,16 @@ SUNLinearSolver_ID SUNLinSolGetID_SPBCGS(SUNLinearSolver S) return (SUNLINEARSOLVER_SPBCGS); } -int SUNLinSolInitialize_SPBCGS(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SPBCGS(SUNLinearSolver S) { - /* ensure valid options */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNFunctionBegin(S->sunctx); if (SPBCGS_CONTENT(S)->maxl <= 0) { SPBCGS_CONTENT(S)->maxl = SUNSPBCGS_MAXL_DEFAULT; } - if (SPBCGS_CONTENT(S)->ATimes == NULL) - { - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(SPBCGS_CONTENT(S)->ATimes, SUN_ERR_ARG_CORRUPT); if ((PRETYPE(S) != SUN_PREC_LEFT) && (PRETYPE(S) != SUN_PREC_RIGHT) && (PRETYPE(S) != SUN_PREC_BOTH)) @@ -262,71 +216,66 @@ int SUNLinSolInitialize_SPBCGS(SUNLinearSolver S) PRETYPE(S) = SUN_PREC_NONE; } - if ((PRETYPE(S) != SUN_PREC_NONE) && (SPBCGS_CONTENT(S)->Psolve == NULL)) - { - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert((PRETYPE(S) == SUN_PREC_NONE) || SPBCGS_CONTENT(S)->Psolve, + SUN_ERR_ARG_CORRUPT); /* no additional memory to allocate */ /* return with success */ - LASTFLAG(S) = SUNLS_SUCCESS; return (LASTFLAG(S)); } -int SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* ATData, SUNATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes_SPBCGS(SUNLinearSolver S, void* ATData, + SUNATimesFn ATimes) { /* set function pointers to integrator-supplied ATimes routine and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPBCGS_CONTENT(S)->ATimes = ATimes; SPBCGS_CONTENT(S)->ATData = ATData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, void* PData, - SUNPSetupFn Psetup, SUNPSolveFn Psolve) +SUNErrCode SUNLinSolSetPreconditioner_SPBCGS(SUNLinearSolver S, void* PData, + SUNPSetupFn Psetup, + SUNPSolveFn Psolve) { /* set function pointers to integrator-supplied Psetup and PSolve routines and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPBCGS_CONTENT(S)->Psetup = Psetup; SPBCGS_CONTENT(S)->Psolve = Psolve; SPBCGS_CONTENT(S)->PData = PData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, N_Vector s1, N_Vector s2) +SUNErrCode SUNLinSolSetScalingVectors_SPBCGS(SUNLinearSolver S, N_Vector s1, + N_Vector s2) { /* set N_Vector pointers to integrator-supplied scaling vectors, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPBCGS_CONTENT(S)->s1 = s1; SPBCGS_CONTENT(S)->s2 = s2; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, sunbooleantype onoff) +SUNErrCode SUNLinSolSetZeroGuess_SPBCGS(SUNLinearSolver S, sunbooleantype onoff) { /* set flag indicating a zero initial guess */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPBCGS_CONTENT(S)->zeroguess = onoff; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } int SUNLinSolSetup_SPBCGS(SUNLinearSolver S, SUNMatrix A) { - int ier; + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + + int status; SUNPSetupFn Psetup; void* PData; /* Set shortcuts to SPBCGS memory structures */ - if (S == NULL) { return (SUNLS_MEM_NULL); } Psetup = SPBCGS_CONTENT(S)->Psetup; PData = SPBCGS_CONTENT(S)->PData; @@ -334,41 +283,46 @@ int SUNLinSolSetup_SPBCGS(SUNLinearSolver S, SUNMatrix A) Psetup routine exists, call that here */ if (Psetup != NULL) { - ier = Psetup(PData); - if (ier != 0) + status = Psetup(PData); + if (status != 0) { - LASTFLAG(S) = (ier < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; return (LASTFLAG(S)); } } /* return with success */ - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype delta) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + /* local data and shortcut variables */ sunrealtype alpha, beta, omega, omega_denom, beta_num, beta_denom, r_norm, rho; N_Vector r_star, r, p, q, u, Ap, vtemp; sunbooleantype preOnLeft, preOnRight, scale_x, scale_b, converged; sunbooleantype* zeroguess; - int l, l_max, ier; + int l, l_max; void *A_data, *P_data; N_Vector sx, sb; SUNATimesFn atimes; SUNPSolveFn psolve; sunrealtype* res_norm; int* nli; + int status; /* local variables for fused vector operations */ sunrealtype cv[3]; N_Vector Xv[3]; /* Make local shorcuts to solver variables. */ - if (S == NULL) { return (SUNLS_MEM_NULL); } l_max = SPBCGS_CONTENT(S)->maxl; r_star = SPBCGS_CONTENT(S)->r_star; r = SPBCGS_CONTENT(S)->r; @@ -401,8 +355,8 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (preOnRight && !(*zeroguess)) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO @@ -412,56 +366,66 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, #endif /* Check if Atimes function has been set */ - if (atimes == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(atimes, SUN_ERR_ARG_CORRUPT); /* If preconditioning, check if psolve has been set */ - if ((preOnLeft || preOnRight) && psolve == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(!(preOnLeft || preOnRight) || psolve, SUN_ERR_ARG_CORRUPT); /* Set r_star to initial (unscaled) residual r_0 = b - A*x_0 */ - if (*zeroguess) { N_VScale(ONE, b, r_star); } + if (*zeroguess) + { + N_VScale(ONE, b, r_star); + SUNCheckLastErrNoRet(); + } else { - ier = atimes(A_data, x, r_star); - if (ier != 0) + status = atimes(A_data, x, r_star); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } N_VLinearSum(ONE, b, -ONE, r_star, r_star); + SUNCheckLastErrNoRet(); } /* Apply left preconditioner and b-scaling to r_star = r_0 */ if (preOnLeft) { - ier = psolve(P_data, r_star, r, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, r_star, r, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, r_star, r); } + else + { + N_VScale(ONE, r_star, r); + SUNCheckLastErrNoRet(); + } - if (scale_b) { N_VProd(sb, r, r_star); } - else { N_VScale(ONE, r, r_star); } + if (scale_b) + { + N_VProd(sb, r, r_star); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, r, r_star); + SUNCheckLastErrNoRet(); + } /* Initialize beta_denom to the dot product of r0 with r0 */ beta_denom = N_VDotProd(r_star, r_star); + SUNCheckLastErrNoRet(); /* Set r_norm to L2 norm of r_star = sb P1_inv r_0, and return if small */ @@ -484,17 +448,23 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (r_norm <= delta) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } /* Copy r_star to r and p */ N_VScale(ONE, r_star, r); + SUNCheckLastErrNoRet(); N_VScale(ONE, r_star, p); + SUNCheckLastErrNoRet(); /* Set x = sx x if non-zero guess */ - if (scale_x && !(*zeroguess)) { N_VProd(sx, x, x); } + if (scale_x && !(*zeroguess)) + { + N_VProd(sx, x, x); + SUNCheckLastErrNoRet(); + } /* Begin main iteration loop */ @@ -506,30 +476,41 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Apply x-scaling: vtemp = sx_inv p */ - if (scale_x) { N_VDiv(p, sx, vtemp); } - else { N_VScale(ONE, p, vtemp); } + if (scale_x) + { + N_VDiv(p, sx, vtemp); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, p, vtemp); + SUNCheckLastErrNoRet(); + } /* Apply right preconditioner: vtemp = P2_inv sx_inv p */ if (preOnRight) { N_VScale(ONE, vtemp, Ap); - ier = psolve(P_data, Ap, vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, Ap, vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } /* Apply A: Ap = A P2_inv sx_inv p */ - ier = atimes(A_data, vtemp, Ap); - if (ier != 0) + status = atimes(A_data, vtemp, Ap); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } @@ -537,57 +518,84 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (preOnLeft) { - ier = psolve(P_data, Ap, vtemp, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, Ap, vtemp, delta, SUN_PREC_LEFT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, Ap, vtemp); } + else + { + N_VScale(ONE, Ap, vtemp); + SUNCheckLastErrNoRet(); + } /* Apply b-scaling: Ap = sb P1_inv A P2_inv sx_inv p */ - if (scale_b) { N_VProd(sb, vtemp, Ap); } - else { N_VScale(ONE, vtemp, Ap); } + if (scale_b) + { + N_VProd(sb, vtemp, Ap); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp, Ap); + SUNCheckLastErrNoRet(); + } /* Calculate alpha = / */ - alpha = ((beta_denom / N_VDotProd(Ap, r_star))); + alpha = N_VDotProd(Ap, r_star); + SUNCheckLastErrNoRet(); + alpha = beta_denom / alpha; /* Update q = r - alpha*Ap = r - alpha*(sb P1_inv A P2_inv sx_inv p) */ N_VLinearSum(ONE, r, -alpha, Ap, q); + SUNCheckLastErrNoRet(); /* Generate u = A-tilde q */ /* Apply x-scaling: vtemp = sx_inv q */ - if (scale_x) { N_VDiv(q, sx, vtemp); } - else { N_VScale(ONE, q, vtemp); } + if (scale_x) + { + N_VDiv(q, sx, vtemp); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, q, vtemp); + SUNCheckLastErrNoRet(); + } /* Apply right preconditioner: vtemp = P2_inv sx_inv q */ if (preOnRight) { N_VScale(ONE, vtemp, u); - ier = psolve(P_data, u, vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, u, vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } /* Apply A: u = A P2_inv sx_inv u */ - ier = atimes(A_data, vtemp, u); - if (ier != 0) + status = atimes(A_data, vtemp, u); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } @@ -595,29 +603,49 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (preOnLeft) { - ier = psolve(P_data, u, vtemp, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, u, vtemp, delta, SUN_PREC_LEFT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, u, vtemp); } + else + { + N_VScale(ONE, u, vtemp); + SUNCheckLastErrNoRet(); + } /* Apply b-scaling: u = sb P1_inv A P2_inv sx_inv u */ - if (scale_b) { N_VProd(sb, vtemp, u); } - else { N_VScale(ONE, vtemp, u); } + if (scale_b) + { + N_VProd(sb, vtemp, u); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp, u); + SUNCheckLastErrNoRet(); + } /* Calculate omega = / */ omega_denom = N_VDotProd(u, u); + SUNCheckLastErrNoRet(); if (omega_denom == ZERO) { omega_denom = ONE; } - omega = (N_VDotProd(u, q) / omega_denom); + omega = N_VDotProd(u, q); + SUNCheckLastErrNoRet(); + omega /= omega_denom; /* Update x = x + alpha*p + omega*q */ - if (l == 0 && *zeroguess) { N_VLinearSum(alpha, p, omega, q, x); } + if (l == 0 && *zeroguess) + { + N_VLinearSum(alpha, p, omega, q, x); + SUNCheckLastErrNoRet(); + } else { cv[0] = ONE; @@ -629,22 +657,18 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, cv[2] = omega; Xv[2] = q; - ier = N_VLinearCombination(3, cv, Xv, x); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(3, cv, Xv, x)); } /* Update the residual r = q - omega*u */ N_VLinearSum(ONE, q, -omega, u, r); + SUNCheckLastErrNoRet(); /* Set rho = norm(r) and check convergence */ *res_norm = rho = SUNRsqrt(N_VDotProd(r, r)); + SUNCheckLastErrNoRet(); #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO /* print current iteration number and the residual */ @@ -669,7 +693,8 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Update beta = / * alpha / omega */ beta_num = N_VDotProd(r, r_star); - beta = ((beta_num / beta_denom) * (alpha / omega)); + SUNCheckLastErrNoRet(); + beta = ((beta_num / beta_denom) * (alpha / omega)); /* Update p = r + beta*(p - omega*Ap) = beta*p - beta*omega*Ap + r */ cv[0] = beta; @@ -681,13 +706,7 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, cv[2] = ONE; Xv[2] = r; - ier = N_VLinearCombination(3, cv, Xv, p); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(3, cv, Xv, p)); /* udpate beta_denom for next iteration */ beta_denom = beta_num; @@ -699,21 +718,27 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, { /* Apply the x-scaling and right preconditioner: x = P2_inv sx_inv x */ - if (scale_x) { N_VDiv(x, sx, x); } + if (scale_x) + { + N_VDiv(x, sx, x); + SUNCheckLastErrNoRet(); + } if (preOnRight) { - ier = psolve(P_data, x, vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + status = psolve(P_data, x, vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } N_VScale(ONE, vtemp, x); + SUNCheckLastErrNoRet(); } *zeroguess = SUNFALSE; - if (converged == SUNTRUE) { LASTFLAG(S) = SUNLS_SUCCESS; } + if (converged == SUNTRUE) { LASTFLAG(S) = SUN_SUCCESS; } else { LASTFLAG(S) = SUNLS_RES_REDUCED; } return (LASTFLAG(S)); } @@ -728,14 +753,12 @@ int SUNLinSolSolve_SPBCGS(SUNLinearSolver S, SUNMatrix A, N_Vector x, int SUNLinSolNumIters_SPBCGS(SUNLinearSolver S) { /* return the stored 'numiters' value */ - if (S == NULL) { return (-1); } return (SPBCGS_CONTENT(S)->numiters); } sunrealtype SUNLinSolResNorm_SPBCGS(SUNLinearSolver S) { /* return the stored 'resnorm' value */ - if (S == NULL) { return (-ONE); } return (SPBCGS_CONTENT(S)->resnorm); } @@ -748,27 +771,27 @@ N_Vector SUNLinSolResid_SPBCGS(SUNLinearSolver S) sunindextype SUNLinSolLastFlag_SPBCGS(SUNLinearSolver S) { /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_SPBCGS(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_SPBCGS(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); sunindextype liw1, lrw1; if (SPBCGS_CONTENT(S)->vtemp->ops->nvspace) { N_VSpace(SPBCGS_CONTENT(S)->vtemp, &lrw1, &liw1); + SUNCheckLastErrNoRet(); } else { lrw1 = liw1 = 0; } *lenrwLS = lrw1 * 9; *leniwLS = liw1 * 9; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_SPBCGS(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SPBCGS(SUNLinearSolver S) { - if (S == NULL) { return (SUNLS_SUCCESS); } - if (S->content) { /* delete items from within the content structure */ @@ -817,5 +840,5 @@ int SUNLinSolFree_SPBCGS(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/spfgmr/fmod/fsunlinsol_spfgmr_mod.c b/src/sunlinsol/spfgmr/fmod/fsunlinsol_spfgmr_mod.c index f56328e942..033e701618 100644 --- a/src/sunlinsol/spfgmr/fmod/fsunlinsol_spfgmr_mod.c +++ b/src/sunlinsol/spfgmr/fmod/fsunlinsol_spfgmr_mod.c @@ -295,11 +295,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_SPFGMR(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPFGMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_SPFGMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_SPFGMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -309,13 +309,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPFGMR(SUNLinearSolver farg1, void *far SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; void *arg2 = (void *) 0 ; SUNATimesFn arg3 = (SUNATimesFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNATimesFn)(farg3); - result = (int)SUNLinSolSetATimes_SPFGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetATimes_SPFGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -326,14 +326,14 @@ SWIGEXPORT int _wrap_FSUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver farg1, v void *arg2 = (void *) 0 ; SUNPSetupFn arg3 = (SUNPSetupFn) 0 ; SUNPSolveFn arg4 = (SUNPSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNPSetupFn)(farg3); arg4 = (SUNPSolveFn)(farg4); - result = (int)SUNLinSolSetPreconditioner_SPFGMR(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetPreconditioner_SPFGMR(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -343,13 +343,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver farg1, N SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; N_Vector arg2 = (N_Vector) 0 ; N_Vector arg3 = (N_Vector) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (N_Vector)(farg2); arg3 = (N_Vector)(farg3); - result = (int)SUNLinSolSetScalingVectors_SPFGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetScalingVectors_SPFGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -358,12 +358,12 @@ SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver farg1, int co int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSolSetZeroGuess_SPFGMR(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetZeroGuess_SPFGMR(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -455,13 +455,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPFGMR(SUNLinearSolver farg1, long *farg2, SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_SPFGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_SPFGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -469,11 +469,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPFGMR(SUNLinearSolver farg1, long *farg2, SWIGEXPORT int _wrap_FSUNLinSolFree_SPFGMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_SPFGMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_SPFGMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c b/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c index 12db0d249e..41c03f0b44 100644 --- a/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c +++ b/src/sunlinsol/spfgmr/sunlinsol_spfgmr.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -50,6 +50,7 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_SPFGMR content; @@ -64,18 +65,15 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, if (maxl <= 0) { maxl = SUNSPFGMR_MAXL_DEFAULT; } /* check that the supplied N_Vector supports all requisite operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvlinearsum == NULL) || (y->ops->nvconst == NULL) || - (y->ops->nvprod == NULL) || (y->ops->nvdiv == NULL) || - (y->ops->nvscale == NULL) || (y->ops->nvdotprod == NULL)) - { - return (NULL); - } + SUNAssertNull((y->ops->nvclone) && (y->ops->nvdestroy) && + (y->ops->nvlinearsum) && (y->ops->nvconst) && (y->ops->nvprod) && + (y->ops->nvdiv) && (y->ops->nvscale) && (y->ops->nvdotprod), + SUN_ERR_ARG_INCOMPATIBLE); /* Create linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_SPFGMR; @@ -97,11 +95,7 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, /* Create content */ content = NULL; content = (SUNLinearSolverContent_SPFGMR)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -140,18 +134,9 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, /* Allocate content */ content->xcor = N_VClone(y); - if (content->xcor == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->vtemp = N_VClone(y); - if (content->vtemp == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); return (S); } @@ -161,7 +146,7 @@ SUNLinearSolver SUNLinSol_SPFGMR(N_Vector y, int pretype, int maxl, * one of SUN_PREC_LEFT, SUN_PREC_RIGHT or SUN_PREC_BOTH; otherwise turns off */ -int SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype) +SUNErrCode SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype) { /* Check for legal pretype */ pretype = ((pretype == SUN_PREC_LEFT) || (pretype == SUN_PREC_RIGHT) || @@ -169,49 +154,40 @@ int SUNLinSol_SPFGMRSetPrecType(SUNLinearSolver S, int pretype) ? SUN_PREC_RIGHT : SUN_PREC_NONE; - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Set pretype */ SPFGMR_CONTENT(S)->pretype = pretype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the type of Gram-Schmidt orthogonalization for SPFGMR to use */ -int SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, int gstype) +SUNErrCode SUNLinSol_SPFGMRSetGSType(SUNLinearSolver S, int gstype) { - /* Check for legal gstype */ - if ((gstype != SUN_MODIFIED_GS) && (gstype != SUN_CLASSICAL_GS)) - { - return (SUNLS_ILL_INPUT); - } + SUNFunctionBegin(S->sunctx); - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + /* Check for legal gstype */ + SUNAssert(gstype == SUN_MODIFIED_GS || gstype == SUN_CLASSICAL_GS, + SUN_ERR_ARG_OUTOFRANGE); /* Set pretype */ SPFGMR_CONTENT(S)->gstype = gstype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the maximum number of FGMRES restarts to allow */ -int SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) +SUNErrCode SUNLinSol_SPFGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) { /* Illegal maxrs implies use of default value */ if (maxrs < 0) { maxrs = SUNSPFGMR_MAXRS_DEFAULT; } - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Set max_restarts */ SPFGMR_CONTENT(S)->max_restarts = maxrs; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* @@ -230,13 +206,13 @@ SUNLinearSolver_ID SUNLinSolGetID_SPFGMR(SUNLinearSolver S) return (SUNLINEARSOLVER_SPFGMR); } -int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) { + SUNFunctionBegin(S->sunctx); int k; SUNLinearSolverContent_SPFGMR content; /* set shortcut to SPFGMR memory structure */ - if (S == NULL) { return (SUNLS_MEM_NULL); } content = SPFGMR_CONTENT(S); /* ensure valid options */ @@ -245,11 +221,7 @@ int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) content->max_restarts = SUNSPFGMR_MAXRS_DEFAULT; } - if (content->ATimes == NULL) - { - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(content->ATimes, SUN_ERR_ARG_CORRUPT); if ((content->pretype != SUN_PREC_LEFT) && (content->pretype != SUN_PREC_RIGHT) && (content->pretype != SUN_PREC_BOTH)) @@ -257,11 +229,8 @@ int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) content->pretype = SUN_PREC_NONE; } - if ((content->pretype != SUN_PREC_NONE) && (content->Psolve == NULL)) - { - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert((content->pretype == SUN_PREC_NONE) || (content->Psolve != NULL), + SUN_ERR_ARG_CORRUPT); /* allocate solver-specific memory (where the size depends on the choice of maxl) here */ @@ -270,22 +239,14 @@ int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) if (content->V == NULL) { content->V = N_VCloneVectorArray(content->maxl + 1, content->vtemp); - if (content->V == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNCheckLastErr(); } /* Preconditioned basis vectors */ if (content->Z == NULL) { content->Z = N_VCloneVectorArray(content->maxl + 1, content->vtemp); - if (content->Z == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNCheckLastErr(); } /* Hessenberg matrix Hes */ @@ -293,21 +254,13 @@ int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) { content->Hes = (sunrealtype**)malloc((content->maxl + 1) * sizeof(sunrealtype*)); - if (content->Hes == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Hes, SUN_ERR_MALLOC_FAIL); for (k = 0; k <= content->maxl; k++) { content->Hes[k] = NULL; content->Hes[k] = (sunrealtype*)malloc(content->maxl * sizeof(sunrealtype)); - if (content->Hes[k] == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Hes[k], SUN_ERR_MALLOC_FAIL); } } @@ -316,103 +269,85 @@ int SUNLinSolInitialize_SPFGMR(SUNLinearSolver S) { content->givens = (sunrealtype*)malloc(2 * content->maxl * sizeof(sunrealtype)); - if (content->givens == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->givens, SUN_ERR_MALLOC_FAIL); } /* y and g vectors */ if (content->yg == NULL) { content->yg = (sunrealtype*)malloc((content->maxl + 1) * sizeof(sunrealtype)); - if (content->yg == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->yg, SUN_ERR_MALLOC_FAIL); } /* cv vector for fused vector ops */ if (content->cv == NULL) { content->cv = (sunrealtype*)malloc((content->maxl + 1) * sizeof(sunrealtype)); - if (content->cv == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->cv, SUN_ERR_MALLOC_FAIL); } /* Xv vector for fused vector ops */ if (content->Xv == NULL) { content->Xv = (N_Vector*)malloc((content->maxl + 1) * sizeof(N_Vector)); - if (content->Xv == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Xv, SUN_ERR_MALLOC_FAIL); } /* return with success */ - content->last_flag = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* ATData, SUNATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes_SPFGMR(SUNLinearSolver S, void* ATData, + SUNATimesFn ATimes) { /* set function pointers to integrator-supplied ATimes routine and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPFGMR_CONTENT(S)->ATimes = ATimes; SPFGMR_CONTENT(S)->ATData = ATData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, void* PData, - SUNPSetupFn Psetup, SUNPSolveFn Psolve) +SUNErrCode SUNLinSolSetPreconditioner_SPFGMR(SUNLinearSolver S, void* PData, + SUNPSetupFn Psetup, + SUNPSolveFn Psolve) { /* set function pointers to integrator-supplied Psetup and PSolve routines and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPFGMR_CONTENT(S)->Psetup = Psetup; SPFGMR_CONTENT(S)->Psolve = Psolve; SPFGMR_CONTENT(S)->PData = PData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, N_Vector s1, N_Vector s2) +SUNErrCode SUNLinSolSetScalingVectors_SPFGMR(SUNLinearSolver S, N_Vector s1, + N_Vector s2) { /* set N_Vector pointers to integrator-supplied scaling vectors, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPFGMR_CONTENT(S)->s1 = s1; SPFGMR_CONTENT(S)->s2 = s2; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, sunbooleantype onoff) +SUNErrCode SUNLinSolSetZeroGuess_SPFGMR(SUNLinearSolver S, sunbooleantype onoff) { /* set flag indicating a zero initial guess */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPFGMR_CONTENT(S)->zeroguess = onoff; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A) { - int ier; + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + + int status; SUNPSetupFn Psetup; void* PData; /* Set shortcuts to SPFGMR memory structures */ - if (S == NULL) { return (SUNLS_MEM_NULL); } Psetup = SPFGMR_CONTENT(S)->Psetup; PData = SPFGMR_CONTENT(S)->PData; @@ -420,32 +355,39 @@ int SUNLinSolSetup_SPFGMR(SUNLinearSolver S, SUNMatrix A) Psetup routine exists, call that here */ if (Psetup != NULL) { - ier = Psetup(PData); - if (ier != 0) + status = Psetup(PData); + if (status != 0) { - LASTFLAG(S) = (ier < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; return (LASTFLAG(S)); } } /* return with success */ - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype delta) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + /* local data and shortcut variables */ N_Vector *V, *Z, xcor, vtemp, s1, s2; sunrealtype **Hes, *givens, *yg, *res_norm; sunrealtype beta, rotation_product, r_norm, s_product, rho; sunbooleantype preOnRight, scale1, scale2, converged; sunbooleantype* zeroguess; - int i, j, k, l, l_max, krydim, ier, ntries, max_restarts, gstype; + int i, j, k, l, l_max, krydim, ntries, max_restarts, gstype; int* nli; void *A_data, *P_data; SUNATimesFn atimes; SUNPSolveFn psolve; + int status; /* local shortcuts for fused vector operations */ sunrealtype* cv; @@ -455,7 +397,6 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, krydim = 0; /* Make local shorcuts to solver variables. */ - if (S == NULL) { return (SUNLS_MEM_NULL); } l_max = SPFGMR_CONTENT(S)->maxl; max_restarts = SPFGMR_CONTENT(S)->max_restarts; gstype = SPFGMR_CONTENT(S)->gstype; @@ -496,41 +437,47 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, #endif /* Check if Atimes function has been set */ - if (atimes == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(atimes, SUN_ERR_ARG_CORRUPT); /* If preconditioning, check if psolve has been set */ - if (preOnRight && psolve == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssertNoRet(!preOnRight || psolve, SUN_ERR_ARG_CORRUPT); /* Set vtemp and V[0] to initial (unscaled) residual r_0 = b - A*x_0 */ - if (*zeroguess) { N_VScale(ONE, b, vtemp); } + if (*zeroguess) + { + N_VScale(ONE, b, vtemp); + SUNCheckLastErrNoRet(); + } else { - ier = atimes(A_data, x, vtemp); - if (ier != 0) + status = atimes(A_data, x, vtemp); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } N_VLinearSum(ONE, b, -ONE, vtemp, vtemp); + SUNCheckLastErrNoRet(); } /* Apply left scaling to vtemp = r_0 to fill V[0]. */ - if (scale1) { N_VProd(s1, vtemp, V[0]); } - else { N_VScale(ONE, vtemp, V[0]); } + if (scale1) + { + N_VProd(s1, vtemp, V[0]); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp, V[0]); + SUNCheckLastErrNoRet(); + } /* Set r_norm = beta to L2 norm of V[0] = s1 r_0, and return if small */ - *res_norm = r_norm = beta = SUNRsqrt(N_VDotProd(V[0], V[0])); + r_norm = N_VDotProd(V[0], V[0]); + SUNCheckLastErrNoRet(); + *res_norm = r_norm = beta = SUNRsqrt(r_norm); #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO /* print initial residual */ @@ -548,7 +495,7 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (r_norm <= delta) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -557,6 +504,7 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Set xcor = 0. */ N_VConst(ZERO, xcor); + SUNCheckLastErrNoRet(); /* Begin outer iterations: up to (max_restarts + 1) attempts. */ for (ntries = 0; ntries <= max_restarts; ntries++) @@ -569,6 +517,7 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, } rotation_product = ONE; N_VScale(ONE / r_norm, V[0], V[0]); + SUNCheckLastErrNoRet(); /* Inner loop: generate Krylov sequence and Arnoldi basis. */ for (l = 0; l < l_max; l++) @@ -580,54 +529,60 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Generate A-tilde V[l], where A-tilde = s1 A P_inv s2_inv. */ /* Apply right scaling: vtemp = s2_inv V[l]. */ - if (scale2) { N_VDiv(V[l], s2, vtemp); } - else { N_VScale(ONE, V[l], vtemp); } + if (scale2) + { + N_VDiv(V[l], s2, vtemp); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, V[l], vtemp); + SUNCheckLastErrNoRet(); + } /* Apply right preconditioner: vtemp = Z[l] = P_inv s2_inv V[l]. */ if (preOnRight) { N_VScale(ONE, vtemp, V[l + 1]); - ier = psolve(P_data, V[l + 1], vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, V[l + 1], vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } N_VScale(ONE, vtemp, Z[l]); + SUNCheckLastErrNoRet(); /* Apply A: V[l+1] = A P_inv s2_inv V[l]. */ - ier = atimes(A_data, vtemp, V[l + 1]); - if (ier != 0) + status = atimes(A_data, vtemp, V[l + 1]); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } /* Apply left scaling: V[l+1] = s1 A P_inv s2_inv V[l]. */ - if (scale1) { N_VProd(s1, V[l + 1], V[l + 1]); } + if (scale1) + { + N_VProd(s1, V[l + 1], V[l + 1]); + SUNCheckLastErrNoRet(); + } /* Orthogonalize V[l+1] against previous V[i]: V[l+1] = w_tilde. */ if (gstype == SUN_CLASSICAL_GS) { - if (SUNClassicalGS(V, Hes, l + 1, l_max, &(Hes[l + 1][l]), cv, Xv) != 0) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_GS_FAIL; - return (LASTFLAG(S)); - } + SUNCheckCallNoRet( + SUNClassicalGS(V, Hes, l + 1, l_max, &(Hes[l + 1][l]), cv, Xv)); } else { - if (SUNModifiedGS(V, Hes, l + 1, l_max, &(Hes[l + 1][l])) != 0) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_GS_FAIL; - return (LASTFLAG(S)); - } + SUNCheckCallNoRet(SUNModifiedGS(V, Hes, l + 1, l_max, &(Hes[l + 1][l]))); } /* Update the QR factorization of Hes. */ @@ -663,6 +618,7 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Normalize V[l+1] with norm value from the Gram-Schmidt routine. */ N_VScale(ONE / Hes[l + 1][l], V[l + 1], V[l + 1]); + SUNCheckLastErrNoRet(); } /* Inner loop is done. Compute the new correction vector xcor. */ @@ -686,21 +642,23 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, cv[k + 1] = yg[k]; Xv[k + 1] = Z[k]; } - ier = N_VLinearCombination(krydim + 1, cv, Xv, xcor); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(krydim + 1, cv, Xv, xcor)); /* If converged, construct the final solution vector x and return. */ if (converged) { - if (*zeroguess) { N_VScale(ONE, xcor, x); } - else { N_VLinearSum(ONE, x, ONE, xcor, x); } + if (*zeroguess) + { + N_VScale(ONE, xcor, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, ONE, xcor, x); + SUNCheckLastErrNoRet(); + } *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -727,13 +685,7 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, cv[k] = yg[k]; Xv[k] = V[k]; } - ier = N_VLinearCombination(krydim + 1, cv, Xv, V[0]); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(krydim + 1, cv, Xv, V[0])); } /* Failed to converge, even after allowed restarts. @@ -741,8 +693,16 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, and return x anyway. Otherwise return failure flag. */ if (rho < beta) { - if (*zeroguess) { N_VScale(ONE, xcor, x); } - else { N_VLinearSum(ONE, x, ONE, xcor, x); } + if (*zeroguess) + { + N_VScale(ONE, xcor, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, ONE, xcor, x); + SUNCheckLastErrNoRet(); + } *zeroguess = SUNFALSE; LASTFLAG(S) = SUNLS_RES_REDUCED; return (LASTFLAG(S)); @@ -755,51 +715,47 @@ int SUNLinSolSolve_SPFGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, int SUNLinSolNumIters_SPFGMR(SUNLinearSolver S) { - /* return the stored 'numiters' value */ - if (S == NULL) { return (-1); } return (SPFGMR_CONTENT(S)->numiters); } sunrealtype SUNLinSolResNorm_SPFGMR(SUNLinearSolver S) { - /* return the stored 'resnorm' value */ - if (S == NULL) { return (-ONE); } return (SPFGMR_CONTENT(S)->resnorm); } N_Vector SUNLinSolResid_SPFGMR(SUNLinearSolver S) { - /* return the stored 'vtemp' vector */ return (SPFGMR_CONTENT(S)->vtemp); } sunindextype SUNLinSolLastFlag_SPFGMR(SUNLinearSolver S) { - /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_SPFGMR(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_SPFGMR(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); int maxl; sunindextype liw1, lrw1; maxl = SPFGMR_CONTENT(S)->maxl; if (SPFGMR_CONTENT(S)->vtemp->ops->nvspace) { N_VSpace(SPFGMR_CONTENT(S)->vtemp, &lrw1, &liw1); + SUNCheckLastErrNoRet(); } else { lrw1 = liw1 = 0; } *lenrwLS = lrw1 * (2 * maxl + 4) + maxl * (maxl + 5) + 2; *leniwLS = liw1 * (2 * maxl + 4); - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_SPFGMR(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SPFGMR(SUNLinearSolver S) { int k; - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return SUN_SUCCESS; } if (S->content) { @@ -867,5 +823,5 @@ int SUNLinSolFree_SPFGMR(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/spgmr/fmod/fsunlinsol_spgmr_mod.c b/src/sunlinsol/spgmr/fmod/fsunlinsol_spgmr_mod.c index 2f9165a238..8e31709783 100644 --- a/src/sunlinsol/spgmr/fmod/fsunlinsol_spgmr_mod.c +++ b/src/sunlinsol/spgmr/fmod/fsunlinsol_spgmr_mod.c @@ -295,11 +295,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_SPGMR(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPGMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_SPGMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_SPGMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -309,13 +309,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPGMR(SUNLinearSolver farg1, void *farg SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; void *arg2 = (void *) 0 ; SUNATimesFn arg3 = (SUNATimesFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNATimesFn)(farg3); - result = (int)SUNLinSolSetATimes_SPGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetATimes_SPGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -326,14 +326,14 @@ SWIGEXPORT int _wrap_FSUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver farg1, vo void *arg2 = (void *) 0 ; SUNPSetupFn arg3 = (SUNPSetupFn) 0 ; SUNPSolveFn arg4 = (SUNPSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNPSetupFn)(farg3); arg4 = (SUNPSolveFn)(farg4); - result = (int)SUNLinSolSetPreconditioner_SPGMR(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetPreconditioner_SPGMR(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -343,13 +343,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver farg1, N_ SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; N_Vector arg2 = (N_Vector) 0 ; N_Vector arg3 = (N_Vector) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (N_Vector)(farg2); arg3 = (N_Vector)(farg3); - result = (int)SUNLinSolSetScalingVectors_SPGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetScalingVectors_SPGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -358,12 +358,12 @@ SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver farg1, int con int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSolSetZeroGuess_SPGMR(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetZeroGuess_SPGMR(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -455,13 +455,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPGMR(SUNLinearSolver farg1, long *farg2, l SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_SPGMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_SPGMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -469,11 +469,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPGMR(SUNLinearSolver farg1, long *farg2, l SWIGEXPORT int _wrap_FSUNLinSolFree_SPGMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_SPGMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_SPGMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/spgmr/sunlinsol_spgmr.c b/src/sunlinsol/spgmr/sunlinsol_spgmr.c index 4d23c5fa08..bff6277667 100644 --- a/src/sunlinsol/spgmr/sunlinsol_spgmr.c +++ b/src/sunlinsol/spgmr/sunlinsol_spgmr.c @@ -19,7 +19,7 @@ #include #include -#include +#include #include #include @@ -50,6 +50,7 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_SPGMR content; @@ -62,18 +63,15 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, if (maxl <= 0) { maxl = SUNSPGMR_MAXL_DEFAULT; } /* check that the supplied N_Vector supports all requisite operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvlinearsum == NULL) || (y->ops->nvconst == NULL) || - (y->ops->nvprod == NULL) || (y->ops->nvdiv == NULL) || - (y->ops->nvscale == NULL) || (y->ops->nvdotprod == NULL)) - { - return (NULL); - } + SUNAssertNull((y->ops->nvclone) && (y->ops->nvdestroy) && + (y->ops->nvlinearsum) && (y->ops->nvconst) && (y->ops->nvprod) && + (y->ops->nvdiv) && (y->ops->nvscale) && (y->ops->nvdotprod), + SUN_ERR_ARG_OUTOFRANGE); /* Create linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_SPGMR; @@ -95,11 +93,7 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, /* Create content */ content = NULL; content = (SUNLinearSolverContent_SPGMR)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -137,18 +131,9 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, /* Allocate content */ content->xcor = N_VClone(y); - if (content->xcor == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->vtemp = N_VClone(y); - if (content->vtemp == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); return (S); } @@ -157,58 +142,47 @@ SUNLinearSolver SUNLinSol_SPGMR(N_Vector y, int pretype, int maxl, * Function to set the type of preconditioning for SPGMR to use */ -int SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, int pretype) +SUNErrCode SUNLinSol_SPGMRSetPrecType(SUNLinearSolver S, int pretype) { + SUNFunctionBegin(S->sunctx); /* Check for legal pretype */ - if ((pretype != SUN_PREC_NONE) && (pretype != SUN_PREC_LEFT) && - (pretype != SUN_PREC_RIGHT) && (pretype != SUN_PREC_BOTH)) - { - return (SUNLS_ILL_INPUT); - } - - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNAssert((pretype == SUN_PREC_NONE) || (pretype == SUN_PREC_LEFT) || + (pretype == SUN_PREC_RIGHT) || (pretype == SUN_PREC_BOTH), + SUN_ERR_ARG_OUTOFRANGE); /* Set pretype */ SPGMR_CONTENT(S)->pretype = pretype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the type of Gram-Schmidt orthogonalization for SPGMR to use */ -int SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, int gstype) +SUNErrCode SUNLinSol_SPGMRSetGSType(SUNLinearSolver S, int gstype) { + SUNFunctionBegin(S->sunctx); /* Check for legal gstype */ - if ((gstype != SUN_MODIFIED_GS) && (gstype != SUN_CLASSICAL_GS)) - { - return (SUNLS_ILL_INPUT); - } - - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNAssert(gstype == SUN_MODIFIED_GS || gstype == SUN_CLASSICAL_GS, + SUN_ERR_ARG_OUTOFRANGE); /* Set pretype */ SPGMR_CONTENT(S)->gstype = gstype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the maximum number of GMRES restarts to allow */ -int SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) +SUNErrCode SUNLinSol_SPGMRSetMaxRestarts(SUNLinearSolver S, int maxrs) { /* Illegal maxrs implies use of default value */ if (maxrs < 0) { maxrs = SUNSPGMR_MAXRS_DEFAULT; } - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Set max_restarts */ SPGMR_CONTENT(S)->max_restarts = maxrs; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* @@ -227,13 +201,13 @@ SUNLinearSolver_ID SUNLinSolGetID_SPGMR(SUNLinearSolver S) return (SUNLINEARSOLVER_SPGMR); } -int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SPGMR(SUNLinearSolver S) { int k; SUNLinearSolverContent_SPGMR content; + SUNFunctionBegin(S->sunctx); /* set shortcut to SPGMR memory structure */ - if (S == NULL) { return (SUNLS_MEM_NULL); } content = SPGMR_CONTENT(S); /* ensure valid options */ @@ -242,11 +216,7 @@ int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) content->max_restarts = SUNSPGMR_MAXRS_DEFAULT; } - if (content->ATimes == NULL) - { - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(content->ATimes, SUN_ERR_ARG_CORRUPT); if ((content->pretype != SUN_PREC_LEFT) && (content->pretype != SUN_PREC_RIGHT) && (content->pretype != SUN_PREC_BOTH)) @@ -254,11 +224,8 @@ int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) content->pretype = SUN_PREC_NONE; } - if ((content->pretype != SUN_PREC_NONE) && (content->Psolve == NULL)) - { - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert((content->pretype == SUN_PREC_NONE) || (content->Psolve != NULL), + SUN_ERR_ARG_CORRUPT); /* allocate solver-specific memory (where the size depends on the choice of maxl) here */ @@ -267,11 +234,7 @@ int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) if (content->V == NULL) { content->V = N_VCloneVectorArray(content->maxl + 1, content->vtemp); - if (content->V == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNCheckLastErr(); } /* Hessenberg matrix Hes */ @@ -279,21 +242,13 @@ int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) { content->Hes = (sunrealtype**)malloc((content->maxl + 1) * sizeof(sunrealtype*)); - if (content->Hes == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Hes, SUN_ERR_MALLOC_FAIL); for (k = 0; k <= content->maxl; k++) { content->Hes[k] = NULL; content->Hes[k] = (sunrealtype*)malloc(content->maxl * sizeof(sunrealtype)); - if (content->Hes[k] == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Hes[k], SUN_ERR_MALLOC_FAIL); } } @@ -302,147 +257,130 @@ int SUNLinSolInitialize_SPGMR(SUNLinearSolver S) { content->givens = (sunrealtype*)malloc(2 * content->maxl * sizeof(sunrealtype)); - if (content->givens == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->givens, SUN_ERR_MALLOC_FAIL); } /* y and g vectors */ if (content->yg == NULL) { content->yg = (sunrealtype*)malloc((content->maxl + 1) * sizeof(sunrealtype)); - if (content->yg == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->yg, SUN_ERR_MALLOC_FAIL); } /* cv vector for fused vector ops */ if (content->cv == NULL) { content->cv = (sunrealtype*)malloc((content->maxl + 1) * sizeof(sunrealtype)); - if (content->cv == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->cv, SUN_ERR_MALLOC_FAIL); } /* Xv vector for fused vector ops */ if (content->Xv == NULL) { content->Xv = (N_Vector*)malloc((content->maxl + 1) * sizeof(N_Vector)); - if (content->Xv == NULL) - { - content->last_flag = SUNLS_MEM_FAIL; - return (SUNLS_MEM_FAIL); - } + SUNAssert(content->Xv, SUN_ERR_MALLOC_FAIL); } - /* return with success */ - content->last_flag = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* ATData, SUNATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes_SPGMR(SUNLinearSolver S, void* ATData, + SUNATimesFn ATimes) { /* set function pointers to integrator-supplied ATimes routine and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPGMR_CONTENT(S)->ATimes = ATimes; SPGMR_CONTENT(S)->ATData = ATData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, void* PData, - SUNPSetupFn Psetup, SUNPSolveFn Psolve) +SUNErrCode SUNLinSolSetPreconditioner_SPGMR(SUNLinearSolver S, void* PData, + SUNPSetupFn Psetup, + SUNPSolveFn Psolve) { /* set function pointers to integrator-supplied Psetup and PSolve routines and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPGMR_CONTENT(S)->Psetup = Psetup; SPGMR_CONTENT(S)->Psolve = Psolve; SPGMR_CONTENT(S)->PData = PData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, N_Vector s1, N_Vector s2) +SUNErrCode SUNLinSolSetScalingVectors_SPGMR(SUNLinearSolver S, N_Vector s1, + N_Vector s2) { /* set N_Vector pointers to integrator-supplied scaling vectors, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPGMR_CONTENT(S)->s1 = s1; SPGMR_CONTENT(S)->s2 = s2; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, sunbooleantype onff) +SUNErrCode SUNLinSolSetZeroGuess_SPGMR(SUNLinearSolver S, sunbooleantype onff) { /* set flag indicating a zero initial guess */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPGMR_CONTENT(S)->zeroguess = onff; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } int SUNLinSolSetup_SPGMR(SUNLinearSolver S, SUNMatrix A) { - int ier; - SUNPSetupFn Psetup; - void* PData; + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + + int status = SUN_SUCCESS; /* Set shortcuts to SPGMR memory structures */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - Psetup = SPGMR_CONTENT(S)->Psetup; - PData = SPGMR_CONTENT(S)->PData; + SUNPSetupFn Psetup = SPGMR_CONTENT(S)->Psetup; + void* PData = SPGMR_CONTENT(S)->PData; /* no solver-specific setup is required, but if user-supplied Psetup routine exists, call that here */ if (Psetup != NULL) { - ier = Psetup(PData); - if (ier != 0) + status = Psetup(PData); + if (status != 0) { - LASTFLAG(S) = (ier < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; return (LASTFLAG(S)); } } /* return with success */ - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype delta) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + /* local data and shortcut variables */ N_Vector *V, xcor, vtemp, s1, s2; sunrealtype **Hes, *givens, *yg, *res_norm; sunrealtype beta, rotation_product, r_norm, s_product, rho; sunbooleantype preOnLeft, preOnRight, scale2, scale1, converged; sunbooleantype* zeroguess; - int i, j, k, l, l_plus_1, l_max, krydim, ier, ntries, max_restarts, gstype; + int i, j, k, l, l_plus_1, l_max, krydim, ntries, max_restarts, gstype; int* nli; void *A_data, *P_data; SUNATimesFn atimes; SUNPSolveFn psolve; - - /* local shortcuts for fused vector operations */ sunrealtype* cv; N_Vector* Xv; + int status; /* Initialize some variables */ l_plus_1 = 0; krydim = 0; /* Make local shorcuts to solver variables. */ - if (S == NULL) { return (SUNLS_MEM_NULL); } l_max = SPGMR_CONTENT(S)->maxl; max_restarts = SPGMR_CONTENT(S)->max_restarts; gstype = SPGMR_CONTENT(S)->gstype; @@ -483,55 +421,67 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, #endif /* Check if Atimes function has been set */ - if (atimes == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(atimes, SUN_ERR_ARG_CORRUPT); /* If preconditioning, check if psolve has been set */ - if ((preOnLeft || preOnRight) && psolve == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert(!(preOnLeft || preOnRight) || psolve, SUN_ERR_ARG_CORRUPT); /* Set vtemp and V[0] to initial (unscaled) residual r_0 = b - A*x_0 */ - if (*zeroguess) { N_VScale(ONE, b, vtemp); } + if (*zeroguess) + { + N_VScale(ONE, b, vtemp); + SUNCheckLastErrNoRet(); + } else { - ier = atimes(A_data, x, vtemp); - if (ier != 0) + status = atimes(A_data, x, vtemp); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } N_VLinearSum(ONE, b, -ONE, vtemp, vtemp); + SUNCheckLastErrNoRet(); } N_VScale(ONE, vtemp, V[0]); + SUNCheckLastErrNoRet(); /* Apply left preconditioner and left scaling to V[0] = r_0 */ if (preOnLeft) { - ier = psolve(P_data, V[0], vtemp, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, V[0], vtemp, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, V[0], vtemp); } + else + { + N_VScale(ONE, V[0], vtemp); + SUNCheckLastErrNoRet(); + } - if (scale1) { N_VProd(s1, vtemp, V[0]); } - else { N_VScale(ONE, vtemp, V[0]); } + if (scale1) + { + N_VProd(s1, vtemp, V[0]); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp, V[0]); + SUNCheckLastErrNoRet(); + } /* Set r_norm = beta to L2 norm of V[0] = s1 P1_inv r_0, and return if small */ - *res_norm = r_norm = beta = SUNRsqrt(N_VDotProd(V[0], V[0])); + r_norm = N_VDotProd(V[0], V[0]); + SUNCheckLastErrNoRet(); + *res_norm = r_norm = beta = SUNRsqrt(r_norm); #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO /* print initial residual */ @@ -549,7 +499,7 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, if (r_norm <= delta) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -558,6 +508,7 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, /* Set xcor = 0 */ N_VConst(ZERO, xcor); + SUNCheckLastErrNoRet(); /* Begin outer iterations: up to (max_restarts + 1) attempts */ for (ntries = 0; ntries <= max_restarts; ntries++) @@ -571,6 +522,7 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, rotation_product = ONE; N_VScale(ONE / r_norm, V[0], V[0]); + SUNCheckLastErrNoRet(); /* Inner loop: generate Krylov sequence and Arnoldi basis */ for (l = 0; l < l_max; l++) @@ -581,69 +533,82 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, /* Generate A-tilde V[l], where A-tilde = s1 P1_inv A P2_inv s2_inv */ /* Apply right scaling: vtemp = s2_inv V[l] */ - if (scale2) { N_VDiv(V[l], s2, vtemp); } - else { N_VScale(ONE, V[l], vtemp); } + if (scale2) + { + N_VDiv(V[l], s2, vtemp); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, V[l], vtemp); + SUNCheckLastErrNoRet(); + } /* Apply right preconditioner: vtemp = P2_inv s2_inv V[l] */ if (preOnRight) { N_VScale(ONE, vtemp, V[l_plus_1]); - ier = psolve(P_data, V[l_plus_1], vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, V[l_plus_1], vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } /* Apply A: V[l+1] = A P2_inv s2_inv V[l] */ - ier = atimes(A_data, vtemp, V[l_plus_1]); - if (ier != 0) + status = atimes(A_data, vtemp, V[l_plus_1]); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } /* Apply left preconditioning: vtemp = P1_inv A P2_inv s2_inv V[l] */ if (preOnLeft) { - ier = psolve(P_data, V[l_plus_1], vtemp, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, V[l_plus_1], vtemp, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, V[l_plus_1], vtemp); } + else + { + N_VScale(ONE, V[l_plus_1], vtemp); + SUNCheckLastErrNoRet(); + } /* Apply left scaling: V[l+1] = s1 P1_inv A P2_inv s2_inv V[l] */ - if (scale1) { N_VProd(s1, vtemp, V[l_plus_1]); } - else { N_VScale(ONE, vtemp, V[l_plus_1]); } + if (scale1) + { + N_VProd(s1, vtemp, V[l_plus_1]); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp, V[l_plus_1]); + SUNCheckLastErrNoRet(); + } /* Orthogonalize V[l+1] against previous V[i]: V[l+1] = w_tilde */ if (gstype == SUN_CLASSICAL_GS) { - if (SUNClassicalGS(V, Hes, l_plus_1, l_max, &(Hes[l_plus_1][l]), cv, - Xv) != 0) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_GS_FAIL; - return (LASTFLAG(S)); - } + SUNCheckCallNoRet( + SUNClassicalGS(V, Hes, l_plus_1, l_max, &(Hes[l_plus_1][l]), cv, Xv)); } else { - if (SUNModifiedGS(V, Hes, l_plus_1, l_max, &(Hes[l_plus_1][l])) != 0) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_GS_FAIL; - return (LASTFLAG(S)); - } + SUNCheckCallNoRet( + SUNModifiedGS(V, Hes, l_plus_1, l_max, &(Hes[l_plus_1][l]))); } /* Update the QR factorization of Hes */ @@ -679,6 +644,7 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, /* Normalize V[l+1] with norm value from the Gram-Schmidt routine */ N_VScale(ONE / Hes[l_plus_1][l], V[l_plus_1], V[l_plus_1]); + SUNCheckLastErrNoRet(); } /* Inner loop is done. Compute the new correction vector xcor */ @@ -702,38 +668,49 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, cv[k + 1] = yg[k]; Xv[k + 1] = V[k]; } - ier = N_VLinearCombination(krydim + 1, cv, Xv, xcor); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(krydim + 1, cv, Xv, xcor)); /* If converged, construct the final solution vector x and return */ if (converged) { /* Apply right scaling and right precond.: vtemp = P2_inv s2_inv xcor */ - if (scale2) { N_VDiv(xcor, s2, xcor); } + if (scale2) + { + N_VDiv(xcor, s2, xcor); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { - ier = psolve(P_data, xcor, vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + status = psolve(P_data, xcor, vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, xcor, vtemp); } + else + { + N_VScale(ONE, xcor, vtemp); + SUNCheckLastErrNoRet(); + } /* Add vtemp to initial x to get final solution x, and return */ - if (*zeroguess) { N_VScale(ONE, vtemp, x); } - else { N_VLinearSum(ONE, x, ONE, vtemp, x); } + if (*zeroguess) + { + N_VScale(ONE, vtemp, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, ONE, vtemp, x); + SUNCheckLastErrNoRet(); + } *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -760,13 +737,7 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, cv[k] = yg[k]; Xv[k] = V[k]; } - ier = N_VLinearCombination(krydim + 1, cv, Xv, V[0]); - if (ier != SUNLS_SUCCESS) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); - } + SUNCheckCallNoRet(N_VLinearCombination(krydim + 1, cv, Xv, V[0])); } /* Failed to converge, even after allowed restarts. @@ -775,22 +746,40 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, if (rho < beta) { /* Apply right scaling and right precond.: vtemp = P2_inv s2_inv xcor */ - if (scale2) { N_VDiv(xcor, s2, xcor); } + if (scale2) + { + N_VDiv(xcor, s2, xcor); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { - ier = psolve(P_data, xcor, vtemp, delta, SUN_PREC_RIGHT); - if (ier != 0) + status = psolve(P_data, xcor, vtemp, delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, xcor, vtemp); } + else + { + N_VScale(ONE, xcor, vtemp); + SUNCheckLastErrNoRet(); + } /* Add vtemp to initial x to get final solution x, and return */ - if (*zeroguess) { N_VScale(ONE, vtemp, x); } - else { N_VLinearSum(ONE, x, ONE, vtemp, x); } + if (*zeroguess) + { + N_VScale(ONE, vtemp, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, ONE, vtemp, x); + SUNCheckLastErrNoRet(); + } *zeroguess = SUNFALSE; LASTFLAG(S) = SUNLS_RES_REDUCED; @@ -804,52 +793,46 @@ int SUNLinSolSolve_SPGMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, int SUNLinSolNumIters_SPGMR(SUNLinearSolver S) { - /* return the stored 'numiters' value */ - if (S == NULL) { return (-1); } return (SPGMR_CONTENT(S)->numiters); } sunrealtype SUNLinSolResNorm_SPGMR(SUNLinearSolver S) { - /* return the stored 'resnorm' value */ - if (S == NULL) { return (-ONE); } return (SPGMR_CONTENT(S)->resnorm); } N_Vector SUNLinSolResid_SPGMR(SUNLinearSolver S) { - /* return the stored 'vtemp' vector */ return (SPGMR_CONTENT(S)->vtemp); } sunindextype SUNLinSolLastFlag_SPGMR(SUNLinearSolver S) { - /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_SPGMR(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_SPGMR(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); int maxl; sunindextype liw1, lrw1; maxl = SPGMR_CONTENT(S)->maxl; if (SPGMR_CONTENT(S)->vtemp->ops->nvspace) { N_VSpace(SPGMR_CONTENT(S)->vtemp, &lrw1, &liw1); + SUNCheckLastErrNoRet(); } else { lrw1 = liw1 = 0; } *lenrwLS = lrw1 * (maxl + 5) + maxl * (maxl + 5) + 2; *leniwLS = liw1 * (maxl + 5); - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_SPGMR(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SPGMR(SUNLinearSolver S) { int k; - if (S == NULL) { return (SUNLS_SUCCESS); } - if (S->content) { /* delete items from within the content structure */ @@ -911,5 +894,5 @@ int SUNLinSolFree_SPGMR(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/sptfqmr/fmod/fsunlinsol_sptfqmr_mod.c b/src/sunlinsol/sptfqmr/fmod/fsunlinsol_sptfqmr_mod.c index 6035841980..2e5ec55831 100644 --- a/src/sunlinsol/sptfqmr/fmod/fsunlinsol_sptfqmr_mod.c +++ b/src/sunlinsol/sptfqmr/fmod/fsunlinsol_sptfqmr_mod.c @@ -281,11 +281,11 @@ SWIGEXPORT int _wrap_FSUNLinSolGetID_SPTFQMR(SUNLinearSolver farg1) { SWIGEXPORT int _wrap_FSUNLinSolInitialize_SPTFQMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolInitialize_SPTFQMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolInitialize_SPTFQMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -295,13 +295,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetATimes_SPTFQMR(SUNLinearSolver farg1, void *fa SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; void *arg2 = (void *) 0 ; SUNATimesFn arg3 = (SUNATimesFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNATimesFn)(farg3); - result = (int)SUNLinSolSetATimes_SPTFQMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetATimes_SPTFQMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -312,14 +312,14 @@ SWIGEXPORT int _wrap_FSUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver farg1, void *arg2 = (void *) 0 ; SUNPSetupFn arg3 = (SUNPSetupFn) 0 ; SUNPSolveFn arg4 = (SUNPSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (void *)(farg2); arg3 = (SUNPSetupFn)(farg3); arg4 = (SUNPSolveFn)(farg4); - result = (int)SUNLinSolSetPreconditioner_SPTFQMR(arg1,arg2,arg3,arg4); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetPreconditioner_SPTFQMR(arg1,arg2,arg3,arg4); + fresult = (SUNErrCode)(result); return fresult; } @@ -329,13 +329,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver farg1, SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; N_Vector arg2 = (N_Vector) 0 ; N_Vector arg3 = (N_Vector) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (N_Vector)(farg2); arg3 = (N_Vector)(farg3); - result = (int)SUNLinSolSetScalingVectors_SPTFQMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetScalingVectors_SPTFQMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -344,12 +344,12 @@ SWIGEXPORT int _wrap_FSUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver farg1, int c int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNLinSolSetZeroGuess_SPTFQMR(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSetZeroGuess_SPTFQMR(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -441,13 +441,13 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPTFQMR(SUNLinearSolver farg1, long *farg2, SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; long *arg2 = (long *) 0 ; long *arg3 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); arg2 = (long *)(farg2); arg3 = (long *)(farg3); - result = (int)SUNLinSolSpace_SPTFQMR(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolSpace_SPTFQMR(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -455,11 +455,11 @@ SWIGEXPORT int _wrap_FSUNLinSolSpace_SPTFQMR(SUNLinearSolver farg1, long *farg2, SWIGEXPORT int _wrap_FSUNLinSolFree_SPTFQMR(SUNLinearSolver farg1) { int fresult ; SUNLinearSolver arg1 = (SUNLinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNLinearSolver)(farg1); - result = (int)SUNLinSolFree_SPTFQMR(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNLinSolFree_SPTFQMR(arg1); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c b/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c index 96ba54bab8..0ffe30b682 100644 --- a/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c +++ b/src/sunlinsol/sptfqmr/sunlinsol_sptfqmr.c @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -49,6 +49,7 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNLinearSolver S; SUNLinearSolverContent_SPTFQMR content; @@ -61,18 +62,15 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, if (maxl <= 0) { maxl = SUNSPTFQMR_MAXL_DEFAULT; } /* check that the supplied N_Vector supports all requisite operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvlinearsum == NULL) || (y->ops->nvconst == NULL) || - (y->ops->nvprod == NULL) || (y->ops->nvdiv == NULL) || - (y->ops->nvscale == NULL) || (y->ops->nvdotprod == NULL)) - { - return (NULL); - } + SUNAssertNull((y->ops->nvclone) && (y->ops->nvdestroy) && + (y->ops->nvlinearsum) && (y->ops->nvconst) && (y->ops->nvprod) && + (y->ops->nvdiv) && (y->ops->nvscale) && (y->ops->nvdotprod), + SUN_ERR_ARG_INCOMPATIBLE); /* Create linear solver */ S = NULL; S = SUNLinSolNewEmpty(sunctx); - if (S == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ S->ops->gettype = SUNLinSolGetType_SPTFQMR; @@ -94,11 +92,7 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, /* Create content */ content = NULL; content = (SUNLinearSolverContent_SPTFQMR)malloc(sizeof *content); - if (content == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Attach content */ S->content = content; @@ -136,74 +130,25 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, /* Allocate content */ content->r_star = N_VClone(y); - if (content->r_star == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->q = N_VClone(y); - if (content->q == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->d = N_VClone(y); - if (content->d == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->v = N_VClone(y); - if (content->v == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->p = N_VClone(y); - if (content->p == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->r = N_VCloneVectorArray(2, y); - if (content->r == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->u = N_VClone(y); - if (content->u == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->vtemp1 = N_VClone(y); - if (content->vtemp1 == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->vtemp2 = N_VClone(y); - if (content->vtemp2 == NULL) - { - SUNLinSolFree(S); - return (NULL); - } - + SUNCheckLastErrNull(); content->vtemp3 = N_VClone(y); - if (content->vtemp3 == NULL) - { - SUNLinSolFree(S); - return (NULL); - } + SUNCheckLastErrNull(); return (S); } @@ -212,38 +157,31 @@ SUNLinearSolver SUNLinSol_SPTFQMR(N_Vector y, int pretype, int maxl, * Function to set the type of preconditioning for SPTFQMR to use */ -int SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, int pretype) +SUNErrCode SUNLinSol_SPTFQMRSetPrecType(SUNLinearSolver S, int pretype) { + SUNFunctionBegin(S->sunctx); /* Check for legal pretype */ - if ((pretype != SUN_PREC_NONE) && (pretype != SUN_PREC_LEFT) && - (pretype != SUN_PREC_RIGHT) && (pretype != SUN_PREC_BOTH)) - { - return (SUNLS_ILL_INPUT); - } - - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + SUNAssert((pretype == SUN_PREC_NONE) || (pretype == SUN_PREC_LEFT) || + (pretype == SUN_PREC_RIGHT) || (pretype == SUN_PREC_BOTH), + SUN_ERR_ARG_OUTOFRANGE); /* Set pretype */ SPTFQMR_CONTENT(S)->pretype = pretype; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* ---------------------------------------------------------------------------- * Function to set the maximum number of iterations for SPTFQMR to use */ -int SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl) +SUNErrCode SUNLinSol_SPTFQMRSetMaxl(SUNLinearSolver S, int maxl) { - /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } - /* Check for legal pretype */ if (maxl <= 0) { maxl = SUNSPTFQMR_MAXL_DEFAULT; } /* Set pretype */ SPTFQMR_CONTENT(S)->maxl = maxl; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } /* @@ -262,22 +200,18 @@ SUNLinearSolver_ID SUNLinSolGetID_SPTFQMR(SUNLinearSolver S) return (SUNLINEARSOLVER_SPTFQMR); } -int SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S) { + SUNFunctionBegin(S->sunctx); SUNLinearSolverContent_SPTFQMR content; /* set shortcut to SPTFQMR memory structure */ - if (S == NULL) { return (SUNLS_MEM_NULL); } content = SPTFQMR_CONTENT(S); /* ensure valid options */ if (content->maxl <= 0) { content->maxl = SUNSPTFQMR_MAXL_DEFAULT; } - if (content->ATimes == NULL) - { - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(content->ATimes, SUN_ERR_ARG_CORRUPT); if ((content->pretype != SUN_PREC_LEFT) && (content->pretype != SUN_PREC_RIGHT) && (content->pretype != SUN_PREC_BOTH)) @@ -285,71 +219,65 @@ int SUNLinSolInitialize_SPTFQMR(SUNLinearSolver S) content->pretype = SUN_PREC_NONE; } - if ((content->pretype != SUN_PREC_NONE) && (content->Psolve == NULL)) - { - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert((content->pretype == SUN_PREC_NONE) || (content->Psolve != NULL), + SUN_ERR_ARG_CORRUPT); /* no additional memory to allocate */ - /* return with success */ - content->last_flag = SUNLS_SUCCESS; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* ATData, SUNATimesFn ATimes) +SUNErrCode SUNLinSolSetATimes_SPTFQMR(SUNLinearSolver S, void* ATData, + SUNATimesFn ATimes) { /* set function pointers to integrator-supplied ATimes routine and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPTFQMR_CONTENT(S)->ATimes = ATimes; SPTFQMR_CONTENT(S)->ATData = ATData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, void* PData, - SUNPSetupFn Psetup, SUNPSolveFn Psolve) +SUNErrCode SUNLinSolSetPreconditioner_SPTFQMR(SUNLinearSolver S, void* PData, + SUNPSetupFn Psetup, + SUNPSolveFn Psolve) { /* set function pointers to integrator-supplied Psetup and PSolve routines and data, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPTFQMR_CONTENT(S)->Psetup = Psetup; SPTFQMR_CONTENT(S)->Psolve = Psolve; SPTFQMR_CONTENT(S)->PData = PData; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, N_Vector s1, N_Vector s2) +SUNErrCode SUNLinSolSetScalingVectors_SPTFQMR(SUNLinearSolver S, N_Vector s1, + N_Vector s2) { /* set N_Vector pointers to integrator-supplied scaling vectors, and return with success */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPTFQMR_CONTENT(S)->s1 = s1; SPTFQMR_CONTENT(S)->s2 = s2; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } -int SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, sunbooleantype onoff) +SUNErrCode SUNLinSolSetZeroGuess_SPTFQMR(SUNLinearSolver S, sunbooleantype onoff) { /* set flag indicating a zero initial guess */ - if (S == NULL) { return (SUNLS_MEM_NULL); } SPTFQMR_CONTENT(S)->zeroguess = onoff; - LASTFLAG(S) = SUNLS_SUCCESS; - return (LASTFLAG(S)); + return SUN_SUCCESS; } int SUNLinSolSetup_SPTFQMR(SUNLinearSolver S, SUNMatrix A) { - int ier; + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + + int status = SUN_SUCCESS; SUNPSetupFn Psetup; void* PData; /* Set shortcuts to SPTFQMR memory structures */ - if (S == NULL) { return (SUNLS_MEM_NULL); } Psetup = SPTFQMR_CONTENT(S)->Psetup; PData = SPTFQMR_CONTENT(S)->PData; @@ -357,21 +285,27 @@ int SUNLinSolSetup_SPTFQMR(SUNLinearSolver S, SUNMatrix A) Psetup routine exists, call that here */ if (Psetup != NULL) { - ier = Psetup(PData); - if (ier != 0) + status = Psetup(PData); + if (status != 0) { - LASTFLAG(S) = (ier < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSET_FAIL_UNREC : SUNLS_PSET_FAIL_REC; return (LASTFLAG(S)); } } /* return with success */ - return (SUNLS_SUCCESS); + LASTFLAG(S) = SUN_SUCCESS; + return (SUN_SUCCESS); } int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, N_Vector b, sunrealtype delta) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNLinearSolver. */ + + SUNFunctionBegin(S->sunctx); + /* local data and shortcut variables */ sunrealtype alpha, tau, eta, beta, c, sigma, v_bar, omega; sunrealtype rho[2]; @@ -379,20 +313,18 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, sunrealtype temp_val; sunbooleantype preOnLeft, preOnRight, scale_x, scale_b, converged, b_ok; sunbooleantype* zeroguess; - int n, m, ier, l_max; + int n, m, l_max; void *A_data, *P_data; SUNATimesFn atimes; SUNPSolveFn psolve; sunrealtype* res_norm; int* nli; N_Vector sx, sb, r_star, q, d, v, p, *r, u, vtemp1, vtemp2, vtemp3; - - /* local variables for fused vector operations */ sunrealtype cv[3]; N_Vector Xv[3]; + int status = SUN_SUCCESS; /* Make local shorcuts to solver variables. */ - if (S == NULL) { return (SUNLS_MEM_NULL); } l_max = SPTFQMR_CONTENT(S)->maxl; r_star = SPTFQMR_CONTENT(S)->r_star; q = SPTFQMR_CONTENT(S)->q; @@ -432,8 +364,8 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (preOnRight && !(*zeroguess)) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ILL_INPUT; - return (SUNLS_ILL_INPUT); + LASTFLAG(S) = SUN_ERR_ARG_INCOMPATIBLE; + return (SUN_ERR_ARG_INCOMPATIBLE); } #if SUNDIALS_LOGGING_LEVEL >= SUNDIALS_LOGGING_INFO @@ -443,56 +375,67 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, #endif /* Check if Atimes function has been set */ - if (atimes == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_ATIMES_NULL; - return (LASTFLAG(S)); - } + SUNAssert(atimes, SUN_ERR_ARG_CORRUPT); /* If preconditioning, check if psolve has been set */ - if ((preOnLeft || preOnRight) && psolve == NULL) - { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_PSOLVE_NULL; - return (LASTFLAG(S)); - } + SUNAssert(!(preOnLeft || preOnRight) || psolve, SUN_ERR_ARG_CORRUPT); /* Set r_star to initial (unscaled) residual r_star = r_0 = b - A*x_0 */ /* NOTE: if x == 0 then just set residual to b and continue */ - if (*zeroguess) { N_VScale(ONE, b, r_star); } + if (*zeroguess) + { + N_VScale(ONE, b, r_star); + SUNCheckLastErrNoRet(); + } else { - ier = atimes(A_data, x, r_star); - if (ier != 0) + status = atimes(A_data, x, r_star); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } N_VLinearSum(ONE, b, -ONE, r_star, r_star); + SUNCheckLastErrNoRet(); } /* Apply left preconditioner and b-scaling to r_star (or really just r_0) */ if (preOnLeft) { - ier = psolve(P_data, r_star, vtemp1, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, r_star, vtemp1, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, r_star, vtemp1); } - if (scale_b) { N_VProd(sb, vtemp1, r_star); } - else { N_VScale(ONE, vtemp1, r_star); } + else + { + N_VScale(ONE, r_star, vtemp1); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, vtemp1, r_star); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp1, r_star); + SUNCheckLastErrNoRet(); + } /* Initialize rho[0] */ /* NOTE: initialized here to reduce number of computations - avoid need to compute r_star^T*r_star twice, and avoid needlessly squaring values */ rho[0] = N_VDotProd(r_star, r_star); + SUNCheckLastErrNoRet(); /* Compute norm of initial residual (r_0) to see if we really need to do anything */ @@ -514,53 +457,88 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, if (r_init_norm <= delta) { *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } /* Set v = A*r_0 (preconditioned and scaled) */ - if (scale_x) { N_VDiv(r_star, sx, vtemp1); } - else { N_VScale(ONE, r_star, vtemp1); } + if (scale_x) + { + N_VDiv(r_star, sx, vtemp1); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, r_star, vtemp1); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { N_VScale(ONE, vtemp1, v); - ier = psolve(P_data, v, vtemp1, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, v, vtemp1, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - ier = atimes(A_data, vtemp1, v); - if (ier != 0) + + status = atimes(A_data, vtemp1, v); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } + if (preOnLeft) { - ier = psolve(P_data, v, vtemp1, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, v, vtemp1, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, v, vtemp1); } - if (scale_b) { N_VProd(sb, vtemp1, v); } - else { N_VScale(ONE, vtemp1, v); } + else + { + N_VScale(ONE, v, vtemp1); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, vtemp1, v); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp1, v); + SUNCheckLastErrNoRet(); + } /* Initialize remaining variables */ N_VScale(ONE, r_star, r[0]); + SUNCheckLastErrNoRet(); N_VScale(ONE, r_star, u); + SUNCheckLastErrNoRet(); N_VScale(ONE, r_star, p); + SUNCheckLastErrNoRet(); N_VConst(ZERO, d); + SUNCheckLastErrNoRet(); /* Set x = sx x if non-zero guess */ - if (scale_x && !(*zeroguess)) { N_VProd(sx, x, x); } + if (scale_x && !(*zeroguess)) + { + N_VProd(sx, x, x); + SUNCheckLastErrNoRet(); + } tau = r_init_norm; v_bar = eta = ZERO; @@ -573,48 +551,76 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* sigma = r_star^T*v */ sigma = N_VDotProd(r_star, v); + SUNCheckLastErrNoRet(); /* alpha = rho[0]/sigma */ alpha = rho[0] / sigma; /* q = u-alpha*v */ N_VLinearSum(ONE, u, -alpha, v, q); + SUNCheckLastErrNoRet(); /* r[1] = r[0]-alpha*A*(u+q) */ N_VLinearSum(ONE, u, ONE, q, r[1]); - if (scale_x) { N_VDiv(r[1], sx, r[1]); } + SUNCheckLastErrNoRet(); + if (scale_x) + { + N_VDiv(r[1], sx, r[1]); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { N_VScale(ONE, r[1], vtemp1); - ier = psolve(P_data, vtemp1, r[1], delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, vtemp1, r[1], delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - ier = atimes(A_data, r[1], vtemp1); - if (ier != 0) + + status = atimes(A_data, r[1], vtemp1); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } + if (preOnLeft) { - ier = psolve(P_data, vtemp1, r[1], delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, vtemp1, r[1], delta, SUN_PREC_LEFT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, vtemp1, r[1]); } - if (scale_b) { N_VProd(sb, r[1], vtemp1); } - else { N_VScale(ONE, r[1], vtemp1); } + else + { + N_VScale(ONE, vtemp1, r[1]); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, r[1], vtemp1); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, r[1], vtemp1); + SUNCheckLastErrNoRet(); + } N_VLinearSum(ONE, r[0], -alpha, vtemp1, r[1]); + SUNCheckLastErrNoRet(); /* START inner loop */ for (m = 0; m < 2; ++m) @@ -627,14 +633,20 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, */ if (m == 0) { - temp_val = SUNRsqrt(N_VDotProd(r[1], r[1])); - omega = SUNRsqrt(SUNRsqrt(N_VDotProd(r[0], r[0])) * temp_val); + temp_val = N_VDotProd(r[1], r[1]); + SUNCheckLastErrNoRet(); + temp_val = SUNRsqrt(temp_val); + omega = N_VDotProd(r[0], r[0]); + SUNCheckLastErrNoRet(); + omega = SUNRsqrt(SUNRsqrt(omega) * temp_val); N_VLinearSum(ONE, u, SUNSQR(v_bar) * eta / alpha, d, d); + SUNCheckLastErrNoRet(); } else { omega = temp_val; N_VLinearSum(ONE, q, SUNSQR(v_bar) * eta / alpha, d, d); + SUNCheckLastErrNoRet(); } /* v_bar = omega/tau */ @@ -650,8 +662,16 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, eta = SUNSQR(c) * alpha; /* x = x+eta*d */ - if (n == 0 && m == 0 && *zeroguess) { N_VScale(eta, d, x); } - else { N_VLinearSum(ONE, x, eta, d, x); } + if (n == 0 && m == 0 && *zeroguess) + { + N_VScale(eta, d, x); + SUNCheckLastErrNoRet(); + } + else + { + N_VLinearSum(ONE, x, eta, d, x); + SUNCheckLastErrNoRet(); + } /* Check for convergence... */ /* NOTE: just use approximation to norm of residual, if possible */ @@ -694,62 +714,100 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, (r_curr_norm >= r_init_norm && m == 1 && n == l_max)) { /* Compute norm of residual ||b-A*x||_2 (preconditioned and scaled) */ - if (scale_x) { N_VDiv(x, sx, vtemp1); } - else { N_VScale(ONE, x, vtemp1); } + if (scale_x) + { + N_VDiv(x, sx, vtemp1); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, x, vtemp1); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { - ier = psolve(P_data, vtemp1, vtemp2, delta, SUN_PREC_RIGHT); - if (ier != 0) + status = psolve(P_data, vtemp1, vtemp2, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_UNREC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_UNREC; return (LASTFLAG(S)); } N_VScale(ONE, vtemp2, vtemp1); + SUNCheckLastErrNoRet(); } - ier = atimes(A_data, vtemp1, vtemp2); - if (ier != 0) + + status = atimes(A_data, vtemp1, vtemp2); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC - : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } + if (preOnLeft) { - ier = psolve(P_data, vtemp2, vtemp1, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, vtemp2, vtemp1, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, vtemp2, vtemp1); } - if (scale_b) { N_VProd(sb, vtemp1, vtemp2); } - else { N_VScale(ONE, vtemp1, vtemp2); } + else + { + N_VScale(ONE, vtemp2, vtemp1); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, vtemp1, vtemp2); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp1, vtemp2); + SUNCheckLastErrNoRet(); + } + /* Only precondition and scale b once (result saved for reuse) */ if (!b_ok) { b_ok = SUNTRUE; if (preOnLeft) { - ier = psolve(P_data, b, vtemp3, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, b, vtemp3, delta, SUN_PREC_LEFT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, b, vtemp3); } - if (scale_b) { N_VProd(sb, vtemp3, vtemp3); } + else + { + N_VScale(ONE, b, vtemp3); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, vtemp3, vtemp3); + SUNCheckLastErrNoRet(); + } } N_VLinearSum(ONE, vtemp3, -ONE, vtemp2, vtemp1); - *res_norm = r_curr_norm = SUNRsqrt(N_VDotProd(vtemp1, vtemp1)); + SUNCheckLastErrNoRet(); + r_curr_norm = N_VDotProd(vtemp1, vtemp1); + SUNCheckLastErrNoRet(); + *res_norm = r_curr_norm = SUNRsqrt(r_curr_norm); /* Exit inner loop if inequality condition is satisfied (meaning exit if we have converged) */ @@ -767,12 +825,14 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* rho[1] = r_star^T*r_[1] */ rho[1] = N_VDotProd(r_star, r[1]); + SUNCheckLastErrNoRet(); /* beta = rho[1]/rho[0] */ beta = rho[1] / rho[0]; /* u = r[1]+beta*q */ N_VLinearSum(ONE, r[1], beta, q, u); + SUNCheckLastErrNoRet(); /* p = u+beta*(q+beta*p) = beta*beta*p + beta*q + u */ cv[0] = SUNSQR(beta); @@ -784,80 +844,109 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, cv[2] = ONE; Xv[2] = u; - ier = N_VLinearCombination(3, cv, Xv, p); - if (ier != SUNLS_SUCCESS) + SUNCheckCallNoRet(N_VLinearCombination(3, cv, Xv, p)); + + /* v = A*p */ + if (scale_x) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = SUNLS_VECTOROP_ERR; - return (SUNLS_VECTOROP_ERR); + N_VDiv(p, sx, vtemp1); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, p, vtemp1); + SUNCheckLastErrNoRet(); } - /* v = A*p */ - if (scale_x) { N_VDiv(p, sx, vtemp1); } - else { N_VScale(ONE, p, vtemp1); } if (preOnRight) { N_VScale(ONE, vtemp1, v); - ier = psolve(P_data, v, vtemp1, delta, SUN_PREC_RIGHT); - if (ier != 0) + SUNCheckLastErrNoRet(); + status = psolve(P_data, v, vtemp1, delta, SUN_PREC_RIGHT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - ier = atimes(A_data, vtemp1, v); - if (ier != 0) + + status = atimes(A_data, vtemp1, v); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_ATIMES_FAIL_UNREC : SUNLS_ATIMES_FAIL_REC; + LASTFLAG(S) = (status < 0) ? SUNLS_ATIMES_FAIL_UNREC + : SUNLS_ATIMES_FAIL_REC; return (LASTFLAG(S)); } + if (preOnLeft) { - ier = psolve(P_data, v, vtemp1, delta, SUN_PREC_LEFT); - if (ier != 0) + status = psolve(P_data, v, vtemp1, delta, SUN_PREC_LEFT); + if (status != 0) { - *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC : SUNLS_PSOLVE_FAIL_REC; + *zeroguess = SUNFALSE; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_REC; return (LASTFLAG(S)); } } - else { N_VScale(ONE, v, vtemp1); } - if (scale_b) { N_VProd(sb, vtemp1, v); } - else { N_VScale(ONE, vtemp1, v); } + else + { + N_VScale(ONE, v, vtemp1); + SUNCheckLastErrNoRet(); + } + + if (scale_b) + { + N_VProd(sb, vtemp1, v); + SUNCheckLastErrNoRet(); + } + else + { + N_VScale(ONE, vtemp1, v); + SUNCheckLastErrNoRet(); + } /* Shift variable values */ /* NOTE: reduces storage requirements */ N_VScale(ONE, r[1], r[0]); + SUNCheckLastErrNoRet(); rho[0] = rho[1]; } /* END outer loop */ /* Determine return value */ - /* If iteration converged or residual was reduced, then return current iterate (x) */ + /* If iteration converged or residual was reduced, then return current iterate + * (x) */ if ((converged == SUNTRUE) || (r_curr_norm < r_init_norm)) { - if (scale_x) { N_VDiv(x, sx, x); } + if (scale_x) + { + N_VDiv(x, sx, x); + SUNCheckLastErrNoRet(); + } + if (preOnRight) { - ier = psolve(P_data, x, vtemp1, delta, SUN_PREC_RIGHT); - if (ier != 0) + status = psolve(P_data, x, vtemp1, delta, SUN_PREC_RIGHT); + if (status != 0) { *zeroguess = SUNFALSE; - LASTFLAG(S) = (ier < 0) ? SUNLS_PSOLVE_FAIL_UNREC - : SUNLS_PSOLVE_FAIL_UNREC; + LASTFLAG(S) = (status < 0) ? SUNLS_PSOLVE_FAIL_UNREC + : SUNLS_PSOLVE_FAIL_UNREC; return (LASTFLAG(S)); } N_VScale(ONE, vtemp1, x); + SUNCheckLastErrNoRet(); } *zeroguess = SUNFALSE; - if (converged == SUNTRUE) { LASTFLAG(S) = SUNLS_SUCCESS; } + if (converged == SUNTRUE) { LASTFLAG(S) = SUN_SUCCESS; } else { LASTFLAG(S) = SUNLS_RES_REDUCED; } return (LASTFLAG(S)); } - /* Otherwise, return error code */ else { *zeroguess = SUNFALSE; @@ -868,47 +957,43 @@ int SUNLinSolSolve_SPTFQMR(SUNLinearSolver S, SUNMatrix A, N_Vector x, int SUNLinSolNumIters_SPTFQMR(SUNLinearSolver S) { - /* return the stored 'numiters' value */ - if (S == NULL) { return (-1); } return (SPTFQMR_CONTENT(S)->numiters); } sunrealtype SUNLinSolResNorm_SPTFQMR(SUNLinearSolver S) { - /* return the stored 'resnorm' value */ - if (S == NULL) { return (-ONE); } return (SPTFQMR_CONTENT(S)->resnorm); } N_Vector SUNLinSolResid_SPTFQMR(SUNLinearSolver S) { - /* return the stored 'vtemp1' vector */ return (SPTFQMR_CONTENT(S)->vtemp1); } sunindextype SUNLinSolLastFlag_SPTFQMR(SUNLinearSolver S) { - /* return the stored 'last_flag' value */ - if (S == NULL) { return (-1); } return (LASTFLAG(S)); } -int SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, long int* lenrwLS, long int* leniwLS) +SUNErrCode SUNLinSolSpace_SPTFQMR(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { + SUNFunctionBegin(S->sunctx); sunindextype liw1, lrw1; if (SPTFQMR_CONTENT(S)->vtemp1->ops->nvspace) { N_VSpace(SPTFQMR_CONTENT(S)->vtemp1, &lrw1, &liw1); + SUNCheckLastErrNoRet(); } else { lrw1 = liw1 = 0; } *lenrwLS = lrw1 * 11; *leniwLS = liw1 * 11; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } -int SUNLinSolFree_SPTFQMR(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SPTFQMR(SUNLinearSolver S) { - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } if (S->content) { @@ -973,5 +1058,5 @@ int SUNLinSolFree_SPTFQMR(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunlinsol/superludist/sunlinsol_superludist.c b/src/sunlinsol/superludist/sunlinsol_superludist.c index 07558c9148..4ae6746b47 100644 --- a/src/sunlinsol/superludist/sunlinsol_superludist.c +++ b/src/sunlinsol/superludist/sunlinsol_superludist.c @@ -176,11 +176,11 @@ SUNLinearSolver_ID SUNLinSolGetID_SuperLUDIST(SUNLinearSolver S) return (SUNLINEARSOLVER_SUPERLUDIST); } -int SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SuperLUDIST(SUNLinearSolver S) { SLU_FIRSTFACTORIZE(S) = SUNTRUE; - SLU_LASTFLAG(S) = SUNLS_SUCCESS; + SLU_LASTFLAG(S) = SUN_SUCCESS; return (SLU_LASTFLAG(S)); } @@ -205,7 +205,7 @@ int SUNLinSolSetup_SuperLUDIST(SUNLinearSolver S, SUNMatrix A) SLU_OPTIONS(S)->Fact = SamePattern; } - SLU_LASTFLAG(S) = SUNLS_SUCCESS; + SLU_LASTFLAG(S) = SUN_SUCCESS; return (SLU_LASTFLAG(S)); } @@ -219,7 +219,7 @@ int SUNLinSolSolve_SuperLUDIST(SUNLinearSolver S, SUNMatrix A, N_Vector x, if ((S == NULL) || (A == NULL) || (x == NULL) || (b == NULL)) { - return (SUNLS_MEM_NULL); + return (SUN_ERR_ARG_CORRUPT); } Asuper = SUNMatrix_SLUNRloc_SuperMatrix(A); @@ -231,7 +231,7 @@ int SUNLinSolSolve_SuperLUDIST(SUNLinearSolver S, SUNMatrix A, N_Vector x, xdata = N_VGetArrayPointer(x); if (xdata == NULL) { - SLU_LASTFLAG(S) = SUNLS_MEM_FAIL; + SLU_LASTFLAG(S) = SUN_ERR_MEM_FAIL; return (SLU_LASTFLAG(S)); } @@ -256,7 +256,7 @@ int SUNLinSolSolve_SuperLUDIST(SUNLinearSolver S, SUNMatrix A, N_Vector x, /* Tell SuperLU-DIST that A is already factored so do not factorize */ SLU_OPTIONS(S)->Fact = FACTORED; - SLU_LASTFLAG(S) = SUNLS_SUCCESS; + SLU_LASTFLAG(S) = SUN_SUCCESS; return (SLU_LASTFLAG(S)); } @@ -266,10 +266,10 @@ sunindextype SUNLinSolLastFlag_SuperLUDIST(SUNLinearSolver S) return (SLU_LASTFLAG(S)); } -int SUNLinSolFree_SuperLUDIST(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SuperLUDIST(SUNLinearSolver S) { /* return with success if already freed */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* Call SuperLU DIST destroy/finalize routines, but don't free the sturctures themselves - that is the user's job */ @@ -294,11 +294,11 @@ int SUNLinSolFree_SuperLUDIST(SUNLinearSolver S) free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, long int* leniwLS, - long int* lenrwLS) +SUNErrCode SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, long int* leniwLS, + long int* lenrwLS) { /* since the SuperLU_DIST structures are opaque objects, we omit those from these results */ @@ -306,5 +306,5 @@ int SUNLinSolSpace_SuperLUDIST(SUNLinearSolver S, long int* leniwLS, *leniwLS = 2; /* last_flag, N */ *lenrwLS = 1; /* berr */ - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunlinsol/superlumt/sunlinsol_superlumt.c b/src/sunlinsol/superlumt/sunlinsol_superlumt.c index fba6729fd7..e4ffa0cf0c 100644 --- a/src/sunlinsol/superlumt/sunlinsol_superlumt.c +++ b/src/sunlinsol/superlumt/sunlinsol_superlumt.c @@ -209,16 +209,16 @@ int SUNLinSol_SuperLUMTSetOrdering(SUNLinearSolver S, int ordering_choice) /* Check for legal ordering_choice */ if ((ordering_choice < 0) || (ordering_choice > 3)) { - return (SUNLS_ILL_INPUT); + return (SUN_ERR_ARG_INCOMPATIBLE); } /* Check for non-NULL SUNLinearSolver */ - if (S == NULL) { return (SUNLS_MEM_NULL); } + if (S == NULL) { return (SUN_ERR_ARG_CORRUPT); } /* Set ordering_choice */ ORDERING(S) = ordering_choice; - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -238,7 +238,7 @@ SUNLinearSolver_ID SUNLinSolGetID_SuperLUMT(SUNLinearSolver S) return (SUNLINEARSOLVER_SUPERLUMT); } -int SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S) +SUNErrCode SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S) { /* force a first factorization */ FIRSTFACTORIZE(S) = 1; @@ -246,7 +246,7 @@ int SUNLinSolInitialize_SuperLUMT(SUNLinearSolver S) /* Initialize statistics variables */ StatInit(SIZE(S), NUMTHREADS(S), GSTAT(S)); - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -314,7 +314,7 @@ int SUNLinSolSetup_SuperLUMT(SUNLinearSolver S, SUNMatrix A) return (LASTFLAG(S)); } - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -333,7 +333,7 @@ int SUNLinSolSolve_SuperLUMT(SUNLinearSolver S, SUNMatrix A, N_Vector x, xdata = N_VGetArrayPointer(x); if (xdata == NULL) { - LASTFLAG(S) = SUNLS_MEM_FAIL; + LASTFLAG(S) = SUN_ERR_MEM_FAIL; return (LASTFLAG(S)); } @@ -350,7 +350,7 @@ int SUNLinSolSolve_SuperLUMT(SUNLinearSolver S, SUNMatrix A, N_Vector x, return (LASTFLAG(S)); } - LASTFLAG(S) = SUNLS_SUCCESS; + LASTFLAG(S) = SUN_SUCCESS; return (LASTFLAG(S)); } @@ -361,20 +361,20 @@ sunindextype SUNLinSolLastFlag_SuperLUMT(SUNLinearSolver S) return (LASTFLAG(S)); } -int SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, long int* lenrwLS, - long int* leniwLS) +SUNErrCode SUNLinSolSpace_SuperLUMT(SUNLinearSolver S, long int* lenrwLS, + long int* leniwLS) { /* since the SuperLU_MT structures are opaque objects, we omit those from these results */ *leniwLS = 5 + 2 * SIZE(S); *lenrwLS = 1; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } -int SUNLinSolFree_SuperLUMT(SUNLinearSolver S) +SUNErrCode SUNLinSolFree_SuperLUMT(SUNLinearSolver S) { /* return with success if already freed */ - if (S == NULL) { return (SUNLS_SUCCESS); } + if (S == NULL) { return (SUN_SUCCESS); } /* delete items from the contents structure (if it exists) */ if (S->content) @@ -446,5 +446,5 @@ int SUNLinSolFree_SuperLUMT(SUNLinearSolver S) } free(S); S = NULL; - return (SUNLS_SUCCESS); + return (SUN_SUCCESS); } diff --git a/src/sunnonlinsol/fixedpoint/fmod/fsunnonlinsol_fixedpoint_mod.c b/src/sunnonlinsol/fixedpoint/fmod/fsunnonlinsol_fixedpoint_mod.c index d200856483..3bfdceb793 100644 --- a/src/sunnonlinsol/fixedpoint/fmod/fsunnonlinsol_fixedpoint_mod.c +++ b/src/sunnonlinsol/fixedpoint/fmod/fsunnonlinsol_fixedpoint_mod.c @@ -257,11 +257,11 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver farg1) { SWIGEXPORT int _wrap_FSUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver farg1) { int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); - result = (int)SUNNonlinSolInitialize_FixedPoint(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolInitialize_FixedPoint(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -293,11 +293,11 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver farg1, N_V SWIGEXPORT int _wrap_FSUNNonlinSolFree_FixedPoint(SUNNonlinearSolver farg1) { int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); - result = (int)SUNNonlinSolFree_FixedPoint(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolFree_FixedPoint(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -306,12 +306,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver farg1, int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolSysFn arg2 = (SUNNonlinSolSysFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolSysFn)(farg2); - result = (int)SUNNonlinSolSetSysFn_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetSysFn_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -321,13 +321,13 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver fa SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolConvTestFn arg2 = (SUNNonlinSolConvTestFn) 0 ; void *arg3 = (void *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolConvTestFn)(farg2); arg3 = (void *)(farg3); - result = (int)SUNNonlinSolSetConvTestFn_FixedPoint(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetConvTestFn_FixedPoint(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -336,12 +336,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver farg int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNNonlinSolSetMaxIters_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetMaxIters_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -350,12 +350,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver farg1 int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; sunrealtype arg2 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (sunrealtype)(*farg2); - result = (int)SUNNonlinSolSetDamping_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetDamping_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -364,12 +364,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver farg int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; long *arg2 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (long *)(farg2); - result = (int)SUNNonlinSolGetNumIters_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetNumIters_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -378,12 +378,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver farg1 int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; int *arg2 = (int *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (int *)(farg2); - result = (int)SUNNonlinSolGetCurIter_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetCurIter_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -392,12 +392,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; long *arg2 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (long *)(farg2); - result = (int)SUNNonlinSolGetNumConvFails_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetNumConvFails_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -406,12 +406,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver farg1, int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolSysFn *arg2 = (SUNNonlinSolSysFn *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolSysFn *)(farg2); - result = (int)SUNNonlinSolGetSysFn_FixedPoint(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetSysFn_FixedPoint(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c b/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c index 4a7b55f898..ca48df017e 100644 --- a/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c +++ b/src/sunnonlinsol/fixedpoint/sunnonlinsol_fixedpoint.c @@ -18,18 +18,17 @@ #include #include #include -#include -#include +#include #include #include #include "sundials_logger_impl.h" /* Internal utility routines */ -static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, - N_Vector xold, int iter); +static SUNErrCode AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, + N_Vector x, N_Vector xold, int iter); -static int AllocateContent(SUNNonlinearSolver NLS, N_Vector tmpl); +static SUNErrCode AllocateContent(SUNNonlinearSolver NLS, N_Vector tmpl); static void FreeContent(SUNNonlinearSolver NLS); /* Content structure accessibility macros */ @@ -45,24 +44,18 @@ static void FreeContent(SUNNonlinearSolver NLS); SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx) { - SUNNonlinearSolver NLS; - SUNNonlinearSolverContent_FixedPoint content; - int retval; - - /* Check that the supplied N_Vector is non-NULL */ - if (y == NULL) { return (NULL); } + SUNFunctionBegin(sunctx); + SUNNonlinearSolver NLS = NULL; + SUNNonlinearSolverContent_FixedPoint content = NULL; /* Check that the supplied N_Vector supports all required operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvscale == NULL) || (y->ops->nvlinearsum == NULL) || - (y->ops->nvdotprod == NULL)) - { - return (NULL); - } + SUNAssertNull(y->ops->nvclone && y->ops->nvdestroy && y->ops->nvscale && + y->ops->nvlinearsum && y->ops->nvdotprod, + SUN_ERR_ARG_CORRUPT); /* Create nonlinear linear solver */ NLS = SUNNonlinSolNewEmpty(sunctx); - if (NLS == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ NLS->ops->gettype = SUNNonlinSolGetType_FixedPoint; @@ -79,11 +72,7 @@ SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx) /* Create nonlinear solver content structure */ content = NULL; content = (SUNNonlinearSolverContent_FixedPoint)malloc(sizeof *content); - if (content == NULL) - { - SUNNonlinSolFree(NLS); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Initialize all components of content to 0/NULL */ memset(content, 0, sizeof(struct _SUNNonlinearSolverContent_FixedPoint)); @@ -110,12 +99,7 @@ SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx) #endif /* Fill allocatable content */ - retval = AllocateContent(NLS, y); - if (retval != SUN_NLS_SUCCESS) - { - SUNNonlinSolFree(NLS); - return (NULL); - } + SUNCheckCallNull(AllocateContent(NLS, y)); return (NLS); } @@ -127,17 +111,21 @@ SUNNonlinearSolver SUNNonlinSol_FixedPoint(N_Vector y, int m, SUNContext sunctx) SUNNonlinearSolver SUNNonlinSol_FixedPointSens(int count, N_Vector y, int m, SUNContext sunctx) { - SUNNonlinearSolver NLS; - N_Vector w; + SUNFunctionBegin(sunctx); + SUNNonlinearSolver NLS = NULL; + N_Vector w = NULL; /* create sensitivity vector wrapper */ w = N_VNew_SensWrapper(count, y); + SUNCheckLastErrNull(); /* create nonlinear solver using sensitivity vector wrapper */ NLS = SUNNonlinSol_FixedPoint(w, m, sunctx); + SUNCheckLastErrNull(); /* free sensitivity vector wrapper */ N_VDestroy(w); + SUNCheckLastErrNull(); /* return NLS object */ return (NLS); @@ -152,29 +140,24 @@ SUNNonlinearSolver_Type SUNNonlinSolGetType_FixedPoint(SUNNonlinearSolver NLS) return (SUNNONLINEARSOLVER_FIXEDPOINT); } -int SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - + SUNFunctionBegin(NLS->sunctx); /* check that all required function pointers have been set */ - if ((FP_CONTENT(NLS)->Sys == NULL) || (FP_CONTENT(NLS)->CTest == NULL)) - { - return (SUN_NLS_MEM_NULL); - } + SUNAssert(FP_CONTENT(NLS)->Sys && FP_CONTENT(NLS)->CTest, SUN_ERR_ARG_CORRUPT); /* reset the total number of iterations and convergence failures */ FP_CONTENT(NLS)->niters = 0; FP_CONTENT(NLS)->nconvfails = 0; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*----------------------------------------------------------------------------- SUNNonlinSolSolve_FixedPoint: Performs the fixed-point solve g(y) = y Successful solve return code: - SUN_NLS_SUCCESS = 0 + SUN_SUCCESS = 0 Recoverable failure return codes (positive): SUN_NLS_CONV_RECVR @@ -187,32 +170,22 @@ int SUNNonlinSolInitialize_FixedPoint(SUNNonlinearSolver NLS) Note that return values beginning with * are package specific values returned by the Sys function provided to the nonlinear solver. ---------------------------------------------------------------------------*/ + int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, N_Vector w, sunrealtype tol, sunbooleantype callSetup, void* mem) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNNonlinearSolver. */ + + SUNFunctionBegin(NLS->sunctx); /* local variables */ int retval; N_Vector yprev, gy, delta; - /* check that the inputs are non-null */ - if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || - (mem == NULL)) - { - return (SUN_NLS_MEM_NULL); - } - /* check that all required function pointers have been set */ - if ((FP_CONTENT(NLS)->Sys == NULL) || (FP_CONTENT(NLS)->CTest == NULL)) - { - return (SUN_NLS_MEM_NULL); - } - - /* check that all required function pointers have been set */ - if ((FP_CONTENT(NLS)->Sys == NULL) || (FP_CONTENT(NLS)->CTest == NULL)) - { - return (SUN_NLS_MEM_NULL); - } + SUNAssertNoRet(FP_CONTENT(NLS)->Sys && FP_CONTENT(NLS)->CTest, + SUN_ERR_ARG_CORRUPT); /* set local shortcut variables */ yprev = FP_CONTENT(NLS)->yprev; @@ -247,19 +220,24 @@ int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, { /* update previous solution guess */ N_VScale(ONE, ycor, yprev); + SUNCheckLastErrNoRet(); - /* compute fixed-point iteration function, store in gy */ - retval = FP_CONTENT(NLS)->Sys(ycor, gy, mem); - if (retval != SUN_NLS_SUCCESS) { break; } + /* Compute fixed-point iteration function, store in gy. + We do not use SUNCheck macros here because Sys is a user-provided + callback and does not return a SUNErrCode, rather it returns an integer + where 0 == success, < 0 is a failure, > 0 is recoverable error. */ + if (FP_CONTENT(NLS)->Sys(ycor, gy, mem)) { break; } /* perform fixed point update, based on choice of acceleration or not */ if (FP_CONTENT(NLS)->m == 0) { /* basic fixed-point solver */ N_VScale(ONE, gy, ycor); + SUNCheckLastErrNoRet(); } else { /* Anderson-accelerated solver */ - retval = AndersonAccelerate(NLS, gy, ycor, yprev, FP_CONTENT(NLS)->curiter); + SUNCheckCallNoRet( + AndersonAccelerate(NLS, gy, ycor, yprev, FP_CONTENT(NLS)->curiter)); } /* increment nonlinear solver iteration counter */ @@ -267,6 +245,7 @@ int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, /* compute change in solution, and call the convergence test function */ N_VLinearSum(ONE, ycor, -ONE, yprev, delta); + SUNCheckLastErrNoRet(); /* test for convergence */ retval = FP_CONTENT(NLS)->CTest(NLS, ycor, delta, tol, w, @@ -288,7 +267,7 @@ int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, #endif /* return if successful */ - if (retval == SUN_NLS_SUCCESS) { return (SUN_NLS_SUCCESS); } + if (retval == 0) { return SUN_SUCCESS; } /* check if the iterations should continue; otherwise increment the convergence failure count and return error flag */ @@ -305,10 +284,10 @@ int SUNNonlinSolSolve_FixedPoint(SUNNonlinearSolver NLS, N_Vector y0, return (SUN_NLS_CONV_RECVR); } -int SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return (SUN_NLS_SUCCESS); } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from content structure, then the structure itself */ if (NLS->content) @@ -328,63 +307,50 @@ int SUNNonlinSolFree_FixedPoint(SUNNonlinearSolver NLS) /* free the overall NLS structure */ free(NLS); - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*============================================================================== Set functions ============================================================================*/ -int SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn SysFn) +SUNErrCode SUNNonlinSolSetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that the nonlinear system function is non-null */ - if (SysFn == NULL) { return (SUN_NLS_ILL_INPUT); } - + SUNFunctionBegin(NLS->sunctx); + SUNAssert(SysFn, SUN_ERR_ARG_CORRUPT); FP_CONTENT(NLS)->Sys = SysFn; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolConvTestFn CTestFn, - void* ctest_data) +SUNErrCode SUNNonlinSolSetConvTestFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that the convergence test function is non-null */ - if (CTestFn == NULL) { return (SUN_NLS_ILL_INPUT); } + SUNFunctionBegin(NLS->sunctx); + SUNAssert(CTestFn, SUN_ERR_ARG_CORRUPT); FP_CONTENT(NLS)->CTest = CTestFn; /* attach convergence test data */ FP_CONTENT(NLS)->ctest_data = ctest_data; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, int maxiters) +SUNErrCode SUNNonlinSolSetMaxIters_FixedPoint(SUNNonlinearSolver NLS, int maxiters) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that maxiters is a vaild */ - if (maxiters < 1) { return (SUN_NLS_ILL_INPUT); } - + SUNFunctionBegin(NLS->sunctx); + SUNAssert(maxiters >= 1, SUN_ERR_ARG_OUTOFRANGE); FP_CONTENT(NLS)->maxiters = maxiters; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, sunrealtype beta) +SUNErrCode SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, + sunrealtype beta) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that beta is a vaild */ - if (beta <= ZERO) { return (SUN_NLS_ILL_INPUT); } + SUNFunctionBegin(NLS->sunctx); + SUNAssert(beta > 0, SUN_ERR_ARG_OUTOFRANGE); if (beta < ONE) { @@ -399,53 +365,42 @@ int SUNNonlinSolSetDamping_FixedPoint(SUNNonlinearSolver NLS, sunrealtype beta) FP_CONTENT(NLS)->damping = SUNFALSE; } - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*============================================================================== Get functions ============================================================================*/ -int SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, long int* niters) +SUNErrCode SUNNonlinSolGetNumIters_FixedPoint(SUNNonlinearSolver NLS, + long int* niters) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return number of nonlinear iterations in the last solve */ *niters = FP_CONTENT(NLS)->niters; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, int* iter) +SUNErrCode SUNNonlinSolGetCurIter_FixedPoint(SUNNonlinearSolver NLS, int* iter) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the current nonlinear solver iteration count */ *iter = FP_CONTENT(NLS)->curiter; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, - long int* nconvfails) +SUNErrCode SUNNonlinSolGetNumConvFails_FixedPoint(SUNNonlinearSolver NLS, + long int* nconvfails) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the total number of nonlinear convergence failures */ *nconvfails = FP_CONTENT(NLS)->nconvfails; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn* SysFn) +SUNErrCode SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the nonlinear system defining function */ *SysFn = FP_CONTENT(NLS)->Sys; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*============================================================================= @@ -460,16 +415,13 @@ int SUNNonlinSolGetSysFn_FixedPoint(SUNNonlinearSolver NLS, this array is never changed throughout this routine. The result of the routine is held in x. - - Possible return values: - SUN_NLS_MEM_NULL --> a required item was missing from memory - SUN_NLS_SUCCESS --> successful completion -------------------------------------------------------------*/ -static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, - N_Vector xold, int iter) +static SUNErrCode AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, + N_Vector x, N_Vector xold, int iter) { + SUNFunctionBegin(NLS->sunctx); /* local variables */ - int nvec, retval, i_pt, i, j, lAA, maa, *ipt_map; + int nvec, i_pt, i, j, lAA, maa, *ipt_map; sunrealtype a, b, rtemp, c, s, beta, onembeta, *cvals, *R, *gamma; N_Vector fv, vtemp, gold, fold, *df, *dg, *Q, *Xvecs; sunbooleantype damping; @@ -497,19 +449,25 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, /* update dg[i_pt], df[i_pt], fv, gold and fold*/ N_VLinearSum(ONE, gval, -ONE, xold, fv); + SUNCheckLastErr(); if (iter > 0) { - N_VLinearSum(ONE, gval, -ONE, gold, dg[i_pt]); /* dg_new = gval - gold */ - N_VLinearSum(ONE, fv, -ONE, fold, df[i_pt]); /* df_new = fv - fold */ + N_VLinearSum(ONE, gval, -ONE, gold, dg[i_pt]); + SUNCheckLastErr(); /* dg_new = gval - gold */ + N_VLinearSum(ONE, fv, -ONE, fold, df[i_pt]); + SUNCheckLastErr(); /* df_new = fv - fold */ } N_VScale(ONE, gval, gold); + SUNCheckLastErr(); N_VScale(ONE, fv, fold); + SUNCheckLastErr(); /* on first iteration, just do basic fixed-point update */ if (iter == 0) { N_VScale(ONE, gval, x); - return (SUN_NLS_SUCCESS); + SUNCheckLastErr(); + return SUN_SUCCESS; } /* update data structures based on current iteration index */ @@ -517,26 +475,39 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, if (iter == 1) { /* second iteration */ - R[0] = SUNRsqrt(N_VDotProd(df[i_pt], df[i_pt])); + R[0] = N_VDotProd(df[i_pt], df[i_pt]); + SUNCheckLastErr(); + R[0] = SUNRsqrt(R[0]); N_VScale(ONE / R[0], df[i_pt], Q[i_pt]); + SUNCheckLastErr(); ipt_map[0] = 0; } else if (iter <= maa) { /* another iteration before we've reached maa */ N_VScale(ONE, df[i_pt], vtemp); + SUNCheckLastErr(); for (j = 0; j < iter - 1; j++) { ipt_map[j] = j; R[(iter - 1) * maa + j] = N_VDotProd(Q[j], vtemp); + SUNCheckLastErr(); N_VLinearSum(ONE, vtemp, -R[(iter - 1) * maa + j], Q[j], vtemp); + SUNCheckLastErr(); } - R[(iter - 1) * maa + iter - 1] = SUNRsqrt(N_VDotProd(vtemp, vtemp)); + R[(iter - 1) * maa + iter - 1] = N_VDotProd(vtemp, vtemp); + SUNCheckLastErr(); + R[(iter - 1) * maa + iter - 1] = SUNRsqrt(R[(iter - 1) * maa + iter - 1]); if (R[(iter - 1) * maa + iter - 1] == ZERO) { N_VScale(ZERO, vtemp, Q[i_pt]); + SUNCheckLastErr(); + } + else + { + N_VScale((ONE / R[(iter - 1) * maa + iter - 1]), vtemp, Q[i_pt]); + SUNCheckLastErr(); } - else { N_VScale((ONE / R[(iter - 1) * maa + iter - 1]), vtemp, Q[i_pt]); } ipt_map[iter - 1] = iter - 1; } else @@ -564,8 +535,11 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, } } N_VLinearSum(c, Q[i], s, Q[i + 1], vtemp); + SUNCheckLastErr(); N_VLinearSum(-s, Q[i], c, Q[i + 1], Q[i + 1]); + SUNCheckLastErr(); N_VScale(ONE, vtemp, Q[i]); + SUNCheckLastErr(); } /* ahift R to the left by one */ @@ -576,13 +550,19 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, /* add the new df vector */ N_VScale(ONE, df[i_pt], vtemp); + SUNCheckLastErr(); for (j = 0; j < maa - 1; j++) { R[(maa - 1) * maa + j] = N_VDotProd(Q[j], vtemp); + SUNCheckLastErr(); N_VLinearSum(ONE, vtemp, -R[(maa - 1) * maa + j], Q[j], vtemp); + SUNCheckLastErr(); } - R[(maa - 1) * maa + maa - 1] = SUNRsqrt(N_VDotProd(vtemp, vtemp)); + R[(maa - 1) * maa + maa - 1] = N_VDotProd(vtemp, vtemp); + SUNCheckLastErr(); + R[(maa - 1) * maa + maa - 1] = SUNRsqrt(R[(maa - 1) * maa + maa - 1]); N_VScale((ONE / R[(maa - 1) * maa + maa - 1]), vtemp, Q[maa - 1]); + SUNCheckLastErr(); /* update the iteration map */ j = 0; @@ -593,8 +573,7 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, /* solve least squares problem and update solution */ lAA = iter; if (maa < iter) { lAA = maa; } - retval = N_VDotProdMulti(lAA, fv, Q, gamma); - if (retval != 0) { return (SUN_NLS_VECTOROP_ERR); } + SUNCheckCall(N_VDotProdMulti(lAA, fv, Q, gamma)); /* set arrays for fused vector operation */ cvals[0] = ONE; @@ -626,113 +605,61 @@ static int AndersonAccelerate(SUNNonlinearSolver NLS, N_Vector gval, N_Vector x, } /* update solution */ - retval = N_VLinearCombination(nvec, cvals, Xvecs, x); - if (retval != 0) { return (SUN_NLS_VECTOROP_ERR); } + SUNCheckCall(N_VLinearCombination(nvec, cvals, Xvecs, x)); - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -static int AllocateContent(SUNNonlinearSolver NLS, N_Vector y) +static SUNErrCode AllocateContent(SUNNonlinearSolver NLS, N_Vector y) { + SUNFunctionBegin(NLS->sunctx); int m = FP_CONTENT(NLS)->m; FP_CONTENT(NLS)->yprev = N_VClone(y); - if (FP_CONTENT(NLS)->yprev == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNCheckLastErr(); FP_CONTENT(NLS)->gy = N_VClone(y); - if (FP_CONTENT(NLS)->gy == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNCheckLastErr(); FP_CONTENT(NLS)->delta = N_VClone(y); - if (FP_CONTENT(NLS)->delta == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNCheckLastErr(); /* Allocate all m-dependent content */ if (m > 0) { FP_CONTENT(NLS)->fold = N_VClone(y); - if (FP_CONTENT(NLS)->fold == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNCheckLastErr(); FP_CONTENT(NLS)->gold = N_VClone(y); - if (FP_CONTENT(NLS)->gold == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNCheckLastErr(); FP_CONTENT(NLS)->imap = (int*)malloc(m * sizeof(int)); - if (FP_CONTENT(NLS)->imap == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->imap, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->R = (sunrealtype*)malloc((m * m) * sizeof(sunrealtype)); - if (FP_CONTENT(NLS)->R == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->R, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->gamma = (sunrealtype*)malloc(m * sizeof(sunrealtype)); - if (FP_CONTENT(NLS)->gamma == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->gamma, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->cvals = (sunrealtype*)malloc(2 * (m + 1) * sizeof(sunrealtype)); - if (FP_CONTENT(NLS)->cvals == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->cvals, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->df = N_VCloneVectorArray(m, y); - if (FP_CONTENT(NLS)->df == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->df, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->dg = N_VCloneVectorArray(m, y); - if (FP_CONTENT(NLS)->dg == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->dg, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->q = N_VCloneVectorArray(m, y); - if (FP_CONTENT(NLS)->q == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->q, SUN_ERR_MALLOC_FAIL); FP_CONTENT(NLS)->Xvecs = (N_Vector*)malloc(2 * (m + 1) * sizeof(N_Vector)); - if (FP_CONTENT(NLS)->Xvecs == NULL) - { - FreeContent(NLS); - return (SUN_NLS_MEM_FAIL); - } + SUNAssert(FP_CONTENT(NLS)->Xvecs, SUN_ERR_MALLOC_FAIL); } - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } static void FreeContent(SUNNonlinearSolver NLS) diff --git a/src/sunnonlinsol/newton/fmod/fsunnonlinsol_newton_mod.c b/src/sunnonlinsol/newton/fmod/fsunnonlinsol_newton_mod.c index 94d12cb79b..75ec5441c3 100644 --- a/src/sunnonlinsol/newton/fmod/fsunnonlinsol_newton_mod.c +++ b/src/sunnonlinsol/newton/fmod/fsunnonlinsol_newton_mod.c @@ -253,11 +253,11 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetType_Newton(SUNNonlinearSolver farg1) { SWIGEXPORT int _wrap_FSUNNonlinSolInitialize_Newton(SUNNonlinearSolver farg1) { int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); - result = (int)SUNNonlinSolInitialize_Newton(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolInitialize_Newton(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -289,11 +289,11 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSolve_Newton(SUNNonlinearSolver farg1, N_Vecto SWIGEXPORT int _wrap_FSUNNonlinSolFree_Newton(SUNNonlinearSolver farg1) { int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); - result = (int)SUNNonlinSolFree_Newton(arg1); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolFree_Newton(arg1); + fresult = (SUNErrCode)(result); return fresult; } @@ -302,12 +302,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver farg1, SUNN int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolSysFn arg2 = (SUNNonlinSolSysFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolSysFn)(farg2); - result = (int)SUNNonlinSolSetSysFn_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetSysFn_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -316,12 +316,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver farg1, S int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolLSetupFn arg2 = (SUNNonlinSolLSetupFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolLSetupFn)(farg2); - result = (int)SUNNonlinSolSetLSetupFn_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetLSetupFn_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -330,12 +330,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver farg1, S int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolLSolveFn arg2 = (SUNNonlinSolLSolveFn) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolLSolveFn)(farg2); - result = (int)SUNNonlinSolSetLSolveFn_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetLSolveFn_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -345,13 +345,13 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver farg1, SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolConvTestFn arg2 = (SUNNonlinSolConvTestFn) 0 ; void *arg3 = (void *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolConvTestFn)(farg2); arg3 = (void *)(farg3); - result = (int)SUNNonlinSolSetConvTestFn_Newton(arg1,arg2,arg3); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetConvTestFn_Newton(arg1,arg2,arg3); + fresult = (SUNErrCode)(result); return fresult; } @@ -360,12 +360,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver farg1, i int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; int arg2 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (int)(*farg2); - result = (int)SUNNonlinSolSetMaxIters_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolSetMaxIters_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -374,12 +374,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver farg1, l int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; long *arg2 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (long *)(farg2); - result = (int)SUNNonlinSolGetNumIters_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetNumIters_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -388,12 +388,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver farg1, in int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; int *arg2 = (int *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (int *)(farg2); - result = (int)SUNNonlinSolGetCurIter_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetCurIter_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -402,12 +402,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver farg int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; long *arg2 = (long *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (long *)(farg2); - result = (int)SUNNonlinSolGetNumConvFails_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetNumConvFails_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } @@ -416,12 +416,12 @@ SWIGEXPORT int _wrap_FSUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver farg1, void int fresult ; SUNNonlinearSolver arg1 = (SUNNonlinearSolver) 0 ; SUNNonlinSolSysFn *arg2 = (SUNNonlinSolSysFn *) 0 ; - int result; + SUNErrCode result; arg1 = (SUNNonlinearSolver)(farg1); arg2 = (SUNNonlinSolSysFn *)(farg2); - result = (int)SUNNonlinSolGetSysFn_Newton(arg1,arg2); - fresult = (int)(result); + result = (SUNErrCode)SUNNonlinSolGetSysFn_Newton(arg1,arg2); + fresult = (SUNErrCode)(result); return fresult; } diff --git a/src/sunnonlinsol/newton/sunnonlinsol_newton.c b/src/sunnonlinsol/newton/sunnonlinsol_newton.c index c701724d17..4124d60e29 100644 --- a/src/sunnonlinsol/newton/sunnonlinsol_newton.c +++ b/src/sunnonlinsol/newton/sunnonlinsol_newton.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include @@ -38,22 +38,18 @@ SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNNonlinearSolver NLS; SUNNonlinearSolverContent_Newton content; - /* Check that the supplied N_Vector is non-NULL */ - if (y == NULL) { return (NULL); } - /* Check that the supplied N_Vector supports all required operations */ - if ((y->ops->nvclone == NULL) || (y->ops->nvdestroy == NULL) || - (y->ops->nvscale == NULL) || (y->ops->nvlinearsum == NULL)) - { - return (NULL); - } + SUNAssertNull(y->ops->nvclone && y->ops->nvdestroy && y->ops->nvscale && + y->ops->nvlinearsum, + SUN_ERR_ARG_CORRUPT); /* Create an empty nonlinear linear solver object */ NLS = SUNNonlinSolNewEmpty(sunctx); - if (NLS == NULL) { return (NULL); } + SUNCheckLastErrNull(); /* Attach operations */ NLS->ops->gettype = SUNNonlinSolGetType_Newton; @@ -72,11 +68,7 @@ SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx) /* Create content */ content = NULL; content = (SUNNonlinearSolverContent_Newton)malloc(sizeof *content); - if (content == NULL) - { - SUNNonlinSolFree(NLS); - return (NULL); - } + SUNAssertNull(content, SUN_ERR_MALLOC_FAIL); /* Initialize all components of content to 0/NULL */ memset(content, 0, sizeof(struct _SUNNonlinearSolverContent_Newton)); @@ -104,11 +96,7 @@ SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx) /* Fill allocatable content */ content->delta = N_VClone(y); - if (content->delta == NULL) - { - SUNNonlinSolFree(NLS); - return (NULL); - } + SUNCheckLastErrNull(); return (NLS); } @@ -120,17 +108,21 @@ SUNNonlinearSolver SUNNonlinSol_Newton(N_Vector y, SUNContext sunctx) SUNNonlinearSolver SUNNonlinSol_NewtonSens(int count, N_Vector y, SUNContext sunctx) { + SUNFunctionBegin(sunctx); SUNNonlinearSolver NLS; N_Vector w; /* create sensitivity vector wrapper */ w = N_VNew_SensWrapper(count, y); + SUNCheckLastErrNull(); /* create nonlinear solver using sensitivity vector wrapper */ NLS = SUNNonlinSol_Newton(w, sunctx); + SUNCheckLastErrNull(); /* free sensitivity vector wrapper */ N_VDestroy(w); + SUNCheckLastErrNull(); /* return NLS object */ return (NLS); @@ -145,18 +137,13 @@ SUNNonlinearSolver_Type SUNNonlinSolGetType_Newton(SUNNonlinearSolver NLS) return (SUNNONLINEARSOLVER_ROOTFIND); } -int SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - + SUNFunctionBegin(NLS->sunctx); /* check that all required function pointers have been set */ - if ((NEWTON_CONTENT(NLS)->Sys == NULL) || - (NEWTON_CONTENT(NLS)->LSolve == NULL) || - (NEWTON_CONTENT(NLS)->CTest == NULL)) - { - return (SUN_NLS_MEM_NULL); - } + SUNAssert(NEWTON_CONTENT(NLS)->Sys && NEWTON_CONTENT(NLS)->CTest && + NEWTON_CONTENT(NLS)->LSolve, + SUN_ERR_ARG_CORRUPT); /* reset the total number of iterations and convergence failures */ NEWTON_CONTENT(NLS)->niters = 0; @@ -165,14 +152,14 @@ int SUNNonlinSolInitialize_Newton(SUNNonlinearSolver NLS) /* reset the Jacobian status */ NEWTON_CONTENT(NLS)->jcur = SUNFALSE; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*------------------------------------------------------------------------------ SUNNonlinSolSolve_Newton: Performs the nonlinear solve F(y) = 0 Successful solve return code: - SUN_NLS_SUCCESS = 0 + SUN_SUCCESS = 0 Recoverable failure return codes (positive): SUN_NLS_CONV_RECVR @@ -193,26 +180,21 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, N_Vector w, sunrealtype tol, sunbooleantype callLSetup, void* mem) { + /* Error checks in this function must be NoRet because the return value + is an integer code specific to the SUNNonlinearSolver. */ + + SUNFunctionBegin(NLS->sunctx); /* local variables */ int retval; sunbooleantype jbad; N_Vector delta; - /* check that the inputs are non-null */ - if ((NLS == NULL) || (y0 == NULL) || (ycor == NULL) || (w == NULL) || - (mem == NULL)) - { - return (SUN_NLS_MEM_NULL); - } - /* check that all required function pointers have been set */ - if ((NEWTON_CONTENT(NLS)->Sys == NULL) || - (NEWTON_CONTENT(NLS)->LSolve == NULL) || - (callLSetup && (NEWTON_CONTENT(NLS)->LSetup == NULL)) || - (NEWTON_CONTENT(NLS)->CTest == NULL)) - { - return (SUN_NLS_MEM_NULL); - } + SUNAssertNoRet(NEWTON_CONTENT(NLS)->Sys && NEWTON_CONTENT(NLS)->CTest && + NEWTON_CONTENT(NLS)->LSolve, + SUN_ERR_ARG_CORRUPT); + SUNAssertNoRet(!callLSetup || (callLSetup && NEWTON_CONTENT(NLS)->LSetup), + SUN_ERR_ARG_CORRUPT); /* set local shortcut variables */ delta = NEWTON_CONTENT(NLS)->delta; @@ -232,14 +214,14 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, { /* compute the nonlinear residual, store in delta */ retval = NEWTON_CONTENT(NLS)->Sys(ycor, delta, mem); - if (retval != SUN_NLS_SUCCESS) { break; } + if (retval != SUN_SUCCESS) { break; } /* if indicated, setup the linear system */ if (callLSetup) { retval = NEWTON_CONTENT(NLS)->LSetup(jbad, &(NEWTON_CONTENT(NLS)->jcur), mem); - if (retval != SUN_NLS_SUCCESS) { break; } + if (retval != SUN_SUCCESS) { break; } } /* initialize current iteration counter for this solve attempt */ @@ -267,13 +249,15 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, /* compute the negative of the residual for the linear system rhs */ N_VScale(-ONE, delta, delta); + SUNCheckLastErrNoRet(); /* solve the linear system to get Newton update delta */ retval = NEWTON_CONTENT(NLS)->LSolve(delta, mem); - if (retval != SUN_NLS_SUCCESS) { break; } + if (retval != SUN_SUCCESS) { break; } /* update the Newton iterate */ N_VLinearSum(ONE, ycor, ONE, delta, ycor); + SUNCheckLastErrNoRet(); /* test for convergence */ retval = NEWTON_CONTENT(NLS)->CTest(NLS, ycor, delta, tol, w, @@ -296,10 +280,10 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, #endif /* if successful update Jacobian status and return */ - if (retval == SUN_NLS_SUCCESS) + if (retval == SUN_SUCCESS) { NEWTON_CONTENT(NLS)->jcur = SUNFALSE; - return (SUN_NLS_SUCCESS); + return (SUN_SUCCESS); } /* check if the iteration should continue; otherwise exit Newton loop */ @@ -315,7 +299,7 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, /* compute the nonlinear residual, store in delta */ retval = NEWTON_CONTENT(NLS)->Sys(ycor, delta, mem); - if (retval != SUN_NLS_SUCCESS) { break; } + if (retval != SUN_SUCCESS) { break; } } /* end of Newton iteration loop */ @@ -345,15 +329,17 @@ int SUNNonlinSolSolve_Newton(SUNNonlinearSolver NLS, N_Vector y0, N_Vector ycor, return (retval); } -int SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS) { - /* return if NLS is already free */ - if (NLS == NULL) { return (SUN_NLS_SUCCESS); } - + SUNFunctionBegin(NLS->sunctx); /* free items from contents, then the generic structure */ if (NLS->content) { - if (NEWTON_CONTENT(NLS)->delta) { N_VDestroy(NEWTON_CONTENT(NLS)->delta); } + if (NEWTON_CONTENT(NLS)->delta) + { + N_VDestroy(NEWTON_CONTENT(NLS)->delta); + SUNCheckLastErr(); + } NEWTON_CONTENT(NLS)->delta = NULL; free(NLS->content); @@ -370,119 +356,91 @@ int SUNNonlinSolFree_Newton(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*============================================================================== Set functions ============================================================================*/ -int SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) +SUNErrCode SUNNonlinSolSetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that the nonlinear system function is non-null */ - if (SysFn == NULL) { return (SUN_NLS_ILL_INPUT); } - + SUNFunctionBegin(NLS->sunctx); + SUNAssert(SysFn, SUN_ERR_ARG_CORRUPT); NEWTON_CONTENT(NLS)->Sys = SysFn; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSetupFn LSetupFn) +SUNErrCode SUNNonlinSolSetLSetupFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSetupFn LSetupFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - NEWTON_CONTENT(NLS)->LSetup = LSetupFn; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolLSolveFn LSolveFn) +SUNErrCode SUNNonlinSolSetLSolveFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolLSolveFn LSolveFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that the linear solver solve function is non-null */ - if (LSolveFn == NULL) { return (SUN_NLS_ILL_INPUT); } - + SUNFunctionBegin(NLS->sunctx); + SUNAssert(LSolveFn, SUN_ERR_ARG_CORRUPT); NEWTON_CONTENT(NLS)->LSolve = LSolveFn; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, - SUNNonlinSolConvTestFn CTestFn, - void* ctest_data) +SUNErrCode SUNNonlinSolSetConvTestFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolConvTestFn CTestFn, + void* ctest_data) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that the convergence test function is non-null */ - if (CTestFn == NULL) { return (SUN_NLS_ILL_INPUT); } + SUNFunctionBegin(NLS->sunctx); + SUNAssert(CTestFn, SUN_ERR_ARG_CORRUPT); NEWTON_CONTENT(NLS)->CTest = CTestFn; /* attach convergence test data */ NEWTON_CONTENT(NLS)->ctest_data = ctest_data; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, int maxiters) +SUNErrCode SUNNonlinSolSetMaxIters_Newton(SUNNonlinearSolver NLS, int maxiters) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - - /* check that maxiters is a vaild */ - if (maxiters < 1) { return (SUN_NLS_ILL_INPUT); } - + SUNFunctionBegin(NLS->sunctx); + SUNAssert(maxiters >= 1, SUN_ERR_ARG_OUTOFRANGE); NEWTON_CONTENT(NLS)->maxiters = maxiters; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } /*============================================================================== Get functions ============================================================================*/ -int SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, long int* niters) +SUNErrCode SUNNonlinSolGetNumIters_Newton(SUNNonlinearSolver NLS, long int* niters) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the number of nonlinear iterations in the last solve */ *niters = NEWTON_CONTENT(NLS)->niters; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, int* iter) +SUNErrCode SUNNonlinSolGetCurIter_Newton(SUNNonlinearSolver NLS, int* iter) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the current nonlinear solver iteration count */ *iter = NEWTON_CONTENT(NLS)->curiter; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, - long int* nconvfails) +SUNErrCode SUNNonlinSolGetNumConvFails_Newton(SUNNonlinearSolver NLS, + long int* nconvfails) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the total number of nonlinear convergence failures */ *nconvfails = NEWTON_CONTENT(NLS)->nconvfails; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } -int SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, SUNNonlinSolSysFn* SysFn) +SUNErrCode SUNNonlinSolGetSysFn_Newton(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn) { - /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return (SUN_NLS_MEM_NULL); } - /* return the nonlinear system defining function */ *SysFn = NEWTON_CONTENT(NLS)->Sys; - return (SUN_NLS_SUCCESS); + return SUN_SUCCESS; } diff --git a/src/sunnonlinsol/petscsnes/sunnonlinsol_petscsnes.c b/src/sunnonlinsol/petscsnes/sunnonlinsol_petscsnes.c index 2c7ceee6ac..4889d435ee 100644 --- a/src/sunnonlinsol/petscsnes/sunnonlinsol_petscsnes.c +++ b/src/sunnonlinsol/petscsnes/sunnonlinsol_petscsnes.c @@ -132,7 +132,7 @@ SUNNonlinearSolver_Type SUNNonlinSolGetType_PetscSNES(SUNNonlinearSolver NLS) } /* performs any initialization needed */ -int SUNNonlinSolInitialize_PetscSNES(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolInitialize_PetscSNES(SUNNonlinearSolver NLS) { PetscErrorCode ptcerr; @@ -142,17 +142,17 @@ int SUNNonlinSolInitialize_PetscSNES(SUNNonlinearSolver NLS) if (ptcerr != 0) { SUNNLS_SNES_CONTENT(NLS)->petsc_last_err = ptcerr; - return SUN_NLS_EXT_FAIL; + return SUN_ERR_OP_FAIL; } - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /*------------------------------------------------------------------------------ SUNNonlinSolSolve_PetscSNES: Performs the nonlinear solve F(y) = 0 or G(y) = y Successful solve return code: - SUN_NLS_SUCCESS = 0 + SUN_SUCCESS = 0 Recoverable failure return codes (positive): SUN_NLS_CONV_RECVR @@ -177,7 +177,7 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, /* check that the inputs are non-null */ if ((NLS == NULL) || (y0 == NULL) || (y == NULL) || (w == NULL)) { - return SUN_NLS_MEM_NULL; + return SUN_ERR_ARG_CORRUPT; } /* store a pointer to the integrator memory so it can be @@ -191,7 +191,7 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, ierr = SNESSolve(SUNNLS_SNESOBJ(NLS), NULL, N_VGetVector_Petsc(y)); /* check if the call to the system function failed */ - if (SUNNLS_SNES_CONTENT(NLS)->sysfn_last_err != SUN_NLS_SUCCESS) + if (SUNNLS_SNES_CONTENT(NLS)->sysfn_last_err != SUN_SUCCESS) { return SUNNLS_SNES_CONTENT(NLS)->sysfn_last_err; } @@ -200,7 +200,7 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, if (ierr != 0) { SUNNLS_SNES_CONTENT(NLS)->petsc_last_err = ierr; - return SUN_NLS_EXT_FAIL; /* ierr != 0 is not recoverable with PETSc */ + return SUN_ERR_OP_FAIL; /* ierr != 0 is not recoverable with PETSc */ } /* @@ -212,7 +212,7 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, if (ierr != 0) { SUNNLS_SNES_CONTENT(NLS)->petsc_last_err = ierr; - return SUN_NLS_EXT_FAIL; /* ierr != 0 is not recoverable with PETSc */ + return SUN_ERR_OP_FAIL; /* ierr != 0 is not recoverable with PETSc */ } if ((reason == SNES_CONVERGED_ITERATING) || @@ -221,7 +221,7 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, (reason == SNES_CONVERGED_SNORM_RELATIVE)) { /* success */ - retval = SUN_NLS_SUCCESS; + retval = SUN_SUCCESS; } else { @@ -235,10 +235,10 @@ int SUNNonlinSolSolve_PetscSNES(SUNNonlinearSolver NLS, N_Vector y0, N_Vector y, } /* free the SUNNonlinearSolver */ -int SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS) +SUNErrCode SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS) { /* return if NLS is already free */ - if (NLS == NULL) { return SUN_NLS_SUCCESS; } + if (NLS == NULL) { return SUN_SUCCESS; } /* free items from contents, then the generic structure */ if (NLS->content) @@ -269,7 +269,7 @@ int SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS) /* free the nonlinear solver */ free(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /*============================================================================== @@ -277,16 +277,17 @@ int SUNNonlinSolFree_PetscSNES(SUNNonlinearSolver NLS) ============================================================================*/ /* set the system residual function */ -int SUNNonlinSolSetSysFn_PetscSNES(SUNNonlinearSolver NLS, SUNNonlinSolSysFn SysFn) +SUNErrCode SUNNonlinSolSetSysFn_PetscSNES(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* check that the nonlinear system function is non-null */ - if (SysFn == NULL) { return (SUN_NLS_ILL_INPUT); } + if (SysFn == NULL) { return (SUN_ERR_ARG_INCOMPATIBLE); } SUNNLS_SNES_CONTENT(NLS)->Sys = SysFn; - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /*============================================================================== @@ -294,73 +295,73 @@ int SUNNonlinSolSetSysFn_PetscSNES(SUNNonlinearSolver NLS, SUNNonlinSolSysFn Sys ============================================================================*/ /* get the PETSc SNES context underneath the SUNNonlinearSolver object */ -int SUNNonlinSolGetSNES_PetscSNES(SUNNonlinearSolver NLS, SNES* snes) +SUNErrCode SUNNonlinSolGetSNES_PetscSNES(SUNNonlinearSolver NLS, SNES* snes) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* return the SNES context */ *snes = SUNNLS_SNESOBJ(NLS); - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /* get the last error return by SNES */ -int SUNNonlinSolGetPetscError_PetscSNES(SUNNonlinearSolver NLS, - PetscErrorCode* err) +SUNErrCode SUNNonlinSolGetPetscError_PetscSNES(SUNNonlinearSolver NLS, + PetscErrorCode* err) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* return the last PETSc error code returned by SNES */ *err = SUNNLS_SNES_CONTENT(NLS)->petsc_last_err; - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /* get a pointer to the SUNDIALS integrator-provided system function F(y) */ -int SUNNonlinSolGetSysFn_PetscSNES(SUNNonlinearSolver NLS, - SUNNonlinSolSysFn* SysFn) +SUNErrCode SUNNonlinSolGetSysFn_PetscSNES(SUNNonlinearSolver NLS, + SUNNonlinSolSysFn* SysFn) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* return the nonlinear system defining function */ *SysFn = SUNNLS_SNES_CONTENT(NLS)->Sys; - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /* get the number of iterations performed in the last solve */ -int SUNNonlinSolGetNumIters_PetscSNES(SUNNonlinearSolver NLS, long int* nni) +SUNErrCode SUNNonlinSolGetNumIters_PetscSNES(SUNNonlinearSolver NLS, long int* nni) { int ierr; sunindextype niters; /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } /* get iteration count */ ierr = SNESGetIterationNumber(SUNNLS_SNESOBJ(NLS), &niters); if (ierr != 0) { SUNNLS_SNES_CONTENT(NLS)->petsc_last_err = ierr; - return SUN_NLS_EXT_FAIL; /* ierr != 0 is not recoverable with PETSc */ + return SUN_ERR_OP_FAIL; /* ierr != 0 is not recoverable with PETSc */ } *nni = (long int)niters; - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /* get the total number of nonlinear convergence failures in the lifetime of this SUNNonlinearSolver object */ -int SUNNonlinSolGetNumConvFails_PetscSNES(SUNNonlinearSolver NLS, - long int* nconvfails) +SUNErrCode SUNNonlinSolGetNumConvFails_PetscSNES(SUNNonlinearSolver NLS, + long int* nconvfails) { /* check that the nonlinear solver is non-null */ - if (NLS == NULL) { return SUN_NLS_MEM_NULL; } + if (NLS == NULL) { return SUN_ERR_ARG_CORRUPT; } *nconvfails = SUNNLS_SNES_CONTENT(NLS)->nconvfails; - return SUN_NLS_SUCCESS; + return SUN_SUCCESS; } /*==============================================================================