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 <limits> 8 : #include <pup.h> 9 : #include <utility> 10 : 11 : #include "Options/Context.hpp" 12 : #include "Options/String.hpp" 13 : #include "Time/StepChoosers/StepChooser.hpp" 14 : #include "Utilities/Serialization/CharmPupable.hpp" 15 : #include "Utilities/TMPL.hpp" 16 : 17 : /// \cond 18 : template <size_t VolumeDim> 19 : class Element; 20 : class TimeStepId; 21 : namespace Tags { 22 : struct TimeStepId; 23 : } // namespace Tags 24 : namespace domain::Tags { 25 : template <size_t VolumeDim> 26 : struct Element; 27 : } // namespace domain::Tags 28 : /// \endcond 29 : 30 : namespace StepChoosers { 31 : /// Changes the step size pseudo-randomly. Values are distributed 32 : /// uniformly in $\log(dt)$. The current step is always accepted. 33 : template <typename StepChooserUse, size_t VolumeDim> 34 1 : class Random : public StepChooser<StepChooserUse> { 35 : public: 36 : /// \cond 37 : Random(); 38 : explicit Random(CkMigrateMessage* /*unused*/); 39 : using PUP::able::register_constructor; 40 : WRAPPED_PUPable_decl_template(Random); // NOLINT 41 : /// \endcond 42 : 43 0 : struct Minimum { 44 0 : using type = double; 45 0 : static constexpr Options::String help{"Minimum value to suggest"}; 46 0 : static type lower_bound() { return 0.0; } 47 : }; 48 : 49 0 : struct Maximum { 50 0 : using type = double; 51 0 : static constexpr Options::String help{"Maximum value to suggest"}; 52 0 : static type lower_bound() { return 0.0; } 53 : }; 54 : 55 0 : struct Seed { 56 0 : using type = size_t; 57 0 : static constexpr Options::String help{"RNG seed"}; 58 : }; 59 : 60 0 : static constexpr Options::String help = 61 : "Changes the step size pseudo-randomly."; 62 0 : using options = tmpl::list<Minimum, Maximum, Seed>; 63 : 64 0 : Random(double minimum, double maximum, size_t seed, 65 : const Options::Context& context = {}); 66 : 67 0 : using argument_tags = 68 : tmpl::list<domain::Tags::Element<VolumeDim>, Tags::TimeStepId>; 69 : 70 0 : std::pair<double, bool> operator()(const Element<VolumeDim>& element, 71 : const TimeStepId& time_step_id, 72 : double last_step_magnitude) const; 73 : 74 1 : bool uses_local_data() const override; 75 : 76 : // NOLINTNEXTLINE(google-runtime-references) 77 0 : void pup(PUP::er& p) override; 78 : 79 : private: 80 0 : double minimum_ = std::numeric_limits<double>::signaling_NaN(); 81 0 : double maximum_ = std::numeric_limits<double>::signaling_NaN(); 82 0 : size_t seed_ = 0; 83 : }; 84 : } // namespace StepChoosers