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);
TXData u;
u.name = "Velocity";
u.name = "Axial velocity";
u.unit = "m/s";
u.symbol = "u";
u.x = dmat(sys.Ns(),ngp());

View File

@ -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);
}
//////////////////////////////////////////////////////////////////////

View File

@ -17,25 +17,12 @@
#include <hdf5.h>
#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! */

View File

@ -416,7 +416,7 @@ void TaSMETMainWindow::on_segmentname_textChanged() {
void TaSMETMainWindow::on_actionSolve_triggered() {
TRACE(15,"actionSolve()");
SolverDialog *d;
std::unique_ptr<SolverDialog> d;
std::unique_ptr<TaSystem> 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<SolverDialog>(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() {

View File

@ -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;
}

View File

@ -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