SpECTRE Documentation Coverage Report
 Current view: top level - ParallelAlgorithms/Amr/Criteria - Random.hpp Hit Total Coverage Commit: 697db44127ce57424c079f629b3283267ec6bd78 Lines: 1 14 7.1 % Date: 2024-06-21 21:13:41 Legend: Lines: hit not hit
 ` Line data Source code` ``` 1 0 : // Distributed under the MIT License. 2 : // See LICENSE.txt for details. 3 : 4 : #pragma once 5 : 6 : #include 7 : #include 8 : #include 9 : #include 10 : 11 : #include "Domain/Amr/Flag.hpp" 12 : #include "Domain/Structure/ElementId.hpp" 13 : #include "Options/String.hpp" 14 : #include "Parallel/GlobalCache.hpp" 15 : #include "ParallelAlgorithms/Amr/Criteria/Criterion.hpp" 16 : #include "Utilities/MakeArray.hpp" 17 : #include "Utilities/Serialization/CharmPupable.hpp" 18 : #include "Utilities/TMPL.hpp" 19 : 20 : namespace amr::Criteria { 21 : namespace detail { 22 : amr::Flag random_flag( 23 : const std::unordered_map& probability_weights); 24 : } // namespace detail 25 : 26 : /*! 27 : * \brief Randomly refine (or coarsen) an Element in each dimension. 28 : * 29 : * You can specify a probability for each possible `amr::Flag`. It is evaluated 30 : * in each dimension separately. Details: 31 : * 32 : * - Probabilities are specified as integer weights. The probability for an 33 : * `amr::Flag` is its weight over the sum of all weights. 34 : * - Flags with weight zero do not need to be specified. 35 : * - If all weights are zero, `amr::Flag::DoNothing` is always chosen. 36 : */ 37 1 : class Random : public Criterion { 38 : public: 39 0 : struct ProbabilityWeights { 40 0 : using type = std::unordered_map; 41 0 : static constexpr Options::String help = { 42 : "Possible refinement types and their probability, specified as integer " 43 : "weights. The probability for a refinement type is its weight over the " 44 : "sum of all weights. For example, set 'Split: 1' and 'DoNothing: 4' to " 45 : "split each element with 20% probability. The refinement is evaluated " 46 : "in each dimension separately."}; 47 : }; 48 : 49 0 : using options = tmpl::list; 50 : 51 0 : static constexpr Options::String help = { 52 : "Randomly refine (or coarsen) the grid"}; 53 : 54 0 : Random() = default; 55 : 56 0 : explicit Random(std::unordered_map probability_weights); 57 : 58 : /// \cond 59 : explicit Random(CkMigrateMessage* msg); 60 : using PUP::able::register_constructor; 61 : WRAPPED_PUPable_decl_template(Random); // NOLINT 62 : /// \endcond 63 : 64 0 : using compute_tags_for_observation_box = tmpl::list<>; 65 : 66 0 : using argument_tags = tmpl::list<>; 67 : 68 : template 69 0 : auto operator()(Parallel::GlobalCache& /*cache*/, 70 : const ElementId& element_id) const; 71 : 72 0 : void pup(PUP::er& p) override; 73 : 74 : private: 75 0 : std::unordered_map probability_weights_{}; 76 : }; 77 : 78 : template 79 : auto Random::operator()(Parallel::GlobalCache& /*cache*/, 80 : const ElementId& /*element_id*/) const { 81 : auto result = make_array(amr::Flag::Undefined); 82 : for (size_t d = 0; d < Dim; ++d) { 83 : result[d] = detail::random_flag(probability_weights_); 84 : } 85 : return result; 86 : } 87 : } // namespace amr::Criteria ```

 Generated by: LCOV version 1.14