28 #include "boost/lexical_cast.hpp" 40 tok_.set_comment_pattern(
"#");
54 using namespace boost;
57 tok_.set_position( Tokenizer::Position() );
59 if (!
tok_.skip_to(
"$Nodes"))
THROW(ExcMissingSection() << EI_Section(
"$Nodes") << EI_GMSHFile(
tok_.f_name()) );
61 tok_.next_line(
false);
62 n_nodes = lexical_cast<
unsigned int> (*tok_);
64 INPUT_CHECK( n_nodes > 0,
"Zero number of nodes, %s.\n", tok_.position_msg().c_str() );
67 for (
unsigned int i = 0; i < n_nodes; ++i) {
70 unsigned int id = lexical_cast<
unsigned int> (*tok_); ++
tok_;
72 coords(0) = lexical_cast<
double> (*tok_); ++
tok_;
73 coords(1) = lexical_cast<
double> (*tok_); ++
tok_;
74 coords(2) = lexical_cast<
double> (*tok_); ++
tok_;
80 }
catch (bad_lexical_cast &) {
81 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
83 MessageOut().fmt(
"... {} nodes read. \n", n_nodes);
88 using namespace boost;
91 if (!
tok_.skip_to(
"$Elements"))
THROW(ExcMissingSection() << EI_Section(
"$Elements") << EI_GMSHFile(
tok_.f_name()) );
93 tok_.next_line(
false);
94 unsigned int n_elements = lexical_cast<
unsigned int> (*tok_);
95 INPUT_CHECK( n_elements > 0,
"Zero number of elements, %s.\n", tok_.position_msg().c_str());
103 for (
unsigned int i = 0; i < n_elements; ++i) {
105 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
112 unsigned int type = lexical_cast<
unsigned int>(*tok_); ++
tok_;
129 THROW(ExcUnsupportedType() << EI_ElementId(
id) << EI_ElementType(type) << EI_GMSHFile(tok_.f_name()) );
134 unsigned int n_tags = lexical_cast<
unsigned int>(*tok_);
135 INPUT_CHECK(n_tags >= 2,
"At least two element tags have to be defined for element with id=%d, %s.\n",
136 id, tok_.position_msg().c_str());
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_);
152 mesh->
add_element(
id, dim, region_id, partition_id, node_ids);
155 }
catch (bad_lexical_cast &) {
156 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
166 ASSERT(mesh).error(
"Argument mesh is NULL.\n");
168 using namespace boost;
170 if (!
tok_.skip_to(
"$PhysicalNames",
"$Nodes") )
return;
172 tok_.next_line(
false);
173 unsigned int n_physicals = lexical_cast<
unsigned int> (*tok_);
176 for (
unsigned int i = 0; i < n_physicals; ++i) {
181 unsigned int dim = lexical_cast<
unsigned int>(*tok_); ++
tok_;
182 unsigned int id = lexical_cast<
unsigned int>(*tok_); ++
tok_;
187 }
catch (bad_lexical_cast &) {
188 THROW(ExcWrongFormat() << EI_Type(
"number") << EI_TokenizerMsg(
tok_.position_msg()) << EI_MeshFile(
tok_.f_name()) );
197 using namespace boost;
200 tok_.next_line(
false);
201 unsigned int n_str = lexical_cast<
unsigned int>(*tok_); ++
tok_;
205 tok_.next_line(); n_str--;
209 tok_.next_line(); n_str--;
212 for(;n_str>0;n_str--) tok_.next_line(
false);
216 unsigned int n_real = lexical_cast<
unsigned int>(*tok_); ++
tok_;
219 tok_.next_line(); n_real--;
220 head.
time=lexical_cast<
double>(*tok_); ++
tok_;
222 for(;n_real>0;n_real--) tok_.next_line(
false);
226 unsigned int n_int = lexical_cast<
unsigned int>(*tok_); ++
tok_;
232 tok_.next_line(); n_int--;
236 tok_.next_line(); n_int--;
240 tok_.next_line(); n_int--;
243 for(;n_int>0;n_int--) tok_.next_line(
false);
244 head.
position = tok_.get_position();
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) {
279 data_cache.
read_ascii_data(tok_, n_components, (id_iter - el_ids.begin()) );
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() );
325 HeaderTable::iterator table_it =
header_table_.find(field_name);
329 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name) << EI_MeshFile(
tok_.f_name()));
337 table_it->second.end(),
341 if (headers_it == table_it->second.begin()) {
342 THROW( ExcFieldNameNotFound() << EI_FieldName(field_name)
343 << EI_MeshFile(
tok_.f_name()) << EI_Time(time));
void make_header_table() override
void read_nodes(Mesh *mesh)
void read_data_header(MeshDataHeader &head)
MeshDataHeader & find_header(double time, std::string field_name) override
void add_node(unsigned int node_id, arma::vec3 coords)
Add new node of given id and coordinates to mesh.
void check_compatible_mesh(Mesh &mesh) override
#define MessageOut()
Macro defining 'message' record of log.
virtual ~GmshMeshReader()
void read_physical_names(Mesh *mesh) override
std::string data_section_name_
Store name of field data section specify for type of mesh file.
GmshMeshReader(const FilePath &file_name)
#define ASSERT(expr)
Allow use shorter versions of macro names if these names is not used with external library...
void add_physical_name(unsigned int dim, unsigned int id, std::string name)
Add new node of given id and coordinates to mesh.
#define LogOut()
Macro defining 'log' record of log.
unsigned int size() const
Returns size of the container. This is independent of the allocated space.
vector< int > bulk_elements_id_
void elements_id_maps(vector< int > &bulk_elements_id, vector< int > &boundary_elements_id) const
virtual void read_ascii_data(Tokenizer &tok, unsigned int n_components, unsigned int i_row)=0
ElementVector bc_elements
void reserve_element_size(unsigned int n_elements)
Reserve size of element vector.
void read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components, bool boundary_domain) override
#define INPUT_CHECK(i,...)
Debugging macros.
Dedicated class for storing path to input and output files.
void read_elements(Mesh *mesh)
HeaderTable header_table_
Table with data of ElementData headers.
unsigned int n_all_input_elements_
Number of elements read from input.
vector< int > boundary_elements_id_
#define WarningOut()
Macro defining 'warning' record of log.
void add_element(unsigned int elm_id, unsigned int dim, unsigned int region_id, unsigned int partition_id, std::vector< unsigned int > node_ids)
Add new element of given id to mesh.
bool has_compatible_mesh_
Tokenizer tok_
Tokenizer used for reading ASCII file format.
void reserve_node_size(unsigned int n_nodes)
Reserve size of node vector.
#define THROW(whole_exception_expr)
Wrapper for throw. Saves the throwing point.
std::vector< int > const & get_element_vector(bool boundary_domain)
ElementVector element
Vector of elements of the mesh.