cgv
Loading...
Searching...
No Matches
sparse_les.h
1#pragma once
2
3#include <vector>
4#include <string>
5#include <cgv/data/ref_ptr.h>
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace math {
11
12class CGV_API sparse_les;
13
15typedef cgv::data::ref_ptr<sparse_les,true> sparse_les_ptr;
16
18enum SparseLesCaps
19{
20 SLC_SYMMETRIC = 1,
21 SLC_UNSYMMETRIC = 2,
22 SLC_NZE_OPTIONAL = 4,
23 SLC_ALL = 7
24};
25
28{
29public:
31 virtual ~sparse_les_factory();
33 virtual SparseLesCaps get_caps() const = 0;
35 virtual std::string get_solver_name() const = 0;
37
43 virtual sparse_les_ptr create(int n, int nr_rhs, int nr_nze = -1) = 0;
44};
45
48
49
51class CGV_API sparse_les : public cgv::data::ref_counted
52{
53public:
55 virtual ~sparse_les() {}
59 static void register_solver_factory(sparse_les_factory_ptr sls_fac);
61 static const std::vector<sparse_les_factory_ptr>& get_solver_factories();
63 static sparse_les_ptr create_by_name(const std::string& solver_name, int n, int nr_rhs, int nr_nze = -1);
65 static sparse_les_ptr create_by_cap(SparseLesCaps caps, int n, int nr_rhs, int nr_nze = -1);
67
70 virtual void set_mat_entry(int r, int c, double val) = 0;
72 virtual void set_b_entry(int i, double val);
74 virtual void set_b_entry(int i, int j, double val) = 0;
76 virtual double& ref_b_entry(int i);
78 virtual double& ref_b_entry(int i, int j) = 0;
80
81 virtual bool solve(bool analyze_residual = false) = 0;
85 virtual double get_x_entry(int i) const;
87 virtual double get_x_entry(int i, int j) const = 0;
89};
90
92template <class T>
94{
95protected:
96 std::string solver_name;
97 SparseLesCaps caps;
98public:
99 sparse_les_factory_impl(const std::string& _solver_name, SparseLesCaps _caps) :
100 solver_name(_solver_name), caps(_caps) {}
102 SparseLesCaps get_caps() const { return caps; }
104 std::string get_solver_name() const { return solver_name; }
106 sparse_les_ptr create(int n, int nr_rhs, int nr_nze) {
107 return sparse_les_ptr(new T(n, nr_rhs, nr_nze));
108 }
109};
110
111
113template <class T>
115{
116 register_sparse_les_factory(const std::string& _solver_name, SparseLesCaps _caps) {
118 new sparse_les_factory_impl<T>(_solver_name, _caps)));
119 }
120};
121
122 }
123}
124
125#include <cgv/config/lib_end.h>
if you derive your class from this class, a ref_ptr will do reference counting in the inhereted ref_c...
Definition ref_counted.h:11
reference counted pointer, which can work together with types that are derived from ref_counted,...
Definition ref_ptr.h:160
implementation of factory class for sparse linear system solvers
Definition sparse_les.h:94
std::string get_solver_name() const
return the name of the solver
Definition sparse_les.h:104
SparseLesCaps get_caps() const
return the supported capabilities of the solver
Definition sparse_les.h:102
sparse_les_ptr create(int n, int nr_rhs, int nr_nze)
create an instance of the solver.
Definition sparse_les.h:106
factory class for sparse linear system solvers
Definition sparse_les.h:28
virtual SparseLesCaps get_caps() const =0
return the supported capabilities of the solver
virtual std::string get_solver_name() const =0
return the name of the solver
virtual sparse_les_ptr create(int n, int nr_rhs, int nr_nze=-1)=0
create an instance of the solver.
interface for implementations of solvers for sparse linear systems of the form A * x = b with a squar...
Definition sparse_les.h:52
virtual void set_mat_entry(int r, int c, double val)=0
set entry in row r and column c in the sparse matrix A
virtual ~sparse_les()
virtual destructor since class is abstract
Definition sparse_les.h:55
virtual bool solve(bool analyze_residual=false)=0
try to solve system - in case of success analyze residuals if demanded by the optional parameter
static void register_solver_factory(sparse_les_factory_ptr sls_fac)
register a factory for a new type of linear equation solver
virtual void set_b_entry(int i, int j, double val)=0
set i-th entry in the j-th right hand side
virtual double get_x_entry(int i, int j) const =0
return the i-th component of the j-th solution vector
virtual double & ref_b_entry(int i, int j)=0
set i-th entry in j-th right hand side
the cgv namespace
Definition print.h:11
helper template to register a sparse les solver
Definition sparse_les.h:115