Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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  LIB_UTILITIES_EXPORT unsigned int GetRows() const;
70 
71  LIB_UTILITIES_EXPORT unsigned int GetTransposedRows(char transpose) const ;
72 
73  LIB_UTILITIES_EXPORT unsigned int GetColumns() const;
74 
75  LIB_UTILITIES_EXPORT unsigned int GetTransposedColumns(char transpose) const ;
76 
77  LIB_UTILITIES_EXPORT const unsigned int* GetSize() const;
78 
80 
82 
83  LIB_UTILITIES_EXPORT static unsigned int CalculateIndex(MatrixStorage type,
84  unsigned int row, unsigned int col,
85  unsigned int numRows, unsigned int numColumns, const char transpose = 'N',
86  unsigned int numSubDiags = 0, unsigned int numSuperDiags = 0) ;
87 
88  LIB_UTILITIES_EXPORT static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows,
89  unsigned int columns, unsigned int subDiags = 0, unsigned int superDiags = 0);
90 
91  protected:
92 
93  // All constructors are private to enforce the abstract nature of ConstMatrix without
94  // resorting to pure virtual functions.
95  LIB_UTILITIES_EXPORT ConstMatrix(unsigned int rows, unsigned int columns);
96 
98 
100 
101  /// \brief Resets the rows and columns in the array.
102  /// This method does not update the data storage to match the new row and column counts.
103  LIB_UTILITIES_EXPORT void Resize(unsigned int rows, unsigned int columns);
104 
105  LIB_UTILITIES_EXPORT void SetTransposeFlag(char newValue);
107 
108  private:
109 
110  virtual typename boost::call_traits<DataType>::value_type v_GetValue(unsigned int row, unsigned int column) const = 0;
111  virtual unsigned int v_GetStorageSize() const = 0;
112  virtual MatrixStorage v_GetStorageType() const = 0;
113  LIB_UTILITIES_EXPORT virtual void v_Transpose();
114  LIB_UTILITIES_EXPORT virtual char v_GetTransposeFlag() const;
115  unsigned int m_size[2];
117  };
118 
119  template<typename DataType>
120  class Matrix : public ConstMatrix<DataType>
121  {
122  public:
123  LIB_UTILITIES_EXPORT virtual ~Matrix();
124 
125  LIB_UTILITIES_EXPORT void SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d);
126 
127  protected:
128  // All constructors are private to enforce the abstract nature of ConstMatrix without
129  // resorting to pure virtual functions.
130  LIB_UTILITIES_EXPORT Matrix(unsigned int rows, unsigned int columns);
131 
133 
135 
137 
138  private:
139  LIB_UTILITIES_EXPORT virtual void v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d) = 0;
140  };
141 
142 
143 }
144 
145 #endif //NEKTAR_LIB_UTILITIES_LINEAR_ALGEBRA_MATRIX_BASE_HPP