Reference documentation for deal.II version 8.4.2
solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2015 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 DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
26 #include <boost/signals2.hpp>
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 template <typename number> class Vector;
32 
324 template <class VectorType = Vector<double> >
325 class Solver : public Subscriptor
326 {
327 public:
331  typedef VectorType vector_type;
332 
342  Solver (SolverControl &solver_control,
343  VectorMemory<VectorType> &vector_memory);
344 
355  Solver (SolverControl &solver_control);
356 
385  boost::signals2::connection
386  connect (const std_cxx11::function<SolverControl::State (const unsigned int iteration,
387  const double check_value,
388  const VectorType &current_iterate)> &slot);
389 
390 
391 
392 protected:
398 
403 
404 private:
413  {
415 
416  SolverControl::State operator() (const SolverControl::State state1,
417  const SolverControl::State state2) const;
418 
419  template <typename Iterator>
420  SolverControl::State operator() (const Iterator begin,
421  const Iterator end) const;
422  };
423 
424 protected:
445  boost::signals2::signal<SolverControl::State (const unsigned int iteration,
446  const double check_value,
447  const VectorType &current_iterate),
449 };
450 
451 
452 /*-------------------------------- Inline functions ------------------------*/
453 
454 
455 template <class VectorType>
456 inline
459  const SolverControl::State state2) const
460 {
461  if ((state1 == SolverControl::failure)
462  ||
463  (state2 == SolverControl::failure))
464  return SolverControl::failure;
465  else if ((state1 == SolverControl::iterate)
466  ||
467  (state2 == SolverControl::iterate))
468  return SolverControl::iterate;
469  else
470  return SolverControl::success;
471 }
472 
473 
474 template <class VectorType>
475 template <typename Iterator>
476 inline
479  const Iterator end) const
480 {
481  Assert (begin != end, ExcMessage ("You can't combine iterator states if no state is given."));
482 
483  // combine the first with all of the following states
484  SolverControl::State state = *begin;
485  Iterator p = begin;
486  ++p;
487  for (; p != end; ++p)
488  state = this->operator()(state, *p);
489 
490  return state;
491 }
492 
493 
494 template<class VectorType>
495 inline
497  VectorMemory<VectorType> &vector_memory)
498  :
499  memory(vector_memory)
500 {
501  // connect the solver control object to the signal. SolverControl::check
502  // only takes two arguments, the iteration and the check_value, and so
503  // we simply ignore the third argument that is passed in whenever the
504  // signal is executed
505  connect (std_cxx11::bind(&SolverControl::check,
506  std_cxx11::ref(solver_control),
507  std_cxx11::_1,
508  std_cxx11::_2));
509 }
510 
511 
512 
513 template<class VectorType>
514 inline
516  :
517  // use the static memory object this class owns
519 {
520  // connect the solver control object to the signal. SolverControl::check
521  // only takes two arguments, the iteration and the check_value, and so
522  // we simply ignore the third argument that is passed in whenever the
523  // signal is executed
524  connect (std_cxx11::bind(&SolverControl::check,
525  std_cxx11::ref(solver_control),
526  std_cxx11::_1,
527  std_cxx11::_2));
528 }
529 
530 
531 
532 template<class VectorType>
533 inline
534 boost::signals2::connection
536 connect (const std_cxx11::function<SolverControl::State (const unsigned int iteration,
537  const double check_value,
538  const VectorType &current_iterate)> &slot)
539 {
540  return iteration_status.connect (slot);
541 }
542 
543 
544 
545 DEAL_II_NAMESPACE_CLOSE
546 
547 #endif
Stop iteration, goal not reached.
virtual State check(const unsigned int step, const double check_value)
Continue iteration.
::ExceptionBase & ExcMessage(std::string arg1)
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:397
boost::signals2::connection connect(const std_cxx11::function< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate)> &slot)
Definition: solver.h:536
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:294
Solver(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:496
VectorMemory< VectorType > & memory
Definition: solver.h:402
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition: solver.h:448
Definition: solver.h:325
VectorType vector_type
Definition: solver.h:331