16 # include "mesh_data.h"
28 MeshData::MeshData(
const MeshData &m) : mesh_file_(m.mesh_file_), n_vert(m.n_vert), n_el(m.n_el), n_bdy(m.n_bdy), n_curv(m.n_curv), n_ref(m.n_ref)
55 mesh_file_ = m.mesh_file_;
90 if (str.find(
'#') != str.npos)
91 str.erase(str.find(
'#'));
94 for (
size_t i = 0; i < str.length(); i++)
97 if (str[i] !=
'\t' && str[i] !=
'[' && str[i] !=
']' && str[i] !=
'{' && str[i] !=
'}')
99 if (str[i] ==
',' || str[i] ==
';')
101 else if (str[i] ==
'=')
104 temp.append(1, str[i]);
112 str.erase(0, str.find_first_not_of(
"\t "));
115 if (str.find_last_of(
"\t ") == (str.size() - 1))
116 str.erase(str.find_last_not_of(
"\t ") + 1);
119 for (
size_t i = 0; i < str.length(); i++)
123 if (str[i + 1] !=
' ' && str[i + 1] !=
'\t' && str[i + 1] !=
'=' && str[i - 1] !=
' ' && str[i - 1] !=
'\t')
127 temp.append(1, str[i]);
137 for (
size_t i = 0; i < str.length(); i++)
144 temp.append(1, str[i]);
157 std::ifstream inFile(mesh_file_.c_str());
161 bool isVert(
false), isElt(
false), isBdy(
false), isCurv(
false), isRef(
false), isVar(
false);
163 while (std::getline(inFile, line))
168 if (line.find_first_not_of(
"\t ") != line.npos)
170 std::istringstream stream(line);
173 if (*word.rbegin() ==
'=')
175 word.erase(word.size() - 1);
177 if (word ==
"vertices")
180 isElt =
false; isBdy =
false; isCurv =
false; isRef =
false; isVar =
false;
183 else if (word ==
"elements")
186 isVert =
false; isBdy =
false; isCurv =
false; isRef =
false; isVar =
false;
189 else if (word ==
"boundaries")
192 isVert =
false; isElt =
false; isCurv =
false; isRef =
false; isVar =
false;
195 else if (word ==
"curves")
198 isVert =
false; isElt =
false; isBdy =
false; isRef =
false; isVar =
false;
201 else if (word ==
"refinements")
204 isVert =
false; isElt =
false; isBdy =
false; isCurv =
false; isVar =
false;
210 isVert =
false; isElt =
false; isBdy =
false; isCurv =
false; isRef =
false;
213 temp_word = restore(word);
223 std::istringstream istr(word);
225 if (!(istr >> dummy_dbl))
228 x_vertex.push_back(atof(word.c_str()));
234 std::istringstream istr(word);
236 if (!(istr >> dummy_int))
237 en1.push_back(atoi(
vars_[restore(word)][0].c_str()));
239 en1.push_back(atoi(word.c_str()));
245 std::istringstream istr(word);
247 if (!(istr >> dummy_dbl))
256 std::istringstream istr(word);
258 if (!(istr >> dummy_int))
267 std::istringstream istr(word);
269 if (!(istr >> dummy_int))
270 ref_elt.push_back(atoi(
vars_[restore(word)][0].c_str()));
272 ref_elt.push_back(atoi(word.c_str()));
278 vars_[temp_word].push_back(restore(word));
285 while (stream >> word)
287 std::istringstream istr(word);
289 if (counter % 2 == 0)
291 if (!(istr >> dummy_dbl))
294 x_vertex.push_back(atof(word.c_str()));
298 if (!(istr >> dummy_dbl))
301 y_vertex.push_back(atof(word.c_str()));
309 while (stream >> word)
311 std::istringstream istr(word);
313 if (counter % 5 == 0)
315 if (!(istr >> dummy_int))
316 en1.push_back(atoi(
vars_[restore(word)][0].c_str()));
318 en1.push_back(atoi(word.c_str()));
320 else if (counter % 5 == 1)
322 if (!(istr >> dummy_int))
323 en2.push_back(atoi(
vars_[restore(word)][0].c_str()));
325 en2.push_back(atoi(word.c_str()));
327 else if (counter % 5 == 2)
329 if (!(istr >> dummy_int))
330 en3.push_back(atoi(
vars_[restore(word)][0].c_str()));
332 en3.push_back(atoi(word.c_str()));
334 else if (counter % 5 == 3)
336 if (!(istr >> dummy_int))
339 e_mtl.push_back(restore(word));
344 en4.push_back(atoi(word.c_str()));
347 e_mtl.push_back(restore(word));
354 while (stream >> word)
356 std::istringstream istr(word);
358 if (counter % 3 == 0)
360 if (!(istr >> dummy_int))
365 else if (counter % 3 == 1)
367 if (!(istr >> dummy_int))
380 while (stream >> word)
382 std::istringstream istr(word);
384 if (counter % 5 == 0)
386 if (!(istr >> dummy_int))
391 else if (counter % 5 == 1)
393 if (!(istr >> dummy_int))
398 else if (counter % 5 == 2)
400 if (istr >> dummy_dbl)
425 else if (counter % 5 == 3)
437 while (stream >> word)
439 std::istringstream istr(word);
441 if (counter % 2 == 0)
443 if (!(istr >> dummy_int))
444 ref_elt.push_back(atoi(
vars_[restore(word)][0].c_str()));
446 ref_elt.push_back(atoi(word.c_str()));
450 if (!(istr >> dummy_int))
453 ref_type.push_back(atoi(word.c_str()));
461 while (stream >> word)
463 vars_[temp_word].push_back(restore(word));
473 assert(
en1.size() ==
en2.size());
474 assert(
en2.size() ==
en3.size());
475 assert(
en3.size() ==
en4.size());
std::vector< std::string > e_mtl
Element markers – single word strings.
void parse_mesh(void)
This function parses a given input mesh file line by line and extracts the necessary information into...
std::vector< int > ref_elt
List of elements to be refined.
int n_ref
Number of elements with specified refinements.
std::map< std::string, std::vector< std::string > > vars_
Map for storing variables in input mesh file.
MeshData & operator=(const MeshData &m)
MeshData Assignment Operator.
std::vector< int > curv_second
Second node of a curved edge.
int n_vert
Number of vertices.
std::vector< bool > curv_nurbs
Nurbs Indicator. True if curve is modeled with NURBS. False if it is a circular arc.
int n_el
Number of elements.
std::vector< std::string > bdy_type
Boundary name.
Class to stored 2d mesh parameters. The MeshData class organizes all the necessary data structures re...
std::vector< int > en4
Nodes with local node number 4. Only for quadrilateral elements. For triangular elements it is set to...
int n_curv
Number of curved edges (including NURBS curves)
std::vector< int > en3
Nodes with local node number 3.
std::vector< int > en2
Nodes with local node number 2.
std::vector< int > ref_type
List of element refinement type.
MeshData(const std::string &mesh_file)
MeshData Constructor.
int n_bdy
Number of boundary edges.
std::vector< std::string > curv_inner_pts
Name of the list of the control points and weights of a NURBS curve. Set to "none" for a circular arc...
std::vector< std::string > curv_knots
Name of the list of knot vectors of a NURBS curve. Set to "none" for a circular arc.
std::vector< int > bdy_first
First node of a boundary edge.
std::vector< int > en1
Nodes with local node number 1.
std::vector< double > y_vertex
y-coordinate of the vertices
std::vector< double > x_vertex
x-coordinate of the vertices
::xsd::cxx::tree::string< char, simple_type > string
C++ type corresponding to the string XML Schema built-in type.
std::vector< int > bdy_second
Second node of a boundary edge.
~MeshData()
MeshData Destructor.
std::vector< int > curv_first
First node of a curved edge.
std::vector< double > curv_third
Third entry of a curve specification. Angle for a circular arc and degree for a NURBS curve...