36 #include "PottsMeshReader.hpp"
38 template<
unsigned SPACE_DIM>
40 : mFilesBaseName(pathBaseName),
41 mIndexFromZero(false),
46 mNumElementAttributes(0)
52 template<
unsigned SPACE_DIM>
58 template<
unsigned SPACE_DIM>
64 template<
unsigned SPACE_DIM>
67 return mNumElementAttributes;
70 template<
unsigned SPACE_DIM>
80 template<
unsigned SPACE_DIM>
87 template<
unsigned SPACE_DIM>
98 template<
unsigned SPACE_DIM>
101 std::vector<double> node_data;
104 GetNextLineFromStream(mNodesFile, buffer);
106 std::stringstream buffer_stream(buffer);
109 buffer_stream >> index;
111 unsigned offset = mIndexFromZero ? 0 : 1;
112 if (index != mNodesRead + offset)
114 EXCEPTION(
"Data for node " << mNodesRead <<
" missing");
118 for (
unsigned i=0; i<SPACE_DIM+1; i++)
120 buffer_stream >> node_value;
121 node_data.push_back(node_value);
128 template<
unsigned SPACE_DIM>
135 GetNextLineFromStream(mElementsFile, buffer);
137 std::stringstream buffer_stream(buffer);
139 unsigned element_index;
140 buffer_stream >> element_index;
142 unsigned offset = mIndexFromZero ? 0 : 1;
143 if (element_index != mElementsRead + offset)
145 EXCEPTION(
"Data for element " << mElementsRead <<
" missing");
148 unsigned num_nodes_in_element;
149 buffer_stream >> num_nodes_in_element;
153 for (
unsigned i=0; i<num_nodes_in_element; i++)
155 buffer_stream >> node_index;
156 element_data.
NodeIndices.push_back(node_index - offset);
159 if (mNumElementAttributes > 0)
161 assert(mNumElementAttributes==1);
163 unsigned attribute_value;
164 buffer_stream >> attribute_value;
176 template<
unsigned SPACE_DIM>
183 template<
unsigned SPACE_DIM>
187 std::string file_name = mFilesBaseName +
".node";
188 mNodesFile.open(file_name.c_str());
189 if (!mNodesFile.is_open())
191 EXCEPTION(
"Could not open data file: " + file_name);
195 template<
unsigned SPACE_DIM>
199 std::string file_name;
200 file_name = mFilesBaseName +
".cell";
202 mElementsFile.open(file_name.c_str());
203 if (!mElementsFile.is_open())
205 EXCEPTION(
"Could not open data file: " + file_name);
209 template<
unsigned SPACE_DIM>
214 GetNextLineFromStream(mNodesFile, buffer);
215 std::stringstream buffer_stream(buffer);
216 buffer_stream >> mNumNodes >> mNumNodeAttributes;
219 GetNextLineFromStream(mNodesFile, buffer);
220 std::stringstream node_buffer_stream(buffer);
222 unsigned first_index;
223 node_buffer_stream >> first_index;
224 assert(first_index == 0 || first_index == 1);
225 mIndexFromZero = (first_index == 0);
230 GetNextLineFromStream(mNodesFile, buffer);
232 GetNextLineFromStream(mElementsFile, buffer);
233 std::stringstream element_buffer_stream(buffer);
235 element_buffer_stream >> mNumElements >> mNumElementAttributes;
238 template<
unsigned SPACE_DIM>
242 mElementsFile.close();
245 template<
unsigned SPACE_DIM>
252 getline(fileStream, rawLine);
254 if (fileStream.eof())
256 EXCEPTION(
"Cannot get the next line from node or element file due to incomplete data");
260 rawLine = rawLine.substr(0,rawLine.find(
'#', 0));
262 line_is_blank = (rawLine.find_first_not_of(
" \t", 0) == std::string::npos);
264 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