Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
solver.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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 SolverBase : public Subscriptor
329 {
330 public:
334  using vector_type = VectorType;
335 
345  SolverBase(SolverControl & solver_control,
346  VectorMemory<VectorType> &vector_memory);
347 
358  SolverBase(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 
470 template <class VectorType = Vector<double>>
471 using Solver DEAL_II_DEPRECATED = SolverBase<VectorType>;
472 
473 
474 /*-------------------------------- Inline functions ------------------------*/
475 
476 
477 template <class VectorType>
480 operator()(const SolverControl::State state1,
481  const SolverControl::State state2) const
482 {
483  if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
484  return SolverControl::failure;
485  else if ((state1 == SolverControl::iterate) ||
486  (state2 == SolverControl::iterate))
487  return SolverControl::iterate;
488  else
489  return SolverControl::success;
490 }
491 
492 
493 template <class VectorType>
494 template <typename Iterator>
497  const Iterator end) const
498 {
499  Assert(begin != end,
500  ExcMessage("You can't combine iterator states if no state is given."));
501 
502  // combine the first with all of the following states
503  SolverControl::State state = *begin;
504  Iterator p = begin;
505  ++p;
506  for (; p != end; ++p)
507  state = this->operator()(state, *p);
508 
509  return state;
510 }
511 
512 
513 template <class VectorType>
515  SolverControl & solver_control,
516  VectorMemory<VectorType> &vector_memory)
517  : memory(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>
533  : // use the static memory object this class owns
535 {
536  // connect the solver control object to the signal. SolverControl::check
537  // only takes two arguments, the iteration and the check_value, and so
538  // we simply ignore the third argument that is passed in whenever the
539  // signal is executed
540  connect(std::bind(&SolverControl::check,
541  std::ref(solver_control),
542  std::placeholders::_1,
543  std::placeholders::_2));
544 }
545 
546 
547 
548 template <class VectorType>
549 inline boost::signals2::connection
551  const std::function<SolverControl::State(const unsigned int iteration,
552  const double check_value,
553  const VectorType & current_iterate)>
554  &slot)
555 {
556  return iteration_status.connect(slot);
557 }
558 
559 
560 
561 DEAL_II_NAMESPACE_CLOSE
562 
563 #endif
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:402
Stop iteration, goal not reached.
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:550
virtual State check(const unsigned int step, const double check_value)
Continue iteration.
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition: solver.h:458
LinearAlgebra::distributed::Vector< Number > Vector
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:1407
SolverBase(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:514
VectorType vector_type
Definition: solver.h:334
VectorMemory< VectorType > & memory
Definition: solver.h:407