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
00030 #include "AbstractHdf5Converter.hpp"
00031 #include "HeartConfig.hpp"
00032 #include "Version.hpp"
00033
00034
00035 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00036 AbstractHdf5Converter<ELEMENT_DIM, SPACE_DIM>::AbstractHdf5Converter(std::string inputDirectory,
00037 std::string fileBaseName,
00038 AbstractTetrahedralMesh<ELEMENT_DIM, SPACE_DIM> *pMesh,
00039 std::string subdirectoryName) :
00040 mFileBaseName(fileBaseName),
00041 mpMesh(pMesh)
00042 {
00043
00044 this->mpReader = new Hdf5DataReader(inputDirectory, this->mFileBaseName);
00045
00046 mpOutputFileHandler = new OutputFileHandler(HeartConfig::Instance()->GetOutputDirectory() + "/" + subdirectoryName, false);
00047
00048 std::vector<std::string> variable_names = this->mpReader->GetVariableNames();
00049 mNumVariables = variable_names.size();
00050 if(mNumVariables==0 || mNumVariables>2)
00051 {
00052 delete mpReader;
00053 delete mpOutputFileHandler;
00054 EXCEPTION("Data has zero or more than two variables - doesn't appear to be mono or bidomain");
00055 }
00056
00057
00058 if(mNumVariables==1)
00059 {
00060 if(variable_names[0]!="V")
00061 {
00062 delete mpReader;
00063 delete mpOutputFileHandler;
00064 EXCEPTION("One variable, but it is not called 'V'");
00065 }
00066 }
00067
00068
00069 if(variable_names.size()==2)
00070 {
00071 if(variable_names[0]!="V" || variable_names[1]!="Phi_e")
00072 {
00073 delete mpReader;
00074 delete mpOutputFileHandler;
00075 EXCEPTION("Two variables, but they are not called 'V' and 'Phi_e'");
00076 }
00077 }
00078 if (mpReader->GetNumberOfRows() != mpMesh->GetNumNodes())
00079 {
00080 delete mpReader;
00081 delete mpOutputFileHandler;
00082 EXCEPTION("Mesh and HDF5 file have a different number of nodes");
00083 }
00084
00085
00086 if (PetscTools::AmMaster())
00087 {
00088
00089
00090 out_stream p_file = this->mpOutputFileHandler->OpenOutputFile(this->mFileBaseName + "_times.info");
00091 unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00092 *p_file << "Number of timesteps " << num_timesteps << std::endl;
00093 *p_file << "timestep " << HeartConfig::Instance()->GetPrintingTimeStep() << std::endl;
00094 double first_timestep=this->mpReader->GetUnlimitedDimensionValues().front();
00095 *p_file << "First timestep " << first_timestep << std::endl;
00096 double last_timestep=this->mpReader->GetUnlimitedDimensionValues().back();
00097 *p_file << "Last timestep " << last_timestep << std::endl;
00098 *p_file << ChasteBuildInfo::GetProvenanceString();
00099 p_file->close();
00100
00101 }
00102
00103 HeartConfig::Instance()->Write(false, subdirectoryName);
00104
00105 }
00106 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00107 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>::~AbstractHdf5Converter()
00108 {
00109 delete mpReader;
00110 delete mpOutputFileHandler;
00111 }
00112
00114
00116
00117 template class AbstractHdf5Converter<1,1>;
00118 template class AbstractHdf5Converter<1,2>;
00119 template class AbstractHdf5Converter<2,2>;
00120 template class AbstractHdf5Converter<1,3>;
00121 template class AbstractHdf5Converter<2,3>;
00122 template class AbstractHdf5Converter<3,3>;
00123