From fbab37e0ad15fd77a3bd359dca8c532df2fd310f Mon Sep 17 00:00:00 2001 From: Thorsten Liebig Date: Mon, 27 Dec 2010 13:54:09 +0100 Subject: [PATCH] processfields: reorganized hdf field & mesh dumps --- Common/processfields.cpp | 98 ++++++++++++++++++------------------- Common/processfields.h | 9 ++-- Common/processfields_fd.cpp | 23 ++++++++- Common/processfields_td.cpp | 28 ++++++++++- Common/processfields_td.h | 2 + 5 files changed, 103 insertions(+), 57 deletions(-) diff --git a/Common/processfields.cpp b/Common/processfields.cpp index 761a5da..94d35f7 100644 --- a/Common/processfields.cpp +++ b/Common/processfields.cpp @@ -46,53 +46,6 @@ ProcessFields::~ProcessFields() } } -void ProcessFields::InitProcess() -{ - if (Enabled==false) return; - //get the correct direction names for all coordinate systems - string names[] = {Op->GetDirName(0),Op->GetDirName(1),Op->GetDirName(2)}; - if (m_fileType==HDF5_FILETYPE) - { - m_filename+= ".h5"; - - H5::H5File* file = new H5::H5File( m_filename , H5F_ACC_TRUNC ); - - H5::Group* group = new H5::Group( file->createGroup( "/Mesh" )); - for (int n=0; n<3; ++n) - { - hsize_t dimsf[1]; // dataset dimensions - dimsf[0] = numLines[n]; - H5::DataSpace dataspace( 1, dimsf ); - H5::FloatType datatype( H5::PredType::NATIVE_FLOAT ); - H5::DataSet dataset = group->createDataSet( names[n].c_str(), datatype, dataspace ); - //convert to float... - float* array = new float[numLines[n]]; - for (unsigned int i=0; iGetGridDelta(); -#endif - } - //write to dataset - dataset.write( array, H5::PredType::NATIVE_FLOAT ); - } - delete group; - - group = new H5::Group( file->createGroup( "/FieldData" )); - delete group; - group = new H5::Group( file->createGroup( "/FieldData/FD" )); - delete group; - group = new H5::Group( file->createGroup( "/FieldData/TD" )); - delete group; - delete file; - } -} - string ProcessFields::GetFieldNameByType(DumpType type) { switch (type) @@ -418,14 +371,57 @@ bool ProcessFields::DumpMultiScalarArray2VTK(ofstream &file, string names[], FDT return true; } -bool ProcessFields::DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time) + +bool ProcessFields::WriteMesh2HDF5(string filename, string groupName, unsigned int const* numLines, double const* const* discLines, MeshType meshT, double discLines_scaling) +{ + H5::H5File file( filename, H5F_ACC_RDWR ); + + H5::Group hdf_group( file.openGroup( groupName )); + + string names[] = {"x","y","z"}; + if (meshT==CYLINDRICAL_MESH) + { + names[0]="rho"; + names[1]="alpha"; + } + + H5::Group* group = new H5::Group( hdf_group.createGroup( "/Mesh" )); + for (int n=0; n<3; ++n) + { + hsize_t dimsf[1]; // dataset dimensions + dimsf[0] = numLines[n]; + H5::DataSpace dataspace( 1, dimsf ); + H5::FloatType datatype( H5::PredType::NATIVE_FLOAT ); + H5::DataSet dataset = group->createDataSet( names[n].c_str(), datatype, dataspace ); + //convert to float... + float* array = new float[numLines[n]]; + for (unsigned int i=0; i const* const* const* const* array, unsigned int const* numLines, float weight, float frequency) +bool ProcessFields::DumpVectorArray2HDF5(string filename, string groupName, string name, std::complex const* const* const* const* array, unsigned int const* numLines, float weight, float frequency) { const H5std_string FILE_NAME(filename); const H5std_string DATASET_NAME_RE( name + "_real"); @@ -474,7 +470,7 @@ bool ProcessFields::DumpVectorArray2HDF5(string filename, string name, std::comp H5::H5File file( FILE_NAME, H5F_ACC_RDWR ); - H5::Group group( file.openGroup( "/FieldData/FD" )); + H5::Group group( file.openGroup( groupName )); hsize_t t_dimsf[] = {1}; H5::DataSpace t_dataspace( 1, t_dimsf ); diff --git a/Common/processfields.h b/Common/processfields.h index 9e8a404..db6127e 100644 --- a/Common/processfields.h +++ b/Common/processfields.h @@ -32,8 +32,6 @@ public: enum FileType { VTK_FILETYPE, HDF5_FILETYPE}; enum DumpType { E_FIELD_DUMP, H_FIELD_DUMP}; - virtual void InitProcess(); - virtual void DefineStartStopCoord(double* dstart, double* dstop); //! Define a field dump sub sampling rate for a given direction (default: \a dir = -1 means all directions) @@ -71,11 +69,14 @@ public: static bool DumpScalarArray2VTK(ofstream &file, string name, FDTD_FLOAT const* const* const* array, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1); static bool DumpMultiScalarArray2VTK(ofstream &file, string names[], FDTD_FLOAT const* const* const* const* array, unsigned int numFields, double const* const* discLines, unsigned int const* numLines, unsigned int precision=12, string header_info = string(), MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1); + //! Write a mesh information to the given hdf5-group + static bool WriteMesh2HDF5(string filename, string groupName, unsigned int const* numLines, double const* const* discLines, MeshType meshT = CARTESIAN_MESH, double discLines_scaling = 1); + //! Dump a time-domain vector dump to an HDF5 file - static bool DumpVectorArray2HDF5(string filename, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time=0); + static bool DumpVectorArray2HDF5(string filename, string groupName, string name, FDTD_FLOAT const* const* const* const* array, unsigned int const* numLines, float time=0); //! Dump a frequency-domain complex-vector dump to an HDF5 file - static bool DumpVectorArray2HDF5(string filename, string name, std::complex const* const* const* const* array, unsigned int const* numLines, float weight, float frequency); + static bool DumpVectorArray2HDF5(string filename, string groupName, string name, std::complex const* const* const* const* array, unsigned int const* numLines, float weight, float frequency); double CalcTotalEnergy() const; diff --git a/Common/processfields_fd.cpp b/Common/processfields_fd.cpp index 36bb88b..3e48d81 100644 --- a/Common/processfields_fd.cpp +++ b/Common/processfields_fd.cpp @@ -17,6 +17,7 @@ #include "processfields_fd.h" #include "Common/operator_base.h" +#include #include #include #include @@ -48,6 +49,26 @@ void ProcessFieldsFD::InitProcess() //setup the hdf5 file ProcessFields::InitProcess(); + if (m_fileType==HDF5_FILETYPE) + { + //create hdf5 file & necessary groups + m_filename+= ".h5"; + H5::H5File* file = new H5::H5File( m_filename , H5F_ACC_TRUNC ); + H5::Group* group = new H5::Group( file->createGroup( "/FieldData" )); + delete group; + group = new H5::Group( file->createGroup( "/FieldData/FD" )); + delete group; + delete file; + + //write mesh information in main root-group + #ifdef OUTPUT_IN_DRAWINGUNITS + double discScaling = 1; + #else + double discScaling = Op->GetGridDelta(); + #endif + ProcessFields::WriteMesh2HDF5(m_filename,"/",numLines,discLines,m_Mesh_Type, discScaling); + } + //create data structures... for (size_t n = 0; n #include #include #include @@ -30,6 +31,31 @@ ProcessFieldsTD::~ProcessFieldsTD() { } +void ProcessFieldsTD::InitProcess() +{ + ProcessFields::InitProcess(); + + if (m_fileType==HDF5_FILETYPE) + { + //create hdf5 file & necessary groups + m_filename+= ".h5"; + H5::H5File* file = new H5::H5File( m_filename, H5F_ACC_TRUNC ); + H5::Group* group = new H5::Group( file->createGroup( "/FieldData" )); + delete group; + group = new H5::Group( file->createGroup( "/FieldData/TD" )); + delete group; + delete file; + + //write mesh information in main root-group + #ifdef OUTPUT_IN_DRAWINGUNITS + double discScaling = 1; + #else + double discScaling = Op->GetGridDelta(); + #endif + ProcessFields::WriteMesh2HDF5(m_filename,"/",numLines,discLines,m_Mesh_Type, discScaling); + } +} + int ProcessFieldsTD::Process() { if (Enabled==false) return -1; @@ -69,7 +95,7 @@ int ProcessFieldsTD::Process() { stringstream ss; ss << std::setw( pad_length ) << std::setfill( '0' ) << m_Eng_Interface->GetNumberOfTimesteps(); - DumpVectorArray2HDF5(filename.c_str(),string( ss.str() ),field,numLines,m_Eng_Interface->GetTime(m_dualTime)); + DumpVectorArray2HDF5(filename.c_str(), "/FieldData/TD", string( ss.str() ), field, numLines, m_Eng_Interface->GetTime(m_dualTime)); } else cerr << "ProcessFieldsTD::Process: unknown File-Type" << endl; diff --git a/Common/processfields_td.h b/Common/processfields_td.h index e30b748..cd8b17c 100644 --- a/Common/processfields_td.h +++ b/Common/processfields_td.h @@ -26,6 +26,8 @@ public: ProcessFieldsTD(Engine_Interface_Base* eng_if); virtual ~ProcessFieldsTD(); + virtual void InitProcess(); + virtual int Process(); //! Set the length of the filename timestep pad filled with zeros (default is 8)