Reference documentation for deal.II version 8.5.1
solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2016 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>
27 DEAL_II_ENABLE_EXTRA_DIAGNOSTICS
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:
415  {
417 
418  SolverControl::State operator() (const SolverControl::State state1,
419  const SolverControl::State state2) const;
420 
421  template <typename Iterator>
422  SolverControl::State operator() (const Iterator begin,
423  const Iterator end) const;
424  };
425 
426 protected:
447  boost::signals2::signal<SolverControl::State (const unsigned int iteration,
448  const double check_value,
449  const VectorType &current_iterate),
451 };
452 
453 
454 /*-------------------------------- Inline functions ------------------------*/
455 
456 
457 template <class VectorType>
458 inline
461  const SolverControl::State state2) const
462 {
463  if ((state1 == SolverControl::failure)
464  ||
465  (state2 == SolverControl::failure))
466  return SolverControl::failure;
467  else if ((state1 == SolverControl::iterate)
468  ||
469  (state2 == SolverControl::iterate))
470  return SolverControl::iterate;
471  else
472  return SolverControl::success;
473 }
474 
475 
476 template <class VectorType>
477 template <typename Iterator>
478 inline
481  const Iterator end) const
482 {
483  Assert (begin != end, ExcMessage ("You can't combine iterator states if no state is given."));
484 
485  // combine the first with all of the following states
486  SolverControl::State state = *begin;
487  Iterator p = begin;
488  ++p;
489  for (; p != end; ++p)
490  state = this->operator()(state, *p);
491 
492  return state;
493 }
494 
495 
496 template<class VectorType>
497 inline
499  VectorMemory<VectorType> &vector_memory)
500  :
501  memory(vector_memory)
502 {
503  // connect the solver control object to the signal. SolverControl::check
504  // only takes two arguments, the iteration and the check_value, and so
505  // we simply ignore the third argument that is passed in whenever the
506  // signal is executed
507  connect (std_cxx11::bind(&SolverControl::check,
508  std_cxx11::ref(solver_control),
509  std_cxx11::_1,
510  std_cxx11::_2));
511 }
512 
513 
514 
515 template<class VectorType>
516 inline
518  :
519  // use the static memory object this class owns
520  memory(static_vector_memory)
521 {
522  // connect the solver control object to the signal. SolverControl::check
523  // only takes two arguments, the iteration and the check_value, and so
524  // we simply ignore the third argument that is passed in whenever the
525  // signal is executed
526  connect (std_cxx11::bind(&SolverControl::check,
527  std_cxx11::ref(solver_control),
528  std_cxx11::_1,
529  std_cxx11::_2));
530 }
531 
532 
533 
534 template<class VectorType>
535 inline
536 boost::signals2::connection
538 connect (const std_cxx11::function<SolverControl::State (const unsigned int iteration,
539  const double check_value,
540  const VectorType &current_iterate)> &slot)
541 {
542  return iteration_status.connect (slot);
543 }
544 
545 
546 
547 DEAL_II_NAMESPACE_CLOSE
548 
549 #endif
Stop iteration, goal not reached.
virtual State check(const unsigned int step, const double check_value)
Continue iteration.
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:397
static ::ExceptionBase & ExcMessage(std::string arg1)
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:538
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:313
Solver(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:498
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:450
Definition: solver.h:325
VectorType vector_type
Definition: solver.h:331