Line data Source code
1 0 : 2 : // Distributed under the MIT License. 3 : // See LICENSE.txt for details. 4 : 5 : #pragma once 6 : 7 : #include <charm++.h> 8 : #include <iterator> 9 : #include <memory> 10 : #include <utility> 11 : #include <vector> 12 : 13 : #include "Parallel/Callback.hpp" 14 : #include "Parallel/GlobalCache.hpp" 15 : #include "Parallel/Phase.hpp" 16 : #include "ParallelAlgorithms/Amr/Actions/SendDataToChildren.hpp" 17 : #include "Utilities/Algorithm.hpp" 18 : #include "Utilities/ErrorHandling/Assert.hpp" 19 : 20 : /// \cond 21 : namespace db { 22 : template <typename> 23 : class DataBox; 24 : } // namespace db 25 : /// \endcond 26 : 27 : namespace amr::Actions { 28 : /// \brief Creates a new element in an ArrayAlgorithm whose id is `child_id` 29 : /// 30 : /// \details This action is meant to be initially invoked by 31 : /// amr::Actions::AdjustDomain on the amr::Component. This action inserts a new 32 : /// element with id `children_ids[index_of_child_id]` in the array referenced by 33 : /// `element_proxy`. A Parallel::SimpleActionCallback is passed to the 34 : /// constructor of the new DistributedObject. If `index_of_child_id` is that of 35 : /// the last element of `children_ids`, the Parallel::SimpleActionCallback will 36 : /// invoke amr::Actions::SendDataToChildren on the element with id `parent_id`. 37 : /// Otherwise, it will invoke amr::Actions::CreateChild on the next element of 38 : /// `children_ids`. 39 : /// 40 : /// This action does not modify anything in the DataBox 41 1 : struct CreateChild { 42 : template <typename ParallelComponent, typename DbTagList, 43 : typename Metavariables, typename ElementProxy> 44 0 : static void apply( 45 : db::DataBox<DbTagList>& /*box*/, 46 : Parallel::GlobalCache<Metavariables>& cache, const int /*array_index*/, 47 : ElementProxy element_proxy, 48 : ElementId<Metavariables::volume_dim> parent_id, 49 : std::vector<ElementId<Metavariables::volume_dim>> children_ids, 50 : const size_t index_of_child_id, 51 : const std::unordered_map<Parallel::Phase, size_t> 52 : parent_phase_bookmarks) { 53 : auto my_proxy = Parallel::get_parallel_component<ParallelComponent>(cache); 54 : const ElementId<Metavariables::volume_dim>& child_id = 55 : children_ids[index_of_child_id]; 56 : if (index_of_child_id + 1 == children_ids.size()) { 57 : auto parent_proxy = element_proxy[parent_id]; 58 : element_proxy[child_id].insert( 59 : cache.get_this_proxy(), Parallel::Phase::AdjustDomain, 60 : parent_phase_bookmarks, 61 : std::make_unique<Parallel::SimpleActionCallback< 62 : SendDataToChildren, decltype(parent_proxy), 63 : std::vector<ElementId<Metavariables::volume_dim>>>>( 64 : parent_proxy, std::move(children_ids))); 65 : } else { 66 : element_proxy[child_id].insert( 67 : cache.get_this_proxy(), Parallel::Phase::AdjustDomain, 68 : parent_phase_bookmarks, 69 : std::make_unique<Parallel::SimpleActionCallback< 70 : CreateChild, decltype(my_proxy), ElementProxy, 71 : ElementId<Metavariables::volume_dim>, 72 : std::vector<ElementId<Metavariables::volume_dim>>, size_t, 73 : std::unordered_map<Parallel::Phase, size_t>>>( 74 : my_proxy, std::move(element_proxy), std::move(parent_id), 75 : std::move(children_ids), index_of_child_id + 1, 76 : parent_phase_bookmarks)); 77 : } 78 : } 79 : }; 80 : } // namespace amr::Actions