AbstractHdf5Converter.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2010
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
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     // store directory, mesh and filenames and create the reader
00044     this->mpReader = new Hdf5DataReader(inputDirectory, this->mFileBaseName);
00045     //Create new directory in which to store everything
00046     mpOutputFileHandler = new OutputFileHandler(HeartConfig::Instance()->GetOutputDirectory() + "/" + subdirectoryName, false);
00047     // check the data file read has one or two variables (ie V; or V and PhiE)
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     // if one variable, it is a monodomain problem
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     // if two variables, it is a bidomain problem
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     //Write an info file
00086     if (PetscTools::AmMaster())
00087     {
00088         //Note that we don't want the child processes to write info files
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     //Write the parameters out
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 // Explicit instantiation
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 

Generated by  doxygen 1.6.2