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::HistoryEvolvedVariables<variables_tag>>; 37 0 : using return_tags = simple_tags; 38 : 39 0 : using compute_tags = tmpl::list<>; 40 0 : using const_global_cache_tags = tmpl::list<>; 41 0 : using mutable_global_cache_tags = tmpl::list<>; 42 0 : using simple_tags_from_options = tmpl::list<Tags::InitialPositionAndVelocity>; 43 0 : using argument_tags = tmpl::list<::Tags::TimeStepper<TimeStepper>, 44 : Tags::InitialPositionAndVelocity>; 45 0 : static void apply( 46 : const gsl::not_null<Variables< 47 : tmpl::list<Tags::EvolvedPosition<Dim>, Tags::EvolvedVelocity<Dim>>>*> 48 : evolved_vars, 49 : const gsl::not_null< 50 : Variables<tmpl::list<::Tags::dt<Tags::EvolvedPosition<Dim>>, 51 : ::Tags::dt<Tags::EvolvedVelocity<Dim>>>>*> 52 : dt_evolved_vars, 53 : const gsl::not_null<size_t*> current_iteration, 54 : const gsl::not_null<::Tags::HistoryEvolvedVariables<variables_tag>::type*> 55 : time_stepper_history, 56 : const TimeStepper& time_stepper, 57 : const std::array<tnsr::I<double, Dim>, 2>& initial_pos_and_vel) { 58 : *current_iteration = 0; 59 : const size_t starting_order = 60 : time_stepper.number_of_past_steps() == 0 ? time_stepper.order() : 1; 61 : *time_stepper_history = 62 : typename ::Tags::HistoryEvolvedVariables<variables_tag>::type{ 63 : starting_order}; 64 : evolved_vars->initialize(size_t(1), 0.); 65 : dt_evolved_vars->initialize(size_t(1), 0.); 66 : for (size_t i = 0; i < Dim; ++i) { 67 : get<Tags::EvolvedPosition<Dim>>(*evolved_vars).get(i)[0] = 68 : initial_pos_and_vel.at(0).get(i); 69 : get<Tags::EvolvedVelocity<Dim>>(*evolved_vars).get(i)[0] = 70 : initial_pos_and_vel.at(1).get(i); 71 : } 72 : } 73 : }; 74 : } // namespace CurvedScalarWave::Worldtube::Initialization