KASKADE 7 development version
Loading...
Searching...
No Matches
cholmod_solve.hh
Go to the documentation of this file.
1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2/* */
3/* This file is part of the library KASKADE 7 */
4/* https://www.zib.de/research/projects/kaskade7-finite-element-toolbox */
5/* */
6/* Copyright (C) 2025-2025 Zuse Institute Berlin */
7/* */
8/* KASKADE 7 is distributed under the terms of the ZIB Academic License. */
9/* see $KASKADE/academic.txt */
10/* */
11/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13#ifndef CHOLMOD_SOLVE_HH
14#define CHOLMOD_SOLVE_HH
15
16#include <vector>
17#include <memory>
18
20
21namespace Kaskade
22{
23
27
28namespace CholmodDetail
29{
30 class Cholmod;
31}
32
33
37
38// ------------------------------------------------------------------------------------------------
39
46template <class Scalar, class Index = int>
48{
49public:
50
63 std::vector<Index> const& ridx,
64 std::vector<Index> const& cidx,
65 std::vector<Scalar> const& values,
67
68
70
71
77 void solve(std::vector<Scalar> const& b, std::vector<Scalar>& x, bool /* transposed */ = false) const
78 {
79 assert(b.size() >= n);
80 x.resize(n);
81 solve_internal(&b[0],&x[0]);
82 }
83
90 void solve(Scalar const* b, Scalar* x, bool /* transposed */ = false) const
91 {
92 solve_internal(b,x);
93 }
94
101 void solve(std::vector<Scalar> const& b, std::vector<Scalar>& x, int nr,
102 bool /* transposed */ = false) const
103 {
104 assert(b.size()>=n*nr);
105 x.resize(nr*n);
106 for(int i=0; i<nr; ++i)
107 solve_internal(&b[i*n],&x[i*n]);
108 }
109
120 void solve(std::vector<Scalar>& b) const
121 {
122 assert(b.size() >= n);
123 std::vector<Scalar> x(n);
124 solve(b,x);
125 std::swap(b,x);
126 }
127
138 void solve(Scalar* b) const
139 {
140 std::vector<Scalar> x(n);
141 solve(b,&x[0]);
142 std::copy(x.begin(),x.end(),b);
143 }
144
148 virtual size_t size() const
149 {
150 return n;
151 }
152
153
154private:
155
156 void solve_internal(Scalar const* bp, Scalar* xp) const;
157
158 size_t const n; // dimension of A
159 std::unique_ptr<CholmodDetail::Cholmod> cholmod;
160};
161
162
163} // namespace Kaskade
164#endif
void solve(std::vector< Scalar > const &b, std::vector< Scalar > &x, int nr, bool=false) const
Solves the system for nr right hand sides.
virtual size_t size() const
reports the dimension of the system
void solve(std::vector< Scalar > &b) const
Solves the system for the given right hand side.
CholmodFactorization(Index n_, std::vector< Index > const &ridx, std::vector< Index > const &cidx, std::vector< Scalar > const &values, FactorizationOptions opt)
Constructor keeping input data in triplet format (aka coordinate format) constant.
void solve(Scalar *b) const
Solves the system for the given right hand side.
void solve(Scalar const *b, Scalar *x, bool=false) const
Solves the system for the given right hand side.
void solve(std::vector< Scalar > const &b, std::vector< Scalar > &x, bool=false) const
Solves the system for the given right hand side.
The Options struct allows to specify several options of factorization.