Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ec80fb5
ARKODE_MRI interface
maggul Oct 25, 2024
c14dcd4
add missing files
maggul Oct 25, 2024
fbba15f
added treatment options
maggul Oct 25, 2024
0861085
remove adaptivity
maggul Nov 18, 2024
9795739
bulk revision
maggul Nov 18, 2024
87baf52
adaptive step and SUNDIALS release updates
maggul Jan 9, 2025
9c5d88f
added SUNDIALS version and removed unnecessary flags
maggul Jan 16, 2025
d23297b
moved sundials_config.h up before the version check
maggul Jan 16, 2025
afebae1
merged with next of BOUT++
maggul Jan 16, 2025
340cdc0
update the SUNDIALS version check
maggul Jan 16, 2025
528135c
Updated include order
maggul Jan 17, 2025
250b1f5
Fixed a function name
maggul Jan 17, 2025
052be87
update version check
maggul Jan 17, 2025
366aad0
update header files
maggul Jan 18, 2025
92db7e1
fixed the arkode_mri solver name
maggul Jan 18, 2025
c680123
version check update
maggul Jan 20, 2025
41830be
removed unnecessary endif
maggul Jan 27, 2025
aa7028e
sundials version check resolved
maggul Jan 27, 2025
52802c1
flag and test-kpr updates
maggul Feb 7, 2025
6b8f7e6
Merge branch 'next' into maggul_next
bendudson Feb 7, 2025
63db0f4
added required header file
maggul Feb 8, 2025
30c16d9
ARKode-MRI: Register unavailable if sundials version is too low
bendudson Feb 8, 2025
462cfb3
Add fast and slow preconditioner callbacks
bendudson Feb 8, 2025
7731d76
ARKode solver: Use ARKodeGetNumRhsEvals from v7.2.0
bendudson Feb 8, 2025
935131d
ARKode-MRI: Only call ARKodeGetCurrentStep if user requests it
bendudson Feb 8, 2025
702cefb
Apply black changes
bendudson Feb 11, 2025
1d1677b
Increment MRI rhs counts
bendudson Feb 12, 2025
3ccd334
run_rhs_f/s internally
maggul Apr 14, 2025
5c98b44
ARKodeSetStopTime before each evolve call
maggul Apr 21, 2025
1bd0b0b
SUNDIALS version update
maggul Aug 5, 2025
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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ set(BOUT_SOURCES
./src/solver/impls/adams_bashforth/adams_bashforth.hxx
./src/solver/impls/arkode/arkode.cxx
./src/solver/impls/arkode/arkode.hxx
./src/solver/impls/arkode/arkode_mri.cxx
./src/solver/impls/arkode/arkode_mri.hxx
./src/solver/impls/cvode/cvode.cxx
./src/solver/impls/cvode/cvode.hxx
./src/solver/impls/euler/euler.cxx
Expand Down
2 changes: 1 addition & 1 deletion cmake/SetupBOUTThirdParty.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ if (BOUT_USE_SUNDIALS)
FetchContent_Declare(
sundials
GIT_REPOSITORY https://github.com/LLNL/sundials
GIT_TAG v7.2.1
GIT_TAG v7.4.0
)
# Note: These are settings for building SUNDIALS
set(EXAMPLES_ENABLE_C OFF CACHE BOOL "" FORCE)
Expand Down
34 changes: 22 additions & 12 deletions include/bout/mesh.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,43 @@ class Mesh;
#ifndef BOUT_MESH_H
#define BOUT_MESH_H

#include "bout/bout_enum_class.hxx"
#include "mpi.h"

#include <bout/deriv_store.hxx>
#include <bout/index_derivs_interface.hxx>
#include <bout/mpi_wrapper.hxx>

#include "bout/bout_types.hxx"
#include "bout/coordinates.hxx" // Coordinates class
#include "bout/field2d.hxx"
#include "bout/field3d.hxx"
#include "bout/field_data.hxx"
#include "bout/fieldgroup.hxx"
#include "bout/generic_factory.hxx"
#include "bout/index_derivs_interface.hxx"
#include "bout/mpi_wrapper.hxx"
#include "bout/options.hxx"
#include "bout/region.hxx"

#include "bout/fieldgroup.hxx"

class BoundaryRegion;
class BoundaryRegionPar;

#include "bout/sys/range.hxx" // RangeIterator

#include <bout/griddata.hxx>

#include "bout/coordinates.hxx" // Coordinates class

#include "bout/unused.hxx"

#include "mpi.h"
#include "bout/generic_factory.hxx"
#include <bout/region.hxx>

#include <bout/bout_enum_class.hxx>

#include <list>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <string>

class BoundaryRegion;
class BoundaryRegionPar;
class GridDataSource;

class MeshFactory : public Factory<Mesh, MeshFactory, GridDataSource*, Options*> {
public:
static constexpr auto type_name = "Mesh";
Expand Down
14 changes: 11 additions & 3 deletions include/bout/monitor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,18 @@ public:

/// number of RHS calls
int ncalls = 0;
/// number of RHS calls for fast timescale
/// number of RHS calls for explicit timescale
int ncalls_e = 0;
/// number of RHS calls for slow timescale
/// number of RHS calls for implicit timescale
int ncalls_i = 0;
/// number of RHS calls for slow explicit timescale
int ncalls_se = 0;
/// number of RHS calls for slow implicit timescale
int ncalls_si = 0;
/// number of RHS calls for fast explicit timescale
int ncalls_fe = 0;
/// number of RHS calls for fast implicit timescale
int ncalls_fi = 0;

/// wall time spent calculating RHS
BoutReal wtime_rhs = 0;
Expand Down Expand Up @@ -122,7 +130,7 @@ public:
/*!
* Write job progress to screen
*/
void writeProgress(BoutReal simtime, bool output_split);
void writeProgress(BoutReal simtime, bool output_split, bool output_splitmri);
};

#endif // BOUT_MONITOR_H
69 changes: 59 additions & 10 deletions include/bout/physicsmodel.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,10 @@
* @brief Base class for Physics Models
*
*
*
* Changelog:
*
* 2013-08 Ben Dudson <benjamin.dudson@york.ac.uk>
* * Initial version
*
**************************************************************************
* Copyright 2013 B.D.Dudson
* Copyright 2013-2025 BOUT++ contributors
*
* Contact: Ben Dudson, bd512@york.ac.uk
* Contact: Ben Dudson, dudson2@llnl.gov
*
* This file is part of BOUT++.
*
Expand Down Expand Up @@ -169,13 +163,26 @@ public:
*
* Returns a flag: 0 indicates success, non-zero an error flag
*/
int runRHS_se(BoutReal time, bool linear = false);
int runRHS_si(BoutReal time, bool linear = false);
int runRHS_fe(BoutReal time, bool linear = false);
int runRHS_fi(BoutReal time, bool linear = false);
int runRHS_s(BoutReal time, bool linear = false);
int runRHS_f(BoutReal time, bool linear = false);
int runRHS(BoutReal time, bool linear = false);

/*!
* True if this model uses split operators
* RHS = convective + diffusive
*/
bool splitOperator();

/*!
* True if this model uses Multi-Rate Integrator (MRI) split operators
* RHS = rhs_se + rhs_si + rhs_fe + rhs_fi
*/
bool splitOperatorMRI();

/*!
* Run the convective (usually explicit) part of the model
*
Expand All @@ -197,7 +204,9 @@ public:
/*!
* True if a preconditioner has been defined
*/
bool hasPrecon();
bool hasPrecon() const { return (userprecon != nullptr); }
bool hasPreconFast() const { return (userprecon_f != nullptr); }
bool hasPreconSlow() const { return (userprecon_s != nullptr); }

/*!
* Run the preconditioner. The system state should be in the
Expand All @@ -208,7 +217,9 @@ public:
*
*/
int runPrecon(BoutReal t, BoutReal gamma, BoutReal delta);

int runPreconFast(BoutReal t, BoutReal gamma, BoutReal delta);
int runPreconSlow(BoutReal t, BoutReal gamma, BoutReal delta);

/*!
* True if a Jacobian function has been defined
*/
Expand Down Expand Up @@ -267,6 +278,24 @@ protected:
* which is set to true when the rhs() function can be
* linearised. This is used in e.g. linear iterative solves.
*/
virtual int rhs_se(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_se(BoutReal t, bool UNUSED(linear)) { return rhs_se(t); }

virtual int rhs_si(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_si(BoutReal t, bool UNUSED(linear)) { return rhs_si(t); }

virtual int rhs_fe(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_fe(BoutReal t, bool UNUSED(linear)) { return rhs_fe(t); }

virtual int rhs_fi(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_fi(BoutReal t, bool UNUSED(linear)) { return rhs_fi(t); }

virtual int rhs_s(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_s(BoutReal t, bool UNUSED(linear)) { return rhs_s(t); }

virtual int rhs_f(BoutReal UNUSED(t)) { return 1; }
virtual int rhs_f(BoutReal t, bool UNUSED(linear)) { return rhs_f(t); }

virtual int rhs(BoutReal UNUSED(t)) { return 1; }
virtual int rhs(BoutReal t, bool UNUSED(linear)) { return rhs(t); }

Expand Down Expand Up @@ -309,13 +338,29 @@ protected:
/// Specify that this model is split into a convective and diffusive part
void setSplitOperator(bool split = true) { splitop = split; }

/// Specify that this model is split into fast and slow parts
void setSplitOperatorMRI(bool split = true) { splitopmri = split; }

/// Specify a preconditioner function
void setPrecon(preconfunc pset) { userprecon = pset; }
template <class Model>
void setPrecon(ModelPreconFunc<Model> preconditioner) {
userprecon = static_cast<preconfunc>(preconditioner);
}

/// Preconditioner for fast implicit RHS
void setPreconFast(preconfunc pset) { userprecon_f = pset; }
template <class Model>
void setPreconFast(ModelPreconFunc<Model> preconditioner) {
userprecon_f = static_cast<preconfunc>(preconditioner);
}
/// Preconditioner for slow implicit RHS
void setPreconSlow(preconfunc pset) { userprecon_s = pset; }
template <class Model>
void setPreconSlow(ModelPreconFunc<Model> preconditioner) {
userprecon_s = static_cast<preconfunc>(preconditioner);
}

/// Specify a Jacobian-vector multiply function
void setJacobian(jacobianfunc jset) { userjacobian = jset; }
template <class Model>
Expand Down Expand Up @@ -391,8 +436,12 @@ private:
bool restart_enabled{true};
/// Split operator model?
bool splitop{false};
/// MPI fast/slow split operator model?
bool splitopmri{false};
/// Pointer to user-supplied preconditioner function
preconfunc userprecon{nullptr};
preconfunc userprecon_f{nullptr};
preconfunc userprecon_s{nullptr};
/// Pointer to user-supplied Jacobian-vector multiply function
jacobianfunc userjacobian{nullptr};
/// True if model already initialised
Expand Down
35 changes: 35 additions & 0 deletions include/bout/solver.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ constexpr auto SOLVEREULER = "euler";
constexpr auto SOLVERRK3SSP = "rk3ssp";
constexpr auto SOLVERPOWER = "power";
constexpr auto SOLVERARKODE = "arkode";
constexpr auto SOLVERARKODEMRI = "arkode_mri";
constexpr auto SOLVERIMEXBDF2 = "imexbdf2";
constexpr auto SOLVERSNES = "snes";
constexpr auto SOLVERRKGENERIC = "rkgeneric";
Expand Down Expand Up @@ -310,9 +311,21 @@ public:
/// Same but fur implicit timestep counter - for IMEX
int resetRHSCounter_i();

/// Same but for slow explicit timestep counter - for MRI IMEX
int resetRHSCounter_se();
/// Same but for slow implicit timestep counter - for MRI IMEX
int resetRHSCounter_si();
/// Same but for fast explicit timestep counter - for MRI IMEX
int resetRHSCounter_fe();
/// Same but for fast implicit timestep counter - for MRI IMEX
int resetRHSCounter_fi();

/// Test if this solver supports split operators (e.g. implicit/explicit)
bool splitOperator();

/// Test if this solver supports split operators (e.g. implicit/explicit)
bool splitOperatorMRI();

bool canReset{false};

/// Add evolving variables to output (dump) file or restart file
Expand Down Expand Up @@ -433,11 +446,19 @@ protected:
bool initialised{false};
/// If calling user RHS for the first time
bool first_rhs_call{true};
bool first_rhs_s_call{false};
bool first_rhs_f_call{false};

/// Current simulation time
BoutReal simtime{0.0};

/// Run the user's RHS function
int run_rhs_se(BoutReal t, bool linear = false);
int run_rhs_si(BoutReal t, bool linear = false);
int run_rhs_fe(BoutReal t, bool linear = false);
int run_rhs_fi(BoutReal t, bool linear = false);
int run_rhs_s(BoutReal t, bool linear = false);
int run_rhs_f(BoutReal t, bool linear = false);
int run_rhs(BoutReal t, bool linear = false);
/// Calculate only the convective parts
int run_convective(BoutReal t, bool linear = false);
Expand Down Expand Up @@ -472,8 +493,13 @@ protected:

/// Do we have a user preconditioner?
bool hasPreconditioner();
bool hasPreconditionerFast();
bool hasPreconditionerSlow();

/// Run the user preconditioner
int runPreconditioner(BoutReal time, BoutReal gamma, BoutReal delta);
int runPreconditionerFast(BoutReal time, BoutReal gamma, BoutReal delta);
int runPreconditionerSlow(BoutReal time, BoutReal gamma, BoutReal delta);

/// Do we have a user Jacobian?
bool hasJacobian();
Expand Down Expand Up @@ -542,6 +568,15 @@ private:
int rhs_ncalls_e{0};
/// Number of calls to the implicit (diffusive) RHS function
int rhs_ncalls_i{0};
/// number of RHS calls for slow explicit timescale
int rhs_ncalls_se = 0;
/// number of RHS calls for slow implicit timescale
int rhs_ncalls_si = 0;
/// number of RHS calls for fast explicit timescale
int rhs_ncalls_fe = 0;
/// number of RHS calls for fast implicit timescale
int rhs_ncalls_fi = 0;

/// Default sampling rate at which to call monitors - same as output to screen
int default_monitor_period{1};
/// timestep - shouldn't be changed after init is called.
Expand Down
Loading
Loading