SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem/Actions - Initialization.hpp Hit Total Coverage
Commit: 3c072f0ce967e2e56649d3fa12aa2a0e4fe2a42e Lines: 3 13 23.1 %
Date: 2024-04-23 20:50:18
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 <cstddef>
       7             : #include <memory>
       8             : #include <unordered_map>
       9             : 
      10             : #include "ControlSystem/Averager.hpp"
      11             : #include "ControlSystem/Tags/IsActiveMap.hpp"
      12             : #include "ControlSystem/Tags/MeasurementTimescales.hpp"
      13             : #include "ControlSystem/Tags/SystemTags.hpp"
      14             : #include "ControlSystem/UpdateFunctionOfTime.hpp"
      15             : #include "Domain/Creators/Tags/ObjectCenter.hpp"
      16             : #include "Domain/FunctionsOfTime/FunctionOfTime.hpp"
      17             : #include "Domain/Structure/ObjectLabel.hpp"
      18             : #include "Parallel/GlobalCache.hpp"
      19             : #include "PointwiseFunctions/GeneralRelativity/Surfaces/Tags.hpp"
      20             : #include "Utilities/Gsl.hpp"
      21             : #include "Utilities/TMPL.hpp"
      22             : 
      23           1 : namespace control_system {
      24           1 : namespace Actions {
      25             : namespace detail {
      26             : template <typename Objects>
      27             : struct get_center_tags;
      28             : 
      29             : template <domain::ObjectLabel... Object>
      30             : struct get_center_tags<domain::object_list<Object...>> {
      31             :   using type = tmpl::list<domain::Tags::ObjectCenter<Object>...>;
      32             : };
      33             : 
      34             : template <>
      35             : struct get_center_tags<domain::object_list<>> {
      36             :   using type = tmpl::list<>;
      37             : };
      38             : }  // namespace detail
      39             : 
      40             : /*!
      41             :  * \ingroup ControlSystemGroup
      42             :  * \ingroup InitializationGroup
      43             :  * \brief Initialize items related to the control system
      44             :  *
      45             :  * GlobalCache:
      46             :  * - Uses:
      47             :  *   - `control_system::Tags::MeasurementTimescales`
      48             :  *   - `control_system::Tags::WriteDataToDisk`
      49             :  *   - `control_system::Tags::ObserveCenters`
      50             :  *   - `control_system::Tags::Verbosity`
      51             :  *   - `control_system::Tags::IsActiveMap`
      52             :  *   - `control_system::Tags::SystemToCombinedNames`
      53             :  *   - `domain::Tags::ObjectCenter<domain::ObjectLabel::A>`
      54             :  *   - `domain::Tags::ObjectCenter<domain::ObjectLabel::B>`
      55             :  *
      56             :  * DataBox:
      57             :  * - Uses: Nothing
      58             :  * - Adds:
      59             :  *   - `control_system::Tags::Averager<ControlSystem>`
      60             :  *   - `control_system::Tags::Controller<ControlSystem>`
      61             :  *   - `control_system::Tags::TimescaleTuner<ControlSystem>`
      62             :  *   - `control_system::Tags::ControlError<ControlSystem>`
      63             :  *   - `control_system::Tags::CurrentNumberOfMeasurements`
      64             :  *   - `control_system::Tags::UpdateAggregators`
      65             :  * - Removes: Nothing
      66             :  * - Modifies:
      67             :  *   - `control_system::Tags::Averager<ControlSystem>`
      68             :  *   - `control_system::Tags::CurrentNumberOfMeasurements`
      69             :  *   - `control_system::Tags::UpdateAggregators`
      70             :  */
      71             : template <typename Metavariables, typename ControlSystem>
      72           1 : struct Initialize {
      73           0 :   static constexpr size_t deriv_order = ControlSystem::deriv_order;
      74             : 
      75           0 :   using simple_tags_from_options =
      76             :       tmpl::list<control_system::Tags::Averager<ControlSystem>,
      77             :                  control_system::Tags::Controller<ControlSystem>,
      78             :                  control_system::Tags::TimescaleTuner<ControlSystem>,
      79             :                  control_system::Tags::ControlError<ControlSystem>>;
      80             : 
      81           0 :   using simple_tags =
      82             :       tmpl::push_back<typename ControlSystem::simple_tags,
      83             :                       control_system::Tags::UpdateAggregators,
      84             :                       control_system::Tags::CurrentNumberOfMeasurements>;
      85             : 
      86           0 :   using const_global_cache_tags = tmpl::flatten<tmpl::list<
      87             :       control_system::Tags::SystemToCombinedNames,
      88             :       control_system::Tags::MeasurementsPerUpdate,
      89             :       control_system::Tags::WriteDataToDisk,
      90             :       control_system::Tags::ObserveCenters, control_system::Tags::Verbosity,
      91             :       control_system::Tags::IsActiveMap,
      92             :       typename detail::get_center_tags<
      93             :           typename ControlSystem::control_error::object_centers>::type>>;
      94             : 
      95           0 :   using mutable_global_cache_tags =
      96             :       tmpl::list<control_system::Tags::MeasurementTimescales>;
      97             : 
      98           0 :   using compute_tags = tmpl::list<>;
      99             : 
     100           0 :   using return_tags =
     101             :       tmpl::list<control_system::Tags::Averager<ControlSystem>,
     102             :                  control_system::Tags::CurrentNumberOfMeasurements,
     103             :                  control_system::Tags::UpdateAggregators>;
     104             : 
     105           0 :   using argument_tags = tmpl::list<Parallel::Tags::GlobalCache>;
     106             : 
     107           0 :   static void apply(
     108             :       const gsl::not_null<::Averager<deriv_order - 1>*> averager,
     109             :       const gsl::not_null<int*> current_number_of_measurements,
     110             :       const gsl::not_null<
     111             :           std::unordered_map<std::string, control_system::UpdateAggregator>*>
     112             :           update_aggregators,
     113             :       const Parallel::GlobalCache<Metavariables>* const& cache) {
     114             :     const auto& measurement_timescales =
     115             :         Parallel::get<control_system::Tags::MeasurementTimescales>(*cache);
     116             :     const std::unordered_map<std::string, std::string>&
     117             :         system_to_combined_names =
     118             :             Parallel::get<control_system::Tags::SystemToCombinedNames>(*cache);
     119             :     const auto& measurement_timescale_func = *(measurement_timescales.at(
     120             :         system_to_combined_names.at(ControlSystem::name())));
     121             :     const double initial_time = measurement_timescale_func.time_bounds()[0];
     122             :     const double measurement_timescale =
     123             :         min(measurement_timescale_func.func(initial_time)[0]);
     124             : 
     125             :     averager->assign_time_between_measurements(measurement_timescale);
     126             :     *current_number_of_measurements = 0;
     127             : 
     128             :     const std::unordered_map<std::string, bool>& is_active_map =
     129             :         Parallel::get<control_system::Tags::IsActiveMap>(*cache);
     130             : 
     131             :     std::unordered_map<std::string, std::unordered_set<std::string>>
     132             :         combined_to_system_names{};
     133             :     for (const auto& [control_system_name, combined_name] :
     134             :          system_to_combined_names) {
     135             :       if (combined_to_system_names.count(combined_name) != 1) {
     136             :         combined_to_system_names[combined_name];
     137             :       }
     138             : 
     139             :       // Only add active control systems
     140             :       if (is_active_map.at(control_system_name)) {
     141             :         combined_to_system_names.at(combined_name).insert(control_system_name);
     142             :       }
     143             :     }
     144             : 
     145             :     for (auto& [combined_name, control_system_names] :
     146             :          combined_to_system_names) {
     147             :       (*update_aggregators)[combined_name] = control_system::UpdateAggregator{
     148             :           combined_name, std::move(control_system_names)};
     149             :     }
     150             :   }
     151             : };
     152             : }  // namespace Actions
     153             : }  // namespace control_system

Generated by: LCOV version 1.14