]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Avoid C-style cast in sundials 7482/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 28 Nov 2018 11:10:11 +0000 (12:10 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 28 Nov 2018 11:10:11 +0000 (12:10 +0100)
source/sundials/arkode.cc
source/sundials/ida.cc
source/sundials/kinsol.cc

index 64bd8be758af62bab299b7fca64b43fd8f6b5c51..ab88f08bc5eaadb03edded6ee54417af88b1adef 100644 (file)
@@ -132,12 +132,15 @@ namespace SUNDIALS
       copy(*src_ypred, ypred);
       copy(*src_fpred, fpred);
 
-      int err = solver.setup_jacobian(convfail,
+      // avoid reinterpret_cast
+      bool jcurPtr_tmp = false;
+      int  err         = solver.setup_jacobian(convfail,
                                       arkode_mem->ark_tn,
                                       arkode_mem->ark_gamma,
                                       *src_ypred,
                                       *src_fpred,
-                                      (bool &)*jcurPtr);
+                                      jcurPtr_tmp);
+      *jcurPtr         = jcurPtr_tmp ? SUNTRUE : SUNFALSE;
 
       return err;
     }
@@ -424,7 +427,7 @@ namespace SUNDIALS
     status = ARKodeSetInitStep(arkode_mem, current_time_step);
     AssertARKode(status);
 
-    status = ARKodeSetUserData(arkode_mem, (void *)this);
+    status = ARKodeSetUserData(arkode_mem, this);
     AssertARKode(status);
 
     status = ARKodeSetStopTime(arkode_mem, data.final_time);
@@ -435,7 +438,7 @@ namespace SUNDIALS
     AssertARKode(status);
 
     // Initialize solver
-    ARKodeMem ARKode_mem = (ARKodeMem)arkode_mem;
+    auto ARKode_mem = static_cast<ARKodeMem>(arkode_mem);
 
     if (solve_jacobian_system)
       {
index 31ea6417f4eeca7e482306406d9673b152993e8a..b1b39328de255611f1b09518a93c98c66d4eb5dc 100644 (file)
@@ -362,7 +362,7 @@ namespace SUNDIALS
     status = IDASetInitStep(ida_mem, current_time_step);
     AssertIDA(status);
 
-    status = IDASetUserData(ida_mem, (void *)this);
+    status = IDASetUserData(ida_mem, this);
     AssertIDA(status);
 
     if (data.ic_type == AdditionalData::use_y_diff ||
@@ -391,8 +391,7 @@ namespace SUNDIALS
     AssertIDA(status);
 
     // Initialize solver
-    IDAMem IDA_mem;
-    IDA_mem = (IDAMem)ida_mem;
+    auto IDA_mem = static_cast<IDAMem>(ida_mem);
 
     IDA_mem->ida_lsetup = t_dae_lsetup<VectorType>;
     IDA_mem->ida_lsolve = t_dae_solve<VectorType>;
index 273bf3a3555f85c927aec9979d4e301a3039da27..e0bb952b04fbfc82965336ef8fa2e43faca1cf47 100644 (file)
@@ -238,7 +238,7 @@ namespace SUNDIALS
     (void)status;
     AssertKINSOL(status);
 
-    status = KINSetUserData(kinsol_mem, (void *)this);
+    status = KINSetUserData(kinsol_mem, static_cast<void *>(this));
     AssertKINSOL(status);
 
     status = KINSetNumMaxIters(kinsol_mem, data.maximum_non_linear_iterations);
@@ -253,7 +253,7 @@ namespace SUNDIALS
     status = KINSetMaxSetupCalls(kinsol_mem, data.maximum_setup_calls);
     AssertKINSOL(status);
 
-    status = KINSetNoInitSetup(kinsol_mem, (int)data.no_init_setup);
+    status = KINSetNoInitSetup(kinsol_mem, data.no_init_setup);
     AssertKINSOL(status);
 
     status = KINSetMaxNewtonStep(kinsol_mem, data.maximum_newton_step);
@@ -275,7 +275,7 @@ namespace SUNDIALS
 
     if (solve_jacobian_system)
       {
-        KINMem KIN_mem      = (KINMem)kinsol_mem;
+        auto KIN_mem        = static_cast<KINMem>(kinsol_mem);
         KIN_mem->kin_lsolve = t_kinsol_solve_jacobian<VectorType>;
         if (setup_jacobian)
           {
@@ -306,7 +306,7 @@ namespace SUNDIALS
       Assert(iteration_function, ExcFunctionNotProvided("iteration_function"));
 
     // call to KINSol
-    status = KINSol(kinsol_mem, solution, (int)data.strategy, u_scale, f_scale);
+    status = KINSol(kinsol_mem, solution, data.strategy, u_scale, f_scale);
     AssertKINSOL(status);
 
     copy(initial_guess_and_solution, solution);
@@ -337,7 +337,7 @@ namespace SUNDIALS
 #  endif
     KINFree(&kinsol_mem);
 
-    return (unsigned int)nniters;
+    return static_cast<unsigned int>(nniters);
   }
 
   template <typename VectorType>

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.