From 35ac761862b44bd3c31b24544fad2ace42e79310 Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Tue, 10 Oct 2023 15:14:03 +0100 Subject: [PATCH 1/9] #3431 update sundials to 6.0.0 for windows wheels --- vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 27c1b0bcb1..1fe14cdd44 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -7,7 +7,7 @@ { "kind": "git", "repository": "https://github.com/pybamm-team/sundials-vcpkg-registry.git", - "baseline": "2aaffb6bba7bc0b50cb74ddad636832d673851a1", + "baseline": "5a6a8c4daf1e898809a19e60ea6e6cece85fe08e", "packages": ["sundials"] }, { From 00d661167d422458c05f1b82a8174c0c04924e3e Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Tue, 10 Oct 2023 15:38:17 +0000 Subject: [PATCH 2/9] #3431 update windows wheels to sundials 6.5.0 --- vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 1fe14cdd44..1d728d704d 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -7,7 +7,7 @@ { "kind": "git", "repository": "https://github.com/pybamm-team/sundials-vcpkg-registry.git", - "baseline": "5a6a8c4daf1e898809a19e60ea6e6cece85fe08e", + "baseline": "7d19be6c0713589465e2eb67ef3f5ffbf9f5d5c1", "packages": ["sundials"] }, { From e1585f79daf891ca420cd3ab5b2fec645166610b Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Tue, 10 Oct 2023 16:11:34 +0000 Subject: [PATCH 3/9] update windows wheels to sundials 6.5.0 --- vcpkg-configuration.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 1d728d704d..8ab4e738fc 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -7,7 +7,7 @@ { "kind": "git", "repository": "https://github.com/pybamm-team/sundials-vcpkg-registry.git", - "baseline": "7d19be6c0713589465e2eb67ef3f5ffbf9f5d5c1", + "baseline": "af9f5e4bc730bf2361c47f809dcfb733e7951faa", "packages": ["sundials"] }, { From 7e1930cdd129e5cb36e668c18bd93591f01da018 Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Thu, 12 Oct 2023 15:42:30 +0000 Subject: [PATCH 4/9] #3431 fix some vstudio compile errors --- pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp | 2 +- pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp b/pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp index c1c71a967d..ad51eda4e1 100644 --- a/pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp +++ b/pybamm/solvers/c_solvers/idaklu/CasadiSolverOpenMP.cpp @@ -275,7 +275,7 @@ Solution CasadiSolverOpenMP::solve( // set inputs auto p_inputs = inputs.unchecked<2>(); - for (uint i = 0; i < functions->inputs.size(); i++) + for (int i = 0; i < functions->inputs.size(); i++) functions->inputs[i] = p_inputs(i, 0); // set initial conditions diff --git a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp index 4f31dbe57d..0c188f6304 100644 --- a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp +++ b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp @@ -219,7 +219,8 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, jac_colptrs[i] = p_jac_times_cjmass_colptrs[i]; } } else if (SUNSparseMatrix_SparseType(JJ) == CSR_MAT) { - realtype newjac[SUNSparseMatrix_NNZ(JJ)]; + const int JJ_nnz = SUNSparseMatrix_NNZ(JJ); + realtype newjac[JJ_nnz]; sunindextype *jac_ptrs = SUNSparseMatrix_IndexPointers(JJ); sunindextype *jac_vals = SUNSparseMatrix_IndexValues(JJ); From 75f87071b42b5430f943c671b511473ac755aa23 Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Thu, 12 Oct 2023 16:29:00 +0000 Subject: [PATCH 5/9] #3431 make nnz a constant --- pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp index 0c188f6304..b3eb5d9f66 100644 --- a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp +++ b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp @@ -219,8 +219,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, jac_colptrs[i] = p_jac_times_cjmass_colptrs[i]; } } else if (SUNSparseMatrix_SparseType(JJ) == CSR_MAT) { - const int JJ_nnz = SUNSparseMatrix_NNZ(JJ); - realtype newjac[JJ_nnz]; + realtype newjac[SM_NNZ_S(JJ)]; sunindextype *jac_ptrs = SUNSparseMatrix_IndexPointers(JJ); sunindextype *jac_vals = SUNSparseMatrix_IndexValues(JJ); From 10e94f7c905bc07f8d83b82b5601a7e2eef35dcd Mon Sep 17 00:00:00 2001 From: martinjrobins Date: Thu, 12 Oct 2023 16:31:43 +0000 Subject: [PATCH 6/9] #3431 revert to SUNSparseMatrix_NNZ --- pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp index b3eb5d9f66..4f31dbe57d 100644 --- a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp +++ b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp @@ -219,7 +219,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, jac_colptrs[i] = p_jac_times_cjmass_colptrs[i]; } } else if (SUNSparseMatrix_SparseType(JJ) == CSR_MAT) { - realtype newjac[SM_NNZ_S(JJ)]; + realtype newjac[SUNSparseMatrix_NNZ(JJ)]; sunindextype *jac_ptrs = SUNSparseMatrix_IndexPointers(JJ); sunindextype *jac_vals = SUNSparseMatrix_IndexValues(JJ); From 9c474fb241d924e8a29b172b74ad1d5521589e65 Mon Sep 17 00:00:00 2001 From: John Brittain Date: Fri, 13 Oct 2023 09:31:03 +0100 Subject: [PATCH 7/9] #3431 refactor variable length array to std::vector --- .../solvers/c_solvers/idaklu/casadi_sundials_functions.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp index 4f31dbe57d..b0ea180641 100644 --- a/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp +++ b/pybamm/solvers/c_solvers/idaklu/casadi_sundials_functions.cpp @@ -219,7 +219,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, jac_colptrs[i] = p_jac_times_cjmass_colptrs[i]; } } else if (SUNSparseMatrix_SparseType(JJ) == CSR_MAT) { - realtype newjac[SUNSparseMatrix_NNZ(JJ)]; + std::vector newjac(SUNSparseMatrix_NNZ(JJ)); sunindextype *jac_ptrs = SUNSparseMatrix_IndexPointers(JJ); sunindextype *jac_vals = SUNSparseMatrix_IndexValues(JJ); @@ -229,7 +229,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, p_python_functions->jac_times_cjmass.m_arg[2] = p_python_functions->inputs.data(); p_python_functions->jac_times_cjmass.m_arg[3] = &cj; - p_python_functions->jac_times_cjmass.m_res[0] = newjac; + p_python_functions->jac_times_cjmass.m_res[0] = newjac.data(); p_python_functions->jac_times_cjmass(); // convert (casadi's) CSC format to CSR @@ -237,7 +237,7 @@ int jacobian_casadi(realtype tt, realtype cj, N_Vector yy, N_Vector yp, std::remove_pointer_tjac_times_cjmass_rowvals.data())>, std::remove_pointer_t >( - newjac, + newjac.data(), p_python_functions->jac_times_cjmass_rowvals.data(), p_python_functions->jac_times_cjmass_colptrs.data(), jac_data, From dc41fbbc417e19f39b3ebc17efcf12bad34b19b5 Mon Sep 17 00:00:00 2001 From: John Brittain Date: Fri, 13 Oct 2023 10:30:12 +0100 Subject: [PATCH 8/9] another variable length array to std::vector --- pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp b/pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp index d29cb7c961..1a33b957f8 100644 --- a/pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp +++ b/pybamm/solvers/c_solvers/idaklu/casadi_functions.hpp @@ -21,7 +21,7 @@ */ template void csc_csr(const realtype f[], const T1 c[], const T1 r[], realtype nf[], T2 nc[], T2 nr[], int N, int cols) { - int nn[cols+1]; + std::vector nn(cols+1); std::vector rr(N); for (int i=0; i Date: Fri, 13 Oct 2023 11:17:40 +0100 Subject: [PATCH 9/9] Make variable length arrays a compile error in cmake --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 38e3d4976c..2a78ee9d62 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,10 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_EXPORT_COMPILE_COMMANDS 1) set(CMAKE_POSITION_INDEPENDENT_CODE ON) - +if(NOT MSVC) + # MSVC does not support variable length arrays (vla) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror=vla") +endif() # casadi seems to compile without the newer versions of std::string add_compile_definitions(_GLIBCXX_USE_CXX11_ABI=0)