| 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 | #include "Vector/map_vector.hpp" |
| 14 | #include "VCluster/VCluster.hpp" |
| 15 | |
| 16 | #ifdef HAVE_EIGEN |
| 17 | #include <Eigen/Sparse> |
| 18 | #define DEFAULT_MATRIX = EIGEN_BASE |
| 19 | #else |
| 20 | #define DEFAULT_MATRIX = 0 |
| 21 | #endif |
| 22 | |
| 23 | /*! \brief It store the non zero elements of the matrix |
| 24 | * |
| 25 | * |
| 26 | */ |
| 27 | template<typename T> struct cval |
| 28 | { |
| 29 | size_t j; |
| 30 | T value; |
| 31 | }; |
| 32 | |
| 33 | /*! \brief It store the non zero elements of the matrix |
| 34 | * |
| 35 | * |
| 36 | */ |
| 37 | template<typename T, int impl> struct triplet |
| 38 | { |
| 39 | long int i; |
| 40 | long int j; |
| 41 | T val; |
| 42 | |
| 43 | triplet(long int i, long int j, T val) |
| 44 | { |
| 45 | row() = i; |
| 46 | col() = j; |
| 47 | value() = val; |
| 48 | } |
| 49 | |
| 50 | triplet() |
| 51 | { |
| 52 | } |
| 53 | |
| 54 | long int & row() |
| 55 | { |
| 56 | return i; |
| 57 | } |
| 58 | |
| 59 | long int & col() |
| 60 | { |
| 61 | return j; |
| 62 | } |
| 63 | |
| 64 | T & value() |
| 65 | { |
| 66 | return val; |
| 67 | } |
| 68 | }; |
| 69 | |
| 70 | /*! \brief Sparse Matrix implementation |
| 71 | * |
| 72 | * \tparam T Type of the sparse Matrix store on each row,colums |
| 73 | * \tparam id_t type of id |
| 74 | * \tparam Mi implementation |
| 75 | * |
| 76 | */ |
| 77 | template<typename T,typename id_t ,unsigned int Mi DEFAULT_MATRIX> |
| 78 | class SparseMatrix |
| 79 | { |
| 80 | public: |
| 81 | |
| 82 | //! Triplet implementation id |
| 83 | typedef boost::mpl::int_<-1> triplet_impl; |
| 84 | |
| 85 | //! Triplet type |
| 86 | typedef triplet<T,-1> triplet_type; |
| 87 | |
| 88 | openfpm::vector<triplet_type> stub_vt; |
| 89 | int stub_i; |
| 90 | T stub_t; |
| 91 | |
| 92 | public: |
| 93 | |
| 94 | |
| 95 | 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;} |
| 96 | 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;} |
| 97 | SparseMatrix() {std::cerr << __FILE__ << ":" << __LINE__ << " Error in order to use this class you must compile OpenFPM with linear algebra support" << std::endl;} |
| 98 | 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;} |
| 99 | 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;} |
| 100 | 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;} |
| 101 | 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;} |
| 102 | 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;} |
| 103 | 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;} |
| 104 | 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;} |
| 105 | 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;} |
| 106 | }; |
| 107 | |
| 108 | #ifdef HAVE_EIGEN |
| 109 | #include "SparseMatrix_Eigen.hpp" |
| 110 | #endif |
| 111 | |
| 112 | #ifdef HAVE_PETSC |
| 113 | #include "SparseMatrix_petsc.hpp" |
| 114 | #endif |
| 115 | |
| 116 | #endif /* OPENFPM_NUMERICS_SRC_MATRIX_SPARSEMATRIX_HPP_ */ |
| 117 | |