SpECTRE Documentation Coverage Report
Current view: top level - Time/Actions - RecordTimeStepperData.hpp Hit Total Coverage
Commit: 318ae36d2001e2abec5256f34415b420007ed6cc Lines: 2 4 50.0 %
Date: 2024-07-18 18:43:07
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 <optional>
       7             : #include <tuple>
       8             : 
       9             : #include "DataStructures/DataBox/DataBox.hpp"
      10             : #include "DataStructures/DataBox/PrefixHelpers.hpp"
      11             : #include "DataStructures/DataBox/Prefixes.hpp"
      12             : #include "Parallel/AlgorithmExecution.hpp"
      13             : #include "Time/Tags/HistoryEvolvedVariables.hpp"
      14             : #include "Utilities/Gsl.hpp"
      15             : #include "Utilities/TMPL.hpp"
      16             : #include "Utilities/TaggedTuple.hpp"
      17             : 
      18             : /// \cond
      19             : class TimeStepId;
      20             : namespace Parallel {
      21             : template <typename Metavariables>
      22             : class GlobalCache;
      23             : }  // namespace Parallel
      24             : namespace Tags {
      25             : struct TimeStepId;
      26             : }  // namespace Tags
      27             : /// \endcond
      28             : 
      29             : namespace record_time_stepper_data_detail {
      30             : template <typename System, typename VariablesTag, typename DbTags>
      31             : void record_one_variables(const gsl::not_null<db::DataBox<DbTags>*> box) {
      32             :   using dt_variables_tag = db::add_tag_prefix<Tags::dt, VariablesTag>;
      33             :   using history_tag = Tags::HistoryEvolvedVariables<VariablesTag>;
      34             : 
      35             :   db::mutate<history_tag>(
      36             :       [](const gsl::not_null<typename history_tag::type*> history,
      37             :          const TimeStepId& time_step_id,
      38             :          const typename VariablesTag::type& vars,
      39             :          const typename dt_variables_tag::type& dt_vars) {
      40             :         history->insert(time_step_id, vars, dt_vars);
      41             :       },
      42             :       box, db::get<Tags::TimeStepId>(*box), db::get<VariablesTag>(*box),
      43             :       db::get<dt_variables_tag>(*box));
      44             : }
      45             : }  // namespace record_time_stepper_data_detail
      46             : 
      47             : /// Records the variables and their time derivatives in the time stepper
      48             : /// history.
      49             : ///
      50             : /// \note this is a free function version of `Actions::RecordTimeStepperData`.
      51             : /// This free function alternative permits the inclusion of the time step
      52             : /// procedure in the middle of another action.
      53             : template <typename System, typename DbTags>
      54           1 : void record_time_stepper_data(const gsl::not_null<db::DataBox<DbTags>*> box) {
      55             :   if constexpr (tt::is_a_v<tmpl::list, typename System::variables_tag>) {
      56             :     // The system has multiple evolved variables, probably because
      57             :     // there is a mixture of real and complex values or similar.  Step
      58             :     // all of them.
      59             :     tmpl::for_each<typename System::variables_tag>([&](auto tag) {
      60             :       record_time_stepper_data_detail::record_one_variables<
      61             :           System, tmpl::type_from<decltype(tag)>>(box);
      62             :     });
      63             :   } else {
      64             :     record_time_stepper_data_detail::record_one_variables<
      65             :         System, typename System::variables_tag>(box);
      66             :   }
      67             : }
      68             : 
      69             : namespace Actions {
      70             : /// \ingroup ActionsGroup
      71             : /// \ingroup TimeGroup
      72             : /// \brief Records the variables and their time derivatives in the
      73             : /// time stepper history.
      74             : ///
      75             : /// With `dt_variables_tag = db::add_tag_prefix<Tags::dt, variables_tag>`:
      76             : ///
      77             : /// Uses:
      78             : /// - GlobalCache: nothing
      79             : /// - DataBox:
      80             : ///   - System::variables_tag
      81             : ///   - dt_variables_tag
      82             : ///   - Tags::HistoryEvolvedVariables<variables_tag>
      83             : ///   - Tags::TimeStepId
      84             : ///
      85             : /// DataBox changes:
      86             : /// - Tags::HistoryEvolvedVariables<variables_tag>
      87             : template <typename System>
      88           1 : struct RecordTimeStepperData {
      89             :   template <typename DbTags, typename... InboxTags, typename Metavariables,
      90             :             typename ArrayIndex, typename ActionList,
      91             :             typename ParallelComponent>
      92           0 :   static Parallel::iterable_action_return_t apply(
      93             :       db::DataBox<DbTags>& box, tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
      94             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
      95             :       const ArrayIndex& /*array_index*/, ActionList /*meta*/,
      96             :       const ParallelComponent* const /*meta*/) {  // NOLINT const
      97             :     record_time_stepper_data<System>(make_not_null(&box));
      98             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
      99             :   }
     100             : };
     101             : }  // namespace Actions

Generated by: LCOV version 1.14