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.size());
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.size());
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  /// Fill matrix with scalar
187  template<typename DataType>
190  {
191  unsigned int requiredStorageSize = GetRequiredStorageSize();
192 
193  DataType* lhs_array = m_data.data();
194 
195  Vmath::Fill(requiredStorageSize,rhs,lhs_array,1);
196 
197  return *this;
198  }
199 
200  template<typename DataType>
202  {
203  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
204  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
205  std::string(" rows"));
206  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
207  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
208  std::string(" columns"));
209 
210  return this->GetValue(row, column, this->GetTransposeFlag());
211  }
212 
213  template<typename DataType>
214  typename NekMatrix<DataType, StandardMatrixTag>::ConstGetValueType NekMatrix<DataType, StandardMatrixTag>::operator()(unsigned int row, unsigned int column, char transpose) const
215  {
216  return this->GetValue(row, column, transpose);
217  }
218 
219  template<typename DataType>
221  {
222  return Matrix<DataType>::GetRequiredStorageSize(this->GetStorageType(),
223  this->GetRows(), this->GetColumns(),
224  this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
225  }
226 
227  template<typename DataType>
228  unsigned int NekMatrix<DataType, StandardMatrixTag>::CalculateIndex(unsigned int row, unsigned int col, const char transpose) const
229  {
230  unsigned int numRows = this->GetSize()[0];
231  unsigned int numColumns = this->GetSize()[1];
232  return Matrix<DataType>::CalculateIndex(this->GetStorageType(),
233  row, col, numRows, numColumns, transpose,
234  m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
235  }
236 
237  template<typename DataType>
238  typename boost::call_traits<DataType>::const_reference NekMatrix<DataType, StandardMatrixTag>::GetValue(unsigned int row, unsigned int column) const
239  {
240  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
241  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
242  std::string(" rows"));
243  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
244  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
245  std::string(" columns"));
246 
247  return GetValue(row, column, this->GetTransposeFlag());
248  }
249 
250  template<typename DataType>
251  typename NekMatrix<DataType, StandardMatrixTag>::ConstGetValueType NekMatrix<DataType, StandardMatrixTag>::GetValue(unsigned int row, unsigned int column, char transpose) const
252  {
253  static DataType defaultReturnValue;
254  unsigned int index = CalculateIndex(row, column, transpose);
255  if( index != std::numeric_limits<unsigned int>::max() )
256  {
257  return m_data[index];
258  }
259  else
260  {
261  return defaultReturnValue;
262  }
263  }
264 
265  template<typename DataType>
267  {
268  return m_data;
269  }
270 
271  template<typename DataType>
273  {
274  return DataType(1);
275  }
276 
277  template<typename DataType>
279  {
280  return m_data.data();
281  }
282 
283  template<typename DataType>
285  {
286  return begin(this->GetTransposeFlag());
287  }
288 
289  template<typename DataType>
291  {
292  if( transpose == 'N' )
293  {
294  return const_iterator(m_data.data(), m_data.data() + m_data.size());
295  }
296  else
297  {
298  return const_iterator(this, transpose);
299  }
300  }
301 
302  template<typename DataType>
304  {
305  return end(this->GetTransposeFlag());
306  }
307 
308  template<typename DataType>
310  {
311  if( transpose == 'N' )
312  {
313  return const_iterator(m_data.data(), m_data.data() + m_data.size(), true);
314  }
315  else
316  {
317  return const_iterator(this, transpose, true);
318  }
319  }
320 
321  template<typename DataType>
323  {
324  return m_data.size();
325  }
326 
327  template<typename DataType>
329  {
330  if( m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max() )
331  {
332  return m_numberOfSubDiagonals;
333  }
334  else if( this->GetRows() > 0 )
335  {
336  return this->GetRows()-1;
337  }
338  else
339  {
340  return 0;
341  }
342  }
343 
344  template<typename DataType>
346  {
347  if( m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max() )
348  {
349  return m_numberOfSuperDiagonals;
350  }
351  else if( this->GetRows() > 0 )
352  {
353  return this->GetRows()-1;
354  }
355  else
356  {
357  return 0;
358  }
359  }
360 
361  template<typename DataType>
363  {
364  return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
365  }
366 
367  template<typename DataType>
369  {
370  if( this->GetRows() != rhs.GetRows() ||
371  this->GetColumns() != rhs.GetColumns() )
372  {
373  return false;
374  }
375 
376  if( this->GetTransposeFlag() == rhs.GetTransposeFlag() )
377  {
378  return std::equal(begin(), end(), rhs.begin());
379  }
380  else
381  {
382  for(unsigned int i = 0; i < this->GetRows(); ++i)
383  {
384  for(unsigned int j = 0; j < this->GetColumns(); ++j)
385  {
386  if( (*this)(i,j) != rhs(i,j) )
387  {
388  return false;
389  }
390  }
391  }
392  }
393 
394  return true;
395  }
396 
397  template<typename DataType>
399 
400  template<typename DataType>
401  std::tuple<unsigned int, unsigned int>
402  NekMatrix<DataType, StandardMatrixTag>::Advance(unsigned int curRow, unsigned int curColumn) const
403  {
404  return Advance(curRow, curColumn, this->GetTransposeFlag());
405  }
406 
407  template<typename DataType>
408  std::tuple<unsigned int, unsigned int>
409  NekMatrix<DataType, StandardMatrixTag>::Advance(unsigned int curRow, unsigned int curColumn, char transpose) const
410  {
411  unsigned int numRows = this->GetTransposedRows(transpose);
412  unsigned int numColumns = this->GetTransposedColumns(transpose);
413 
414  switch(this->GetStorageType())
415  {
416  case eFULL:
418  numRows, numColumns, curRow, curColumn);
419  break;
420  case eDIAGONAL:
422  numRows, numColumns, curRow, curColumn);
423  break;
424  case eUPPER_TRIANGULAR:
426  numRows, numColumns, curRow, curColumn);
427  break;
428 
429  case eLOWER_TRIANGULAR:
431  numRows, numColumns, curRow, curColumn);
432  break;
433 
434  case eSYMMETRIC:
437  numRows, numColumns, curRow, curColumn);
438  break;
439  case eBANDED:
441  numRows, numColumns, curRow, curColumn);
442  break;
443  case eSYMMETRIC_BANDED:
445  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
446  break;
448  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
449  break;
451  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
452  break;
453 
454  default:
455  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
456  }
457  return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
458  }
459 
460  template<typename DataType>
462  {
464  }
465 
466  template<typename DataType>
467  std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> > NekMatrix<DataType, StandardMatrixTag>::CreateWrapper(const std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> >& rhs)
468  {
469  return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag> >(new NekMatrix<DataType, StandardMatrixTag>(*rhs, eWrapper));
470  }
471 
472  template<typename DataType>
474  BaseType(rhs),
475  m_data(),
476  m_wrapperType(wrapperType),
477  m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
478  m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
479  {
480  PerformCopyConstruction(rhs);
481  }
482 
483 
484  template<typename DataType>
486 
487  template<typename DataType>
489  {
490  if( m_wrapperType == eCopy )
491  {
492  unsigned int requiredStorageSize = GetRequiredStorageSize();
493  if( m_data.size() > requiredStorageSize )
494  {
495  Array<OneD, DataType> newArray(requiredStorageSize);
496  CopyArrayN(m_data, newArray, requiredStorageSize);
497  m_data = newArray;
498  }
499  }
500  else if( m_wrapperType == eWrapper )
501  {
502  ASSERTL0(true, "Can't call RemoveExcessCapacity on a wrapped matrix.");
503  }
504  }
505 
506  template<typename DataType>
508  {
509  if( m_wrapperType == eCopy )
510  {
511  if( m_data.size() < requiredStorageSize )
512  {
513  Array<OneD, DataType> newData(requiredStorageSize);
514  std::copy(m_data.data(), m_data.data() + m_data.size(), newData.data());
515  m_data = newData;
516  }
517  }
518  else if( m_wrapperType == eWrapper )
519  {
520  // If the current matrix is wrapped, then just copy over the top,
521  // but the sizes of the two matrices must be the same.
522  ASSERTL0(m_data.size() >= requiredStorageSize, "Wrapped NekMatrices must have the same dimension in operator=");
523  }
524  }
525 
526  template<typename DataType>
528  {
529  unsigned int requiredStorageSize = GetRequiredStorageSize();
530  ResizeDataArrayIfNeeded(requiredStorageSize);
531  }
532 
533  template<typename DataType>
535  {
536  if( m_wrapperType == eWrapper )
537  {
538  m_data = rhs.m_data;
539  }
540  else
541  {
542  m_data = Array<OneD, DataType>(GetRequiredStorageSize());
543  CopyArrayN(rhs.m_data, m_data, m_data.size());
544  }
545  }
546 
547  template<typename DataType>
548  typename boost::call_traits<DataType>::value_type NekMatrix<DataType, StandardMatrixTag>::v_GetValue(unsigned int row, unsigned int column) const
549  {
551  }
552 
553  template<typename DataType>
555  {
557  }
558 
559  template<typename DataType>
560  void NekMatrix<DataType, StandardMatrixTag>::v_SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d)
561  {
563  }
564 
565 
566 
567  template<typename DataType>
568  void NekMatrix<DataType, StandardMatrixTag>::SetSize(unsigned int rows, unsigned int cols)
569  {
570  this->Resize(rows, cols);
571 
572  // Some places in Nektar++ access the matrix data array and
573  // use size() to see how big it is. When using
574  // expression templates, the data array's capacity is often larger
575  // than the actual number of elements, so this statement is
576  // required to report the correct number of elements.
577  this->GetData().ChangeSize(this->GetRequiredStorageSize());
578  ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(), "Can't resize matrices if there is not enough capacity.");
579  }
580 
581 
582  template<typename DataType>
584  {
585  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
586  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
587  std::string(" rows"));
588  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
589  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
590  std::string(" columns"));
591 
592  return (*this)(row, column, this->GetTransposeFlag());
593  }
594 
595  template<typename DataType>
596  typename NekMatrix<DataType, StandardMatrixTag>::Proxy NekMatrix<DataType, StandardMatrixTag>::operator()(unsigned int row, unsigned int column, char transpose)
597  {
598  unsigned int index = this->CalculateIndex(row, column, transpose);
599  if( index != std::numeric_limits<unsigned int>::max() )
600  {
601  return Proxy(this->GetData()[index]);
602  }
603  else
604  {
605  return Proxy();
606  }
607 
608  }
609 
610  template<typename DataType>
611  void NekMatrix<DataType, StandardMatrixTag>::SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d)
612  {
613  ASSERTL2(row < this->GetRows(), std::string("Row ") + std::to_string(row) +
614  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetRows()) +
615  std::string(" rows"));
616  ASSERTL2(column < this->GetColumns(), std::string("Column ") + std::to_string(column) +
617  std::string(" requested in a matrix with a maximum of ") + std::to_string(this->GetColumns()) +
618  std::string(" columns"));
619  SetValue(row, column, d, this->GetTransposeFlag());
620  }
621 
622  template<typename DataType>
623  void NekMatrix<DataType, StandardMatrixTag>::SetValue(unsigned int row, unsigned int column, typename boost::call_traits<DataType>::const_reference d, char transpose)
624  {
625  unsigned int index = this->CalculateIndex(row, column, transpose);
626  if( index != std::numeric_limits<unsigned int>::max() )
627  {
628  this->GetData()[index] = d;
629  }
630  else
631  {
632  NEKERROR(ErrorUtil::efatal, "Can't assign values into zeroed elements of a special array.");
633  }
634  }
635 
636  template<typename DataType>
638  {
639  return this->GetData();
640  }
641 
642  template<typename DataType>
644  {
645  return this->GetData().data();
646  }
647 
648  template<typename DataType>
650  {
651  return begin(this->GetTransposeFlag());
652  }
653 
654  template<typename DataType>
656  {
657  if( transpose == 'N' )
658  {
659  return iterator(this->GetData().data(), this->GetData().data() + this->GetData().size());
660  }
661  else
662  {
663  return iterator(this, transpose);
664  }
665  }
666 
667  template<typename DataType>
669  {
670  return end(this->GetTransposeFlag());
671  }
672 
673  template<typename DataType>
675  {
676  if( transpose == 'N' )
677  {
678  return iterator(this->GetData().data(), this->GetData().data() + this->GetData().size(), true);
679  }
680  else
681  {
682  return iterator(this, transpose, true);
683  }
684  }
685 
686  template<typename DataType>
688  {
689  DataType returnval;
690  int nvals = this->GetColumns();
691  Array<OneD, DataType> EigValReal(nvals);
692  Array<OneD, DataType> EigValImag(nvals);
693  Array<OneD, DataType> Evecs;
694 
695  EigenSolve(EigValReal,EigValImag,Evecs);
696 
697  Vmath::Vmul(nvals,EigValReal,1,EigValReal,1,EigValReal,1);
698  Vmath::Vmul(nvals,EigValImag,1,EigValImag,1,EigValImag,1);
699  Vmath::Vadd(nvals,EigValReal,1,EigValImag,1,EigValReal,1);
700 
701  returnval = sqrt(Vmath::Vmax(nvals,EigValReal,1)/Vmath::Vmin(nvals,EigValReal,1));
702 
703  return returnval;
704  }
705 
706  template<typename DataType>
708  Array<OneD, DataType> &EigValImag,
709  Array<OneD, DataType> &EigVecs)
710  {
711  ASSERTL0(this->GetRows()==this->GetColumns(), "Only square matrices can be called");
712 
713  switch(this->GetType())
714  {
715  case eFULL:
716  FullMatrixFuncs::EigenSolve(this->GetRows(),
717  this->GetData(), EigValReal,
718  EigValImag, EigVecs);
719  break;
720  case eDIAGONAL:
721  Vmath::Vcopy(this->GetRows(),&(this->GetData())[0],1, &EigValReal[0],1);
722  Vmath::Zero(this->GetRows(),&EigValImag[0],1);
723  break;
724  case eUPPER_TRIANGULAR:
725  case eLOWER_TRIANGULAR:
726  case eSYMMETRIC:
727  case eBANDED:
728  case eSYMMETRIC_BANDED:
731  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
732  break;
733 
734  default:
735  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
736  }
737  }
738 
739  template<typename DataType>
741  {
742  ASSERTL0(this->GetRows()==this->GetColumns(), "Only square matrices can be inverted.");
743  ASSERTL0(this->GetTransposeFlag()=='N', "Only untransposed matrices may be inverted.");
744 
745  switch(this->GetType())
746  {
747  case eFULL:
748  FullMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
749  this->GetData(), this->GetTransposeFlag());
750  break;
751  case eDIAGONAL:
752  DiagonalMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
753  this->GetData());
754  break;
755  case eSYMMETRIC:
756  SymmetricMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
757  this->GetData());
758  break;
759  case eUPPER_TRIANGULAR:
760  case eLOWER_TRIANGULAR:
761  case eBANDED:
762  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
763  break;
764  case eSYMMETRIC_BANDED:
765  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
766  break;
768  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
769  break;
771  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
772  break;
773 
774  default:
775  NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
776  }
777  }
778 
779  template<typename DataType>
781  {
782  if( m_tempSpace.capacity() == 0 )
783  {
784  m_tempSpace = Array<OneD, DataType>(this->GetData().capacity());
785  }
786  return m_tempSpace;
787  }
788 
789  template<typename DataType>
791  {
792  std::swap(m_tempSpace, this->GetData());
793  }
794 
795  template<typename DataType>
797  {
799  NegateInPlace(result);
800  return result;
801  }
802 
803  template<typename DataType>
805  {
806  for(unsigned int i = 0; i < this->GetPtr().size(); ++i)
807  {
808  this->GetPtr()[i] *= s;
809  }
810  return *this;
811  }
812 
813 
814  template<typename DataType>
817  {
819  rhs.GetPtr(), eWrapper, rhs.GetType(), rhs.GetNumberOfSubDiagonals(),
821  result.Transpose();
822  return result;
823  }
824 
826 
828 
830 
832 
833  template<typename DataType>
835  {
836  for(unsigned int i = 0; i < m.GetRows(); ++i)
837  {
838  for(unsigned int j = 0; j < m.GetColumns(); ++j)
839  {
840  m(i,j) *= -1.0;
841  }
842  }
843  }
844 
847 
848 }
849 
850 
#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:59
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: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
char GetTransposeFlag() const
Definition: MatrixBase.cpp:113
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
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:1
@ eVECTOR_WRAPPER
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &rhs)
void NegateInPlace(NekVector< DataType > &v)
Definition: NekVector.cpp:1184
@ 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)
NekMatrix< typename NekMatrix< LhsDataType, LhsMatrixType >::NumberType, StandardMatrixTag > operator-(const NekMatrix< LhsDataType, LhsMatrixType > &lhs, const NekMatrix< RhsDataType, RhsMatrixType > &rhs)
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:192
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:992
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:322
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.cpp:436
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:892
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.cpp:1199
scalarT< T > sqrt(scalarT< T > in)
Definition: scalar.hpp:267
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:269
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:146
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:219
static std::tuple< unsigned int, unsigned int > Advance(const unsigned int totalRows, const unsigned int totalColumns, const unsigned int curRow, const unsigned int curColumn)