36 #include "PottsMeshReader.hpp"
41 template<
unsigned SPACE_DIM>
43 : mFilesBaseName(pathBaseName),
44 mIndexFromZero(false),
49 mNumElementAttributes(0)
55 template<
unsigned SPACE_DIM>
61 template<
unsigned SPACE_DIM>
67 template<
unsigned SPACE_DIM>
70 return mNumElementAttributes;
73 template<
unsigned SPACE_DIM>
83 template<
unsigned SPACE_DIM>
90 template<
unsigned SPACE_DIM>
101 template<
unsigned SPACE_DIM>
104 std::vector<double> node_data;
107 GetNextLineFromStream(mNodesFile, buffer);
109 std::stringstream buffer_stream(buffer);
112 buffer_stream >> index;
114 unsigned offset = mIndexFromZero ? 0 : 1;
115 if (index != mNodesRead + offset)
117 EXCEPTION(
"Data for node " << mNodesRead <<
" missing");
121 for (
unsigned i=0; i<SPACE_DIM+1; i++)
123 buffer_stream >> node_value;
124 node_data.push_back(node_value);
131 template<
unsigned SPACE_DIM>
138 GetNextLineFromStream(mElementsFile, buffer);
140 std::stringstream buffer_stream(buffer);
142 unsigned element_index;
143 buffer_stream >> element_index;
145 unsigned offset = mIndexFromZero ? 0 : 1;
146 if (element_index != mElementsRead + offset)
148 EXCEPTION(
"Data for element " << mElementsRead <<
" missing");
151 unsigned num_nodes_in_element;
152 buffer_stream >> num_nodes_in_element;
156 for (
unsigned i=0; i<num_nodes_in_element; i++)
158 buffer_stream >> node_index;
159 element_data.
NodeIndices.push_back(node_index - offset);
162 if (mNumElementAttributes > 0)
164 assert(mNumElementAttributes==1);
166 unsigned attribute_value;
167 buffer_stream >> attribute_value;
179 template<
unsigned SPACE_DIM>
186 template<
unsigned SPACE_DIM>
190 std::string file_name = mFilesBaseName +
".node";
191 mNodesFile.open(file_name.c_str());
192 if (!mNodesFile.is_open())
194 EXCEPTION(
"Could not open data file: " + file_name);
198 template<
unsigned SPACE_DIM>
202 std::string file_name;
203 file_name = mFilesBaseName +
".cell";
205 mElementsFile.open(file_name.c_str());
206 if (!mElementsFile.is_open())
208 EXCEPTION(
"Could not open data file: " + file_name);
212 template<
unsigned SPACE_DIM>
217 GetNextLineFromStream(mNodesFile, buffer);
218 std::stringstream buffer_stream(buffer);
219 buffer_stream >> mNumNodes >> mNumNodeAttributes;
222 GetNextLineFromStream(mNodesFile, buffer);
223 std::stringstream node_buffer_stream(buffer);
225 unsigned first_index;
226 node_buffer_stream >> first_index;
227 assert(first_index == 0 || first_index == 1);
228 mIndexFromZero = (first_index == 0);
233 GetNextLineFromStream(mNodesFile, buffer);
235 GetNextLineFromStream(mElementsFile, buffer);
236 std::stringstream element_buffer_stream(buffer);
238 element_buffer_stream >> mNumElements >> mNumElementAttributes;
241 template<
unsigned SPACE_DIM>
245 mElementsFile.close();
248 template<
unsigned SPACE_DIM>
255 getline(fileStream, rawLine);
257 if (fileStream.eof())
259 EXCEPTION(
"Cannot get the next line from node or element file due to incomplete data");
263 rawLine = rawLine.substr(0,rawLine.find(
'#', 0));
265 line_is_blank = (rawLine.find_first_not_of(
" \t", 0) == std::string::npos);
267 while (line_is_blank);
std::vector< double > GetNextNode()
#define EXCEPTION(message)
unsigned GetNumNodes() const
unsigned GetNumElementAttributes() const
void GetNextLineFromStream(std::ifstream &fileStream, std::string &rawLine)
std::vector< unsigned > NodeIndices
PottsMeshReader(std::string pathBaseName)
ElementData GetNextElementData()
unsigned GetNumFaces() const
ElementData GetNextFaceData()
unsigned GetNumElements() const