OpenFPM_pdata  1.1.0
Project that contain the implementation of distributed structures
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Pages
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  {
129  for (size_t j = 0 ; j < dim ; j++)
130  {
131  get(i,j) = p.get(i,j);
132  }
133  }
134  }
135 
141  Matrix(const T (&p)[dim][dim])
142  {
143  for(size_t i = 0; i < dim ; i++)
144  {
145  for (size_t j = 0 ; j < dim ; j++)
146  {
147  get(i,j) = p[i][j];
148  }
149  }
150  }
151 
154  {}
155 
161  inline static Matrix<dim,T> identity()
162  {
163  Matrix<dim,T> ret;
164 
165  for (size_t i = 0 ; i < dim ; i++)
166  {
167  for (size_t j = 0 ; j < dim ; j++)
168  {
169  /* coverity[dead_error_line] */
170  ret.get(i,j) = (i == j)?1:0;
171  }
172  }
173 
174  return ret;
175  }
176 
178  static const unsigned int max_prop = 1;
179 
181  static const unsigned int dims = dim;
182 };
183 
184 
185 #endif /* MATRIX_HPP_ */
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
static const unsigned int max_prop
1 property
Definition: Matrix.hpp:178
Matrix(const Matrix< dim, T > &p)
Point constructor from point.
Definition: Matrix.hpp:125
Matrix()
Default contructor.
Definition: Matrix.hpp:153
T get(size_t i, size_t j) const
Get coordinate.
Definition: Matrix.hpp:55
static const unsigned int dims
dimension of the matrix (it is a square matrix)
Definition: Matrix.hpp:181
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
Matrix(const Matrix< dim, T > &&p)
Point constructor from point.
Definition: Matrix.hpp:109
static Matrix< dim, T > identity()
Identity matrix.
Definition: Matrix.hpp:161
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:141
type data
structure that store the data of the point
Definition: Matrix.hpp:42