Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // License for the specific language governing rights and limitations under
14 // Permission is hereby granted, free of charge, to any person obtaining a
15 // copy of this software and associated documentation files (the "Software"),
16 // to deal in the Software without restriction, including without limitation
17 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
18 // and/or sell copies of the Software, and to permit persons to whom the
19 // Software is furnished to do so, subject to the following conditions:
20 //
21 // The above copyright notice and this permission notice shall be included
22 // in all copies or substantial portions of the Software.
23 //
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
27 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 // DEALINGS IN THE SOFTWARE.
31 //
32 // Description: Interface classes for matrices
33 //
34 ///////////////////////////////////////////////////////////////////////////////
35 
36 #ifndef NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP
37 #define NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP
38 
40 
45 
47 
48 #include <boost/lexical_cast.hpp>
49 
50 #ifdef max
51 #undef max
52 #endif
53 
54 namespace Nektar
55 {
56  template<typename DataType>
58  {
59  public:
61 
62  public:
63  LIB_UTILITIES_EXPORT typename boost::call_traits<DataType>::value_type operator()(unsigned int row, unsigned int column) const;
64 
65  LIB_UTILITIES_EXPORT unsigned int GetStorageSize() const;
66 
68  {
69  return m_storageType;
70  }
71 
73  {
74  return m_storageType;
75  }
76 
77  LIB_UTILITIES_EXPORT unsigned int GetRows() const;
78 
79  LIB_UTILITIES_EXPORT unsigned int GetTransposedRows(char transpose) const ;
80 
81  LIB_UTILITIES_EXPORT unsigned int GetColumns() const;
82 
83  LIB_UTILITIES_EXPORT unsigned int GetTransposedColumns(char transpose) const ;
84 
85  LIB_UTILITIES_EXPORT const unsigned int* GetSize() const;
86 
88 
90 
91  LIB_UTILITIES_EXPORT static unsigned int CalculateIndex(MatrixStorage type,
92  unsigned int row, unsigned int col,
93  unsigned int numRows, unsigned int numColumns, const char transpose = 'N',
94  unsigned int numSubDiags = 0, unsigned int numSuperDiags = 0) ;
95 
96  LIB_UTILITIES_EXPORT static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows,
97  unsigned int columns, unsigned int subDiags = 0, unsigned int superDiags = 0);
98 
99  protected:
100 
101  // All constructors are private to enforce the abstract nature of ConstMatrix without
102  // resorting to pure virtual functions.
103  LIB_UTILITIES_EXPORT ConstMatrix(unsigned int rows, unsigned int columns,
104  MatrixStorage policy = eFULL);
105 
107 
109 
110  /// \brief Resets the rows and columns in the array.
111  /// This method does not update the data storage to match the new row and column counts.
112  LIB_UTILITIES_EXPORT void Resize(unsigned int rows, unsigned int columns);
113 
114  LIB_UTILITIES_EXPORT void SetTransposeFlag(char newValue);
116  {
117  return m_transpose;
118  }
119 
120  private:
121 
122  virtual typename boost::call_traits<DataType>::value_type v_GetValue(unsigned int row, unsigned int column) const = 0;
123  virtual unsigned int v_GetStorageSize() const = 0;
124  LIB_UTILITIES_EXPORT virtual void v_Transpose();
125  LIB_UTILITIES_EXPORT virtual char v_GetTransposeFlag() const;
126  unsigned int m_size[2];
129  };
130 
131  template<typename DataType>
132  class Matrix : public ConstMatrix<DataType>
133  {
134  public:
135  LIB_UTILITIES_EXPORT virtual ~Matrix();
136 
137  LIB_UTILITIES_EXPORT void SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d);
138 
139  protected:
140  // All constructors are private to enforce the abstract nature of ConstMatrix without
141  // resorting to pure virtual functions.
142  LIB_UTILITIES_EXPORT Matrix(unsigned int rows, unsigned int columns,
143  MatrixStorage policy = eFULL);
144 
146 
148 
150 
151  private:
152  LIB_UTILITIES_EXPORT virtual void v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d) = 0;
153  };
154 
155 
156 }
157 
158 #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:258
unsigned int m_size[2]
Definition: MatrixBase.hpp:126
const unsigned int * GetSize() const
Definition: MatrixBase.cpp:97
Matrix(unsigned int rows, unsigned int columns, MatrixStorage policy=eFULL)
Definition: MatrixBase.cpp:293
virtual unsigned int v_GetStorageSize() const =0
char GetTransposeFlag() const
Definition: MatrixBase.cpp:114
virtual void v_Transpose()
Definition: MatrixBase.cpp:271
virtual void v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits< DataType >::const_reference d)=0
unsigned int GetColumns() const
Definition: MatrixBase.cpp:78
MatrixStorage m_storageType
Definition: MatrixBase.hpp:128
ConstMatrix(unsigned int rows, unsigned int columns, MatrixStorage policy=eFULL)
Definition: MatrixBase.cpp:226
unsigned int GetStorageSize() const
Definition: MatrixBase.cpp:53
virtual ~ConstMatrix()
Definition: MatrixBase.cpp:38
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
Definition: MatrixBase.cpp:306
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:120
#define LIB_UTILITIES_EXPORT
virtual char v_GetTransposeFlag() const
Definition: MatrixBase.cpp:274
MatrixStorage GetStorageType() const
Definition: MatrixBase.hpp:72
char GetRawTransposeFlag() const
Definition: MatrixBase.hpp:115
unsigned int GetTransposedColumns(char transpose) const
Definition: MatrixBase.cpp:84
void SetTransposeFlag(char newValue)
Definition: MatrixBase.cpp:265
unsigned int GetRows() const
Definition: MatrixBase.cpp:59
MatrixStorage GetType() const
Definition: MatrixBase.hpp:67
ConstMatrix< DataType > & operator=(const ConstMatrix< DataType > &rhs)
Definition: MatrixBase.cpp:247
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
Definition: MatrixBase.cpp:176
void SetValue(unsigned int row, unsigned int column, typename boost::call_traits< DataType >::const_reference d)
Definition: MatrixBase.cpp:281
boost::call_traits< DataType >::value_type operator()(unsigned int row, unsigned int column) const
Definition: MatrixBase.cpp:41
unsigned int GetTransposedRows(char transpose) const
Definition: MatrixBase.cpp:65
virtual ~Matrix()
Definition: MatrixBase.cpp:278