From: Giuseppe Pitton Date: Thu, 7 Apr 2016 21:01:56 +0000 (-0500) Subject: Update a comment for a variable. X-Git-Tag: v8.5.0-rc1~1114^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=39a064f2f1c5ee3893057fdec918d8c02739350d;p=dealii.git Update a comment for a variable. --- diff --git a/doc/news/changes.h b/doc/news/changes.h index eb6858df67..6ae21c3be5 100644 --- a/doc/news/changes.h +++ b/doc/news/changes.h @@ -145,6 +145,13 @@ inconvenience this causes.

Specific improvements

    +
  1. New: added hessenberg_signal and krylov_space_signal to SolverGMRES. + These signals allow to retrieve the Hessenberg matrix and the basis vectors + generated by the Arnoldi algorithm. +
    + (Giuseppe Pitton, Luca Heltai, 2016/04/11) +
  2. +
  3. Fixed: Meshworker::Assembler::ResidualSimple now also works for multiple blocks if no constraints are given.
    diff --git a/include/deal.II/lac/solver_gmres.h b/include/deal.II/lac/solver_gmres.h index c3e031f821..f83ccd4538 100644 --- a/include/deal.II/lac/solver_gmres.h +++ b/include/deal.II/lac/solver_gmres.h @@ -83,6 +83,13 @@ namespace internal VectorType &operator() (const unsigned int i, const VectorType &temp); + /** + * Returns size of data vector. It is used in the solver to store + * the Arnoldi vectors. + */ + unsigned int size() const; + + private: /** * Pool were vectors are obtained from. @@ -288,6 +295,28 @@ public: const std_cxx11::function > &)> &slot, const bool every_iteration=false); + /** + * Connect a slot to retrieve the Hessenberg matrix obtained by the + * projection of the initial matrix on the Krylov basis. Called on each + * outer iteration if every_iteration=true, otherwise called once when + * iterations are ended (i.e., either because convergence has been achieved, + * or because divergence has been detected). + */ + boost::signals2::connection + connect_hessenberg_slot( + const std_cxx11::function &)> &slot, + const bool every_iteration=true); + + /** + * Connect a slot to retrieve the basis vectors of the Krylov space + * generated by the Arnoldi algorithm. Called at once when iterations + * are completed (i.e., either because convergence has been achieved, + * or because divergence has been detected). + */ + boost::signals2::connection + connect_krylov_space_slot( + const std_cxx11::function &)> &slot); + DeclException1 (ExcTooFewTmpVectors, int, @@ -326,6 +355,23 @@ protected: */ boost::signals2::signal > &)> all_eigenvalues_signal; + /** + * Signal used to retrieve the Hessenberg matrix. Called once when + * all iterations are ended. + */ + boost::signals2::signal &)> hessenberg_signal; + + /** + * Signal used to retrieve the Hessenberg matrix. Called on each outer + * iteration. + */ + boost::signals2::signal &)> all_hessenberg_signal; + + /** + * Signal used to retrieve the Krylov space basis vectors. Called once + * when all iterations are ended. + */ + boost::signals2::signal &)> krylov_space_signal; /** * Implementation of the computation of the norm of the residual. @@ -369,6 +415,7 @@ protected: const FullMatrix &H_orig , const unsigned int dim, const boost::signals2::signal > &)> &eigenvalues_signal, + const boost::signals2::signal &)> &hessenberg_signal, const boost::signals2::signal &cond_signal, const bool log_eigenvalues); @@ -537,6 +584,15 @@ namespace internal return *data[i-offset]; } + + template + unsigned int + TmpVectors::size() const + { + return (data.size() > 0 ? data.size()-1 : 0); + } + + // A comparator for better printing eigenvalues inline bool complex_less_pred(const std::complex &x, @@ -701,16 +757,19 @@ SolverGMRES::compute_eigs_and_cond (const FullMatrix &H_orig, const unsigned int dim, const boost::signals2::signal > &)> &eigenvalues_signal, + const boost::signals2::signal &)> &hessenberg_signal, const boost::signals2::signal &cond_signal, const bool log_eigenvalues) { //Avoid copying the Hessenberg matrix if it isn't needed. - if (!eigenvalues_signal.empty() || !cond_signal.empty() || log_eigenvalues ) + if (!eigenvalues_signal.empty() || !hessenberg_signal.empty() + || !cond_signal.empty() || log_eigenvalues ) { LAPACKFullMatrix mat(dim,dim); for (unsigned int i=0; i::solve (const MatrixType &A, |!all_condition_numbers_signal.empty() |!eigenvalues_signal.empty() |!all_eigenvalues_signal.empty() + |!hessenberg_signal.empty() + |!all_hessenberg_signal.empty() |additional_data.compute_eigenvalues; // for eigenvalue computation, need to collect the Hessenberg matrix (before // applying Givens rotations) @@ -1003,6 +1064,7 @@ SolverGMRES::solve (const MatrixType &A, H1(i,j) = H(i,j); compute_eigs_and_cond(H_orig,dim,all_eigenvalues_signal, + all_hessenberg_signal, all_condition_numbers_signal, additional_data.compute_eigenvalues); @@ -1024,8 +1086,13 @@ SolverGMRES::solve (const MatrixType &A, } while (iteration_state == SolverControl::iterate); - compute_eigs_and_cond(H_orig,dim,eigenvalues_signal,condition_number_signal, + compute_eigs_and_cond(H_orig,dim,eigenvalues_signal,hessenberg_signal, + condition_number_signal, false); + + if (!krylov_space_signal.empty()) + krylov_space_signal(tmp_vectors); + if (!use_default_residual) { this->memory.free(r); @@ -1080,6 +1147,34 @@ SolverGMRES::connect_eigenvalues_slot +template +boost::signals2::connection +SolverGMRES::connect_hessenberg_slot +(const std_cxx11::function &)> &slot, + const bool every_iteration) +{ + if (every_iteration) + { + return all_hessenberg_signal.connect(slot); + } + else + { + return hessenberg_signal.connect(slot); + } +} + + + +template +boost::signals2::connection +SolverGMRES::connect_krylov_space_slot +(const std_cxx11::function &)> &slot) +{ + return krylov_space_signal.connect(slot); +} + + + template double SolverGMRES::criterion () diff --git a/tests/lac/solver_signals.cc b/tests/lac/solver_signals.cc index 18eedb9930..e2857462b9 100644 --- a/tests/lac/solver_signals.cc +++ b/tests/lac/solver_signals.cc @@ -56,6 +56,26 @@ void output_eigenvalues(const std::vector &eigenvalues,const std::string deallog << std::endl; } +template +void output_hessenberg_matrix(const FullMatrix &H,const std::string &text) +{ + deallog << text << std::endl; + for (unsigned int i=0; i +void output_arnoldi_vectors_norms(const internal::SolverGMRES::TmpVectors > &tmp_vector,const std::string &text) +{ + deallog << text << std::endl; + for (unsigned int i=0; i void check_solve(SolverType &solver, @@ -128,6 +148,10 @@ int main() std_cxx11::bind(output_eigenvalues >,std_cxx11::_1,"Eigenvalues: "),true); solver_gmres.connect_eigenvalues_slot( std_cxx11::bind(output_eigenvalues >,std_cxx11::_1,"Final Eigenvalues: ")); + solver_gmres.connect_hessenberg_slot( + std_cxx11::bind(output_hessenberg_matrix,std_cxx11::_1,"Hessenberg matrix: "),false); + solver_gmres.connect_krylov_space_slot( + std_cxx11::bind(output_arnoldi_vectors_norms,std_cxx11::_1,"Arnoldi vectors norms: ")); solver_gmres.solve(A,u,f,PreconditionIdentity()); } catch (std::exception &e) diff --git a/tests/lac/solver_signals.output b/tests/lac/solver_signals.output index caa51fc486..896dae4732 100644 --- a/tests/lac/solver_signals.output +++ b/tests/lac/solver_signals.output @@ -127,5 +127,66 @@ DEAL:GMRES::Condition number: 288.5 DEAL:GMRES::Convergence step 65 value 0.0009799 DEAL:GMRES::Eigenvalues: (0.02681,0.000) (0.2333,0.000) (1.178,0.000) (2.161,0.000) (3.554,0.000) (4.930,0.000) (6.307,0.000) (7.170,0.000) (7.726,0.000) DEAL:GMRES::Condition number: 288.2 +DEAL:GMRES::Hessenberg matrix: +DEAL:GMRES::0.1982 0.8628 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0.8628 6.098 1.971 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 1.971 4.008 1.721 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 1.721 3.583 2.004 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 2.004 4.008 1.910 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 1.910 3.325 1.950 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 1.950 4.036 1.744 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 1.744 3.951 1.992 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 1.992 4.080 1.994 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 1.920 4.007 2.002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 2.002 3.981 2.022 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 2.022 4.028 1.908 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 1.908 4.238 1.925 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 1.925 4.011 2.042 0 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 2.042 3.827 2.111 0 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.111 3.742 2.046 0 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.046 4.070 1.879 0 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.879 4.168 1.933 0 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.933 4.013 1.886 0 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.886 3.963 1.957 0 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.957 3.818 2.033 0 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.033 4.006 2.201 0 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.201 3.944 1.862 0 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.862 4.039 1.827 0 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.827 3.704 1.844 0 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.844 4.073 2.046 0 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.046 3.592 1.647 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1.647 3.431 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2.155 0 +DEAL:GMRES::0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 DEAL:GMRES::Final Eigenvalues: (0.02681,0.000) (0.2333,0.000) (1.178,0.000) (2.161,0.000) (3.554,0.000) (4.930,0.000) (6.307,0.000) (7.170,0.000) (7.726,0.000) DEAL:GMRES::Final condition number: 288.2 +DEAL:GMRES::Arnoldi vectors norms: +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000 +DEAL:GMRES::1.000