WriteToWorldtubeH5.hpp
1 // Distributed under the MIT License.
2 // See LICENSE.txt for details.
3 
4 #pragma once
5 
6 #include "DataStructures/ComplexModalVector.hpp"
7 #include "IO/H5/Dat.hpp"
8 #include "IO/H5/File.hpp"
9 #include "IO/H5/Version.hpp"
10 
11 namespace Cce {
12 namespace TestHelpers {
13 
14 // records worldtube data in the SpEC h5 style.
16  public:
17  WorldtubeModeRecorder(const std::string& filename,
18  const size_t l_max) noexcept
19  : output_file_{filename} {
20  // write the .ver that indicates that the derivatives are correctly
21  // normalized.
22  output_file_.insert<h5::Version>(
23  "/VersionHist", "Bugfix in CCE radial derivatives (ticket 1096).");
24  output_file_.close_current_object();
25  file_legend_.emplace_back("time");
26  for (int l = 0; l <= static_cast<int>(l_max); ++l) {
27  for (int m = -l; m <= l; ++m) {
28  file_legend_.push_back("Real Y_" + std::to_string(l) + "," +
29  std::to_string(m));
30  file_legend_.push_back("Imag Y_" + std::to_string(l) + "," +
31  std::to_string(m));
32  }
33  }
34  }
35 
36  // append to `dataset_path` the vector created by `time` followed by the
37  // `modes` rearranged to be compatible with SpEC h5 format.
38  void append_worldtube_mode_data(const std::string& dataset_path,
39  const double time,
40  const ComplexModalVector& modes,
41  const size_t l_max) noexcept {
42  auto& output_mode_dataset =
43  output_file_.try_insert<h5::Dat>(dataset_path, file_legend_, 0);
44  const size_t output_size = square(l_max + 1);
45  std::vector<double> data_to_write(2 * output_size + 1);
46  data_to_write[0] = time;
47  for (int l = 0; l <= static_cast<int>(l_max); ++l) {
48  for (int m = -l; m <= l; ++m) {
49  data_to_write[2 * Spectral::Swsh::goldberg_mode_index(
50  l_max, static_cast<size_t>(l), -m) +
51  1] =
53  l_max, static_cast<size_t>(l), m)]);
54  data_to_write[2 * Spectral::Swsh::goldberg_mode_index(
55  l_max, static_cast<size_t>(l), -m) +
56  2] =
58  l_max, static_cast<size_t>(l), m)]);
59  }
60  }
61  output_mode_dataset.append(data_to_write);
62  output_file_.close_current_object();
63  }
64 
65  private:
67  std::vector<std::string> file_legend_;
68 };
69 } // namespace TestHelpers
70 } // namespace Cce
Definition: TestCreation.hpp:14
ObjectType & insert(const std::string &path, Args &&... args)
Insert an object into an H5 file.
Definition: File.hpp:242
The set of utilities for performing Cauchy characteristic evolution and Cauchy characteristic matchin...
Definition: BoundaryComputeAndSendToEvolution.hpp:28
Defines class h5::H5File.
Represents a multicolumn dat file inside an HDF5 file.
Definition: Dat.hpp:42
constexpr size_t goldberg_mode_index(const size_t l_max, const size_t l, const int m, const size_t radial_offset=0) noexcept
Returns the index into a vector of modes consistent with .
Definition: SwshCoefficients.hpp:478
Used to store the version of the file.
Definition: Version.hpp:31
void close_current_object() const noexcept
Definition: File.hpp:151
A class for storing complex spectral coefficients on a spectral grid.
Definition: ComplexModalVector.hpp:39
Defines class h5::Version for storing version history of files.
ObjectType & try_insert(const std::string &path, Args &&... args) noexcept
Inserts an object like insert if it does not exist, returns the object if it does.
Definition: File.hpp:269
Defines class h5::Dat.
Definition: WriteToWorldtubeH5.hpp:15
decltype(auto) constexpr square(const T &x)
Compute the square of x
Definition: ConstantExpressions.hpp:54