SpECTRE Documentation Coverage Report
Current view: top level - IO/Observer - WriteSimpleData.hpp Hit Total Coverage
Commit: 1f2210958b4f38fdc0400907ee7c6d5af5111418 Lines: 1 3 33.3 %
Date: 2025-12-05 05:03:31
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 <mutex>
       8             : 
       9             : #include "DataStructures/DataBox/DataBox.hpp"
      10             : #include "IO/H5/AccessType.hpp"
      11             : #include "IO/H5/File.hpp"
      12             : #include "IO/Observer/Helpers.hpp"
      13             : #include "IO/Observer/Tags.hpp"
      14             : #include "Parallel/ArrayComponentId.hpp"
      15             : #include "Parallel/GlobalCache.hpp"
      16             : #include "Parallel/Info.hpp"
      17             : #include "Parallel/Invoke.hpp"
      18             : #include "Parallel/Local.hpp"
      19             : #include "Parallel/NodeLock.hpp"
      20             : #include "Utilities/Requires.hpp"
      21             : #include "Utilities/TMPL.hpp"
      22             : 
      23             : namespace observers {
      24             : namespace ThreadedActions {
      25             : 
      26             : /*!
      27             :  * \brief Append data to an h5::Dat subfile of `Tags::VolumeFileName`.
      28             :  *
      29             :  * \details This is a streamlined interface for getting data to the volume file
      30             :  * associated with a node; it will simply write the `.dat` object
      31             :  * `subfile_name`, giving it the `file_legend` if it does not yet exist,
      32             :  * appending `data_row` to the end of the dat.
      33             :  */
      34           1 : struct WriteSimpleData {
      35             :   template <typename ParallelComponent, typename DbTagsList,
      36             :             typename Metavariables, typename ArrayIndex>
      37           0 :   static void apply(db::DataBox<DbTagsList>& box,
      38             :                     Parallel::GlobalCache<Metavariables>& cache,
      39             :                     const ArrayIndex& /*array_index*/,
      40             :                     const gsl::not_null<Parallel::NodeLock*> node_lock,
      41             :                     const std::vector<std::string>& file_legend,
      42             :                     const std::vector<double>& data_row,
      43             :                     const std::string& subfile_name) {
      44             :     Parallel::NodeLock* file_lock = nullptr;
      45             :     {
      46             :       const std::lock_guard hold_lock(*node_lock);
      47             :       db::mutate<Tags::H5FileLock>(
      48             :           [&file_lock](const gsl::not_null<Parallel::NodeLock*> in_file_lock) {
      49             :             file_lock = in_file_lock;
      50             :           },
      51             :           make_not_null(&box));
      52             :     }
      53             : 
      54             :     // scoped to close file
      55             :     {
      56             :       const std::lock_guard hold_lock(*file_lock);
      57             :       const auto& file_prefix = Parallel::get<Tags::VolumeFileName>(cache);
      58             :       auto& my_proxy =
      59             :           Parallel::get_parallel_component<ParallelComponent>(cache);
      60             :       h5::H5File<h5::AccessType::ReadWrite> h5file(
      61             :           file_prefix +
      62             :               std::to_string(
      63             :                   Parallel::my_node<int>(*Parallel::local_branch(my_proxy))) +
      64             :               ".h5",
      65             :           true, observers::input_source_from_cache(cache));
      66             :       const size_t version_number = 0;
      67             :       auto& output_dataset =
      68             :           h5file.try_insert<h5::Dat>(subfile_name, file_legend, version_number);
      69             :       output_dataset.append(data_row);
      70             :       h5file.close_current_object();
      71             :     }
      72             :   }
      73             : };
      74             : }  // namespace ThreadedActions
      75             : }  // namespace observers

Generated by: LCOV version 1.14