16 #ifndef dealii_householder_h 17 #define dealii_householder_h 21 #include <deal.II/base/config.h> 22 #include <deal.II/lac/full_matrix.h> 23 #include <deal.II/lac/vector_memory.h> 27 DEAL_II_NAMESPACE_OPEN
31 template <
typename number>
class Vector;
77 template <
typename number>
94 template <
typename number2>
102 template <
typename number2>
116 template <
typename number2>
118 const Vector<number2> &src)
const;
123 template <
typename number2>
131 template <
class VectorType>
132 void vmult (VectorType &dst,
133 const VectorType &src)
const;
139 template <
class VectorType>
140 void Tvmult (VectorType &dst,
const VectorType &src)
const;
163 template <
typename number>
164 template <
typename number2>
168 const size_type m = M.n_rows(), n = M.n_cols();
175 Assert (storage.n_cols() <= storage.n_rows(),
178 for (size_type j=0 ; j<n ; ++j)
183 for (i=j ; i<m ; ++i)
184 sigma += storage(i,j)*storage(i,j);
187 if (std::fabs(sigma) < 1.e-15)
return;
189 number2 s = (storage(j,j) < 0) ? std::sqrt(sigma) : -std::sqrt(sigma);
191 number2 beta = std::sqrt(1./(sigma-s*storage(j,j)));
196 diagonal[j] = beta*(storage(j,j) - s);
199 for (i=j+1 ; i<m ; ++i)
200 storage(i,j) *= beta;
205 for (size_type k=j+1 ; k<n ; ++k)
207 number2
sum = diagonal[j]*storage(j,k);
208 for (i=j+1 ; i<m ; ++i)
209 sum += storage(i,j)*storage(i,k);
211 storage(j,k) -=
sum*this->diagonal[j];
212 for (i=j+1 ; i<m ; ++i)
213 storage(i,k) -=
sum*storage(i,j);
220 template <
typename number>
221 template <
typename number2>
229 template <
typename number>
230 template <
typename number2>
233 const Vector<number2> &src)
const 239 const size_type m = storage.m(), n = storage.n();
243 aux->reinit(src,
true);
249 for (size_type j=0; j<n; ++j)
253 for (size_type i=j+1 ; i<m ; ++i)
254 sum += static_cast<number2>(storage(i,j))*(*aux)(i);
256 (*aux)(j) -=
sum*diagonal[j];
257 for (size_type i=j+1 ; i<m ; ++i)
258 (*aux)(i) -=
sum*static_cast<number2>(storage(i,j));
262 for (size_type i=n ; i<m ; ++i)
263 sum += (*aux)(i) * (*aux)(i);
267 storage.backward(dst, *aux);
269 return std::sqrt(
sum);
274 template <
typename number>
275 template <
typename number2>
284 const size_type m = storage.m(), n = storage.n();
288 aux->reinit(src,
true);
294 for (size_type j=0; j<n; ++j)
298 for (size_type i=j+1 ; i<m ; ++i)
299 sum += storage(i,j)*(*aux)(i);
301 (*aux)(j) -=
sum*diagonal[j];
302 for (size_type i=j+1 ; i<m ; ++i)
303 (*aux)(i) -=
sum*storage(i,j);
307 for (size_type i=n ; i<m ; ++i)
308 sum += (*aux)(i) * (*aux)(i);
314 Vector<number2> v_dst, v_aux;
318 storage.backward(v_dst, v_aux);
323 return std::sqrt(
sum);
327 template <
typename number>
328 template <
class VectorType>
332 least_squares (dst, src);
336 template <
typename number>
337 template <
class VectorType>
348 DEAL_II_NAMESPACE_CLOSE
types::global_dof_index size_type
static ::ExceptionBase & ExcEmptyMatrix()
#define AssertDimension(dim1, dim2)
void Tvmult(VectorType &dst, const VectorType &src) const
types::global_dof_index size_type
unsigned int global_dof_index
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)
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)