Flow123d  JS_before_hm-2152-gf87f4aac4
msh_gmshreader.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2015 Technical University of Liberec. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it under
6  * the terms of the GNU General Public License version 3 as published by the
7  * Free Software Foundation. (http://www.gnu.org/licenses/gpl-3.0.en.html)
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12  *
13  *
14  * @file msh_gmshreader.h
15  * @brief
16  * @author dalibor
17  */
18 
19 #ifndef _GMSHMESHREADER_H
20 #define _GMSHMESHREADER_H
21 
22 
23 #include <map> // for map, map<>::value_compare
24 #include <string> // for string
25 #include <vector> // for vector
26 #include "io/msh_basereader.hh" // for MeshDataHeader, BaseMeshReader
27 #include "system/exceptions.hh" // for ExcStream, operator<<, EI, TYPED...
28 
30 class FilePath;
31 class Mesh;
32 
33 
34 
36 public:
37  TYPEDEF_ERR_INFO(EI_GMSHFile, std::string);
38  TYPEDEF_ERR_INFO(EI_Section, std::string);
39  TYPEDEF_ERR_INFO(EI_ElementId, int);
40  TYPEDEF_ERR_INFO(EI_ElementType, int);
41  TYPEDEF_ERR_INFO(EI_Position, std::string);
42  DECLARE_EXCEPTION(ExcMissingSection,
43  << "Missing section " << EI_Section::qval << " in the GMSH input file: " << EI_GMSHFile::qval);
44  DECLARE_EXCEPTION(ExcUnsupportedType,
45  << "Element " << EI_ElementId::val << "in the GMSH input file " << EI_GMSHFile::qval
46  << " is of the unsupported type " << EI_ElementType::val );
47  DECLARE_EXCEPTION(ExcZeroNodes,
48  << "Zero number of nodes, " << EI_Position::val << ".\n");
49  DECLARE_EXCEPTION(ExcZeroElements,
50  << "Zero number of elements, " << EI_Position::val << ".\n");
51  DECLARE_EXCEPTION(ExcTooManyElementTags,
52  << "At least two element tags have to be defined for element with id=" << EI_ElementId::val << ", " << EI_Position::val << ".\n");
53 
54  /**
55  * Construct the GMSH format reader from given FilePath.
56  * This opens the file for reading.
57  */
58  GmshMeshReader(const FilePath &file_name);
59 
60  /**
61  * Destructor close the file if opened.
62  */
63  virtual ~GmshMeshReader();
64 
65  /**
66  * Read section '$PhysicalNames' of the GMSH file and save the physical sections as regions in the RegionDB.
67  *
68  * Region Labels starting with '!' are treated as boundary regions. Elements of these regions are used just to
69  * assign regions to the boundary and are not used in actual FEM computations.
70  */
71  void read_physical_names(Mesh * mesh) override;
72 
73  /**
74  * Finds GMSH data header for ElementData given by time and field_name and stores it as \p actual_header_.
75  */
76  MeshDataHeader & find_header(HeaderQuery &header_query) override;
77 
78 protected:
79  /**
80  * Map of ElementData sections in GMSH file.
81  *
82  * For each field_name contains vector of MeshDataHeader.
83  * Headers are sorted by time in ascending order.
84  */
86 
87  /**
88  * private method for reading of nodes
89  */
90  void read_nodes(Mesh * mesh);
91  /**
92  * Method for reading of elements.
93  * Input of the mesh allows changing regions within the input CON file.
94  * Read section '$PhysicalNames' of the GMSH file and save the physical sections to general data structure.
95  *
96  * Region Labels starting with '!' are treated as boundary regions. Elements of these regions are used just to
97  * assign regions to the boundary and are not used in actual FEM computations.
98  */
99  void read_elements(Mesh * mesh);
100  /**
101  * Reads the header from the tokenizer @p tok and return it as the second parameter.
102  */
103  void read_data_header(MeshDataHeader &head);
104  /**
105  * Reads table of ElementData headers from the tokenizer file.
106  */
107  void make_header_table() override;
108  /**
109  * Implements @p BaseMeshReader::read_element_data.
110  */
111  void read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components,
112  bool boundary_domain) override;
113 
114 
115  /// Table with data of ElementData headers
117 };
118 
119 #endif /* _GMSHMESHREADER_H */
120 
121 
GmshMeshReader::DECLARE_EXCEPTION
DECLARE_EXCEPTION(ExcMissingSection,<< "Missing section "<< EI_Section::qval<< " in the GMSH input file: "<< EI_GMSHFile::qval)
msh_basereader.hh
GmshMeshReader::find_header
MeshDataHeader & find_header(HeaderQuery &header_query) override
Definition: msh_gmshreader.cc:324
GmshMeshReader::make_header_table
void make_header_table() override
Definition: msh_gmshreader.cc:297
GmshMeshReader::read_physical_names
void read_physical_names(Mesh *mesh) override
Definition: msh_gmshreader.cc:165
FilePath
Dedicated class for storing path to input and output files.
Definition: file_path.hh:54
exceptions.hh
GmshMeshReader::HeaderTable
std::map< std::string, std::vector< MeshDataHeader > > HeaderTable
Definition: msh_gmshreader.h:85
GmshMeshReader::read_element_data
void read_element_data(ElementDataCacheBase &data_cache, MeshDataHeader actual_header, unsigned int n_components, bool boundary_domain) override
Definition: msh_gmshreader.cc:253
GmshMeshReader::TYPEDEF_ERR_INFO
TYPEDEF_ERR_INFO(EI_GMSHFile, std::string)
BaseMeshReader
Definition: msh_basereader.hh:58
GmshMeshReader
Definition: msh_gmshreader.h:35
GmshMeshReader::read_nodes
void read_nodes(Mesh *mesh)
Definition: msh_gmshreader.cc:56
ElementDataCacheBase
Definition: element_data_cache_base.hh:33
std::map
Definition: doxy_dummy_defs.hh:11
BaseMeshReader::MeshDataHeader
Definition: msh_basereader.hh:100
GmshMeshReader::~GmshMeshReader
virtual ~GmshMeshReader()
Definition: msh_gmshreader.cc:51
Mesh
Definition: mesh.h:355
GmshMeshReader::header_table_
HeaderTable header_table_
Table with data of ElementData headers.
Definition: msh_gmshreader.h:116
GmshMeshReader::read_data_header
void read_data_header(MeshDataHeader &head)
Definition: msh_gmshreader.cc:196
BaseMeshReader::HeaderQuery
Definition: msh_basereader.hh:132
GmshMeshReader::GmshMeshReader
GmshMeshReader(const FilePath &file_name)
Definition: msh_gmshreader.cc:39
GmshMeshReader::read_elements
void read_elements(Mesh *mesh)
Definition: msh_gmshreader.cc:90