SpECTRE Documentation Coverage Report
Current view: top level - IO/H5 - Cce.hpp Hit Total Coverage
Commit: f23e75c235cae5144b8ac7ce01280be5b8cd2c8a Lines: 12 16 75.0 %
Date: 2024-09-07 06:21:00
Legend: Lines: hit not hit

          Line data    Source code
       1           1 : // Distributed under the MIT License.
       2             : // See LICENSE.txt for details.
       3             : 
       4             : /// \file
       5             : /// Defines class h5::Cce
       6             : 
       7             : #pragma once
       8             : 
       9             : #include <array>
      10             : #include <cstddef>
      11             : #include <cstdint>
      12             : #include <hdf5.h>
      13             : #include <string>
      14             : #include <unordered_map>
      15             : #include <unordered_set>
      16             : #include <vector>
      17             : 
      18             : #include "IO/H5/Object.hpp"
      19             : #include "IO/H5/OpenGroup.hpp"
      20             : 
      21             : /// \cond
      22             : class Matrix;
      23             : /// \endcond
      24             : 
      25             : namespace h5 {
      26             : /*!
      27             :  * \ingroup HDF5Group
      28             :  * \brief Represents Cauchy-Characteristic Extraction (CCE) bondi variables
      29             :  * inside of an HDF5 file.
      30             :  *
      31             :  * Within a Cce object, there are several datasets that correspond to the
      32             :  * `Cce::scri_plus_interpolation_set` bondi variables at future null infinity
      33             :  * represented as complex spherical harmonic coefficients. The names of these
      34             :  * bondi variables are
      35             :  *
      36             :  * - `EthInertialRetardedTime`
      37             :  * - `News`
      38             :  * - `Psi0`
      39             :  * - `Psi1`
      40             :  * - `Psi2`
      41             :  * - `Psi3`
      42             :  * - `Psi4`
      43             :  * - `Strain`
      44             :  *
      45             :  * Each dataset has a couple H5 attributes:
      46             :  *
      47             :  * - `Legend` which is determined by the `l_max` massed to the constructor.
      48             :  * - `sxs_format` which is a string. The value is "SpECTRE_CCE_v1"
      49             :  *
      50             :  * The Cce object itself also has the `sxs_format` attribute with the same
      51             :  * value, along with a `version` and `header` attribute.
      52             :  *
      53             :  * The columns of data are stored in each dataset in the following order:
      54             :  *
      55             :  * - `time`
      56             :  * - `Real Y_0,0`
      57             :  * - `Imag Y_0,0`
      58             :  * - `Real Y_1,-1`
      59             :  * - `Imag Y_1,-1`
      60             :  * - `Real Y_1,0`
      61             :  * - `Imag Y_1,0`
      62             :  * - `Real Y_1,1`
      63             :  * - `Imag Y_1,1`
      64             :  * - ...
      65             :  *
      66             :  * and so on until you reach the coefficients for `l_max`.
      67             :  *
      68             :  * \note This class does not do any caching of data so all data is written as
      69             :  * soon as append() is called.
      70             :  */
      71           1 : class Cce : public h5::Object {
      72           0 :   struct DataSet {
      73           0 :     hid_t id;
      74           0 :     std::array<hsize_t, 2> size;
      75             :   };
      76             : 
      77             :  public:
      78             :   /// \cond HIDDEN_SYMBOLS
      79             :   static std::string extension() { return ".cce"; }
      80             : 
      81             :   Cce(bool exists, detail::OpenGroup&& group, hid_t location,
      82             :       const std::string& name, size_t l_max, uint32_t version = 1);
      83             : 
      84             :   Cce(const Cce& /*rhs*/) = delete;
      85             :   Cce& operator=(const Cce& /*rhs*/) = delete;
      86             :   Cce(Cce&& /*rhs*/) = delete;             // NOLINT
      87             :   Cce& operator=(Cce&& /*rhs*/) = delete;  // NOLINT
      88             : 
      89             :   ~Cce() override;
      90             :   /// \endcond HIDDEN_SYMBOLS
      91             : 
      92             :   /*!
      93             :    * \brief For each bondi variable name, appends the \p data to the dataset in
      94             :    * the H5 file.
      95             :    *
      96             :    * \details The `data.at(name).size()` must be the same as the number of
      97             :    * columns already in the dataset. Also, all bondi variable names listed in
      98             :    * the constructor of `h5::Cce` must be present in the \p data.
      99             :    */
     100           1 :   void append(const std::unordered_map<std::string, std::vector<double>>& data);
     101             : 
     102             :   /// @{
     103             :   /*!
     104             :    * \brief Return all currently stored data in the `h5::Cce` file in the form
     105             :    * of a `Matrix` for each bondi variable
     106             :    */
     107           1 :   std::unordered_map<std::string, Matrix> get_data() const;
     108             : 
     109           1 :   Matrix get_data(const std::string& bondi_variable_name) const;
     110             :   /// @}
     111             : 
     112             :   /// @{
     113             :   /*!
     114             :    * \brief Get only some values of $\ell$ over a range of rows
     115             :    *
     116             :    * \details The `time` column is always returned. The coefficients will be
     117             :    * returned in the order that you requested them in. No sorting is done
     118             :    * internally. All requested \p these_ell must be less that or equal to the \p
     119             :    * l_max that this file was constructed with. Also both the first and last row
     120             :    * requested must be less than or equal to the total number of rows.
     121             :    */
     122           1 :   std::unordered_map<std::string, Matrix> get_data_subset(
     123             :       const std::vector<size_t>& these_ell, size_t first_row = 0,
     124             :       size_t num_rows = 1) const;
     125             : 
     126           1 :   Matrix get_data_subset(const std::string& bondi_variable_name,
     127             :                          const std::vector<size_t>& these_ell,
     128             :                          size_t first_row = 0, size_t num_rows = 1) const;
     129             :   /// @}
     130             : 
     131             :   /*!
     132             :    * \brief Return the legend. All bondi variables have the same legend.
     133             :    */
     134           1 :   const std::vector<std::string> get_legend() const { return legend_; }
     135             : 
     136             :   /*!
     137             :    * \brief Return the number of rows (first index) and columns (second index)
     138             :    * of the \p bondi_variable_name dataset. All bondi variables will have the
     139             :    * same dimensions.
     140             :    */
     141           1 :   const std::array<hsize_t, 2>& get_dimensions(
     142             :       const std::string& bondi_variable_name) const;
     143             : 
     144             :   /*!
     145             :    * \brief The header of the Cce file
     146             :    */
     147           1 :   const std::string& get_header() const { return header_; }
     148             : 
     149             :   /*!
     150             :    * \brief The user-specified version number of the Cce file
     151             :    *
     152             :    * \note h5::Version returns a uint32_t, so we return one here too for the
     153             :    * version
     154             :    */
     155           1 :   uint32_t get_version() const { return version_; }
     156             : 
     157             :   /*!
     158             :    * \brief Path to this Cce file.
     159             :    */
     160           1 :   const std::string& subfile_path() const override { return path_; }
     161             : 
     162             :  private:
     163           0 :   void check_bondi_variable(const std::string& bondi_variable_name) const;
     164             :   /// \cond HIDDEN_SYMBOLS
     165             :   detail::OpenGroup group_;
     166             :   std::string name_;
     167             :   std::string path_;
     168             :   uint32_t version_;
     169             :   size_t l_max_;
     170             :   std::vector<std::string> legend_{};
     171             :   detail::OpenGroup cce_group_{};
     172             :   std::string header_;
     173             :   std::unordered_map<std::string, DataSet> bondi_datasets_;
     174             :   std::unordered_set<std::string> bondi_variables_{"EthInertialRetardedTime",
     175             :                                                    "News",
     176             :                                                    "Psi0",
     177             :                                                    "Psi1",
     178             :                                                    "Psi2",
     179             :                                                    "Psi3",
     180             :                                                    "Psi4",
     181             :                                                    "Strain"};
     182             :   std::string sxs_format_str_{"sxs_format"};
     183             :   std::string sxs_version_str_{"SpECTRE_CCE_v1"};
     184             :   /// \endcond HIDDEN_SYMBOLS
     185             : };
     186             : }  // namespace h5

Generated by: LCOV version 1.14