Line data Source code
1 0 : // 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/String.hpp" 13 : #include "Utilities/PrettyType.hpp" 14 : 15 : namespace Convergence { 16 : /// Option tags related to the convergence of iterative algorithms 17 1 : namespace OptionTags { 18 : 19 : template <typename OptionsGroup> 20 0 : struct Criteria { 21 0 : static std::string name() { return "ConvergenceCriteria"; } 22 0 : static constexpr Options::String help = 23 : "Determine convergence of the algorithm"; 24 0 : using type = Convergence::Criteria; 25 0 : using group = OptionsGroup; 26 : }; 27 : 28 : template <typename OptionsGroup> 29 0 : struct Iterations { 30 0 : static constexpr Options::String help = 31 : "Number of iterations to run the algorithm"; 32 0 : using type = size_t; 33 0 : using group = OptionsGroup; 34 : }; 35 : 36 : } // namespace OptionTags 37 : 38 : /// Tags related to the convergence of iterative algorithms 39 1 : namespace Tags { 40 : 41 : /// `Convergence::Criteria` that determine the iterative algorithm has converged 42 : template <typename OptionsGroup> 43 1 : struct Criteria : db::SimpleTag { 44 0 : static std::string name() { 45 : return "ConvergenceCriteria(" + pretty_type::name<OptionsGroup>() + ")"; 46 : } 47 0 : using type = Convergence::Criteria; 48 : 49 0 : using option_tags = tmpl::list<OptionTags::Criteria<OptionsGroup>>; 50 0 : static constexpr bool pass_metavariables = false; 51 0 : static Convergence::Criteria create_from_options( 52 : const Convergence::Criteria& convergence_criteria) { 53 : return convergence_criteria; 54 : } 55 : }; 56 : 57 : /// A fixed number of iterations to run the iterative algorithm 58 : template <typename OptionsGroup> 59 1 : struct Iterations : db::SimpleTag { 60 0 : static std::string name() { 61 : return "Iterations(" + pretty_type::name<OptionsGroup>() + ")"; 62 : } 63 0 : using type = size_t; 64 : 65 0 : static constexpr bool pass_metavariables = false; 66 0 : using option_tags = tmpl::list<OptionTags::Iterations<OptionsGroup>>; 67 0 : static size_t create_from_options(const size_t max_iterations) { 68 : return max_iterations; 69 : } 70 : }; 71 : 72 : /// Identifies a step in an iterative algorithm 73 : template <typename Label> 74 1 : struct IterationId : db::SimpleTag { 75 0 : static std::string name() { 76 : return "IterationId(" + pretty_type::name<Label>() + ")"; 77 : } 78 0 : 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> 86 1 : struct HasConverged : db::SimpleTag { 87 0 : static std::string name() { 88 : return "HasConverged(" + pretty_type::name<Label>() + ")"; 89 : } 90 0 : using type = Convergence::HasConverged; 91 : }; 92 : 93 : } // namespace Tags 94 : } // namespace Convergence