OpenFPM_data  0.1.0
Project that contain the implementation and interfaces for basic structure like vectors, grids, graph ... .
 All Data Structures Namespaces Functions Variables Typedefs Friends
Matrix.hpp
1 /*
2  * Matrix.hpp
3  *
4  * Created on: Jun 3, 2015
5  * Author: Pietro Incardona
6  */
7 
8 #ifndef MATRIX_HPP_
9 #define MATRIX_HPP_
10 
11 
12 #include <boost/fusion/sequence/intrinsic/at_c.hpp>
13 #include <boost/fusion/include/at_c.hpp>
14 #include <boost/fusion/container/vector.hpp>
15 #include <boost/fusion/include/vector.hpp>
16 #include <boost/fusion/container/vector/vector_fwd.hpp>
17 #include <boost/fusion/include/vector_fwd.hpp>
18 #include "boost/multi_array.hpp"
19 #include "Grid/grid_key.hpp"
20 
32 template<unsigned int dim ,typename T> class Matrix
33 {
34  public:
35 
36  typedef T coord_type;
37 
39  typedef boost::fusion::vector<T[dim][dim]> type;
40 
43 
45  static const unsigned int mat = 0;
46 
55  inline T get(size_t i,size_t j) const
56  {
57  return boost::fusion::at_c<mat>(data)[i][j];
58  }
59 
68  inline T& get(size_t i,size_t j)
69  {
70  return boost::fusion::at_c<mat>(data)[i][j];
71  }
72 
79  {
80  for (size_t i = 0 ; i < dim ; i++)
81  {
82  for (size_t j = 0 ; j < dim ; j++)
83  get(i,j) = m.get(i,j);
84  }
85 
86  return *this;
87  }
88 
93  void zero()
94  {
95  for (size_t i = 0 ; i < dim ; i++)
96  {
97  for (size_t j = 0 ; j < dim ; j++)
98  {
99  get(i,j) = 0;
100  }
101  }
102  }
103 
109  Matrix(const Matrix<dim,T> && p)
110  {
111  for(size_t i = 0; i < dim ; i++)
112  {
113  for (size_t j = 0 ; j < dim ; j++)
114  {
115  get(i,j) = p.get(i,j);
116  }
117  }
118  }
119 
126  {
127  for(size_t i = 0; i < dim ; i++)
128  {get(i) = p.get(i);}
129  }
130 
136  Matrix(const T (&p)[dim][dim])
137  {
138  for(size_t i = 0; i < dim ; i++)
139  {get(i) = p[i];}
140  }
141 
148  {
149  for(size_t i = 0 ; i < dim ; i++)
150  {get(i) = key.k[i];}
151  }
152 
158  Matrix(std::initializer_list<T> p1)
159  {
160  size_t i = 0;
161  for(T x : p1)
162  {get(i) = x;i++;}
163  }
164 
167  {}
168 
174  inline static Matrix<dim,T> identity()
175  {
176  Matrix<dim,T> ret;
177 
178  for (size_t i = 0 ; i < dim ; i++)
179  {
180  for (size_t j = 0 ; j < dim ; j++)
181  {
182  ret.get(i,j) = (i == j)?1:0;
183  }
184  }
185 
186  return ret;
187  }
188 
189  static const unsigned int max_prop = 1;
190  static const unsigned int dims = dim;
191 };
192 
193 
194 #endif /* MATRIX_HPP_ */
mem_id k[dim]
structure that store all the index
Definition: grid_key.hpp:327
grid_key_dx is the key to access any element in the grid
Definition: grid_key.hpp:18
void zero()
Set to zero the point coordinate.
Definition: Matrix.hpp:93
boost::fusion::vector< T[dim][dim]> type
boost fusion that store the point
Definition: Matrix.hpp:39
Matrix(const Matrix< dim, T > &p)
Point constructor from point.
Definition: Matrix.hpp:125
Matrix()
Default contructor.
Definition: Matrix.hpp:166
T get(size_t i, size_t j) const
Get coordinate.
Definition: Matrix.hpp:55
Matrix(std::initializer_list< T > p1)
Constructor from a list.
Definition: Matrix.hpp:158
Matrix(grid_key_dx< dim > key)
Constructor from a grid_key_dx<dim>
Definition: Matrix.hpp:147
This class implement an NxN (dense) matrix.
Definition: Matrix.hpp:32
Matrix< dim, T > & operator=(const Matrix< dim, T > &m)
operator= between Matrix
Definition: Matrix.hpp:78
This class is a trick to indicate the compiler a specific specialization pattern. ...
Definition: memory_c.hpp:202
Matrix(const Matrix< dim, T > &&p)
Point constructor from point.
Definition: Matrix.hpp:109
static Matrix< dim, T > identity()
Identity matrix.
Definition: Matrix.hpp:174
static const unsigned int mat
Property id of the point.
Definition: Matrix.hpp:45
Matrix(const T(&p)[dim][dim])
Constructor from an array.
Definition: Matrix.hpp:136
type data
structure that store the data of the point
Definition: Matrix.hpp:42