MCPcopy Create free account
hub / github.com/NGSolve/ngsolve / InverseMatrix

Method InverseMatrix

parallel/parallel_matrices.cpp:636–690  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

634
635
636 shared_ptr<BaseMatrix> ParallelMatrix::InverseMatrix (shared_ptr<BitArray> subset) const
637 {
638 if (invcreator)
639 return invcreator(const_pointer_cast<ParallelMatrix>
640 (dynamic_pointer_cast<const ParallelMatrix>(this->shared_from_this())), subset, nullptr);
641
642
643 if (auto diagmat = dynamic_pointer_cast<DiagonalMatrix<double>>(mat))
644 {
645 auto locinv = make_shared<DiagonalMatrix<double>>(diagmat->Height());
646 auto vec = diagmat->AsVector().FV<double>();
647 auto invvec = locinv->AsVector().FV<double>();
648
649 invvec = vec;
650 ParallelVFlatVector<double> parinvvec (invvec.Size(), invvec.Data(),
651 this->col_paralleldofs, DISTRIBUTED);
652 parinvvec.Cumulate();
653 if (subset)
654 {
655 for (size_t i : Range(diagmat->Height()))
656 if (subset->Test(i))
657 invvec(i) = 1.0/invvec(i);
658 else
659 invvec(i) = 0;
660 }
661 else
662 for (size_t i : Range(diagmat->Height()))
663 invvec(i) = 1.0/invvec(i);
664
665 return make_shared<ParallelMatrix> (locinv,
666 this->col_paralleldofs, this->row_paralleldofs,
667 D2D);
668 }
669
670
671 shared_ptr<BaseMatrix> inv;
672
673 Iterate<MAX_SYS_DIM> ( [&](auto i) -> void {
674 constexpr int N = 1+i.value;
675 if (inv) return;
676 if constexpr(N == 1) {
677 inv = InverseMatrixTM<double> (subset); if (inv) return;
678 inv = InverseMatrixTM<Complex> (subset); if (inv) return;
679 }
680 else {
681 inv = InverseMatrixTM<Mat<N> > (subset); if (inv) return;
682 inv = InverseMatrixTM<Mat<N,N,Complex> > (subset); if (inv) return;
683 }
684 });
685
686 if (inv) return inv;
687
688 throw Exception ("ParallelMatrix::Inverse(BitArray) not available, typeid(mat) = "
689 + ToString (typeid(mat).name()));
690 }
691
692
693

Callers 5

UpdateMethod · 0.45
UpdateMethod · 0.45
UpdateMethod · 0.45
MasterInverseMethod · 0.45

Calls 9

ToStringFunction · 0.85
FV<double>Method · 0.80
CumulateMethod · 0.80
RangeFunction · 0.50
shared_from_thisMethod · 0.45
HeightMethod · 0.45
AsVectorMethod · 0.45
SizeMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected