PottsMeshReader.hpp

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 #ifndef POTTSMESHREADER_HPP_
00030 #define POTTSMESHREADER_HPP_
00031 
00032 #include <string>
00033 #include <fstream>
00034 #include <cassert>
00035 #include <vector>
00036 
00037 #include "AbstractMeshReader.hpp"
00038 
00043 struct PottsElementData
00044 {
00045     std::vector<unsigned> NodeIndices; 
00046     std::vector<bool> Orientations; 
00047     unsigned AttributeValue; 
00048     unsigned ContainingElement; 
00049 };
00050 
00054 template<unsigned SPACE_DIM>
00055 class PottsMeshReader : public AbstractMeshReader<SPACE_DIM, SPACE_DIM>
00056 {
00057 private:
00058 
00060     std::string mFilesBaseName;
00061 
00063     std::ifstream mNodesFile;
00064 
00066     std::ifstream mElementsFile;
00067 
00069     bool mIndexFromZero;
00070 
00072     unsigned mNumNodes;
00073 
00075     unsigned mNumElements;
00076 
00078     unsigned mNodesRead;
00079 
00081     unsigned mElementsRead;
00082 
00084     unsigned mNumNodeAttributes;
00085 
00087     unsigned mNumElementAttributes;
00088 
00092     void OpenFiles();
00093 
00097     void OpenNodeFile();
00098 
00102     void OpenElementsFile();
00103 
00107     void ReadHeaders();
00108 
00112     void CloseFiles();
00113 
00120     void GetNextLineFromStream(std::ifstream& fileStream, std::string& rawLine);
00121 
00122 public:
00123 
00129     PottsMeshReader(std::string pathBaseName);
00130 
00134     ~PottsMeshReader()
00135     {}
00136 
00140     unsigned GetNumElements() const;
00141 
00145     unsigned GetNumNodes() const;
00146 
00150     unsigned GetNumElementAttributes() const;
00151 
00155     unsigned GetNumFaces() const;
00156 
00160     ElementData GetNextFaceData();
00161 
00165     void Reset();
00166 
00170     std::vector<double> GetNextNode();
00171 
00175     ElementData GetNextElementData();
00176 };
00177 
00178 #endif /*POTTSMESHREADER_HPP_*/
Generated on Thu Dec 22 13:00:04 2011 for Chaste by  doxygen 1.6.3