Nektar++
MatrixBase.cpp
Go to the documentation of this file.
1///////////////////////////////////////////////////////////////////////////////
2//
3// File: MatrixBase.cpp
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:
32//
33///////////////////////////////////////////////////////////////////////////////
34
36
37namespace Nektar
38{
39
40template <typename DataType> ConstMatrix<DataType>::~ConstMatrix()
41{
42}
43
44template <typename DataType>
45typename boost::call_traits<DataType>::value_type ConstMatrix<
46 DataType>::operator()(unsigned int row, unsigned int column) const
47{
48 ASSERTL2(row < GetRows(),
49 std::string("Row ") + std::to_string(row) +
50 std::string(" requested in a matrix with a maximum of ") +
51 std::to_string(GetRows()) + std::string(" rows"));
52 ASSERTL2(column < GetColumns(),
53 std::string("Column ") + std::to_string(column) +
54 std::string(" requested in a matrix with a maximum of ") +
55 std::to_string(GetColumns()) + std::string(" columns"));
56 return v_GetValue(row, column);
57}
58
59template <typename DataType>
61{
62 return v_GetStorageSize();
63}
64
65template <typename DataType> unsigned int ConstMatrix<DataType>::GetRows() const
66{
67 return GetTransposedRows(GetTransposeFlag());
68}
69
70template <typename DataType>
71unsigned int ConstMatrix<DataType>::GetTransposedRows(char transpose) const
72{
73 if (transpose == 'N')
74 {
75 return m_size[0];
76 }
77 else
78 {
79 return m_size[1];
80 }
81}
82
83template <typename DataType>
86 return GetTransposedColumns(GetTransposeFlag());
88
89template <typename DataType>
90unsigned int ConstMatrix<DataType>::GetTransposedColumns(char transpose) const
91{
92 if (transpose == 'N')
93 {
94 return m_size[1];
95 }
96 else
97 {
98 return m_size[0];
99 }
100}
101
102template <typename DataType>
103const unsigned int *ConstMatrix<DataType>::GetSize() const
104{
105 return m_size;
106}
108template <typename DataType> void ConstMatrix<DataType>::Transpose()
109{
110 if (m_transpose == 'N')
111 {
112 m_transpose = 'T';
114 else
116 m_transpose = 'N';
117 }
118 v_Transpose();
119}
120
121template <typename DataType>
123{
124 return v_GetTransposeFlag();
126
127template <typename DataType>
129 MatrixStorage type, unsigned int row, unsigned int col,
130 unsigned int numRows, unsigned int numColumns, const char transpose,
131 unsigned int numSubDiags, unsigned int numSuperDiags)
132{
133 if (transpose == 'T')
134 {
135 std::swap(row, col);
136 }
137 switch (type)
138 {
139 case eFULL:
140 return FullMatrixFuncs::CalculateIndex(numRows, numColumns, row,
141 col);
142 break;
143 case eDIAGONAL:
145 break;
148 break;
150 return LowerTriangularMatrixFuncs::CalculateIndex(numColumns, row,
151 col);
152 break;
153 case eSYMMETRIC:
156 break;
157 case eBANDED:
159 numRows, numColumns, row, col, numSubDiags, numSuperDiags);
160 break;
163 {
164 ASSERTL1(numSubDiags == numSuperDiags,
165 std::string("Number of sub- and superdiagonals should ") +
166 std::string("be equal for a symmetric banded matrix"));
168 numSuperDiags);
169 }
170 break;
172 NEKERROR(ErrorUtil::efatal, "Not yet implemented.");
173 break;
175 NEKERROR(ErrorUtil::efatal, "Not yet implemented.");
176 break;
177
178 default:
179 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
180 }
181
182 return std::numeric_limits<unsigned int>::max();
183}
184
185template <typename DataType>
187 MatrixStorage type, unsigned int rows, unsigned int columns,
188 unsigned int subDiags, unsigned int superDiags)
189{
190 switch (type)
191 {
192 case eFULL:
193 return FullMatrixFuncs::GetRequiredStorageSize(rows, columns);
194 break;
195 case eDIAGONAL:
197 break;
200 columns);
201 break;
204 columns);
205 break;
206 case eSYMMETRIC:
209 break;
210 case eBANDED:
212 rows, columns, subDiags, superDiags);
213 break;
216 {
217 ASSERTL1(subDiags == superDiags,
218 std::string("Number of sub- and superdiagonals should ") +
219 std::string("be equal for a symmetric banded matrix"));
221 rows, columns, superDiags);
222 }
223 break;
225 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
226 break;
228 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
229 break;
230
231 default:
232 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
233 }
234
235 return 0;
236}
237
238template <typename DataType>
239ConstMatrix<DataType>::ConstMatrix(unsigned int rows, unsigned int columns,
240 MatrixStorage policy)
241 : m_size(), m_transpose('N'), m_storageType(policy)
242{
243 m_size[0] = rows;
244 m_size[1] = columns;
245}
246
247template <typename DataType>
249 : m_size(), m_transpose(rhs.m_transpose), m_storageType(rhs.m_storageType)
250{
251 m_size[0] = rhs.m_size[0];
252 m_size[1] = rhs.m_size[1];
253}
254
255template <typename DataType>
257 const ConstMatrix<DataType> &rhs)
258{
259 m_size[0] = rhs.m_size[0];
260 m_size[1] = rhs.m_size[1];
261 m_transpose = rhs.m_transpose;
262 m_storageType = rhs.m_storageType;
263 return *this;
264}
265
266template <typename DataType>
267void ConstMatrix<DataType>::Resize(unsigned int rows, unsigned int columns)
268{
269 m_size[0] = rows;
270 m_size[1] = columns;
271}
272
273template <typename DataType>
275{
276 m_transpose = newValue;
277}
278
279template <typename DataType> void ConstMatrix<DataType>::v_Transpose()
280{
281}
282
283template <typename DataType>
285{
286 return m_transpose;
287}
288
289template <typename DataType> Matrix<DataType>::~Matrix()
290{
291}
292
293template <typename DataType>
295 unsigned int row, unsigned int column,
296 typename boost::call_traits<DataType>::const_reference d)
297{
298 ASSERTL2(row < this->GetRows(),
299 std::string("Row ") + std::to_string(row) +
300 std::string(" requested in a matrix with a maximum of ") +
301 std::to_string(this->GetRows()) + std::string(" rows"));
302 ASSERTL2(column < this->GetColumns(),
303 std::string("Column ") + std::to_string(column) +
304 std::string(" requested in a matrix with a maximum of ") +
305 std::to_string(this->GetColumns()) + std::string(" columns"));
306 v_SetValue(row, column, d);
307}
308
309template <typename DataType>
310Matrix<DataType>::Matrix(unsigned int rows, unsigned int columns,
311 MatrixStorage policy)
312 : ConstMatrix<DataType>(rows, columns, policy)
313{
314}
315
316template <typename DataType>
318 : ConstMatrix<DataType>(rhs)
319{
320}
321
322template <typename DataType>
324{
326 return *this;
327}
328
329template <typename DataType>
331{
333 return *this;
334}
335
338
340template LIB_UTILITIES_EXPORT class Matrix<int>;
341
344
347} // namespace Nektar
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
#define ASSERTL1(condition, msg)
Assert Level 1 – Debugging which is used whether in FULLDEBUG or DEBUG compilation mode....
Definition: ErrorUtil.hpp:242
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:265
#define LIB_UTILITIES_EXPORT
void SetTransposeFlag(char newValue)
Definition: MatrixBase.cpp:274
unsigned int m_size[2]
Definition: MatrixBase.hpp:128
ConstMatrix< DataType > & operator=(const ConstMatrix< DataType > &rhs)
Definition: MatrixBase.cpp:256
unsigned int GetStorageSize() const
Definition: MatrixBase.cpp:60
ConstMatrix(unsigned int rows, unsigned int columns, MatrixStorage policy=eFULL)
Definition: MatrixBase.cpp:239
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:128
unsigned int GetTransposedColumns(char transpose) const
Definition: MatrixBase.cpp:90
virtual char v_GetTransposeFlag() const
Definition: MatrixBase.cpp:284
unsigned int GetRows() const
Definition: MatrixBase.cpp:65
virtual void v_Transpose()
Definition: MatrixBase.cpp:279
MatrixStorage m_storageType
Definition: MatrixBase.hpp:130
virtual ~ConstMatrix()
Definition: MatrixBase.cpp:40
unsigned int GetTransposedRows(char transpose) const
Definition: MatrixBase.cpp:71
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:267
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
Definition: MatrixBase.cpp:186
char GetTransposeFlag() const
Definition: MatrixBase.cpp:122
unsigned int GetColumns() const
Definition: MatrixBase.cpp:84
const unsigned int * GetSize() const
Definition: MatrixBase.cpp:103
void SetValue(unsigned int row, unsigned int column, typename boost::call_traits< DataType >::const_reference d)
Definition: MatrixBase.cpp:294
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
Definition: MatrixBase.cpp:323
Matrix(unsigned int rows, unsigned int columns, MatrixStorage policy=eFULL)
Definition: MatrixBase.cpp:310
~Matrix() override
Definition: MatrixBase.cpp:289
std::vector< double > d(NPUPPER *NPUPPER)
@ eLOWER_TRIANGULAR_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
@ eUPPER_TRIANGULAR_BANDED
static unsigned int CalculateIndex(unsigned int totalRows, unsigned int totalColumns, unsigned int row, unsigned int column, unsigned int sub, unsigned int super)
Definition: MatrixFuncs.cpp:75
static unsigned int GetRequiredStorageSize(unsigned int totalRows, unsigned int totalColumns, unsigned int subDiags, unsigned int superDiags)
Calculates and returns the storage size required.
Definition: MatrixFuncs.cpp:42
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static unsigned int CalculateIndex(unsigned int row, unsigned int col)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static unsigned int CalculateIndex(unsigned int totalRows, unsigned int totalColumns, unsigned int curRow, unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int totalColumns, unsigned int curRow, unsigned int curColumn)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn, unsigned int nSuperDiags)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns, unsigned int nSubSuperDiags)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn)
static unsigned int GetRequiredStorageSize(unsigned int rows, unsigned int columns)
static unsigned int CalculateIndex(unsigned int curRow, unsigned int curColumn)