AbstractHdf5Converter.cpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
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 #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     // Store directory, mesh and filenames and create the reader
00042     mpReader = new Hdf5DataReader(inputDirectory, mFileBaseName);
00043 
00044     // Create new directory in which to store everything
00045     mpOutputFileHandler = new OutputFileHandler(inputDirectory + "/" + mRelativeSubdirectory, false);
00046 
00047     // Check the data file for basic validity
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     // 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 = 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 // Explicit instantiation
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>;
Generated on Thu Dec 22 13:00:17 2011 for Chaste by  doxygen 1.6.3