Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
2722003
Add rosenbrock
alexander-novo Mar 16, 2026
bd2c5f9
Add rosenbrock tests
alexander-novo Mar 16, 2026
dd9ebb1
Fixed bug setting alpha coefficient in rosenbrock
alexander-novo Mar 16, 2026
9d15c72
Removed extra move
alexander-novo Mar 16, 2026
fb45769
Remove some debug outputs
alexander-novo Mar 16, 2026
7c58a56
Properly reset stats in initializeSimulation
alexander-novo Mar 16, 2026
22829e1
Switch back to klu solver
alexander-novo Mar 16, 2026
e719466
Add empirical order testing
alexander-novo Mar 16, 2026
bfc88c7
Fix dense output indexing issue
alexander-novo Mar 16, 2026
b696073
Add RODAS5P tableau
alexander-novo Mar 16, 2026
5f48049
Add rodas5p order test
alexander-novo Mar 16, 2026
99270a2
Add error checking
alexander-novo Mar 17, 2026
5b46fec
Re-organize rosenbrock implementation code
alexander-novo Mar 17, 2026
480da97
Add embedded coefficients for rodas5p
alexander-novo Mar 17, 2026
227780e
Documentation and organization
alexander-novo Mar 17, 2026
c5be4bc
Fix cmake when resolve not enabled
alexander-novo Mar 17, 2026
8c5ea66
Fix some documentation mistakes
alexander-novo Mar 17, 2026
33281cb
Make error_estimator_stage more ergonomic
alexander-novo Mar 18, 2026
4b69ae9
Move documentation
alexander-novo Mar 20, 2026
08f100b
More documentation
alexander-novo Mar 23, 2026
7748003
Update ReSolve dependency
alexander-novo Mar 23, 2026
c84a7c1
Code review documentation changes
alexander-novo Mar 24, 2026
7eba4f6
Changes from review
alexander-novo Mar 26, 2026
8cf790e
Fix compiler errors and warnings on g++
alexander-novo Apr 17, 2026
8cd71e0
Apply pre-commit fixes
alexander-novo Jul 7, 2026
b7a01cb
fix cmake issue
alexander-novo Jul 7, 2026
9b26bdf
Update Rosenbrock to use GridKit Vector and VectorHandler
alexander-novo Jul 9, 2026
db7f95d
Apply pre-commit fixes
alexander-novo Jul 9, 2026
9f7055a
[skip ci] Update Documentation
alexander-novo Jul 9, 2026
ca9fbfb
Add to changelog
alexander-novo Jul 9, 2026
c4ae3de
[skip ci] Add Rodas5p citation
alexander-novo Jul 9, 2026
c327f84
Update naming conventions
alexander-novo Jul 9, 2026
0188944
[skip ci] Add comment explaining confusing interaction
alexander-novo Jul 9, 2026
48bf159
[skip ci] Update Documentation
alexander-novo Jul 9, 2026
39d95cd
Made screaming snake case convention explicit (#484)
shakedregev Jul 10, 2026
0ddcd67
Apply suggestion from @shakedregev
shakedregev Jul 10, 2026
4670635
Revert documentation delimiter change
alexander-novo Jul 10, 2026
7c1b1cb
Update constants and templates
alexander-novo Jul 10, 2026
c5e345b
Remove SUNDIALS type
alexander-novo Jul 10, 2026
4086a9f
Fix header include templating
alexander-novo Jul 10, 2026
fc3f548
Update rosenbrock test cmake target name
alexander-novo Jul 10, 2026
8546dda
Update ReSolve dependency
alexander-novo Jul 10, 2026
21affa7
Remove extra sundials include
alexander-novo Jul 10, 2026
bfbd34a
Update test name
alexander-novo Jul 10, 2026
2be100a
remove extra ReSolve memory space
alexander-novo Jul 12, 2026
58e9137
Break Rosenbrock helper classes into own files
alexander-novo Jul 13, 2026
abd9071
Apply pre-commit fixes
alexander-novo Jul 13, 2026
7c16628
Update Rosenbrock to use new LinearSolver interface
alexander-novo Jul 13, 2026
a69598f
Apply pre-commit fixes
alexander-novo Jul 13, 2026
8cd2a68
Moved Rosenbrock support classes to Native folder
alexander-novo Jul 14, 2026
e5226df
Change Integrator namespace
alexander-novo Jul 14, 2026
774f47d
Remove ResolveMemoryUtils.hpp
alexander-novo Jul 14, 2026
2878373
document test_order
alexander-novo Jul 14, 2026
91d0fd8
Apply pre-commit fixes
alexander-novo Jul 14, 2026
e4b1206
Add necessary headers to cmake
alexander-novo Jul 14, 2026
bcfc4c5
Apply pre-commit fixes
alexander-novo Jul 14, 2026
8941295
Fix compile error.
pelesh Jul 16, 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
- Removed `COO_Matrix` class.
- Added portable `Vector` class and policy-based memory utilities.
- Add new `LinearSolver` interface for linear solvers.
- Added new `Rosenbrock` integrator.
- Clarified naming conventions for macros.

## v0.1

Expand Down
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,10 @@ name. Use all caps (screaming snake case).
constexpr double EXP = 2.7183 // Yes
```

### Macros

Macros should use all caps, same as constants.

### Enums (enumerated types)

Always define `enum`s inside `GridKit` namespace. The `enum` name should
Expand Down
2 changes: 1 addition & 1 deletion GridKit/LinearAlgebra/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_subdirectory(SparseMatrix)
add_subdirectory(DenseMatrix)
add_subdirectory(Vector)
add_subdirectory(Solver)
add_subdirectory(Solver)
7 changes: 2 additions & 5 deletions GridKit/LinearAlgebra/Solver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,5 @@ if(GRIDKIT_ENABLE_RESOLVE)
resolve_system_solver
SOURCES ResolveSystemSolver.cpp
HEADERS ResolveSystemSolver.hpp
LINK_LIBRARIES
PRIVATE
ReSolve::ReSolve
)
endif()
LINK_LIBRARIES PRIVATE ReSolve::ReSolve)
endif()
5 changes: 3 additions & 2 deletions GridKit/LinearAlgebra/Solver/ResolveSystemSolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ namespace GridKit
}

template <class ScalarT, typename IdxT>
ResolveSystemSolver<ScalarT, IdxT>::ResolveSystemSolver(ReSolve::SystemSolver& lin_solver, GridKit::memory::MemorySpace memspace) : lin_solver_(lin_solver), memspace_(memorySpaceAsResolve(memspace))
ResolveSystemSolver<ScalarT, IdxT>::ResolveSystemSolver(ReSolve::SystemSolver& lin_solver, GridKit::memory::MemorySpace memspace)
: lin_solver_(lin_solver), memspace_(memorySpaceAsResolve(memspace))
{
}

Expand Down Expand Up @@ -101,4 +102,4 @@ namespace GridKit

template class ResolveSystemSolver<double, int>;
} // namespace LinearAlgebra
} // namespace GridKit
} // namespace GridKit
2 changes: 1 addition & 1 deletion GridKit/LinearAlgebra/Solver/ResolveSystemSolver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ namespace GridKit
ReSolve::memory::MemorySpace memspace_;
};
} // namespace LinearAlgebra
} // namespace GridKit
} // namespace GridKit
29 changes: 25 additions & 4 deletions GridKit/Solver/Dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@
# - Cameron Rutherford <cameron.rutherford@pnnl.gov>
#]]

set(_install_headers DynamicSolver.hpp Ida.hpp)

if(GRIDKIT_ENABLE_SUNDIALS_SPARSE)
gridkit_add_library(
solvers_dyn
SOURCES Ida.cpp
HEADERS ${_install_headers}
HEADERS Ida.hpp DynamicSolver.hpp
LINK_LIBRARIES
PUBLIC
SUNDIALS::nvecserial
Expand All @@ -29,7 +27,7 @@ else()
gridkit_add_library(
solvers_dyn
SOURCES Ida.cpp
HEADERS ${_install_headers}
HEADERS Ida.hpp DynamicSolver.hpp
LINK_LIBRARIES
PUBLIC
SUNDIALS::nvecserial
Expand All @@ -42,3 +40,26 @@ else()
PUBLIC
GridKit::sparse_matrix)
endif()

if(GRIDKIT_ENABLE_RESOLVE)
gridkit_add_library(
rosenbrock
SOURCES Rosenbrock.cpp RosenbrockTableaus.cpp
HEADERS Rosenbrock.hpp
Native/ErrorNorm.hpp
Native/StepControl.hpp
Native/StepController.hpp
LINK_LIBRARIES
PRIVATE
ReSolve::ReSolve
PUBLIC
GridKit::dense_vector
PUBLIC
GridKit::definitions
PUBLIC
GridKit::utilities_logger
PUBLIC
GridKit::sparse_matrix)
endif()

add_subdirectory(Native)
33 changes: 33 additions & 0 deletions GridKit/Solver/Dynamic/Native/AdaptiveStep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "AdaptiveStep.hpp"

#include <algorithm>
#include <cmath>

#include <GridKit/Constants.hpp>

namespace AnalysisManager
{
namespace NativeDynamicSolver
{
/**
* @brief Standard textbook adaptive controller. Accept if `err <= 1` and use
*
* \f[h_{new} = h * \min \left\{fac_{max}, \max\left\{fac_{min}, fac_{scale} \cdot e ^{-1/p}\right\}\right\}.\f]
*
*/
template <typename RealT>
StepControl<RealT> AdaptiveStep<RealT>::nextStep(RealT err, StepControl<RealT> prev_step, uint8_t method_order)
{
StepControl<RealT> next_step = prev_step;

double h_mult = std::min(params_.fac_max_, std::max(params_.fac_scale_ * std::pow(err, GridKit::MINUS_ONE<RealT> / method_order), params_.fac_min_));

next_step.accept_ = err <= 1;
next_step.step_size_ *= h_mult;

return next_step;
}

template class AdaptiveStep<double>;
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
72 changes: 72 additions & 0 deletions GridKit/Solver/Dynamic/Native/AdaptiveStep.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#pragma once

#include <GridKit/Solver/Dynamic/Native/StepController.hpp>

namespace AnalysisManager
{
namespace NativeDynamicSolver
{

/**
* @brief A simple textbook adaptive `StepController` which seeks to meet a relative and absolute tolerance
* based on an error estimate.
*
*/
template <typename RealT>
class AdaptiveStep : public StepController<RealT>
{
/**
* @brief Parameters for the step controller.
*
*/
struct Parameters
{
/**
* @brief The minimum multiple by which the step size can be multiplied to obtain the new step size.
* Increasing this can allow the integrator to be slightly more conservative in selecting the step size
* - decreasing the number of steps taken but increasing the risk of failing the next step.
*
* @note Should be between 0 and 1.
*
*/
RealT fac_min_ = 0.2;
/**
* @brief The maximum multiple by which the step size can be multiplied to obtain the new step size.
* Decreasing this will make the integrator more conservative in selecting the step size -
* increasing the number of steps taken but decreasing the risk of failing the next step.
*
* @note Should be greater than 1.
*
*/
RealT fac_max_ = 5.0;
/**
* @brief A "fudge factor" introduced to decrease risk of failing a step. The larger the fudge factor,
* the more likely steps will fail, but fewer steps will be taken.
*
* @note Should be between 0 and 1.
*
*/
RealT fac_scale_ = 0.9;
} params_;

public:
AdaptiveStep(const Parameters& params)
: params_(params)
{
}

StepControl<RealT> nextStep(RealT err, StepControl<RealT> prev_step, uint8_t method_order) final;

/**
* @brief This controller uses error estimates.
*
* @see `nextStep()`
*
*/
constexpr bool usesError() const final
{
return true;
}
};
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
21 changes: 21 additions & 0 deletions GridKit/Solver/Dynamic/Native/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
if(GRIDKIT_ENABLE_RESOLVE)
gridkit_add_library(
inf_norm
SOURCES InfNorm.cpp
HEADERS InfNorm.hpp
LINK_LIBRARIES
PRIVATE
ReSolve::ReSolve
PUBLIC
GridKit::dense_vector)
endif()

gridkit_add_library(
adaptive_step
SOURCES AdaptiveStep.cpp
HEADERS AdaptiveStep.hpp)

gridkit_add_library(
fixed_step
SOURCES FixedStep.cpp
HEADERS FixedStep.hpp)
38 changes: 38 additions & 0 deletions GridKit/Solver/Dynamic/Native/ErrorNorm.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include <GridKit/LinearAlgebra/Vector/Vector.hpp>
#include <GridKit/LinearAlgebra/Vector/VectorHandler.hpp>
#include <GridKit/ScalarTraits.hpp>

namespace AnalysisManager
{
namespace NativeDynamicSolver
{
/**
* @brief Interface for error norms. Used to calculate the `err` parameter in `StepController::nextStep` based on a residual state error vector.
*
*/
template <class ScalarT, typename IdxT>
class ErrorNorm
{
using State = GridKit::LinearAlgebra::Vector<ScalarT, IdxT>;
using RealT = typename GridKit::ScalarTraits<ScalarT>::RealT;

public:
/**
* @brief Calculate an error to be used by a step controller. Typically, an error > 1 indicates an error which does not meet tolerances, while
* an error < 1 indicates an error which meets tolerances. For that reason, tolerances should be included in the calculation of the error.
*
* @param err The state error residual being measured.
* @param y The state that the error was calculated from. Can be used for proper relative error normalization.
* @param yprev The state from the previous step. Can be used for proper relative error normalization.
* @param handler A vector handler which can be used to facilitate vector operations.
* @param memspace The memory space which vector operations should be performed in/.
* @return The error.
*
* @todo Allow this method to fail, since it will likely involve linear algebra calls.
*/
virtual RealT errorNorm(State& err, State& y, State& yprev, GridKit::LinearAlgebra::VectorHandler<ScalarT, IdxT>& handler, GridKit::memory::MemorySpace memspace) const = 0;
};
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
22 changes: 22 additions & 0 deletions GridKit/Solver/Dynamic/Native/FixedStep.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "FixedStep.hpp"

namespace AnalysisManager
{
namespace NativeDynamicSolver
{
/**
* @brief Fixed step - accept every step, no matter the error, and keep the step size the same.
*
*/
template <typename RealT>
StepControl<RealT> FixedStep<RealT>::nextStep([[maybe_unused]] RealT err, StepControl<RealT> prev_step, [[maybe_unused]] uint8_t method_order)
{
return StepControl<RealT>{
.accept_ = true,
.step_size_ = prev_step.step_size_,
};
}

template class FixedStep<double>;
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
34 changes: 34 additions & 0 deletions GridKit/Solver/Dynamic/Native/FixedStep.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include <GridKit/Solver/Dynamic/Native/StepController.hpp>

namespace AnalysisManager
{
namespace NativeDynamicSolver
{
/**
* @brief A fixed step controller which doesn't change the step size and accepts every step.
* Useful if you know what time scale your simulation operates on apriori and you're
* using a method without an embedded error controller.
*
* To set the fixed size, set the `Rosenbrock::Parameters::starting_step` parameter.
*
*/
template <typename RealT>
class FixedStep : public StepController<RealT>
{
StepControl<RealT> nextStep(RealT err, StepControl<RealT> prev_step, uint8_t method_order) final;

/**
* @brief This controller does not use error estimates.
*
* @see `nextStep()`
*
*/
constexpr bool usesError() const final
{
return false;
}
};
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
55 changes: 55 additions & 0 deletions GridKit/Solver/Dynamic/Native/InfNorm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include "InfNorm.hpp"

#include <format>

#include <GridKit/Constants.hpp>

namespace AnalysisManager
{
namespace NativeDynamicSolver
{
/**
* @brief Calculate the infinity error norm as
*
* \f[e = \max_i\frac{|\hat{e}_i|}{Atol_i + Rtol \cdot \max\{|y_{0i}|, |y_{1i}|\}},\f]
*
* where \f(y_0\f) is the initial state, \f(y_1\f) is the next state, and \f(\hat{e}\f) is the estimated error made in calculating
* the next state (typically \f(\hat{e} = y_1 - \hat{y}_1\f) for some different-order approximation \f(\hat{y}_1\f)).
*
* @param err \f(\hat{e}\f) in the above formula.
* @param y \f(y_1\f) in the above formula.
* @param yprev \f(y_0\f) in the above formula.
* @param handler The handler to be used for performing linear algebra operations.
* @param memspace The memory space to be used for performing linear lagebra operations.
* @see `Rosenbrock::errorEstimate()`
*/
template <class ScalarT, typename IdxT>
InfNorm<ScalarT, IdxT>::RealT InfNorm<ScalarT, IdxT>::errorNorm(State& err, State& y, State& yprev, GridKit::LinearAlgebra::VectorHandler<ScalarT, IdxT>& handler, GridKit::memory::MemorySpace memspace) const
{
if (int err_code = workspace_.out_->copyFromExternal(&err, memspace, memspace))
{
throw std::format("GridKit::LinearAlgebra::Vector::copyFromExternal failed with error code {}", err_code);
}
if (int err_code = workspace_.scale_->copyFromExternal(&y, memspace, memspace))
{
throw std::format("GridKit::LinearAlgebra::Vector::copyFromExternal failed with error code {}", err_code);
}
if (int err_code = workspace_.yprev_abs_->copyFromExternal(&yprev, memspace, memspace))
{
throw std::format("GridKit::LinearAlgebra::Vector::copyFromExternal failed with error code {}", err_code);
}

handler.abs(workspace_.scale_.get(), workspace_.scale_.get(), memspace);
handler.abs(workspace_.yprev_abs_.get(), workspace_.scale_.get(), memspace);
handler.max(workspace_.yprev_abs_.get(), workspace_.scale_.get(), workspace_.scale_.get(), memspace);

// TODO: This scal shouldn't be necessary, but axpy doesn't support scaling the y parameter. In the future,
// the scaling should be able to be put on the next axpy.
handler.scal(params_.rel_tol_, workspace_.scale_.get(), memspace);
handler.axpy(GridKit::ONE<RealT>, params_.abs_tol_.get(), workspace_.scale_.get(), memspace);
handler.diagSolve(workspace_.scale_.get(), workspace_.out_.get(), memspace);

return handler.amax(workspace_.out_.get(), memspace);
}
} // namespace NativeDynamicSolver
} // namespace AnalysisManager
Loading
Loading