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 <deque> 8 : #include <optional> 9 : #include <string> 10 : #include <type_traits> 11 : #include <unordered_map> 12 : #include <unordered_set> 13 : 14 : #include "DataStructures/DataBox/PrefixHelpers.hpp" 15 : #include "DataStructures/DataBox/Tag.hpp" 16 : #include "DataStructures/Variables.hpp" 17 : #include "IO/Logging/Tags.hpp" 18 : #include "IO/Logging/Verbosity.hpp" 19 : #include "NumericalAlgorithms/Spectral/Mesh.hpp" 20 : #include "Options/String.hpp" 21 : #include "ParallelAlgorithms/Interpolation/InterpolatedVars.hpp" 22 : #include "Utilities/TaggedTuple.hpp" 23 : 24 : /// \cond 25 : template <size_t VolumeDim> 26 : class ElementId; 27 : /// \endcond 28 : 29 : namespace intrp { 30 : 31 0 : namespace OptionTags { 32 : /*! 33 : * \ingroup OptionGroupsGroup 34 : * \brief Groups option tags for InterpolationTargets. 35 : */ 36 1 : struct InterpolationTargets { 37 0 : static constexpr Options::String help{"Options for interpolation targets"}; 38 : }; 39 : 40 : /*! 41 : * \ingroup OptionGroupsGroup 42 : * \brief Groups option tags for the Interpolator. 43 : */ 44 1 : struct Interpolator { 45 0 : static constexpr Options::String help{ 46 : "Options related to the Interpolator parallel component"}; 47 : }; 48 : 49 : /// Option tag that determines if volume data will be dumped from the 50 : /// Interpolator upon a failure. 51 1 : struct DumpVolumeDataOnFailure { 52 0 : using type = bool; 53 0 : static constexpr Options::String help{ 54 : "Whether or not to dump all volume data currently stored by the " 55 : "interpolator. Volume data is written to the file corresponding to the " 56 : "node it was collected on."}; 57 0 : using group = Interpolator; 58 : }; 59 : } // namespace OptionTags 60 : 61 : /// Tags for items held in the `DataBox` of `InterpolationTarget` or 62 : /// `Interpolator`. 63 : namespace Tags { 64 : /// Tag that determines if volume data will be dumped form the Interpolator upon 65 : /// failure 66 1 : struct DumpVolumeDataOnFailure : db::SimpleTag { 67 0 : using type = bool; 68 0 : using option_tags = tmpl::list<OptionTags::DumpVolumeDataOnFailure>; 69 0 : static constexpr bool pass_metavariables = false; 70 : 71 0 : static bool create_from_options(const bool input) { return input; } 72 : }; 73 : 74 : /// Tag that determines the verbosity of output from the interpolator 75 1 : struct Verbosity : db::SimpleTag { 76 0 : using type = ::Verbosity; 77 : 78 0 : using option_tags = 79 : tmpl::list<logging::OptionTags::Verbosity<OptionTags::Interpolator>>; 80 0 : static constexpr bool pass_metavariables = false; 81 0 : static ::Verbosity create_from_options(const ::Verbosity& verbosity) { 82 : return verbosity; 83 : } 84 : }; 85 : 86 : /// Keeps track of which points have been filled with interpolated data. 87 : template <typename TemporalId> 88 1 : struct IndicesOfFilledInterpPoints : db::SimpleTag { 89 0 : using type = std::unordered_map<TemporalId, std::unordered_set<size_t>>; 90 : }; 91 : 92 : /// Keeps track of points that cannot be filled with interpolated data. 93 : /// 94 : /// The InterpolationTarget can decide what to do with these points. 95 : /// In most cases the correct action is to throw an error, but in other 96 : /// cases one might wish to fill these points with a default value or 97 : /// take some other action. 98 : template <typename TemporalId> 99 1 : struct IndicesOfInvalidInterpPoints : db::SimpleTag { 100 0 : using type = std::unordered_map<TemporalId, std::unordered_set<size_t>>; 101 : }; 102 : 103 : /// Holds potential dependency for apparent horizon callbacks. 104 : template <typename TemporalId> 105 1 : struct Dependencies : db::SimpleTag { 106 0 : using type = std::unordered_map<TemporalId, std::optional<std::string>>; 107 : }; 108 : 109 : /// `temporal_id`s that have been flagged to interpolate on, but that 110 : /// have not yet been added to Tags::CurrentTemporalId. A `temporal_id` is 111 : /// pending if the `FunctionOfTime`s are not up to date for the time 112 : /// associated with the `temporal_id`. 113 : template <typename TemporalId> 114 1 : struct PendingTemporalIds : db::SimpleTag { 115 0 : using type = std::deque<TemporalId>; 116 : }; 117 : 118 : /// `temporal_id` on which to interpolate. 119 : /// 120 : /// \note This tag is only used in sequential targets because only one temporal 121 : /// id can be interpolated to at any given time 122 : template <typename TemporalId> 123 1 : struct CurrentTemporalId : db::SimpleTag { 124 0 : using type = std::optional<TemporalId>; 125 : }; 126 : 127 : /// `temporal_id`s on which to interpolate. 128 : /// 129 : /// \note This tag is only used in non-sequential targets 130 : template <typename TemporalId> 131 1 : struct TemporalIds : db::SimpleTag { 132 0 : using type = std::unordered_set<TemporalId>; 133 : }; 134 : 135 : /// `temporal_id`s that we have already interpolated onto. 136 : /// This is used to prevent problems with multiple late calls to 137 : /// AddTemporalIdsToInterpolationTarget. 138 : template <typename TemporalId> 139 1 : struct CompletedTemporalIds : db::SimpleTag { 140 0 : using type = std::deque<TemporalId>; 141 : }; 142 : 143 : /// Holds interpolated variables on an InterpolationTarget. 144 : template <typename InterpolationTargetTag, typename TemporalId> 145 1 : struct InterpolatedVars : db::SimpleTag { 146 0 : using type = std::unordered_map< 147 : TemporalId, 148 : Variables< 149 : typename InterpolationTargetTag::vars_to_interpolate_to_target>>; 150 : }; 151 : 152 : template <typename InterpolationTargetTag> 153 0 : struct VarsToInterpolateToTarget { 154 0 : using type = 155 : Variables<typename InterpolationTargetTag::vars_to_interpolate_to_target>; 156 : }; 157 : 158 : /// Volume variables at all `temporal_id`s for all local `Element`s. 159 : /// Held by the Interpolator. 160 : template <typename Metavariables, typename TemporalId> 161 1 : struct VolumeVarsInfo : db::SimpleTag { 162 0 : struct Info { 163 0 : Mesh<Metavariables::volume_dim> mesh; 164 : // Variables that have been sent from the Elements. 165 : Variables<typename Metavariables::interpolator_source_vars> 166 0 : source_vars_from_element; 167 : // Variables, for each InterpolationTargetTag, that have been 168 : // computed in the volume before interpolation, and that will 169 : // be interpolated. 170 : tuples::tagged_tuple_from_typelist< 171 : db::wrap_tags_in<VarsToInterpolateToTarget, 172 : typename Metavariables::interpolation_target_tags>> 173 0 : vars_to_interpolate; 174 0 : Info() = default; 175 0 : Info( 176 : Mesh<Metavariables::volume_dim> mesh_in, 177 : Variables<typename Metavariables::interpolator_source_vars> 178 : source_vars_from_element_in, 179 : tuples::tagged_tuple_from_typelist< 180 : db::wrap_tags_in<VarsToInterpolateToTarget, 181 : typename Metavariables::interpolation_target_tags>> 182 : vars_to_interpolate_in) 183 : : mesh(std::move(mesh_in)), 184 : source_vars_from_element(std::move(source_vars_from_element_in)), 185 : vars_to_interpolate(std::move(vars_to_interpolate_in)) {} 186 : // NOLINTNEXTLINE(google-runtime-references) 187 0 : void pup(PUP::er& p) { 188 : p | mesh; 189 : p | source_vars_from_element; 190 : p | vars_to_interpolate; 191 : } 192 : }; 193 0 : using type = std::unordered_map< 194 : typename TemporalId::type, 195 : std::unordered_map<ElementId<Metavariables::volume_dim>, Info>>; 196 : }; 197 : 198 : namespace holders_detail { 199 : template <typename InterpolationTargetTag, typename Metavariables> 200 : using WrappedHolderTag = Vars::HolderTag<InterpolationTargetTag, Metavariables>; 201 : } // namespace holders_detail 202 : 203 : /// `TaggedTuple` containing all local `Vars::Holder`s for 204 : /// all `InterpolationTarget`s. 205 : /// 206 : /// A particular `Vars::Holder` can be retrieved from this 207 : /// `TaggedTuple` via a `Vars::HolderTag`. An `Interpolator` uses the 208 : /// object in `InterpolatedVarsHolders` to iterate over all of the 209 : /// `InterpolationTarget`s. 210 : template <typename Metavariables> 211 1 : struct InterpolatedVarsHolders : db::SimpleTag { 212 0 : using type = tuples::tagged_tuple_from_typelist<db::wrap_tags_in< 213 : holders_detail::WrappedHolderTag, 214 : typename Metavariables::interpolation_target_tags, Metavariables>>; 215 : }; 216 : 217 : /// Map between interpolation target name and an unordered set of element ids on 218 : /// each interpolator core that will participate for that target. 219 : template <size_t Dim> 220 1 : struct NumberOfElements : db::SimpleTag { 221 0 : using type = 222 : std::unordered_map<std::string, std::unordered_set<ElementId<Dim>>>; 223 : }; 224 : } // namespace Tags 225 : } // namespace intrp