Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions bindings/sundials4py/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ set(sundials_SOURCES
sunnonlinsol/sunnonlinsol_newton.cpp
test/sundials4py_test.cpp)

if(SUNDIALS_ENABLE_SUPERLUMT)
list(APPEND sundials_SOURCES sunlinsol/sunlinsol_superlumt.cpp)
endif()

# Create the Python sundials library
nanobind_add_module(sundials4py STABLE_ABI NB_STATIC ${sundials_SOURCES})

Expand Down Expand Up @@ -146,5 +150,9 @@ target_link_libraries(
sundials_sundomeigestpower
sundials_core)

if(SUNDIALS_ENABLE_SUPERLUMT)
target_link_libraries(sundials4py PRIVATE sundials_sunlinsolsuperlumt)
endif()

# Install directive for scikit-build-core
install(TARGETS sundials4py LIBRARY DESTINATION .)
6 changes: 6 additions & 0 deletions bindings/sundials4py/sundials4py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ void bind_sunlinsol_spbcgs(nb::module_& m);
void bind_sunlinsol_spfgmr(nb::module_& m);
void bind_sunlinsol_spgmr(nb::module_& m);
void bind_sunlinsol_sptfqmr(nb::module_& m);
#if defined(SUNDIALS_SUPERLUMT_ENABLED)
void bind_sunlinsol_superlumt(nb::module_& m);
#endif

void bind_sunmatrix_band(nb::module_& m);
void bind_sunmatrix_dense(nb::module_& m);
Expand Down Expand Up @@ -134,6 +137,9 @@ NB_MODULE(sundials4py, m)
sundials4py::bind_sunlinsol_spfgmr(core_m);
sundials4py::bind_sunlinsol_spgmr(core_m);
sundials4py::bind_sunlinsol_sptfqmr(core_m);
#if defined(SUNDIALS_SUPERLUMT_ENABLED)
sundials4py::bind_sunlinsol_superlumt(core_m);
#endif

sundials4py::bind_sunmatrix_band(core_m);
sundials4py::bind_sunmatrix_dense(core_m);
Expand Down
4 changes: 4 additions & 0 deletions bindings/sundials4py/sunlinsol/generate.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ modules:
path: sunlinsol/sunlinsol_pcg_generated.hpp
headers:
- ../../include/sunlinsol/sunlinsol_pcg.h
sunlinsol_superlumt:
path: sunlinsol/sunlinsol_superlumt_generated.hpp
headers:
- ../../include/sunlinsol/sunlinsol_superlumt.h
33 changes: 33 additions & 0 deletions bindings/sundials4py/sunlinsol/sunlinsol_superlumt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* -----------------------------------------------------------------
* Programmer(s): Cody J. Balos @ LLNL
* -----------------------------------------------------------------
* SUNDIALS Copyright Start
* Copyright (c) 2025-2026, Lawrence Livermore National Security,
* University of Maryland Baltimore County, and the SUNDIALS contributors.
* Copyright (c) 2013-2025, Lawrence Livermore National Security
* and Southern Methodist University.
* Copyright (c) 2002-2013, Lawrence Livermore National Security.
* All rights reserved.
*
* See the top-level LICENSE and NOTICE files for details.
*
* SPDX-License-Identifier: BSD-3-Clause
* SUNDIALS Copyright End
* -----------------------------------------------------------------*/

#include "sundials4py.hpp"

#include <sundials/sundials_core.hpp>
#include <sunlinsol/sunlinsol_superlumt.h>

namespace nb = nanobind;
using namespace sundials::experimental;

namespace sundials4py {

void bind_sunlinsol_superlumt(nb::module_& m)
{
#include "sunlinsol_superlumt_generated.hpp"
}

} // namespace sundials4py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// #ifndef _SUNLINSOL_SLUMT_H
//
// #ifdef __cplusplus
// #endif
//

auto pyClass_SUNLinearSolverContent_SuperLUMT =
nb::class_<_SUNLinearSolverContent_SuperLUMT>(
m, "_SUNLinearSolverContent_SuperLUMT", "")
.def(nb::init<>()) // implicit default constructor
;

m.def(
"SUNLinSol_SuperLUMT",
[](N_Vector y, SUNMatrix A, int num_threads,
SUNContext sunctx) -> std::shared_ptr<std::remove_pointer_t<SUNLinearSolver>>
{
auto SUNLinSol_SuperLUMT_adapt_return_type_to_shared_ptr =
[](N_Vector y, SUNMatrix A, int num_threads, SUNContext sunctx)
-> std::shared_ptr<std::remove_pointer_t<SUNLinearSolver>>
{
auto lambda_result = SUNLinSol_SuperLUMT(y, A, num_threads, sunctx);

return our_make_shared<std::remove_pointer_t<SUNLinearSolver>,
SUNLinearSolverDeleter>(lambda_result);
};

return SUNLinSol_SuperLUMT_adapt_return_type_to_shared_ptr(y, A, num_threads,
sunctx);
},
nb::arg("y"), nb::arg("A"), nb::arg("num_threads"), nb::arg("sunctx"),
nb::keep_alive<0, 4>());

m.def("SUNLinSol_SuperLUMTSetOrdering", SUNLinSol_SuperLUMTSetOrdering,
nb::arg("S"), nb::arg("ordering_choice"));
// #ifdef __cplusplus
//
// #endif
//
// #endif
//
10 changes: 10 additions & 0 deletions bindings/sundials4py/test/test_sunlinearsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
# -----------------------------------------------------------------

import pytest
import importlib
from fixtures import *
from sundials4py.core import *

Expand Down Expand Up @@ -52,6 +53,15 @@ def test_create_sptfqmr(sunctx, nvec):
assert LS is not None


def test_create_superlumt(sunctx, nvec):
if not hasattr(importlib.import_module("sundials4py.core"), "SUNLinSol_SuperLUMT"):
pytest.skip("SUNLinSol_SuperLUMT is not enabled in this build")

A = SUNSparseMatrix(N_VGetLength(nvec), N_VGetLength(nvec), 1, CSC_MAT, sunctx)
LS = SUNLinSol_SuperLUMT(nvec, A, 1, sunctx)
assert LS is not None


def test_get_type_and_id(sunctx, nvec):
A = SUNDenseMatrix(N_VGetLength(nvec), N_VGetLength(nvec), sunctx)
LS = SUNLinSol_Dense(nvec, A, sunctx)
Expand Down