OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
NativeGmres.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Caleb Buahin
3
12
13#pragma once
14
15#include <cstddef>
16#include <functional>
17#include <vector>
18
19namespace openswmm::fv {
20
26public:
27 using Apply = std::function<bool(const double*, double*)>;
28 struct Controls {
29 int restart = 40, max_iterations = 200;
31 double absolute_tolerance = 1.e-12, relative_tolerance = 1.e-10;
32 std::size_t workspace_limit_bytes = 64 * 1024 * 1024;
33 };
45 struct Result {
47 int iterations = 0, restarts = 0, matvecs = 0;
49 std::size_t workspace_bytes = 0;
50 double true_residual = 0.0, estimated_residual = 0.0, tolerance = 0.0;
51 bool happy_breakdown = false;
52 int workspace_growths = 0; // vector capacity increases in this call
53 bool reused_workspace = false; // every required vector reused without growth
58 bool converged() const { return status == Status::Converged; }
59 };
60
82 Result solve(const std::vector<double>& rhs, const Apply& matrix, const Apply& inverse,
83 const Controls& controls, std::vector<double>& output);
89 std::size_t workspaceBytes() const { return bytes(); }
96 void clearWorkspace() { release(); }
97
98private:
99 std::vector<double> basis_, hessenberg_, cosine_, sine_, g_, y_;
100 std::vector<double> x_, r_, w_, z_, update_, image_;
105 std::size_t bytes() const;
111 void release();
112};
113} // namespace openswmm::fv
Definition NativeGmres.hpp:25
std::size_t workspaceBytes() const
Count retained numerical workspace capacity in bytes.
Definition NativeGmres.hpp:89
Status
Definition NativeGmres.hpp:34
@ Breakdown
Definition NativeGmres.hpp:41
@ OperatorFailure
Definition NativeGmres.hpp:39
@ MemoryLimit
Definition NativeGmres.hpp:37
@ Stagnated
Definition NativeGmres.hpp:42
@ PreconditionerFailure
Definition NativeGmres.hpp:40
@ NonFinite
Definition NativeGmres.hpp:38
@ IterationLimit
Definition NativeGmres.hpp:43
@ InvalidInput
Definition NativeGmres.hpp:36
@ Converged
Definition NativeGmres.hpp:35
Result solve(const std::vector< double > &rhs, const Apply &matrix, const Apply &inverse, const Controls &controls, std::vector< double > &output)
Solve a dense-vector linear system with restarted fixed-right-preconditioned GMRES.
Definition NativeGmres.cpp:78
std::function< bool(const double *, double *)> Apply
Definition NativeGmres.hpp:27
void clearWorkspace()
Release all retained numerical workspace allocations.
Definition NativeGmres.hpp:96
Definition Controls.cpp:47
Definition AcceptedWaterVolumes.hpp:8
Definition NativeGmres.hpp:28
int restart
Definition NativeGmres.hpp:29
std::size_t workspace_limit_bytes
Definition NativeGmres.hpp:32
double absolute_tolerance
Definition NativeGmres.hpp:31
int stagnant_restarts
Definition NativeGmres.hpp:30
int max_iterations
Definition NativeGmres.hpp:29
double relative_tolerance
Definition NativeGmres.hpp:31
Definition NativeGmres.hpp:45
double estimated_residual
Definition NativeGmres.hpp:50
bool converged() const
Test whether the solve result passed true-residual acceptance.
Definition NativeGmres.hpp:58
Status status
Definition NativeGmres.hpp:46
int reorthogonalizations
Definition NativeGmres.hpp:48
bool happy_breakdown
Definition NativeGmres.hpp:51
std::size_t workspace_bytes
Definition NativeGmres.hpp:49
int iterations
Definition NativeGmres.hpp:47
bool reused_workspace
Definition NativeGmres.hpp:53
double tolerance
Definition NativeGmres.hpp:50
double true_residual
Definition NativeGmres.hpp:50
int matvecs
Definition NativeGmres.hpp:47
int restarts
Definition NativeGmres.hpp:47
int workspace_growths
Definition NativeGmres.hpp:52
int preconditioner_applications
Definition NativeGmres.hpp:48