Tags.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include <cstddef>
7 #include <string>
8 
9 #include "DataStructures/DataBox/Tag.hpp"
10 #include "NumericalAlgorithms/Convergence/Criteria.hpp"
11 #include "NumericalAlgorithms/Convergence/HasConverged.hpp"
12 #include "Options/Options.hpp"
13 #include "Utilities/PrettyType.hpp"
14 
15 namespace Convergence {
16 /// Option tags related to the convergence of iterative algorithms
17 namespace OptionTags {
18 
19 template <typename OptionsGroup>
20 struct Criteria {
21  static std::string name() noexcept { return "ConvergenceCriteria"; }
22  static constexpr Options::String help =
23  "Determine convergence of the algorithm";
25  using group = OptionsGroup;
26 };
27 
28 template <typename OptionsGroup>
29 struct Iterations {
30  static constexpr Options::String help =
31  "Number of iterations to run the algorithm";
32  using type = size_t;
33  using group = OptionsGroup;
34 };
35 
36 } // namespace OptionTags
37 
38 /// Tags related to the convergence of iterative algorithms
39 namespace Tags {
40 
41 /// `Convergence::Criteria` that determine the iterative algorithm has converged
42 template <typename OptionsGroup>
44  static std::string name() noexcept {
45  return "ConvergenceCriteria(" + Options::name<OptionsGroup>() + ")";
46  }
48 
49  using option_tags = tmpl::list<OptionTags::Criteria<OptionsGroup>>;
50  static constexpr bool pass_metavariables = false;
51  static Convergence::Criteria create_from_options(
52  const Convergence::Criteria& convergence_criteria) noexcept {
53  return convergence_criteria;
54  }
55 };
56 
57 /// A fixed number of iterations to run the iterative algorithm
58 template <typename OptionsGroup>
60  static std::string name() noexcept {
61  return "Iterations(" + Options::name<OptionsGroup>() + ")";
62  }
63  using type = size_t;
64 
65  static constexpr bool pass_metavariables = false;
66  using option_tags = tmpl::list<OptionTags::Iterations<OptionsGroup>>;
67  static size_t create_from_options(const size_t max_iterations) noexcept {
68  return max_iterations;
69  }
70 };
71 
72 /// Identifies a step in an iterative algorithm
73 template <typename Label>
75  static std::string name() noexcept {
76  return "IterationId(" + pretty_type::short_name<Label>() + ")";
77  }
78  using type = size_t;
79 };
80 
81 /*!
82  * \brief Holds a `Convergence::HasConverged` flag that signals the iterative
83  * algorithm has converged, along with the reason for convergence.
84  */
85 template <typename Label>
87  static std::string name() noexcept {
88  return "HasConverged(" + pretty_type::short_name<Label>() + ")";
89  }
91 };
92 
93 } // namespace Tags
94 } // namespace Convergence
std::string
Options.hpp
Convergence::Criteria
Criteria that determine an iterative algorithm has converged.
Definition: Criteria.hpp:35
PrettyType.hpp
Convergence::OptionTags::Iterations
Definition: Tags.hpp:29
db::SimpleTag
Mark a struct as a simple tag by inheriting from this.
Definition: Tag.hpp:36
Convergence::HasConverged
Signals convergence of the algorithm.
Definition: HasConverged.hpp:59
Convergence
Items related to checking the convergence of numerical algorithms.
Definition: Convergence.hpp:10
cstddef
Convergence::Tags::Iterations
A fixed number of iterations to run the iterative algorithm.
Definition: Tags.hpp:59
Convergence::Tags::IterationId
Identifies a step in an iterative algorithm.
Definition: Tags.hpp:74
Options::String
const char *const String
The string used in option structs.
Definition: Options.hpp:32
Convergence::Tags::Criteria
Convergence::Criteria that determine the iterative algorithm has converged
Definition: Tags.hpp:43
Convergence::Tags::HasConverged
Holds a Convergence::HasConverged flag that signals the iterative algorithm has converged,...
Definition: Tags.hpp:86
Convergence::OptionTags::Criteria
Definition: Tags.hpp:20
string