16 #ifndef dealii_householder_h 17 #define dealii_householder_h 20 #include <deal.II/base/config.h> 22 #include <deal.II/lac/full_matrix.h> 23 #include <deal.II/lac/vector_memory.h> 28 DEAL_II_NAMESPACE_OPEN
32 template <
typename number>
79 template <
typename number>
96 template <
typename number2>
104 template <
typename number2>
118 template <
typename number2>
120 least_squares(Vector<number2> &dst,
const Vector<number2> &src)
const;
125 template <
typename number2>
134 template <
class VectorType>
136 vmult(VectorType &dst,
const VectorType &src)
const;
142 template <
class VectorType>
144 Tvmult(VectorType &dst,
const VectorType &src)
const;
167 template <
typename number>
168 template <
typename number2>
172 const size_type m = M.n_rows(), n = M.n_cols();
179 Assert(storage.n_cols() <= storage.n_rows(),
182 for (size_type j = 0; j < n; ++j)
187 for (i = j; i < m; ++i)
188 sigma += storage(i, j) * storage(i, j);
191 if (std::fabs(sigma) < 1.e-15)
194 number2 s = (storage(j, j) < 0) ? std::sqrt(sigma) : -std::sqrt(sigma);
196 number2 beta = std::sqrt(1. / (sigma - s * storage(j, j)));
201 diagonal[j] = beta * (storage(j, j) - s);
204 for (i = j + 1; i < m; ++i)
205 storage(i, j) *= beta;
210 for (size_type k = j + 1; k < n; ++k)
212 number2
sum = diagonal[j] * storage(j, k);
213 for (i = j + 1; i < m; ++i)
214 sum += storage(i, j) * storage(i, k);
216 storage(j, k) -=
sum * this->diagonal[j];
217 for (i = j + 1; i < m; ++i)
218 storage(i, k) -=
sum * storage(i, j);
225 template <
typename number>
226 template <
typename number2>
234 template <
typename number>
235 template <
typename number2>
238 const Vector<number2> &src)
const 244 const size_type m = storage.m(), n = storage.n();
248 aux->reinit(src,
true);
254 for (size_type j = 0; j < n; ++j)
258 for (size_type i = j + 1; i < m; ++i)
259 sum += static_cast<number2>(storage(i, j)) * (*aux)(i);
261 (*aux)(j) -=
sum * diagonal[j];
262 for (size_type i = j + 1; i < m; ++i)
263 (*aux)(i) -=
sum * static_cast<number2>(storage(i, j));
267 for (size_type i = n; i < m; ++i)
268 sum += (*aux)(i) * (*aux)(i);
272 storage.backward(dst, *aux);
274 return std::sqrt(
sum);
279 template <
typename number>
280 template <
typename number2>
289 const size_type m = storage.m(), n = storage.n();
293 aux->reinit(src,
true);
299 for (size_type j = 0; j < n; ++j)
303 for (size_type i = j + 1; i < m; ++i)
304 sum += storage(i, j) * (*aux)(i);
306 (*aux)(j) -=
sum * diagonal[j];
307 for (size_type i = j + 1; i < m; ++i)
308 (*aux)(i) -=
sum * storage(i, j);
312 for (size_type i = n; i < m; ++i)
313 sum += (*aux)(i) * (*aux)(i);
319 Vector<number2> v_dst, v_aux;
323 storage.backward(v_dst, v_aux);
328 return std::sqrt(
sum);
332 template <
typename number>
333 template <
class VectorType>
337 least_squares(dst, src);
341 template <
typename number>
342 template <
class VectorType>
353 DEAL_II_NAMESPACE_CLOSE
static ::ExceptionBase & ExcEmptyMatrix()
#define AssertDimension(dim1, dim2)
void Tvmult(VectorType &dst, const VectorType &src) const
types::global_dof_index size_type
LinearAlgebra::distributed::Vector< Number > Vector
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
#define Assert(cond, exc)
static ::ExceptionBase & ExcDimensionMismatch(std::size_t arg1, std::size_t arg2)
void vmult(VectorType &dst, const VectorType &src) const
FullMatrix< double > storage
SymmetricTensor< rank, dim, Number > sum(const SymmetricTensor< rank, dim, Number > &local, const MPI_Comm &mpi_communicator)
unsigned int global_dof_index
std::vector< number > diagonal
void initialize(const FullMatrix< number2 > &A)
double least_squares(Vector< number2 > &dst, const Vector< number2 > &src) const
static ::ExceptionBase & ExcNotImplemented()
#define AssertIsFinite(number)