28 #include <boost/signals2/signal.hpp> 43 template <
typename VectorType>
49 using Number =
typename VectorType::value_type;
96 solve(Vector<Number> & x,
97 const Vector<Number> &y,
137 boost::signals2::connection
139 const std::function<
void(
const unsigned int i,
140 const unsigned int j,
141 const std::array<Number, 3> &csr)> &slot);
160 std::vector<std::unique_ptr<VectorType>>
columns;
176 boost::signals2::signal<void(
const unsigned int i,
177 const unsigned int j,
178 const std::array<Number, 3> &)>
239 template <
typename VectorType>
246 using Number =
typename VectorType::value_type;
256 virtual ~
QR() =
default;
321 apply_givens_rotation(
const unsigned int i,
const unsigned int k);
348 template <
typename VectorType>
355 using Number =
typename VectorType::value_type;
406 boost::signals2::connection
407 connect_append_column_slot(
408 const std::function<
bool(
const Vector<Number> &u,
410 const Number & col_norm_sqr)> &slot);
417 apply_givens_rotation(
const unsigned int i,
const unsigned int k);
427 boost::signals2::signal<bool(const Vector<Number> &u,
429 const Number & col_norm_sqr)>
438 template <
typename VectorType>
447 template <
typename VectorType>
456 template <
typename VectorType>
465 template <
typename VectorType>
468 const Vector<Number> &y,
486 transpose ?
"T" :
"N",
499 template <
typename VectorType>
502 const Vector<Number> &x)
const 509 y.add(x[j], *this->columns[j]);
514 template <
typename VectorType>
523 y[j] = (*this->
columns[j]) * x;
528 template <
class VectorType>
529 boost::signals2::connection
531 const std::function<
void(
const unsigned int i,
532 const unsigned int j,
533 const std::array<Number, 3> &)> &slot)
540 template <
class VectorType>
541 boost::signals2::connection
543 const std::function<
bool(
const Vector<Number> &u,
545 const Number & col_norm_sqr)> &slot)
552 template <
typename VectorType>
559 template <
typename VectorType>
566 this->
columns.push_back(std_cxx14::make_unique<VectorType>(column));
567 this->
R(0, 0) = column.l2_norm();
583 "U",
"T",
"N", &N, &n_rhs, &this->
R(0, 0), &lda, &u(0), &ldb, &info);
587 const Number column_norm_sqr = column.norm_sqr();
588 const Number rho2 = column_norm_sqr - u.norm_sqr();
589 const bool linearly_independent =
594 if (!linearly_independent)
599 this->
columns.push_back(std_cxx14::make_unique<VectorType>(column));
603 this->
R(i, this->current_size) = u(i);
605 this->current_size++;
613 template <
typename VectorType>
616 const unsigned int k)
620 const std::array<Number, 3> csr =
621 ::Utilities::LinearAlgebra::givens_rotation<Number>(this->
R(i, k),
625 this->
R(i, k) = csr[2];
628 for (
unsigned int j = 0; j < this->
R.
n(); ++j)
631 const Number t = this->
R(i, j);
632 this->
R(i, j) = csr[0] * this->
R(i, j) + csr[1] * this->
R(k, j);
633 this->
R(k, j) = -csr[1] * t + csr[0] * this->
R(k, j);
642 template <
typename VectorType>
648 for (
unsigned int j = k + 1; j < this->
R.
n(); ++j)
650 const unsigned int i = j - 1;
664 template <
typename VectorType>
667 const Vector<Number> &x)
const 671 Vector<Number> x1 = x;
678 template <
typename VectorType>
692 template <
typename VectorType>
695 const Vector<Number> &x)
const 702 template <
typename VectorType>
712 template <
typename VectorType>
719 template <
typename VectorType>
725 this->
columns.push_back(std_cxx14::make_unique<VectorType>(column));
729 auto &last_col = *this->
columns.back();
732 const auto &i_col = *this->
columns[i];
733 this->
R(i, this->current_size) = i_col * last_col;
734 last_col.
add(-this->
R(i, this->current_size), i_col);
737 this->
R(this->current_size, this->current_size) = last_col.l2_norm();
739 Assert(this->
R(this->current_size, this->current_size) > 0.,
741 last_col *= 1. / this->
R(this->current_size, this->current_size);
749 template <
typename VectorType>
752 const unsigned int k)
756 const std::array<Number, 3> csr =
757 ::Utilities::LinearAlgebra::givens_rotation<Number>(this->
R(i, k),
761 this->
R(i, k) = csr[2];
764 for (
unsigned int j = 0; j < this->
R.
n(); ++j)
767 const Number t = this->
R(i, j);
768 this->
R(i, j) = csr[0] * this->
R(i, j) + csr[1] * this->
R(k, j);
769 this->
R(k, j) = -csr[1] * t + csr[0] * this->
R(k, j);
774 auto &col_i = *this->
columns[i];
775 auto &col_k = *this->
columns[k];
778 col_i.sadd(csr[0], csr[1], col_k);
779 col_k.sadd(csr[0], -csr[1], tmp);
787 template <
typename VectorType>
793 ExcMessage(
"Can not remove a column if QR is empty"));
810 for (
unsigned int j = k + 1; j < this->
R.
n(); ++j)
812 const unsigned int i = j - 1;
819 const unsigned int size_minus_1 = this->
columns.size() - 1;
829 template <
typename VectorType>
838 template <
typename VectorType>
847 template <
typename VectorType>
851 Vector<Number> x1 = x;
855 trmv(
"U",
"N",
"N", &N, &this->
R(0, 0), &lda, &x1[0], &incx);
862 template <
typename VectorType>
871 trmv(
"U",
"T",
"N", &N, &this->
R(0, 0), &lda, &y[0], &incx);
void trmv(const char *, const char *, const char *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *)
unsigned int size() const
std::vector< std::unique_ptr< VectorType > > columns
void remove_row_and_column(const size_type row, const size_type col)
Matrix is upper triangular.
void multiply_with_colsT(Vector< Number > &y, const VectorType &x) const
virtual bool append_column(const VectorType &column)
#define AssertIndexRange(index, range)
virtual ~BaseQR()=default
virtual void multiply_with_A(VectorType &y, const Vector< Number > &x) const =0
unsigned int current_size
virtual void multiply_with_AT(Vector< Number > &y, const VectorType &x) const
virtual void multiply_with_Q(VectorType &y, const Vector< Number > &x) const =0
virtual bool append_column(const VectorType &column)=0
virtual void multiply_with_Q(VectorType &y, const Vector< Number > &x) const
static ::ExceptionBase & ExcDivideByZero()
LAPACKFullMatrix< Number > R
virtual void multiply_with_A(VectorType &y, const Vector< Number > &x) const
boost::signals2::signal< bool(const Vector< Number > &u, const Number &rho, const Number &col_norm_sqr)> column_signal
void trtrs(const char *, const char *, const char *, const ::types::blas_int *, const ::types::blas_int *, const number1 *, const ::types::blas_int *, number2 *, const ::types::blas_int *, ::types::blas_int *)
boost::signals2::connection connect_append_column_slot(const std::function< bool(const Vector< Number > &u, const Number &rho2, const Number &col_norm_sqr)> &slot)
static ::ExceptionBase & ExcMessage(std::string arg1)
void solve(Vector< Number > &x, const Vector< Number > &y, const bool transpose=false) const
boost::signals2::connection connect_givens_slot(const std::function< void(const unsigned int i, const unsigned int j, const std::array< Number, 3 > &csr)> &slot)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
virtual void multiply_with_AT(Vector< Number > &y, const VectorType &x) const =0
virtual void remove_column(const unsigned int k=0)
void add(const number a, const LAPACKFullMatrix< number > &B)
boost::signals2::signal< void(const unsigned int i, const unsigned int j, const std::array< Number, 3 > &)> givens_signal
#define DEAL_II_NAMESPACE_CLOSE
virtual void multiply_with_A(VectorType &y, const Vector< Number > &x) const
virtual void multiply_with_AT(Vector< Number > &y, const VectorType &x) const
const LAPACKFullMatrix< Number > & get_R() const
virtual void multiply_with_Q(VectorType &y, const Vector< Number > &x) const
void apply_givens_rotation(const unsigned int i, const unsigned int k)
virtual void multiply_with_QT(Vector< Number > &y, const VectorType &x) const
void grow_or_shrink(const size_type size)
virtual bool append_column(const VectorType &column)
virtual void remove_column(const unsigned int k=0)
virtual void multiply_with_QT(Vector< Number > &y, const VectorType &x) const
virtual void remove_column(const unsigned int k=0)=0
void apply_givens_rotation(const unsigned int i, const unsigned int k)
#define DEAL_II_NAMESPACE_OPEN
void set_property(const LAPACKSupport::Property property)
virtual void multiply_with_QT(Vector< Number > &y, const VectorType &x) const =0
void multiply_with_cols(VectorType &y, const Vector< Number > &x) const
typename VectorType::value_type Number