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 #ifndef _GENERICMESHREADER_HPP_
00030 #define _GENERICMESHREADER_HPP_
00031
00032 #include "AbstractMeshReader.hpp"
00033
00034 #include "TrianglesMeshReader.hpp"
00035 #include "MemfemMeshReader.hpp"
00036 #include "VtkMeshReader.hpp"
00037
00050 template <unsigned ELEMENT_DIM, unsigned SPACE_DIM>
00051 class GenericMeshReader : public AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>
00052 {
00053 private:
00057 AbstractMeshReader<ELEMENT_DIM, SPACE_DIM>* mpMeshReader;
00058 public:
00071 GenericMeshReader(std::string pathBaseName,
00072 unsigned orderOfElements=1,
00073 unsigned orderOfBoundaryElements=1,
00074 bool readContainingElementsForBoundaryElements=false)
00075 {
00076 try
00077 {
00078 mpMeshReader = new TrianglesMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName,
00079 orderOfElements,
00080 orderOfBoundaryElements,
00081 readContainingElementsForBoundaryElements);
00082 }
00083 catch (const Exception& r_triangles_exception)
00084 {
00085 if (orderOfElements!=1 || orderOfBoundaryElements!=1 || readContainingElementsForBoundaryElements)
00086 {
00087 EXCEPTION("Quadratic meshes are only supported in Triangles format.");
00088 }
00089
00090 try
00091 {
00092 mpMeshReader = new MemfemMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00093 }
00094 catch (const Exception& r_memfem_exception)
00095 {
00096 #ifdef CHASTE_VTK
00097 try
00098 {
00099 mpMeshReader = new VtkMeshReader<ELEMENT_DIM, SPACE_DIM>(pathBaseName);
00100 }
00101 catch (const Exception& r_vtk_exception)
00102 {
00103 #endif // CHASTE_VTK
00104 std::string eol("\n");
00105 std::string combined_message = "Could not open appropriate mesh files for " + pathBaseName + eol;
00106 combined_message += "Triangle format: " + r_triangles_exception.GetShortMessage() + eol;
00107 combined_message += "Memfem format: " + r_memfem_exception.GetShortMessage() + eol;
00108 #ifdef CHASTE_VTK
00109 combined_message += "Vtk format: " + r_vtk_exception.GetShortMessage() + eol;
00110 #endif // CHASTE_VTK
00111 EXCEPTION(combined_message);
00112 #ifdef CHASTE_VTK
00113 }
00114 #endif // CHASTE_VTK
00115 }
00116 }
00117
00118 }
00119
00120
00124 ~GenericMeshReader()
00125 {
00126 delete mpMeshReader;
00127 }
00128
00129
00133 unsigned GetNumNodes() const
00134 {
00135 return mpMeshReader->GetNumNodes();
00136 }
00137
00141 unsigned GetNumElements() const
00142 {
00143 return mpMeshReader->GetNumElements();
00144 }
00145
00149 unsigned GetNumFaces() const
00150 {
00151 return mpMeshReader->GetNumFaces();
00152 }
00156 unsigned GetNumElementAttributes() const
00157 {
00158 return mpMeshReader->GetNumElementAttributes();
00159 }
00160
00164 unsigned GetNumFaceAttributes() const
00165 {
00166 return mpMeshReader->GetNumFaceAttributes();
00167 }
00168
00172 void Reset()
00173 {
00174 mpMeshReader->Reset();
00175 }
00176
00180 std::vector<double> GetNextNode()
00181 {
00182 return mpMeshReader->GetNextNode();
00183 }
00184
00188 ElementData GetNextElementData()
00189 {
00190 return mpMeshReader->GetNextElementData();
00191 }
00195 ElementData GetNextFaceData()
00196 {
00197 return mpMeshReader->GetNextFaceData();
00198 }
00199
00206 std::vector<double> GetNode(unsigned index)
00207 {
00208 return mpMeshReader->GetNode(index);
00209 }
00210
00211
00218 ElementData GetElementData(unsigned index)
00219 {
00220 return mpMeshReader->GetElementData(index);
00221 }
00222
00223
00230 ElementData GetFaceData(unsigned index)
00231 {
00232 return mpMeshReader->GetFaceData(index);
00233 }
00234
00235
00243 std::vector<unsigned> GetContainingElementIndices(unsigned index)
00244 {
00245 return mpMeshReader->GetContainingElementIndices(index);
00246 }
00247
00252 std::string GetMeshFileBaseName()
00253 {
00254 return mpMeshReader->GetMeshFileBaseName();
00255 }
00256
00260 bool IsFileFormatBinary()
00261 {
00262 return mpMeshReader->IsFileFormatBinary();
00263 }
00264
00268 bool HasNclFile()
00269 {
00270 return mpMeshReader->HasNclFile();
00271 }
00272
00273
00274 };
00275
00276 #endif //_GENERICMESHREADER_HPP_