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 "Utilities/TMPL.hpp" 14 : 15 : /// \cond 16 : template <size_t> 17 : class ElementId; 18 : template <size_t> 19 : class Mesh; 20 : /// \endcond 21 : 22 : namespace amr::Criteria { 23 : /*! 24 : * \brief Refine the grid towards the target number of grid points and 25 : * refinement levels in each dimension and then oscillate about the target. 26 : * 27 : * \details If the grid is at neither target in a given dimension, the 28 : * flag chosen will be in the priority order Split, IncreaseResolution, 29 : * DecreaseResolution, Join. 30 : * 31 : * \note To remain at the target, set the OscillationAtTarget Flags to 32 : * DoNothing. 33 : * 34 : * \note This criterion is primarily for testing the mechanics of refinement. 35 : */ 36 : template <size_t Dim> 37 1 : class DriveToTarget : public Criterion { 38 : public: 39 : /// The target number of grid point in each dimension 40 1 : struct TargetNumberOfGridPoints { 41 0 : using type = std::array<size_t, Dim>; 42 0 : static constexpr Options::String help = { 43 : "The target number of grid points in each dimension."}; 44 : }; 45 : 46 : /// The target refinement level in each dimension 47 1 : struct TargetRefinementLevels { 48 0 : using type = std::array<size_t, Dim>; 49 0 : static constexpr Options::String help = { 50 : "The target refinement level in each dimension."}; 51 : }; 52 : 53 : /// The AMR flags chosen when the target number of grid points and refinement 54 : /// levels are reached 55 1 : struct OscillationAtTarget { 56 0 : using type = std::array<Flag, Dim>; 57 0 : static constexpr Options::String help = { 58 : "The flags returned when at the target."}; 59 : }; 60 : 61 0 : using options = tmpl::list<TargetNumberOfGridPoints, TargetRefinementLevels, 62 : OscillationAtTarget>; 63 : 64 0 : static constexpr Options::String help = { 65 : "Refine the grid towards the TargetNumberOfGridPoints and " 66 : "TargetRefinementLevels, and then oscillate about them by applying " 67 : "OscillationAtTarget."}; 68 : 69 0 : DriveToTarget() = default; 70 : 71 0 : DriveToTarget(const std::array<size_t, Dim>& target_number_of_grid_points, 72 : const std::array<size_t, Dim>& target_refinement_levels, 73 : const std::array<Flag, Dim>& flags_at_target); 74 : 75 : /// \cond 76 : explicit DriveToTarget(CkMigrateMessage* msg); 77 : using PUP::able::register_constructor; 78 : WRAPPED_PUPable_decl_template(DriveToTarget); // NOLINT 79 : /// \endcond 80 : 81 0 : using compute_tags_for_observation_box = tmpl::list<>; 82 : 83 0 : using argument_tags = tmpl::list<::domain::Tags::Mesh<Dim>>; 84 : 85 : template <typename Metavariables> 86 0 : auto operator()(const Mesh<Dim>& current_mesh, 87 : Parallel::GlobalCache<Metavariables>& /*cache*/, 88 : const ElementId<Dim>& element_id) const; 89 : 90 0 : void pup(PUP::er& p) override; 91 : 92 : private: 93 0 : std::array<Flag, Dim> impl(const Mesh<Dim>& current_mesh, 94 : const ElementId<Dim>& element_id) const; 95 : 96 0 : std::array<size_t, Dim> target_number_of_grid_points_{}; 97 0 : std::array<size_t, Dim> target_refinement_levels_{}; 98 0 : std::array<Flag, Dim> flags_at_target_{}; 99 : }; 100 : 101 : template <size_t Dim> 102 : template <typename Metavariables> 103 : auto DriveToTarget<Dim>::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