Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_solver_h
17 #define dealii_solver_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/subscriptor.h>
21 #include <deal.II/lac/vector_memory.h>
22 #include <deal.II/lac/solver_control.h>
23 
24 // Ignore deprecation warnings for auto_ptr.
25 #include <boost/signals2.hpp>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 template <typename number> class Vector;
30 
321 template <class VectorType = Vector<double> >
322 class Solver : public Subscriptor
323 {
324 public:
328  typedef VectorType vector_type;
329 
339  Solver (SolverControl &solver_control,
340  VectorMemory<VectorType> &vector_memory);
341 
352  Solver (SolverControl &solver_control);
353 
382  boost::signals2::connection
383  connect (const std::function<SolverControl::State (const unsigned int iteration,
384  const double check_value,
385  const VectorType &current_iterate)> &slot);
386 
387 
388 
389 protected:
395 
400 
401 private:
412  {
414 
415  SolverControl::State operator() (const SolverControl::State state1,
416  const SolverControl::State state2) const;
417 
418  template <typename Iterator>
419  SolverControl::State operator() (const Iterator begin,
420  const Iterator end) const;
421  };
422 
423 protected:
444  boost::signals2::signal<SolverControl::State (const unsigned int iteration,
445  const double check_value,
446  const VectorType &current_iterate),
448 };
449 
450 
451 /*-------------------------------- Inline functions ------------------------*/
452 
453 
454 template <class VectorType>
455 inline
458  const SolverControl::State state2) const
459 {
460  if ((state1 == SolverControl::failure)
461  ||
462  (state2 == SolverControl::failure))
463  return SolverControl::failure;
464  else if ((state1 == SolverControl::iterate)
465  ||
466  (state2 == SolverControl::iterate))
467  return SolverControl::iterate;
468  else
469  return SolverControl::success;
470 }
471 
472 
473 template <class VectorType>
474 template <typename Iterator>
475 inline
478  const Iterator end) const
479 {
480  Assert (begin != end, ExcMessage ("You can't combine iterator states if no state is given."));
481 
482  // combine the first with all of the following states
483  SolverControl::State state = *begin;
484  Iterator p = begin;
485  ++p;
486  for (; p != end; ++p)
487  state = this->operator()(state, *p);
488 
489  return state;
490 }
491 
492 
493 template <class VectorType>
494 inline
496  VectorMemory<VectorType> &vector_memory)
497  :
498  memory(vector_memory)
499 {
500  // connect the solver control object to the signal. SolverControl::check
501  // only takes two arguments, the iteration and the check_value, and so
502  // we simply ignore the third argument that is passed in whenever the
503  // signal is executed
504  connect (std::bind(&SolverControl::check,
505  std::ref(solver_control),
506  std::placeholders::_1,
507  std::placeholders::_2));
508 }
509 
510 
511 
512 template <class VectorType>
513 inline
515  :
516  // use the static memory object this class owns
517  memory(static_vector_memory)
518 {
519  // connect the solver control object to the signal. SolverControl::check
520  // only takes two arguments, the iteration and the check_value, and so
521  // we simply ignore the third argument that is passed in whenever the
522  // signal is executed
523  connect (std::bind(&SolverControl::check,
524  std::ref(solver_control),
525  std::placeholders::_1,
526  std::placeholders::_2));
527 }
528 
529 
530 
531 template <class VectorType>
532 inline
533 boost::signals2::connection
535 connect (const std::function<SolverControl::State (const unsigned int iteration,
536  const double check_value,
537  const VectorType &current_iterate)> &slot)
538 {
539  return iteration_status.connect (slot);
540 }
541 
542 
543 
544 DEAL_II_NAMESPACE_CLOSE
545 
546 #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:535
Continue iteration.
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:394
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:1142
Solver(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:495
VectorMemory< VectorType > & memory
Definition: solver.h:399
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition: solver.h:447
Definition: solver.h:322
VectorType vector_type
Definition: solver.h:328