deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\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// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 1998 - 2024 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_solver_h
14#define dealii_solver_h
15
16#include <deal.II/base/config.h>
17
20
23
24#include <boost/signals2.hpp>
25
27
28// Forward declaration
29#ifndef DOXYGEN
30template <typename number>
31class Vector;
32#endif
33
337template <typename VectorType = Vector<double>>
340{
341public:
345 using vector_type = VectorType;
346
356 SolverBase(SolverControl &solver_control,
357 VectorMemory<VectorType> &vector_memory);
358
369 SolverBase(SolverControl &solver_control);
370
399 boost::signals2::connection
401 const std::function<SolverControl::State(const unsigned int iteration,
402 const double check_value,
403 const VectorType &current_iterate)>
404 &slot);
405
406
407
408protected:
414
419
420private:
431 {
433
436 const SolverControl::State state2) const;
437
438 template <typename Iterator>
440 operator()(const Iterator begin, const Iterator end) const;
441 };
442
443protected:
464 boost::signals2::signal<
465 SolverControl::State(const unsigned int iteration,
466 const double check_value,
467 const VectorType &current_iterate),
470};
471
472
473
474/*-------------------------------- Inline functions ------------------------*/
475#ifndef DOXYGEN
476
477template <typename VectorType>
480 const SolverControl::State state1,
481 const SolverControl::State state2) const
482{
483 if ((state1 == SolverControl::failure) || (state2 == SolverControl::failure))
485 else if ((state1 == SolverControl::iterate) ||
486 (state2 == SolverControl::iterate))
488 else
490}
491
492
493template <typename 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 <typename 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 <typename VectorType>
537 : // use the static memory object this class owns
538 memory(static_vector_memory)
539{
540 // connect the solver control object to the signal. SolverControl::check
541 // only takes two arguments, the iteration and the check_value, and so
542 // we simply ignore the third argument that is passed in whenever the
543 // signal is executed
544 connect([&solver_control](const unsigned int iteration,
545 const double check_value,
546 const VectorType &) {
547 return solver_control.check(iteration, check_value);
548 });
549}
550
551
552
553template <typename VectorType>
555inline boost::signals2::connection SolverBase<VectorType>::connect(
556 const std::function<SolverControl::State(const unsigned int iteration,
557 const double check_value,
558 const VectorType &current_iterate)>
559 &slot)
560{
561 return iteration_status.connect(slot);
562}
563
564#endif
565
567
568#endif
*  iterator end()
*  *  iterator begin()
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition solver.h:469
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)
VectorType vector_type
Definition solver.h:345
GrowingVectorMemory< VectorType > static_vector_memory
Definition solver.h:413
VectorMemory< VectorType > & memory
Definition solver.h:418
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:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
SolverControl::State operator()(const Iterator begin, const Iterator end) const
SolverControl::State operator()(const SolverControl::State state1, const SolverControl::State state2) const