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
37namespace Nektar
38{
39
40template <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
50template <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
63template <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
79template <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
93template <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
109template <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
122template <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 {
133 m_data = Array<OneD, DataType>(d);
134 }
135 else
136 {
137 m_data = Array<OneD, DataType>(GetRequiredStorageSize());
138 CopyArrayN(d, m_data, m_data.size());
139 }
140}
141
142template <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
152template <typename DataType>
155{
156 if (this == &rhs)
157 {
158 return *this;
159 }
160
162 m_numberOfSubDiagonals = rhs.m_numberOfSubDiagonals;
163 m_numberOfSuperDiagonals = rhs.m_numberOfSuperDiagonals;
164
165 ResizeDataArrayIfNeeded();
166
167 unsigned int requiredStorageSize = GetRequiredStorageSize();
168 std::copy(rhs.m_data.data(), rhs.m_data.data() + requiredStorageSize,
169 m_data.data());
170
171 return *this;
172}
173
174/// Fill matrix with scalar
175template <typename DataType>
177 DataType, StandardMatrixTag>::operator=(const DataType &rhs)
178{
179 unsigned int requiredStorageSize = GetRequiredStorageSize();
180
181 DataType *lhs_array = m_data.data();
182
183 Vmath::Fill(requiredStorageSize, rhs, lhs_array, 1);
184
185 return *this;
186}
187
188template <typename DataType>
190 DataType, StandardMatrixTag>::operator()(unsigned int row,
191 unsigned int column) const
192{
193 ASSERTL2(row < this->GetRows(),
194 std::string("Row ") + std::to_string(row) +
195 std::string(" requested in a matrix with a maximum of ") +
196 std::to_string(this->GetRows()) + std::string(" rows"));
197 ASSERTL2(column < this->GetColumns(),
198 std::string("Column ") + std::to_string(column) +
199 std::string(" requested in a matrix with a maximum of ") +
200 std::to_string(this->GetColumns()) + std::string(" columns"));
201
202 return this->GetValue(row, column, this->GetTransposeFlag());
203}
204
205template <typename DataType>
207 DataType, StandardMatrixTag>::operator()(unsigned int row,
208 unsigned int column,
209 char transpose) const
210{
211 return this->GetValue(row, column, transpose);
212}
213
214template <typename DataType>
216 const
217{
219 this->GetStorageType(), this->GetRows(), this->GetColumns(),
220 this->GetNumberOfSubDiagonals(), this->GetNumberOfSuperDiagonals());
221}
222
223template <typename DataType>
225 unsigned int row, unsigned int col, const char transpose) const
226{
227 unsigned int numRows = this->GetSize()[0];
228 unsigned int numColumns = this->GetSize()[1];
230 this->GetStorageType(), row, col, numRows, numColumns, transpose,
231 m_numberOfSubDiagonals, m_numberOfSuperDiagonals);
232}
233
234template <typename DataType>
235typename boost::call_traits<DataType>::const_reference NekMatrix<
236 DataType, StandardMatrixTag>::GetValue(unsigned int row,
237 unsigned int column) const
238{
239 ASSERTL2(row < this->GetRows(),
240 std::string("Row ") + std::to_string(row) +
241 std::string(" requested in a matrix with a maximum of ") +
242 std::to_string(this->GetRows()) + std::string(" rows"));
243 ASSERTL2(column < this->GetColumns(),
244 std::string("Column ") + std::to_string(column) +
245 std::string(" requested in a matrix with a maximum of ") +
246 std::to_string(this->GetColumns()) + std::string(" columns"));
247
248 return GetValue(row, column, this->GetTransposeFlag());
249}
250
251template <typename DataType>
253 DataType, StandardMatrixTag>::GetValue(unsigned int row,
254 unsigned int column,
255 char transpose) const
256{
257 static DataType defaultReturnValue;
258 unsigned int index = CalculateIndex(row, column, transpose);
259 if (index != std::numeric_limits<unsigned int>::max())
260 {
261 return m_data[index];
262 }
263 else
264 {
265 return defaultReturnValue;
266 }
267}
268
269template <typename DataType>
271 StandardMatrixTag>::GetPtr() const
272{
273 return m_data;
274}
275
276template <typename DataType>
278{
279 return DataType(1);
280}
281
282template <typename DataType>
284{
285 return m_data.data();
286}
287
288template <typename DataType>
290 DataType, StandardMatrixTag>::begin() const
291{
292 return begin(this->GetTransposeFlag());
293}
294
295template <typename DataType>
297 DataType, StandardMatrixTag>::begin(char transpose) const
298{
299 if (transpose == 'N')
300 {
301 return const_iterator(m_data.data(), m_data.data() + m_data.size());
302 }
303 else
304 {
305 return const_iterator(this, transpose);
306 }
307}
308
309template <typename DataType>
311 DataType, StandardMatrixTag>::end() const
312{
313 return end(this->GetTransposeFlag());
314}
315
316template <typename DataType>
318 DataType, StandardMatrixTag>::end(char transpose) const
319{
320 if (transpose == 'N')
321 {
322 return const_iterator(m_data.data(), m_data.data() + m_data.size(),
323 true);
324 }
325 else
326 {
327 return const_iterator(this, transpose, true);
328 }
329}
330
331template <typename DataType>
333{
334 return m_data.size();
335}
336
337template <typename DataType>
339 const
340{
341 if (m_numberOfSubDiagonals != std::numeric_limits<unsigned int>::max())
342 {
343 return m_numberOfSubDiagonals;
344 }
345 else if (this->GetRows() > 0)
346 {
347 return this->GetRows() - 1;
348 }
349 else
350 {
351 return 0;
352 }
353}
354
355template <typename DataType>
357 const
358{
359 if (m_numberOfSuperDiagonals != std::numeric_limits<unsigned int>::max())
360 {
361 return m_numberOfSuperDiagonals;
362 }
363 else if (this->GetRows() > 0)
364 {
365 return this->GetRows() - 1;
366 }
367 else
368 {
369 return 0;
370 }
371}
372
373template <typename DataType>
375 const
376{
377 return GetNumberOfSubDiagonals() + GetNumberOfSuperDiagonals() + 1;
378}
379
380template <typename DataType>
383{
384 if (this->GetRows() != rhs.GetRows() ||
385 this->GetColumns() != rhs.GetColumns())
386 {
387 return false;
388 }
389
390 if (this->GetTransposeFlag() == rhs.GetTransposeFlag())
391 {
392 return std::equal(begin(), end(), rhs.begin());
393 }
394 else
395 {
396 for (unsigned int i = 0; i < this->GetRows(); ++i)
397 {
398 for (unsigned int j = 0; j < this->GetColumns(); ++j)
399 {
400 if ((*this)(i, j) != rhs(i, j))
401 {
402 return false;
403 }
404 }
405 }
406 }
407
408 return true;
409}
410
411template <typename DataType>
413{
414 return m_wrapperType;
415}
416
417template <typename DataType>
418std::tuple<unsigned int, unsigned int> NekMatrix<
419 DataType, StandardMatrixTag>::Advance(unsigned int curRow,
420 unsigned int curColumn) const
421{
422 return Advance(curRow, curColumn, this->GetTransposeFlag());
423}
424
425template <typename DataType>
426std::tuple<unsigned int, unsigned int> NekMatrix<
427 DataType, StandardMatrixTag>::Advance(unsigned int curRow,
428 unsigned int curColumn,
429 char transpose) const
430{
431 unsigned int numRows = this->GetTransposedRows(transpose);
432 unsigned int numColumns = this->GetTransposedColumns(transpose);
433
434 switch (this->GetStorageType())
435 {
436 case eFULL:
437 return FullMatrixFuncs::Advance(numRows, numColumns, curRow,
438 curColumn);
439 break;
440 case eDIAGONAL:
441 return DiagonalMatrixFuncs::Advance(numRows, numColumns, curRow,
442 curColumn);
443 break;
445 return UpperTriangularMatrixFuncs::Advance(numRows, numColumns,
446 curRow, curColumn);
447 break;
448
450 return LowerTriangularMatrixFuncs::Advance(numRows, numColumns,
451 curRow, curColumn);
452 break;
453
454 case eSYMMETRIC:
456 return SymmetricMatrixFuncs::Advance(numRows, numColumns, curRow,
457 curColumn);
458 break;
459 case eBANDED:
460 return BandedMatrixFuncs::Advance(numRows, numColumns, curRow,
461 curColumn);
462 break;
465 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
466 break;
468 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
469 break;
471 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
472 break;
473
474 default:
475 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
476 }
477 return std::tuple<unsigned int, unsigned int>(curRow, curColumn);
478}
479
480template <typename DataType>
483{
485}
486
487template <typename DataType>
488std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>> NekMatrix<
489 DataType, StandardMatrixTag>::
490 CreateWrapper(
491 const std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>> &rhs)
492{
493 return std::shared_ptr<NekMatrix<DataType, StandardMatrixTag>>(
495}
496
497template <typename DataType>
500 PointerWrapper wrapperType)
501 : BaseType(rhs), m_data(), m_wrapperType(wrapperType),
502 m_numberOfSuperDiagonals(rhs.m_numberOfSuperDiagonals),
503 m_numberOfSubDiagonals(rhs.m_numberOfSubDiagonals)
504{
505 PerformCopyConstruction(rhs);
506}
507
508template <typename DataType>
510{
511 return m_data;
512}
513
514template <typename DataType>
516{
517 if (m_wrapperType == eCopy)
518 {
519 unsigned int requiredStorageSize = GetRequiredStorageSize();
520 if (m_data.size() > requiredStorageSize)
521 {
522 Array<OneD, DataType> newArray(requiredStorageSize);
523 CopyArrayN(m_data, newArray, requiredStorageSize);
524 m_data = newArray;
525 }
526 }
527 else if (m_wrapperType == eWrapper)
528 {
529 ASSERTL0(true, "Can't call RemoveExcessCapacity on a wrapped matrix.");
530 }
531}
532
533template <typename DataType>
535 unsigned int requiredStorageSize)
536{
537 if (m_wrapperType == eCopy)
538 {
539 if (m_data.size() < requiredStorageSize)
540 {
541 Array<OneD, DataType> newData(requiredStorageSize);
542 std::copy(m_data.data(), m_data.data() + m_data.size(),
543 newData.data());
544 m_data = newData;
545 }
546 }
547 else if (m_wrapperType == eWrapper)
548 {
549 // If the current matrix is wrapped, then just copy over the top,
550 // but the sizes of the two matrices must be the same.
551 ASSERTL0(
552 m_data.size() >= requiredStorageSize,
553 "Wrapped NekMatrices must have the same dimension in operator=");
554 }
555}
556
557template <typename DataType>
559{
560 unsigned int requiredStorageSize = GetRequiredStorageSize();
561 ResizeDataArrayIfNeeded(requiredStorageSize);
562}
563
564template <typename DataType>
566 const ThisType &rhs)
567{
568 if (m_wrapperType == eWrapper)
569 {
570 m_data = rhs.m_data;
571 }
572 else
573 {
574 m_data = Array<OneD, DataType>(GetRequiredStorageSize());
575 CopyArrayN(rhs.m_data, m_data, m_data.size());
576 }
577}
578
579template <typename DataType>
580typename boost::call_traits<DataType>::value_type NekMatrix<
581 DataType, StandardMatrixTag>::v_GetValue(unsigned int row,
582 unsigned int column) const
583{
585}
586
587template <typename DataType>
589{
591}
592
593template <typename DataType>
595 unsigned int row, unsigned int column,
596 typename boost::call_traits<DataType>::const_reference d)
597{
599}
600
601template <typename DataType>
603 unsigned int cols)
604{
605 this->Resize(rows, cols);
606
607 // Some places in Nektar++ access the matrix data array and
608 // use size() to see how big it is. When using
609 // expression templates, the data array's capacity is often larger
610 // than the actual number of elements, so this statement is
611 // required to report the correct number of elements.
612 this->GetData().ChangeSize(this->GetRequiredStorageSize());
613 ASSERTL0(this->GetRequiredStorageSize() <= this->GetData().size(),
614 "Can't resize matrices if there is not enough capacity.");
615}
616
617template <typename DataType>
619 DataType, StandardMatrixTag>::operator()(unsigned int row,
620 unsigned int column)
621{
622 ASSERTL2(row < this->GetRows(),
623 std::string("Row ") + std::to_string(row) +
624 std::string(" requested in a matrix with a maximum of ") +
625 std::to_string(this->GetRows()) + std::string(" rows"));
626 ASSERTL2(column < this->GetColumns(),
627 std::string("Column ") + std::to_string(column) +
628 std::string(" requested in a matrix with a maximum of ") +
629 std::to_string(this->GetColumns()) + std::string(" columns"));
630
631 return (*this)(row, column, this->GetTransposeFlag());
632}
633
634template <typename DataType>
636 DataType, StandardMatrixTag>::operator()(unsigned int row,
637 unsigned int column,
638 char transpose)
639{
640 unsigned int index = this->CalculateIndex(row, column, transpose);
641 if (index != std::numeric_limits<unsigned int>::max())
642 {
643 return Proxy(this->GetData()[index]);
644 }
645 else
646 {
647 return Proxy();
648 }
649}
650
651template <typename DataType>
653 unsigned int row, unsigned int column,
654 typename boost::call_traits<DataType>::const_reference d)
655{
656 ASSERTL2(row < this->GetRows(),
657 std::string("Row ") + std::to_string(row) +
658 std::string(" requested in a matrix with a maximum of ") +
659 std::to_string(this->GetRows()) + std::string(" rows"));
660 ASSERTL2(column < this->GetColumns(),
661 std::string("Column ") + std::to_string(column) +
662 std::string(" requested in a matrix with a maximum of ") +
663 std::to_string(this->GetColumns()) + std::string(" columns"));
664 SetValue(row, column, d, this->GetTransposeFlag());
665}
666
667template <typename DataType>
669 unsigned int row, unsigned int column,
670 typename boost::call_traits<DataType>::const_reference d, char transpose)
671{
672 unsigned int index = this->CalculateIndex(row, column, transpose);
673 if (index != std::numeric_limits<unsigned int>::max())
674 {
675 this->GetData()[index] = d;
676 }
677 else
678 {
679 NEKERROR(
681 "Can't assign values into zeroed elements of a special array.");
682 }
683}
684
685template <typename DataType>
687{
688 return this->GetData();
689}
690
691template <typename DataType>
693{
694 return this->GetData().data();
695}
696
697template <typename DataType>
699 DataType, StandardMatrixTag>::begin()
700{
701 return begin(this->GetTransposeFlag());
702}
703
704template <typename DataType>
706 DataType, StandardMatrixTag>::begin(char transpose)
707{
708 if (transpose == 'N')
709 {
710 return iterator(this->GetData().data(),
711 this->GetData().data() + this->GetData().size());
712 }
713 else
714 {
715 return iterator(this, transpose);
716 }
717}
718
719template <typename DataType>
721 DataType, StandardMatrixTag>::end()
722{
723 return end(this->GetTransposeFlag());
724}
725
726template <typename DataType>
728 DataType, StandardMatrixTag>::end(char transpose)
729{
730 if (transpose == 'N')
731 {
732 return iterator(this->GetData().data(),
733 this->GetData().data() + this->GetData().size(), true);
734 }
735 else
736 {
737 return iterator(this, transpose, true);
738 }
739}
740
741template <typename DataType>
743 void)
744{
745 DataType returnval;
746 int nvals = this->GetColumns();
747 Array<OneD, DataType> EigValReal(nvals);
748 Array<OneD, DataType> EigValImag(nvals);
750
751 EigenSolve(EigValReal, EigValImag, Evecs);
752
753 Vmath::Vmul(nvals, EigValReal, 1, EigValReal, 1, EigValReal, 1);
754 Vmath::Vmul(nvals, EigValImag, 1, EigValImag, 1, EigValImag, 1);
755 Vmath::Vadd(nvals, EigValReal, 1, EigValImag, 1, EigValReal, 1);
756
757 returnval = sqrt(Vmath::Vmax(nvals, EigValReal, 1) /
758 Vmath::Vmin(nvals, EigValReal, 1));
759
760 return returnval;
761}
762
763template <typename DataType>
765 Array<OneD, DataType> &EigValReal, Array<OneD, DataType> &EigValImag,
766 Array<OneD, DataType> &EigVecs)
767{
768 ASSERTL0(this->GetRows() == this->GetColumns(),
769 "Only square matrices can be called");
770
771 switch (this->GetType())
772 {
773 case eFULL:
774 FullMatrixFuncs::EigenSolve(this->GetRows(), this->GetData(),
775 EigValReal, EigValImag, EigVecs);
776 break;
777 case eDIAGONAL:
778 Vmath::Vcopy(this->GetRows(), &(this->GetData())[0], 1,
779 &EigValReal[0], 1);
780 Vmath::Zero(this->GetRows(), &EigValImag[0], 1);
781 break;
784 case eSYMMETRIC:
785 case eBANDED:
789 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
790 break;
791
792 default:
793 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
794 }
795}
796
797template <typename DataType>
799{
800 ASSERTL0(this->GetRows() == this->GetColumns(),
801 "Only square matrices can be inverted.");
802 ASSERTL0(this->GetTransposeFlag() == 'N',
803 "Only untransposed matrices may be inverted.");
804
805 switch (this->GetType())
806 {
807 case eFULL:
808 FullMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
809 this->GetData(), this->GetTransposeFlag());
810 break;
811 case eDIAGONAL:
812 DiagonalMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
813 this->GetData());
814 break;
815 case eSYMMETRIC:
816 SymmetricMatrixFuncs::Invert(this->GetRows(), this->GetColumns(),
817 this->GetData());
818 break;
821 case eBANDED:
822 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
823 break;
825 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
826 break;
828 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
829 break;
831 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
832 break;
833
834 default:
835 NEKERROR(ErrorUtil::efatal, "Unhandled matrix type");
836 }
837}
838
839template <typename DataType>
841{
842 if (m_tempSpace.capacity() == 0)
843 {
844 m_tempSpace = Array<OneD, DataType>(this->GetData().capacity());
845 }
846 return m_tempSpace;
847}
848
849template <typename DataType>
851{
852 std::swap(m_tempSpace, this->GetData());
853}
854
855template <typename DataType>
857 DataType, StandardMatrixTag>::operator-() const
858{
860 NegateInPlace(result);
861 return result;
862}
863
864template <typename DataType>
866 DataType, StandardMatrixTag>::operator*=(const DataType &s)
867{
868 for (unsigned int i = 0; i < this->GetPtr().size(); ++i)
869 {
870 this->GetPtr()[i] *= s;
871 }
872 return *this;
873}
874
875template <typename DataType>
878{
880 rhs.GetRows(), rhs.GetColumns(), rhs.GetPtr(), eWrapper, rhs.GetType(),
882 result.Transpose();
883 return result;
884}
885
888
890
893
895
896template <typename DataType>
898{
899 for (unsigned int i = 0; i < m.GetRows(); ++i)
900 {
901 for (unsigned int j = 0; j < m.GetColumns(); ++j)
902 {
903 m(i, j) *= -1.0;
904 }
905 }
906}
907
912
913} // namespace Nektar
#define ASSERTL0(condition, msg)
Definition: ErrorUtil.hpp:208
#define NEKERROR(type, msg)
Assert Level 0 – Fundamental assert which is used whether in FULLDEBUG, DEBUG or OPT compilation mode...
Definition: ErrorUtil.hpp:202
#define ASSERTL2(condition, msg)
Assert Level 2 – Debugging which is used FULLDEBUG compilation mode. This level assert is designed to...
Definition: ErrorUtil.hpp:265
#define LIB_UTILITIES_EXPORT
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.
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:110
unsigned int GetRows() const
Definition: MatrixBase.cpp:61
static unsigned int GetRequiredStorageSize(MatrixStorage type, unsigned int rows, unsigned int columns, unsigned int subDiags=0, unsigned int superDiags=0)
Definition: MatrixBase.cpp:168
char GetTransposeFlag() const
Definition: MatrixBase.cpp:104
unsigned int GetColumns() const
Definition: MatrixBase.cpp:73
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
std::vector< double > d(NPUPPER *NPUPPER)
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)
NekMatrix< InnerMatrixType, BlockMatrixTag > Transpose(NekMatrix< InnerMatrixType, BlockMatrixTag > &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.hpp:72
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.hpp:725
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.hpp:180
void Zero(int n, T *x, const int incx)
Zero vector.
Definition: Vmath.hpp:273
void Fill(int n, const T alpha, T *x, const int incx)
Fill a vector with a constant value.
Definition: Vmath.hpp:54
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.hpp:644
void Vcopy(int n, const T *x, const int incx, T *y, const int incy)
Definition: Vmath.hpp:825
STL namespace.
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)
Definition: MatrixFuncs.cpp:97
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)