SpECTRE Documentation Coverage Report
Current view: top level - Evolution/Systems/Cce/Events - ObserveTimeStep.hpp Hit Total Coverage
Commit: 965048f86d23c819715b3af1ca3f880c8145d4bb Lines: 3 24 12.5 %
Date: 2024-05-16 17:00:40
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 <pup.h>
       8             : #include <pup_stl.h>
       9             : #include <string>
      10             : #include <tuple>
      11             : #include <vector>
      12             : 
      13             : #include "IO/Observer/ObserverComponent.hpp"
      14             : #include "IO/Observer/ReductionActions.hpp"
      15             : #include "Options/String.hpp"
      16             : #include "Parallel/GlobalCache.hpp"
      17             : #include "Parallel/Invoke.hpp"
      18             : #include "Parallel/Printf/Printf.hpp"
      19             : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
      20             : #include "Time/Time.hpp"
      21             : #include "Utilities/Serialization/CharmPupable.hpp"
      22             : #include "Utilities/System/ParallelInfo.hpp"
      23             : #include "Utilities/TMPL.hpp"
      24             : 
      25             : /// \cond
      26             : namespace Tags {
      27             : struct TimeStep;
      28             : }  // namespace Tags
      29             : /// \endcond
      30             : 
      31             : namespace Cce::Events {
      32             : 
      33             : /*!
      34             :  * \brief %Observe the size of the time steps on the characteristic evolution.
      35             :  *
      36             :  * Writes reduction quantities:
      37             :  * - `%Time`
      38             :  * - `Time Step`
      39             :  *
      40             :  * The subfile will be written into the `/Cce` subgroup.
      41             :  */
      42           1 : class ObserveTimeStep : public Event {
      43             :  public:
      44             :   /// The name of the subfile inside the HDF5 file
      45           1 :   struct SubfileName {
      46           0 :     using type = std::string;
      47           0 :     static constexpr Options::String help = {
      48             :         "The name of the subfile inside the HDF5 file without an extension and "
      49             :         "without a preceding '/'. The subfile will be written into the "
      50             :         "subgroup '/Cce'."};
      51             :   };
      52             : 
      53           0 :   struct PrintTimeToTerminal {
      54           0 :     using type = bool;
      55           0 :     static constexpr Options::String help = {
      56             :         "Whether to print the time to screen."};
      57             :   };
      58             : 
      59             :   /// \cond
      60             :   explicit ObserveTimeStep(CkMigrateMessage* /*unused*/) {}
      61             :   using PUP::able::register_constructor;
      62             :   WRAPPED_PUPable_decl_template(ObserveTimeStep);  // NOLINT
      63             :   /// \endcond
      64             : 
      65           0 :   using options = tmpl::list<SubfileName, PrintTimeToTerminal>;
      66           0 :   static constexpr Options::String help =
      67             :       "Observe the size of the time step for the characteristic evolution.\n"
      68             :       "\n"
      69             :       "Writes quantities:\n"
      70             :       "- Time\n"
      71             :       "- Time Step\n"
      72             :       "\n"
      73             :       "The subfile will be written into the subgroup '/Cce'.";
      74             : 
      75           0 :   ObserveTimeStep() = default;
      76           0 :   explicit ObserveTimeStep(const std::string& subfile_name,
      77             :                            const bool output_time);
      78             : 
      79           0 :   using observed_reduction_data_tags = tmpl::list<>;
      80             : 
      81           0 :   using compute_tags_for_observation_box = tmpl::list<>;
      82             : 
      83           0 :   using return_tags = tmpl::list<>;
      84           0 :   using argument_tags = tmpl::list<::Tags::TimeStep>;
      85             : 
      86             :   template <typename ArrayIndex, typename ParallelComponent,
      87             :             typename Metavariables>
      88           0 :   void operator()(const TimeDelta& time_step,
      89             :                   Parallel::GlobalCache<Metavariables>& cache,
      90             :                   const ArrayIndex& /*array_index*/,
      91             :                   const ParallelComponent* const /*meta*/,
      92             :                   const ObservationValue& observation_value) const {
      93             :     std::vector<double> data_to_write{observation_value.value,
      94             :                                       time_step.value()};
      95             : 
      96             :     auto& writer = Parallel::get_parallel_component<
      97             :         observers::ObserverWriter<Metavariables>>(cache);
      98             : 
      99             :     Parallel::threaded_action<
     100             :         observers::ThreadedActions::WriteReductionDataRow>(
     101             :         writer[0], subfile_path_, legend_,
     102             :         std::make_tuple(std::move(data_to_write)));
     103             : 
     104             :     if (output_time_) {
     105             :       Parallel::printf(
     106             :           "Simulation time: %s\n"
     107             :           "  Wall time: %s\n",
     108             :           std::to_string(observation_value.value), sys::pretty_wall_time());
     109             :     }
     110             :   }
     111             : 
     112           0 :   using is_ready_argument_tags = tmpl::list<>;
     113             : 
     114             :   template <typename Metavariables, typename ArrayIndex, typename Component>
     115           0 :   bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
     116             :                 const ArrayIndex& /*array_index*/,
     117             :                 const Component* const /*meta*/) const {
     118             :     return true;
     119             :   }
     120             : 
     121           1 :   bool needs_evolved_variables() const override { return false; }
     122             : 
     123             :   // NOLINTNEXTLINE(google-runtime-references)
     124           0 :   void pup(PUP::er& p) override {
     125             :     Event::pup(p);
     126             :     p | subfile_path_;
     127             :     p | output_time_;
     128             :     p | legend_;
     129             :   }
     130             : 
     131             :  private:
     132           0 :   std::string subfile_path_;
     133           0 :   bool output_time_;
     134           0 :   std::vector<std::string> legend_;
     135             : };
     136             : 
     137             : ObserveTimeStep::ObserveTimeStep(const std::string& subfile_name,
     138             :                                  const bool output_time)
     139             :     : subfile_path_("/Cce/" + subfile_name),
     140             :       output_time_(output_time),
     141             :       legend_(std::vector<std::string>{"Time", "Time Step"}) {}
     142             : 
     143             : /// \cond
     144             : PUP::able::PUP_ID ObserveTimeStep::my_PUP_ID = 0;  // NOLINT
     145             : /// \endcond
     146             : }  // namespace Cce::Events

Generated by: LCOV version 1.14