AbstractHdf5Converter.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "AbstractHdf5Converter.hpp"
00030 #include "Version.hpp"
00031
00032 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00033 AbstractHdf5Converter<ELEMENT_DIM, SPACE_DIM>::AbstractHdf5Converter(std::string inputDirectory,
00034 std::string fileBaseName,
00035 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM>* pMesh,
00036 std::string subdirectoryName)
00037 : mFileBaseName(fileBaseName),
00038 mpMesh(pMesh),
00039 mRelativeSubdirectory(subdirectoryName)
00040 {
00041
00042 mpReader = new Hdf5DataReader(inputDirectory, mFileBaseName);
00043
00044
00045 mpOutputFileHandler = new OutputFileHandler(inputDirectory + "/" + mRelativeSubdirectory, false);
00046
00047
00048 std::vector<std::string> variable_names = mpReader->GetVariableNames();
00049 mNumVariables = variable_names.size();
00050
00051 if (mpReader->GetNumberOfRows() != mpMesh->GetNumNodes())
00052 {
00053 delete mpReader;
00054 delete mpOutputFileHandler;
00055 EXCEPTION("Mesh and HDF5 file have a different number of nodes");
00056 }
00057
00058
00059 if (PetscTools::AmMaster())
00060 {
00061
00062 out_stream p_file = mpOutputFileHandler->OpenOutputFile(mFileBaseName + "_times.info");
00063
00064 std::vector<double> time_values = mpReader->GetUnlimitedDimensionValues();
00065 unsigned num_timesteps = time_values.size();
00066 double first_timestep = time_values.front();
00067 double last_timestep = time_values.back();
00068
00069 double timestep = num_timesteps > 1 ? time_values[1] - time_values[0] : DOUBLE_UNSET;
00070
00071 *p_file << "Number of timesteps " << num_timesteps << std::endl;
00072 *p_file << "timestep " << timestep << std::endl;
00073 *p_file << "First timestep " << first_timestep << std::endl;
00074 *p_file << "Last timestep " << last_timestep << std::endl;
00075 *p_file << ChasteBuildInfo::GetProvenanceString();
00076
00077 p_file->close();
00078 }
00079 }
00080
00081 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00082 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>::~AbstractHdf5Converter()
00083 {
00084 delete mpReader;
00085 delete mpOutputFileHandler;
00086 }
00087
00088 template<unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00089 std::string AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>::GetSubdirectory()
00090 {
00091 return mRelativeSubdirectory;
00092 }
00093
00095
00097
00098 template class AbstractHdf5Converter<1,1>;
00099 template class AbstractHdf5Converter<1,2>;
00100 template class AbstractHdf5Converter<2,2>;
00101 template class AbstractHdf5Converter<1,3>;
00102 template class AbstractHdf5Converter<2,3>;
00103 template class AbstractHdf5Converter<3,3>;