Reference documentation for deal.II version Git bedfa10003 2019-09-17 13:28:06 -0600
\(\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 // Forward declaration
32 #ifndef DOXYGEN
33 template <typename number>
34 class Vector;
35 #endif
36 
330 template <class VectorType = Vector<double>>
331 class SolverBase : public Subscriptor
332 {
333 public:
337  using vector_type = VectorType;
338 
348  SolverBase(SolverControl & solver_control,
349  VectorMemory<VectorType> &vector_memory);
350 
361  SolverBase(SolverControl &solver_control);
362 
391  boost::signals2::connection
392  connect(
393  const std::function<SolverControl::State(const unsigned int iteration,
394  const double check_value,
395  const VectorType &current_iterate)>
396  &slot);
397 
398 
399 
400 protected:
406 
411 
412 private:
423  {
425 
427  operator()(const SolverControl::State state1,
428  const SolverControl::State state2) const;
429 
430  template <typename Iterator>
432  operator()(const Iterator begin, const Iterator end) const;
433  };
434 
435 protected:
456  boost::signals2::signal<
457  SolverControl::State(const unsigned int iteration,
458  const double check_value,
459  const VectorType & current_iterate),
462 };
463 
464 
465 
473 template <class VectorType = Vector<double>>
474 using Solver DEAL_II_DEPRECATED = SolverBase<VectorType>;
475 
476 
477 /*-------------------------------- Inline functions ------------------------*/
478 
479 
480 template <class VectorType>
483 operator()(const SolverControl::State state1,
484  const SolverControl::State state2) const
485 {
486  if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
487  return SolverControl::failure;
488  else if ((state1 == SolverControl::iterate) ||
489  (state2 == SolverControl::iterate))
490  return SolverControl::iterate;
491  else
492  return SolverControl::success;
493 }
494 
495 
496 template <class VectorType>
497 template <typename Iterator>
500  const Iterator end) const
501 {
502  Assert(begin != end,
503  ExcMessage("You can't combine iterator states if no state is given."));
504 
505  // combine the first with all of the following states
506  SolverControl::State state = *begin;
507  Iterator p = begin;
508  ++p;
509  for (; p != end; ++p)
510  state = this->operator()(state, *p);
511 
512  return state;
513 }
514 
515 
516 template <class VectorType>
518  SolverControl & solver_control,
519  VectorMemory<VectorType> &vector_memory)
520  : memory(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::bind(&SolverControl::check,
527  std::ref(solver_control),
528  std::placeholders::_1,
529  std::placeholders::_2));
530 }
531 
532 
533 
534 template <class VectorType>
536  : // use the static memory object this class owns
538 {
539  // connect the solver control object to the signal. SolverControl::check
540  // only takes two arguments, the iteration and the check_value, and so
541  // we simply ignore the third argument that is passed in whenever the
542  // signal is executed
543  connect(std::bind(&SolverControl::check,
544  std::ref(solver_control),
545  std::placeholders::_1,
546  std::placeholders::_2));
547 }
548 
549 
550 
551 template <class VectorType>
552 inline boost::signals2::connection
554  const std::function<SolverControl::State(const unsigned int iteration,
555  const double check_value,
556  const VectorType & current_iterate)>
557  &slot)
558 {
559  return iteration_status.connect(slot);
560 }
561 
562 
563 
564 DEAL_II_NAMESPACE_CLOSE
565 
566 #endif
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:405
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:553
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:461
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:517
VectorType vector_type
Definition: solver.h:337
VectorMemory< VectorType > & memory
Definition: solver.h:410