Reference documentation for deal.II version Git ede8f93e86 2020-12-03 14:59:20 -0700
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
solver.h
Go to the documentation of this file.
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 
22 
25 
26 // Ignore deprecation warnings for auto_ptr.
27 #include <boost/signals2.hpp>
28 
30 
31 // Forward declaration
32 #ifndef DOXYGEN
33 template <typename number>
34 class Vector;
35 #endif
36 
340 template <class VectorType = Vector<double>>
341 class SolverBase : public Subscriptor
342 {
343 public:
348 
358  SolverBase(SolverControl & solver_control,
359  VectorMemory<VectorType> &vector_memory);
360 
371  SolverBase(SolverControl &solver_control);
372 
401  boost::signals2::connection
402  connect(
403  const std::function<SolverControl::State(const unsigned int iteration,
404  const double check_value,
405  const VectorType &current_iterate)>
406  &slot);
407 
408 
409 
410 protected:
416 
421 
422 private:
433  {
435 
437  operator()(const SolverControl::State state1,
438  const SolverControl::State state2) const;
439 
440  template <typename Iterator>
442  operator()(const Iterator begin, const Iterator end) const;
443  };
444 
445 protected:
466  boost::signals2::signal<
467  SolverControl::State(const unsigned int iteration,
468  const double check_value,
469  const VectorType & current_iterate),
472 };
473 
474 
475 
476 /*-------------------------------- Inline functions ------------------------*/
477 
478 
479 template <class VectorType>
483  const SolverControl::State state2) const
484 {
485  if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
486  return SolverControl::failure;
487  else if ((state1 == SolverControl::iterate) ||
488  (state2 == SolverControl::iterate))
489  return SolverControl::iterate;
490  else
491  return SolverControl::success;
492 }
493 
494 
495 template <class VectorType>
496 template <typename Iterator>
499  const Iterator end) const
500 {
501  Assert(begin != end,
502  ExcMessage("You can't combine iterator states if no state is given."));
503 
504  // combine the first with all of the following states
505  SolverControl::State state = *begin;
506  Iterator p = begin;
507  ++p;
508  for (; p != end; ++p)
509  state = this->operator()(state, *p);
510 
511  return state;
512 }
513 
514 
515 template <class VectorType>
517  SolverControl & solver_control,
518  VectorMemory<VectorType> &vector_memory)
519  : memory(vector_memory)
520 {
521  // connect the solver control object to the signal. SolverControl::check
522  // only takes two arguments, the iteration and the check_value, and so
523  // we simply ignore the third argument that is passed in whenever the
524  // signal is executed
525  connect([&solver_control](const unsigned int iteration,
526  const double check_value,
527  const VectorType &) {
528  return solver_control.check(iteration, check_value);
529  });
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([&solver_control](const unsigned int iteration,
544  const double check_value,
545  const VectorType &) {
546  return solver_control.check(iteration, check_value);
547  });
548 }
549 
550 
551 
552 template <class VectorType>
553 inline boost::signals2::connection
555  const std::function<SolverControl::State(const unsigned int iteration,
556  const double check_value,
557  const VectorType & current_iterate)>
558  &slot)
559 {
560  return iteration_status.connect(slot);
561 }
562 
563 
564 
566 
567 #endif
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:415
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:554
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:471
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:1466
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:372
SolverControl::State operator()(const SolverControl::State state1, const SolverControl::State state2) const
Definition: solver.h:482
VectorType::value_type * end(VectorType &V)
SolverBase(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:516
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:371
VectorType::value_type * begin(VectorType &V)
VectorMemory< VectorType > & memory
Definition: solver.h:420