Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
efd6237
Start N_Vector implementation
Steven-Roberts May 7, 2024
aaac372
Add clone operation
Steven-Roberts May 7, 2024
8a06159
Allow N_Vector template type to be Vector2D/Vector3D
Steven-Roberts May 7, 2024
a49253a
Apply formatter
Steven-Roberts May 7, 2024
184b7e9
Add remaining basic operations
Steven-Roberts May 21, 2024
bfdf9ec
Add missing sqrt
Steven-Roberts Jun 10, 2024
a92de11
Merge branch 'next' into cusotm-nvector
Steven-Roberts Jun 10, 2024
6ead1ae
Start adding vector to arkode integrator
Steven-Roberts Oct 17, 2024
cfbc21f
Merge branch 'next' into cusotm-nvector
Steven-Roberts Oct 17, 2024
c200e2f
Add functions to swap state
Steven-Roberts Oct 19, 2024
3518b56
Finish swap state after evolve
Steven-Roberts Nov 4, 2024
d2fbc28
Merge branch 'next' into cusotm-nvector
Steven-Roberts Jan 13, 2025
937a3c4
Get prototype running
Steven-Roberts Jan 24, 2025
58dc11d
Merge branch 'next' into cusotm-nvector
Steven-Roberts Mar 24, 2025
c62c551
Merge branch 'next' into cusotm-nvector
Steven-Roberts Apr 14, 2025
3fc1914
Switch to sundials::Context
Steven-Roberts Apr 14, 2025
ccb47fd
Merge branch 'next' into cusotm-nvector
Steven-Roberts May 19, 2025
d7db014
Use move assignment rather than pointer swapping
Steven-Roberts May 19, 2025
a0eeb26
Fix access to deriv field
Steven-Roberts May 19, 2025
88dfb29
Get things working with implicit and IMEX methods
Steven-Roberts May 20, 2025
fa7f651
Fix iterator const
Steven-Roberts May 20, 2025
4f01b4c
Merge branch 'next' into cusotm-nvector
Steven-Roberts Jul 3, 2025
a9d7766
Merge branch 'next' into cusotm-nvector
Steven-Roberts Aug 4, 2025
c52fb53
Add swapData function
Steven-Roberts Aug 4, 2025
506e208
Merge branch 'next' into cusotm-nvector
Steven-Roberts Oct 30, 2025
42e239f
Merge branch 'next' into custom-nvector
bendudson Jun 16, 2026
b51d38a
NVector: Fix reduce_field callable
bendudson Jun 17, 2026
45f6473
Sundials nvecmanyvector may be missing
bendudson Jun 17, 2026
b649511
ARKode: nvector option to select N_Vector
bendudson Jun 17, 2026
d894b63
Sundials N_Vector backend for CVODE and IDA
bendudson Jun 17, 2026
ceeeb80
Document Sundials N_Vector options
bendudson Jun 17, 2026
d997e6c
Formatting changes
bendudson Jun 17, 2026
c0abd20
Unit tests for custom N_Vector
bendudson Jun 17, 2026
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
20 changes: 12 additions & 8 deletions cmake/SetupBOUTThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,8 @@ if(BOUT_USE_ADIOS2)
find_package(ADIOS2 REQUIRED)
endif()


foreach(_adios2_candidate
adios2::cxx_mpi
adios2::cxx20_mpi
adios2::cxx17_mpi
adios2::cxx11_mpi
foreach(_adios2_candidate adios2::cxx_mpi adios2::cxx20_mpi adios2::cxx17_mpi
adios2::cxx11_mpi
)
if(TARGET ${_adios2_candidate})
set(_adios2_target ${_adios2_candidate})
Expand All @@ -299,8 +295,7 @@ if(BOUT_USE_ADIOS2)
endforeach()

if(NOT DEFINED _adios2_target)
message(FATAL_ERROR
"Could not find a usable ADIOS2 CXX CMake target. ")
message(FATAL_ERROR "Could not find a usable ADIOS2 CXX CMake target. ")
endif()
message(STATUS "Using ADIOS2 CMake target: ${_adios2_target}")

Expand Down Expand Up @@ -358,6 +353,7 @@ cmake_dependent_option(
BOUT_USE_SUNDIALS "Enable support for SUNDIALS time solvers" OFF
"NOT BOUT_DOWNLOAD_SUNDIALS" ON
)
set(BOUT_HAS_SUNDIALS_MANYVECTOR OFF)
if(BOUT_USE_SUNDIALS)
enable_language(C)
if(BOUT_DOWNLOAD_SUNDIALS)
Expand Down Expand Up @@ -411,6 +407,14 @@ if(BOUT_USE_SUNDIALS)
set(SUNDIALS_ROOT "${SUNDIALS_DIR}")
endif()
target_link_libraries(bout++ PUBLIC SUNDIALS::nvecparallel)
if(TARGET SUNDIALS::nvecmanyvector)
target_link_libraries(bout++ PUBLIC SUNDIALS::nvecmanyvector)
set(BOUT_HAS_SUNDIALS_MANYVECTOR ON)
else()
message(
STATUS "SUNDIALS ManyVector support not found; custom N_Vector disabled"
)
endif()
target_link_libraries(bout++ PUBLIC SUNDIALS::cvode)
target_link_libraries(bout++ PUBLIC SUNDIALS::ida)
target_link_libraries(bout++ PUBLIC SUNDIALS::arkode)
Expand Down
1 change: 1 addition & 0 deletions cmake_build_defines.hxx.in
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#cmakedefine01 BOUT_HAS_SCOREP
#cmakedefine01 BOUT_HAS_SLEPC
#cmakedefine01 BOUT_HAS_SUNDIALS
#cmakedefine01 BOUT_HAS_SUNDIALS_MANYVECTOR
#cmakedefine01 BOUT_HAS_UUID_SYSTEM_GENERATOR
#cmakedefine01 BOUT_USE_COLOR
#cmakedefine01 BOUT_USE_OPENMP
Expand Down
1 change: 1 addition & 0 deletions include/bout/build_config.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ constexpr auto has_uuid_system_generator =
static_cast<bool>(BOUT_HAS_UUID_SYSTEM_GENERATOR);
constexpr auto has_slepc = static_cast<bool>(BOUT_HAS_SLEPC);
constexpr auto has_sundials = static_cast<bool>(BOUT_HAS_SUNDIALS);
constexpr auto has_sundials_manyvector = static_cast<bool>(BOUT_HAS_SUNDIALS_MANYVECTOR);
constexpr auto use_backtrace = static_cast<bool>(BOUT_USE_BACKTRACE);
constexpr auto use_color = static_cast<bool>(BOUT_USE_COLOR);
constexpr auto use_openmp = static_cast<bool>(BOUT_USE_OPENMP);
Expand Down
1 change: 1 addition & 0 deletions include/bout/field2d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ public:
void applyTDerivBoundary() override;
void setBoundaryTo(const Field2D& f2d); ///< Copy the boundary region

void swapData(Field2D& other);
friend void swap(Field2D& first, Field2D& second) noexcept;

int size() const override { return nx * ny; }
Expand Down
1 change: 1 addition & 0 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ public:
void applyParallelBoundary(const std::string& region, const std::string& condition,
Field3D* f);

void swapData(Field3D& other);
friend void swap(Field3D& first, Field3D& second) noexcept;

int size() const override { return nx * ny * nz; };
Expand Down
3 changes: 3 additions & 0 deletions include/bout/solver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
// C function pointer types

class Solver;
class SundialsNVectorInterface;

/// RHS function pointer
using rhsfunc = int (*)(BoutReal);
Expand Down Expand Up @@ -358,6 +359,8 @@ public:
int getIterationOffset() const { return iteration_offset; }

protected:
friend class SundialsNVectorInterface;

/// Number of command-line arguments
static int* pargc;
/// Command-line arguments
Expand Down
15 changes: 8 additions & 7 deletions include/bout/sundials_backports.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@

// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define SUNDIALS_VERSION_AT_LEAST(major, minor, patch) \
((major) < SUNDIALS_VERSION_MAJOR \
|| ((major) == SUNDIALS_VERSION_MAJOR \
&& ((minor) < SUNDIALS_VERSION_MINOR \
|| ((minor) == SUNDIALS_VERSION_MINOR && (patch) <= SUNDIALS_VERSION_PATCH))))
((major) < SUNDIALS_VERSION_MAJOR \
|| ((major) == SUNDIALS_VERSION_MAJOR \
&& ((minor) < SUNDIALS_VERSION_MINOR \
|| ((minor) == SUNDIALS_VERSION_MINOR \
&& (patch) <= SUNDIALS_VERSION_PATCH))))
#define SUNDIALS_VERSION_LESS_THAN(major, minor, patch) \
(!SUNDIALS_VERSION_AT_LEAST(major, minor, patch))
// NOLINTEND(cppcoreguidelines-macro-usage)
Expand Down Expand Up @@ -77,13 +78,13 @@ inline sundials::Context createSUNContext([[maybe_unused]] MPI_Comm& comm) {
#endif
}

template <typename Func, typename... Args>
inline decltype(auto) callWithSUNContext(Func f, [[maybe_unused]] sundials::Context& ctx,
template <typename Func, typename Ctx, typename... Args>
inline decltype(auto) callWithSUNContext(Func f, [[maybe_unused]] Ctx&& ctx,
Args&&... args) {
#if SUNDIALS_VERSION_LESS_THAN(6, 0, 0)
return f(std::forward<Args>(args)...);
#else
return f(std::forward<Args>(args)..., ctx);
return f(std::forward<Args>(args)..., std::forward<Ctx>(ctx));
#endif
}

Expand Down
31 changes: 29 additions & 2 deletions manual/sphinx/user_docs/time_integration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ needed to make the solver available.

.. _tab-solvers:
.. table:: Available time integration solvers

+---------------+-----------------------------------------+------------------------+
| Name | Description | Compile options |
+===============+=========================================+========================+
Expand Down Expand Up @@ -68,7 +68,7 @@ given in table :numref:`tab-solveropts`.

.. _tab-solveropts:
.. table:: Time integration solver options

+--------------------------+--------------------------------------------+-------------------------------------+
| Option | Description | Solvers used |
+==========================+============================================+=====================================+
Expand Down Expand Up @@ -104,13 +104,40 @@ given in table :numref:`tab-solveropts`.
+--------------------------+--------------------------------------------+-------------------------------------+
| diagnose | Collect and print additional diagnostics | cvode, imexbdf2, beuler |
+--------------------------+--------------------------------------------+-------------------------------------+
| nvector | ``N_Vector`` backend for SUNDIALS solvers: | cvode, ida, arkode |
| | ``sundials`` or ``manyvector`` | |
+--------------------------+--------------------------------------------+-------------------------------------+

|

The most commonly changed options are the absolute and relative solver
tolerances, ``atol`` and ``rtol`` which should be varied to check
convergence.

SUNDIALS ``N_Vector`` backends
------------------------------

The SUNDIALS-based solvers ``cvode``, ``ida``, and ``arkode`` can select
the ``N_Vector`` backend at runtime using ``solver:nvector``:

.. code-block:: cfg

[solver]
type = cvode
nvector = sundials

Valid values are:

- ``sundials`` uses the standard SUNDIALS parallel ``N_Vector``. This is the
default.
- ``manyvector`` uses the BOUT++ field-backed custom ``N_Vector`` built on top
of SUNDIALS ManyVector support.

The ``manyvector`` option is only available when BOUT++ was built with SUNDIALS
ManyVector support. If ``solver:nvector=manyvector`` is selected in a build
that does not provide this support, solver initialisation will throw an
exception.

CVODE
-----

Expand Down
2 changes: 2 additions & 0 deletions src/field/field2d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ void Field2D::setBoundaryTo(const Field2D& f2d) {
}
}

void Field2D::swapData(Field2D& other) { std::swap(data, other.data); }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::swap" is directly included [misc-include-cleaner]

void Field2D::swapData(Field2D& other) { std::swap(data, other.data); }
                                              ^


////////////// NON-MEMBER OVERLOADED OPERATORS //////////////

// Unary minus
Expand Down
2 changes: 2 additions & 0 deletions src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,8 @@ void Field3D::applyParallelBoundary(const std::string& region,
}
}

void Field3D::swapData(Field3D& other) { std::swap(data, other.data); }

/***************************************************************
* NON-MEMBER OVERLOADED OPERATORS
***************************************************************/
Expand Down
Loading