Nektar++
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatrixBase.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // For more information, please see: http://www.nektar.info
4 //
5 // The MIT License
6 //
7 // Copyright (c) 2006 Division of Applied Mathematics, Brown University (USA),
8 // Department of Aeronautics, Imperial College London (UK), and Scientific
9 // Computing and Imaging Institute, University of Utah (USA).
10 //
11 // License for the specific language governing rights and limitations under
12 // Permission is hereby granted, free of charge, to any person obtaining a
13 // copy of this software and associated documentation files (the "Software"),
14 // to deal in the Software without restriction, including without limitation
15 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 // and/or sell copies of the Software, and to permit persons to whom the
17 // Software is furnished to do so, subject to the following conditions:
18 //
19 // The above copyright notice and this permission notice shall be included
20 // in all copies or substantial portions of the Software.
21 //
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
28 // DEALINGS IN THE SOFTWARE.
29 //
30 ///////////////////////////////////////////////////////////////////////////////
31 
33 
34 namespace Nektar
35 {
36 
37  template<typename DataType>
39 
40  template<typename DataType>
41  typename boost::call_traits<DataType>::value_type ConstMatrix<DataType>::operator()(unsigned int row, unsigned int column) const
42  {
43  ASSERTL2(row < GetRows(), std::string("Row ") + boost::lexical_cast<std::string>(row) +
44  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(GetRows()) +
45  std::string(" rows"));
46  ASSERTL2(column < GetColumns(), std::string("Column ") + boost::lexical_cast<std::string>(column) +
47  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(GetColumns()) +
48  std::string(" columns"));
49  return v_GetValue(row, column);
50  }
51 
52  template<typename DataType>
54  {
55  return v_GetStorageSize();
56  }
57 
58  template<typename DataType>
60  {
61  return v_GetStorageType();
62  }
63 
64  template<typename DataType>
65  unsigned int ConstMatrix<DataType>::GetRows() const
66  {
67  return GetTransposedRows(GetTransposeFlag());
68  }
69 
70  template<typename DataType>
71  unsigned 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 
83  template<typename DataType>
84  unsigned int ConstMatrix<DataType>::GetColumns() const
85  {
86  return GetTransposedColumns(GetTransposeFlag());
87  }
88 
89  template<typename DataType>
90  unsigned 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 
102  template<typename DataType>
103  const unsigned int* ConstMatrix<DataType>::GetSize() const { return m_size; }
104 
105  template<typename DataType>
107  {
108  if( m_transpose == 'N' )
109  {
110  m_transpose = 'T';
111  }
112  else
113  {
114  m_transpose = 'N';
115  }
116  v_Transpose();
117  }
118 
119  template<typename DataType>
121  {
122  return v_GetTransposeFlag();
123  }
124 
125  template<typename DataType>
127  unsigned int row, unsigned int col,
128  unsigned int numRows, unsigned int numColumns, const char transpose,
129  unsigned int numSubDiags, unsigned int numSuperDiags )
130  {
131  if(transpose == 'T' )
132  {
133  std::swap(row, col);
134  }
135  switch(type)
136  {
137  case eFULL:
138  return FullMatrixFuncs::CalculateIndex(numRows, numColumns, row, col);
139  break;
140  case eDIAGONAL:
141  return DiagonalMatrixFuncs::CalculateIndex(row, col);
142  break;
143  case eUPPER_TRIANGULAR:
145  break;
146  case eLOWER_TRIANGULAR:
147  return LowerTriangularMatrixFuncs::CalculateIndex(numColumns, row, col);
148  break;
149  case eSYMMETRIC:
151  return SymmetricMatrixFuncs::CalculateIndex(row, col);
152  break;
153  case eBANDED:
154  return BandedMatrixFuncs::CalculateIndex(numRows, numColumns,
155  row, col, numSubDiags, numSuperDiags);
156  break;
157  case eSYMMETRIC_BANDED:
159  {
160  ASSERTL1(numSubDiags==numSuperDiags,
161  std::string("Number of sub- and superdiagonals should ") +
162  std::string("be equal for a symmetric banded matrix"));
164  numSuperDiags);
165  }
166  break;
168  NEKERROR(ErrorUtil::efatal, "Not yet implemented.");
169  break;
171  NEKERROR(ErrorUtil::efatal, "Not yet implemented.");
172  break;
173 
174  default:
175  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
176  }
177 
178  return std::numeric_limits<unsigned int>::max();
179  }
180 
181  template<typename DataType>
182  unsigned int ConstMatrix<DataType>::GetRequiredStorageSize(MatrixStorage type, unsigned int rows,
183  unsigned int columns, unsigned int subDiags, unsigned int superDiags)
184  {
185  switch(type)
186  {
187  case eFULL:
188  return FullMatrixFuncs::GetRequiredStorageSize(rows, columns);
189  break;
190  case eDIAGONAL:
191  return DiagonalMatrixFuncs::GetRequiredStorageSize(rows, columns);
192  break;
193  case eUPPER_TRIANGULAR:
195  break;
196  case eLOWER_TRIANGULAR:
198  break;
199  case eSYMMETRIC:
201  return SymmetricMatrixFuncs::GetRequiredStorageSize(rows, columns);
202  break;
203  case eBANDED:
204  return BandedMatrixFuncs::GetRequiredStorageSize(rows, columns,
205  subDiags, superDiags);
206  break;
207  case eSYMMETRIC_BANDED:
209  {
210  ASSERTL1(subDiags==superDiags,
211  std::string("Number of sub- and superdiagonals should ") +
212  std::string("be equal for a symmetric banded matrix"));
214  superDiags);
215  }
216  break;
218  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
219  break;
221  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
222  break;
223 
224  default:
225  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
226  }
227 
228  return 0;
229  }
230 
231  template<typename DataType>
232  ConstMatrix<DataType>::ConstMatrix(unsigned int rows, unsigned int columns) :
233  m_size(),
234  m_transpose('N')
235  {
236  m_size[0] = rows;
237  m_size[1] = columns;
238  }
239 
240  template<typename DataType>
242  m_size(),
243  m_transpose(rhs.m_transpose)
244  {
245  m_size[0] = rhs.m_size[0];
246  m_size[1] = rhs.m_size[1];
247  }
248 
249  template<typename DataType>
251  {
252  m_size[0] = rhs.m_size[0];
253  m_size[1] = rhs.m_size[1];
254  m_transpose = rhs.m_transpose;
255  return *this;
256  }
257 
258 
259  template<typename DataType>
260  void ConstMatrix<DataType>::Resize(unsigned int rows, unsigned int columns)
261  {
262  m_size[0] = rows;
263  m_size[1] = columns;
264  }
265 
266  template<typename DataType>
268  {
269  m_transpose = newValue;
270  }
271 
272  template<typename DataType>
273  char ConstMatrix<DataType>::GetRawTransposeFlag() const { return m_transpose; }
274 
275  template<typename DataType>
277 
278  template<typename DataType>
279  char ConstMatrix<DataType>::v_GetTransposeFlag() const { return m_transpose; }
280 
281 
282  template<typename DataType>
284 
285  template<typename DataType>
286  void Matrix<DataType>::SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d)
287  {
288  ASSERTL2(row < this->GetRows(), std::string("Row ") + boost::lexical_cast<std::string>(row) +
289  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(this->GetRows()) +
290  std::string(" rows"));
291  ASSERTL2(column < this->GetColumns(), std::string("Column ") + boost::lexical_cast<std::string>(column) +
292  std::string(" requested in a matrix with a maximum of ") + boost::lexical_cast<std::string>(this->GetColumns()) +
293  std::string(" columns"));
294  v_SetValue(row, column, d);
295  }
296 
297  template<typename DataType>
298  Matrix<DataType>::Matrix(unsigned int rows, unsigned int columns) :
299  ConstMatrix<DataType>(rows, columns)
300  {
301  }
302 
303  template<typename DataType>
305  ConstMatrix<DataType>(rhs)
306  {
307  }
308 
309  template<typename DataType>
311  {
313  return *this;
314  }
315 
316  template<typename DataType>
318  {
320  return *this;
321  }
322 
323 
326 
327  template LIB_UTILITIES_EXPORT class ConstMatrix<int>;
328  template LIB_UTILITIES_EXPORT class Matrix<int>;
329 
332 
334  template LIB_UTILITIES_EXPORT class Matrix<float>;
335 }