Reference documentation for deal.II version Git 6177fad8a5 2019-03-23 23:27:20 +0100
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2018 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_solver_h
17 #define dealii_solver_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/subscriptor.h>
22 
23 #include <deal.II/lac/solver_control.h>
24 #include <deal.II/lac/vector_memory.h>
25 
26 // Ignore deprecation warnings for auto_ptr.
27 #include <boost/signals2.hpp>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 template <typename number>
32 class Vector;
33 
327 template <class VectorType = Vector<double>>
328 class Solver : public Subscriptor
329 {
330 public:
334  using vector_type = VectorType;
335 
345  Solver(SolverControl & solver_control,
346  VectorMemory<VectorType> &vector_memory);
347 
358  Solver(SolverControl &solver_control);
359 
388  boost::signals2::connection
389  connect(
390  const std::function<SolverControl::State(const unsigned int iteration,
391  const double check_value,
392  const VectorType &current_iterate)>
393  &slot);
394 
395 
396 
397 protected:
403 
408 
409 private:
420  {
422 
424  operator()(const SolverControl::State state1,
425  const SolverControl::State state2) const;
426 
427  template <typename Iterator>
429  operator()(const Iterator begin, const Iterator end) const;
430  };
431 
432 protected:
453  boost::signals2::signal<
454  SolverControl::State(const unsigned int iteration,
455  const double check_value,
456  const VectorType & current_iterate),
459 };
460 
461 
462 /*-------------------------------- Inline functions ------------------------*/
463 
464 
465 template <class VectorType>
468 operator()(const SolverControl::State state1,
469  const SolverControl::State state2) const
470 {
471  if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
472  return SolverControl::failure;
473  else if ((state1 == SolverControl::iterate) ||
474  (state2 == SolverControl::iterate))
475  return SolverControl::iterate;
476  else
477  return SolverControl::success;
478 }
479 
480 
481 template <class VectorType>
482 template <typename Iterator>
485  const Iterator end) const
486 {
487  Assert(begin != end,
488  ExcMessage("You can't combine iterator states if no state is given."));
489 
490  // combine the first with all of the following states
491  SolverControl::State state = *begin;
492  Iterator p = begin;
493  ++p;
494  for (; p != end; ++p)
495  state = this->operator()(state, *p);
496 
497  return state;
498 }
499 
500 
501 template <class VectorType>
503  VectorMemory<VectorType> &vector_memory)
504  : memory(vector_memory)
505 {
506  // connect the solver control object to the signal. SolverControl::check
507  // only takes two arguments, the iteration and the check_value, and so
508  // we simply ignore the third argument that is passed in whenever the
509  // signal is executed
510  connect(std::bind(&SolverControl::check,
511  std::ref(solver_control),
512  std::placeholders::_1,
513  std::placeholders::_2));
514 }
515 
516 
517 
518 template <class VectorType>
520  : // use the static memory object this class owns
522 {
523  // connect the solver control object to the signal. SolverControl::check
524  // only takes two arguments, the iteration and the check_value, and so
525  // we simply ignore the third argument that is passed in whenever the
526  // signal is executed
527  connect(std::bind(&SolverControl::check,
528  std::ref(solver_control),
529  std::placeholders::_1,
530  std::placeholders::_2));
531 }
532 
533 
534 
535 template <class VectorType>
536 inline boost::signals2::connection
538  const std::function<SolverControl::State(const unsigned int iteration,
539  const double check_value,
540  const VectorType & current_iterate)>
541  &slot)
542 {
543  return iteration_status.connect(slot);
544 }
545 
546 
547 
548 DEAL_II_NAMESPACE_CLOSE
549 
550 #endif
Stop iteration, goal not reached.
virtual State check(const unsigned int step, const double check_value)
boost::signals2::connection connect(const std::function< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate)> &slot)
Definition: solver.h:537
VectorType vector_type
Definition: solver.h:334
Continue iteration.
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:402
LinearAlgebra::distributed::Vector< Number > Vector
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:1407
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition: solver.h:458
Solver(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:502
VectorMemory< VectorType > & memory
Definition: solver.h:407
Definition: solver.h:328