From a9d6378e7b14e91193b212929086b3b37dda871f Mon Sep 17 00:00:00 2001 From: Anne de Jong Date: Wed, 8 Feb 2017 21:02:17 +0100 Subject: [PATCH] Some improvements on HDF5 export --- src/duct/duct.cpp | 2 +- src/export/export.cpp | 48 +++++++++++++++++++++++------------------ src/export/export.h | 36 +++++++------------------------ src/gui/mainwindow.cpp | 5 ++--- src/protobuf/duct.proto | 2 ++ src/sys/tasystem.cpp | 15 ++++++++----- 6 files changed, 50 insertions(+), 58 deletions(-) diff --git a/src/duct/duct.cpp b/src/duct/duct.cpp index da0f6f2..90d7876 100644 --- a/src/duct/duct.cpp +++ b/src/duct/duct.cpp @@ -366,7 +366,7 @@ void Duct::exportHDF5(const hid_t group_id) const { rh.exportHDF5(group_id); TXData u; - u.name = "Velocity"; + u.name = "Axial velocity"; u.unit = "m/s"; u.symbol = "u"; u.x = dmat(sys.Ns(),ngp()); diff --git a/src/export/export.cpp b/src/export/export.cpp index 2f9813e..c8ead6b 100644 --- a/src/export/export.cpp +++ b/src/export/export.cpp @@ -48,6 +48,11 @@ namespace { "symbol", 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; herr_t status; - string dsetname = (string("/") + symbol); // name - status = make_dataset(hfgroup, // Group - dsetname.c_str(), + symbol.c_str(), rank, dims, &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 rank = 1; - string dsetname = (string("/") + symbol); // name herr_t status; status = make_dataset(hfgroup, // Group - dsetname.c_str(), // Dataset name + symbol.c_str(), // Dataset name rank, dims, x.memptr()); - - setAttributes(*this,dsetname,hfgroup); + setAttributes(*this,symbol,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 rank = 1; - - string dsetname = (string("/") + symbol); // name herr_t status; status = make_dataset(hfgroup, // Group - dsetname.c_str(), + symbol.c_str(), rank, dims, x.memptr()); - setAttributes(*this,dsetname,hfgroup); + setAttributes(*this,symbol,hfgroup); H5Eprint(status,0); @@ -119,11 +118,6 @@ void PosData::exportHDF5(hid_t hfgroup) { void TXData::exportHDF5(hid_t hfgroup) { // 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 rank = 2; @@ -135,20 +129,32 @@ void TXData::exportHDF5(hid_t hfgroup) { col_ptrs[col] = &xptr[col*x.n_rows]; } - string dsetname = (string("/") + symbol); // name - make_dataset(hfgroup, // Group - dsetname.c_str(), // name + symbol.c_str(), // name rank, dims, &col_ptrs[0][0]); setAttributes(*this, - dsetname, + symbol, 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); + } ////////////////////////////////////////////////////////////////////// + + diff --git a/src/export/export.h b/src/export/export.h index 5869cec..be4a9ab 100644 --- a/src/export/export.h +++ b/src/export/export.h @@ -17,25 +17,12 @@ #include #endif -DECLARE_ENUM(FileType,FileTypeTXT) - struct ExportData { string name; /**< Full name of the quantity */ string unit; /**< Unit of the quantity */ string symbol; /**< Used symbol / abbreviation */ - - /** - * Export the data to a text file - * - * @param FileType - * @param filename - * @param group - * - * - */ - // void export(const string& filename)=0; - + string datatype; /**< Key representing the datatype */ /** * Export the result to an existing HDF5 * @@ -45,9 +32,6 @@ struct ExportData virtual void exportHDF5(hid_t hfgroup)=0; #endif - - // void show() const = 0; - virtual ~ExportData(){} }; @@ -57,7 +41,7 @@ struct ExportData */ struct PointData: public ExportData { d x; /**< The value */ - + PointData() { datatype = "point";} #ifdef TASMET_HDF5 void exportHDF5(hid_t hfgroup); #endif @@ -69,8 +53,8 @@ struct PointData: public ExportData { */ struct TimeData: public ExportData { - vd t; /**< The time instances of the - record */ + TimeData() { datatype = "time";} + vd x; /**< The quantity at the time instance */ @@ -86,10 +70,9 @@ struct TimeData: public ExportData */ struct PosData: public ExportData { - vd X; /**< The positions of the - record */ - vd x; /**< The quantity as function of the - position */ + PosData() { datatype = "pos"; } + vd x; /**< The quantity as function of the + position */ #ifdef TASMET_HDF5 void exportHDF5(hid_t hfgroup); @@ -104,11 +87,8 @@ struct PosData: 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: the first axis denotes time, the second axis denotes position! */ diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 77d49d1..83110a2 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -416,7 +416,7 @@ void TaSMETMainWindow::on_segmentname_textChanged() { void TaSMETMainWindow::on_actionSolve_triggered() { TRACE(15,"actionSolve()"); - SolverDialog *d; + std::unique_ptr d; std::unique_ptr sys; try { @@ -434,7 +434,7 @@ void TaSMETMainWindow::on_actionSolve_triggered() { } catch(...) {} } - d = new SolverDialog(this,*sys.get(),*_model.mutable_sparams()); + d = std::unique_ptr(new SolverDialog(this,*sys.get(),*_model.mutable_sparams())); } catch(TaSMETError &e) { @@ -459,7 +459,6 @@ void TaSMETMainWindow::on_actionSolve_triggered() { // dialog. Therefore we are now probably dirty changed(); - delete d; } void TaSMETMainWindow::on_actionPostprocess_model_triggered() { diff --git a/src/protobuf/duct.proto b/src/protobuf/duct.proto index c521e76..37e75f5 100644 --- a/src/protobuf/duct.proto +++ b/src/protobuf/duct.proto @@ -47,4 +47,6 @@ message Duct { required string stempfunc = 16 [default = "293.15+x*x/L"]; required SolidTemperatureModel stempmodel = 17 [default = Prescribed]; + // Whether the total surface area is time-dependent or not + optional bool Sfixed = 18; } diff --git a/src/sys/tasystem.cpp b/src/sys/tasystem.cpp index e7b8183..057b702 100644 --- a/src/sys/tasystem.cpp +++ b/src/sys/tasystem.cpp @@ -486,13 +486,18 @@ void TaSystem::exportHDF5(const string& filename) const { for(const auto& seg_ : _segs) { // Create a group for each segment + string group = string("/") + std::to_string(seg_.first); + VARTRACE(15,group); hid_t grp_id = H5Gcreate(file_id, - (string("/") + - std::to_string(seg_.first)).c_str(), - H5P_DEFAULT, - H5P_DEFAULT, - H5P_DEFAULT); + group.c_str(), + H5P_DEFAULT, + H5P_DEFAULT, + H5P_DEFAULT); + if(grp_id < 0) + throw TaSMETError("Group creation failed"); + + seg_.second->exportHDF5(grp_id); // Close the group