Some improvements on HDF5 export

This commit is contained in:
Anne de Jong 2017-02-08 21:02:17 +01:00
parent a7fa5cb646
commit a9d6378e7b
6 changed files with 50 additions and 58 deletions

View File

@ -366,7 +366,7 @@ void Duct::exportHDF5(const hid_t group_id) const {
rh.exportHDF5(group_id); rh.exportHDF5(group_id);
TXData u; TXData u;
u.name = "Velocity"; u.name = "Axial velocity";
u.unit = "m/s"; u.unit = "m/s";
u.symbol = "u"; u.symbol = "u";
u.x = dmat(sys.Ns(),ngp()); u.x = dmat(sys.Ns(),ngp());

View File

@ -48,6 +48,11 @@ namespace {
"symbol", "symbol",
data.symbol.c_str()); data.symbol.c_str());
H5LTset_attribute_string(hfgroup,
dsetname.c_str(),
"datatype",
data.datatype.c_str());
} }
} }
@ -60,16 +65,14 @@ void PointData::exportHDF5(hid_t hfgroup) {
hsize_t rank = 1; hsize_t rank = 1;
herr_t status; herr_t status;
string dsetname = (string("/") + symbol); // name
status = make_dataset(hfgroup, // Group status = make_dataset(hfgroup, // Group
dsetname.c_str(), symbol.c_str(),
rank, rank,
dims, dims,
&x); &x);
setAttributes(*this,dsetname,hfgroup); setAttributes(*this,symbol,hfgroup);
} }
@ -80,16 +83,14 @@ void TimeData::exportHDF5(hid_t hfgroup) {
hsize_t dims[] = {x.size()}; // First dimension has lenght 1 hsize_t dims[] = {x.size()}; // First dimension has lenght 1
hsize_t rank = 1; hsize_t rank = 1;
string dsetname = (string("/") + symbol); // name
herr_t status; herr_t status;
status = make_dataset(hfgroup, // Group status = make_dataset(hfgroup, // Group
dsetname.c_str(), // Dataset name symbol.c_str(), // Dataset name
rank, rank,
dims, dims,
x.memptr()); x.memptr());
setAttributes(*this,symbol,hfgroup);
setAttributes(*this,dsetname,hfgroup);
} }
void PosData::exportHDF5(hid_t hfgroup) { void PosData::exportHDF5(hid_t hfgroup) {
@ -101,17 +102,15 @@ void PosData::exportHDF5(hid_t hfgroup) {
hsize_t dims[] = {x.size()}; // First dimension has lenght 1 hsize_t dims[] = {x.size()}; // First dimension has lenght 1
hsize_t rank = 1; hsize_t rank = 1;
string dsetname = (string("/") + symbol); // name
herr_t status; herr_t status;
status = make_dataset(hfgroup, // Group status = make_dataset(hfgroup, // Group
dsetname.c_str(), symbol.c_str(),
rank, rank,
dims, dims,
x.memptr()); x.memptr());
setAttributes(*this,dsetname,hfgroup); setAttributes(*this,symbol,hfgroup);
H5Eprint(status,0); H5Eprint(status,0);
@ -119,11 +118,6 @@ void PosData::exportHDF5(hid_t hfgroup) {
void TXData::exportHDF5(hid_t hfgroup) { void TXData::exportHDF5(hid_t hfgroup) {
// We use the lite API for setting the data // We use the lite API for setting the data
// HDF5 Stores data in row-major ordering. Armadillo uses
// column-major ordering. Therefore, we store the transpose of the data.
dmat x = this->x.t();
hsize_t dims[] = {x.n_cols,x.n_rows}; // First dimension has lenght 1 hsize_t dims[] = {x.n_cols,x.n_rows}; // First dimension has lenght 1
hsize_t rank = 2; hsize_t rank = 2;
@ -135,20 +129,32 @@ void TXData::exportHDF5(hid_t hfgroup) {
col_ptrs[col] = &xptr[col*x.n_rows]; col_ptrs[col] = &xptr[col*x.n_rows];
} }
string dsetname = (string("/") + symbol); // name
make_dataset(hfgroup, // Group make_dataset(hfgroup, // Group
dsetname.c_str(), // name symbol.c_str(), // name
rank, rank,
dims, dims,
&col_ptrs[0][0]); &col_ptrs[0][0]);
setAttributes(*this, setAttributes(*this,
dsetname, symbol,
hfgroup); hfgroup);
// Generate the time-averaged values and export them as well
PosData time_avg;
time_avg.x = arma::mean(x).t();
time_avg.name = name + " (time-averaged)";
time_avg.unit = unit;
time_avg.symbol = symbol + "_gem";
time_avg.exportHDF5(hfgroup);
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////

View File

@ -17,25 +17,12 @@
#include <hdf5.h> #include <hdf5.h>
#endif #endif
DECLARE_ENUM(FileType,FileTypeTXT)
struct ExportData struct ExportData
{ {
string name; /**< Full name of the quantity */ string name; /**< Full name of the quantity */
string unit; /**< Unit of the quantity */ string unit; /**< Unit of the quantity */
string symbol; /**< Used symbol / abbreviation */ string symbol; /**< Used symbol / abbreviation */
string datatype; /**< Key representing the datatype */
/**
* Export the data to a text file
*
* @param FileType
* @param filename
* @param group
*
*
*/
// void export(const string& filename)=0;
/** /**
* Export the result to an existing HDF5 * Export the result to an existing HDF5
* *
@ -45,9 +32,6 @@ struct ExportData
virtual void exportHDF5(hid_t hfgroup)=0; virtual void exportHDF5(hid_t hfgroup)=0;
#endif #endif
// void show() const = 0;
virtual ~ExportData(){} virtual ~ExportData(){}
}; };
@ -57,7 +41,7 @@ struct ExportData
*/ */
struct PointData: public ExportData { struct PointData: public ExportData {
d x; /**< The value */ d x; /**< The value */
PointData() { datatype = "point";}
#ifdef TASMET_HDF5 #ifdef TASMET_HDF5
void exportHDF5(hid_t hfgroup); void exportHDF5(hid_t hfgroup);
#endif #endif
@ -69,8 +53,8 @@ struct PointData: public ExportData {
*/ */
struct TimeData: public ExportData struct TimeData: public ExportData
{ {
vd t; /**< The time instances of the TimeData() { datatype = "time";}
record */
vd x; /**< The quantity at the time vd x; /**< The quantity at the time
instance */ instance */
@ -86,10 +70,9 @@ struct TimeData: public ExportData
*/ */
struct PosData: public ExportData struct PosData: public ExportData
{ {
vd X; /**< The positions of the PosData() { datatype = "pos"; }
record */ vd x; /**< The quantity as function of the
vd x; /**< The quantity as function of the position */
position */
#ifdef TASMET_HDF5 #ifdef TASMET_HDF5
void exportHDF5(hid_t hfgroup); void exportHDF5(hid_t hfgroup);
@ -104,11 +87,8 @@ struct PosData: public ExportData
*/ */
struct TXData : public ExportData struct TXData : public ExportData
{ {
TXData() { datatype = "postime"; }
vd t; /**< The time instances of the
record */
vd X; /**< The positions of the record */
dmat x; /**< The quantity at the time and position instance. Note: dmat x; /**< The quantity at the time and position instance. Note:
the first axis denotes time, the second axis denotes the first axis denotes time, the second axis denotes
position! */ position! */

View File

@ -416,7 +416,7 @@ void TaSMETMainWindow::on_segmentname_textChanged() {
void TaSMETMainWindow::on_actionSolve_triggered() { void TaSMETMainWindow::on_actionSolve_triggered() {
TRACE(15,"actionSolve()"); TRACE(15,"actionSolve()");
SolverDialog *d; std::unique_ptr<SolverDialog> d;
std::unique_ptr<TaSystem> sys; std::unique_ptr<TaSystem> sys;
try { try {
@ -434,7 +434,7 @@ void TaSMETMainWindow::on_actionSolve_triggered() {
} }
catch(...) {} catch(...) {}
} }
d = new SolverDialog(this,*sys.get(),*_model.mutable_sparams()); d = std::unique_ptr<SolverDialog>(new SolverDialog(this,*sys.get(),*_model.mutable_sparams()));
} }
catch(TaSMETError &e) { catch(TaSMETError &e) {
@ -459,7 +459,6 @@ void TaSMETMainWindow::on_actionSolve_triggered() {
// dialog. Therefore we are now probably dirty // dialog. Therefore we are now probably dirty
changed(); changed();
delete d;
} }
void TaSMETMainWindow::on_actionPostprocess_model_triggered() { void TaSMETMainWindow::on_actionPostprocess_model_triggered() {

View File

@ -47,4 +47,6 @@ message Duct {
required string stempfunc = 16 [default = "293.15+x*x/L"]; required string stempfunc = 16 [default = "293.15+x*x/L"];
required SolidTemperatureModel stempmodel = 17 [default = Prescribed]; required SolidTemperatureModel stempmodel = 17 [default = Prescribed];
// Whether the total surface area is time-dependent or not
optional bool Sfixed = 18;
} }

View File

@ -486,13 +486,18 @@ void TaSystem::exportHDF5(const string& filename) const {
for(const auto& seg_ : _segs) { for(const auto& seg_ : _segs) {
// Create a group for each segment // Create a group for each segment
string group = string("/") + std::to_string(seg_.first);
VARTRACE(15,group);
hid_t grp_id = H5Gcreate(file_id, hid_t grp_id = H5Gcreate(file_id,
(string("/") + group.c_str(),
std::to_string(seg_.first)).c_str(), H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT, H5P_DEFAULT);
H5P_DEFAULT);
if(grp_id < 0)
throw TaSMETError("Group creation failed");
seg_.second->exportHDF5(grp_id); seg_.second->exportHDF5(grp_id);
// Close the group // Close the group