-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSDUtil.hpp
178 lines (154 loc) · 4.18 KB
/
GSDUtil.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
//
// Created by Alec Glisman on 07/30/21
// Building off of GSDReader class in HOOMD-Blue
//
#ifndef BODIES_IN_POTENTIAL_FLOW_GSD_READER_H
#define BODIES_IN_POTENTIAL_FLOW_GSD_READER_H
#ifdef NVCC
#error This header cannot be compiled by nvcc
#endif
/* Include all internal project dependencies */
#include <SystemData.hpp>
#include <gsd.h> // GSD File
/* Include all external project dependencies */
// Logging
#include <spdlog/sinks/basic_file_sink.h>
#include <spdlog/spdlog.h>
// STL
#include <memory> // for std::unique_ptr and std::shared_ptr
#include <stdexcept> // std::errors
#include <string> // std::string
/* Forward declarations */
class SystemData;
/**
* @class GSDUtil
*
* @brief Wrapper class for `gsd.h` to load data from input GSD file into `SystemData` class
*
*/
class GSDUtil
{
public:
/**
* @brief Construct a new GSDUtil object
*
* @param sys `SystemData` class to collect data from. Its attributes will be overwritten using setter functions.
*/
explicit GSDUtil(std::shared_ptr<SystemData> sys);
/**
* @brief Construct a new GSDUtil object
*
* @param sys `SystemData` class to collect data from. Its attributes will be overwritten using setter functions.
* @param frame specific GSD frame number to parse
*/
explicit GSDUtil(std::shared_ptr<SystemData> sys, uint64_t frame);
/**
* @brief Destroy the GSDUtil object
*
*/
~GSDUtil();
/**
* @brief Removes all frames and data from GSD file. This returns GSD to a "new file" state.
*
* @warning Make sure you are positive that you want to call this function. It is dangerous, as it deletes all data
* inside GSD file.
*/
void
truncateGSD();
/**
* @brief Appends frame to GSD file using data from `SystemData` class
*
* @details Ends GSD frame after data is written
*
*/
void
writeFrame();
private:
/**
* @brief Helper function that checks data parsing from GSD is successful.
*
*/
void
checkGSDReturn();
/**
* @brief Finds and then loads data from GSD
*
* @details Expected size is in units of bytes
* u_int8: 1
* float (np.single, np.float32): 4
* double (np.double, np.float64): 8
*
* @param data pointer to variable function will load data into
* @param frame GSD frame number to load data from
* @param name Path of data chunk to load data from in GSD schema
* @param expected_size n number of bytes that data is.
* @param cur_n number of rows in chunk
* @return true Data chunk found and loaded
* @return false Data chunk not found
*/
bool
readChunk(void* data, uint64_t frame, const char* name, size_t expected_size, unsigned int cur_n = 0);
/**
* @brief Read header information from GSD frame `m_frame`
*
*/
void
readHeader();
/**
* @brief Read parameter information from GSD frame `m_frame`
*
*/
void
readParameters();
/**
* @brief Read particle information from GSD frame `m_frame`
*
*/
void
readParticles();
/**
* @brief Reads system specific variables from GSD frame `m_frame`
*
* @review_swimmer change variables loaded based on variables needed in `SystemData` for specific systems.
*/
void
readSystemSpecifics();
/**
* @brief Writes header information to GSD
*
*/
void
writeHeader();
/**
* @brief Writes parameter information to GSD
*
*/
void
writeParameters();
/**
* @brief Writes particle information to GSD
*
*/
void
writeParticles();
// classes
/// shared pointer reference to `SystemData` class
std::shared_ptr<SystemData> m_system;
// GSD
/// GSD frame number
uint64_t m_frame;
// logging
/// path of logfile for spdlog to write to
std::string m_logFile;
/// filename of logfile for spdlog to write to
const std::string m_logName{"GSDUtil"};
/* SECTION: getters/setters */
public:
uint64_t
frame() const
{
return m_frame;
}
/* !SECTION */
};
#endif // BODIES_IN_POTENTIAL_FLOW_GSD_READER_H