16 logInfo(
"readHDF5File()",
"Entering filereader..." );
18 const H5std_string FILE_NAME ( filename.c_str() );
21 const H5std_string GROUP_NAME (
"/PartType0" );
27 const H5std_string DATASET_NAME1(
"/Coordinates" );
28 const H5std_string DATASET_NAME2(
"/Velocities" );
29 const H5std_string DATASET_NAME3(
"/Masses" );
30 const H5std_string DATASET_NAME4(
"/SmoothingLength" );
31 const H5std_string DATASET_NAME5(
"/InternalEnergy" );
32 const H5std_string DATASET_NAME6(
"/ParticleIDs" );
37 H5::H5File file( FILE_NAME, H5F_ACC_RDONLY );
38 logInfo(
"readHDF5File()",
"File: " << FILE_NAME <<
" opened." ) ;
47 _Coordinates = toolbox::particles::FileReaderHDF5::readDoubleArray( file, GROUP_NAME, DATASET_NAME1 );
50 _Velocity = toolbox::particles::FileReaderHDF5::readFloatArray( file, GROUP_NAME, DATASET_NAME2 );
53 _Mass = toolbox::particles::FileReaderHDF5::readDoubleScalar( file, GROUP_NAME, DATASET_NAME3 );
56 _SmoothingLength = toolbox::particles::FileReaderHDF5::readDoubleScalar( file, GROUP_NAME, DATASET_NAME4 );
59 _InternalEnergy = toolbox::particles::FileReaderHDF5::readDoubleScalar( file, GROUP_NAME, DATASET_NAME5 );
66 _ParticleIDs = toolbox::particles::FileReaderHDF5::readIntScalar( file, GROUP_NAME, DATASET_NAME6 );
68 logInfo(
"readHDF5File()",
"Reading file: " << FILE_NAME <<
" complete." ) ;
71 logError(
"readHDF5File()",
"tried to use Peano's HDF5 reader though code has been compiled without --with-hdf5 (autotools)" );
78std::vector< int > toolbox::particles::FileReaderHDF5::readIntScalar(
79 const H5::H5File& file,
80 const H5std_string& groupName,
81 const H5std_string& datasetName
84 std::vector< int > result;
89 H5::Group group = file.openGroup ( groupName );
90 logInfo(
"readIntScalar()",
"Group: " << groupName <<
" opened." ) ;
95 H5::DataSet dataset = file.openDataSet( groupName + datasetName );
96 logInfo(
"readIntScalar()",
"Dataset: " << groupName + datasetName <<
" opened." ) ;
101 H5::DataSpace dataspace = dataset.getSpace();
106 int rank = dataspace.getSimpleExtentNdims();
113 int ndims = dataspace.getSimpleExtentDims( dims_out, NULL );
116 "Dataspace dimensions: rank " << rank <<
118 (
unsigned long)(dims_out[0]) )
123 const int LengthInputDataX = dims_out[0];
126 const int LengthDataBufferX = LengthInputDataX;
127 const int RankDataBuffer = rank;
130 int DataBuffer[LengthDataBufferX];
131 for (i = 0; i < LengthDataBufferX; i++)
136 dataspace.selectAll();
137 H5::DataSpace memspace( 1 , dims_out );
140 dataset.read( DataBuffer, H5::PredType::NATIVE_INT, memspace, dataspace );
144 for (i = 0; i < LengthDataBufferX; i++)
146 result.push_back( DataBuffer[i] );
147 logDebug(
"readIntScalar()",
"entry value: " << DataBuffer[i] );
150 logInfo(
"readIntScalar()",
"read " << result.size() <<
" entries. " );
156std::vector< double > toolbox::particles::FileReaderHDF5::readDoubleScalar(
157 const H5::H5File& file,
158 const H5std_string& groupName,
159 const H5std_string& datasetName
162 std::vector< double > result;
167 H5::Group group =
file.openGroup ( groupName );
168 logInfo(
"readDoubleScalar()",
"Group: " << groupName <<
" opened." ) ;
173 H5::DataSet dataset =
file.openDataSet( groupName + datasetName );
174 logInfo(
"readDoubleScalar()",
"Dataset: " << groupName + datasetName <<
" opened." ) ;
179 H5::DataSpace dataspace = dataset.getSpace();
184 int rank = dataspace.getSimpleExtentNdims();
190 int ndims = dataspace.getSimpleExtentDims( dims_out, NULL );
193 "Dataspace dimensions: rank " << rank <<
195 (
unsigned long)(dims_out[0]) )
201 const int LengthInputDataX = dims_out[0];
202 const int RankDataBuffer = rank;
205 const int LengthDataBufferX = LengthInputDataX;
208 float DataBuffer[LengthDataBufferX];
209 for (i = 0;
i < LengthDataBufferX;
i++)
214 dataspace.selectAll();
217 H5::DataSpace memspace( RankDataBuffer , dims_out );
220 dataset.read( DataBuffer, H5::PredType::NATIVE_FLOAT, memspace, dataspace );
224 for (i = 0;
i < LengthDataBufferX;
i++)
226 result.push_back( DataBuffer[i] );
227 logDebug(
"readDoubleScalar()",
"entry value: " << DataBuffer[i] );
230 logInfo(
"readDoubleScalar()",
"read " << result.size() <<
" entries. " );
237std::list< tarch::la::Vector<Dimensions,double> > toolbox::particles::FileReaderHDF5::readDoubleArray(
238 const H5::H5File& file,
239 const H5std_string& groupName,
240 const H5std_string& datasetName
243 std::list< tarch::la::Vector<Dimensions,double> > result;
248 H5::Group group =
file.openGroup ( groupName );
249 logInfo(
"readHDF5File()",
"Group: " << groupName <<
" opened." ) ;
254 H5::DataSet dataset =
file.openDataSet( groupName+datasetName );
255 logInfo(
"readHDF5File()",
"Dataset: " << groupName + datasetName <<
" opened." ) ;
260 H5::DataSpace dataspace = dataset.getSpace();
265 int rank = dataspace.getSimpleExtentNdims();
271 int ndims = dataspace.getSimpleExtentDims( dims_out, NULL );
274 "Dataspace dimensions: rank " << rank <<
276 (
unsigned long)(dims_out[0]) <<
" x " <<
277 (
unsigned long)(dims_out[1]) ) ;
283 const int LengthInputDataX = dims_out[0];
284 const int LengthInputDataY = dims_out[1];
285 const int RankDataBuffer = rank;
288 const int LengthDataBufferX = LengthInputDataX;
289 const int LengthDataBufferY = LengthInputDataY;
295 double dataBuffer[LengthDataBufferX][LengthDataBufferY];
296 for (i = 0;
i < LengthDataBufferX;
i++)
298 for (j = 0;
j < LengthDataBufferY;
j++)
300 dataBuffer[
i][
j] = 0;
312 count[0] = LengthInputDataX;
313 count[1] = LengthInputDataY;
315 dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
321 dimsm[0] = LengthDataBufferX;
322 dimsm[1] = LengthDataBufferY;
324 H5::DataSpace memspace( RankDataBuffer, dimsm );
329 hsize_t offset_out[2];
330 hsize_t count_out[2];
333 count_out[0] = LengthInputDataX;
334 count_out[1] = LengthInputDataY;
336 memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );
339 H5::DataType Datatype;
340 Datatype = H5::PredType::NATIVE_DOUBLE;
342 dataset.read( dataBuffer, Datatype, memspace, dataspace );
354 for (i = 0;
i < LengthDataBufferX;
i++)
356 for (j = 0;
j < Dimensions;
j++)
358 tmpDataArray[
j] = dataBuffer[
i][
j];
361 result.push_back( tmpDataArray );
363 logDebug(
"readDoubleArray()",
"tmpDataArray " << tmpDataArray <<
", i = " << i );
366 logInfo(
"readHDF5File()",
"read " << result.size() <<
" entries. " );
372std::vector< tarch::la::Vector<Dimensions,double> > toolbox::particles::FileReaderHDF5::readFloatArray(
373 const H5::H5File& file,
374 const H5std_string& groupName,
375 const H5std_string& datasetName
378 std::vector< tarch::la::Vector<Dimensions,double> > result;
383 H5::Group group =
file.openGroup ( groupName );
384 logInfo(
"readHDF5File()",
"Group: " << groupName <<
" opened." ) ;
389 H5::DataSet dataset =
file.openDataSet( groupName+datasetName );
390 logInfo(
"readHDF5File()",
"Dataset: " << groupName + datasetName <<
" opened." ) ;
395 H5::DataSpace dataspace = dataset.getSpace();
400 int rank = dataspace.getSimpleExtentNdims();
406 int ndims = dataspace.getSimpleExtentDims( dims_out, NULL );
409 "Dataspace dimensions: rank " << rank <<
411 (
unsigned long)(dims_out[0]) <<
" x " <<
412 (
unsigned long)(dims_out[1]) ) ;
418 const int LengthInputDataX = dims_out[0];
419 const int LengthInputDataY = dims_out[1];
420 const int RankDataBuffer = rank;
423 const int LengthDataBufferX = LengthInputDataX;
424 const int LengthDataBufferY = LengthInputDataY;
430 double dataBuffer[LengthDataBufferX][LengthDataBufferY];
431 for (i = 0;
i < LengthDataBufferX;
i++)
433 for (j = 0;
j < LengthDataBufferY;
j++)
435 dataBuffer[
i][
j] = 0;
447 count[0] = LengthInputDataX;
448 count[1] = LengthInputDataY;
450 dataspace.selectHyperslab( H5S_SELECT_SET, count, offset );
456 dimsm[0] = LengthDataBufferX;
457 dimsm[1] = LengthDataBufferY;
459 H5::DataSpace memspace( RankDataBuffer, dimsm );
464 hsize_t offset_out[2];
465 hsize_t count_out[2];
468 count_out[0] = LengthInputDataX;
469 count_out[1] = LengthInputDataY;
471 memspace.selectHyperslab( H5S_SELECT_SET, count_out, offset_out );
474 H5::DataType Datatype = H5::PredType::NATIVE_FLOAT;
476 dataset.read( dataBuffer, Datatype, memspace, dataspace );
488 for (i = 0;
i < LengthDataBufferX;
i++)
490 for (j = 0;
j < Dimensions;
j++)
492 tmpDataArray[
j] = dataBuffer[
i][
j];
495 result.push_back( tmpDataArray );
497 logDebug(
"readFloatArray()",
"tmpDataArray " << tmpDataArray <<
", i = " << i );
500 logInfo(
"readHDF5File()",
"read " << result.size() <<
" entries. " );
508 _VelocityWithinVoxel.clear();
509 _MassWithinVoxel.clear();
510 _SmoothingLengthWithinVoxel.clear();
511 _InternalEnergyWithinVoxel.clear();
512 _ParticleIDsWithinVoxel.clear();
516 return (_VelocityWithinVoxel.empty() &&
517 _MassWithinVoxel.empty() &&
518 _SmoothingLengthWithinVoxel.empty() &&
519 _InternalEnergyWithinVoxel.empty() &&
520 _ParticleIDsWithinVoxel.empty());
528 std::list< tarch::la::Vector<Dimensions,double> > result;
530 std::list< tarch::la::Vector<Dimensions,double> >::iterator p = _Coordinates.begin();
531 std::list<int>::iterator pind = _ParticleIndex.begin();
534 if (!isVoxelEmpty()) clearVoxel();
539 while ( p!=_Coordinates.end() ) {
541 bool overlaps =
true;
543 for (
int d=0; d<Dimensions; d++) {
550 result.push_back(*p);
553 _VelocityWithinVoxel.push_back ( _Velocity [*pind] );
554 _MassWithinVoxel.push_back ( _Mass [*pind] );
555 _SmoothingLengthWithinVoxel.push_back( _SmoothingLength[*pind] );
556 _InternalEnergyWithinVoxel.push_back ( _InternalEnergy [*pind] );
557 _ParticleIDsWithinVoxel.push_back ( _ParticleIDs [*pind] );
560 p = _Coordinates.erase(p);
561 pind = _ParticleIndex.erase(pind);
579 _Coordinates.clear();
581 _SmoothingLength.clear();
582 _InternalEnergy.clear();
583 _ParticleIDs.clear();
584 _ParticleIndex.clear();
589 return _Coordinates.empty();
594 return _Coordinates.size();
599 return _VelocityWithinVoxel;
604 return _MassWithinVoxel;
609 return _SmoothingLengthWithinVoxel;
614 return _InternalEnergyWithinVoxel;
619 return _ParticleIDsWithinVoxel;
#define logError(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
#define logDebug(methodName, logMacroMessageStream)
#define logInfo(methodName, logMacroMessageStream)
Wrapper macro around tarch::tarch::logging::Log to improve logging.
std::vector< double > _InternalEnergy
std::vector< double > getMassWithinVoxel() const
bool isVoxelEmpty() const
Check whether voxel data carried by this instance of FileReaderHDF5 is empty.
void readHDF5File(const std::string &filename)
Read HDF5 file in SWIFT format.
std::vector< double > getSmoothingLengthWithinVoxel() const
std::vector< double > _SmoothingLength
std::vector< double > getInternalEnergyWithinVoxel() const
std::vector< double > _Mass
void clearVoxel()
Clear data of a voxel carried by this instance of FileReaderHDF5.
std::list< tarch::la::Vector< Dimensions, double > > getParticlesWithinVoxel(const tarch::la::Vector< Dimensions, double > &x, const tarch::la::Vector< Dimensions, double > &h, bool remove)
Take particles from database which fall into given voxel.
std::vector< tarch::la::Vector< Dimensions, double > > getVelocityWithinVoxel() const
std::list< tarch::la::Vector< Dimensions, double > > _Coordinates
std::list< int > _ParticleIndex
bool getNumberOfCoordinates() const
static tarch::logging::Log _log
std::vector< int > getParticleIDsWithinVoxel() const
std::vector< tarch::la::Vector< Dimensions, double > > _Velocity
std::vector< int > _ParticleIDs
bool greaterEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)
bool smallerEquals(double lhs, double rhs, double tolerance=NUMERICAL_ZERO_DIFFERENCE)