Flow123d  jenkins-Flow123d-windows32-release-multijob-51
msh_gmshreader.h
Go to the documentation of this file.
1 /*!
2  *
3  * Copyright (C) 2007 Technical University of Liberec. All rights reserved.
4  *
5  * Please make a following refer to Flow123d on your project site if you use the program for any purpose,
6  * especially for academic research:
7  * Flow123d, Research Centre: Advanced Remedial Technologies, Technical University of Liberec, Czech Republic
8  *
9  * This program is free software; you can redistribute it and/or modify it under the terms
10  * of the GNU General Public License version 3 as published by the Free Software Foundation.
11  *
12  * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along with this program; if not,
17  * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 021110-1307, USA.
18  *
19  *
20  * $Id$
21  * $Revision$
22  * $LastChangedBy$
23  * $LastChangedDate$
24  *
25  *
26  * @file msh_gmshreader.h
27  * @author dalibor
28  *
29  * @date October 3, 2010, 11:23 AM
30  */
31 
32 #ifndef _GMSHMESHREADER_H
33 #define _GMSHMESHREADER_H
34 
35 #include <string>
36 #include <istream>
37 #include <vector>
38 #include <map>
39 
40 
41 #include "system/tokenizer.hh"
42 #include "mesh/region.hh"
43 
44 class Mesh;
45 class FilePath;
46 
47 
48 
49 /***********************************
50  * Structure to store the information from a header of \\$ElementData section.
51  *
52  * Format of GMSH ASCII data sections
53  *
54  number-of-string-tags (== 2)
55  field_name
56  interpolation_scheme_name
57  number-of-real-tags (==1)
58  time_of_dataset
59  number-of-integer-tags
60  time_step_index (starting from zero)
61  number_of_field_components (1, 3, or 9 - i.e. 3d scalar, vector or tensor data)
62  number_of entities (nodes or elements)
63  partition_index (0 == no partition, not clear if GMSH support reading different partition from different files)
64  elm-number value ...
65 *
66 */
67 
69  /// True if the stream position is just after the header.
70  /// False either before first header is found or at EOF.
71  bool actual;
72  std::string field_name;
73  /// Currently ont used
74  std::string interpolation_scheme;
75  double time;
76  /// Currently ont used
77  unsigned int time_index;
78  /// Number of values on one row
79  unsigned int n_components;
80  /// Number of rows
81  unsigned int n_entities;
82  /// ?? Currently ont used
83  unsigned int partition_index;
84 };
85 
86 
88 public:
89  /**
90  * Construct the GMSH format reader from given filename.
91  * This opens the file for reading.
92  */
93  GmshMeshReader(const FilePath &file_name);
94  /**
95  * Construct the GMSH format reader from given input stream.
96  * The input stream should be correctly opened. To get correct information about
97  * line numbers there should be no previous reading from the stream.
98  */
99  GmshMeshReader(std::istream &in);
100 
101  /**
102  * Destructor close the file if opened.
103  */
104  ~GmshMeshReader();
105 
106  /**
107  * Reads @p mesh from the GMSH file.
108  * Optional map el_to_reg_map can be used to override region of some elements provided by GMSH file.
109  * Input of the mesh allows changing regions within the input CON file.
110  */
111  void read_mesh(Mesh* mesh, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL);
112 
113  /**
114  * Reads ElementData sections of opened GMSH file. The file is serached for the \\$ElementData section with header
115  * that match the given @p search_header (same field_name, time of the next section is the first greater then
116  * that given in the @p search_header). If such section has not been yet read, we read the data section into
117  * raw buffer @p data. The map @p id_to_idx is used to convert IDs that marks individual input rows/entities into
118  * indexes to the raw buffer. The buffer must have size at least @p search_header.n_components * @p search_header.n_entities.
119  * Indexes in the map must be smaller then @p search_header.n_entities.
120  * If the @p data buffer is updated we set search_header.actual to true.
121  *
122  * Possible optimizations:
123  * If the map ID lookup seem slow, we may assume that IDs are in increasing order, use simple array of IDs instead of map
124  * and just check that they comes in in correct order.
125  */
126  void read_element_data( GMSH_DataHeader &search_header,
127  double *data, std::vector<int> const & el_ids);
128 
129 private:
130  /**
131  * Read section '$PhysicalNames' of the GMSH file and save the physical sections as regions in the RegionDB.
132  *
133  * Region Labels starting with '!' are treated as boundary regions. Elements of these regions are used just to
134  * assign regions to the boundary and are not used in actual FEM computations.
135  */
136  void read_physical_names(Tokenizer &in, Mesh * mesh);
137 
138  /**
139  * private method for reading of nodes
140  */
141  void read_nodes(Tokenizer &in, Mesh*);
142  /**
143  * Method for reading of elements.
144  * Optional map el_to_reg_map can be used to override region of some elements provided by GMSH file.
145  * Input of the mesh allows changing regions within the input CON file.
146  *
147  */
148  void read_elements(Tokenizer &in, Mesh*, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL);
149  /**
150  *
151  */
152  void read_data_header(Tokenizer &tok, GMSH_DataHeader &head);
153 
154 
155  /// Tokenizer used for reading ASCII GMSH file format.
156  Tokenizer tok_;
157  /// Last read header of ElementData section.
159 };
160 
161 #endif /* _GMSHMESHREADER_H */
162 
std::string field_name
void read_nodes(Tokenizer &in, Mesh *)
void read_data_header(Tokenizer &tok, GMSH_DataHeader &head)
void read_physical_names(Tokenizer &in, Mesh *mesh)
Definition: mesh.h:108
GmshMeshReader(const FilePath &file_name)
void read_elements(Tokenizer &in, Mesh *, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL)
unsigned int n_entities
Number of rows.
void read_element_data(GMSH_DataHeader &search_header, double *data, std::vector< int > const &el_ids)
unsigned int n_components
Number of values on one row.
Dedicated class for storing path to input and output files.
Definition: file_path.hh:32
void read_mesh(Mesh *mesh, const RegionDB::MapElementIDToRegionID *el_to_reg_map=NULL)
GMSH_DataHeader last_header
Last read header of ElementData section.
std::string interpolation_scheme
Currently ont used.
unsigned int time_index
Currently ont used.
unsigned int partition_index
?? Currently ont used
Tokenizer tok_
Tokenizer used for reading ASCII GMSH file format.