Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error handling in ida #385

Merged
merged 27 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5dbe6e2
error handling in ida
balos1 Dec 6, 2023
3de7634
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 6, 2023
dda59c0
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
04b178d
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
8f7ce21
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
d80c54c
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
4d30945
Merge branch 'feature/error-handling-just-the-core-formatted' into fe…
balos1 Dec 7, 2023
032efe0
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
ded0740
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 7, 2023
46d0e9f
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
0dd5c9d
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
66582d6
reapply refactor tool
balos1 Dec 8, 2023
44dfaea
remove ida error handler function
balos1 Dec 8, 2023
a00dd89
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
d3148d8
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
dc97664
formatting after merge
balos1 Dec 8, 2023
5466f54
Update src/ida/ida.c
balos1 Dec 8, 2023
a92b7b2
remove errfp reference that was missed
balos1 Dec 8, 2023
99b089e
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 8, 2023
a5bcd4c
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
5c5ab0b
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
370ca62
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 11, 2023
7bd9e7f
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 12, 2023
49f22f0
address comments
balos1 Dec 12, 2023
940f62c
call GetLastError in ProcessError
balos1 Dec 12, 2023
0fbffe6
Merge branch 'feature/error-handling-staging' into feature/error-hand…
balos1 Dec 12, 2023
da712dd
Update src/ida/ida.c
balos1 Dec 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/ida/guide/source/Introduction.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ Users now need to link to ``sundials_core`` in addition to the libraries already
This will be picked up automatically in projects that use the SUNDIALS CMake target. The library ``sundials_generic`` has been superceded by ``sundials_core`` and is no longer available.
This fixes some duplicate symbol errors on Windows when linking to multiple SUNDIALS libraries.

**Breaking change**
The functions ``IDASetErrFile`` and ``IDASetHandlerErrFn`` have been removed.
Users of these functions can use the functions :c:func:`SUNContext_PushErrHandler`,
and :c:func:`SUNLogger_SetErrorFilename` instead. For further details see
Sections :numref:`SUNDIALS.Errors` and :numref:`SUNDIALS.Logging`.

Changes in v6.6.2
-----------------

Expand Down
91 changes: 3 additions & 88 deletions doc/ida/guide/source/Usage/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -893,11 +893,9 @@ an error message to the error handler function. All error return values are
negative, so the test ``flag < 0`` will catch all errors.

The optional input calls can, unless otherwise noted, be executed in any order.
However, if the user’s program calls either :c:func:`IDASetErrFile` or
:c:func:`IDASetErrHandlerFn`, then that call should appear first, in order to
take effect for any later error message. Finally, a call to an ``IDASet***``
function can, unless otherwise noted, be made at any time from the user’s
calling program and, if successful, takes effect immediately.
Finally, a call to an ``IDASet***`` function can, unless otherwise noted, be
made at any time from the user’s calling program and, if successful, takes
effect immediately.


.. _IDA.Usage.CC.optional_input.optin_main:
Expand All @@ -912,10 +910,6 @@ Main solver optional input functions
+--------------------------------------------------------------------+---------------------------------+----------------+
| **Optional input** | **Function name** | **Default** |
+--------------------------------------------------------------------+---------------------------------+----------------+
| Pointer to an error file | :c:func:`IDASetErrFile` | ``stderr`` |
+--------------------------------------------------------------------+---------------------------------+----------------+
| Error handler function | :c:func:`IDASetErrHandlerFn` | internal fn. |
+--------------------------------------------------------------------+---------------------------------+----------------+
| User data | :c:func:`IDASetUserData` | NULL |
+--------------------------------------------------------------------+---------------------------------+----------------+
| Maximum order for BDF method | :c:func:`IDASetMaxOrd` | 5 |
Expand All @@ -942,53 +936,6 @@ Main solver optional input functions
+--------------------------------------------------------------------+---------------------------------+----------------+


.. c:function:: int IDASetErrFile(void * ida_mem, FILE * errfp)
balos1 marked this conversation as resolved.
Show resolved Hide resolved

The function ``IDASetErrFile`` specifies the file pointer where all IDA
messages should be directed when using the default IDA error handler
function.

**Arguments:**
* ``ida_mem`` -- pointer to the IDA solver object.
* ``errfp`` -- pointer to output file.

**Return value:**
* ``IDA_SUCCESS`` -- The optional value has been successfully set.
* ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``.

**Notes:**
The default value for ``errfp`` is ``stderr``. Passing a value ``NULL``
disables all future error message output (except for the case in which the
IDA memory pointer is ``NULL``). This use of :c:func:`IDASetErrFile` is
strongly discouraged.

.. warning::

If :c:func:`IDASetErrFile` is to be called, it should be called before any
other optional input functions, in order to take effect for any later
error message.

.. c:function:: int IDASetErrHandlerFn(void * ida_mem, IDAErrHandlerFn ehfun, void * eh_data)

The function ``IDASetErrHandlerFn`` specifies the optional user-defined
function to be used in handling error messages.

**Arguments:**
* ``ida_mem`` -- pointer to the IDA solver object.
* ``ehfun`` -- is the user's error handler function. See
:c:type:`IDAErrHandlerFn` for more details.
* ``eh_data`` -- pointer to user data passed to ``ehfun`` every time it is
called.

**Return value:**
* ``IDA_SUCCESS`` -- The function ``ehfun`` and data pointer ``eh_data`` have
been successfully set.
* ``IDA_MEM_NULL`` -- The ``ida_mem`` pointer is ``NULL``.

**Notes:**
Error messages indicating that the IDA solver memory is ``NULL`` will always
be directed to ``stderr``.

.. c:function:: int IDASetUserData(void * ida_mem, void * user_data)

The function ``IDASetUserData`` attaches a user-defined data pointer to the
Expand Down Expand Up @@ -3251,38 +3198,6 @@ The user must provide a function of type :c:type:`IDAResFn` defined as follows:
following integration step, but a successful step cannot be undone.)


.. _IDA.Usage.CC.user_fct_sim.ehFn:

Error message handler function
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

As an alternative to the default behavior of directing error and warning
messages to the file pointed to by ``errfp`` (see :c:func:`IDASetErrFile`), the
user may provide a function of type :c:type:`IDAErrHandlerFn` to process any
such messages. The function type :c:type:`IDAErrHandlerFn` is defined as
follows:

.. c:type:: void (*IDAErrHandlerFn)(int error_code, const char *module, const char *function, char *msg, void *user_data)

This function processes error and warning messages from IDA and its
sub-modules.

**Arguments:**
* ``error_code`` -- is the error code.
* ``module`` -- is the name of the IDA module reporting the error.
* ``function`` -- is the name of the function in which the error occurred.
* ``eH_data`` -- is a pointer to user data, the same as the ``eh_data``
parameter passed to :c:func:`IDASetErrHandlerFn`.

**Return value:**
This function has no return value.

**Notes:**
``error_code`` is negative for errors and positive (``IDA_WARNING``) for
warnings. If a function that returns a pointer to memory encounters an error,
it sets ``error_code`` to 0.


.. _IDA.Usage.CC.user_fct_sim.ewtsetFn:

Error weight function
Expand Down
6 changes: 0 additions & 6 deletions include/ida/ida.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,6 @@ typedef int (*IDARootFn)(sunrealtype t, N_Vector y, N_Vector yp,

typedef int (*IDAEwtFn)(N_Vector y, N_Vector ewt, void* user_data);

typedef void (*IDAErrHandlerFn)(int error_code, const char* module,
const char* function, char* msg, void* user_data);

/* -------------------
* Exported Functions
* ------------------- */
Expand Down Expand Up @@ -128,9 +125,6 @@ SUNDIALS_EXPORT int IDASetMaxBacksIC(void* ida_mem, int maxbacks);

/* Optional input functions */
SUNDIALS_EXPORT int IDASetDeltaCjLSetup(void* ida_max, sunrealtype dcj);
SUNDIALS_EXPORT int IDASetErrHandlerFn(void* ida_mem, IDAErrHandlerFn ehfun,
balos1 marked this conversation as resolved.
Show resolved Hide resolved
void* eh_data);
SUNDIALS_EXPORT int IDASetErrFile(void* ida_mem, FILE* errfp);
SUNDIALS_EXPORT int IDASetUserData(void* ida_mem, void* user_data);
SUNDIALS_EXPORT int IDASetMaxOrd(void* ida_mem, int maxord);
SUNDIALS_EXPORT int IDASetMaxNumSteps(void* ida_mem, long int mxsteps);
Expand Down
30 changes: 0 additions & 30 deletions src/ida/fmod/fida_mod.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,36 +459,6 @@ SWIGEXPORT int _wrap_FIDASetDeltaCjLSetup(void *farg1, double const *farg2) {
}


SWIGEXPORT int _wrap_FIDASetErrHandlerFn(void *farg1, IDAErrHandlerFn farg2, void *farg3) {
int fresult ;
void *arg1 = (void *) 0 ;
IDAErrHandlerFn arg2 = (IDAErrHandlerFn) 0 ;
void *arg3 = (void *) 0 ;
int result;

arg1 = (void *)(farg1);
arg2 = (IDAErrHandlerFn)(farg2);
arg3 = (void *)(farg3);
result = (int)IDASetErrHandlerFn(arg1,arg2,arg3);
fresult = (int)(result);
return fresult;
}


SWIGEXPORT int _wrap_FIDASetErrFile(void *farg1, void *farg2) {
int fresult ;
void *arg1 = (void *) 0 ;
FILE *arg2 = (FILE *) 0 ;
int result;

arg1 = (void *)(farg1);
arg2 = (FILE *)(farg2);
result = (int)IDASetErrFile(arg1,arg2);
fresult = (int)(result);
return fresult;
}


SWIGEXPORT int _wrap_FIDASetUserData(void *farg1, void *farg2) {
int fresult ;
void *arg1 = (void *) 0 ;
Expand Down
56 changes: 0 additions & 56 deletions src/ida/fmod/fida_mod.f90
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ module fida_mod
public :: FIDASetStepToleranceIC
public :: FIDASetMaxBacksIC
public :: FIDASetDeltaCjLSetup
public :: FIDASetErrHandlerFn
public :: FIDASetErrFile
public :: FIDASetUserData
public :: FIDASetMaxOrd
public :: FIDASetMaxNumSteps
Expand Down Expand Up @@ -340,25 +338,6 @@ function swigc_FIDASetDeltaCjLSetup(farg1, farg2) &
integer(C_INT) :: fresult
end function

function swigc_FIDASetErrHandlerFn(farg1, farg2, farg3) &
bind(C, name="_wrap_FIDASetErrHandlerFn") &
result(fresult)
use, intrinsic :: ISO_C_BINDING
type(C_PTR), value :: farg1
type(C_FUNPTR), value :: farg2
type(C_PTR), value :: farg3
integer(C_INT) :: fresult
end function

function swigc_FIDASetErrFile(farg1, farg2) &
bind(C, name="_wrap_FIDASetErrFile") &
result(fresult)
use, intrinsic :: ISO_C_BINDING
type(C_PTR), value :: farg1
type(C_PTR), value :: farg2
integer(C_INT) :: fresult
end function

function swigc_FIDASetUserData(farg1, farg2) &
bind(C, name="_wrap_FIDASetUserData") &
result(fresult)
Expand Down Expand Up @@ -1470,41 +1449,6 @@ function FIDASetDeltaCjLSetup(ida_max, dcj) &
swig_result = fresult
end function

function FIDASetErrHandlerFn(ida_mem, ehfun, eh_data) &
result(swig_result)
use, intrinsic :: ISO_C_BINDING
integer(C_INT) :: swig_result
type(C_PTR) :: ida_mem
type(C_FUNPTR), intent(in), value :: ehfun
type(C_PTR) :: eh_data
integer(C_INT) :: fresult
type(C_PTR) :: farg1
type(C_FUNPTR) :: farg2
type(C_PTR) :: farg3

farg1 = ida_mem
farg2 = ehfun
farg3 = eh_data
fresult = swigc_FIDASetErrHandlerFn(farg1, farg2, farg3)
swig_result = fresult
end function

function FIDASetErrFile(ida_mem, errfp) &
result(swig_result)
use, intrinsic :: ISO_C_BINDING
integer(C_INT) :: swig_result
type(C_PTR) :: ida_mem
type(C_PTR) :: errfp
integer(C_INT) :: fresult
type(C_PTR) :: farg1
type(C_PTR) :: farg2

farg1 = ida_mem
farg2 = errfp
fresult = swigc_FIDASetErrFile(farg1, farg2)
swig_result = fresult
end function

function FIDASetUserData(ida_mem, user_data) &
result(swig_result)
use, intrinsic :: ISO_C_BINDING
Expand Down
Loading
Loading