42 #include "boost/lexical_cast.hpp"
55 tok_.set_comment_pattern(
"#");
65 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);
298 }
catch (bad_lexical_cast &) {
299 xprintf(
UsrErr,
"Wrong format of the $ElementData header, %s.\n", tok.position_msg().c_str());
309 using namespace boost;
314 unsigned int id, idx, i_row;
315 unsigned int n_read = 0;
316 unsigned int size_of_cache;
321 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of entities: %d, using %d instead.\n",
335 xprintf(
Warn,
"In file '%s', '$ElementData' section for field '%s', time: %f.\nWrong number of components: %d, using %d instead.\n",
343 for (
unsigned int i=0; i<size_of_cache; ++i) {
346 data_cache[i] = row_vec;
354 for (i_row = 0; i_row < actual_header.
n_entities; ++i_row)
357 id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
359 while (id_iter != el_ids.end() && *id_iter < (int)
id) {
362 if (id_iter == el_ids.end()) {
363 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",
364 tok_.f_name().c_str(), search_header.
field_name.c_str(), actual_header.
time, id);
368 if (*id_iter == (
int)id) {
369 for (
unsigned int i_vec=0; i_vec<size_of_cache; ++i_vec) {
370 idx = (id_iter - el_ids.begin()) * search_header.
n_components;
372 for (
unsigned int i_col=0; i_col < search_header.
n_components; ++i_col, ++idx) {
373 vec[idx] = lexical_cast<T>(*tok_);
380 }
catch (bad_lexical_cast &) {
381 xprintf(
UsrErr,
"Wrong format of $ElementData line, %s.\n",
tok_.position_msg().c_str());
384 while (i_row < actual_header.
n_entities)
tok_.next_line(
false), ++i_row;
389 search_header.
actual =
true;
396 if (component_idx == std::numeric_limits<unsigned int>::max()) component_idx = 0;
406 while ( !
tok_.eof() ) {
407 if (
tok_.skip_to(
"$ElementData") ) {
413 vec.push_back(header);
415 }
else if ( header.
time <= it->second.back().time ) {
417 "Wrong time order: field '%s', time '%d', file '%s'. Skipping this '$ElementData' section.\n",
420 it->second.push_back(header);
425 tok_.set_position( Tokenizer::Position() );
432 HeaderTable::iterator table_it =
header_table_.find(field_name);
436 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name) << EI_GMSHFile(
tok_.f_name()));
444 table_it->second.end(),
448 if (headers_it == table_it->second.begin()) {
449 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name)
450 << EI_GMSHFile(
tok_.f_name()) << EI_Time(time));
459 #define READER_GET_ELEMENT_DATA(TYPE) \
460 template typename ElementDataCache<TYPE>::ComponentDataPtr GmshMeshReader::get_element_data<TYPE>(GMSH_DataHeader &search_header, \
461 std::vector<int> const & el_ids, unsigned int component_idx)
#define READER_GET_ELEMENT_DATA(TYPE)
#define FOR_ELEMENT_NODES(i, j)
std::shared_ptr< std::vector< T > > ComponentDataPtr
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)
ElementDataCacheBase * current_cache_
Cache with last read element data.
GMSH_DataHeader & find_header(double time, std::string field_name)
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.
ElementDataCache< T >::ComponentDataPtr get_element_data(GMSH_DataHeader &search_header, std::vector< int > const &el_ids, unsigned int component_idx)
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.
HeaderTable header_table_
Table with data of ElementData headers.
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)
bool is_actual(double time, std::string quantity_name)
Check if cache stored actual data.
FullIter end()
Returns FullFullIterer of the fictions past the end element.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
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.