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 <optional> 8 : #include <tuple> 9 : #include <type_traits> 10 : #include <utility> 11 : 12 : #include "DataStructures/DataBox/DataBox.hpp" 13 : #include "DataStructures/DataBox/PrefixHelpers.hpp" 14 : #include "DataStructures/DataBox/Prefixes.hpp" 15 : #include "Domain/CoordinateMaps/Tags.hpp" 16 : #include "Domain/FunctionsOfTime/Tags.hpp" 17 : #include "Domain/Tags.hpp" 18 : #include "Domain/TagsTimeDependent.hpp" 19 : #include "Evolution/Initialization/InitialData.hpp" 20 : #include "NumericalAlgorithms/LinearOperators/Divergence.tpp" // Needs to be included somewhere and here seems most natural. 21 : #include "Parallel/AlgorithmExecution.hpp" 22 : #include "Parallel/GlobalCache.hpp" 23 : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp" 24 : #include "PointwiseFunctions/AnalyticData/Tags.hpp" 25 : #include "Utilities/ErrorHandling/Error.hpp" 26 : #include "Utilities/Gsl.hpp" 27 : #include "Utilities/NoSuchType.hpp" 28 : #include "Utilities/Requires.hpp" 29 : #include "Utilities/TMPL.hpp" 30 : 31 : /// \cond 32 : namespace Frame { 33 : struct Inertial; 34 : } // namespace Frame 35 : 36 : namespace domain { 37 : namespace Tags { 38 : template <size_t VolumeDim, typename Frame> 39 : struct Coordinates; 40 : template <size_t VolumeDim> 41 : struct Mesh; 42 : } // namespace Tags 43 : } // namespace domain 44 : // IWYU pragma: no_forward_declare db::DataBox 45 : 46 : namespace tuples { 47 : template <class... Tags> 48 : class TaggedTuple; 49 : } // namespace tuples 50 : /// \endcond 51 : 52 0 : namespace Initialization { 53 0 : namespace Actions { 54 : /// \ingroup InitializationGroup 55 : /// \brief Allocate variables needed for evolution of conservative systems 56 : /// 57 : /// Uses: 58 : /// - DataBox: 59 : /// * `Tags::Mesh<Dim>` 60 : /// 61 : /// DataBox changes: 62 : /// - Adds: 63 : /// * System::variables_tag 64 : /// * db::add_tag_prefix<Tags::Flux, System::variables_tag> 65 : /// * db::add_tag_prefix<Tags::Source, System::variables_tag> 66 : /// 67 : /// - Removes: nothing 68 : /// - Modifies: nothing 69 : template <typename System> 70 1 : struct ConservativeSystem { 71 : private: 72 0 : static constexpr size_t dim = System::volume_dim; 73 : 74 0 : using variables_tag = typename System::variables_tag; 75 : 76 : template <typename LocalSystem, 77 : bool = LocalSystem::has_primitive_and_conservative_vars> 78 0 : struct simple_tags_impl { 79 0 : using type = tmpl::list<variables_tag>; 80 : }; 81 : 82 : template <typename LocalSystem> 83 0 : struct simple_tags_impl<LocalSystem, true> { 84 0 : using type = 85 : tmpl::list<variables_tag, typename System::primitive_variables_tag>; 86 : }; 87 : 88 : public: 89 0 : using simple_tags = typename simple_tags_impl<System>::type; 90 : 91 0 : using compute_tags = db::AddComputeTags<>; 92 : 93 : template <typename DbTagsList, typename... InboxTags, typename Metavariables, 94 : typename ArrayIndex, typename ActionList, 95 : typename ParallelComponent> 96 0 : static Parallel::iterable_action_return_t apply( 97 : db::DataBox<DbTagsList>& box, 98 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 99 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 100 : const ArrayIndex& /*array_index*/, ActionList /*meta*/, 101 : const ParallelComponent* const /*meta*/) { 102 : const size_t num_grid_points = 103 : db::get<domain::Tags::Mesh<dim>>(box).number_of_grid_points(); 104 : typename variables_tag::type vars(num_grid_points); 105 : 106 : if constexpr (System::has_primitive_and_conservative_vars) { 107 : using PrimitiveVars = typename System::primitive_variables_tag::type; 108 : 109 : PrimitiveVars primitive_vars{ 110 : db::get<domain::Tags::Mesh<dim>>(box).number_of_grid_points()}; 111 : Initialization::mutate_assign<simple_tags>( 112 : make_not_null(&box), std::move(vars), std::move(primitive_vars)); 113 : } else { 114 : Initialization::mutate_assign<simple_tags>(make_not_null(&box), 115 : std::move(vars)); 116 : } 117 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 118 : } 119 : }; 120 : } // namespace Actions 121 : } // namespace Initialization