Nektar++
MatrixBase.hpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: MatrixBase.hpp
4 //
5 // For more information, please see: http://www.nektar.info
6 //
7 // The MIT License
8 //
9 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
10 // Department of Aeronautics, Imperial College London (UK), and Scientific
11 // Computing and Imaging Institute, University of Utah (USA).
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining a
14 // copy of this software and associated documentation files (the "Software"),
15 // to deal in the Software without restriction, including without limitation
16 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 // and/or sell copies of the Software, and to permit persons to whom the
18 // Software is furnished to do so, subject to the following conditions:
19 //
20 // The above copyright notice and this permission notice shall be included
21 // in all copies or substantial portions of the Software.
22 //
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
26 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
29 // DEALINGS IN THE SOFTWARE.
30 //
31 // Description: Interface classes for matrices
32 //
33 ///////////////////////////////////////////////////////////////////////////////
34 
35 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP
36 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP
37 
39 
44 
46 
47 #ifdef max
48 #undef max
49 #endif
50 
51 namespace Nektar
52 {
53  template<typename DataType>
55  {
56  public:
58 
59  public:
60  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::value_type operator()(unsigned int row, unsigned int column) const;
61 
62  LIB_UTILITIES_EXPORT unsigned int GetStorageSize() const;
63 
65  {
66  return m_storageType;
67  }
68 
70  {
71  return m_storageType;
72  }
73 
74  LIB_UTILITIES_EXPORT unsigned int GetRows() const;
75 
76  LIB_UTILITIES_EXPORT unsigned int GetTransposedRows(char transpose) const ;
77 
78  LIB_UTILITIES_EXPORT unsigned int GetColumns() const;
79 
80  LIB_UTILITIES_EXPORT unsigned int GetTransposedColumns(char transpose) const ;
81 
82  LIB_UTILITIES_EXPORT const unsigned int* GetSize() const;
83 
85 
87 
88  LIB_UTILITIES_EXPORT static unsigned int CalculateIndex(MatrixStorage type,
89  unsigned int row, unsigned int col,
90  unsigned int numRows, unsigned int numColumns, const char transpose = 'N',
91  unsigned int numSubDiags = 0, unsigned int numSuperDiags = 0) ;
92 
93  LIB_UTILITIES_EXPORT static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows,
94  unsigned int columns, unsigned int subDiags = 0, unsigned int superDiags = 0);
95 
96  protected:
97 
98  // All constructors are private to enforce the abstract nature of ConstMatrix without
99  // resorting to pure virtual functions.
100  LIB_UTILITIES_EXPORT ConstMatrix(unsigned int rows, unsigned int columns,
101  MatrixStorage policy = eFULL);
102 
104 
106 
107  /// \brief Resets the rows and columns in the array.
108  /// This method does not update the data storage to match the new row and column counts.
109  LIB_UTILITIES_EXPORT void Resize(unsigned int rows, unsigned int columns);
110 
111  LIB_UTILITIES_EXPORT void SetTransposeFlag(char newValue);
113  {
114  return m_transpose;
115  }
116 
117  private:
118 
119  virtual typename boost::call_traits<DataType>::value_type v_GetValue(unsigned int row, unsigned int column) const = 0;
120  virtual unsigned int v_GetStorageSize() const = 0;
121  LIB_UTILITIES_EXPORT virtual void v_Transpose();
122  LIB_UTILITIES_EXPORT virtual char v_GetTransposeFlag() const;
123  unsigned int m_size[2];
126  };
127 
128  template<typename DataType>
129  class Matrix : public ConstMatrix<DataType>
130  {
131  public:
132  LIB_UTILITIES_EXPORT virtual ~Matrix();
133 
134  LIB_UTILITIES_EXPORT void SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d);
135 
136  protected:
137  // All constructors are private to enforce the abstract nature of ConstMatrix without
138  // resorting to pure virtual functions.
139  LIB_UTILITIES_EXPORT Matrix(unsigned int rows, unsigned int columns,
140  MatrixStorage policy = eFULL);
141 
143 
145 
147 
148  private:
149  LIB_UTILITIES_EXPORT virtual void v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d) = 0;
150  };
151 
152 
153 }
154 
155 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP
virtual boost::call_traits< DataType >::value_type v_GetValue(unsigned int row, unsigned int column) const =0
void Resize(unsigned int rows, unsigned int columns)
Resets the rows and columns in the array. This method does not update the data storage to match the n...
Definition: MatrixBase.cpp:257
MatrixStorage GetStorageType() const
Definition: MatrixBase.hpp:69
static unsigned int CalculateIndex(MatrixStorage type, unsigned int row, unsigned int col, unsigned int numRows, unsigned int numColumns, const char transpose='N', unsigned int numSubDiags=0, unsigned int numSuperDiags=0)
Definition: MatrixBase.cpp:119
unsigned int m_size[2]
Definition: MatrixBase.hpp:123
unsigned int GetTransposedRows(char transpose) const
Definition: MatrixBase.cpp:64
virtual unsigned int v_GetStorageSize() const =0
char GetTransposeFlag() const
Definition: MatrixBase.cpp:113
unsigned int GetStorageSize() const
Definition: MatrixBase.cpp:52
virtual void v_Transpose()
Definition: MatrixBase.cpp:270
char GetRawTransposeFlag() const
Definition: MatrixBase.hpp:112
MatrixStorage GetType() const
Definition: MatrixBase.hpp:64
MatrixStorage m_storageType
Definition: MatrixBase.hpp:125
unsigned int GetColumns() const
Definition: MatrixBase.cpp:77
unsigned int GetTransposedColumns(char transpose) const
Definition: MatrixBase.cpp:83
ConstMatrix(unsigned int rows, unsigned int columns, MatrixStorage policy=eFULL)
Definition: MatrixBase.cpp:225
virtual ~ConstMatrix()
Definition: MatrixBase.cpp:37
#define LIB_UTILITIES_EXPORT
void SetTransposeFlag(char newValue)
Definition: MatrixBase.cpp:264
virtual char v_GetTransposeFlag() const
Definition: MatrixBase.cpp:273
unsigned int GetRows() const
Definition: MatrixBase.cpp:58
ConstMatrix< DataType > & operator=(const ConstMatrix< DataType > &rhs)
Definition: MatrixBase.cpp:246
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
Definition: MatrixBase.cpp:175
boost::call_traits< DataType >::value_type operator()(unsigned int row, unsigned int column) const
Definition: MatrixBase.cpp:40
const unsigned int * GetSize() const
Definition: MatrixBase.cpp:96
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs