29 #include "boost/lexical_cast.hpp"
41 tok_.set_comment_pattern(
"#");
55 using namespace boost;
58 tok_.set_position( Tokenizer::Position() );
60 if (!
tok_.skip_to(
"$Nodes"))
THROW(ExcMissingSection() << EI_Section(
"$Nodes") << EI_GMSHFile(
tok_.f_name()) );
62 tok_.next_line(
false);
63 n_nodes = lexical_cast<unsigned int> (*
tok_);
65 if (n_nodes == 0)
THROW( ExcZeroNodes() << EI_Position(
tok_.position_msg()) );
68 for (
unsigned int i = 0; i < n_nodes; ++i) {
71 unsigned int id = lexical_cast<unsigned int> (*
tok_); ++
tok_;
73 coords(0) = lexical_cast<double> (*
tok_); ++
tok_;
74 coords(1) = lexical_cast<double> (*
tok_); ++
tok_;
75 coords(2) = lexical_cast<double> (*
tok_); ++
tok_;
81 }
catch (bad_lexical_cast &) {
82 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
84 MessageOut().fmt(
"... {} nodes read. \n", n_nodes);
89 using namespace boost;
92 if (!
tok_.skip_to(
"$Elements"))
THROW(ExcMissingSection() << EI_Section(
"$Elements") << EI_GMSHFile(
tok_.f_name()) );
94 tok_.next_line(
false);
95 unsigned int n_elements = lexical_cast<unsigned int> (*
tok_);
96 if (n_elements == 0)
THROW( ExcZeroElements() << EI_Position(
tok_.position_msg()) );
104 for (
unsigned int i = 0; i < n_elements; ++i) {
106 unsigned int id = lexical_cast<unsigned int>(*
tok_); ++
tok_;
113 unsigned int type = lexical_cast<unsigned int>(*
tok_); ++
tok_;
130 THROW(ExcUnsupportedType() << EI_ElementId(
id) << EI_ElementType(type) << EI_GMSHFile(
tok_.f_name()) );
135 unsigned int n_tags = lexical_cast<unsigned int>(*
tok_);
136 if (n_tags < 2)
THROW( ExcTooManyElementTags() << EI_ElementId(
id) << EI_Position(
tok_.position_msg()) );
140 unsigned int region_id = lexical_cast<unsigned int>(*
tok_); ++
tok_;
141 lexical_cast<unsigned int>(*
tok_); ++
tok_;
143 unsigned int partition_id = 0;
144 if (n_tags > 2) { partition_id = lexical_cast<unsigned int>(*
tok_); ++
tok_; }
145 for (
unsigned int ti = 3; ti < n_tags; ti++) ++
tok_;
147 for (
unsigned int ni=0; ni<dim+1; ++ni) {
148 node_ids[ni] = lexical_cast<unsigned int>(*
tok_);
151 mesh->
add_element(
id, dim, region_id, partition_id, node_ids);
154 }
catch (bad_lexical_cast &) {
155 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
159 MessageOut().fmt(
"... {} bulk elements, {} boundary elements. \n", mesh->
n_elements(), n_read_boundary);
165 ASSERT(mesh).error(
"Argument mesh is NULL.\n");
167 using namespace boost;
169 if (!
tok_.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
171 tok_.next_line(
false);
172 unsigned int n_physicals = lexical_cast<unsigned int> (*
tok_);
175 for (
unsigned int i = 0; i < n_physicals; ++i) {
180 unsigned int dim = lexical_cast<unsigned int>(*
tok_); ++
tok_;
181 unsigned int id = lexical_cast<unsigned int>(*
tok_); ++
tok_;
186 }
catch (bad_lexical_cast &) {
187 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
196 using namespace boost;
199 tok_.next_line(
false);
200 unsigned int n_str = lexical_cast<unsigned int>(*
tok_); ++
tok_;
204 tok_.next_line(); n_str--;
208 tok_.next_line(); n_str--;
211 for(;n_str>0;n_str--)
tok_.next_line(
false);
215 unsigned int n_real = lexical_cast<unsigned int>(*
tok_); ++
tok_;
218 tok_.next_line(); n_real--;
221 for(;n_real>0;n_real--)
tok_.next_line(
false);
225 unsigned int n_int = lexical_cast<unsigned int>(*
tok_); ++
tok_;
231 tok_.next_line(); n_int--;
235 tok_.next_line(); n_int--;
239 tok_.next_line(); n_int--;
242 for(;n_int>0;n_int--)
tok_.next_line(
false);
245 }
catch (bad_lexical_cast &) {
246 THROW(ExcWrongFormat() << EI_Type(
"$ElementData header") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
253 bool boundary_domain) {
254 unsigned int id, i_row;
255 unsigned int n_read = 0;
264 for (i_row = 0; i_row < actual_header.
n_entities; ++i_row)
267 id = boost::lexical_cast<unsigned int>(*
tok_); ++
tok_;
269 while (id_iter != el_ids.end() && *id_iter < (
int)
id) {
272 if (id_iter == el_ids.end()) {
273 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nData ID {} not found or is not in order. Skipping rest of data.\n",
278 if (*id_iter == (
int)
id) {
283 }
catch (boost::bad_lexical_cast &) {
284 THROW(ExcWrongFormat() << EI_Type(
"$ElementData line") << EI_TokenizerMsg(
tok_.position_msg())
285 << EI_MeshFile(
tok_.f_name()) );
288 while (i_row < actual_header.
n_entities)
tok_.next_line(
false), ++i_row;
290 LogOut().fmt(
"time: {}; {} entities of field {} read.\n",
300 while ( !
tok_.eof() ) {
301 if (
tok_.skip_to(
"$ElementData") ) {
307 vec.push_back(header);
309 }
else if ( header.
time <=
it->second.back().time ) {
310 WarningOut().fmt(
"Wrong time order: field '{}', time '{}', file '{}'. Skipping this '$ElementData' section.\n",
313 it->second.push_back(header);
318 tok_.set_position( Tokenizer::Position() );
326 if (header_query.
discretization != OutputTime::DiscreteSpace::ELEM_DATA) {
327 if (header_query.
discretization != OutputTime::DiscreteSpace::UNDEFINED && header_query.
discretization != OutputTime::DiscreteSpace::NATIVE_DATA) {
329 "Unsupported discretization for field '{}', time: {} and GMSH format.\nType 'ELEM_DATA' of discretization will be used.\n",
332 header_query.
discretization = OutputTime::DiscreteSpace::ELEM_DATA;
339 THROW( ExcFieldNameNotFound() << EI_FieldName(header_query.
field_name) << EI_MeshFile(
tok_.f_name()));
343 return t * (1.0 + 2.0*numeric_limits<double>::epsilon()) < a.time;
347 table_it->second.end(),
351 if (headers_it == table_it->second.begin()) {
353 << EI_MeshFile(
tok_.f_name()) << EI_Time(header_query.
time));