Reference documentation for deal.II version 9.5.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\}}\)
Loading...
Searching...
No Matches
solver.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 1998 - 2022 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#include <boost/signals2.hpp>
27
29
30// Forward declaration
31#ifndef DOXYGEN
32template <typename number>
33class Vector;
34#endif
35
339template <class VectorType = Vector<double>>
341{
342public:
346 using vector_type = VectorType;
347
357 SolverBase(SolverControl & solver_control,
358 VectorMemory<VectorType> &vector_memory);
359
370 SolverBase(SolverControl &solver_control);
371
400 boost::signals2::connection
402 const std::function<SolverControl::State(const unsigned int iteration,
403 const double check_value,
404 const VectorType &current_iterate)>
405 &slot);
406
407
408
409protected:
415
420
421private:
432 {
434
437 const SolverControl::State state2) const;
438
439 template <typename Iterator>
441 operator()(const Iterator begin, const Iterator end) const;
442 };
443
444protected:
465 boost::signals2::signal<
466 SolverControl::State(const unsigned int iteration,
467 const double check_value,
468 const VectorType & current_iterate),
471};
472
473
474
475/*-------------------------------- Inline functions ------------------------*/
476
477
478template <class VectorType>
481 const SolverControl::State state1,
482 const SolverControl::State state2) const
483{
484 if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
486 else if ((state1 == SolverControl::iterate) ||
487 (state2 == SolverControl::iterate))
489 else
491}
492
493
494template <class VectorType>
495template <typename Iterator>
498 const Iterator end) const
499{
500 Assert(begin != end,
501 ExcMessage("You can't combine iterator states if no state is given."));
502
503 // combine the first with all of the following states
505 Iterator p = begin;
506 ++p;
507 for (; p != end; ++p)
508 state = this->operator()(state, *p);
509
510 return state;
511}
512
513
514template <class VectorType>
516 SolverControl & solver_control,
517 VectorMemory<VectorType> &vector_memory)
518 : memory(vector_memory)
519{
520 // connect the solver control object to the signal. SolverControl::check
521 // only takes two arguments, the iteration and the check_value, and so
522 // we simply ignore the third argument that is passed in whenever the
523 // signal is executed
524 connect([&solver_control](const unsigned int iteration,
525 const double check_value,
526 const VectorType &) {
527 return solver_control.check(iteration, check_value);
528 });
529}
530
531
532
533template <class VectorType>
535 : // use the static memory object this class owns
536 memory(static_vector_memory)
537{
538 // connect the solver control object to the signal. SolverControl::check
539 // only takes two arguments, the iteration and the check_value, and so
540 // we simply ignore the third argument that is passed in whenever the
541 // signal is executed
542 connect([&solver_control](const unsigned int iteration,
543 const double check_value,
544 const VectorType &) {
545 return solver_control.check(iteration, check_value);
546 });
547}
548
549
550
551template <class VectorType>
552inline 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
565
566#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:470
VectorType vector_type
Definition solver.h:346
GrowingVectorMemory< VectorType > static_vector_memory
Definition solver.h:414
VectorMemory< VectorType > & memory
Definition solver.h:419
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.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:472
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:473
#define Assert(cond, exc)
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