29 #include "boost/lexical_cast.hpp" 42 tok_.set_comment_pattern(
"#");
52 tok_.set_comment_pattern(
"#");
66 OLD_ASSERT( mesh ,
"Argument mesh is NULL.\n");
74 using namespace boost;
77 if (!
tok_.skip_to(
"$Nodes"))
THROW(ExcMissingSection() << EI_Section(
"$Nodes") << EI_GMSHFile(
tok_.f_name()) );
79 tok_.next_line(
false);
80 unsigned int n_nodes = lexical_cast<
unsigned int> (*tok_);;
81 INPUT_CHECK( n_nodes > 0,
"Zero number of nodes, %s.\n", tok_.position_msg().c_str() );
85 for (
unsigned int i = 0; i < n_nodes; ++i) {
88 unsigned int id = lexical_cast<
unsigned int> (*tok_); ++
tok_;
91 node->point()(0)=lexical_cast<double> (*tok_); ++
tok_;
92 node->point()(1)=lexical_cast<double> (*tok_); ++
tok_;
93 node->point()(2)=lexical_cast<double> (*tok_); ++
tok_;
97 }
catch (bad_lexical_cast &) {
98 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
106 using namespace boost;
109 if (!
tok_.skip_to(
"$Elements"))
THROW(ExcMissingSection() << EI_Section(
"$Elements") << EI_GMSHFile(
tok_.f_name()) );
111 tok_.next_line(
false);
112 unsigned int n_elements = lexical_cast<
unsigned int> (*tok_);
113 INPUT_CHECK( n_elements > 0,
"Zero number of elements, %s.\n", tok_.position_msg().c_str());
118 for (
unsigned int i = 0; i < n_elements; ++i) {
121 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
129 unsigned int type = lexical_cast<
unsigned int>(*tok_); ++
tok_;
146 THROW(ExcUnsupportedType() << EI_ElementId(
id) << EI_ElementType(type) << EI_GMSHFile(tok_.f_name()) );
151 unsigned int n_tags = lexical_cast<
unsigned int>(*tok_);
152 INPUT_CHECK(n_tags >= 2,
"At least two element tags have to be defined for element with id=%d, %s.\n",
153 id, tok_.position_msg().c_str());
157 unsigned int region_id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
158 lexical_cast<
unsigned int>(*tok_); ++
tok_;
160 unsigned int partition_id=0;
161 if (n_tags > 2) { partition_id = lexical_cast<
unsigned int>(*tok_); ++
tok_; }
162 for (
unsigned int ti = 3; ti < n_tags; ti++) ++tok_;
177 WarningOut().fmt(
"Bulk elements of zero size(dim=0) are not supported. Mesh file: {}, Element ID: {}.\n", tok_.f_name() ,id);
181 ele->
init(dim, mesh, region_idx);
182 ele->
pid=partition_id;
186 unsigned int node_id = lexical_cast<
unsigned int>(*tok_);
189 "Unknown node id %d in specification of element with id=%d, %s.\n",
190 node_id, id, tok_.position_msg().c_str());
191 ele->
node[ni] = node;
196 }
catch (bad_lexical_cast &) {
197 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
207 OLD_ASSERT( mesh ,
"Argument mesh is NULL.\n");
208 using namespace boost;
210 if (!
tok_.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
212 tok_.next_line(
false);
213 unsigned int n_physicals = lexical_cast<
unsigned int> (*tok_);
216 for (
unsigned int i = 0; i < n_physicals; ++i) {
221 unsigned int dim = lexical_cast<
unsigned int>(*tok_); ++
tok_;
222 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
228 }
catch (bad_lexical_cast &) {
229 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
237 using namespace boost;
240 tok_.next_line(
false);
241 unsigned int n_str = lexical_cast<
unsigned int>(*tok_); ++
tok_;
245 tok_.next_line(); n_str--;
249 tok_.next_line(); n_str--;
252 for(;n_str>0;n_str--) tok_.next_line(
false);
256 unsigned int n_real = lexical_cast<
unsigned int>(*tok_); ++
tok_;
259 tok_.next_line(); n_real--;
260 head.
time=lexical_cast<
double>(*tok_); ++
tok_;
262 for(;n_real>0;n_real--) tok_.next_line(
false);
266 unsigned int n_int = lexical_cast<
unsigned int>(*tok_); ++
tok_;
272 tok_.next_line(); n_int--;
276 tok_.next_line(); n_int--;
280 tok_.next_line(); n_int--;
283 for(;n_int>0;n_int--) tok_.next_line(
false);
284 head.
position = tok_.get_position();
285 }
catch (bad_lexical_cast &) {
286 THROW(ExcWrongFormat() << EI_Type(
"$ElementData header") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
296 using namespace boost;
301 unsigned int id, idx, i_row;
302 unsigned int n_read = 0;
303 unsigned int size_of_cache;
308 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nWrong number of entities: {}, using {} instead.\n",
322 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nWrong number of components: {}, using {} instead.\n",
330 for (
unsigned int i=0; i<size_of_cache; ++i) {
333 data_cache[i] = row_vec;
341 for (i_row = 0; i_row < actual_header.
n_entities; ++i_row)
344 id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
346 while (id_iter != el_ids.end() && *id_iter < (int)
id) {
349 if (id_iter == el_ids.end()) {
350 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nData ID {} not found or is not in order. Skipping rest of data.\n",
355 if (*id_iter == (
int)id) {
356 for (
unsigned int i_vec=0; i_vec<size_of_cache; ++i_vec) {
357 idx = (id_iter - el_ids.begin()) * search_header.
n_components;
359 for (
unsigned int i_col=0; i_col < search_header.
n_components; ++i_col, ++idx) {
360 vec[idx] = lexical_cast<T>(*tok_);
367 }
catch (bad_lexical_cast &) {
368 THROW(ExcWrongFormat() << EI_Type(
"$ElementData line") << EI_TokenizerMsg(
tok_.position_msg())
369 << EI_GMSHFile(
tok_.f_name()) );
372 while (i_row < actual_header.
n_entities)
tok_.next_line(
false), ++i_row;
374 LogOut().fmt(
"time: {}; {} entities of field {} read.\n",
377 search_header.
actual =
true;
384 if (component_idx == std::numeric_limits<unsigned int>::max()) component_idx = 0;
394 while ( !
tok_.eof() ) {
395 if (
tok_.skip_to(
"$ElementData") ) {
401 vec.push_back(header);
403 }
else if ( header.
time <= it->second.back().time ) {
404 WarningOut().fmt(
"Wrong time order: field '{}', time '{}', file '{}'. Skipping this '$ElementData' section.\n",
407 it->second.push_back(header);
412 tok_.set_position( Tokenizer::Position() );
419 HeaderTable::iterator table_it =
header_table_.find(field_name);
423 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name) << EI_GMSHFile(
tok_.f_name()));
431 table_it->second.end(),
435 if (headers_it == table_it->second.begin()) {
436 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name)
437 << EI_GMSHFile(
tok_.f_name()) << EI_Time(time));
446 #define READER_GET_ELEMENT_DATA(TYPE) \ 447 template typename ElementDataCache<TYPE>::ComponentDataPtr GmshMeshReader::get_element_data<TYPE>(GMSH_DataHeader &search_header, \ 448 std::vector<int> const & el_ids, unsigned int component_idx) void read_elements(Mesh *)
#define READER_GET_ELEMENT_DATA(TYPE)
#define FOR_ELEMENT_NODES(i, j)
std::shared_ptr< std::vector< T > > ComponentDataPtr
bool is_boundary() const
Returns true if it is a Boundary region and false if it is a Bulk region.
#define MessageOut()
Macro defining 'message' record of log.
#define INPUT_CHECK(i,...)
Debugging macros.
void reserve(unsigned int size)
Reallocates the container space.
string create_label_from_id(unsigned int id) const
FullIter add_item(int id)
GmshMeshReader(const FilePath &file_name)
FullIter find_id(const int id)
void read_data_header(GMSH_DataHeader &head)
ElementDataCacheBase * current_cache_
Cache with last read element data.
GMSH_DataHeader & find_header(double time, std::string field_name)
#define LogOut()
Macro defining 'log' record of log.
Region get_region(unsigned int id, unsigned int dim)
ElementDataCache< T >::ComponentDataPtr get_element_data(GMSH_DataHeader &search_header, std::vector< int > const &el_ids, unsigned int component_idx)
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.
ElementVector bc_elements
void read_mesh(Mesh *mesh)
void init(unsigned int dim, Mesh *mesh_in, RegionIdx reg)
Dedicated class for storing path to input and output files.
void mark_used_region(unsigned int idx)
Region add_region(unsigned int id, const std::string &label, unsigned int dim, const std::string &address="implicit")
HeaderTable header_table_
Table with data of ElementData headers.
unsigned int n_all_input_elements_
Number of elements read from input.
void read_physical_names(Mesh *mesh)
#define WarningOut()
Macro defining 'warning' record of log.
bool is_actual(double time, std::string quantity_name)
Check if cache stored actual data.
bool is_valid() const
Returns false if the region has undefined/invalid value.
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.
unsigned int idx() const
Returns a global index of the region.