cgv
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 
9 namespace cgv {
10  namespace math {
11 
12 class CGV_API sparse_les;
13 
16 
19 {
20  SLC_SYMMETRIC = 1,
21  SLC_UNSYMMETRIC = 2,
22  SLC_NZE_OPTIONAL = 4,
23  SLC_ALL = 7
24 };
25 
28 {
29 public:
31  virtual SparseLesCaps get_caps() const = 0;
33  virtual std::string get_solver_name() const = 0;
35 
41  virtual sparse_les_ptr create(int n, int nr_rhs, int nr_nze = -1) = 0;
42 };
43 
46 
47 
49 class CGV_API sparse_les : public cgv::data::ref_counted
50 {
51 public:
54  static void register_solver_factory(sparse_les_factory_ptr sls_fac);
57  static const std::vector<sparse_les_factory_ptr>& get_solver_factories();
59  static sparse_les_ptr create_by_name(const std::string& solver_name, int n, int nr_rhs, int nr_nze = -1);
61  static sparse_les_ptr create_by_cap(SparseLesCaps caps, int n, int nr_rhs, int nr_nze = -1);
63 
65  virtual void set_mat_entry(int r, int c, double val) = 0;
68  virtual void set_b_entry(int i, double val);
70  virtual void set_b_entry(int i, int j, double val) = 0;
72  virtual double& ref_b_entry(int i);
74  virtual double& ref_b_entry(int i, int j) = 0;
76  virtual bool solve(bool analyze_residual = false) = 0;
80  virtual double get_x_entry(int i) const;
83  virtual double get_x_entry(int i, int j) const = 0;
85 };
86 
88 template <class T>
90 {
91 protected:
92  std::string solver_name;
93  SparseLesCaps caps;
94 public:
95  sparse_les_factory_impl(const std::string& _solver_name, SparseLesCaps _caps) :
96  solver_name(_solver_name), caps(_caps) {}
98  SparseLesCaps get_caps() const { return caps; }
100  std::string get_solver_name() const { return solver_name; }
102  sparse_les_ptr create(int n, int nr_rhs, int nr_nze) {
103  return sparse_les_ptr(new T(n, nr_rhs, nr_nze));
104  }
105 };
106 
107 
109 template <class T>
111 {
112  register_sparse_les_factory(const std::string& _solver_name, SparseLesCaps _caps) {
114  new sparse_les_factory_impl<T>(_solver_name, _caps)));
115  }
116 };
117 
118  }
119 }
120 
121 #include <cgv/config/lib_end.h>
cgv::math::sparse_les::set_b_entry
virtual void set_b_entry(int i, int j, double val)=0
set i-th entry in the j-th right hand side
cgv::math::sparse_les_factory_impl::get_solver_name
std::string get_solver_name() const
return the name of the solver
Definition: sparse_les.h:100
cgv::math::sparse_les_factory_impl
implementation of factory class for sparse linear system solvers
Definition: sparse_les.h:90
cgv::math::sparse_les_ptr
cgv::data::ref_ptr< sparse_les, true > sparse_les_ptr
reference counted pointer type for sparse les solver
Definition: sparse_les.h:15
cgv::math::sparse_les::register_solver_factory
static void register_solver_factory(sparse_les_factory_ptr sls_fac)
register a factory for a new type of linear equation solver
Definition: sparse_les.cxx:14
cgv::math::solve
bool solve(const up_tri_mat< T > &a, const vec< T > &b, vec< T > &x)
Definition: lin_solve.h:20
cgv::math::sparse_les_factory
factory class for sparse linear system solvers
Definition: sparse_les.h:28
cgv::math::sparse_les_factory_ptr
cgv::data::ref_ptr< sparse_les_factory, true > sparse_les_factory_ptr
reference counted pointer type for sparse les solver factories
Definition: sparse_les.h:45
cgv::data::ref_ptr
Definition: ref_ptr.h:19
cgv::math::sparse_les_factory_impl::create
sparse_les_ptr create(int n, int nr_rhs, int nr_nze)
create an instance of the solver.
Definition: sparse_les.h:102
cgv::math::SparseLesCaps
SparseLesCaps
capability options for a sparse linear solver
Definition: sparse_les.h:19
cgv::math::register_sparse_les_factory
helper template to register a sparse les solver
Definition: sparse_les.h:111
cgv::math::sparse_les_factory_impl::get_caps
SparseLesCaps get_caps() const
return the supported capabilities of the solver
Definition: sparse_les.h:98
cgv::math::sparse_les::get_x_entry
virtual double get_x_entry(int i, int j) const =0
return the i-th component of the j-th solution vector
cgv::data::ref_counted
Definition: ref_counted.h:11
cgv::math::sparse_les_factory::get_solver_name
virtual std::string get_solver_name() const =0
return the name of the solver
cgv::math::sparse_les_factory::get_caps
virtual SparseLesCaps get_caps() const =0
return the supported capabilities of the solver
cgv::math::sparse_les
Definition: sparse_les.h:50
cgv::math::sparse_les_factory::create
virtual sparse_les_ptr create(int n, int nr_rhs, int nr_nze=-1)=0
create an instance of the solver.
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::math::sparse_les::ref_b_entry
virtual double & ref_b_entry(int i, int j)=0
set i-th entry in j-th right hand side