Cholla 3.0.1-dev
Cholla - Massively parallel hydro on GPUs
Loading...
Searching...
No Matches
system_tester.h
1
9#pragma once
10
11// STL includes
12#include <memory>
13#include <string>
14#include <string_view>
15#include <unordered_map>
16#include <vector>
17
18// External Libraries and Headers
19#include <H5Cpp.h>
20
21#include "../io/io.h" // to_string_exact
22
26namespace system_test
27{
28
31{
33 std::string s_;
34
36 ParamArgListBuilder &update_(std::string_view name, std::string_view val)
37 {
38 s_.reserve(s_.size() + 2 + name.size() + val.size());
39 s_ += ' ';
40 s_ += name;
41 s_ += '=';
42 s_ += val;
43 return *this;
44 }
45
46 public:
48 const std::string &getCombinedArgList() const { return s_; }
49
50 // we may need to add more overloads over time
52
56 ParamArgListBuilder &param(std::string_view name, int val) { return update_(name, std::to_string(val)); }
57 ParamArgListBuilder &param(std::string_view name, size_t val) { return update_(name, std::to_string(val)); }
58 ParamArgListBuilder &param(std::string_view name, float val) { return update_(name, to_string_exact(val)); }
59 ParamArgListBuilder &param(std::string_view name, double val) { return update_(name, to_string_exact(val)); }
60 ParamArgListBuilder &param(std::string_view name, std::string_view val)
61 {
62 // for now, this is simple. This will get more complex if we require strings to be quoted
63 return update_(name, val);
64 }
66};
67
93class SystemTestRunner;
94} // namespace system_test
95
97{
98 public:
100 size_t numMpiRanks = 1;
101
110
115 void runTest(bool const &compute_L2_norm_only = false, double const &maxAllowedL1Error = 0.0,
116 double const &maxAllowedError = 0.0);
117
126 void runL1ErrorTest(double const &maxAllowedL1Error, double const &maxAllowedError = 1E-7);
127
132 void launchCholla();
133
134 void openHydroTestData();
135
141 std::string getChollaPath() { return _chollaPath; };
142
149 std::string getChollaSettingsFilePath() { return _chollaSettingsPath; };
150
156 double getL2Norm() { return L2Norm_; };
157
164 std::string getOutputDirectory() { return _outputDirectory; };
165
172 std::string getConsoleOutputPath() { return _consoleOutputPath; };
173
179 H5::H5File getFiducialFile() { return _fiducialFile; };
180
187 H5::H5File getTestFile(size_t const &i = 0) { return _testHydroFieldsFileVec[i]; };
188
194 std::vector<std::string> getDataSetsToTest() { return _fiducialDataSetNames; };
195
201 void setFixedEpsilon(double const &newVal) { _fixedEpsilon = newVal; };
202
212 void setDataSetsToTest(std::vector<std::string> const &dataSetNames) { _fiducialDataSetNames = dataSetNames; };
213
220 void setCompareNumTimeSteps(bool const &compare) { _compareNumTimeSteps = compare; };
221
229 void setFiducialData(std::string const &fieldName, std::vector<double> const &dataVec);
230
236 void setFiducialNumTimeSteps(int const &numTimeSteps) { _numFiducialTimeSteps = numTimeSteps; };
237
252 std::vector<double> generateConstantData(double const &value, size_t const &nx = 1, size_t const &ny = 1,
253 size_t const &nz = 1);
254
265 std::vector<double> loadTestFieldData(std::string dataSetName, std::vector<size_t> &testDims,
266 std::vector<H5::H5File> file = {});
267
289 std::vector<double> generateSineData(double const &offset, double const &amplitude, double const &kx,
290 double const &ky, double const &kz, double const &phase, size_t const &nx = 1,
291 size_t const &ny = 1, size_t const &nz = 1);
292
293 // Constructor and Destructor
308 SystemTestRunner(bool const &particleData = false, bool const &hydroData = true, bool const &useFiducialFile = true,
309 bool const &useSettingsFile = true, bool const &gravityData = false);
310 ~SystemTestRunner();
311
312 private:
314 H5::H5File _fiducialFile;
316 std::vector<H5::H5File> _testHydroFieldsFileVec;
318 std::vector<H5::H5File> _testParticlesFileVec;
320 std::vector<H5::H5File> _testGravityFileVec;
321
323 std::string _chollaPath;
326 std::string _fullTestFileName;
328 std::string _chollaSettingsPath;
330 std::string _fiducialFilePath;
332 std::string _outputDirectory;
334 std::string _consoleOutputPath;
335
337 std::vector<std::string> _fiducialDataSetNames;
339 std::vector<std::string> _testDataSetNames;
340
342 int _numFiducialTimeSteps;
344 std::unordered_map<std::string, std::vector<double>> _fiducialDataSets;
345
347 std::vector<double> _testParticleIDs;
349 size_t _testTotalNumParticles = 0;
351 std::vector<double> _fiducialParticleIDs;
353 size_t _fiducialTotalNumParticles = 0;
354
357 double _fixedEpsilon = 5.0E-12;
358
360 double L2Norm_;
361
365 bool _fiducialFileExists = false;
367 bool _compareNumTimeSteps = true;
368
373 bool _hydroDataExists = true;
378 bool _particleDataExists = false;
379
384 bool _gravityDataExists = false;
385
391 void _checkNumTimeSteps();
392
401 std::vector<double> _loadTestParticleData(std::string const &dataSetName);
402
411 std::vector<double> _loadFiducialFieldData(std::string const &dataSetName);
412
413 std::vector<double> _loadGravityPotential(H5::H5File const &data_file);
414
422 std::vector<double> _loadFiducialParticleData(std::string const &dataSetName);
423
430 std::vector<std::string> _findDataSetNames(H5::H5File const &inputFile);
431}; // End of class system_test::SystemTestRunner
Definition system_tester.h:31
const std::string & getCombinedArgList() const
Definition system_tester.h:48
ParamArgListBuilder & param(std::string_view name, int val)
Definition system_tester.h:56
Definition system_tester.h:97
H5::H5File getTestFile(size_t const &i=0)
Get the Test File object.
Definition system_tester.h:187
std::string getOutputDirectory()
Get the Output Directory object.
Definition system_tester.h:164
void runTest(bool const &compute_L2_norm_only=false, double const &maxAllowedL1Error=0.0, double const &maxAllowedError=0.0)
Run the system test that has been set up.
Definition system_tester.cpp:34
void setFixedEpsilon(double const &newVal)
Set the Fixed Epsilon value.
Definition system_tester.h:201
void setDataSetsToTest(std::vector< std::string > const &dataSetNames)
Choose which datasets to test. By default it tests all the datasets in the fiducial data....
Definition system_tester.h:212
void setFiducialNumTimeSteps(int const &numTimeSteps)
Set the Fiducial Num Time Steps object.
Definition system_tester.h:236
size_t numMpiRanks
The number of MPI ranks, defaults to 1.
Definition system_tester.h:100
std::vector< double > loadTestFieldData(std::string dataSetName, std::vector< size_t > &testDims, std::vector< H5::H5File > file={})
Load the test data for physical fields from the HDF5 file(s). If there is more than one HDF5 file the...
Definition system_tester.cpp:562
void setFiducialData(std::string const &fieldName, std::vector< double > const &dataVec)
Set or add a fiducial dataset.
Definition system_tester.cpp:397
void runL1ErrorTest(double const &maxAllowedL1Error, double const &maxAllowedError=1E-7)
Compute the L1 error for each field compared to the initial conditions. Doesn't work with particle da...
Definition system_tester.cpp:226
std::vector< double > generateConstantData(double const &value, size_t const &nx=1, size_t const &ny=1, size_t const &nz=1)
Generate an vector of the specified size populated by the specified value.
Definition system_tester.cpp:412
system_test::ParamArgListBuilder chollaLaunchParams
Set the parameters that Cholla launches with, potentially entirely replacing the need for a settings ...
Definition system_tester.h:109
std::string getConsoleOutputPath()
Get the Console Output Path object.
Definition system_tester.h:172
std::string getChollaPath()
Get the Cholla Path object.
Definition system_tester.h:141
std::vector< std::string > getDataSetsToTest()
Get the vector of datasets that will be tested.
Definition system_tester.h:194
double getL2Norm()
Get the L2Norm.
Definition system_tester.h:156
std::vector< double > generateSineData(double const &offset, double const &amplitude, double const &kx, double const &ky, double const &kz, double const &phase, size_t const &nx=1, size_t const &ny=1, size_t const &nz=1)
Generate a std::vector of the specified size populated by a sine wave. The equation used to generate ...
Definition system_tester.cpp:425
H5::H5File getFiducialFile()
Get the Fiducial File object.
Definition system_tester.h:179
void setCompareNumTimeSteps(bool const &compare)
Set the Compare Num Time Steps object.
Definition system_tester.h:220
std::string getChollaSettingsFilePath()
Get the Cholla Settings File Path object.
Definition system_tester.h:149
void launchCholla()
Launch Cholla as it is set up.
Definition system_tester.cpp:357
std::string to_string_exact(T const &input)
Convert a floating point number to a string such that it can be exactly deserialized back from a stri...
Definition io.h:51
This namespace defines SystemTestRunner (and all relevant machinery).
Definition system_tester.h:27