Nektar++
StandardMatrix.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 // Permission is hereby granted, free of charge, to any person obtaining a
12 // copy of this software and associated documentation files (the "Software"),
13 // to deal in the Software without restriction, including without limitation
14 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 // and/or sell copies of the Software, and to permit persons to whom the
16 // Software is furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included
19 // in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 // DEALINGS IN THE SOFTWARE.
28 //
29 ///////////////////////////////////////////////////////////////////////////////
30 
32 
33 
34 namespace Nektar
35 {
36 
37 
38  template<typename DataType>
40  Matrix<DataType>(0, 0, eFULL),
41  m_data(),
42  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>
51  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns, MatrixStorage policy,
52  unsigned int subDiagonals,
53  unsigned int superDiagonals) :
54  Matrix<DataType>(rows, columns, policy),
55  m_data(),
56  m_wrapperType(eCopy),
57  m_numberOfSuperDiagonals(superDiagonals),
58  m_numberOfSubDiagonals(subDiagonals),
59  m_tempSpace()
60  {
61  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
62  }
63 
64  template<typename DataType>
65  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns,
66  MatrixStorage policy,
67  unsigned int subDiagonals,
68  unsigned int superDiagonals,
69  unsigned int capacity) :
70  Matrix<DataType>(rows, columns, policy),
71  m_data(),
72  m_wrapperType(eCopy),
73  m_numberOfSuperDiagonals(superDiagonals),
74  m_numberOfSubDiagonals(subDiagonals),
75  m_tempSpace()
76  {
77  unsigned int requiredStorage = this->GetRequiredStorageSize();
78  unsigned int actualSize = std::max(requiredStorage, capacity);
79  m_data = Array<OneD, DataType>(actualSize);
80  }
81 
82  template<typename DataType>
83  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns, typename boost::call_traits<DataType>::const_reference initValue,
84  MatrixStorage policy,
85  unsigned int subDiagonals,
86  unsigned int superDiagonals) :
87  Matrix<DataType>(rows, columns, policy),
88  m_data(),
89  m_wrapperType(eCopy),
90  m_numberOfSuperDiagonals(superDiagonals),
91  m_numberOfSubDiagonals(subDiagonals),
92  m_tempSpace()
93  {
94  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
95  std::fill(m_data.begin(), m_data.end(), initValue);
96  }
97 
98  template<typename DataType>
99  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns, const DataType* data,
100  MatrixStorage policy,
101  unsigned int subDiagonals,
102  unsigned int superDiagonals) :
103  Matrix<DataType>(rows, columns, policy),
104  m_data(),
105  m_wrapperType(eCopy),
106  m_numberOfSuperDiagonals(superDiagonals),
107  m_numberOfSubDiagonals(subDiagonals),
108  m_tempSpace()
109  {
110  unsigned int size = GetRequiredStorageSize();
111  m_data = Array<OneD, DataType>(size);
112  std::copy(data, data + size, m_data.begin());
113  }
114 
115  template<typename DataType>
116  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns, const Array<OneD, const DataType>& d,
117  MatrixStorage policy,
118  unsigned int subDiagonals,
119  unsigned int superDiagonals) :
120  Matrix<DataType>(rows, columns, policy),
121  m_data(),
122  m_wrapperType(eCopy),
123  m_numberOfSuperDiagonals(superDiagonals),
124  m_numberOfSubDiagonals(subDiagonals),
125  m_tempSpace()
126  {
127  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
128  CopyArrayN(d, m_data, m_data.num_elements());
129  }
130 
131  template<typename DataType>
132  NekMatrix<DataType, StandardMatrixTag>::NekMatrix(unsigned int rows, unsigned int columns, const Array<OneD, DataType>& d, PointerWrapper wrapperType,
133  MatrixStorage policy,
134  unsigned int subDiagonals,
135  unsigned int superDiagonals) :
136  Matrix<DataType>(rows, columns, policy),
137  m_data(),
138  m_wrapperType(wrapperType),
139  m_numberOfSuperDiagonals(superDiagonals),
140  m_numberOfSubDiagonals(subDiagonals),
141  m_tempSpace()
142  {
143  if( wrapperType == eWrapper )
144  {
146  }
147  else
148  {
149  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
150  CopyArrayN(d, m_data, m_data.num_elements());
151  }
152  }
153 
154  template<typename DataType>
156  Matrix<DataType>(rhs),
157  m_data(),
158  m_wrapperType(rhs.m_wrapperType),
159  m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
160  m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals),
161  m_tempSpace()
162  {
163  PerformCopyConstruction(rhs);
164  }
165 
166  template<typename DataType>
168  {
169  if( this == &rhs )
170  {
171  return *this;
172  }
173 
175  m_numberOfSubDiagonals = rhs.m_numberOfSubDiagonals;
176  m_numberOfSuperDiagonals = rhs.m_numberOfSuperDiagonals;
177 
178  ResizeDataArrayIfNeeded();
179 
180  unsigned int requiredStorageSize = GetRequiredStorageSize();
181  std::copy(rhs.m_data.data(), rhs.m_data.data() + requiredStorageSize, m_data.data());
182 
183  return *this;
184  }
185 
186 
187  template<typename DataType>
189  {
190  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
191  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
192  std::string(" rows"));
193  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
194  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
195  std::string(" columns"));
196 
197  return this->GetValue(row, column, this->GetTransposeFlag());
198  }
199 
200  template<typename DataType>
201  typename NekMatrix<DataType, StandardMatrixTag>::ConstGetValueType NekMatrix<DataType, StandardMatrixTag>::operator()(unsigned int row, unsigned int column, char transpose) const
202  {
203  return this->GetValue(row, column, transpose);
204  }
205 
206  template<typename DataType>
208  {
209  return Matrix<DataType>::GetRequiredStorageSize(this->GetStorageType(),
210  this->GetRows(), this->GetColumns(),
211  this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
212  }
213 
214  template<typename DataType>
215  unsigned int NekMatrix<DataType, StandardMatrixTag>::CalculateIndex(unsigned int row, unsigned int col, const char transpose) const
216  {
217  unsigned int numRows = this->GetSize()[0];
218  unsigned int numColumns = this->GetSize()[1];
219  return Matrix<DataType>::CalculateIndex(this->GetStorageType(),
220  row, col, numRows, numColumns, transpose,
221  m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
222  }
223 
224  template<typename DataType>
225  typename boost::call_traits<DataType>::const_reference NekMatrix<DataType, StandardMatrixTag>::GetValue(unsigned int row, unsigned int column) const
226  {
227  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
228  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
229  std::string(" rows"));
230  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
231  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
232  std::string(" columns"));
233 
234  return GetValue(row, column, this->GetTransposeFlag());
235  }
236 
237  template<typename DataType>
238  typename NekMatrix<DataType, StandardMatrixTag>::ConstGetValueType NekMatrix<DataType, StandardMatrixTag>::GetValue(unsigned int row, unsigned int column, char transpose) const
239  {
240  static DataType defaultReturnValue;
241  unsigned int index = CalculateIndex(row, column, transpose);
242  if( index != std::numeric_limits<unsigned int>::max() )
243  {
244  return m_data[index];
245  }
246  else
247  {
248  return defaultReturnValue;
249  }
250  }
251 
252  template<typename DataType>
254  {
255  return m_data;
256  }
257 
258  template<typename DataType>
260  {
261  return DataType(1);
262  }
263 
264  template<typename DataType>
266  {
267  return m_data.data();
268  }
269 
270  template<typename DataType>
272  {
273  return begin(this->GetTransposeFlag());
274  }
275 
276  template<typename DataType>
278  {
279  if( transpose == 'N' )
280  {
281  return const_iterator(m_data.data(), m_data.data() + m_data.num_elements());
282  }
283  else
284  {
285  return const_iterator(this, transpose);
286  }
287  }
288 
289  template<typename DataType>
291  {
292  return end(this->GetTransposeFlag());
293  }
294 
295  template<typename DataType>
297  {
298  if( transpose == 'N' )
299  {
300  return const_iterator(m_data.data(), m_data.data() + m_data.num_elements(), true);
301  }
302  else
303  {
304  return const_iterator(this, transpose, true);
305  }
306  }
307 
308  template<typename DataType>
310  {
311  return m_data.num_elements();
312  }
313 
314  template<typename DataType>
316  {
317  if( m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max() )
318  {
319  return m_numberOfSubDiagonals;
320  }
321  else if( this->GetRows() > 0 )
322  {
323  return this->GetRows()-1;
324  }
325  else
326  {
327  return 0;
328  }
329  }
330 
331  template<typename DataType>
333  {
334  if( m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max() )
335  {
336  return m_numberOfSuperDiagonals;
337  }
338  else if( this->GetRows() > 0 )
339  {
340  return this->GetRows()-1;
341  }
342  else
343  {
344  return 0;
345  }
346  }
347 
348  template<typename DataType>
350  {
351  return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
352  }
353 
354  template<typename DataType>
356  {
357  if( this->GetRows() != rhs.GetRows() ||
358  this->GetColumns() != rhs.GetColumns() )
359  {
360  return false;
361  }
362 
363  if( this->GetTransposeFlag() == rhs.GetTransposeFlag() )
364  {
365  return std::equal(begin(), end(), rhs.begin());
366  }
367  else
368  {
369  for(unsigned int i = 0; i < this->GetRows(); ++i)
370  {
371  for(unsigned int j = 0; j < this->GetColumns(); ++j)
372  {
373  if( (*this)(i,j) != rhs(i,j) )
374  {
375  return false;
376  }
377  }
378  }
379  }
380 
381  return true;
382  }
383 
384  template<typename DataType>
386 
387  template<typename DataType>
388  std::tuple<unsigned int, unsigned int>
389  NekMatrix<DataType, StandardMatrixTag>::Advance(unsigned int curRow, unsigned int curColumn) const
390  {
391  return Advance(curRow, curColumn, this->GetTransposeFlag());
392  }
393 
394  template<typename DataType>
395  std::tuple<unsigned int, unsigned int>
396  NekMatrix<DataType, StandardMatrixTag>::Advance(unsigned int curRow, unsigned int curColumn, char transpose) const
397  {
398  unsigned int numRows = this->GetTransposedRows(transpose);
399  unsigned int numColumns = this->GetTransposedColumns(transpose);
400 
401  switch(this->GetStorageType())
402  {
403  case eFULL:
405  numRows, numColumns, curRow, curColumn);
406  break;
407  case eDIAGONAL:
409  numRows, numColumns, curRow, curColumn);
410  break;
411  case eUPPER_TRIANGULAR:
413  numRows, numColumns, curRow, curColumn);
414  break;
415 
416  case eLOWER_TRIANGULAR:
418  numRows, numColumns, curRow, curColumn);
419  break;
420 
421  case eSYMMETRIC:
424  numRows, numColumns, curRow, curColumn);
425  break;
426  case eBANDED:
428  numRows, numColumns, curRow, curColumn);
429  break;
430  case eSYMMETRIC_BANDED:
432  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
433  break;
435  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
436  break;
438  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
439  break;
440 
441  default:
442  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
443  }
444  return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
445  }
446 
447  template<typename DataType>
449  {
451  }
452 
453  template<typename DataType>
454  std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> > NekMatrix<DataType, StandardMatrixTag>::CreateWrapper(const std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> >& rhs)
455  {
456  return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> >(new NekMatrix<DataType, StandardMatrixTag>(*rhs, eWrapper));
457  }
458 
459  template<typename DataType>
461  BaseType(rhs),
462  m_data(),
463  m_wrapperType(wrapperType),
464  m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
465  m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
466  {
467  PerformCopyConstruction(rhs);
468  }
469 
470 
471  template<typename DataType>
473 
474  template<typename DataType>
476  {
477  if( m_wrapperType == eCopy )
478  {
479  unsigned int requiredStorageSize = GetRequiredStorageSize();
480  if( m_data.num_elements() > requiredStorageSize )
481  {
482  Array<OneD, DataType> newArray(requiredStorageSize);
483  CopyArrayN(m_data, newArray, requiredStorageSize);
484  m_data = newArray;
485  }
486  }
487  else if( m_wrapperType == eWrapper )
488  {
489  ASSERTL0(true, "Can't call RemoveExcessCapacity on a wrapped matrix.");
490  }
491  }
492 
493  template<typename DataType>
495  {
496  if( m_wrapperType == eCopy )
497  {
498  if( m_data.num_elements() < requiredStorageSize )
499  {
500  Array<OneD, DataType> newData(requiredStorageSize);
501  std::copy(m_data.data(), m_data.data() + m_data.num_elements(), newData.data());
502  m_data = newData;
503  }
504  }
505  else if( m_wrapperType == eWrapper )
506  {
507  // If the current matrix is wrapped, then just copy over the top,
508  // but the sizes of the two matrices must be the same.
509  ASSERTL0(m_data.num_elements() >= requiredStorageSize, "Wrapped NekMatrices must have the same dimension in operator=");
510  }
511  }
512 
513  template<typename DataType>
515  {
516  unsigned int requiredStorageSize = GetRequiredStorageSize();
517  ResizeDataArrayIfNeeded(requiredStorageSize);
518  }
519 
520  template<typename DataType>
522  {
523  if( m_wrapperType == eWrapper )
524  {
525  m_data = rhs.m_data;
526  }
527  else
528  {
529  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
530  CopyArrayN(rhs.m_data, m_data, m_data.num_elements());
531  }
532  }
533 
534  template<typename DataType>
535  typename boost::call_traits<DataType>::value_type NekMatrix<DataType, StandardMatrixTag>::v_GetValue(unsigned int row, unsigned int column) const
536  {
538  }
539 
540  template<typename DataType>
542  {
544  }
545 
546  template<typename DataType>
547  void NekMatrix<DataType, StandardMatrixTag>::v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d)
548  {
550  }
551 
552 
553 
554  template<typename DataType>
555  void NekMatrix<DataType, StandardMatrixTag>::SetSize(unsigned int rows, unsigned int cols)
556  {
557  this->Resize(rows, cols);
558 
559  // Some places in Nektar++ access the matrix data array and
560  // use num_elements() to see how big it is. When using
561  // expression templates, the data array's capacity is often larger
562  // than the actual number of elements, so this statement is
563  // required to report the correct number of elements.
564  this->GetData().ChangeSize(this->GetRequiredStorageSize());
565  ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().num_elements(), "Can't resize matrices if there is not enough capacity.");
566  }
567 
568 
569  template<typename DataType>
571  {
572  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
573  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
574  std::string(" rows"));
575  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
576  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
577  std::string(" columns"));
578 
579  return (*this)(row, column, this->GetTransposeFlag());
580  }
581 
582  template<typename DataType>
583  typename NekMatrix<DataType, StandardMatrixTag>::Proxy NekMatrix<DataType, StandardMatrixTag>::operator()(unsigned int row, unsigned int column, char transpose)
584  {
585  unsigned int index = this->CalculateIndex(row, column, transpose);
586  if( index != std::numeric_limits<unsigned int>::max() )
587  {
588  return Proxy(this->GetData()[index]);
589  }
590  else
591  {
592  return Proxy();
593  }
594 
595  }
596 
597  template<typename DataType>
598  void NekMatrix<DataType, StandardMatrixTag>::SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d)
599  {
600  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
601  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
602  std::string(" rows"));
603  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
604  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
605  std::string(" columns"));
606  SetValue(row, column, d, this->GetTransposeFlag());
607  }
608 
609  template<typename DataType>
610  void NekMatrix<DataType, StandardMatrixTag>::SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d, char transpose)
611  {
612  unsigned int index = this->CalculateIndex(row, column, transpose);
613  if( index != std::numeric_limits<unsigned int>::max() )
614  {
615  this->GetData()[index] = d;
616  }
617  else
618  {
619  NEKERROR(ErrorUtil::efatal, "Can't assign values into zeroed elements of a special array.");
620  }
621  }
622 
623  template<typename DataType>
625  {
626  return this->GetData();
627  }
628 
629  template<typename DataType>
631  {
632  return this->GetData().data();
633  }
634 
635  template<typename DataType>
637  {
638  return begin(this->GetTransposeFlag());
639  }
640 
641  template<typename DataType>
643  {
644  if( transpose == 'N' )
645  {
646  return iterator(this->GetData().data(), this->GetData().data() + this->GetData().num_elements());
647  }
648  else
649  {
650  return iterator(this, transpose);
651  }
652  }
653 
654  template<typename DataType>
656  {
657  return end(this->GetTransposeFlag());
658  }
659 
660  template<typename DataType>
662  {
663  if( transpose == 'N' )
664  {
665  return iterator(this->GetData().data(), this->GetData().data() + this->GetData().num_elements(), true);
666  }
667  else
668  {
669  return iterator(this, transpose, true);
670  }
671  }
672 
673  template<typename DataType>
675  {
676  NekDouble returnval;
677  int nvals = this->GetColumns();
678  Array<OneD, NekDouble> EigValReal(nvals);
679  Array<OneD, NekDouble> EigValImag(nvals);
680 
681  EigenSolve(EigValReal,EigValImag);
682 
683  Vmath::Vmul(nvals,EigValReal,1,EigValReal,1,EigValReal,1);
684  Vmath::Vmul(nvals,EigValImag,1,EigValImag,1,EigValImag,1);
685  Vmath::Vadd(nvals,EigValReal,1,EigValImag,1,EigValReal,1);
686 
687  returnval = sqrt(Vmath::Vmax(nvals,EigValReal,1)/Vmath::Vmin(nvals,EigValReal,1));
688 
689  return returnval;
690  }
691 
692  template<typename DataType>
694  Array<OneD, NekDouble> &EigValImag,
695  Array<OneD, NekDouble> &EigVecs)
696  {
697  ASSERTL0(this->GetRows()==this->GetColumns(), "Only square matrices can be called");
698 
699  switch(this->GetType())
700  {
701  case eFULL:
702  FullMatrixFuncs::EigenSolve(this->GetRows(),
703  this->GetData(), EigValReal,
704  EigValImag, EigVecs);
705  break;
706  case eDIAGONAL:
707  Vmath::Vcopy(this->GetRows(),&(this->GetData())[0],1, &EigValReal[0],1);
708  Vmath::Zero(this->GetRows(),&EigValImag[0],1);
709  break;
710  case eUPPER_TRIANGULAR:
711  case eLOWER_TRIANGULAR:
712  case eSYMMETRIC:
713  case eBANDED:
714  case eSYMMETRIC_BANDED:
717  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
718  break;
719 
720  default:
721  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
722  }
723  }
724 
725  template<typename DataType>
727  {
728  ASSERTL0(this->GetRows()==this->GetColumns(), "Only square matrices can be inverted.");
729  ASSERTL0(this->GetTransposeFlag()=='N', "Only untransposed matrices may be inverted.");
730 
731  switch(this->GetType())
732  {
733  case eFULL:
734  FullMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
735  this->GetData(), this->GetTransposeFlag());
736  break;
737  case eDIAGONAL:
738  DiagonalMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
739  this->GetData());
740  break;
741  case eSYMMETRIC:
742  SymmetricMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
743  this->GetData());
744  break;
745  case eUPPER_TRIANGULAR:
746  case eLOWER_TRIANGULAR:
747  case eBANDED:
748  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
749  break;
750  case eSYMMETRIC_BANDED:
751  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
752  break;
754  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
755  break;
757  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
758  break;
759 
760  default:
761  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
762  }
763  }
764 
765  template<typename DataType>
767  {
768  if( m_tempSpace.capacity() == 0 )
769  {
770  m_tempSpace = Array<OneD, DataType>(this->GetData().capacity());
771  }
772  return m_tempSpace;
773  }
774 
775  template<typename DataType>
777  {
778  std::swap(m_tempSpace, this->GetData());
779  }
780 
781  template<typename DataType>
783  {
785  NegateInPlace(result);
786  return result;
787  }
788 
789  template<typename DataType>
791  {
792  for(unsigned int i = 0; i < this->GetPtr().num_elements(); ++i)
793  {
794  this->GetPtr()[i] *= s;
795  }
796  return *this;
797  }
798 
799 
800  template<typename DataType>
803  {
804  NekMatrix<DataType, StandardMatrixTag> result(rhs.GetRows(), rhs.GetColumns(),
805  rhs.GetPtr(), eWrapper, rhs.GetType(), rhs.GetNumberOfSubDiagonals(),
806  rhs.GetNumberOfSuperDiagonals());
807  result.Transpose();
808  return result;
809  }
810 
812 
814 
815  template<typename DataType>
817  {
818  for(unsigned int i = 0; i < m.GetRows(); ++i)
819  {
820  for(unsigned int j = 0; j < m.GetColumns(); ++j)
821  {
822  m(i,j) *= -1.0;
823  }
824  }
825  }
826 
828 
829 }
830 
831 
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:216
#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:274
#define LIB_UTILITIES_EXPORT
bool operator==(const VertexSharedPtr &v1, const VertexSharedPtr &v2)
Define comparison operator for the vertex struct.
Definition: VtkToFld.cpp:55
1D Array of constant elements with garbage collection and bounds checking.
Definition: SharedArray.hpp:58
size_t num_elements() const
Returns the array's size.
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:119
unsigned int GetRows() const
Definition: MatrixBase.cpp:58
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
Definition: MatrixBase.cpp:175
unsigned int GetColumns() const
Definition: MatrixBase.cpp:77
Matrix< DataType > & operator=(const Matrix< DataType > &rhs)
Definition: MatrixBase.cpp:305
iterator_impl< const DataType, const ThisType > const_iterator
iterator_impl< DataType, ThisType > iterator
def copy(self)
Definition: pycml.py:2663
StandardMatrixTag boost::call_traits< LhsDataType >::const_reference rhs
@ eVECTOR_WRAPPER
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:959
@ eLOWER_TRIANGULAR_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC_BANDED
@ ePOSITIVE_DEFINITE_SYMMETRIC
@ eUPPER_TRIANGULAR_BANDED
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
void CopyArrayN(const Array< OneD, ConstDataType > &source, Array< OneD, DataType > &dest, unsigned int n)
double NekDouble
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:186
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:874
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:302
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:376
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:782
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1064
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)
Definition: MatrixFuncs.cpp:93
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:248
static void EigenSolve(unsigned int n, const Array< OneD, const double > &A, Array< OneD, NekDouble > &EigValReal, Array< OneD, NekDouble > &EigValImag, Array< OneD, NekDouble > &EigVecs=NullNekDouble1DArray)
Definition: MatrixFuncs.h:125
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:84
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:198
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)