Reference documentation for deal.II version GIT relicensing-384-g4769914377 2024-04-13 09:00:02+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: LGPL-2.1-or-later
4// Copyright (C) 1998 - 2023 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Part of the source code is dual licensed under Apache-2.0 WITH
9// LLVM-exception OR LGPL-2.1-or-later. Detailed license information
10// governing the source code and code contributions can be found in
11// LICENSE.md and CONTRIBUTING.md at the top level directory of deal.II.
12//
13// ------------------------------------------------------------------------
14
15#ifndef dealii_solver_h
16#define dealii_solver_h
17
18#include <deal.II/base/config.h>
19
21
24
25#include <boost/signals2.hpp>
26
28
29// Forward declaration
30#ifndef DOXYGEN
31template <typename number>
32class Vector;
33#endif
34
338template <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>
494template <typename Iterator>
497 const Iterator end) const
498{
499 Assert(begin != end,
500 ExcMessage("You can't combine iterator states if no state is given."));
501
502 // combine the first with all of the following states
504 Iterator p = begin;
505 ++p;
506 for (; p != end; ++p)
507 state = this->operator()(state, *p);
508
509 return state;
510}
511
512
513template <typename VectorType>
515 SolverControl &solver_control,
516 VectorMemory<VectorType> &vector_memory)
517 : memory(vector_memory)
518{
519 // connect the solver control object to the signal. SolverControl::check
520 // only takes two arguments, the iteration and the check_value, and so
521 // we simply ignore the third argument that is passed in whenever the
522 // signal is executed
523 connect([&solver_control](const unsigned int iteration,
524 const double check_value,
525 const VectorType &) {
526 return solver_control.check(iteration, check_value);
527 });
528}
529
530
531
532template <typename VectorType>
534 : // use the static memory object this class owns
535 memory(static_vector_memory)
536{
537 // connect the solver control object to the signal. SolverControl::check
538 // only takes two arguments, the iteration and the check_value, and so
539 // we simply ignore the third argument that is passed in whenever the
540 // signal is executed
541 connect([&solver_control](const unsigned int iteration,
542 const double check_value,
543 const VectorType &) {
544 return solver_control.check(iteration, check_value);
545 });
546}
547
548
549
550template <typename VectorType>
551inline boost::signals2::connection
553 const std::function<SolverControl::State(const unsigned int iteration,
554 const double check_value,
555 const VectorType &current_iterate)>
556 &slot)
557{
558 return iteration_status.connect(slot);
559}
560
561#endif
562
564
565#endif
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:502
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:503
#define Assert(cond, exc)
static ::ExceptionBase & ExcMessage(std::string arg1)
spacedim const Point< spacedim > & p
Definition grid_tools.h:990
const Iterator const std_cxx20::type_identity_t< Iterator > & end
Definition parallel.h:610
const Iterator & begin
Definition parallel.h:609
SolverControl::State operator()(const Iterator begin, const Iterator end) const
SolverControl::State operator()(const SolverControl::State state1, const SolverControl::State state2) const