LifeV
MatrixSmall.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5 Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6 Copyright (C) 2010 EPFL, Politecnico di Milano, Emory UNiversity
7 
8 This file is part of the LifeV library
9 
10 LifeV is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 3 of the License, or
13 (at your option) any later version.
14 
15 LifeV is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public
21 License along with this library; if not, see <http://www.gnu.org/licenses/>
22 
23 
24 *******************************************************************************
25 */
26 //@HEADER
27 
28 /*!
29  * @file
30  @brief This file contains a simple matrix class
31 
32  @contributor Ivan Kuraj <ivan.kuraj@epfl.ch>
33 */
34 
35 #ifndef _MATRIXSMALL_H_
36 #define _MATRIXSMALL_H_ 1
37 
38 #include <lifev/core/LifeV.hpp>
39 
40 #include <lifev/core/mesh/MeshVertex.hpp>
41 #include <lifev/core/array/RNM.hpp>
42 #include <lifev/core/array/VectorSmall.hpp>
43 
44 #include <vector>
45 #include <cmath>
46 #include <limits>
47 #include <stdexcept>
48 
49 // macros for defining actions on an out-of-bound reference
50 #define MATRIX_SMALL_DIMENSION_CHECK_NO_CHECK 0
51 #define MATRIX_SMALL_DIMENSION_CHECK_ASSERT 1
52 #define MATRIX_SMALL_DIMENSION_CHECK_EXCEPTION 2
53 #define MATRIX_SMALL_DIMENSION_CHECK MATRIX_SMALL_DIMENSION_CHECK_NO_CHECK
54 
55 // LifeV namespace.
56 namespace LifeV
57 {
58 //! class MtrixSmall This class implements a simple matrix
59 
60 /*!
61  @author Ivan Kuraj <ivan.kuraj@epfl.ch>
62 
63  This class implements a simple matrix.
64  <br>
65  It allows all kind of geometric operations on the node,
66  such as summation, multiplication by scalar, scalar product,
67  cross product, etc.
68  The implementation is oriented to best perform with small (less than 30) n
69 
70 */
71 
72 template <UInt Dim1, UInt Dim2>
73 class MatrixSmall
74 {
75 
76 private:
77  typedef Real& (MatrixSmall::*DereferenceMethod) ( UInt const& i );
78  typedef const Real& (MatrixSmall::*ConstDereferenceMethod) ( UInt const& i ) const;
79 
81  typedef Real const* OpIndexReturnConstType;
82 
83  void copyFrom ( MatrixSmall<Dim1, Dim2> const& matrix )
84  {
85  for ( UInt i = 0; i < Dim1; i++ )
86  for ( UInt j = 0; j < Dim2; j++ )
87  {
88  M_coords[i][j] = matrix.M_coords[i][j];
89  }
90  //reinterpret_cast<Real*>(M_coords)[ i ] = reinterpret_cast<const Real*>(matrix.M_coords)[ i ];
91  }
92 
93  bool realEquality (const Real& r1, const Real& r2) const
94  {
95  // TODO change if it is not appropriate
96  //return (fabs(r1 - r2) <= numeric_limits<double>::epsilon());
97  //return (r1==r2);
98  return (fabs (r1 - r2) <= 0.1);
99  }
100 
101 public:
102 
103  //! @name Constructors and destructors
104  //@{
105 
106  //! Empty constructor (all components are set to zero)
108  {
109  for ( UInt i = 0; i < Dim1 * Dim2; i++ )
110  {
111  reinterpret_cast<Real*> (M_coords) [ i ] = 0.;
112  }
113  }
114 
115  //! Copy constructor
116  MatrixSmall ( MatrixSmall<Dim1, Dim2> const& matrix )
117  {
118  copyFrom (matrix);
119  }
120 
121  //! Import from a vector
122  MatrixSmall (const std::vector< std::vector<Real> >& matrix)
123  {
124  // check if dimensions are correct
125  bool isDim2Appropriate = true;
126  for (unsigned i = 0; i < matrix.size(); i++)
127  if (matrix[i].size() != Dim2)
128  {
129  isDim2Appropriate = false;
130  break;
131  }
132  ASSERT ( matrix.size() == Dim1 && isDim2Appropriate,
133  " Non matching dimension for the construction of a fixed size matrix via vector ");
134 
135  for (unsigned int i = 0; i < Dim1; ++i)
136  {
137  for (unsigned int j = 0; j < Dim2; ++j)
138  {
139  M_coords[i][j] = matrix[i][j];
140  }
141  }
142  }
143 
144  //@}
145 
146  //! @name Overloaded operators
147  //@{
148 
149  //! Operator ==
150  bool operator== ( MatrixSmall<Dim1, Dim2> const& matrix ) const
151  {
152  for ( UInt i = 0; i < Dim1; i++ )
153  for ( UInt j = 0; j < Dim2; j++ )
154  if (!realEquality (M_coords[i][j], matrix.M_coords[i][j]) )
155  {
156  return false;
157  }
158  return true;
159  }
160 
161  //! Operator !=
162  bool operator!= ( MatrixSmall<Dim1, Dim2> const& matrix ) const
163  {
164  return ! (*this == matrix);
165  }
166 
167  //! Assignment operator
168  MatrixSmall<Dim1, Dim2>& operator= ( MatrixSmall<Dim1, Dim2> const& matrix )
169  {
170  // avoid this check for fastest common case
171  //if (this != &matrix)
172  copyFrom (matrix);
173  return (*this);
174  }
175 
176  //! Operator +=
177  MatrixSmall<Dim1, Dim2>& operator+= ( MatrixSmall<Dim1, Dim2> const& matrix )
178  {
179  for ( UInt i = 0; i < Dim1; i++ )
180  for ( UInt j = 0; j < Dim2; j++ )
181  {
182  M_coords[ i ][ j ] += matrix.M_coords[ i ][ j ];
183  }
184  return (*this);
185  }
186 
187  //! Operator +
188  MatrixSmall<Dim1, Dim2> operator+ ( MatrixSmall<Dim1, Dim2> const& matrix ) const
189  {
190  MatrixSmall<Dim1, Dim2> tmp ( *this );
191  return (tmp += matrix);
192  }
193 
194  //! Operator -=
195  MatrixSmall<Dim1, Dim2>& operator-= ( MatrixSmall<Dim1, Dim2> const& matrix )
196  {
197  for ( UInt i = 0; i < Dim1; i++ )
198  for ( UInt j = 0; j < Dim2; j++ )
199  {
200  M_coords[ i ][ j ] -= matrix.M_coords[ i ][ j ];
201  }
202  return (*this);
203  }
204 
205  //! Operator -
206  MatrixSmall<Dim1, Dim2> operator- ( MatrixSmall<Dim1, Dim2> const& matrix ) const
207  {
208  MatrixSmall<Dim1, Dim2> tmp ( *this );
209  return (tmp -= matrix);
210  }
211 
212  //! Operator *= (multiplication by scalar)
213  MatrixSmall<Dim1, Dim2>& operator*= ( Real const& factor )
214  {
215  for ( UInt i = 0; i < Dim1; i++ )
216  for ( UInt j = 0; j < Dim2; j++ )
217  {
218  M_coords[ i ][ j ] *= factor;
219  }
220  return (*this);
221  }
222 
223  //! Operator /= (division by scalar)
224  MatrixSmall<Dim1, Dim2>& operator/= ( Real const& factor )
225  {
226  ASSERT ( factor != 0. , "Division by zero!" );
227  *this *= 1. / factor;
228  return (*this);
229  }
230 
231  //! Operator / (division by scalar)
232  MatrixSmall<Dim1, Dim2> operator/ ( Real const& factor ) const
233  {
234  MatrixSmall<Dim1, Dim2> tmp ( *this );
235  return (tmp /= factor);
236  }
237 
238  //! Operator * (division by scalar)
239  MatrixSmall<Dim1, Dim2> operator* ( Real const& factor ) const
240  {
241  MatrixSmall<Dim1, Dim2> tmp ( *this );
242  return (tmp *= factor);
243  }
244 
245  //! Operator * (multiplication by a vector)
246  VectorSmall<Dim1> operator* ( VectorSmall<Dim2> const& vector ) const
247  {
248  VectorSmall<Dim1> resultVector;
249  for ( UInt i = 0; i < Dim1; i++ )
250  {
251  resultVector[i] = 0;
252  for ( UInt j = 0; j < Dim2; j++ )
253  {
254  resultVector[i] += vector[j] * (*this) [i][j];
255  }
256  }
257  return (resultVector);
258  }
259 
260  //! Operator * between two squared matrices (multiplication by a matrix)
261  MatrixSmall<Dim1, Dim2> operator* ( MatrixSmall<Dim2, Dim1> const& matrix ) const
262  {
263  MatrixSmall<Dim1, Dim1> resultMatrix;
264  for ( UInt i = 0; i < Dim1; i++ )
265  {
266  for ( UInt j = 0; j < Dim1; j++ )
267  {
268  resultMatrix[i][j] = 0;
269  for ( UInt k = 0; k < Dim2; k++ )
270  {
271  resultMatrix[i][j] += M_coords[i][k] * matrix.M_coords[k][j];
272  }
273  }
274  }
275  return (resultMatrix);
276  }
277 
278 
279  //! Operator []
280  //const OpIndexReturnType operator[] ( UInt const & i ) const
281  OpIndexReturnConstType const operator[] ( UInt const& i ) const
282  {
283  ASSERT ( i < Dim1, "trying to access an index that exceeds the first dimension of the matrix" );
284  return (M_coords [ i ]);
285  }
286 
287  //! Operator []
289  {
290  ASSERT ( i < Dim1, "trying to access an index that exceeds the first dimension of the matrix" );
291  return (M_coords [ i ]);
292  }
293 
294  //! Operator ()
295  Real const& operator() ( UInt const& i, UInt const& j ) const
296  {
297  ASSERT ( i < Dim1 && j < Dim2, "trying to access an index that exceeds the first dimension of the matrix" );
298  return (M_coords[i][j]);
299  }
300 
301  //! Operator ()
302  Real& operator() ( UInt const& i, UInt const& j )
303  {
304  return (const_cast<Real&> (const_cast<const MatrixSmall<Dim1, Dim2>&> (*this) (i, j) ) );
305  }
306 
307  //@}
308 
309  //! @name Geometric Methods
310  //@{
311 
312  //! Scalar product
313  /*!
314  @param matrix second operand
315  @return scalar product value
316  */
317  Real dot ( MatrixSmall<Dim1, Dim2> const& matrix ) const
318  {
319  Real scalarProduct = 0.;
320  for ( UInt i = 0; i < Dim1; i++ )
321  for ( UInt j = 0; j < Dim2; j++ )
322  {
323  scalarProduct += M_coords[ i ][ j ] * matrix.M_coords[ i ][ j ];
324  }
325  return scalarProduct;
326  }
327 
328 
329  //! Element-wise multiplication between matrices
330  /*!
331  @param matrix second operand
332  @return resultant matrix
333  */
334  MatrixSmall<Dim1, Dim2> emult ( MatrixSmall<Dim1, Dim2> const& matrix ) const
335  {
336  MatrixSmall<Dim1, Dim2> resultantMatrix ;
337  for ( UInt i = 0; i < Dim1; i++ )
338  for ( UInt j = 0; j < Dim2; j++ )
339  {
340  resultantMatrix.M_coords[ i ][ j ] = M_coords[ i ][ j ] * matrix.M_coords[ i ][ j ];
341  }
342  return resultantMatrix;
343  }
344 
345  //! Element-wise multiplication between a matrix and a vector
346  /*!
347  Line[i] of the matrix is multipled by the scalar vector[i]
348  @param vector
349  @return resultant matrix
350  */
351  MatrixSmall<Dim1, Dim2> emult ( VectorSmall<Dim1> const& vector ) const
352  {
353  MatrixSmall<Dim1, Dim2> resultantMatrix ;
354  for ( UInt i = 0; i < Dim1; i++ )
355  for ( UInt j = 0; j < Dim2; j++ )
356  {
357  resultantMatrix.M_coords[ i ][ j ] = M_coords[ i ][ j ] * vector[ i ];
358  }
359  return resultantMatrix;
360  }
361 
362 
363  //! Extraction of a row
364  /*!
365  @param index of the row to be extracted
366  @return extracted row
367  */
368  VectorSmall<Dim2> extractRow ( UInt const& i ) const
369  {
370  VectorSmall<Dim2> row;
371  for ( UInt j = 0; j < Dim2; j++ )
372  {
373  row[j] = M_coords[i][j];
374  }
375  return ( row );
376  }
377 
378  //! Extraction of a column
379  /*!
380  @param index of the column to be extracted
381  @return extracted column
382  */
383  VectorSmall<Dim1> extractColumn ( UInt const& j ) const
384  {
385  VectorSmall<Dim1> column;
386  for ( UInt i = 0; i < Dim1; i++ )
387  {
388  column[i] = M_coords[i][j];
389  }
390  return ( column );
391  }
392 
393  //! Extraction of a component
394  /*!
395  @param index of the component to be extracted
396  @return extracted component
397  */
398  Real extract ( UInt const& i, UInt const& j ) const
399  {
400  return ( M_coords[i][j] );
401  }
402 
403  //! Transpose of a matrix
404  /*!
405  @return transposed matrix
406  */
407  MatrixSmall<Dim2, Dim1> transpose () const
408  {
409  MatrixSmall<Dim2, Dim1> resultantMatrix ;
410  for (UInt j = 0; j < Dim2; ++j)
411  for (UInt i = 0; i < Dim1; ++i)
412  {
413  resultantMatrix.M_coords[ j ][ i ] = M_coords[ i ][ j ];
414  }
415 
416  return (resultantMatrix);
417  }
418 
419  //! Determinant of a matrix
420  //! In this class the determinant is computed explicitly
421  //! for matrices of dimensions 1 2 3
422  /*!
423  @return determinant of the matrix
424  */
426  {
427  ASSERT ( Dim2 == Dim1, "The determinat is defined only for squared matrices!");
428 
429  Real det (0);
430 
431  switch ( Dim1 )
432  {
433  case 1:
434  det = M_coords[ 0 ][ 0 ];
435  break;
436  case 2:
437  det = M_coords[ 0 ][ 0 ] * M_coords[ 1 ][ 1 ] - M_coords[ 0 ][ 1 ] * M_coords[ 1 ][ 0 ];
438  break;
439  case 3:
440  det = M_coords[ 0 ][ 0 ] * ( M_coords[ 1 ][ 1 ] * M_coords[ 2 ][ 2 ] - M_coords[ 1 ][ 2 ] * M_coords[ 2 ][ 1 ] )
441  - M_coords[ 0 ][ 1 ] * ( M_coords[ 1 ][ 0 ] * M_coords[ 2 ][ 2 ] - M_coords[ 1 ][ 2 ] * M_coords[ 2 ][ 0 ] )
442  + M_coords[ 0 ][ 2 ] * ( M_coords[ 1 ][ 0 ] * M_coords[ 2 ][ 1 ] - M_coords[ 1 ][ 1 ] * M_coords[ 2 ][ 0 ] );
443 
444  break;
445  default:
446  ERROR_MSG ("The determinat for matrices is implemented for Dim1 = Dim2 < 3!");
447  break;
448  }
449 
450  return det;
451  }
452 
453  //! Cofactor of a matrix
454  //! In this class the cofactor is computed explicitly
455  //! for matrices of dimensions 1 2 3
456  /*!
457  @return determinant of the matrix
458  */
459  MatrixSmall<Dim1, Dim2> cofactor() const
460  {
461  ASSERT ( Dim2 == Dim1, "The cofactor is defined only for squared matrices!");
462 
463  //Create the matrix to store the cofactor
464  //In this case it is a copy of the current matrix
465  MatrixSmall<Dim1, Dim2> cofactor (*this);
466 
467  switch ( Dim1 )
468  {
469  case 1:
470  cofactor[ 0][0 ] = 1.0;
471  break;
472  case 2:
473  cofactor[0][0] = M_coords[1][1];
474  cofactor[0][1] = - M_coords[0][1];
475  cofactor[1][0] = - M_coords[1][0];
476  cofactor[1][1] = M_coords[0][0];
477  break;
478  case 3:
479  cofactor[ 0][0 ] = M_coords[1][1] * M_coords[2][2] - M_coords[1][2] * M_coords[2][1];
480  cofactor[ 0][1 ] = - (M_coords[1][0] * M_coords[2][2] - M_coords[1][2] * M_coords[2][0]);
481  cofactor[ 0][2 ] = M_coords[1][0] * M_coords[2][1] - M_coords[1][1] * M_coords[2][0];
482  cofactor[ 1][0 ] = - (M_coords[0][1] * M_coords[2][2] - M_coords[0][2] * M_coords[2][1]);
483  cofactor[ 1][1 ] = M_coords[0][0] * M_coords[2][2] - M_coords[0][2] * M_coords[2][0];
484  cofactor[ 1][2 ] = - (M_coords[0][0] * M_coords[2][1] - M_coords[2][0] * M_coords[0][1]);
485  cofactor[ 2][0 ] = M_coords[0][1] * M_coords[1][2] - M_coords[0][2] * M_coords[1][1];
486  cofactor[ 2][1 ] = - (M_coords[0][0] * M_coords[1][2] - M_coords[0][2] * M_coords[1][0]);
487  cofactor[ 2][2 ] = M_coords[0][0] * M_coords[1][1] - M_coords[1][0] * M_coords[0][1];
488  break;
489  default:
490  ERROR_MSG ("The cofactor for matrices is implemented for Dim1 = Dim2 < 3!");
491  break;
492  }
493 
494  return cofactor;
495  }
496 
497  //! Plot the Matrix
498  /*!
499  @return void
500  */
501  void showMe() const
502  {
503  for ( Int i = 0; i < Dim1; i++ )
504  {
505  for ( Int j = 0; j < Dim2; j++ )
506  {
507  std::cout << "M_coords[ " << i << " ][ " << j << " ]= " << M_coords[i][j] << std::endl;
508  }
509  }
510  }
511 
512 
513  //! This method
514  //! In this method, which is based on cofactor and determinant,
515  //! given a matrix, its inverse transposed is computed explicitly
516  //! for matrices of dimensions 1 2 3
517  //! This method is mainly used for structural problems.
518  /*!
519  @return determinant of the matrix
520  */
521  MatrixSmall<Dim1, Dim2> minusTransposed() const
522  {
523  ASSERT ( Dim2 == Dim1, "This method is based on the cofactor and determinant methods which are defined only for squared matrices!");
524 
525  //Create the matrix to store the cofactor
526  //In this case it is a copy of the current matrix
527  MatrixSmall<Dim1, Dim2> minusT (*this);
528 
529  Real det (0);
530 
531  minusT = this->cofactor();
532  det = this->determinant();
533 
534  minusT *= 1.0 / det;
535 
536  return minusT;
537  }
538 
539 
540  //! This method
541  //! In this method, which is based on cofactor and determinant,
542  //! given a matrix, its inverse is computed explicitly
543  //! for matrices of dimensions 1 2 3
544  //! This method is mainly used for structural problems.
545  /*!
546  @return a small matrix containing the inverse
547  */
548  MatrixSmall<Dim1, Dim2> inverse() const
549  {
550  ASSERT ( Dim2 == Dim1, "This method is based on the cofactor and determinant methods which are defined only for squared matrices!");
551 
552  //Create the matrix to store the cofactor
553  //In this case it is a copy of the current matrix
554  MatrixSmall<Dim1, Dim2> minusT (*this);
555 
556  minusT = this->minusTransposed();
557 
558  return minusT.transpose( );
559  }
560 
561 
562  Real trace() const
563  {
564  ASSERT ( Dim2 == Dim1, "The trace is defined only for squared matrices!");
565 
566  Real trace (0);
567 
568  for ( UInt i (0); i < Dim1; i++ )
569  {
570  trace += M_coords[ i ][ i ];
571  }
572 
573  return trace;
574  }
575 
576  //! Norm value
577  /*!
578  @return norm value
579  */
580  Real norm () const
581  {
582  return std::sqrt ( this->dot ( *this ) );
583  }
584 
585  //! Normalize matrix
586  void normalize ()
587  {
588  *this /= norm ();
589  }
590 
591  //! Create the versor associated to this MatrixSmall
592  /*!
593  @return the versor associated to this MatrixSmall
594  */
595  MatrixSmall<Dim1, Dim2> normalized ()
596  {
597  return ( ( *this ) / norm () );
598  }
599 
600  //@}
601 
602  //! @name Tools
603  //@{
604 
605  //! function to get the size of the MatrixSmall ( for compatibility with Eigen)
606  /*!
607  @return the fixed size of the MatrixSmall
608  */
609  // we avoid the size method for matrix
610  // static UInt size() { return Dim1 * Dim2;}
611 
612  //@}
613 
614  //! @name Output stream operator overload
615  //@{
616  friend std::ostream& operator<< ( std::ostream& out, MatrixSmall<Dim1, Dim2> const& matrix )
617  {
618  out << "(" << std::endl ;
619  for ( UInt i = 0; i < Dim1; i++ )
620  {
621  for ( UInt j = 0; j < Dim2; j++ )
622  {
623  out << matrix.M_coords[i][j] << " ";
624  }
625  out << std::endl;
626  }
627  out << ")";
628  return (out);
629  }
630  //@}
631 
632  //! @name Conversion free-functions
633  //@{
634 
635  //! Conversion of an array (std::vector, KN, etc. if applicable) to a MatrixSmall
636  /*!
637  @param coords matrix of point coordinates with operator[][] available
638  @return the matrixSmall that corresponds to the input
639  */
640  template <typename Matrix>
641  friend inline MatrixSmall<Dim1, Dim2> castToMatrixSmall ( Matrix const& coords )
642  {
643  MatrixSmall<Dim1, Dim2> tmp;
644  for ( UInt i = 0; i < Dim1; i++ )
645  for ( UInt j = 0; j < Dim2; j++ )
646  {
647  tmp.M_coords[ i ][ j ] = coords[ i ][ j ];
648  }
649  return (tmp);
650  }
651  //@}
652  //
653 private:
654 
655  //! @name Data
656  //@{
657 
658  //! Data storage
659  Real M_coords[ Dim1 ] [ Dim2 ];
660 
661  //@}
662 };
663 
664 //! @name External overloaded operators
665 //@{
666 
667 //! Operator * (multiplication by scalar on the left)
668 template <UInt Dim1, UInt Dim2>
669 inline MatrixSmall<Dim1, Dim2> operator* ( Real const& factor, MatrixSmall<Dim1, Dim2> const& matrix )
670 {
671  MatrixSmall<Dim1, Dim2> tmp ( matrix );
672  return (tmp *= factor);
673 }
674 
675 //! Operator * (multiplication by vector on the left)
676 template <UInt Dim1, UInt Dim2>
677 inline VectorSmall<Dim1> operator* ( VectorSmall<Dim2> const& vector, MatrixSmall<Dim1, Dim2> const& matrix )
678 {
679  return (matrix * vector);
680 }
681 
682 
683 
684 //@}
685 
686 } // namespace LifeV
687 
688 
689 #endif //_MATRIXSMALL_H_
690 
691 // -*- mode: c++ -*-
MatrixSmall< Dim1, Dim2 > & operator+=(MatrixSmall< Dim1, Dim2 > const &matrix)
Operator +=.
void showMe() const
Plot the Matrix.
MatrixSmall< Dim1, Dim2 > operator*(Real const &factor, MatrixSmall< Dim1, Dim2 > const &matrix)
Operator * (multiplication by scalar on the left)
MatrixSmall< Dim1, Dim2 > & operator/=(Real const &factor)
Operator /= (division by scalar)
void normalize()
Normalize matrix.
VectorSmall< Dim1 > operator*(VectorSmall< Dim2 > const &vector) const
Operator * (multiplication by a vector)
MatrixSmall< Dim1, Dim2 > operator-(MatrixSmall< Dim1, Dim2 > const &matrix) const
Operator -.
MatrixSmall< Dim1, Dim2 > operator/(Real const &factor) const
Operator / (division by scalar)
MatrixSmall(MatrixSmall< Dim1, Dim2 > const &matrix)
Copy constructor.
friend MatrixSmall< Dim1, Dim2 > castToMatrixSmall(Matrix const &coords)
Conversion of an array (std::vector, KN, etc. if applicable) to a MatrixSmall.
MatrixSmall< Dim1, Dim2 > emult(MatrixSmall< Dim1, Dim2 > const &matrix) const
Element-wise multiplication between matrices.
OpIndexReturnType operator[](UInt const &i)
Operator [].
Real & operator()(UInt const &i, UInt const &j)
Operator ()
Real dot(MatrixSmall< Dim1, Dim2 > const &matrix) const
Scalar product.
int32_type Int
Generic integer data.
Definition: LifeV.hpp:188
VectorSmall< Dim1 > operator*(VectorSmall< Dim2 > const &vector, MatrixSmall< Dim1, Dim2 > const &matrix)
Operator * (multiplication by vector on the left)
MatrixSmall< Dim1, Dim2 > & operator-=(MatrixSmall< Dim1, Dim2 > const &matrix)
Operator -=.
MatrixSmall< Dim1, Dim2 > operator*(MatrixSmall< Dim2, Dim1 > const &matrix) const
Operator * between two squared matrices (multiplication by a matrix)
void updateInverseJacobian(const UInt &iQuadPt)
#define MATRIX_SMALL_DIMENSION_CHECK_NO_CHECK
Definition: MatrixSmall.hpp:50
Real extract(UInt const &i, UInt const &j) const
Extraction of a component.
MatrixSmall< Dim1, Dim2 > operator+(MatrixSmall< Dim1, Dim2 > const &matrix) const
Operator +.
Real determinant() const
Determinant of a matrix In this class the determinant is computed explicitly for matrices of dimensio...
OpIndexReturnConstType const operator[](UInt const &i) const
Operator [].
Real const * OpIndexReturnConstType
Definition: MatrixSmall.hpp:81
#define ERROR_MSG(A)
Definition: LifeAssert.hpp:69
#define ASSERT(X, A)
Definition: LifeAssert.hpp:90
MatrixSmall< Dim1, Dim2 > inverse() const
This method In this method, which is based on cofactor and determinant, given a matrix, its inverse is computed explicitly for matrices of dimensions 1 2 3 This method is mainly used for structural problems.
bool realEquality(const Real &r1, const Real &r2) const
Definition: MatrixSmall.hpp:93
MatrixSmall< Dim1, Dim2 > cofactor() const
Cofactor of a matrix In this class the cofactor is computed explicitly for matrices of dimensions 1 2...
MatrixSmall< Dim1, Dim2 > & operator*=(Real const &factor)
Operator *= (multiplication by scalar)
MatrixSmall< Dim1, Dim2 > operator*(Real const &factor) const
Operator * (division by scalar)
Real trace() const
void copyFrom(MatrixSmall< Dim1, Dim2 > const &matrix)
Definition: MatrixSmall.hpp:83
double Real
Generic real data.
Definition: LifeV.hpp:175
VectorSmall< Dim1 > extractColumn(UInt const &j) const
Extraction of a column.
MatrixSmall< Dim1, Dim2 > & operator=(MatrixSmall< Dim1, Dim2 > const &matrix)
Assignment operator.
MatrixSmall< Dim2, Dim1 > transpose() const
Transpose of a matrix.
MatrixSmall< Dim1, Dim2 > emult(VectorSmall< Dim1 > const &vector) const
Element-wise multiplication between a matrix and a vector.
bool operator==(MatrixSmall< Dim1, Dim2 > const &matrix) const
Operator ==.
MatrixSmall< Dim1, Dim2 > minusTransposed() const
This method In this method, which is based on cofactor and determinant, given a matrix, its inverse transposed is computed explicitly for matrices of dimensions 1 2 3 This method is mainly used for structural problems.
MatrixSmall()
Empty constructor (all components are set to zero)
bool operator!=(MatrixSmall< Dim1, Dim2 > const &matrix) const
Operator !=.
MatrixSmall< Dim1, Dim2 > normalized()
Create the versor associated to this MatrixSmall.
Real norm() const
Norm value.
Real const & operator()(UInt const &i, UInt const &j) const
Operator ()
MatrixSmall(const std::vector< std::vector< Real > > &matrix)
Import from a vector.
VectorSmall< Dim2 > extractRow(UInt const &i) const
Extraction of a row.
Real M_coords[Dim1][Dim2]
Data storage.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191