42 #include "boost/lexical_cast.hpp"
54 tok_.set_comment_pattern(
"#");
64 tok_.set_comment_pattern(
"#");
79 ASSERT( mesh ,
"Argument mesh is NULL.\n");
88 using namespace boost;
91 if (! tok.skip_to(
"$Nodes"))
xprintf(
UsrErr,
"Missing section '$Nodes' in the GMSH input file: %s\n",tok.f_name().c_str());
94 unsigned int n_nodes = lexical_cast<
unsigned int> (*tok);;
95 INPUT_CHECK( n_nodes > 0,
"Zero number of nodes, %s.\n", tok.position_msg().c_str() );
99 for (
unsigned int i = 0; i < n_nodes; ++i) {
102 unsigned int id = lexical_cast<
unsigned int> (*tok); ++tok;
105 node->point()(0)=lexical_cast<double> (*tok); ++tok;
106 node->point()(1)=lexical_cast<double> (*tok); ++tok;
107 node->point()(2)=lexical_cast<double> (*tok); ++tok;
111 }
catch (bad_lexical_cast &) {
112 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
120 using namespace boost;
123 if (! tok.skip_to(
"$Elements"))
xprintf(
UsrErr,
"Missing section '$Elements' in the GMSH input file: %s\n",tok.f_name().c_str());
125 tok.next_line(
false);
126 unsigned int n_elements = lexical_cast<
unsigned int> (*tok);
127 INPUT_CHECK( n_elements > 0,
"Zero number of elements, %s.\n", tok.position_msg().c_str());
132 for (
unsigned int i = 0; i < n_elements; ++i) {
135 unsigned int id = lexical_cast<
unsigned int>(*tok); ++tok;
143 unsigned int type = lexical_cast<
unsigned int>(*tok); ++tok;
160 xprintf(
UsrErr,
"Element %d is of the unsupported type %d\n",
id, type);
165 unsigned int n_tags = lexical_cast<
unsigned int>(*tok);
166 INPUT_CHECK(n_tags >= 2,
"At least two element tags have to be defined for element with id=%d, %s.\n",
167 id, tok.position_msg().c_str());
171 unsigned int region_id = lexical_cast<
unsigned int>(*tok); ++tok;
172 lexical_cast<
unsigned int>(*tok); ++tok;
174 unsigned int partition_id=0;
175 if (n_tags > 2) { partition_id = lexical_cast<
unsigned int>(*tok); ++tok; }
176 for (
unsigned int ti = 3; ti < n_tags; ti++) ++tok;
182 RegionDB::MapElementIDToRegionID::const_iterator it = el_to_reg_map->find(
id);
183 if (it != el_to_reg_map->end()) region_id = it->second;
191 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);
195 ele->
init(dim, mesh, region_idx);
196 ele->
pid=partition_id;
200 unsigned int node_id = lexical_cast<
unsigned int>(*tok);
203 "Unknown node id %d in specification of element with id=%d, %s.\n",
204 node_id, id, tok.position_msg().c_str());
205 ele->
node[ni] = node;
210 }
catch (bad_lexical_cast &) {
211 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
221 using namespace boost;
223 if (! tok.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
225 tok.next_line(
false);
226 unsigned int n_physicals = lexical_cast<
unsigned int> (*tok);
229 for (
unsigned int i = 0; i < n_physicals; ++i) {
234 unsigned int dim = lexical_cast<
unsigned int>(*tok); ++tok;
235 unsigned int id = lexical_cast<
unsigned int>(*tok); ++tok;
236 string name = *tok; ++tok;
241 }
catch (bad_lexical_cast &) {
242 xprintf(
UsrErr,
"Wrong format of number, %s.\n", tok.position_msg().c_str());
250 using namespace boost;
253 tok.next_line(
false);
254 unsigned int n_str = lexical_cast<
unsigned int>(*tok); ++tok;
258 tok.next_line(); n_str--;
262 tok.next_line(); n_str--;
265 for(;n_str>0;n_str--) tok.next_line(
false);
269 unsigned int n_real = lexical_cast<
unsigned int>(*tok); ++tok;
272 tok.next_line(); n_real--;
273 head.
time=lexical_cast<
double>(*tok); ++tok;
275 for(;n_real>0;n_real--) tok.next_line(
false);
279 unsigned int n_int = lexical_cast<
unsigned int>(*tok); ++tok;
285 tok.next_line(); n_int--;
286 head.
time_index=lexical_cast<
unsigned int>(*tok); ++tok;
289 tok.next_line(); n_int--;
290 head.
n_components=lexical_cast<
unsigned int>(*tok); ++tok;
293 tok.next_line(); n_int--;
294 head.
n_entities=lexical_cast<
unsigned int>(*tok); ++tok;
296 for(;n_int>0;n_int--) tok.next_line(
false);
297 }
catch (bad_lexical_cast &) {
298 xprintf(
UsrErr,
"Wrong format of the $ElementData header, %s.\n", tok.position_msg().c_str());
308 using namespace boost;
310 unsigned int id, idx, n_read;
322 id_iter=el_ids.begin();
327 id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
328 while (id_iter != el_ids.end() && *id_iter < (int)
id) {
331 if (id_iter == el_ids.end()) {
332 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",
337 if (*id_iter == (
int)id) {
338 idx = id_iter - el_ids.begin();
340 for (
unsigned int i_col =0; i_col < search_header.
n_components; ++i_col, ++data_ptr) {
341 *(data_ptr) = lexical_cast<double>(*tok_); ++
tok_;
346 }
catch (bad_lexical_cast &) {
347 xprintf(
UsrErr,
"Wrong format of $ElementData line, %s.\n",
tok_.position_msg().c_str());
352 xprintf(
Msg,
"time: %f; %d entities of field %s read.\n",
355 search_header.
actual =
true;
361 if (
tok_.skip_to(
"$ElementData") )
368 xprintf(
UsrErr,
"In file '%s', missing '$ElementData' section for field '%s'.\n",
379 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of components: %d, using %d instead.\n",
384 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of entities: %d, using %d instead.\n",
#define FOR_ELEMENT_NODES(i, j)
void read_nodes(Tokenizer &in, Mesh *)
bool is_boundary() const
Returns true if it is a Boundary region and false if it is a Bulk region.
void read_data_header(Tokenizer &tok, GMSH_DataHeader &head)
void read_physical_names(Tokenizer &in, Mesh *mesh)
void reserve(unsigned int size)
Reallocates the container space.
FullIter add_item(int id)
GmshMeshReader(const FilePath &file_name)
FullIter find_id(const int id)
void read_elements(Tokenizer &in, Mesh *, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL)
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
#define START_TIMER(tag)
Starts a timer with specified tag.
void read_element_data(GMSH_DataHeader &search_header, double *data, std::vector< int > const &el_ids)
ElementVector bc_elements
Region add_region(unsigned int id, const std::string &label, unsigned int dim)
#define INPUT_CHECK(i,...)
Debugging macros.
void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
Dedicated class for storing path to input and output files.
unsigned int n_all_input_elements_
Number of elements read from input.
void read_mesh(Mesh *mesh, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL)
GMSH_DataHeader last_header
Last read header of ElementData section.
FullIter end()
Returns FullFullIterer of the fictions past the end element.
Tokenizer tok_
Tokenizer used for reading ASCII GMSH file format.
NodeVector node_vector
Vector of nodes of the mesh.
ElementVector element
Vector of elements of the mesh.