Reference documentation for deal.II version 9.2.0
\(\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 
332 template <class VectorType = Vector<double>>
333 class SolverBase : public Subscriptor
334 {
335 public:
340 
350  SolverBase(SolverControl & solver_control,
351  VectorMemory<VectorType> &vector_memory);
352 
363  SolverBase(SolverControl &solver_control);
364 
393  boost::signals2::connection
394  connect(
395  const std::function<SolverControl::State(const unsigned int iteration,
396  const double check_value,
397  const VectorType &current_iterate)>
398  &slot);
399 
400 
401 
402 protected:
408 
413 
414 private:
425  {
427 
429  operator()(const SolverControl::State state1,
430  const SolverControl::State state2) const;
431 
432  template <typename Iterator>
434  operator()(const Iterator begin, const Iterator end) const;
435  };
436 
437 protected:
458  boost::signals2::signal<
459  SolverControl::State(const unsigned int iteration,
460  const double check_value,
461  const VectorType & current_iterate),
464 };
465 
466 
467 
475 template <class VectorType = Vector<double>>
477 
478 
479 /*-------------------------------- Inline functions ------------------------*/
480 
481 
482 template <class VectorType>
486  const SolverControl::State state2) const
487 {
488  if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
489  return SolverControl::failure;
490  else if ((state1 == SolverControl::iterate) ||
491  (state2 == SolverControl::iterate))
492  return SolverControl::iterate;
493  else
494  return SolverControl::success;
495 }
496 
497 
498 template <class VectorType>
499 template <typename Iterator>
502  const Iterator end) const
503 {
504  Assert(begin != end,
505  ExcMessage("You can't combine iterator states if no state is given."));
506 
507  // combine the first with all of the following states
508  SolverControl::State state = *begin;
509  Iterator p = begin;
510  ++p;
511  for (; p != end; ++p)
512  state = this->operator()(state, *p);
513 
514  return state;
515 }
516 
517 
518 template <class VectorType>
520  SolverControl & solver_control,
521  VectorMemory<VectorType> &vector_memory)
522  : memory(vector_memory)
523 {
524  // connect the solver control object to the signal. SolverControl::check
525  // only takes two arguments, the iteration and the check_value, and so
526  // we simply ignore the third argument that is passed in whenever the
527  // signal is executed
528  connect([&solver_control](const unsigned int iteration,
529  const double check_value,
530  const VectorType &) {
531  return solver_control.check(iteration, check_value);
532  });
533 }
534 
535 
536 
537 template <class VectorType>
539  : // use the static memory object this class owns
541 {
542  // connect the solver control object to the signal. SolverControl::check
543  // only takes two arguments, the iteration and the check_value, and so
544  // we simply ignore the third argument that is passed in whenever the
545  // signal is executed
546  connect([&solver_control](const unsigned int iteration,
547  const double check_value,
548  const VectorType &) {
549  return solver_control.check(iteration, check_value);
550  });
551 }
552 
553 
554 
555 template <class VectorType>
556 inline boost::signals2::connection
558  const std::function<SolverControl::State(const unsigned int iteration,
559  const double check_value,
560  const VectorType & current_iterate)>
561  &slot)
562 {
563  return iteration_status.connect(slot);
564 }
565 
566 
567 
569 
570 #endif
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:407
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:557
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:463
static ::ExceptionBase & ExcMessage(std::string arg1)
Stop iteration, goal reached.
#define Assert(cond, exc)
Definition: exceptions.h:1419
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
SolverControl::State operator()(const SolverControl::State state1, const SolverControl::State state2) const
Definition: solver.h:485
VectorType::value_type * end(VectorType &V)
SolverBase(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
Definition: solver.h:519
MatrixTableIterators::Iterator< TransposeTable< T >, Constness, MatrixTableIterators::Storage::column_major > Iterator
Definition: table.h:1913
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
VectorType::value_type * begin(VectorType &V)
#define DEAL_II_DEPRECATED
Definition: config.h:98
VectorMemory< VectorType > & memory
Definition: solver.h:412