Line data Source code
1 0 : // Distributed under the MIT License.
2 : // See LICENSE.txt for details.
3 :
4 : #pragma once
5 :
6 : #include <array>
7 : #include <cstddef>
8 : #include <pup.h>
9 :
10 : #include "Domain/Amr/Flag.hpp"
11 : #include "Domain/Tags.hpp"
12 : #include "ParallelAlgorithms/Amr/Criteria/Criterion.hpp"
13 : #include "ParallelAlgorithms/Amr/Criteria/Type.hpp"
14 : #include "Utilities/TMPL.hpp"
15 :
16 : /// \cond
17 : template <size_t>
18 : class ElementId;
19 : template <size_t>
20 : class Mesh;
21 : /// \endcond
22 :
23 : namespace amr::Criteria {
24 : /*!
25 : * \brief Refine the grid towards the target number of grid points and
26 : * refinement levels in each dimension and then oscillate about the target.
27 : *
28 : * \details If the grid is at neither target in a given dimension, the
29 : * flag chosen will be in the priority order Split, IncreaseResolution,
30 : * DecreaseResolution, Join.
31 : *
32 : * \note To remain at the target, set the OscillationAtTarget Flags to
33 : * DoNothing.
34 : *
35 : * \note This criterion is primarily for testing the mechanics of refinement.
36 : */
37 : template <size_t Dim, Type CriteriaType>
38 1 : class DriveToTarget : public Criterion {
39 : public:
40 : /// The target (number of grid points or refinement level) in each dimension
41 1 : struct Target {
42 0 : using type = std::array<size_t, Dim>;
43 0 : static constexpr Options::String help = {
44 : CriteriaType == Type::p
45 : ? "The target number of grid points in each dimension."
46 : : "The target refinement level in each dimension."};
47 : };
48 :
49 : /// The AMR flags chosen when the target in each dimension is reached
50 1 : struct OscillationAtTarget {
51 0 : using type = std::array<Flag, Dim>;
52 0 : static constexpr Options::String help = {
53 : "The flags returned when at the target."};
54 : };
55 :
56 0 : using options = tmpl::list<Target, OscillationAtTarget>;
57 :
58 0 : static constexpr Options::String help = {
59 : "Refine the grid towards the Target, and then oscillate about them by "
60 : "applying OscillationAtTarget."};
61 :
62 0 : DriveToTarget() = default;
63 :
64 0 : DriveToTarget(const std::array<size_t, Dim>& target,
65 : const std::array<Flag, Dim>& flags_at_target);
66 :
67 : /// \cond
68 : explicit DriveToTarget(CkMigrateMessage* msg);
69 : using PUP::able::register_constructor;
70 : WRAPPED_PUPable_decl_template(DriveToTarget); // NOLINT
71 : /// \endcond
72 :
73 0 : static std::string name() {
74 : return CriteriaType == Type::p ? "DriveToTargetNumberOfGridPoints"
75 : : "DriveToTargetRefinementLevels";
76 : }
77 :
78 0 : Type type() override { return CriteriaType; }
79 :
80 0 : std::string observation_name() override { return "DriveToTarget"; }
81 :
82 0 : using compute_tags_for_observation_box = tmpl::list<>;
83 :
84 0 : using argument_tags = tmpl::list<::domain::Tags::Mesh<Dim>>;
85 :
86 : template <typename Metavariables>
87 0 : auto operator()(const Mesh<Dim>& current_mesh,
88 : Parallel::GlobalCache<Metavariables>& /*cache*/,
89 : const ElementId<Dim>& element_id) const;
90 :
91 0 : void pup(PUP::er& p) override;
92 :
93 : private:
94 0 : std::array<Flag, Dim> impl(const Mesh<Dim>& current_mesh,
95 : const ElementId<Dim>& element_id) const;
96 :
97 0 : std::array<size_t, Dim> target_{};
98 0 : std::array<Flag, Dim> flags_at_target_{};
99 : };
100 :
101 : template <size_t Dim, Type CriteriaType>
102 : template <typename Metavariables>
103 : auto DriveToTarget<Dim, CriteriaType>::operator()(
104 : const Mesh<Dim>& current_mesh,
105 : Parallel::GlobalCache<Metavariables>& /*cache*/,
106 : const ElementId<Dim>& element_id) const {
107 : return impl(current_mesh, element_id);
108 : }
109 : } // namespace amr::Criteria
|