1#ifndef DUNE_COPASI_SOLVER_ISTL_UMFPACK_HH
2#define DUNE_COPASI_SOLVER_ISTL_UMFPACK_HH
4#if !HAVE_SUITESPARSE_UMFPACK
5#error Trying to use umfpack wrapper without including umfpack
10#include <dune/istl/solver.hh>
18#if __cpp_lib_execution >= 201603L
24template<Concept::AssembledLinearOperator O,
class Alloc = std::allocator<
void>>
25class UMFPackWapper final :
public InverseOperator<typename O::domain_type, typename O::range_type>
27 using Matrix =
typename O::matrix_type;
28 using X =
typename O::domain_type;
29 using Y =
typename O::range_type;
30 using MI = PDELab::MultiIndex<std::size_t, blockLevel<Matrix>()>;
32 static const inline std::map<std::string, double> umf_strategy_map = {
38 static const inline std::map<std::string, double> umf_ordering_map = {
44#if defined(UMFPACK_VER) && (UMFPACK >= UMFPACK_VER_CODE(6, 0))
62 struct SymbolicDeleter
113 if (
config.get(
"report_control",
false))
116 storeFlatMatrix(
op->getmat());
121 void forEachMatrixEntry(M&&
mat,
const auto&
call_back, MI row = MI(), MI col = MI())
123 using MD = std::decay_t<M>;
124 if constexpr (IsNumber<MD>::value) {
136 void storeFlatMatrix(
const Matrix&
mat)
140 forEachMatrixEntry(
mat, [&](
double val, MI row, MI col) {
141 entries.emplace_back(Entry{ val, row, col });
147 return std::ranges::lexicographical_compare(
lhs.row,
rhs.row);
161 for (
auto& [val, row, col] :
entries) {
163 if (row != std::exchange(
last_row, row))
176 return std::ranges::lexicographical_compare(std::array{
lhs.col,
lhs.row },
177 std::array{
rhs.col,
rhs.row },
178 std::ranges::lexicographical_compare);
199 for (std::size_t
i = 0;
i !=
entries.size(); ++
i) {
202 if (col != std::exchange(
last_col, col))
260 PDELab::forEachContainerEntry(
b, [&](
auto val) {
_umf_b[
flat_i++] = val; });
283 PDELab::forEachContainerEntry(
x, [&](
auto& val) { val =
_umf_x[
flat_i++]; });
297 return SolverCategory::Category::sequential;
302 return [](
const std::shared_ptr<LinearOperator<X, Y>>&
op,
304 const Alloc&
alloc) -> std::shared_ptr<InverseOperator<X, Y>> {
310 auto aop = std::dynamic_pointer_cast<O>(
op);
double _umf_info[UMFPACK_INFO]
Definition umfpack.hh:329
void apply(X &x, Y &b, InverseOperatorResult &res) override
Definition umfpack.hh:249
double _umf_control[UMFPACK_CONTROL]
Definition umfpack.hh:328
std::vector< int64_t, Int64Alloc > _umf_offsets
Definition umfpack.hh:320
std::unique_ptr< void, NumericDeleter > _umf_numeric_ptr
Definition umfpack.hh:327
int _umf_m
Definition umfpack.hh:318
std::vector< int64_t, Int64Alloc > _umf_iworkspace
Definition umfpack.hh:322
bool _report_numeric
Definition umfpack.hh:331
bool _report_info
Definition umfpack.hh:332
UMFPackWapper(const std::shared_ptr< const O > &op, const ParameterTree &config, const Alloc &alloc=Alloc())
Definition umfpack.hh:74
std::vector< double, DoubleAlloc > _umf_values
Definition umfpack.hh:324
std::vector< double, DoubleAlloc > _umf_b
Definition umfpack.hh:326
SolverCategory::Category category() const override
Definition umfpack.hh:295
static auto factory()
Definition umfpack.hh:300
Alloc _alloc
Definition umfpack.hh:319
int _umf_n
Definition umfpack.hh:318
void apply(X &x, Y &b, double reduction, InverseOperatorResult &res) override
Definition umfpack.hh:290
std::vector< double, DoubleAlloc > _umf_x
Definition umfpack.hh:325
std::vector< int64_t, Int64Alloc > _umf_rows
Definition umfpack.hh:321
bool _report_symbolic
Definition umfpack.hh:330
std::vector< double, DoubleAlloc > _umf_dworkspace
Definition umfpack.hh:323
Definition block_jacobi.hh:14
auto format_exception(Exception &&e, fmt::format_string< Args... > format, Args &&... args)
Definition exceptions.hh:23
constexpr bool is_bitflags_v
Alias for Bitflag indicator.
Definition bit_flags.hh:24