SpECTRE Documentation Coverage Report
Current view: top level - Time/Actions - UpdateU.hpp Hit Total Coverage
Commit: eded15d6fcfa762a5dfde087b28df9bcedd8b386 Lines: 3 4 75.0 %
Date: 2024-04-15 22:23:51
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines action UpdateU
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <optional>
      10             : #include <tuple>
      11             : #include <utility>  // IWYU pragma: keep // for std::move
      12             : 
      13             : #include "DataStructures/DataBox/DataBox.hpp"
      14             : #include "DataStructures/DataBox/Prefixes.hpp"
      15             : #include "Parallel/AlgorithmExecution.hpp"
      16             : #include "Time/Tags/HistoryEvolvedVariables.hpp"
      17             : #include "Time/Tags/PreviousStepperError.hpp"
      18             : #include "Time/Tags/StepperError.hpp"
      19             : #include "Time/TimeSteppers/TimeStepper.hpp"
      20             : #include "Utilities/Gsl.hpp"
      21             : #include "Utilities/SetNumberOfGridPoints.hpp"
      22             : #include "Utilities/TMPL.hpp"
      23             : #include "Utilities/TaggedTuple.hpp"
      24             : #include "Utilities/TypeTraits/IsA.hpp"
      25             : 
      26             : // IWYU pragma: no_include "Time/Time.hpp" // for TimeDelta
      27             : 
      28             : /// \cond
      29             : namespace Parallel {
      30             : template <typename Metavariables>
      31             : class GlobalCache;
      32             : }  // namespace Parallel
      33             : namespace Tags {
      34             : struct IsUsingTimeSteppingErrorControl;
      35             : struct StepperErrorUpdated;
      36             : struct TimeStep;
      37             : template <typename StepperInterface>
      38             : struct TimeStepper;
      39             : }  // namespace Tags
      40             : /// \endcond
      41             : 
      42             : namespace update_u_detail {
      43             : template <typename System, typename VariablesTag, typename DbTags>
      44             : void update_one_variables(const gsl::not_null<db::DataBox<DbTags>*> box) {
      45             :   using history_tag = Tags::HistoryEvolvedVariables<VariablesTag>;
      46             :   bool is_using_error_control = false;
      47             :   if constexpr (db::tag_is_retrievable_v<Tags::IsUsingTimeSteppingErrorControl,
      48             :                                          db::DataBox<DbTags>>) {
      49             :     is_using_error_control =
      50             :         db::get<Tags::IsUsingTimeSteppingErrorControl>(*box);
      51             :   }
      52             :   if (is_using_error_control) {
      53             :     using error_tag = ::Tags::StepperError<VariablesTag>;
      54             :     using previous_error_tag = ::Tags::PreviousStepperError<VariablesTag>;
      55             :     if constexpr (tmpl::list_contains_v<DbTags, error_tag>) {
      56             :       db::mutate<Tags::StepperErrorUpdated, VariablesTag, error_tag,
      57             :                  previous_error_tag, history_tag>(
      58             :           [](const gsl::not_null<bool*> stepper_error_updated,
      59             :              const gsl::not_null<typename VariablesTag::type*> vars,
      60             :              const gsl::not_null<typename error_tag::type*> error,
      61             :              const gsl::not_null<typename previous_error_tag::type*>
      62             :                  previous_error,
      63             :              const gsl::not_null<typename history_tag::type*> history,
      64             :              const ::TimeDelta& time_step, const TimeStepper& time_stepper) {
      65             :             using std::swap;
      66             :             set_number_of_grid_points(previous_error, *vars);
      67             :             swap(*error, *previous_error);
      68             :             *stepper_error_updated = time_stepper.update_u(
      69             :                 vars, make_not_null(&*error), history, time_step);
      70             :             if (not *stepper_error_updated) {
      71             :               swap(*error, *previous_error);
      72             :             }
      73             :           },
      74             :           box, db::get<Tags::TimeStep>(*box),
      75             :           db::get<Tags::TimeStepper<TimeStepper>>(*box));
      76             :     } else {
      77             :       ERROR(
      78             :           "Cannot update the stepper error measure -- "
      79             :           "`::Tags::StepperError<VariablesTag>` is not present in the box.");
      80             :     }
      81             :   } else {
      82             :     db::mutate<VariablesTag, history_tag>(
      83             :         [](const gsl::not_null<typename VariablesTag::type*> vars,
      84             :            const gsl::not_null<typename history_tag::type*> history,
      85             :            const ::TimeDelta& time_step, const TimeStepper& time_stepper) {
      86             :           time_stepper.update_u(vars, history, time_step);
      87             :         },
      88             :         box, db::get<Tags::TimeStep>(*box),
      89             :         db::get<Tags::TimeStepper<TimeStepper>>(*box));
      90             :   }
      91             : }
      92             : }  // namespace update_u_detail
      93             : 
      94             : /// Perform variable updates for one substep for a substep method, or one step
      95             : /// for an LMM method.
      96             : ///
      97             : /// \note This is a free function version of `Actions::UpdateU`. This free
      98             : /// function alternative permits the inclusion of the time step procedure in
      99             : /// the middle of another action.
     100             : template <typename System, typename DbTags>
     101           1 : void update_u(const gsl::not_null<db::DataBox<DbTags>*> box) {
     102             :   if constexpr (tt::is_a_v<tmpl::list, typename System::variables_tag>) {
     103             :     // The system has multiple evolved variables, probably because
     104             :     // there is a mixture of real and complex values or similar.  Step
     105             :     // all of them.
     106             :     tmpl::for_each<typename System::variables_tag>([&](auto tag) {
     107             :       update_u_detail::update_one_variables<System,
     108             :                                             tmpl::type_from<decltype(tag)>>(
     109             :           box);
     110             :     });
     111             :   } else {
     112             :     update_u_detail::update_one_variables<System,
     113             :                                           typename System::variables_tag>(box);
     114             :   }
     115             : }
     116             : 
     117             : namespace Actions {
     118             : /// \ingroup ActionsGroup
     119             : /// \ingroup TimeGroup
     120             : /// \brief Perform variable updates for one substep
     121             : ///
     122             : /// Uses:
     123             : /// - DataBox:
     124             : ///   - system::variables_tag
     125             : ///   - Tags::HistoryEvolvedVariables<variables_tag>
     126             : ///   - Tags::TimeStep
     127             : ///   - Tags::TimeStepper<TimeStepper>
     128             : ///   - Tags::IsUsingTimeSteppingErrorControl
     129             : ///
     130             : /// DataBox changes:
     131             : /// - Adds: nothing
     132             : /// - Removes: nothing
     133             : /// - Modifies:
     134             : ///   - variables_tag
     135             : ///   - Tags::HistoryEvolvedVariables<variables_tag>
     136             : template <typename System>
     137           1 : struct UpdateU {
     138             :   template <typename DbTags, typename... InboxTags, typename Metavariables,
     139             :             typename ArrayIndex, typename ActionList,
     140             :             typename ParallelComponent>
     141           0 :   static Parallel::iterable_action_return_t apply(
     142             :       db::DataBox<DbTags>& box, tuples::TaggedTuple<InboxTags...>& /*inboxes*/,
     143             :       const Parallel::GlobalCache<Metavariables>& /*cache*/,
     144             :       const ArrayIndex& /*array_index*/, ActionList /*meta*/,
     145             :       const ParallelComponent* const /*meta*/) {  // NOLINT const
     146             :     update_u<System>(make_not_null(&box));
     147             :     return {Parallel::AlgorithmExecution::Continue, std::nullopt};
     148             :   }
     149             : };
     150             : }  // namespace Actions

Generated by: LCOV version 1.14