Line data Source code
1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : #include <cstddef> 6 : #include "DataStructures/DataBox/Prefixes.hpp" 7 : #include "DataStructures/Variables.hpp" 8 : #include "DataStructures/VariablesTag.hpp" 9 : #include "Evolution/Systems/CurvedScalarWave/Worldtube/Tags.hpp" 10 : #include "Time/Tags/HistoryEvolvedVariables.hpp" 11 : #include "Time/TimeSteppers/TimeStepper.hpp" 12 : #include "Utilities/Gsl.hpp" 13 : /// \cond 14 : namespace Tags { 15 : template <typename StepperInterface> 16 : struct TimeStepper; 17 : } // namespace Tags 18 : /// \endcond 19 : namespace CurvedScalarWave::Worldtube::Initialization { 20 : /*! 21 : * \brief Initializes the time stepper and evolved variables used by the 22 : * worldtube system. Also sets `Tags::CurrentIteration` to 0. 23 : * 24 : * \details Sets the initial position and velocity of the particle to the values 25 : * specified in the input file. The time stepper history is set analogous to the 26 : * elements which use the same time stepper. 27 : */ 28 1 : struct InitializeEvolvedVariables { 29 0 : static constexpr size_t Dim = 3; 30 0 : using variables_tag = ::Tags::Variables< 31 : tmpl::list<Tags::EvolvedPosition<Dim>, Tags::EvolvedVelocity<Dim>>>; 32 0 : using dt_variables_tag = db::add_tag_prefix<::Tags::dt, variables_tag>; 33 : 34 0 : using simple_tags = 35 : tmpl::list<variables_tag, dt_variables_tag, Tags::CurrentIteration, 36 : Tags::ExpirationTime, Tags::WorldtubeRadius, 37 : ::Tags::HistoryEvolvedVariables<variables_tag>>; 38 0 : using return_tags = simple_tags; 39 : 40 0 : using compute_tags = tmpl::list<>; 41 0 : using const_global_cache_tags = tmpl::list<>; 42 0 : using mutable_global_cache_tags = tmpl::list<>; 43 0 : using simple_tags_from_options = tmpl::list<Tags::InitialPositionAndVelocity>; 44 0 : using argument_tags = tmpl::list<::Tags::TimeStepper<TimeStepper>, 45 : Tags::InitialPositionAndVelocity, 46 : ::Tags::Time, Tags::ExcisionSphere<Dim>>; 47 0 : static void apply( 48 : const gsl::not_null<Variables< 49 : tmpl::list<Tags::EvolvedPosition<Dim>, Tags::EvolvedVelocity<Dim>>>*> 50 : evolved_vars, 51 : const gsl::not_null< 52 : Variables<tmpl::list<::Tags::dt<Tags::EvolvedPosition<Dim>>, 53 : ::Tags::dt<Tags::EvolvedVelocity<Dim>>>>*> 54 : dt_evolved_vars, 55 : const gsl::not_null<size_t*> current_iteration, 56 : const gsl::not_null<double*> expiration_time, 57 : const gsl::not_null<double*> worldtube_radius, 58 : const gsl::not_null<::Tags::HistoryEvolvedVariables<variables_tag>::type*> 59 : time_stepper_history, 60 : const TimeStepper& time_stepper, 61 : const std::array<tnsr::I<double, Dim>, 2>& initial_pos_and_vel, 62 : const double initial_time, const ExcisionSphere<Dim>& excision_sphere) { 63 : *current_iteration = 0; 64 : 65 : // the functions of time should be ready during the first step but not the 66 : // second. We choose the arbitrary value of 1e-10 here to ensure this. 67 : *expiration_time = initial_time + 1e-10; 68 : *worldtube_radius = excision_sphere.radius(); 69 : 70 : const size_t starting_order = 71 : visit( 72 : []<typename Tag>( 73 : const std::pair<tmpl::type_<Tag>, typename Tag::type&&> order) { 74 : if constexpr (std::is_same_v<Tag, 75 : TimeSteppers::Tags::FixedOrder>) { 76 : return order.second; 77 : } else { 78 : return order.second.minimum; 79 : } 80 : }, 81 : time_stepper.order()) - 82 : time_stepper.number_of_past_steps(); 83 : *time_stepper_history = 84 : typename ::Tags::HistoryEvolvedVariables<variables_tag>::type{ 85 : starting_order}; 86 : evolved_vars->initialize(size_t(1), 0.); 87 : dt_evolved_vars->initialize(size_t(1), 0.); 88 : for (size_t i = 0; i < Dim; ++i) { 89 : get<Tags::EvolvedPosition<Dim>>(*evolved_vars).get(i)[0] = 90 : initial_pos_and_vel.at(0).get(i); 91 : get<Tags::EvolvedVelocity<Dim>>(*evolved_vars).get(i)[0] = 92 : initial_pos_and_vel.at(1).get(i); 93 : } 94 : } 95 : }; 96 : } // namespace CurvedScalarWave::Worldtube::Initialization