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 for basic validity
00048     std::vector<std::string> variable_names = this->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     //Write an info file
00059     if (PetscTools::AmMaster())
00060     {
00061         //Note that we don't want the child processes to write info files
00062         out_stream p_file = this->mpOutputFileHandler->OpenOutputFile(this->mFileBaseName + "_times.info");
00063         unsigned num_timesteps = this->mpReader->GetUnlimitedDimensionValues().size();
00064         *p_file << "Number of timesteps " << num_timesteps << std::endl;
00065         *p_file << "timestep " << HeartConfig::Instance()->GetPrintingTimeStep() << std::endl;
00066         double first_timestep=this->mpReader->GetUnlimitedDimensionValues().front();
00067         *p_file << "First timestep " << first_timestep << std::endl;
00068         double last_timestep=this->mpReader->GetUnlimitedDimensionValues().back();
00069         *p_file << "Last timestep " << last_timestep << std::endl;
00070         *p_file << ChasteBuildInfo::GetProvenanceString();
00071         p_file->close();
00072     }
00073     //Write the parameters out
00074     HeartConfig::Instance()->Write(false, subdirectoryName);
00075 
00076 }
00077 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00078 AbstractHdf5Converter<ELEMENT_DIM,SPACE_DIM>::~AbstractHdf5Converter()
00079 {
00080     delete mpReader;
00081     delete mpOutputFileHandler;
00082 }
00083 
00085 // Explicit instantiation
00087 
00088 template class AbstractHdf5Converter<1,1>;
00089 template class AbstractHdf5Converter<1,2>;
00090 template class AbstractHdf5Converter<2,2>;
00091 template class AbstractHdf5Converter<1,3>;
00092 template class AbstractHdf5Converter<2,3>;
00093 template class AbstractHdf5Converter<3,3>;
00094 

Generated on Mon Nov 1 12:35:16 2010 for Chaste by  doxygen 1.5.5