42 #include "boost/lexical_cast.hpp"
54 tok_.set_comment_pattern(
"#");
64 tok_.set_comment_pattern(
"#");
81 ASSERT( mesh ,
"Argument mesh is NULL.\n");
90 using namespace boost;
93 if (! tok.skip_to(
"$Nodes"))
xprintf(
UsrErr,
"Missing section '$Nodes' in the GMSH input file: %s\n",tok.f_name().c_str());
96 unsigned int n_nodes = lexical_cast<
unsigned int> (*tok);;
97 INPUT_CHECK( n_nodes > 0,
"Zero number of nodes, %s.\n", tok.position_msg().c_str() );
101 for (
unsigned int i = 0; i < n_nodes; ++i) {
104 unsigned int id = lexical_cast<
unsigned int> (*tok); ++tok;
107 node->point()(0)=lexical_cast<double> (*tok); ++tok;
108 node->point()(1)=lexical_cast<double> (*tok); ++tok;
109 node->point()(2)=lexical_cast<double> (*tok); ++tok;
113 }
catch (bad_lexical_cast &) {
114 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
122 using namespace boost;
125 if (! tok.skip_to(
"$Elements"))
xprintf(
UsrErr,
"Missing section '$Elements' in the GMSH input file: %s\n",tok.f_name().c_str());
127 tok.next_line(
false);
128 unsigned int n_elements = lexical_cast<
unsigned int> (*tok);
129 INPUT_CHECK( n_elements > 0,
"Zero number of elements, %s.\n", tok.position_msg().c_str());
134 for (
unsigned int i = 0; i < n_elements; ++i) {
137 unsigned int id = lexical_cast<
unsigned int>(*tok); ++tok;
145 unsigned int type = lexical_cast<
unsigned int>(*tok); ++tok;
161 xprintf(
UsrErr,
"Element %d is of the unsupported type %d\n",
id, type);
166 unsigned int n_tags = lexical_cast<
unsigned int>(*tok);
167 INPUT_CHECK(n_tags >= 2,
"At least two element tags have to be defined for element with id=%d, %s.\n",
168 id, tok.position_msg().c_str());
172 unsigned int region_id = lexical_cast<
unsigned int>(*tok); ++tok;
173 unsigned int object_id = lexical_cast<
unsigned int>(*tok); ++tok;
175 unsigned int partition_id=0;
176 if (n_tags > 2) { partition_id = lexical_cast<
unsigned int>(*tok); ++tok; }
177 for (
unsigned int ti = 3; ti < n_tags; ti++) ++tok;
183 RegionDB::MapElementIDToRegionID::const_iterator it = el_to_reg_map->find(
id);
184 if (it != el_to_reg_map->end()) region_id = it->second;
192 xprintf(
Warn,
"Bulk elements of zero size(dim=0) are not supported. Mesh file: %s, Element ID: %d.\n", tok.f_name().c_str() ,id);
196 ele->
init(dim, mesh, region_idx);
197 ele->
pid=partition_id;
201 unsigned int node_id = lexical_cast<
unsigned int>(*tok);
204 "Unknown node id %d in specification of element with id=%d, %s.\n",
205 node_id, id, tok.position_msg().c_str());
206 ele->
node[ni] = node;
211 }
catch (bad_lexical_cast &) {
212 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
222 using namespace boost;
224 if (! tok.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
226 tok.next_line(
false);
227 unsigned int n_physicals = lexical_cast<
unsigned int> (*tok);
230 for (
unsigned int i = 0; i < n_physicals; ++i) {
235 unsigned int dim = lexical_cast<
unsigned int>(*tok); ++tok;
236 unsigned int id = lexical_cast<
unsigned int>(*tok); ++tok;
237 string name = *tok; ++tok;
239 bool boundary = ( name.size() != 0 && name[0] ==
'.' );
243 }
catch (bad_lexical_cast &) {
244 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
252 using namespace boost;
255 tok.next_line(
false);
256 unsigned int n_str = lexical_cast<
unsigned int>(*tok); ++tok;
260 tok.next_line(); n_str--;
264 tok.next_line(); n_str--;
267 for(;n_str>0;n_str--) tok.next_line(
false);
271 unsigned int n_real = lexical_cast<
unsigned int>(*tok); ++tok;
274 tok.next_line(); n_real--;
275 head.
time=lexical_cast<
double>(*tok); ++tok;
277 for(;n_real>0;n_real--) tok.next_line(
false);
281 unsigned int n_int = lexical_cast<
unsigned int>(*tok); ++tok;
287 tok.next_line(); n_int--;
288 head.
time_index=lexical_cast<
unsigned int>(*tok); ++tok;
291 tok.next_line(); n_int--;
292 head.
n_components=lexical_cast<
unsigned int>(*tok); ++tok;
295 tok.next_line(); n_int--;
296 head.
n_entities=lexical_cast<
unsigned int>(*tok); ++tok;
298 for(;n_int>0;n_int--) tok.next_line(
false);
299 }
catch (bad_lexical_cast &) {
300 xprintf(
UsrErr,
"Wrong format of the $ElementData header, %s.\n", tok.position_msg().c_str());
310 using namespace boost;
312 unsigned int id, idx, n_read;
324 id_iter=el_ids.begin();
330 id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
331 while (id_iter != el_ids.end() && *id_iter < (int)
id) {
335 if (id_iter == el_ids.end()) {
336 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nData ID %d not found or is not in order. Skipping rest of data.\n",
341 if (*id_iter == (
int)id) {
342 idx = id_iter - el_ids.begin();
344 for (
unsigned int i_col =0; i_col < search_header.
n_components; ++i_col, ++data_ptr) {
345 *(data_ptr) = lexical_cast<double>(*tok_); ++
tok_;
350 }
catch (bad_lexical_cast &) {
351 xprintf(
UsrErr,
"Wrong format of $ElementData line, %s.\n",
tok_.position_msg().c_str());
356 xprintf(
Msg,
"time: %f; %d entities of field %s read.\n",
359 search_header.
actual =
true;
365 if (
tok_.skip_to(
"$ElementData") )
372 xprintf(
UsrErr,
"In file '%s', missing '$ElementData' section for field '%s'.\n",
383 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of components: %d, using %d instead.\n",
388 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of entities: %d, using %d instead.\n",