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 <pup.h> 8 : #include <pup_stl.h> // IWYU pragma: keep 9 : #include <utility> 10 : #include <vector> 11 : 12 : #include "Options/String.hpp" 13 : #include "Time/StepChoosers/StepChooser.hpp" // IWYU pragma: keep 14 : #include "Utilities/ErrorHandling/Error.hpp" 15 : #include "Utilities/Serialization/CharmPupable.hpp" 16 : #include "Utilities/TMPL.hpp" 17 : 18 : /// \cond 19 : template <size_t VolumeDim> 20 : class Element; 21 : namespace domain { 22 : namespace Tags { 23 : template <size_t VolumeDim> 24 : struct Element; 25 : } // namespace Tags 26 : } // namespace domain 27 : /// \endcond 28 : 29 1 : namespace StepChoosers { 30 : /// Suggests specified step sizes in each block 31 : template <typename StepChooserUse, size_t Dim> 32 1 : class ByBlock : public StepChooser<StepChooserUse> { 33 : public: 34 : /// \cond 35 : ByBlock() = default; 36 : explicit ByBlock(CkMigrateMessage* /*unused*/) {} 37 : using PUP::able::register_constructor; 38 : WRAPPED_PUPable_decl_template(ByBlock); // NOLINT 39 : /// \endcond 40 : 41 0 : struct Sizes { 42 0 : using type = std::vector<double>; 43 0 : static constexpr Options::String help{ 44 : "Step sizes, indexed by block number"}; 45 : }; 46 : 47 0 : static constexpr Options::String help{ 48 : "Suggests specified step sizes in each block"}; 49 0 : using options = tmpl::list<Sizes>; 50 : 51 0 : explicit ByBlock(std::vector<double> sizes) : sizes_(std::move(sizes)) {} 52 : 53 0 : using argument_tags = tmpl::list<domain::Tags::Element<Dim>>; 54 : 55 0 : std::pair<double, bool> operator()( 56 : const Element<Dim>& element, 57 : const double /*last_step_magnitude*/) const { 58 : const size_t block = element.id().block_id(); 59 : if (block >= sizes_.size()) { 60 : ERROR("Step size not specified for block " << block); 61 : } 62 : return std::make_pair(sizes_[block], true); 63 : } 64 : 65 1 : bool uses_local_data() const override { return true; } 66 : 67 : // NOLINTNEXTLINE(google-runtime-references) 68 0 : void pup(PUP::er& p) override { p | sizes_; } 69 : 70 : private: 71 0 : std::vector<double> sizes_; 72 : }; 73 : 74 : /// \cond 75 : template <typename StepChooserUse, size_t Dim> 76 : PUP::able::PUP_ID ByBlock<StepChooserUse, Dim>::my_PUP_ID = 0; // NOLINT 77 : /// \endcond 78 : } // namespace StepChoosers