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 <functional> 8 : #include <unordered_map> 9 : #include <unordered_set> 10 : #include <vector> 11 : 12 : #include "Domain/Block.hpp" 13 : #include "Domain/Creators/DomainCreator.hpp" 14 : #include "Domain/Creators/OptionTags.hpp" 15 : #include "Domain/Creators/Tags/Domain.hpp" 16 : #include "Domain/Creators/Tags/InitialExtents.hpp" 17 : #include "Domain/Creators/Tags/InitialRefinementLevels.hpp" 18 : #include "Domain/Domain.hpp" 19 : #include "Domain/ElementDistribution.hpp" 20 : #include "Domain/Structure/ElementId.hpp" 21 : #include "Domain/Structure/InitialElementIds.hpp" 22 : #include "Domain/Tags/ElementDistribution.hpp" 23 : #include "Evolution/DiscontinuousGalerkin/Initialization/QuadratureTag.hpp" 24 : #include "NumericalAlgorithms/Spectral/Basis.hpp" 25 : #include "NumericalAlgorithms/Spectral/Quadrature.hpp" 26 : #include "Parallel/Algorithms/AlgorithmArray.hpp" 27 : #include "Parallel/ArrayCollection/CreateElementsUsingDistribution.hpp" 28 : #include "Parallel/GlobalCache.hpp" 29 : #include "Parallel/Info.hpp" 30 : #include "Parallel/Local.hpp" 31 : #include "Parallel/ParallelComponentHelpers.hpp" 32 : #include "Parallel/Phase.hpp" 33 : #include "Parallel/Printf/Printf.hpp" 34 : #include "Parallel/Tags/Parallelization.hpp" 35 : #include "Utilities/Literals.hpp" 36 : #include "Utilities/Numeric.hpp" 37 : #include "Utilities/System/ParallelInfo.hpp" 38 : #include "Utilities/TMPL.hpp" 39 : 40 : /*! 41 : * \brief The parallel component responsible for managing the DG elements that 42 : * compose the computational domain 43 : * 44 : * This parallel component will perform the actions specified by the 45 : * `PhaseDepActionList`. 46 : * 47 : * An unordered set of `size_t`s can be passed to the `allocate_array` 48 : * function which represents physical processors to avoid placing 49 : * elements on. 50 : */ 51 : template <class Metavariables, class PhaseDepActionList> 52 1 : struct DgElementArray { 53 0 : static constexpr size_t volume_dim = Metavariables::volume_dim; 54 : 55 0 : using chare_type = Parallel::Algorithms::Array; 56 0 : static constexpr bool checkpoint_data = true; 57 0 : using metavariables = Metavariables; 58 0 : using phase_dependent_action_list = PhaseDepActionList; 59 0 : using array_index = ElementId<volume_dim>; 60 : 61 0 : using const_global_cache_tags = tmpl::list<domain::Tags::Domain<volume_dim>, 62 : domain::Tags::ElementDistribution>; 63 : 64 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options< 65 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>; 66 : 67 0 : using array_allocation_tags = tmpl::list<>; 68 : 69 0 : static void allocate_array( 70 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache, 71 : const tuples::tagged_tuple_from_typelist<simple_tags_from_options>& 72 : initialization_items, 73 : const tuples::tagged_tuple_from_typelist<array_allocation_tags>& 74 : array_allocation_items = {}, 75 : const std::unordered_set<size_t>& procs_to_ignore = {}); 76 : 77 0 : static void execute_next_phase( 78 : const Parallel::Phase next_phase, 79 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache, 80 : const bool force = false) { 81 : auto& local_cache = *Parallel::local_branch(global_cache); 82 : Parallel::get_parallel_component<DgElementArray>(local_cache) 83 : .start_phase(next_phase, force); 84 : } 85 : }; 86 : 87 : template <class Metavariables, class PhaseDepActionList> 88 : void DgElementArray<Metavariables, PhaseDepActionList>::allocate_array( 89 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache, 90 : const tuples::tagged_tuple_from_typelist<simple_tags_from_options>& 91 : initialization_items, 92 : const tuples::tagged_tuple_from_typelist<array_allocation_tags>& 93 : /*array_allocation_items*/, 94 : const std::unordered_set<size_t>& procs_to_ignore) { 95 : auto& local_cache = *Parallel::local_branch(global_cache); 96 : auto& dg_element_array = 97 : Parallel::get_parallel_component<DgElementArray>(local_cache); 98 : 99 : const auto& domain = 100 : Parallel::get<domain::Tags::Domain<volume_dim>>(local_cache); 101 : const auto& initial_refinement_levels = 102 : get<domain::Tags::InitialRefinementLevels<volume_dim>>( 103 : initialization_items); 104 : const auto& initial_extents = 105 : get<domain::Tags::InitialExtents<volume_dim>>(initialization_items); 106 : const auto i1_basis = Spectral::Basis::Legendre; 107 : const auto& i1_quadrature = 108 : get<evolution::dg::Tags::Quadrature>(initialization_items); 109 : const std::optional<domain::ElementWeight>& element_weight = 110 : Parallel::get<domain::Tags::ElementDistribution>(local_cache); 111 : 112 : const size_t number_of_procs = Parallel::number_of_procs<size_t>(local_cache); 113 : const size_t number_of_nodes = Parallel::number_of_nodes<size_t>(local_cache); 114 : const size_t num_of_procs_to_use = number_of_procs - procs_to_ignore.size(); 115 : 116 : const auto& blocks = domain.blocks(); 117 : 118 : Parallel::create_elements_using_distribution( 119 : [&dg_element_array, &global_cache, &initialization_items]( 120 : const ElementId<volume_dim>& element_id, const size_t target_proc, 121 : const size_t /*target_node*/) { 122 : dg_element_array(element_id) 123 : .insert(global_cache, initialization_items, target_proc); 124 : }, 125 : element_weight, blocks, initial_extents, initial_refinement_levels, 126 : i1_basis, i1_quadrature, 127 : 128 : procs_to_ignore, number_of_procs, number_of_nodes, num_of_procs_to_use, 129 : local_cache, true); 130 : dg_element_array.doneInserting(); 131 : }