Nektar++
StandardMatrix.cpp
Go to the documentation of this file.
1 ///////////////////////////////////////////////////////////////////////////////
2 //
3 // File: StandardMatrix.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 
37 namespace Nektar
38 {
39 
40 template <typename DataType>
42  : Matrix<DataType>(0, 0, eFULL), m_data(), m_wrapperType(eCopy),
43  m_numberOfSuperDiagonals(std::numeric_limits<unsigned int>::max()),
44  m_numberOfSubDiagonals(std::numeric_limits<unsigned int>::max()),
45  m_tempSpace()
46 {
47  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
48 }
49 
50 template <typename DataType>
52  unsigned int columns,
53  MatrixStorage policy,
54  unsigned int subDiagonals,
55  unsigned int superDiagonals)
56  : Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(eCopy),
57  m_numberOfSuperDiagonals(superDiagonals),
58  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
59 {
60  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
61 }
62 
63 template <typename DataType>
65  unsigned int columns,
66  MatrixStorage policy,
67  unsigned int subDiagonals,
68  unsigned int superDiagonals,
69  unsigned int capacity)
70  : Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(eCopy),
71  m_numberOfSuperDiagonals(superDiagonals),
72  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
73 {
74  unsigned int requiredStorage = this->GetRequiredStorageSize();
75  unsigned int actualSize = std::max(requiredStorage, capacity);
76  m_data = Array<OneD, DataType>(actualSize);
77 }
78 
79 template <typename DataType>
81  unsigned int rows, unsigned int columns,
82  typename boost::call_traits<DataType>::const_reference initValue,
83  MatrixStorage policy, unsigned int subDiagonals,
84  unsigned int superDiagonals)
85  : Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(eCopy),
86  m_numberOfSuperDiagonals(superDiagonals),
87  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
88 {
89  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
90  std::fill(m_data.begin(), m_data.end(), initValue);
91 }
92 
93 template <typename DataType>
95  unsigned int columns,
96  const DataType *data,
97  MatrixStorage policy,
98  unsigned int subDiagonals,
99  unsigned int superDiagonals)
100  : Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(eCopy),
101  m_numberOfSuperDiagonals(superDiagonals),
102  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
103 {
104  unsigned int size = GetRequiredStorageSize();
105  m_data = Array<OneD, DataType>(size);
106  std::copy(data, data + size, m_data.begin());
107 }
108 
109 template <typename DataType>
111  unsigned int rows, unsigned int columns,
113  unsigned int subDiagonals, unsigned int superDiagonals)
114  : Matrix<DataType>(rows, columns, policy), m_data(), m_wrapperType(eCopy),
115  m_numberOfSuperDiagonals(superDiagonals),
116  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
117 {
118  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
119  CopyArrayN(d, m_data, m_data.size());
120 }
121 
122 template <typename DataType>
124  unsigned int rows, unsigned int columns, const Array<OneD, DataType> &d,
125  PointerWrapper wrapperType, MatrixStorage policy, unsigned int subDiagonals,
126  unsigned int superDiagonals)
127  : Matrix<DataType>(rows, columns, policy), m_data(),
128  m_wrapperType(wrapperType), m_numberOfSuperDiagonals(superDiagonals),
129  m_numberOfSubDiagonals(subDiagonals), m_tempSpace()
130 {
131  if (wrapperType == eWrapper)
132  {
134  }
135  else
136  {
137  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
138  CopyArrayN(d, m_data, m_data.size());
139  }
140 }
141 
142 template <typename DataType>
145  : Matrix<DataType>(rhs), m_data(), m_wrapperType(rhs.m_wrapperType),
146  m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
147  m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals), m_tempSpace()
148 {
149  PerformCopyConstruction(rhs);
150 }
151 
152 template <typename DataType>
156 {
157  if (this == &rhs)
158  {
159  return *this;
160  }
161 
163  m_numberOfSubDiagonals = rhs.m_numberOfSubDiagonals;
164  m_numberOfSuperDiagonals = rhs.m_numberOfSuperDiagonals;
165 
166  ResizeDataArrayIfNeeded();
167 
168  unsigned int requiredStorageSize = GetRequiredStorageSize();
169  std::copy(rhs.m_data.data(), rhs.m_data.data() + requiredStorageSize,
170  m_data.data());
171 
172  return *this;
173 }
174 
175 /// Fill matrix with scalar
176 template <typename DataType>
179 {
180  unsigned int requiredStorageSize = GetRequiredStorageSize();
181 
182  DataType *lhs_array = m_data.data();
183 
184  Vmath::Fill(requiredStorageSize, rhs, lhs_array, 1);
185 
186  return *this;
187 }
188 
189 template <typename DataType>
191  DataType, StandardMatrixTag>::operator()(unsigned int row,
192  unsigned int column) const
193 {
194  ASSERTL2(row < this->GetRows(),
195  std::string("Row ") + std::to_string(row) +
196  std::string(" requested in a matrix with a maximum of ") +
197  std::to_string(this->GetRows()) + std::string(" rows"));
198  ASSERTL2(column < this->GetColumns(),
199  std::string("Column ") + std::to_string(column) +
200  std::string(" requested in a matrix with a maximum of ") +
201  std::to_string(this->GetColumns()) + std::string(" columns"));
202 
203  return this->GetValue(row, column, this->GetTransposeFlag());
204 }
205 
206 template <typename DataType>
208  DataType, StandardMatrixTag>::operator()(unsigned int row,
209  unsigned int column,
210  char transpose) const
211 {
212  return this->GetValue(row, column, transpose);
213 }
214 
215 template <typename DataType>
217  const
218 {
220  this->GetStorageType(), this->GetRows(), this->GetColumns(),
221  this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
222 }
223 
224 template <typename DataType>
226  unsigned int row, unsigned int col, const char transpose) const
227 {
228  unsigned int numRows = this->GetSize()[0];
229  unsigned int numColumns = this->GetSize()[1];
231  this->GetStorageType(), row, col, numRows, numColumns, transpose,
232  m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
233 }
234 
235 template <typename DataType>
236 typename boost::call_traits<DataType>::const_reference NekMatrix<
237  DataType, StandardMatrixTag>::GetValue(unsigned int row,
238  unsigned int column) const
239 {
240  ASSERTL2(row < this->GetRows(),
241  std::string("Row ") + std::to_string(row) +
242  std::string(" requested in a matrix with a maximum of ") +
243  std::to_string(this->GetRows()) + std::string(" rows"));
244  ASSERTL2(column < this->GetColumns(),
245  std::string("Column ") + std::to_string(column) +
246  std::string(" requested in a matrix with a maximum of ") +
247  std::to_string(this->GetColumns()) + std::string(" columns"));
248 
249  return GetValue(row, column, this->GetTransposeFlag());
250 }
251 
252 template <typename DataType>
254  DataType, StandardMatrixTag>::GetValue(unsigned int row,
255  unsigned int column,
256  char transpose) const
257 {
258  static DataType defaultReturnValue;
259  unsigned int index = CalculateIndex(row, column, transpose);
260  if (index != std::numeric_limits<unsigned int>::max())
261  {
262  return m_data[index];
263  }
264  else
265  {
266  return defaultReturnValue;
267  }
268 }
269 
270 template <typename DataType>
273 {
274  return m_data;
275 }
276 
277 template <typename DataType>
279 {
280  return DataType(1);
281 }
282 
283 template <typename DataType>
285 {
286  return m_data.data();
287 }
288 
289 template <typename DataType>
291  DataType, StandardMatrixTag>::begin() const
292 {
293  return begin(this->GetTransposeFlag());
294 }
295 
296 template <typename DataType>
298  DataType, StandardMatrixTag>::begin(char transpose) const
299 {
300  if (transpose == 'N')
301  {
302  return const_iterator(m_data.data(), m_data.data() + m_data.size());
303  }
304  else
305  {
306  return const_iterator(this, transpose);
307  }
308 }
309 
310 template <typename DataType>
312  DataType, StandardMatrixTag>::end() const
313 {
314  return end(this->GetTransposeFlag());
315 }
316 
317 template <typename DataType>
319  DataType, StandardMatrixTag>::end(char transpose) const
320 {
321  if (transpose == 'N')
322  {
323  return const_iterator(m_data.data(), m_data.data() + m_data.size(),
324  true);
325  }
326  else
327  {
328  return const_iterator(this, transpose, true);
329  }
330 }
331 
332 template <typename DataType>
334 {
335  return m_data.size();
336 }
337 
338 template <typename DataType>
340  const
341 {
342  if (m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max())
343  {
344  return m_numberOfSubDiagonals;
345  }
346  else if (this->GetRows() > 0)
347  {
348  return this->GetRows() - 1;
349  }
350  else
351  {
352  return 0;
353  }
354 }
355 
356 template <typename DataType>
358  const
359 {
360  if (m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max())
361  {
362  return m_numberOfSuperDiagonals;
363  }
364  else if (this->GetRows() > 0)
365  {
366  return this->GetRows() - 1;
367  }
368  else
369  {
370  return 0;
371  }
372 }
373 
374 template <typename DataType>
376  const
377 {
378  return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
379 }
380 
381 template <typename DataType>
384 {
385  if (this->GetRows() != rhs.GetRows() ||
386  this->GetColumns() != rhs.GetColumns())
387  {
388  return false;
389  }
390 
391  if (this->GetTransposeFlag() == rhs.GetTransposeFlag())
392  {
393  return std::equal(begin(), end(), rhs.begin());
394  }
395  else
396  {
397  for (unsigned int i = 0; i < this->GetRows(); ++i)
398  {
399  for (unsigned int j = 0; j < this->GetColumns(); ++j)
400  {
401  if ((*this)(i, j) != rhs(i, j))
402  {
403  return false;
404  }
405  }
406  }
407  }
408 
409  return true;
410 }
411 
412 template <typename DataType>
414 {
415  return m_wrapperType;
416 }
417 
418 template <typename DataType>
419 std::tuple<unsigned int, unsigned int> NekMatrix<
420  DataType, StandardMatrixTag>::Advance(unsigned int curRow,
421  unsigned int curColumn) const
422 {
423  return Advance(curRow, curColumn, this->GetTransposeFlag());
424 }
425 
426 template <typename DataType>
427 std::tuple<unsigned int, unsigned int> NekMatrix<
428  DataType, StandardMatrixTag>::Advance(unsigned int curRow,
429  unsigned int curColumn,
430  char transpose) const
431 {
432  unsigned int numRows = this->GetTransposedRows(transpose);
433  unsigned int numColumns = this->GetTransposedColumns(transpose);
434 
435  switch (this->GetStorageType())
436  {
437  case eFULL:
438  return FullMatrixFuncs::Advance(numRows, numColumns, curRow,
439  curColumn);
440  break;
441  case eDIAGONAL:
442  return DiagonalMatrixFuncs::Advance(numRows, numColumns, curRow,
443  curColumn);
444  break;
445  case eUPPER_TRIANGULAR:
446  return UpperTriangularMatrixFuncs::Advance(numRows, numColumns,
447  curRow, curColumn);
448  break;
449 
450  case eLOWER_TRIANGULAR:
451  return LowerTriangularMatrixFuncs::Advance(numRows, numColumns,
452  curRow, curColumn);
453  break;
454 
455  case eSYMMETRIC:
457  return SymmetricMatrixFuncs::Advance(numRows, numColumns, curRow,
458  curColumn);
459  break;
460  case eBANDED:
461  return BandedMatrixFuncs::Advance(numRows, numColumns, curRow,
462  curColumn);
463  break;
464  case eSYMMETRIC_BANDED:
466  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
467  break;
469  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
470  break;
472  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
473  break;
474 
475  default:
476  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
477  }
478  return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
479 }
480 
481 template <typename DataType>
484 {
486 }
487 
488 template <typename DataType>
489 std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>> NekMatrix<
490  DataType, StandardMatrixTag>::
491  CreateWrapper(
492  const std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>> &rhs)
493 {
494  return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>(
496 }
497 
498 template <typename DataType>
501  PointerWrapper wrapperType)
502  : BaseType(rhs), m_data(), m_wrapperType(wrapperType),
503  m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
504  m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
505 {
506  PerformCopyConstruction(rhs);
507 }
508 
509 template <typename DataType>
511 {
512  return m_data;
513 }
514 
515 template <typename DataType>
517 {
518  if (m_wrapperType == eCopy)
519  {
520  unsigned int requiredStorageSize = GetRequiredStorageSize();
521  if (m_data.size() > requiredStorageSize)
522  {
523  Array<OneD, DataType> newArray(requiredStorageSize);
524  CopyArrayN(m_data, newArray, requiredStorageSize);
525  m_data = newArray;
526  }
527  }
528  else if (m_wrapperType == eWrapper)
529  {
530  ASSERTL0(true, "Can't call RemoveExcessCapacity on a wrapped matrix.");
531  }
532 }
533 
534 template <typename DataType>
536  unsigned int requiredStorageSize)
537 {
538  if (m_wrapperType == eCopy)
539  {
540  if (m_data.size() < requiredStorageSize)
541  {
542  Array<OneD, DataType> newData(requiredStorageSize);
543  std::copy(m_data.data(), m_data.data() + m_data.size(),
544  newData.data());
545  m_data = newData;
546  }
547  }
548  else if (m_wrapperType == eWrapper)
549  {
550  // If the current matrix is wrapped, then just copy over the top,
551  // but the sizes of the two matrices must be the same.
552  ASSERTL0(
553  m_data.size() >= requiredStorageSize,
554  "Wrapped NekMatrices must have the same dimension in operator=");
555  }
556 }
557 
558 template <typename DataType>
560 {
561  unsigned int requiredStorageSize = GetRequiredStorageSize();
562  ResizeDataArrayIfNeeded(requiredStorageSize);
563 }
564 
565 template <typename DataType>
567  const ThisType &rhs)
568 {
569  if (m_wrapperType == eWrapper)
570  {
571  m_data = rhs.m_data;
572  }
573  else
574  {
575  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
576  CopyArrayN(rhs.m_data, m_data, m_data.size());
577  }
578 }
579 
580 template <typename DataType>
581 typename boost::call_traits<DataType>::value_type NekMatrix<
582  DataType, StandardMatrixTag>::v_GetValue(unsigned int row,
583  unsigned int column) const
584 {
586 }
587 
588 template <typename DataType>
590 {
592 }
593 
594 template <typename DataType>
596  unsigned int row, unsigned int column,
597  typename boost::call_traits<DataType>::const_reference d)
598 {
600 }
601 
602 template <typename DataType>
604  unsigned int cols)
605 {
606  this->Resize(rows, cols);
607 
608  // Some places in Nektar++ access the matrix data array and
609  // use size() to see how big it is. When using
610  // expression templates, the data array's capacity is often larger
611  // than the actual number of elements, so this statement is
612  // required to report the correct number of elements.
613  this->GetData().ChangeSize(this->GetRequiredStorageSize());
614  ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
615  "Can't resize matrices if there is not enough capacity.");
616 }
617 
618 template <typename DataType>
620  DataType, StandardMatrixTag>::operator()(unsigned int row,
621  unsigned int column)
622 {
623  ASSERTL2(row < this->GetRows(),
624  std::string("Row ") + std::to_string(row) +
625  std::string(" requested in a matrix with a maximum of ") +
626  std::to_string(this->GetRows()) + std::string(" rows"));
627  ASSERTL2(column < this->GetColumns(),
628  std::string("Column ") + std::to_string(column) +
629  std::string(" requested in a matrix with a maximum of ") +
630  std::to_string(this->GetColumns()) + std::string(" columns"));
631 
632  return (*this)(row, column, this->GetTransposeFlag());
633 }
634 
635 template <typename DataType>
637  DataType, StandardMatrixTag>::operator()(unsigned int row,
638  unsigned int column,
639  char transpose)
640 {
641  unsigned int index = this->CalculateIndex(row, column, transpose);
642  if (index != std::numeric_limits<unsigned int>::max())
643  {
644  return Proxy(this->GetData()[index]);
645  }
646  else
647  {
648  return Proxy();
649  }
650 }
651 
652 template <typename DataType>
654  unsigned int row, unsigned int column,
655  typename boost::call_traits<DataType>::const_reference d)
656 {
657  ASSERTL2(row < this->GetRows(),
658  std::string("Row ") + std::to_string(row) +
659  std::string(" requested in a matrix with a maximum of ") +
660  std::to_string(this->GetRows()) + std::string(" rows"));
661  ASSERTL2(column < this->GetColumns(),
662  std::string("Column ") + std::to_string(column) +
663  std::string(" requested in a matrix with a maximum of ") +
664  std::to_string(this->GetColumns()) + std::string(" columns"));
665  SetValue(row, column, d, this->GetTransposeFlag());
666 }
667 
668 template <typename DataType>
670  unsigned int row, unsigned int column,
671  typename boost::call_traits<DataType>::const_reference d, char transpose)
672 {
673  unsigned int index = this->CalculateIndex(row, column, transpose);
674  if (index != std::numeric_limits<unsigned int>::max())
675  {
676  this->GetData()[index] = d;
677  }
678  else
679  {
680  NEKERROR(
682  "Can't assign values into zeroed elements of a special array.");
683  }
684 }
685 
686 template <typename DataType>
688 {
689  return this->GetData();
690 }
691 
692 template <typename DataType>
694 {
695  return this->GetData().data();
696 }
697 
698 template <typename DataType>
700  DataType, StandardMatrixTag>::begin()
701 {
702  return begin(this->GetTransposeFlag());
703 }
704 
705 template <typename DataType>
707  DataType, StandardMatrixTag>::begin(char transpose)
708 {
709  if (transpose == 'N')
710  {
711  return iterator(this->GetData().data(),
712  this->GetData().data() + this->GetData().size());
713  }
714  else
715  {
716  return iterator(this, transpose);
717  }
718 }
719 
720 template <typename DataType>
722  DataType, StandardMatrixTag>::end()
723 {
724  return end(this->GetTransposeFlag());
725 }
726 
727 template <typename DataType>
729  DataType, StandardMatrixTag>::end(char transpose)
730 {
731  if (transpose == 'N')
732  {
733  return iterator(this->GetData().data(),
734  this->GetData().data() + this->GetData().size(), true);
735  }
736  else
737  {
738  return iterator(this, transpose, true);
739  }
740 }
741 
742 template <typename DataType>
744  void)
745 {
746  DataType returnval;
747  int nvals = this->GetColumns();
748  Array<OneD, DataType> EigValReal(nvals);
749  Array<OneD, DataType> EigValImag(nvals);
750  Array<OneD, DataType> Evecs;
751 
752  EigenSolve(EigValReal, EigValImag, Evecs);
753 
754  Vmath::Vmul(nvals, EigValReal, 1, EigValReal, 1, EigValReal, 1);
755  Vmath::Vmul(nvals, EigValImag, 1, EigValImag, 1, EigValImag, 1);
756  Vmath::Vadd(nvals, EigValReal, 1, EigValImag, 1, EigValReal, 1);
757 
758  returnval = sqrt(Vmath::Vmax(nvals, EigValReal, 1) /
759  Vmath::Vmin(nvals, EigValReal, 1));
760 
761  return returnval;
762 }
763 
764 template <typename DataType>
766  Array<OneD, DataType> &EigValReal, Array<OneD, DataType> &EigValImag,
767  Array<OneD, DataType> &EigVecs)
768 {
769  ASSERTL0(this->GetRows() == this->GetColumns(),
770  "Only square matrices can be called");
771 
772  switch (this->GetType())
773  {
774  case eFULL:
775  FullMatrixFuncs::EigenSolve(this->GetRows(), this->GetData(),
776  EigValReal, EigValImag, EigVecs);
777  break;
778  case eDIAGONAL:
779  Vmath::Vcopy(this->GetRows(), &(this->GetData())[0], 1,
780  &EigValReal[0], 1);
781  Vmath::Zero(this->GetRows(), &EigValImag[0], 1);
782  break;
783  case eUPPER_TRIANGULAR:
784  case eLOWER_TRIANGULAR:
785  case eSYMMETRIC:
786  case eBANDED:
787  case eSYMMETRIC_BANDED:
790  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
791  break;
792 
793  default:
794  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
795  }
796 }
797 
798 template <typename DataType>
800 {
801  ASSERTL0(this->GetRows() == this->GetColumns(),
802  "Only square matrices can be inverted.");
803  ASSERTL0(this->GetTransposeFlag() == 'N',
804  "Only untransposed matrices may be inverted.");
805 
806  switch (this->GetType())
807  {
808  case eFULL:
809  FullMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
810  this->GetData(), this->GetTransposeFlag());
811  break;
812  case eDIAGONAL:
813  DiagonalMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
814  this->GetData());
815  break;
816  case eSYMMETRIC:
817  SymmetricMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
818  this->GetData());
819  break;
820  case eUPPER_TRIANGULAR:
821  case eLOWER_TRIANGULAR:
822  case eBANDED:
823  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
824  break;
825  case eSYMMETRIC_BANDED:
826  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
827  break;
829  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
830  break;
832  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
833  break;
834 
835  default:
836  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
837  }
838 }
839 
840 template <typename DataType>
842 {
843  if (m_tempSpace.capacity() == 0)
844  {
845  m_tempSpace = Array<OneD, DataType>(this->GetData().capacity());
846  }
847  return m_tempSpace;
848 }
849 
850 template <typename DataType>
852 {
853  std::swap(m_tempSpace, this->GetData());
854 }
855 
856 template <typename DataType>
858  DataType, StandardMatrixTag>::operator-() const
859 {
861  NegateInPlace(result);
862  return result;
863 }
864 
865 template <typename DataType>
868 {
869  for (unsigned int i = 0; i < this->GetPtr().size(); ++i)
870  {
871  this->GetPtr()[i] *= s;
872  }
873  return *this;
874 }
875 
876 template <typename DataType>
879 {
881  rhs.GetRows(), rhs.GetColumns(), rhs.GetPtr(), eWrapper, rhs.GetType(),
883  result.Transpose();
884  return result;
885 }
886 
889 
891 
894 
896 
897 template <typename DataType>
899 {
900  for (unsigned int i = 0; i < m.GetRows(); ++i)
901  {
902  for (unsigned int j = 0; j < m.GetColumns(); ++j)
903  {
904  m(i, j) *= -1.0;
905  }
906  }
907 }
908 
913 
914 } // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:215
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:209
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:272
#define LIB_UTILITIES_EXPORT
bool operator==(const VertexSharedPtr &v1, const VertexSharedPtr &v2)
Define comparison operator for the vertex struct.
Definition: VtkToFld.cpp:95
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:58
size_type size() const
Returns the array's size.
MatrixStorage GetType() const
Definition: MatrixBase.hpp:64
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 GetRows() const
Definition: MatrixBase.cpp:65
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
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
Definition: MatrixBase.cpp:323
iterator_impl< const DataType, const ThisType > const_iterator
iterator_impl< DataType, ThisType > iterator
const Array< OneD, const DataType > & GetPtr() const
def copy(self)
Definition: pycml.py:2663
The above copyright notice and this permission notice shall be included.
Definition: CoupledSolver.h:2
@ eVECTOR_WRAPPER
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:1160
@ eLOWER_TRIANGULAR_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
@ eUPPER_TRIANGULAR_BANDED
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, typename Array< OneD, DataType >::size_type n)
PointerWrapper
Specifies if the pointer passed to a NekMatrix or NekVector is copied into an internal representation...
void Vmul(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Multiply vector z = x*y.
Definition: Vmath.cpp:209
T Vmin(int n, const T *x, const int incx)
Return the minimum element in x - called vmin to avoid conflict with min.
Definition: Vmath.cpp:1050
void Vadd(int n, const T *x, const int incx, const T *y, const int incy, T *z, const int incz)
Add vector z = x+y.
Definition: Vmath.cpp:359
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:492
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.cpp:45
T Vmax(int n, const T *x, const int incx)
Return the maximum element in x – called vmax to avoid conflict with max.
Definition: Vmath.cpp:945
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1255
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:294
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
Definition: MatrixFuncs.h:285
static void EigenSolve(unsigned int n, const Array< OneD, const DataType > &A, Array< OneD, DataType > &EigValReal, Array< OneD, DataType > &EigValImag, Array< OneD, DataType > &EigVecs)
Definition: MatrixFuncs.h:159
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data, const char transpose)
Definition: MatrixFuncs.h:91
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn, char transpose='N')
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
static void Invert(unsigned int rows, unsigned int columns, Array< OneD, DataType > &data)
Definition: MatrixFuncs.h:230
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)