SpECTRE Documentation Coverage Report
Current view: top level - IO/H5 - Cce.hpp Coverage Total Hit
Commit: 0d1d717af84a81fb1284a20c4013708fe85cc2f0 Lines: 75.0 % 16 12
Test Date: 2026-10-22 17:29:42
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` or a `std::vector<std::vector<double>>` for each bondi
     106              :    * variable
     107              :    */
     108              :   template <typename T = Matrix>
     109            1 :   std::unordered_map<std::string, T> get_data() const;
     110              : 
     111              :   template <typename T = Matrix>
     112            1 :   T get_data(const std::string& bondi_variable_name) const;
     113              :   /// @}
     114              : 
     115              :   /// @{
     116              :   /*!
     117              :    * \brief Get only some values of $\ell$ over a range of rows
     118              :    *
     119              :    * \details The `time` column is always returned. The coefficients will be
     120              :    * returned in the order that you requested them in. No sorting is done
     121              :    * internally. All requested \p these_ell must be less that or equal to the \p
     122              :    * l_max that this file was constructed with. Also both the first and last row
     123              :    * requested must be less than or equal to the total number of rows.
     124              :    */
     125              :   template <typename T = Matrix>
     126            1 :   std::unordered_map<std::string, T> get_data_subset(
     127              :       const std::vector<size_t>& these_ell, size_t first_row = 0,
     128              :       size_t num_rows = 1) const;
     129              : 
     130              :   template <typename T = Matrix>
     131            1 :   T get_data_subset(const std::string& bondi_variable_name,
     132              :                     const std::vector<size_t>& these_ell, size_t first_row = 0,
     133              :                     size_t num_rows = 1) const;
     134              :   /// @}
     135              : 
     136              :   /*!
     137              :    * \brief Return the legend. All bondi variables have the same legend.
     138              :    */
     139            1 :   const std::vector<std::string> get_legend() const { return legend_; }
     140              : 
     141              :   /*!
     142              :    * \brief Return the number of rows (first index) and columns (second index)
     143              :    * of the \p bondi_variable_name dataset. All bondi variables will have the
     144              :    * same dimensions.
     145              :    */
     146            1 :   const std::array<hsize_t, 2>& get_dimensions(
     147              :       const std::string& bondi_variable_name) const;
     148              : 
     149              :   /*!
     150              :    * \brief The header of the Cce file
     151              :    */
     152            1 :   const std::string& get_header() const { return header_; }
     153              : 
     154              :   /*!
     155              :    * \brief The user-specified version number of the Cce file
     156              :    *
     157              :    * \note h5::Version returns a uint32_t, so we return one here too for the
     158              :    * version
     159              :    */
     160            1 :   uint32_t get_version() const { return version_; }
     161              : 
     162              :   /*!
     163              :    * \brief Path to this Cce file.
     164              :    */
     165            1 :   const std::string& subfile_path() const override { return path_; }
     166              : 
     167              :  private:
     168            0 :   void check_bondi_variable(const std::string& bondi_variable_name) const;
     169              :   /// \cond HIDDEN_SYMBOLS
     170              :   detail::OpenGroup group_;
     171              :   std::string name_;
     172              :   std::string path_;
     173              :   uint32_t version_;
     174              :   size_t l_max_;
     175              :   std::vector<std::string> legend_{};
     176              :   detail::OpenGroup cce_group_{};
     177              :   std::string header_;
     178              :   std::unordered_map<std::string, DataSet> bondi_datasets_;
     179              :   std::unordered_set<std::string> bondi_variables_{"EthInertialRetardedTime",
     180              :                                                    "News",
     181              :                                                    "Psi0",
     182              :                                                    "Psi1",
     183              :                                                    "Psi2",
     184              :                                                    "Psi3",
     185              :                                                    "Psi4",
     186              :                                                    "Strain"};
     187              :   std::string sxs_format_str_{"sxs_format"};
     188              :   std::string sxs_version_str_{"SpECTRE_CCE_v1"};
     189              :   /// \endcond HIDDEN_SYMBOLS
     190              : };
     191              : }  // namespace h5
        

Generated by: LCOV version 2.0-1