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/TaggedTuple.hpp" 14 : #include "DataStructures/VariablesTag.hpp" 15 : #include "Evolution/DiscontinuousGalerkin/Actions/ComputeTimeDerivativeHelpers.hpp" 16 : #include "Evolution/Initialization/InitialData.hpp" 17 : #include "Parallel/AlgorithmExecution.hpp" 18 : #include "Parallel/GlobalCache.hpp" 19 : #include "ParallelAlgorithms/Initialization/MutateAssign.hpp" 20 : #include "Utilities/TMPL.hpp" 21 : 22 : /// \cond 23 : namespace domain { 24 : namespace Tags { 25 : template <size_t VolumeDim> 26 : struct Mesh; 27 : } // namespace Tags 28 : } // namespace domain 29 : 30 : /// \endcond 31 : 32 : namespace Initialization { 33 : namespace Actions { 34 : /// \ingroup InitializationGroup 35 : /// \brief Allocate variables needed for evolution of nonconservative systems 36 : /// 37 : /// Uses: 38 : /// - DataBox: 39 : /// * `Tags::Mesh<Dim>` 40 : /// 41 : /// DataBox changes: 42 : /// - Adds: 43 : /// * System::variables_tag 44 : /// * `::Tags::Variables<System::auxiliary_variables>` (only if the system 45 : /// declares a non-empty `auxiliary_variables`) 46 : /// 47 : /// - Removes: nothing 48 : /// - Modifies: nothing 49 : template <typename System> 50 1 : struct NonconservativeSystem { 51 : static_assert(not System::is_in_flux_conservative_form, 52 : "System is in flux conservative form"); 53 0 : static constexpr size_t dim = System::volume_dim; 54 0 : using variables_tag = typename System::variables_tag; 55 0 : using auxiliary_variables = 56 : evolution::dg::Actions::detail::get_auxiliary_variables_or_default_t< 57 : System, tmpl::list<>>; 58 0 : static constexpr bool has_auxiliary_variables = 59 : not std::is_same_v<auxiliary_variables, tmpl::list<>>; 60 0 : using auxiliary_variables_tag = ::Tags::Variables<auxiliary_variables>; 61 0 : using simple_tags = tmpl::conditional_t< 62 : has_auxiliary_variables, 63 : db::AddSimpleTags<variables_tag, auxiliary_variables_tag>, 64 : db::AddSimpleTags<variables_tag>>; 65 0 : using compute_tags = db::AddComputeTags<>; 66 : 67 : template <typename DbTagsList, typename... InboxTags, typename Metavariables, 68 : typename ArrayIndex, typename ActionList, 69 : typename ParallelComponent> 70 0 : static Parallel::iterable_action_return_t apply( 71 : db::DataBox<DbTagsList>& box, 72 : const tuples::TaggedTuple<InboxTags...>& /*inboxes*/, 73 : const Parallel::GlobalCache<Metavariables>& /*cache*/, 74 : const ArrayIndex& /*array_index*/, ActionList /*meta*/, 75 : const ParallelComponent* const /*meta*/) { 76 : using Vars = typename variables_tag::type; 77 : const size_t number_of_grid_points = 78 : db::get<domain::Tags::Mesh<dim>>(box).number_of_grid_points(); 79 : if constexpr (has_auxiliary_variables) { 80 : using AuxVars = typename auxiliary_variables_tag::type; 81 : Initialization::mutate_assign<simple_tags>( 82 : make_not_null(&box), Vars{number_of_grid_points}, 83 : AuxVars{number_of_grid_points}); 84 : } else { 85 : Initialization::mutate_assign<simple_tags>(make_not_null(&box), 86 : Vars{number_of_grid_points}); 87 : } 88 : 89 : return {Parallel::AlgorithmExecution::Continue, std::nullopt}; 90 : } 91 : }; 92 : } // namespace Actions 93 : } // namespace Initialization