/home/runner/work/kynema/kynema/kynema/src/utilities/netcdf/node_state_writer.hpp Source File

Kynema API: /home/runner/work/kynema/kynema/kynema/src/utilities/netcdf/node_state_writer.hpp Source File
Kynema API
A flexible multibody structural dynamics code for wind turbines
Loading...
Searching...
No Matches
node_state_writer.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <algorithm>
4#include <array>
5#include <string>
6#include <vector>
7
8#include "netcdf_file.hpp"
9
10namespace kynema::util {
11
31public:
33 static constexpr size_t kDefaultBufferSize{0};
34
46 const std::string& file_path, bool create, size_t num_nodes,
47 const std::vector<std::string>& enabled_state_prefixes = {"x", "u", "v", "a", "f"},
48 size_t buffer_size = kDefaultBufferSize
49 );
50
53
54 // Rule of five -> explicitly delete the copy ctor, copy assignment operator,
55 // move ctor, and move assignment operator
60
75 size_t timestep, const std::string& component_prefix, const std::vector<double>& x,
76 const std::vector<double>& y, const std::vector<double>& z, const std::vector<double>& i,
77 const std::vector<double>& j, const std::vector<double>& k,
78 const std::vector<double>& w = std::vector<double>()
79 );
80
82 [[nodiscard]] const NetCdfFile& GetFile() const;
83
85 [[nodiscard]] size_t GetNumNodes() const;
86
88 void Close();
89
91 void Open();
92
93private:
94 NetCdfFile file_; //< NetCDF file object for writing output data
95 size_t num_nodes_; //< number of nodes in the simulation
96 std::vector<std::string> enabled_state_prefixes_; //< prefixes for the state components to write
97 size_t buffer_size_; //< number of timesteps to accumulate before auto-flush
98
106 void DefineStateVariables(
107 const std::string& prefix, const std::vector<int>& dimensions, bool has_w
108 );
109
110 //-----------------------------------
111 // support for buffering
112 //-----------------------------------
113
115 struct StateTimestepData {
116 size_t timestep;
117 std::string component_prefix; //< prefix for the component
118 std::vector<double> x, y, z, i, j, k, w; //< data for the component
119 };
120
121 std::vector<StateTimestepData>
122 state_buffers_[5]; //< buffer for each state component type -- x, u, v, a, f
123
129 [[nodiscard]] static size_t GetComponentIndex(const std::string& prefix);
130
135 void FlushStateBuffer(size_t component_index);
136
140 void FlushAllBuffers();
141};
142
143} // namespace kynema::util
Definition netcdf_file.hpp:18
Class for writing Kynema nodal state data to NetCDF-based output files.
Definition node_state_writer.hpp:30
NodeStateWriter(NodeStateWriter &&)=delete
NodeStateWriter & operator=(const NodeStateWriter &)=delete
NodeStateWriter & operator=(NodeStateWriter &&)=delete
size_t GetNumNodes() const
Get the number of nodes with state data in output file.
Definition node_state_writer.cpp:134
static constexpr size_t kDefaultBufferSize
Default buffer size (number of timesteps to accumulate before auto-flush, 0 = no buffering)
Definition node_state_writer.hpp:33
~NodeStateWriter()
Destructor to flush any remaining buffered data.
Definition node_state_writer.cpp:65
void WriteStateDataAtTimestep(size_t timestep, const std::string &component_prefix, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &i, const std::vector< double > &j, const std::vector< double > &k, const std::vector< double > &w=std::vector< double >())
Writes state data for a specific timestep.
Definition node_state_writer.cpp:72
NodeStateWriter(const NodeStateWriter &)=delete
void Open()
Manually (re)open the underlying NetCDF file.
Definition node_state_writer.cpp:146
void Close()
Manually flush and close the underlying NetCDF file.
Definition node_state_writer.cpp:138
const NetCdfFile & GetFile() const
Get the NetCDF file object.
Definition node_state_writer.cpp:130
Definition aerodyn_inflow.hpp:14