Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include "Parallel/Algorithms/AlgorithmSingleton.hpp"
7 : #include "Parallel/ArrayCollection/IsDgElementCollection.hpp"
8 : #include "Parallel/ArrayCollection/SimpleActionOnElement.hpp"
9 : #include "Parallel/GlobalCache.hpp"
10 : #include "Parallel/Local.hpp"
11 : #include "Parallel/ParallelComponentHelpers.hpp"
12 : #include "Parallel/Phase.hpp"
13 : #include "ParallelAlgorithms/Amr/Actions/AdjustDomain.hpp"
14 : #include "ParallelAlgorithms/Amr/Actions/ElementsRegistration.hpp"
15 : #include "ParallelAlgorithms/Amr/Actions/EvaluateRefinementCriteria.hpp"
16 : #include "ParallelAlgorithms/Amr/Criteria/Tags/Criteria.hpp"
17 : #include "ParallelAlgorithms/Amr/Policies/Tags.hpp"
18 : #include "ParallelAlgorithms/Amr/Protocols/AmrMetavariables.hpp"
19 : #include "Utilities/ProtocolHelpers.hpp"
20 : #include "Utilities/TMPL.hpp"
21 :
22 : /// \ingroup AmrGroup
23 : namespace amr {
24 : /// \brief A singleton parallel component to manage adaptive mesh refinement
25 : ///
26 : /// \details This component can be used for:
27 : /// - Running actions that create new elements. This may be necessary to
28 : /// work around Charm++ bugs, and may require the singleton to be placed
29 : /// on global processor 0.
30 : /// - As a reduction target to perform sanity checks after AMR, output
31 : /// AMR diagnostics, or determine when to trigger AMR.
32 : template <class Metavariables>
33 1 : struct Component {
34 0 : using metavariables = Metavariables;
35 0 : static constexpr size_t volume_dim = Metavariables::volume_dim;
36 : static_assert(tt::assert_conforms_to_v<typename metavariables::amr,
37 : amr::protocols::AmrMetavariables>);
38 0 : using ElementArray = typename metavariables::amr::element_array;
39 :
40 0 : using chare_type = Parallel::Algorithms::Singleton;
41 0 : static constexpr bool checkpoint_data = true;
42 :
43 0 : using const_global_cache_tags =
44 : tmpl::list<amr::Criteria::Tags::Criteria,
45 : amr::Tags::AmrBlocks<volume_dim>, amr::Tags::Policies,
46 : logging::Tags::Verbosity<amr::OptionTags::AmrGroup>>;
47 :
48 0 : using phase_dependent_action_list = tmpl::list<
49 : Parallel::PhaseActions<
50 : Parallel::Phase::Initialization,
51 : tmpl::list<amr::Actions::InitializeElementsRegistration<volume_dim>>>,
52 : Parallel::PhaseActions<
53 : Parallel::Phase::UpdateSections,
54 : tmpl::conditional_t<
55 : metavariables::amr::keep_coarse_grids,
56 : tmpl::list<::amr::Actions::UpdateSections<ElementArray>>,
57 : tmpl::list<>>>>;
58 :
59 0 : using simple_tags_from_options = Parallel::get_simple_tags_from_options<
60 : Parallel::get_initialization_actions_list<phase_dependent_action_list>>;
61 :
62 0 : static void execute_next_phase(
63 : const Parallel::Phase next_phase,
64 : Parallel::CProxy_GlobalCache<Metavariables>& global_cache_proxy) {
65 : auto& local_cache = *Parallel::local_branch(global_cache_proxy);
66 : Parallel::get_parallel_component<Component>(local_cache)
67 : .start_phase(next_phase);
68 : auto& element_array =
69 : Parallel::get_parallel_component<ElementArray>(local_cache);
70 : if (Parallel::Phase::EvaluateAmrCriteria == next_phase) {
71 : if constexpr (Parallel::is_dg_element_collection_v<ElementArray>) {
72 : Parallel::threaded_action<Parallel::Actions::SimpleActionOnElement<
73 : ::amr::Actions::EvaluateRefinementCriteria, true>>(element_array);
74 : } else {
75 : Parallel::simple_action<::amr::Actions::EvaluateRefinementCriteria>(
76 : element_array);
77 : }
78 : }
79 : if (Parallel::Phase::AdjustDomain == next_phase) {
80 : if constexpr (Parallel::is_dg_element_collection_v<ElementArray>) {
81 : Parallel::threaded_action<Parallel::Actions::SimpleActionOnElement<
82 : ::amr::Actions::AdjustDomain, true>>(element_array);
83 : } else {
84 : Parallel::simple_action<::amr::Actions::AdjustDomain>(element_array);
85 : }
86 : }
87 : }
88 : };
89 : } // namespace amr
|