OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
SparseMatrix.hpp
1 /*
2  * Matrix.hpp
3  *
4  * Created on: Oct 5, 2015
5  * Author: i-bird
6  */
7 
8 #ifndef OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_HPP_
9 #define OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_HPP_
10 
11 #include "config/config.h"
12 #include "util/linalgebra_lib.hpp"
13 
14 #ifdef HAVE_EIGEN
15 #include <Eigen/Sparse>
16 #define DEFAULT_MATRIX = EIGEN_BASE
17 #else
18 #define DEFAULT_MATRIX = 0
19 #endif
20 
25 template<typename T> struct cval
26 {
27  size_t j;
28  T value;
29 };
30 
35 template<typename T, int impl> struct triplet
36 {
37  long int i;
38  long int j;
39  T val;
40 
41  triplet(long int i, long int j, T val)
42  {
43  row() = i;
44  col() = j;
45  value() = val;
46  }
47 
48  triplet()
49  {
50  }
51 
52  long int & row()
53  {
54  return i;
55  }
56 
57  long int & col()
58  {
59  return j;
60  }
61 
62  T & value()
63  {
64  return val;
65  }
66 };
67 
75 template<typename T,typename id_t ,unsigned int Mi DEFAULT_MATRIX>
77 {
78 public:
79 
81  typedef boost::mpl::int_<-1> triplet_impl;
82 
84  typedef triplet<T,-1> triplet_type;
85 
87  int stub_i;
88  T stub_t;
89 
90 public:
91 
92 
93  SparseMatrix(size_t N1, size_t N2) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;}
94  SparseMatrix(size_t N1, size_t N2, size_t loc) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;}
95  SparseMatrix() {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;}
96  openfpm::vector<triplet_type> & getMatrixTriplets() {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return stub_vt;}
97  const int & getMat() const {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return stub_i;}
98  int & getMat() {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return stub_i;}
99  void resize(size_t row, size_t col, size_t row_n, size_t col_n) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;}
100  T operator()(id_t i, id_t j) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return stub_t;}
101  bool save(const std::string & file) const {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;return true;}
102  bool load(const std::string & file) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return false;}
103  T getValue(size_t r, size_t c) {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl; return stub_i;}
104 };
105 
106 #ifdef HAVE_EIGEN
107 #include "SparseMatrix_Eigen.hpp"
108 #endif
109 
110 #ifdef HAVE_PETSC
111 #include "SparseMatrix_petsc.hpp"
112 #endif
113 
114 #endif /* OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_HPP_ */
It store the non zero elements of the matrix.
It store the non zero elements of the matrix.
Sparse Matrix implementation.
triplet< T,-1 > triplet_type
Triplet type.
boost::mpl::int_<-1 > triplet_impl
Triplet implementation id.
Implementation of 1-D std::vector like structure.
Definition: map_vector.hpp:61