COOLFluiD  Release kernel
COOLFluiD is a Collaborative Simulation Environment (CSE) focused on complex MultiPhysics simulations.
Reader.hpp
Go to the documentation of this file.
1 // Copyright (C) 2010-2013 von Karman Institute for Fluid Dynamics, Belgium
2 //
3 // This software is distributed under the terms of the
4 // GNU Lesser General Public License version 3 (LGPLv3).
5 // See doc/lgpl.txt and doc/gpl.txt for the license text.
6 
7 #ifndef cf3_mesh_Gmsh_Reader_hpp
8 #define cf3_mesh_Gmsh_Reader_hpp
9 
11 
12 #include <set>
13 #include <boost/tuple/tuple.hpp>
14 
15 #include "mesh/MeshReader.hpp"
16 
17 #include "mesh/gmsh/LibGmsh.hpp"
18 #include "mesh/gmsh/Shared.hpp"
19 
21 
22 namespace cf3 {
23 namespace mesh {
24 
25 class Elements;
26 class Region;
27 class MergedParallelDistribution;
28 class Dictionary;
29 
30 class Mesh;
31 
32 namespace gmsh {
33 
35 
39 class gmsh_API Reader : public MeshReader, public Shared
40 {
41 public: // functions
43  Reader( const std::string& name );
44 
46  static std::string type_name() { return "Reader"; }
47 
48  virtual std::string get_format() { return "Gmsh"; }
49 
50  virtual std::vector<std::string> get_extensions();
51 
52 private: // functions
53 
54  void get_file_positions();
55 
56  Handle<Region> create_region(std::string const& relative_path);
57 
58  void find_used_nodes();
59 
60  void read_coordinates();
61 
62  void read_connectivity();
63 
64  void read_element_node_data();
65 
66  void read_element_data();
67 
68  void read_node_data();
69 
70 private: // data
71 
72  virtual void do_read_mesh_into(const common::URI& fp, Mesh& mesh);
73 
74  enum HashType { NODES=0, ELEMS=1 };
76 
77  // map< gmsh index , pair< elements, index in elements > >
78  std::map<Uint, std::pair<Handle<Elements>,Uint> > m_elem_idx_gmsh_to_cf;
79  std::map<Uint, Uint> m_node_idx_gmsh_to_cf;
80 
81  boost::filesystem::fstream m_file;
84 
85  std::string m_file_basename;
86 
87  struct RegionData
88  {
91  std::string name;
93  std::set<Uint> element_types;
94  };
95 
96  Uint m_nb_regions; // This corresponds to the number of physical groups in
97  // gmsh terminology
99 
100 
101  std::vector<RegionData> m_region_list;
102 
103  std::set<Uint> m_ghost_nodes;
104  //std::set<Uint> m_ghost_elems;
105  std::set<Uint> m_used_nodes;
106 
107  std::vector<std::set<Uint> > m_node_to_glb_elements;
108 
109  //Markers for important places in the file to be read
110  std::streampos m_region_names_position;
111  std::streampos m_coordinates_position;
112  std::streampos m_elements_position;
113  std::vector<std::streampos> m_element_data_positions;
114  std::vector<std::streampos> m_node_data_positions;
115  std::vector<std::streampos> m_element_node_data_positions;
116 
117 
118  std::vector<std::vector<Uint> > m_nb_gmsh_elem_in_region;
121 
122  struct Field
123  {
124  std::string name;
125  std::vector<std::string> var_names;
126  std::string interpolation_scheme;
127  Real time;
129  std::vector<Uint> var_types;
131  std::vector<std::streampos> file_data_positions;
132  std::string description() const
133  {
134  std::stringstream ss;
135  for (Uint var=0; var<var_names.size(); ++var)
136  {
137  ss << var_names[var] << "["<<var_type_gmsh_to_cf(var_types[var])<<"]";
138  if (var<var_names.size()-1)
139  ss << ",";
140  }
141  return ss.str();
142  }
143  std::string var_type_gmsh_to_cf(const Uint& var_type_gmsh) const
144  {
145  switch (var_type_gmsh)
146  {
147  case 1:
148  return "scalar";
149  case 3:
150  return "vector";
151  case 9:
152  return "tensor";
153  default:
154  throw common::FileFormatError(FromHere(),"Gmsh variable type should be either 1(scalar), 3(vector), 9(tensor).");
155  }
156  return "null";
157  }
158  std::string dict_name() const;
159  std::string space_lib_name() const;
160  };
161 
162  void fix_negative_volumes(Mesh& mesh);
163 
164  void read_variable_header(std::map<std::string,Field>& fields);
165 
167 }; // end Reader
168 
170 
171 } // gmsh
172 } // mesh
173 } // cf3
174 
176 
177 #endif // cf3_mesh_Gmsh_Reader_hpp
std::string name(ComponentWrapper &self)
Handle< Mesh > m_mesh
Definition: Reader.hpp:82
std::vector< std::streampos > m_element_node_data_positions
Definition: Reader.hpp:115
std::streampos m_coordinates_position
Definition: Reader.hpp:111
Safe pointer to an object. This is the supported method for referring to components.
Definition: Handle.hpp:39
Handle< MergedParallelDistribution > m_hash
Definition: Reader.hpp:75
std::string var_type_gmsh_to_cf(const Uint &var_type_gmsh) const
Definition: Reader.hpp:143
std::set< Uint > element_types
Definition: Reader.hpp:93
virtual std::string get_format()
Definition: Reader.hpp:48
std::streampos m_region_names_position
Definition: Reader.hpp:110
#define gmsh_API
Definition: LibGmsh.hpp:22
std::string m_file_basename
Definition: Reader.hpp:85
boost::filesystem::fstream m_file
Definition: Reader.hpp:81
std::string description() const
Definition: Reader.hpp:132
std::map< Uint, std::pair< Handle< Elements >, Uint > > m_elem_idx_gmsh_to_cf
Definition: Reader.hpp:78
std::string interpolation_scheme
Definition: Reader.hpp:126
Handle< Region > m_region
Definition: Reader.hpp:83
std::vector< std::streampos > m_node_data_positions
Definition: Reader.hpp:114
Top-level namespace for coolfluid.
Definition: Action.cpp:18
static std::string type_name()
Gets the Class name.
Definition: Reader.hpp:46
std::vector< std::string > var_names
Definition: Reader.hpp:125
std::vector< std::streampos > m_element_data_positions
Definition: Reader.hpp:113
std::set< Uint > m_ghost_nodes
Definition: Reader.hpp:103
std::set< Uint > m_used_nodes
Definition: Reader.hpp:105
std::vector< URI > fields
unsigned int Uint
typedef for unsigned int
Definition: CF.hpp:90
std::vector< Uint > var_types
Definition: Reader.hpp:129
std::vector< std::vector< Uint > > m_nb_gmsh_elem_in_region
Definition: Reader.hpp:118
std::vector< RegionData > m_region_list
Definition: Reader.hpp:101
std::map< Uint, Uint > m_node_idx_gmsh_to_cf
Definition: Reader.hpp:79
std::vector< std::set< Uint > > m_node_to_glb_elements
Definition: Reader.hpp:107
std::streampos m_elements_position
Definition: Reader.hpp:112
std::vector< std::streampos > file_data_positions
Definition: Reader.hpp:131
#define FromHere()
Send comments to:
COOLFluiD Web Admin