Skip to content

Commit

Permalink
error handling in cvodes
Browse files Browse the repository at this point in the history
  • Loading branch information
balos1 committed Dec 6, 2023
1 parent 6e74b6b commit 36fe1db
Show file tree
Hide file tree
Showing 15 changed files with 890 additions and 1,120 deletions.
169 changes: 88 additions & 81 deletions src/cvodes/cvodea.c

Large diffs are not rendered by default.

116 changes: 46 additions & 70 deletions src/cvodes/cvodea_io.c

Large diffs are not rendered by default.

751 changes: 323 additions & 428 deletions src/cvodes/cvodes.c

Large diffs are not rendered by default.

61 changes: 29 additions & 32 deletions src/cvodes/cvodes_bandpre.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,

if (cvode_mem == NULL)
{
cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_MEM_NULL);
return (CVLS_MEM_NULL);
}
Expand All @@ -79,7 +79,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
/* Test if the CVSLS linear solver interface has been attached */
if (cv_mem->cv_lmem == NULL)
{
cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_LMEM_NULL);
return (CVLS_LMEM_NULL);
}
Expand All @@ -88,7 +88,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
/* Test compatibility of NVECTOR package with the BAND preconditioner */
if (cv_mem->cv_tempv->ops->nvgetarraypointer == NULL)
{
cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__,
MSGBP_BAD_NVECTOR);
return (CVLS_ILL_INPUT);
}
Expand All @@ -98,7 +98,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
pdata = (CVBandPrecData)malloc(sizeof *pdata);
if (pdata == NULL)
{
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -119,7 +119,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
{
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -133,7 +133,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
SUNMatDestroy(pdata->savedJ);
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -147,7 +147,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
SUNMatDestroy(pdata->savedJ);
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -162,7 +162,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
SUNMatDestroy(pdata->savedJ);
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -176,7 +176,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
N_VDestroy(pdata->tmp1);
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_MEM_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_MEM_FAIL, __LINE__, __func__, __FILE__,
MSGBP_MEM_FAIL);
return (CVLS_MEM_FAIL);
}
Expand All @@ -192,7 +192,7 @@ int CVBandPrecInit(void* cvode_mem, sunindextype N, sunindextype mu,
N_VDestroy(pdata->tmp2);
free(pdata);
pdata = NULL;
cvProcessError(cv_mem, CVLS_SUNLS_FAIL, "CVSBANDPRE", "CVBandPrecInit",
cvProcessError(cv_mem, CVLS_SUNLS_FAIL, __LINE__, __func__, __FILE__,
MSGBP_SUNLS_FAIL);
return (CVLS_SUNLS_FAIL);
}
Expand Down Expand Up @@ -222,24 +222,24 @@ int CVBandPrecGetWorkSpace(void* cvode_mem, long int* lenrwBP, long int* leniwBP

if (cvode_mem == NULL)
{
cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", "CVBandPrecGetWorkSpace",
cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_MEM_NULL);
return (CVLS_MEM_NULL);
}
cv_mem = (CVodeMem)cvode_mem;

if (cv_mem->cv_lmem == NULL)
{
cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE",
"CVBandPrecGetWorkSpace", MSGBP_LMEM_NULL);
cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_LMEM_NULL);
return (CVLS_LMEM_NULL);
}
cvls_mem = (CVLsMem)cv_mem->cv_lmem;

if (cvls_mem->P_data == NULL)
{
cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBANDPRE",
"CVBandPrecGetWorkSpace", MSGBP_PMEM_NULL);
cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_PMEM_NULL);
return (CVLS_PMEM_NULL);
}
pdata = (CVBandPrecData)cvls_mem->P_data;
Expand Down Expand Up @@ -286,24 +286,24 @@ int CVBandPrecGetNumRhsEvals(void* cvode_mem, long int* nfevalsBP)

if (cvode_mem == NULL)
{
cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE",
"CVBandPrecGetNumRhsEvals", MSGBP_MEM_NULL);
cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_MEM_NULL);
return (CVLS_MEM_NULL);
}
cv_mem = (CVodeMem)cvode_mem;

if (cv_mem->cv_lmem == NULL)
{
cvProcessError(cv_mem, CVLS_LMEM_NULL, "CVSBANDPRE",
"CVBandPrecGetNumRhsEvals", MSGBP_LMEM_NULL);
cvProcessError(cv_mem, CVLS_LMEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_LMEM_NULL);
return (CVLS_LMEM_NULL);
}
cvls_mem = (CVLsMem)cv_mem->cv_lmem;

if (cvls_mem->P_data == NULL)
{
cvProcessError(cv_mem, CVLS_PMEM_NULL, "CVSBANDPRE",
"CVBandPrecGetNumRhsEvals", MSGBP_PMEM_NULL);
cvProcessError(cv_mem, CVLS_PMEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_PMEM_NULL);
return (CVLS_PMEM_NULL);
}
pdata = (CVBandPrecData)cvls_mem->P_data;
Expand Down Expand Up @@ -373,8 +373,7 @@ static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy,
retval = SUNMatCopy(pdata->savedJ, pdata->savedP);
if (retval < 0)
{
cvProcessError(cv_mem, -1, "CVBANDPRE", "cvBandPrecSetup",
MSGBP_SUNMAT_FAIL);
cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL);
return (-1);
}
if (retval > 0) { return (1); }
Expand All @@ -386,16 +385,15 @@ static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy,
retval = SUNMatZero(pdata->savedJ);
if (retval < 0)
{
cvProcessError(cv_mem, -1, "CVBANDPRE", "cvBandPrecSetup",
MSGBP_SUNMAT_FAIL);
cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL);
return (-1);
}
if (retval > 0) { return (1); }

retval = cvBandPrecDQJac(pdata, t, y, fy, pdata->tmp1, pdata->tmp2);
if (retval < 0)
{
cvProcessError(cv_mem, -1, "CVBANDPRE", "cvBandPrecSetup",
cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__,
MSGBP_RHSFUNC_FAILED);
return (-1);
}
Expand All @@ -404,8 +402,7 @@ static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy,
retval = SUNMatCopy(pdata->savedJ, pdata->savedP);
if (retval < 0)
{
cvProcessError(cv_mem, -1, "CVBANDPRE", "cvBandPrecSetup",
MSGBP_SUNMAT_FAIL);
cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL);
return (-1);
}
if (retval > 0) { return (1); }
Expand All @@ -415,7 +412,7 @@ static int cvBandPrecSetup(sunrealtype t, N_Vector y, N_Vector fy,
retval = SUNMatScaleAddI(-gamma, pdata->savedP);
if (retval)
{
cvProcessError(cv_mem, -1, "CVBANDPRE", "cvBandPrecSetup", MSGBP_SUNMAT_FAIL);
cvProcessError(cv_mem, -1, __LINE__, __func__, __FILE__, MSGBP_SUNMAT_FAIL);
return (-1);
}

Expand Down Expand Up @@ -615,7 +612,7 @@ int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB,
/* Check if cvode_mem exists */
if (cvode_mem == NULL)
{
cvProcessError(NULL, CVLS_MEM_NULL, "CVSBANDPRE", "CVBandPrecInitB",
cvProcessError(NULL, CVLS_MEM_NULL, __LINE__, __func__, __FILE__,
MSGBP_MEM_NULL);
return (CVLS_MEM_NULL);
}
Expand All @@ -624,7 +621,7 @@ int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB,
/* Was ASA initialized? */
if (cv_mem->cv_adjMallocDone == SUNFALSE)
{
cvProcessError(cv_mem, CVLS_NO_ADJ, "CVSBANDPRE", "CVBandPrecInitB",
cvProcessError(cv_mem, CVLS_NO_ADJ, __LINE__, __func__, __FILE__,
MSGBP_NO_ADJ);
return (CVLS_NO_ADJ);
}
Expand All @@ -633,7 +630,7 @@ int CVBandPrecInitB(void* cvode_mem, int which, sunindextype nB,
/* Check which */
if (which >= ca_mem->ca_nbckpbs)
{
cvProcessError(cv_mem, CVLS_ILL_INPUT, "CVSBANDPRE", "CVBandPrecInitB",
cvProcessError(cv_mem, CVLS_ILL_INPUT, __LINE__, __func__, __FILE__,
MSGBP_BAD_WHICH);
return (CVLS_ILL_INPUT);
}
Expand Down
Loading

0 comments on commit 36fe1db

Please sign in to comment.