From 2d2117f7bff3ea2e3deb167cd5542c01bc7d0cb1 Mon Sep 17 00:00:00 2001 From: Steven Roberts Date: Wed, 15 May 2024 20:48:42 -0700 Subject: [PATCH 1/3] Fix promotion of double to sunrealtype identified with -Wdouble-promotion --- src/arkode/arkode.c | 24 +++++++++--------------- src/arkode/arkode_io.c | 2 +- src/arkode/arkode_sprk.c | 10 +++++----- src/cvodes/cvodea.c | 2 +- src/sundials/sundials_band.c | 2 +- src/sundials/sundials_dense.c | 2 +- src/sunmatrix/sparse/sunmatrix_sparse.c | 4 ++-- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index 098d0756c6..dca47469fd 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -1559,10 +1559,8 @@ int arkRwtSet(N_Vector y, N_Vector weight, void* data) flag = ark_mem->step_mmult((void*)ark_mem, y, My); if (flag != ARK_SUCCESS) { return (ARK_MASSMULT_FAIL); } } - else - { /* this condition should not apply, but just in case */ - N_VScale(ONE, y, My); - } + else { /* this condition should not apply, but just in case */ + N_VScale(ONE, y, My); } /* call appropriate routine to fill rwt */ switch (ark_mem->ritol) @@ -1871,10 +1869,8 @@ int arkInitialSetup(ARKodeMem ark_mem, sunrealtype tout) } /* Load initial residual weights */ - if (ark_mem->rwt_is_ewt) - { /* update pointer to ewt */ - ark_mem->rwt = ark_mem->ewt; - } + if (ark_mem->rwt_is_ewt) { /* update pointer to ewt */ + ark_mem->rwt = ark_mem->ewt; } else { retval = ark_mem->rfun(ark_mem->yn, ark_mem->rwt, ark_mem->r_data); @@ -2816,8 +2812,8 @@ int arkPredict_MaximumOrder(ARKodeMem ark_mem, sunrealtype tau, N_Vector yguess) int arkPredict_VariableOrder(ARKodeMem ark_mem, sunrealtype tau, N_Vector yguess) { int ord; - sunrealtype tau_tol = 0.5; - sunrealtype tau_tol2 = 0.75; + sunrealtype tau_tol = HALF; + sunrealtype tau_tol2 = SUN_RCONST(0.75); /* verify that ark_mem and interpolation structure are provided */ if (ark_mem == NULL) @@ -2854,7 +2850,7 @@ int arkPredict_VariableOrder(ARKodeMem ark_mem, sunrealtype tau, N_Vector yguess int arkPredict_CutoffOrder(ARKodeMem ark_mem, sunrealtype tau, N_Vector yguess) { int ord; - sunrealtype tau_tol = 0.5; + sunrealtype tau_tol = HALF; /* verify that ark_mem and interpolation structure are provided */ if (ark_mem == NULL) @@ -3364,10 +3360,8 @@ sunbooleantype arkResizeVectors(ARKodeMem ark_mem, ARKVecResizeFn resize, } /* rwt */ - if (ark_mem->rwt_is_ewt) - { /* update pointer to ewt */ - ark_mem->rwt = ark_mem->ewt; - } + if (ark_mem->rwt_is_ewt) { /* update pointer to ewt */ + ark_mem->rwt = ark_mem->ewt; } else { /* resize if distinct from ewt */ if (!arkResizeVec(ark_mem, resize, resize_data, lrw_diff, liw_diff, tmpl, diff --git a/src/arkode/arkode_io.c b/src/arkode/arkode_io.c index 291a61ec35..c1d73c866c 100644 --- a/src/arkode/arkode_io.c +++ b/src/arkode/arkode_io.c @@ -1588,7 +1588,7 @@ int ARKodeSetErrorBias(void* arkode_mem, sunrealtype bias) /* set allowed value, otherwise set default */ if (bias < ONE) { - retval = SUNAdaptController_SetErrorBias(hadapt_mem->hcontroller, -1.0); + retval = SUNAdaptController_SetErrorBias(hadapt_mem->hcontroller, -ONE); } else { diff --git a/src/arkode/arkode_sprk.c b/src/arkode/arkode_sprk.c index 974228afd1..18ffc6ee30 100644 --- a/src/arkode/arkode_sprk.c +++ b/src/arkode/arkode_sprk.c @@ -137,7 +137,7 @@ ARKodeSPRKTable ARKodeSymplecticMcLachlan2(void) sprk_table->q = 2; sprk_table->stages = 2; sprk_table->a[1] = SUN_RCONST(1.0) - - (SUN_RCONST(1.0) / SUN_RCONST(2.0)) * SUNRsqrt(2.0); + (SUN_RCONST(1.0) / SUN_RCONST(2.0)) * SUNRsqrt(SUN_RCONST(2.0)); sprk_table->a[0] = SUN_RCONST(1.0) - sprk_table->a[1]; sprk_table->ahat[1] = SUN_RCONST(1.0) / (SUN_RCONST(2.0) * (SUN_RCONST(1.0) - sprk_table->a[1])); @@ -147,9 +147,9 @@ ARKodeSPRKTable ARKodeSymplecticMcLachlan2(void) ARKodeSPRKTable ARKodeSymplecticMcLachlan3(void) { - sunrealtype w = 0.0; - sunrealtype y = 0.0; - sunrealtype z = 0.0; + sunrealtype w = SUN_RCONST(0.0); + sunrealtype y = SUN_RCONST(0.0); + sunrealtype z = SUN_RCONST(0.0); ARKodeSPRKTable sprk_table = ARKodeSPRKTable_Alloc(3); if (!sprk_table) { return NULL; } @@ -157,7 +157,7 @@ ARKodeSPRKTable ARKodeSymplecticMcLachlan3(void) sprk_table->stages = 3; z = -SUNRpowerR((SUN_RCONST(2.0) / SUN_RCONST(27.0)) - - SUN_RCONST(1.0) / (SUN_RCONST(9.0) * SUNRsqrt(3.0)), + SUN_RCONST(1.0) / (SUN_RCONST(9.0) * SUNRsqrt(SUN_RCONST(3.0))), SUN_RCONST(1.0) / SUN_RCONST(3.0)); w = -SUN_RCONST(2.0) / SUN_RCONST(3.0) + SUN_RCONST(1.0) / (SUN_RCONST(9.0) * z) + z; diff --git a/src/cvodes/cvodea.c b/src/cvodes/cvodea.c index fd4ae06f97..2df97cf712 100644 --- a/src/cvodes/cvodea.c +++ b/src/cvodes/cvodea.c @@ -1793,7 +1793,7 @@ static CVckpntMem CVAckpntInit(CVodeMem cv_mem) ck_mem->ck_t0 = cv_mem->cv_tn; ck_mem->ck_nst = 0; ck_mem->ck_q = 1; - ck_mem->ck_h = 0.0; + ck_mem->ck_h = ZERO; /* Do we need to carry quadratures */ ck_mem->ck_quadr = cv_mem->cv_quadr && cv_mem->cv_errconQ; diff --git a/src/sundials/sundials_band.c b/src/sundials/sundials_band.c index e8051d80c1..4124c701ea 100644 --- a/src/sundials/sundials_band.c +++ b/src/sundials/sundials_band.c @@ -322,7 +322,7 @@ void SUNDlsMat_bandMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, sunindextype i, j, is, ie; sunrealtype* col_j; - for (i = 0; i < n; i++) { y[i] = 0.0; } + for (i = 0; i < n; i++) { y[i] = ZERO; } for (j = 0; j < n; j++) { diff --git a/src/sundials/sundials_dense.c b/src/sundials/sundials_dense.c index f022212f9c..f037fefbdf 100644 --- a/src/sundials/sundials_dense.c +++ b/src/sundials/sundials_dense.c @@ -502,7 +502,7 @@ void SUNDlsMat_denseMatvec(sunrealtype** a, sunrealtype* x, sunrealtype* y, sunindextype i, j; sunrealtype* col_j; - for (i = 0; i < m; i++) { y[i] = 0.0; } + for (i = 0; i < m; i++) { y[i] = ZERO; } for (j = 0; j < n; j++) { diff --git a/src/sunmatrix/sparse/sunmatrix_sparse.c b/src/sunmatrix/sparse/sunmatrix_sparse.c index 96754afbd6..ff2d1db1ce 100644 --- a/src/sunmatrix/sparse/sunmatrix_sparse.c +++ b/src/sunmatrix/sparse/sunmatrix_sparse.c @@ -1187,7 +1187,7 @@ SUNErrCode Matvec_SparseCSC(SUNMatrix A, N_Vector x, N_Vector y) SUNCheckLastErr(); /* initialize result */ - for (i = 0; i < SM_ROWS_S(A); i++) { yd[i] = 0.0; } + for (i = 0; i < SM_ROWS_S(A); i++) { yd[i] = ZERO; } /* iterate through matrix columns */ for (j = 0; j < SM_COLUMNS_S(A); j++) @@ -1230,7 +1230,7 @@ SUNErrCode Matvec_SparseCSR(SUNMatrix A, N_Vector x, N_Vector y) SUNAssert(yd, SUN_ERR_ARG_CORRUPT); SUNAssert(xd != yd, SUN_ERR_ARG_CORRUPT); /* initialize result */ - for (i = 0; i < SM_ROWS_S(A); i++) { yd[i] = 0.0; } + for (i = 0; i < SM_ROWS_S(A); i++) { yd[i] = ZERO; } /* iterate through matrix rows */ for (i = 0; i < SM_ROWS_S(A); i++) From 7c43fe48308f31d7e2232269f020ed2806ae8c4c Mon Sep 17 00:00:00 2001 From: Steven Roberts Date: Wed, 15 May 2024 20:53:50 -0700 Subject: [PATCH 2/3] Apply formatter --- src/arkode/arkode.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/arkode/arkode.c b/src/arkode/arkode.c index dca47469fd..cddd647a34 100644 --- a/src/arkode/arkode.c +++ b/src/arkode/arkode.c @@ -1559,8 +1559,10 @@ int arkRwtSet(N_Vector y, N_Vector weight, void* data) flag = ark_mem->step_mmult((void*)ark_mem, y, My); if (flag != ARK_SUCCESS) { return (ARK_MASSMULT_FAIL); } } - else { /* this condition should not apply, but just in case */ - N_VScale(ONE, y, My); } + else + { /* this condition should not apply, but just in case */ + N_VScale(ONE, y, My); + } /* call appropriate routine to fill rwt */ switch (ark_mem->ritol) @@ -1869,8 +1871,10 @@ int arkInitialSetup(ARKodeMem ark_mem, sunrealtype tout) } /* Load initial residual weights */ - if (ark_mem->rwt_is_ewt) { /* update pointer to ewt */ - ark_mem->rwt = ark_mem->ewt; } + if (ark_mem->rwt_is_ewt) + { /* update pointer to ewt */ + ark_mem->rwt = ark_mem->ewt; + } else { retval = ark_mem->rfun(ark_mem->yn, ark_mem->rwt, ark_mem->r_data); @@ -3360,8 +3364,10 @@ sunbooleantype arkResizeVectors(ARKodeMem ark_mem, ARKVecResizeFn resize, } /* rwt */ - if (ark_mem->rwt_is_ewt) { /* update pointer to ewt */ - ark_mem->rwt = ark_mem->ewt; } + if (ark_mem->rwt_is_ewt) + { /* update pointer to ewt */ + ark_mem->rwt = ark_mem->ewt; + } else { /* resize if distinct from ewt */ if (!arkResizeVec(ark_mem, resize, resize_data, lrw_diff, liw_diff, tmpl, From d3c42bdf3bd15d81d2938239e2f9620449043bae Mon Sep 17 00:00:00 2001 From: Steven Roberts Date: Wed, 15 May 2024 20:59:59 -0700 Subject: [PATCH 3/3] Apply formatter --- src/arkode/arkode_sprk.c | 7 ++++--- src/sunmatrix/sparse/sunmatrix_sparse.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/arkode/arkode_sprk.c b/src/arkode/arkode_sprk.c index 18ffc6ee30..c5e17837ab 100644 --- a/src/arkode/arkode_sprk.c +++ b/src/arkode/arkode_sprk.c @@ -136,8 +136,8 @@ ARKodeSPRKTable ARKodeSymplecticMcLachlan2(void) if (!sprk_table) { return NULL; } sprk_table->q = 2; sprk_table->stages = 2; - sprk_table->a[1] = SUN_RCONST(1.0) - - (SUN_RCONST(1.0) / SUN_RCONST(2.0)) * SUNRsqrt(SUN_RCONST(2.0)); + sprk_table->a[1] = SUN_RCONST(1.0) - (SUN_RCONST(1.0) / SUN_RCONST(2.0)) * + SUNRsqrt(SUN_RCONST(2.0)); sprk_table->a[0] = SUN_RCONST(1.0) - sprk_table->a[1]; sprk_table->ahat[1] = SUN_RCONST(1.0) / (SUN_RCONST(2.0) * (SUN_RCONST(1.0) - sprk_table->a[1])); @@ -157,7 +157,8 @@ ARKodeSPRKTable ARKodeSymplecticMcLachlan3(void) sprk_table->stages = 3; z = -SUNRpowerR((SUN_RCONST(2.0) / SUN_RCONST(27.0)) - - SUN_RCONST(1.0) / (SUN_RCONST(9.0) * SUNRsqrt(SUN_RCONST(3.0))), + SUN_RCONST(1.0) / + (SUN_RCONST(9.0) * SUNRsqrt(SUN_RCONST(3.0))), SUN_RCONST(1.0) / SUN_RCONST(3.0)); w = -SUN_RCONST(2.0) / SUN_RCONST(3.0) + SUN_RCONST(1.0) / (SUN_RCONST(9.0) * z) + z; diff --git a/src/sunmatrix/sparse/sunmatrix_sparse.c b/src/sunmatrix/sparse/sunmatrix_sparse.c index ff2d1db1ce..18d644dba5 100644 --- a/src/sunmatrix/sparse/sunmatrix_sparse.c +++ b/src/sunmatrix/sparse/sunmatrix_sparse.c @@ -1298,7 +1298,7 @@ SUNErrCode format_convert(const SUNMatrix A, SUNMatrix B) sunindextype jj; for (jj = Ap[row]; jj < Ap[row + 1]; jj++) { - sunindextype col = Aj[jj]; + col = Aj[jj]; sunindextype dest = Bp[col]; Bi[dest] = row;