SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/Tags - FunctionsOfTimeInitialize.hpp Hit Total Coverage
Commit: d0fc80462417e83e5cddfa1b9901bb4a9b6af4d6 Lines: 4 11 36.4 %
Date: 2024-03-29 00:33:31
Legend: Lines: hit not hit

          Line data    Source code
       1           0 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : #pragma once
       5             : 
       6             : #include <memory>
       7             : #include <string>
       8             : #include <type_traits>
       9             : #include <unordered_map>
      10             : 
      11             : #include "ControlSystem/ExpirationTimes.hpp"
      12             : #include "ControlSystem/Tags/IsActiveMap.hpp"
      13             : #include "ControlSystem/Tags/OptionTags.hpp"
      14             : #include "ControlSystem/Tags/SystemTags.hpp"
      15             : #include "DataStructures/DataBox/Tag.hpp"
      16             : #include "Domain/Creators/OptionTags.hpp"
      17             : #include "Domain/Creators/Tags/FunctionsOfTime.hpp"
      18             : #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
      19             : #include "Domain/FunctionsOfTime/Tags.hpp"
      20             : #include "Time/OptionTags/InitialTime.hpp"
      21             : #include "Time/OptionTags/InitialTimeStep.hpp"
      22             : #include "Utilities/TMPL.hpp"
      23             : #include "Utilities/TypeTraits/IsA.hpp"
      24             : 
      25             : /// \cond
      26             : template <class Metavariables, typename ControlSystem>
      27             : struct ControlComponent;
      28             : /// \endcond
      29             : 
      30           1 : namespace control_system::Tags {
      31             : namespace detail {
      32             : // Check that all control systems are actually controlling a function of
      33             : // time, and that the expiration times have been set appropriately. If there
      34             : // exists a control system that isn't controlling a function of time, or the
      35             : // expiration times were set improperly, this is an error and we shouldn't
      36             : // continue.
      37             : void check_expiration_time_consistency(
      38             :     const std::unordered_map<std::string, double>& initial_expiration_times,
      39             :     const std::unordered_map<std::string, bool>& is_active_map,
      40             :     const std::unordered_map<
      41             :         std::string, std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>&
      42             :         functions_of_time);
      43             : }  // namespace detail
      44             : 
      45             : /// \ingroup ControlSystemGroup
      46             : /// The FunctionsOfTime initialized from a DomainCreator, initial time, and
      47             : /// control system OptionHolders.
      48           1 : struct FunctionsOfTimeInitialize : domain::Tags::FunctionsOfTime,
      49             :                                    db::SimpleTag {
      50           0 :   using type = std::unordered_map<
      51             :       std::string, std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>;
      52             : 
      53           0 :   static constexpr bool pass_metavariables = true;
      54             : 
      55           0 :   static std::string name() { return "FunctionsOfTime"; }
      56             : 
      57             :   template <typename Metavariables>
      58           0 :   using option_holders = control_system::inputs<
      59             :       tmpl::transform<tmpl::filter<typename Metavariables::component_list,
      60             :                                    tt::is_a<ControlComponent, tmpl::_1>>,
      61             :                       tmpl::bind<tmpl::back, tmpl::_1>>>;
      62             : 
      63             :   template <typename Metavariables>
      64           0 :   static constexpr bool metavars_has_control_systems =
      65             :       tmpl::size<option_holders<Metavariables>>::value > 0;
      66             : 
      67             :   template <typename Metavariables>
      68           0 :   using option_tags = tmpl::push_front<
      69             :       tmpl::conditional_t<
      70             :           metavars_has_control_systems<Metavariables>,
      71             :           tmpl::flatten<tmpl::list<
      72             :               control_system::OptionTags::MeasurementsPerUpdate,
      73             :               ::OptionTags::InitialTime, option_holders<Metavariables>>>,
      74             :           tmpl::list<>>,
      75             :       domain::OptionTags::DomainCreator<Metavariables::volume_dim>>;
      76             : 
      77             :   /// This version of create_from_options is used if the metavariables did
      78             :   /// define control systems
      79             :   template <typename Metavariables, typename... OptionHolders>
      80           1 :   static type create_from_options(
      81             :       const std::unique_ptr<::DomainCreator<Metavariables::volume_dim>>&
      82             :           domain_creator,
      83             :       const int measurements_per_update,
      84             :      const double initial_time, const OptionHolders&... option_holders) {
      85             :     const auto initial_expiration_times =
      86             :         control_system::initial_expiration_times(
      87             :             initial_time, measurements_per_update, domain_creator,
      88             :             option_holders...);
      89             : 
      90             :     // We need to check the expiration times so we can ensure a proper domain
      91             :     // creator was chosen from options.
      92             :     auto functions_of_time =
      93             :         domain_creator->functions_of_time(initial_expiration_times);
      94             : 
      95             :     const auto is_active_map = detail::create_is_active_map(option_holders...);
      96             : 
      97             :     detail::check_expiration_time_consistency(initial_expiration_times,
      98             :                                               is_active_map, functions_of_time);
      99             : 
     100             :     return functions_of_time;
     101             :   }
     102             : 
     103             :   /// This version of create_from_options is used if the metavariables did not
     104             :   /// define control systems
     105             :   template <typename Metavariables>
     106           1 :   static type create_from_options(
     107             :      const std::unique_ptr<::DomainCreator<Metavariables::volume_dim>>&
     108             :           domain_creator) {
     109             :     return domain_creator->functions_of_time();
     110             :   }
     111             : };
     112             : }  // namespace control_system::Tags

Generated by: LCOV version 1.14