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