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");
67 tok_.set_position( Tokenizer::Position() );
75 using namespace boost;
78 if (!
tok_.skip_to(
"$Nodes"))
THROW(ExcMissingSection() << EI_Section(
"$Nodes") << EI_GMSHFile(
tok_.f_name()) );
80 tok_.next_line(
false);
81 unsigned int n_nodes = lexical_cast<
unsigned int> (*tok_);;
82 INPUT_CHECK( n_nodes > 0,
"Zero number of nodes, %s.\n", tok_.position_msg().c_str() );
86 for (
unsigned int i = 0; i < n_nodes; ++i) {
89 unsigned int id = lexical_cast<
unsigned int> (*tok_); ++
tok_;
92 node->point()(0)=lexical_cast<double> (*tok_); ++
tok_;
93 node->point()(1)=lexical_cast<double> (*tok_); ++
tok_;
94 node->point()(2)=lexical_cast<double> (*tok_); ++
tok_;
98 }
catch (bad_lexical_cast &) {
99 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
107 using namespace boost;
110 if (!
tok_.skip_to(
"$Elements"))
THROW(ExcMissingSection() << EI_Section(
"$Elements") << EI_GMSHFile(
tok_.f_name()) );
112 tok_.next_line(
false);
113 unsigned int n_elements = lexical_cast<
unsigned int> (*tok_);
114 INPUT_CHECK( n_elements > 0,
"Zero number of elements, %s.\n", tok_.position_msg().c_str());
119 for (
unsigned int i = 0; i < n_elements; ++i) {
122 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
130 unsigned int type = lexical_cast<
unsigned int>(*tok_); ++
tok_;
147 THROW(ExcUnsupportedType() << EI_ElementId(
id) << EI_ElementType(type) << EI_GMSHFile(tok_.f_name()) );
152 unsigned int n_tags = lexical_cast<
unsigned int>(*tok_);
153 INPUT_CHECK(n_tags >= 2,
"At least two element tags have to be defined for element with id=%d, %s.\n",
154 id, tok_.position_msg().c_str());
158 unsigned int region_id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
159 lexical_cast<
unsigned int>(*tok_); ++
tok_;
161 unsigned int partition_id=0;
162 if (n_tags > 2) { partition_id = lexical_cast<
unsigned int>(*tok_); ++
tok_; }
163 for (
unsigned int ti = 3; ti < n_tags; ti++) ++tok_;
178 WarningOut().fmt(
"Bulk elements of zero size(dim=0) are not supported. Mesh file: {}, Element ID: {}.\n", tok_.f_name() ,id);
182 ele->
init(dim, mesh, region_idx);
183 ele->
pid=partition_id;
187 unsigned int node_id = lexical_cast<
unsigned int>(*tok_);
190 "Unknown node id %d in specification of element with id=%d, %s.\n",
191 node_id, id, tok_.position_msg().c_str());
192 ele->
node[ni] = node;
197 }
catch (bad_lexical_cast &) {
198 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
208 OLD_ASSERT( mesh ,
"Argument mesh is NULL.\n");
209 using namespace boost;
211 if (!
tok_.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
213 tok_.next_line(
false);
214 unsigned int n_physicals = lexical_cast<
unsigned int> (*tok_);
217 for (
unsigned int i = 0; i < n_physicals; ++i) {
222 unsigned int dim = lexical_cast<
unsigned int>(*tok_); ++
tok_;
223 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
229 }
catch (bad_lexical_cast &) {
230 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
238 using namespace boost;
241 tok_.next_line(
false);
242 unsigned int n_str = lexical_cast<
unsigned int>(*tok_); ++
tok_;
246 tok_.next_line(); n_str--;
250 tok_.next_line(); n_str--;
253 for(;n_str>0;n_str--) tok_.next_line(
false);
257 unsigned int n_real = lexical_cast<
unsigned int>(*tok_); ++
tok_;
260 tok_.next_line(); n_real--;
261 head.
time=lexical_cast<
double>(*tok_); ++
tok_;
263 for(;n_real>0;n_real--) tok_.next_line(
false);
267 unsigned int n_int = lexical_cast<
unsigned int>(*tok_); ++
tok_;
273 tok_.next_line(); n_int--;
277 tok_.next_line(); n_int--;
281 tok_.next_line(); n_int--;
284 for(;n_int>0;n_int--) tok_.next_line(
false);
285 head.
position = tok_.get_position();
286 }
catch (bad_lexical_cast &) {
287 THROW(ExcWrongFormat() << EI_Type(
"$ElementData header") << EI_TokenizerMsg(
tok_.position_msg()) << EI_GMSHFile(
tok_.f_name()) );
297 using namespace boost;
302 unsigned int id, idx, i_row;
303 unsigned int n_read = 0;
304 unsigned int size_of_cache;
309 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nWrong number of entities: {}, using {} instead.\n",
323 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nWrong number of components: {}, using {} instead.\n",
331 for (
unsigned int i=0; i<size_of_cache; ++i) {
334 data_cache[i] = row_vec;
342 for (i_row = 0; i_row < actual_header.
n_entities; ++i_row)
345 id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
347 while (id_iter != el_ids.end() && *id_iter < (int)
id) {
350 if (id_iter == el_ids.end()) {
351 WarningOut().fmt(
"In file '{}', '$ElementData' section for field '{}', time: {}.\nData ID {} not found or is not in order. Skipping rest of data.\n",
356 if (*id_iter == (
int)id) {
357 for (
unsigned int i_vec=0; i_vec<size_of_cache; ++i_vec) {
358 idx = (id_iter - el_ids.begin()) * search_header.
n_components;
360 for (
unsigned int i_col=0; i_col < search_header.
n_components; ++i_col, ++idx) {
361 vec[idx] = lexical_cast<T>(*tok_);
368 }
catch (bad_lexical_cast &) {
369 THROW(ExcWrongFormat() << EI_Type(
"$ElementData line") << EI_TokenizerMsg(
tok_.position_msg())
370 << EI_GMSHFile(
tok_.f_name()) );
373 while (i_row < actual_header.
n_entities)
tok_.next_line(
false), ++i_row;
375 LogOut().fmt(
"time: {}; {} entities of field {} read.\n",
378 search_header.
actual =
true;
385 if (component_idx == std::numeric_limits<unsigned int>::max()) component_idx = 0;
395 while ( !
tok_.eof() ) {
396 if (
tok_.skip_to(
"$ElementData") ) {
402 vec.push_back(header);
404 }
else if ( header.
time <= it->second.back().time ) {
405 WarningOut().fmt(
"Wrong time order: field '{}', time '{}', file '{}'. Skipping this '$ElementData' section.\n",
408 it->second.push_back(header);
413 tok_.set_position( Tokenizer::Position() );
420 HeaderTable::iterator table_it =
header_table_.find(field_name);
424 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name) << EI_GMSHFile(
tok_.f_name()));
432 table_it->second.end(),
436 if (headers_it == table_it->second.begin()) {
437 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name)
438 << EI_GMSHFile(
tok_.f_name()) << EI_Time(time));
447 #define READER_GET_ELEMENT_DATA(TYPE) \ 448 template typename ElementDataCache<TYPE>::ComponentDataPtr GmshMeshReader::get_element_data<TYPE>(GMSH_DataHeader &search_header, \ 449 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.
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)
#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.
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.