16 #ifndef dealii_solver_cg_h
17 #define dealii_solver_cg_h
97 template <
typename VectorType = Vector<
double>>
135 template <
typename MatrixType,
typename PreconditionerType>
137 solve(
const MatrixType &
A,
140 const PreconditionerType &preconditioner);
148 boost::signals2::connection
150 const std::function<
void(
typename VectorType::value_type,
151 typename VectorType::value_type)> &slot);
159 boost::signals2::connection
161 const bool every_iteration =
false);
169 boost::signals2::connection
171 const std::function<
void(
const std::vector<double> &)> &slot,
172 const bool every_iteration =
false);
193 const std::vector<typename VectorType::value_type> &
diagonal,
194 const std::vector<typename VectorType::value_type> &offdiagonal,
195 const boost::signals2::signal<
void(
const std::vector<double> &)>
197 const boost::signals2::signal<
void(
double)> &cond_signal);
207 boost::signals2::signal<void(
typename VectorType::value_type,
208 typename VectorType::value_type)>
233 boost::signals2::signal<void(
const std::vector<double> &)>
243 template <
typename VectorType>
246 const AdditionalData & data)
248 , additional_data(data)
253 template <
typename VectorType>
256 , additional_data(data)
261 template <
typename VectorType>
271 template <
typename VectorType>
274 const std::vector<typename VectorType::value_type> &
diagonal,
275 const std::vector<typename VectorType::value_type> &offdiagonal,
276 const boost::signals2::signal<
void(
const std::vector<double> &)>
277 & eigenvalues_signal,
278 const boost::signals2::signal<
void(
double)> &cond_signal)
281 if (!cond_signal.empty() || !eigenvalues_signal.empty())
289 T(i, i + 1) = offdiagonal[i];
291 T.compute_eigenvalues();
295 auto condition_number =
T.eigenvalue(
T.n() - 1) /
T.eigenvalue(0);
298 cond_signal(std::abs(condition_number));
302 if (!eigenvalues_signal.empty())
305 for (
unsigned int j = 0; j <
T.n(); ++j)
318 template <
typename VectorType>
319 template <
typename MatrixType,
typename PreconditionerType>
324 const PreconditionerType &preconditioner)
326 using number =
typename VectorType::value_type;
343 const bool do_eigenvalues =
344 !condition_number_signal.empty() || !all_condition_numbers_signal.empty() ||
345 !eigenvalues_signal.empty() || !all_eigenvalues_signal.empty();
349 std::vector<typename VectorType::value_type>
diagonal;
350 std::vector<typename VectorType::value_type> offdiagonal;
355 typename VectorType::value_type eigen_beta_alpha = 0;
378 conv = this->iteration_status(0, res, x);
384 preconditioner.vmult(h, g);
401 number alpha =
d * h;
406 res =
std::sqrt(std::abs(g.add_and_dot(alpha, h, g)));
408 print_vectors(it, x, g,
d);
410 conv = this->iteration_status(it, res, x);
417 preconditioner.vmult(h, g);
423 d.sadd(beta, -1., h);
430 d.sadd(beta, -1., g);
433 this->coefficients_signal(alpha, beta);
440 diagonal.push_back(number(1.) / alpha + eigen_beta_alpha);
441 eigen_beta_alpha = beta / alpha;
442 offdiagonal.push_back(std::sqrt(beta) / alpha);
446 all_eigenvalues_signal,
447 all_condition_numbers_signal);
453 condition_number_signal);
463 template <
typename VectorType>
464 boost::signals2::connection
466 const std::function<
void(
typename VectorType::value_type,
467 typename VectorType::value_type)> &slot)
469 return coefficients_signal.connect(slot);
474 template <
typename VectorType>
475 boost::signals2::connection
477 const std::function<
void(
double)> &slot,
478 const bool every_iteration)
482 return all_condition_numbers_signal.connect(slot);
486 return condition_number_signal.connect(slot);
492 template <
typename VectorType>
493 boost::signals2::connection
495 const std::function<
void(
const std::vector<double> &)> &slot,
496 const bool every_iteration)
500 return all_eigenvalues_signal.connect(slot);
504 return eigenvalues_signal.connect(slot);