Reference documentation for deal.II version 9.3.3
\(\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 - 2020 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
33template <typename number>
34class Vector;
35#endif
36
340template <class VectorType = Vector<double>>
342{
343public:
347 using vector_type = VectorType;
348
358 SolverBase(SolverControl & solver_control,
359 VectorMemory<VectorType> &vector_memory);
360
371 SolverBase(SolverControl &solver_control);
372
401 boost::signals2::connection
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
410protected:
416
421
422private:
433 {
435
438 const SolverControl::State state2) const;
439
440 template <typename Iterator>
442 operator()(const Iterator begin, const Iterator end) const;
443 };
444
445protected:
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
479template <class VectorType>
483 const SolverControl::State state2) const
484{
485 if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
487 else if ((state1 == SolverControl::iterate) ||
488 (state2 == SolverControl::iterate))
490 else
492}
493
494
495template <class VectorType>
496template <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
506 Iterator p = begin;
507 ++p;
508 for (; p != end; ++p)
509 state = this->operator()(state, *p);
510
511 return state;
512}
513
514
515template <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
534template <class VectorType>
536 : // use the static memory object this class owns
537 memory(static_vector_memory)
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
552template <class VectorType>
553inline 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
SolverBase(SolverControl &solver_control, VectorMemory< VectorType > &vector_memory)
boost::signals2::connection connect(const std::function< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate)> &slot)
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition: solver.h:471
VectorType vector_type
Definition: solver.h:347
GrowingVectorMemory< VectorType > static_vector_memory
Definition: solver.h:415
VectorMemory< VectorType > & memory
Definition: solver.h:420
SolverBase(SolverControl &solver_control)
virtual State check(const unsigned int step, const double check_value)
@ iterate
Continue iteration.
@ success
Stop iteration, goal reached.
@ failure
Stop iteration, goal not reached.
Definition: vector.h:110
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcMessage(std::string arg1)
VectorType::value_type * end(VectorType &V)
VectorType::value_type * begin(VectorType &V)
SolverControl::State operator()(const Iterator begin, const Iterator end) const
SolverControl::State operator()(const SolverControl::State state1, const SolverControl::State state2) const