SpECTRE Documentation Coverage Report
Current view: top level - ControlSystem - CleanFunctionsOfTime.hpp Hit Total Coverage
Commit: 3ffcbc8ecf43797401b60bcca17d6040ee06f013 Lines: 3 17 17.6 %
Date: 2026-03-03 02:01:44
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 <pup.h>
       8             : #include <string>
       9             : #include <unordered_map>
      10             : 
      11             : #include "IO/Observer/ObserverComponent.hpp"
      12             : #include "Options/String.hpp"
      13             : #include "Parallel/ArrayCollection/IsDgElementCollection.hpp"
      14             : #include "Parallel/GlobalCache.hpp"
      15             : #include "Parallel/Reduction.hpp"
      16             : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
      17             : #include "Utilities/ErrorHandling/Error.hpp"
      18             : #include "Utilities/Functional.hpp"
      19             : #include "Utilities/Serialization/CharmPupable.hpp"
      20             : #include "Utilities/TMPL.hpp"
      21             : 
      22             : /// \cond
      23             : namespace Tags {
      24             : struct Time;
      25             : }  // namespace Tags
      26             : namespace control_system::Tags {
      27             : struct MeasurementTimescales;
      28             : }  // namespace control_system::Tags
      29             : namespace db {
      30             : template <typename TagsList>
      31             : class DataBox;
      32             : }  // namespace db
      33             : namespace domain::FunctionsOfTime {
      34             : class FunctionOfTime;
      35             : }  // namespace domain::FunctionsOfTime
      36             : namespace domain::Tags {
      37             : struct FunctionsOfTime;
      38             : }  // namespace domain::Tags
      39             : namespace gsl {
      40             : template <class T>
      41             : class not_null;
      42             : }  // namespace gsl
      43             : /// \endcond
      44             : 
      45             : namespace control_system {
      46             : /// \ingroup ControlSystemGroup
      47             : /// Reduction action that deletes function-of-time data from before
      48             : /// the passed time.
      49             : ///
      50             : /// \see CleanFunctionsOfTime
      51           1 : struct CleanFunctionsOfTimeAction {
      52             :  private:
      53           0 :   struct CleanFunc {
      54           0 :     static void apply(
      55             :         gsl::not_null<std::unordered_map<
      56             :             std::string,
      57             :             std::unique_ptr<domain::FunctionsOfTime::FunctionOfTime>>*>
      58             :             functions,
      59             :         double time);
      60             :   };
      61             : 
      62             :  public:
      63             :   template <typename ParallelComponent, typename DbTags, typename Metavariables,
      64             :             typename ArrayIndex>
      65           0 :   static void apply(db::DataBox<DbTags>& /*box*/,
      66             :                     Parallel::GlobalCache<Metavariables>& cache,
      67             :                     const ArrayIndex& /*array_index*/, const double time) {
      68             :     Parallel::mutate<domain::Tags::FunctionsOfTime, CleanFunc>(cache, time);
      69             :     Parallel::mutate<Tags::MeasurementTimescales, CleanFunc>(cache, time);
      70             :   }
      71             : };
      72             : 
      73             : /// \ingroup ControlSystemGroup
      74             : /// Delete old function-of-time data to save memory.
      75             : ///
      76             : /// \warning Running this event will make the
      77             : /// `global_functions_of_time` data stored in the output files
      78             : /// useless.
      79           1 : class CleanFunctionsOfTime : public Event {
      80           0 :   using ReductionData = Parallel::ReductionData<
      81             :       Parallel::ReductionDatum<double, funcl::AssertEqual<>>>;
      82             : 
      83             :  public:
      84             :   /// \cond
      85             :   explicit CleanFunctionsOfTime(CkMigrateMessage* m);
      86             :   using PUP::able::register_constructor;
      87             :   WRAPPED_PUPable_decl_template(CleanFunctionsOfTime);  // NOLINT
      88             :   /// \endcond
      89             : 
      90           0 :   using options = tmpl::list<>;
      91           0 :   static constexpr Options::String help =
      92             :       "Delete old function-of-time data to save memory.\n"
      93             :       "\n"
      94             :       "WARNING: Running this event will make the global_functions_of_time\n"
      95             :       "data stored in the output files useless.";
      96             : 
      97           0 :   CleanFunctionsOfTime() = default;
      98             : 
      99           0 :   using compute_tags_for_observation_box = tmpl::list<>;
     100             : 
     101           0 :   using return_tags = tmpl::list<>;
     102           0 :   using argument_tags = tmpl::list<::Tags::Time>;
     103             : 
     104             :   template <typename Metavariables, typename ArrayIndex,
     105             :             typename ParallelComponent>
     106           0 :   void operator()(const double time,
     107             :                   Parallel::GlobalCache<Metavariables>& cache,
     108             :                   const ArrayIndex& array_index,
     109             :                   const ParallelComponent* const /*meta*/,
     110             :                   const ObservationValue& /*observation_value*/) const {
     111             :     if constexpr (Parallel::is_dg_element_collection_v<ParallelComponent>) {
     112             :       (void)cache;
     113             :       (void)array_index;
     114             :       (void)time;
     115             :       ERROR("Reductions not implemented with DgElementCollection.");
     116             :     } else {
     117             :       // It doesn't matter what individual component the target is.
     118             :       // We use ObserverWriter[0] because it must exist and is easy to
     119             :       // name here.
     120             :       const auto& writer0_proxy = Parallel::get_parallel_component<
     121             :           observers::ObserverWriter<Metavariables>>(cache)[0];
     122             :       const auto& self_proxy =
     123             :           Parallel::get_parallel_component<ParallelComponent>(
     124             :               cache)[array_index];
     125             :       Parallel::contribute_to_reduction<CleanFunctionsOfTimeAction>(
     126             :           ReductionData(time), self_proxy, writer0_proxy);
     127             :     }
     128             :   }
     129             : 
     130           0 :   using is_ready_argument_tags = tmpl::list<>;
     131             : 
     132             :   template <typename Metavariables, typename ArrayIndex, typename Component>
     133           0 :   bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
     134             :                 const ArrayIndex& /*array_index*/,
     135             :                 const Component* const /*meta*/) const {
     136             :     return true;
     137             :   }
     138             : 
     139           1 :   bool needs_evolved_variables() const override;
     140             : };
     141             : }  // namespace control_system

Generated by: LCOV version 1.14