Move remaining writing of summary file to C++

This commit is contained in:
Paul Romano 2019-01-25 07:53:27 -06:00
parent 1690dc0af3
commit 4788bb9f85
9 changed files with 200 additions and 294 deletions

View file

@ -358,6 +358,12 @@ write_attribute(hid_t obj_id, const char* name, const char* buffer)
write_attr_string(obj_id, name, buffer);
}
inline void
write_attribute(hid_t obj_id, const char* name, const std::string& buffer)
{
write_attr_string(obj_id, name, buffer.c_str());
}
template<typename T, std::size_t N> inline void
write_attribute(hid_t obj_id, const char* name, const std::array<T, N>& buffer)
{
@ -398,6 +404,29 @@ write_dataset(hid_t obj_id, const char* name, const std::array<T, N>& buffer)
write_dataset(obj_id, 1, dims, name, H5TypeMap<T>::type_id, buffer.data(), false);
}
inline void
write_dataset(hid_t obj_id, const char* name, const std::vector<std::string>& buffer)
{
auto n {buffer.size()};
hsize_t dims[] {n};
// Determine length of longest string, including \0
size_t m = 1;
for (const auto& s : buffer) {
m = std::max(m, s.size() + 1);
}
// Copy data into contiguous buffer
char temp[n][m];
std::fill(temp[0], temp[0] + n*m, '\0');
for (int i = 0; i < n; ++i) {
std::copy(buffer[i].begin(), buffer[i].end(), temp[i]);
}
// Write 2D data
write_string(obj_id, 1, dims, m, name, temp[0], false);
}
template<typename T> inline void
write_dataset(hid_t obj_id, const char* name, const std::vector<T>& buffer)
{

View file

@ -6,6 +6,7 @@
#include <unordered_map>
#include <vector>
#include <hdf5.h>
#include "pugixml.hpp"
#include "xtensor/xtensor.hpp"
@ -58,6 +59,9 @@ public:
//! Set total density of the material
int set_density(double density, std::string units);
//! Write material data to HDF5
void to_hdf5(hid_t group) const;
// Data
int32_t id_; //!< Unique ID
std::string name_; //!< Name of material

17
include/openmc/summary.h Normal file
View file

@ -0,0 +1,17 @@
#ifndef OPENMC_SUMMARY_H
#define OPENMC_SUMMARY_H
#include <hdf5.h>
namespace openmc {
void write_summary();
void write_header(hid_t file);
void write_nuclides(hid_t file);
void write_geometry(hid_t file);
void write_materials(hid_t file);
}
#endif // OPENMC_SUMMARY_H