deal.II version GIT relicensing-2206-gaa53ff9447 2024-12-02 09:10:00+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 - 2024 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
22
25
26#include <boost/signals2.hpp>
27
29
30// Forward declaration
31#ifndef DOXYGEN
32template <typename number>
33class Vector;
34#endif
35
339template <typename 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#ifndef DOXYGEN
478
479template <typename VectorType>
482 const SolverControl::State state1,
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 <typename VectorType>
497template <typename Iterator>
500 const Iterator end) const
501{
502 Assert(begin != end,
503 ExcMessage("You can't combine iterator states if no state is given."));
504
505 // combine the first with all of the following states
507 Iterator p = begin;
508 ++p;
509 for (; p != end; ++p)
510 state = this->operator()(state, *p);
511
512 return state;
513}
514
515
516template <typename VectorType>
519 SolverControl &solver_control,
520 VectorMemory<VectorType> &vector_memory)
521 : memory(vector_memory)
522{
523 // connect the solver control object to the signal. SolverControl::check
524 // only takes two arguments, the iteration and the check_value, and so
525 // we simply ignore the third argument that is passed in whenever the
526 // signal is executed
527 connect([&solver_control](const unsigned int iteration,
528 const double check_value,
529 const VectorType &) {
530 return solver_control.check(iteration, check_value);
531 });
532}
533
534
535
536template <typename VectorType>
539 : // use the static memory object this class owns
540 memory(static_vector_memory)
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
555template <typename VectorType>
557inline boost::signals2::connection SolverBase<VectorType>::connect(
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#endif
567
569
570#endif
boost::signals2::signal< SolverControl::State(const unsigned int iteration, const double check_value, const VectorType &current_iterate), StateCombiner > iteration_status
Definition solver.h:471
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: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.
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:498
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:175
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:499
#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