SpECTRE Documentation Coverage Report
Current view: top level - ParallelAlgorithms/Events - ObserveFields.hpp Hit Total Coverage
Commit: c3e43f8d41800b0ecefb9d1393f1de1d5a280c8f Lines: 6 50 12.0 %
Date: 2026-07-24 22:09:25
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 <cstddef>
       7             : #include <functional>
       8             : #include <initializer_list>
       9             : #include <optional>
      10             : #include <pup.h>
      11             : #include <string>
      12             : #include <type_traits>
      13             : #include <unordered_map>
      14             : #include <unordered_set>
      15             : #include <utility>
      16             : #include <vector>
      17             : 
      18             : #include "DataStructures/DataBox/ObservationBox.hpp"
      19             : #include "DataStructures/DataBox/Prefixes.hpp"
      20             : #include "DataStructures/DataBox/TagName.hpp"
      21             : #include "DataStructures/DataBox/ValidateSelection.hpp"
      22             : #include "DataStructures/DataVector.hpp"
      23             : #include "DataStructures/FloatingPointType.hpp"
      24             : #include "Domain/Structure/BlockGroups.hpp"
      25             : #include "Domain/Structure/ElementId.hpp"
      26             : #include "Domain/Tags.hpp"
      27             : #include "IO/H5/TensorData.hpp"
      28             : #include "IO/Observer/GetSectionObservationKey.hpp"
      29             : #include "IO/Observer/ObservationId.hpp"
      30             : #include "IO/Observer/Tags.hpp"
      31             : #include "IO/Observer/VolumeActions.hpp"
      32             : #include "NumericalAlgorithms/Interpolation/RegularGridInterpolant.hpp"
      33             : #include "NumericalAlgorithms/Spectral/Mesh.hpp"
      34             : #include "NumericalAlgorithms/Spectral/Projection.hpp"
      35             : #include "Options/Auto.hpp"
      36             : #include "Options/String.hpp"
      37             : #include "Parallel/ArrayComponentId.hpp"
      38             : #include "Parallel/ArrayIndex.hpp"
      39             : #include "Parallel/GlobalCache.hpp"
      40             : #include "Parallel/Printf/Printf.hpp"
      41             : #include "Parallel/TypeTraits.hpp"
      42             : #include "ParallelAlgorithms/Events/Tags.hpp"
      43             : #include "ParallelAlgorithms/EventsAndTriggers/Event.hpp"
      44             : #include "PointwiseFunctions/AnalyticSolutions/Tags.hpp"
      45             : #include "Utilities/Algorithm.hpp"
      46             : #include "Utilities/ErrorHandling/Assert.hpp"
      47             : #include "Utilities/ErrorHandling/Error.hpp"
      48             : #include "Utilities/Literals.hpp"
      49             : #include "Utilities/MakeString.hpp"
      50             : #include "Utilities/Numeric.hpp"
      51             : #include "Utilities/OptionalHelpers.hpp"
      52             : #include "Utilities/Serialization/CharmPupable.hpp"
      53             : #include "Utilities/Serialization/PupStlCpp17.hpp"
      54             : #include "Utilities/StdHelpers.hpp"
      55             : #include "Utilities/TMPL.hpp"
      56             : #include "Utilities/TypeTraits/IsA.hpp"
      57             : 
      58             : /// \cond
      59             : template <size_t Dim>
      60             : class Mesh;
      61             : namespace Frame {
      62             : struct Inertial;
      63             : }  // namespace Frame
      64             : /// \endcond
      65             : 
      66             : namespace dg {
      67             : namespace Events {
      68             : /// \cond
      69             : template <size_t VolumeDim, typename Tensors,
      70             :           typename NonTensorComputeTagsList = tmpl::list<>,
      71             :           typename ArraySectionIdTag = void>
      72             : class ObserveFields;
      73             : /// \endcond
      74             : 
      75             : /*!
      76             :  * \ingroup DiscontinuousGalerkinGroup
      77             :  * \brief %Observe volume tensor fields.
      78             :  *
      79             :  * A class that writes volume quantities to an h5 file during the simulation.
      80             :  * The observed quantitites are specified in the `VariablesToObserve` option.
      81             :  * Any `Tensor` in the `db::DataBox` can be observed but must be listed in the
      82             :  * `Tensors` template parameter. Any additional compute tags that hold a
      83             :  * `Tensor` can also be added to the `Tensors` template parameter. Finally,
      84             :  * `Variables` and other non-tensor compute tags can be listed in the
      85             :  * `NonTensorComputeTags` to facilitate observing. Note that the
      86             :  * `InertialCoordinates` are always observed.
      87             :  *
      88             :  * The user may specify an `interpolation_mesh` to which the
      89             :  * data is interpolated.
      90             :  *
      91             :  * \note The `NonTensorComputeTags` are intended to be used for `Variables`
      92             :  * compute tags like `Tags::DerivCompute`
      93             :  *
      94             :  * \par Array sections
      95             :  * This event supports sections (see `Parallel::Section`). Set the
      96             :  * `ArraySectionIdTag` template parameter to split up observations into subsets
      97             :  * of elements. The `observers::Tags::ObservationKey<ArraySectionIdTag>` must be
      98             :  * available in the DataBox. It identifies the section and is used as a suffix
      99             :  * for the path in the output file.
     100             :  */
     101             : template <size_t VolumeDim, typename... Tensors,
     102             :           typename... NonTensorComputeTags, typename ArraySectionIdTag>
     103           1 : class ObserveFields<VolumeDim, tmpl::list<Tensors...>,
     104             :                     tmpl::list<NonTensorComputeTags...>, ArraySectionIdTag>
     105             :     : public Event {
     106             :  public:
     107             :   /// The name of the subfile inside the HDF5 file
     108           1 :   struct SubfileName {
     109           0 :     using type = std::string;
     110           0 :     static constexpr Options::String help = {
     111             :         "The name of the subfile inside the HDF5 file without an extension and "
     112             :         "without a preceding '/'."};
     113             :   };
     114             : 
     115             :   /// \cond
     116             :   explicit ObserveFields(CkMigrateMessage* /*unused*/) {}
     117             :   using PUP::able::register_constructor;
     118             :   WRAPPED_PUPable_decl_template(ObserveFields);  // NOLINT
     119             :   /// \endcond
     120             : 
     121           0 :   struct VariablesToObserve {
     122           0 :     static constexpr Options::String help = "Subset of variables to observe";
     123           0 :     using type = std::vector<std::string>;
     124           0 :     static size_t lower_bound_on_size() { return 1; }
     125             :   };
     126             : 
     127           0 :   struct InterpolateToMesh {
     128           0 :     using type = Options::Auto<Mesh<VolumeDim>, Options::AutoLabel::None>;
     129           0 :     static constexpr Options::String help =
     130             :         "An optional mesh to which the variables are interpolated. This mesh "
     131             :         "specifies any number of collocation points, basis, and quadrature on "
     132             :         "which the observed quantities are evaluated. If no mesh is given, the "
     133             :         "results will be evaluated on the mesh the simulation runs on. The "
     134             :         "user may add several ObserveField Events e.g. with and without an "
     135             :         "interpolating mesh to output the data both on the original mesh and "
     136             :         "on a new mesh.";
     137             :   };
     138             : 
     139           0 :   struct ProjectToMesh {
     140           0 :     using type = Options::Auto<Mesh<VolumeDim>, Options::AutoLabel::None>;
     141           0 :     static constexpr Options::String help =
     142             :         "An optional mesh to which the variables are projected. This mesh "
     143             :         "must use a Legendre basis (Gauss or Gauss-Lobatto quadrature). This "
     144             :         "option is mutually exclusive with InterpolateToMesh. Projection "
     145             :         "truncates the fields in modal space but works only between two "
     146             :         "Legendre meshes, whereas interpolation works with any mesh but is not "
     147             :         "a clean truncation and therefore picks up an aliasing error.";
     148             :   };
     149             : 
     150             :   /// The floating point type/precision with which to write the data to disk.
     151             :   ///
     152             :   /// Must be specified once for all data or individually for each variable
     153             :   /// being observed.
     154           1 :   struct FloatingPointTypes {
     155           0 :     static constexpr Options::String help =
     156             :         "The floating point type/precision with which to write the data to "
     157             :         "disk.\n\n"
     158             :         "Must be specified once for all data or individually  for each "
     159             :         "variable being observed.";
     160           0 :     using type = std::vector<FloatingPointType>;
     161           0 :     static size_t upper_bound_on_size() { return sizeof...(Tensors); }
     162           0 :     static size_t lower_bound_on_size() { return 1; }
     163             :   };
     164             : 
     165             :   /// The floating point type/precision with which to write the coordinates to
     166             :   /// disk.
     167           1 :   struct CoordinatesFloatingPointType {
     168           0 :     static constexpr Options::String help =
     169             :         "The floating point type/precision with which to write the coordinates "
     170             :         "to disk.";
     171           0 :     using type = FloatingPointType;
     172             :   };
     173             : 
     174             :   /// \brief A list of block or group names on which to observe.
     175             :   ///
     176             :   /// Set to `All` to observe everywhere.
     177           1 :   struct BlocksToObserve {
     178           0 :     using type =
     179             :         Options::Auto<std::vector<std::string>, Options::AutoLabel::All>;
     180           0 :     static constexpr Options::String help = {
     181             :         "A list of block and group names on which to observe."};
     182             :   };
     183             : 
     184           0 :   using options = tmpl::list<SubfileName, CoordinatesFloatingPointType,
     185             :                              FloatingPointTypes, VariablesToObserve,
     186             :                              BlocksToObserve, InterpolateToMesh, ProjectToMesh>;
     187             : 
     188           0 :   static constexpr Options::String help =
     189             :       "Observe volume tensor fields.\n"
     190             :       "\n"
     191             :       "Writes volume quantities:\n"
     192             :       " * InertialCoordinates\n"
     193             :       " * Tensors listed in the 'VariablesToObserve' option\n";
     194             : 
     195           0 :   ObserveFields() = default;
     196             : 
     197             :   // The dependency isn't available through Options
     198           0 :   ObserveFields(
     199             :       const std::string& subfile_name,
     200             :       FloatingPointType coordinates_floating_point_type,
     201             :       const std::vector<FloatingPointType>& floating_point_types,
     202             :       const std::vector<std::string>& variables_to_observe,
     203             :       std::optional<std::vector<std::string>> active_block_or_block_groups = {},
     204             :       std::optional<Mesh<VolumeDim>> interpolation_mesh = {},
     205             :       std::optional<Mesh<VolumeDim>> projection_mesh = {},
     206             :       std::optional<std::string> dependency = {},
     207             :       const Options::Context& context = {});
     208             : 
     209           0 :   ObserveFields(
     210             :       const std::string& subfile_name,
     211             :       FloatingPointType coordinates_floating_point_type,
     212             :       const std::vector<FloatingPointType>& floating_point_types,
     213             :       const std::vector<std::string>& variables_to_observe,
     214             :       std::optional<std::vector<std::string>> active_block_or_block_groups = {},
     215             :       std::optional<Mesh<VolumeDim>> interpolation_mesh = {},
     216             :       std::optional<Mesh<VolumeDim>> projection_mesh = {},
     217             :       const Options::Context& context = {})
     218             :       : ObserveFields(subfile_name, coordinates_floating_point_type,
     219             :                       floating_point_types, variables_to_observe,
     220             :                       std::move(active_block_or_block_groups),
     221             :                       std::move(interpolation_mesh), std::move(projection_mesh),
     222             :                       std::nullopt, context) {}
     223             : 
     224           0 :   using compute_tags_for_observation_box =
     225             :       tmpl::list<Tensors..., NonTensorComputeTags...>;
     226             : 
     227           0 :   using return_tags = tmpl::list<>;
     228           0 :   using argument_tags = tmpl::list<::Tags::ObservationBox,
     229             :                                    ::Events::Tags::ObserverMesh<VolumeDim>>;
     230             : 
     231             :   template <typename DataBoxType, typename ComputeTagsList,
     232             :             typename Metavariables, typename ParallelComponent>
     233           0 :   void operator()(const ObservationBox<DataBoxType, ComputeTagsList>& box,
     234             :                   const Mesh<VolumeDim>& mesh,
     235             :                   Parallel::GlobalCache<Metavariables>& cache,
     236             :                   const ElementId<VolumeDim>& array_index,
     237             :                   const ParallelComponent* const component,
     238             :                   const ObservationValue& observation_value) const {
     239             :     if (not active_block(get<domain::Tags::Domain<VolumeDim>>(box),
     240             :                          array_index)) {
     241             :       return;
     242             :     }
     243             :     // Skip observation on elements that are not part of a section
     244             :     const std::optional<std::string> section_observation_key =
     245             :         observers::get_section_observation_key<ArraySectionIdTag>(box);
     246             :     if (not section_observation_key.has_value()) {
     247             :       return;
     248             :     }
     249             :     call_operator_impl(subfile_path_ + *section_observation_key,
     250             :                        variables_to_observe_, interpolation_mesh_,
     251             :                        projection_mesh_, mesh, box, cache, array_index,
     252             :                        component, observation_value, dependency_);
     253             :   }
     254             : 
     255             :   // We factor out the work into a static member function so it can  be shared
     256             :   // with other field observing events, like the one that deals with DG-subcell
     257             :   // where there are two grids. This is to avoid copy-pasting all of the code.
     258             :   template <typename DataBoxType, typename ComputeTagsList,
     259             :             typename Metavariables, typename ParallelComponent>
     260           0 :   static void call_operator_impl(
     261             :       const std::string& subfile_path,
     262             :       const std::unordered_map<std::string, FloatingPointType>&
     263             :           variables_to_observe,
     264             :       const std::optional<Mesh<VolumeDim>>& interpolation_mesh,
     265             :       const std::optional<Mesh<VolumeDim>>& projection_mesh,
     266             :       const Mesh<VolumeDim>& mesh,
     267             :       const ObservationBox<DataBoxType, ComputeTagsList>& box,
     268             :       Parallel::GlobalCache<Metavariables>& cache,
     269             :       const ElementId<VolumeDim>& element_id,
     270             :       const ParallelComponent* const /*meta*/,
     271             :       const ObservationValue& observation_value,
     272             :       const std::optional<std::string>& dependency) {
     273             :     const bool do_projection = projection_mesh.has_value();
     274             :     const Mesh<VolumeDim>& target_mesh =
     275             :         do_projection ? projection_mesh.value()
     276             :                       : interpolation_mesh.value_or(mesh);
     277             :     if (do_projection) {
     278             :       for (size_t d = 0; d < VolumeDim; ++d) {
     279             :         if (mesh.basis(d) != Spectral::Basis::Legendre or
     280             :             target_mesh.basis(d) != Spectral::Basis::Legendre) {
     281             :           ERROR("ProjectToMesh requires Legendre basis.");
     282             :         }
     283             :         if ((mesh.quadrature(d) != Spectral::Quadrature::Gauss and
     284             :              mesh.quadrature(d) != Spectral::Quadrature::GaussLobatto) or
     285             :             (target_mesh.quadrature(d) != Spectral::Quadrature::Gauss and
     286             :              target_mesh.quadrature(d) != Spectral::Quadrature::GaussLobatto)) {
     287             :           ERROR("ProjectToMesh requires Gauss or Gauss-Lobatto quadrature.");
     288             :         }
     289             :       }
     290             :     }
     291             :     // If no interpolation_mesh is provided, the interpolation is essentially
     292             :     // ignored by the RegularGridInterpolant except for a single copy.
     293             :     const intrp::RegularGrid interpolant(mesh, target_mesh);
     294             : 
     295             :     // Remove tensor types, only storing individual components.
     296             :     std::vector<TensorComponent> components;
     297             :     // This is larger than we need if we are only observing some
     298             :     // tensors, but that's not a big deal and calculating the correct
     299             :     // size is nontrivial.
     300             :     components.reserve(alg::accumulate(
     301             :         std::initializer_list<size_t>{
     302             :             std::decay_t<decltype(value(typename Tensors::type{}))>::size()...},
     303             :         0_st));
     304             : 
     305             :     const auto record_tensor_component_impl =
     306             :         [&components](DataVector&& tensor_component,
     307             :                       const FloatingPointType floating_point_type,
     308             :                       const std::string& component_name) {
     309             :           if (floating_point_type == FloatingPointType::Float) {
     310             :             components.emplace_back(component_name,
     311             :                                     std::vector<float>{tensor_component.begin(),
     312             :                                                        tensor_component.end()});
     313             :           } else {
     314             :             components.emplace_back(component_name,
     315             :                                     std::move(tensor_component));
     316             :           }
     317             :         };
     318             : 
     319             :     const auto record_tensor_components_impl =
     320             :         [&record_tensor_component_impl, &interpolant, &mesh, &target_mesh,
     321             :          do_projection](const auto& tensor,
     322             :                         const FloatingPointType floating_point_type,
     323             :                         const std::string& tag_name) {
     324             :           using TensorType = std::decay_t<decltype(tensor)>;
     325             :           using VectorType = typename TensorType::type;
     326             :           for (size_t i = 0; i < tensor.size(); ++i) {
     327             :             auto tensor_component =
     328             :                 do_projection
     329             :                     ? Spectral::project(
     330             :                           tensor[i], mesh, target_mesh,
     331             :                           make_array<VolumeDim>(Spectral::SegmentSize::Full),
     332             :                           make_array<VolumeDim>(Spectral::SegmentSize::Full))
     333             :                     : interpolant.interpolate(tensor[i]);
     334             :             const std::string component_name =
     335             :                 tag_name + tensor.component_suffix(i);
     336             :             if constexpr (std::is_same_v<VectorType, ComplexDataVector>) {
     337             :               record_tensor_component_impl(real(tensor_component),
     338             :                                            floating_point_type,
     339             :                                            "Re(" + component_name + ")");
     340             :               record_tensor_component_impl(imag(tensor_component),
     341             :                                            floating_point_type,
     342             :                                            "Im(" + component_name + ")");
     343             :             } else {
     344             :               record_tensor_component_impl(std::move(tensor_component),
     345             :                                            floating_point_type, component_name);
     346             :             }
     347             :           }
     348             :         };
     349             :     const auto record_tensor_components =
     350             :         [&box, &record_tensor_components_impl,
     351             :          &variables_to_observe](const auto tensor_tag_v) {
     352             :           using tensor_tag = tmpl::type_from<decltype(tensor_tag_v)>;
     353             :           const std::string tag_name = db::tag_name<tensor_tag>();
     354             :           if (const auto var_to_observe = variables_to_observe.find(tag_name);
     355             :               var_to_observe != variables_to_observe.end()) {
     356             :             const auto& tensor = get<tensor_tag>(box);
     357             :             if (not has_value(tensor)) {
     358             :               // This will only print a warning the first time it's called on a
     359             :               // node.
     360             :               [[maybe_unused]] static bool t =
     361             :                   ObserveFields::print_warning_about_optional<tensor_tag>();
     362             :               return;
     363             :             }
     364             :             const auto floating_point_type = var_to_observe->second;
     365             :             record_tensor_components_impl(value(tensor), floating_point_type,
     366             :                                           tag_name);
     367             :           }
     368             :         };
     369             :     EXPAND_PACK_LEFT_TO_RIGHT(record_tensor_components(tmpl::type_<Tensors>{}));
     370             : 
     371             :     const Parallel::ArrayComponentId array_component_id{
     372             :         std::add_pointer_t<ParallelComponent>{nullptr},
     373             :         Parallel::ArrayIndex<ElementId<VolumeDim>>{element_id}};
     374             :     ElementVolumeData element_volume_data{element_id, std::move(components),
     375             :                                           target_mesh};
     376             :     observers::ObservationId observation_id{observation_value.value,
     377             :                                             subfile_path + ".vol"};
     378             : 
     379             :     observers::contribute_volume_data<
     380             :         not Parallel::is_nodegroup_v<ParallelComponent>>(
     381             :         cache, std::move(observation_id), subfile_path, array_component_id,
     382             :         std::move(element_volume_data), dependency);
     383             :   }
     384             : 
     385           0 :   using observation_registration_tags = tmpl::list<::Tags::DataBox>;
     386             : 
     387             :   template <typename DbTagsList>
     388             :   std::optional<
     389             :       std::pair<observers::TypeOfObservation, observers::ObservationKey>>
     390           0 :   get_observation_type_and_key_for_registration(
     391             :       const db::DataBox<DbTagsList>& box) const {
     392             :     if (not active_block(db::get<domain::Tags::Domain<VolumeDim>>(box),
     393             :                          db::get<domain::Tags::Element<VolumeDim>>(box).id())) {
     394             :       return std::nullopt;
     395             :     }
     396             :     const std::optional<std::string> section_observation_key =
     397             :         observers::get_section_observation_key<ArraySectionIdTag>(box);
     398             :     if (not section_observation_key.has_value()) {
     399             :       return std::nullopt;
     400             :     }
     401             :     return {{observers::TypeOfObservation::Volume,
     402             :              observers::ObservationKey{
     403             :                  subfile_path_ + section_observation_key.value() + ".vol"}}};
     404             :   }
     405             : 
     406           0 :   using is_ready_argument_tags = tmpl::list<>;
     407             : 
     408             :   template <typename Metavariables, typename ArrayIndex, typename Component>
     409           0 :   bool is_ready(Parallel::GlobalCache<Metavariables>& /*cache*/,
     410             :                 const ArrayIndex& /*array_index*/,
     411             :                 const Component* const /*meta*/) const {
     412             :     return true;
     413             :   }
     414             : 
     415           1 :   bool needs_evolved_variables() const override { return true; }
     416             : 
     417             :   // NOLINTNEXTLINE(google-runtime-references)
     418           0 :   void pup(PUP::er& p) override {
     419             :     Event::pup(p);
     420             :     p | subfile_path_;
     421             :     p | variables_to_observe_;
     422             :     p | active_block_or_block_groups_;
     423             :     p | interpolation_mesh_;
     424             :     p | projection_mesh_;
     425             :     p | dependency_;
     426             :   }
     427             : 
     428             :  private:
     429             :   template <typename Tag>
     430           0 :   static bool print_warning_about_optional() {
     431             :     Parallel::printf(
     432             :         "Warning: ObserveFields is trying to dump the tag %s "
     433             :         "but it is stored as a std::optional and has not been "
     434             :         "evaluated. This most commonly occurs when you are "
     435             :         "trying to either observe an analytic solution or errors when "
     436             :         "no analytic solution is available.\n",
     437             :         db::tag_name<Tag>());
     438             :     return false;
     439             :   }
     440             : 
     441           0 :   bool active_block(const Domain<VolumeDim>& domain,
     442             :                     const ElementId<VolumeDim>& element_id) const {
     443             :     if (not active_block_or_block_groups_.has_value()) {
     444             :       return true;
     445             :     }
     446             :     const std::unordered_set<std::string> block_names =
     447             :         domain::expand_block_groups_to_block_names(
     448             :             active_block_or_block_groups_.value(), domain.block_names(),
     449             :             domain.block_groups());
     450             :     return alg::found(block_names,
     451             :                       domain.blocks().at(element_id.block_id()).name());
     452             :   }
     453             : 
     454           0 :   std::string subfile_path_;
     455           0 :   std::unordered_map<std::string, FloatingPointType> variables_to_observe_{};
     456           0 :   std::optional<std::vector<std::string>> active_block_or_block_groups_{};
     457           0 :   std::optional<Mesh<VolumeDim>> interpolation_mesh_{};
     458           0 :   std::optional<Mesh<VolumeDim>> projection_mesh_{};
     459           0 :   std::optional<std::string> dependency_;
     460             : };
     461             : 
     462             : template <size_t VolumeDim, typename... Tensors,
     463             :           typename... NonTensorComputeTags, typename ArraySectionIdTag>
     464             : ObserveFields<VolumeDim, tmpl::list<Tensors...>,
     465             :               tmpl::list<NonTensorComputeTags...>, ArraySectionIdTag>::
     466             :     ObserveFields(
     467             :         const std::string& subfile_name,
     468             :         const FloatingPointType coordinates_floating_point_type,
     469             :         const std::vector<FloatingPointType>& floating_point_types,
     470             :         const std::vector<std::string>& variables_to_observe,
     471             :         std::optional<std::vector<std::string>> active_block_or_block_groups,
     472             :         std::optional<Mesh<VolumeDim>> interpolation_mesh,
     473             :         std::optional<Mesh<VolumeDim>> projection_mesh,
     474             :         std::optional<std::string> dependency, const Options::Context& context)
     475             :     : subfile_path_("/" + subfile_name),
     476             :       variables_to_observe_([&context, &floating_point_types,
     477             :                              &variables_to_observe]() {
     478             :         if (floating_point_types.size() != 1 and
     479             :             floating_point_types.size() != variables_to_observe.size()) {
     480             :           PARSE_ERROR(context, "The number of floating point types specified ("
     481             :                                    << floating_point_types.size()
     482             :                                    << ") must be 1 or the number of variables "
     483             :                                       "specified for observing ("
     484             :                                    << variables_to_observe.size() << ")");
     485             :         }
     486             :         std::unordered_map<std::string, FloatingPointType> result{};
     487             :         for (size_t i = 0; i < variables_to_observe.size(); ++i) {
     488             :           result[variables_to_observe[i]] = floating_point_types.size() == 1
     489             :                                                 ? floating_point_types[0]
     490             :                                                 : floating_point_types[i];
     491             :           ASSERT(
     492             :               result.at(variables_to_observe[i]) == FloatingPointType::Float or
     493             :                   result.at(variables_to_observe[i]) ==
     494             :                       FloatingPointType::Double,
     495             :               "Floating point type for variable '"
     496             :                   << variables_to_observe[i]
     497             :                   << "' must be either Float or Double.");
     498             :         }
     499             :         return result;
     500             :       }()),
     501             :       active_block_or_block_groups_(std::move(active_block_or_block_groups)),
     502             :       interpolation_mesh_(interpolation_mesh),
     503             :       projection_mesh_(projection_mesh),
     504             :       dependency_(std::move(dependency)) {
     505             :   if (interpolation_mesh_.has_value() and projection_mesh_.has_value()) {
     506             :     PARSE_ERROR(context,
     507             :                 "Specify only one of InterpolateToMesh or ProjectToMesh.");
     508             :   }
     509             :   if (projection_mesh_.has_value()) {
     510             :     const auto& proj_mesh = projection_mesh_.value();
     511             :     for (size_t d = 0; d < VolumeDim; ++d) {
     512             :       if (proj_mesh.basis(d) != Spectral::Basis::Legendre) {
     513             :         PARSE_ERROR(context, "ProjectToMesh requires Legendre basis.");
     514             :       }
     515             :       if (proj_mesh.quadrature(d) != Spectral::Quadrature::Gauss and
     516             :           proj_mesh.quadrature(d) != Spectral::Quadrature::GaussLobatto) {
     517             :         PARSE_ERROR(
     518             :             context,
     519             :             "ProjectToMesh requires Gauss or Gauss-Lobatto quadrature.");
     520             :       }
     521             :     }
     522             :   }
     523             :   ASSERT(
     524             :       (... or (db::tag_name<Tensors>() == "InertialCoordinates")),
     525             :       "There is no tag with name 'InertialCoordinates' specified "
     526             :       "for the observer. Please make sure you specify a tag in the 'Tensors' "
     527             :       "list that has the 'db::tag_name()' 'InertialCoordinates'.");
     528             :   db::validate_selection<tmpl::list<Tensors...>>(variables_to_observe, context);
     529             :   variables_to_observe_["InertialCoordinates"] =
     530             :       coordinates_floating_point_type;
     531             : }
     532             : 
     533             : /// \cond
     534             : template <size_t VolumeDim, typename... Tensors,
     535             :           typename... NonTensorComputeTags, typename ArraySectionIdTag>
     536             : PUP::able::PUP_ID ObserveFields<VolumeDim, tmpl::list<Tensors...>,
     537             :                                 tmpl::list<NonTensorComputeTags...>,
     538             :                                 ArraySectionIdTag>::my_PUP_ID = 0;  // NOLINT
     539             : /// \endcond
     540             : }  // namespace Events
     541             : }  // namespace dg

Generated by: LCOV version 1.14