LifeV
Importer.hpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
5  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
6  This file is part of LifeV.
7  LifeV is free software; you can redistribute it and/or modify
8  it under the terms of the GNU Lesser General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11  LifeV is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15  You should have received a copy of the GNU Lesser General Public License
16  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
17 *******************************************************************************
18 */
19 //@HEADER
20 /*!
21  * @file
22  * @brief Import mesh data formats into LifeV mesh data structure.
23  *
24  *
25  * @date 06-11-2004
26  *
27  * @author Christophe Prud'homme <christophe.prudhomme@epfl.ch>
28  *
29  *
30  * @contributor Alessio Fumagalli <alessio.fumagalli@mail.polimi.it>
31  *
32  * @mantainer Alessio Fumagalli <alessio.fumagalli@mail.polimi.it>
33  *
34  */
35 
36 #ifndef _IMPORTER_H
37 #define _IMPORTER_H 1
38 
39 #include <lifev/core/mesh/RegionMesh.hpp>
40 
41 namespace LifeV
42 {
43 
44 /*! @enum MeshFormat
45  List of reading mesh format.
46 */
48 {
49  MESHPP, /*!< Meshpp type mesh */
50  INRIA, /*!< INRIA type mesh */
51  GMSH, /*!< Gmsh type mesh */
52  NETGEN, /*!< NetGen type mesh */
53  FREEFEM /*!< FreeFem type mesh */
54 };
55 
56 namespace detail
57 {
58 
59 // Import function for 3D mesh
60 template<typename Elt>
61 void
62 import3D ( std::string const& fileName,
63  MeshFormat const& format,
64  RegionMesh<Elt>& mesh,
65  markerID_Type regionFlag )
66 {
67  // Select the right mesh format
68  switch ( format )
69  {
70  case MESHPP:
71  readMppFile ( mesh, fileName, regionFlag );
72  break;
73 
74  case INRIA:
75  readINRIAMeshFile ( mesh, fileName, regionFlag );
76  break;
77 
78  case GMSH:
79  readGmshFile ( mesh, fileName, regionFlag );
80  break;
81 
82  case NETGEN:
83  readNetgenMesh ( mesh, fileName, regionFlag );
84  break;
85  default:
86  {
87  std::ostringstream ostr;
88  ostr << "Unsupported 2D file format";
89  throw std::invalid_argument ( ostr.str() );
90  }
91  }
92 } // import
93 
94 //Import function for 2D mesh
95 template<typename Elt>
96 void
97 import2D ( std::string const& fileName,
98  MeshFormat const& format,
99  RegionMesh<Elt>& mesh,
100  markerID_Type regionFlag )
101 {
102  // Select the right mesh format, only Gmsh allowed
103  switch ( format )
104  {
105  case FREEFEM:
106  readFreeFemFile ( mesh, fileName, regionFlag );
107  break;
108  default:
109  {
110  std::ostringstream ostr;
111  ostr << "Unsupported 2D file format";
112  throw std::invalid_argument ( ostr.str() );
113  }
114  }
115 } // import
116 
117 } // Namespace detail
118 
119 //! Importer General interface for read different types of mesh.
120 /*!
121  @author Christophe Prud'homme <christophe.prudhomme@epfl.ch>
122 
123  Import different type of mesh data formats into Life mesh data structure.
124 
125 */
126 class Importer
127 {
128 public:
129 
130  //! @name Constructor & Destructor
131  //@{
132 
133  //! Empty constructor, use GMSH as default mesh format
135  M_fileName ( ),
136  M_format ( GMSH )
137  {}
138 
139  //! Constructor with name and format
140  /*!
141  @param filename mesh filename to import
142  @param format format of the file
143  */
144  Importer ( std::string const& fileName, MeshFormat const& format ) :
145  M_fileName ( fileName ),
146  M_format ( format )
147  {}
148 
149  //! Copy constructor
150  /*!
151  @param import Importer object to be copied
152  */
153  Importer ( const Importer& importer ) :
154  M_fileName ( importer.M_fileName ),
155  M_format ( importer.M_format )
156  {}
157 
158  //@}
159 
160  //! @name Operators
161  //@{
162 
163  //! Assign opertor overloading
164  /*!
165  @param import Importer object to be copied
166  */
167  Importer& operator= ( const Importer& importer );
168 
169  //@}
170 
171  //! @name Methods
172  //@{
173 
174  //! Import mesh with tetrahedras
175  /*!
176  @param mesh mesh data structure to fill in
177  @param regionFlag marker for the region to load
178  */
179  void import ( RegionMesh<LinearTetra>& mesh, markerID_Type regionFlag );
180 
181 
182  //! Import mesh with linear hexahedras
183  /*!
184  @param mesh mesh data structure to fill in
185  @param regionFlag marker for the region to load
186  */
187  void import ( RegionMesh<LinearHexa>& mesh, markerID_Type regionFlag );
188 
189  //! Import mesh with linear triangles
190  /*!
191  @param mesh mesh data structure to fill in
192  @param regionFlag marker for the region to load
193  */
194  void import ( RegionMesh<LinearTriangle>& mesh, markerID_Type regionFlag );
195 
196 
197  //! Import mesh with linear quadrangles
198  /*!
199  @param mesh mesh data structure to fill in
200  @param regionFlag marker for the region to load
201  */
202  void import ( RegionMesh<LinearQuad>& mesh, markerID_Type regionFlag );
203 
204  //! Print attributes of the class
205  /*!
206  @param output Stream to put the output
207  */
208  void showMe ( std::ostream& output = std::cout ) const;
209 
210  //@}
211 
212  //! @name Set Methods
213  //@{
214 
215  //! Set the file name
216  /*!
217  @param fileName of the mesh file
218  */
219  inline void setFileName ( std::string const& fileName )
220  {
221  M_fileName = fileName;
222  }
223 
224  //! Set the format of the mesh file
225  /*!
226  @param format format of the mesh file
227  */
228  inline void setFormat ( MeshFormat const& format )
229  {
230  M_format = format;
231  }
232 
233  //@}
234 
235 private:
236 
237  //! Name of the file to import
238  std::string M_fileName;
239 
240  //! Format of the file to import
242 };
243 
244 } // Namespace LifeV
245 
246 #endif /* _IMPORTER_H */
Importer(const Importer &importer)
Copy constructor.
Definition: Importer.hpp:153
void showMe(std::ostream &output=std::cout) const
Print attributes of the class.
Definition: Importer.cpp:99
Importer(std::string const &fileName, MeshFormat const &format)
Constructor with name and format.
Definition: Importer.hpp:144
Importer General interface for read different types of mesh.
Definition: Importer.hpp:126
Importer()
Empty constructor, use GMSH as default mesh format.
Definition: Importer.hpp:134
ID markerID_Type
markerID_Type is the type used to store the geometric entity marker IDs
Definition: Marker.hpp:81
Importer & operator=(const Importer &importer)
Assign opertor overloading.
Definition: Importer.cpp:50
MeshFormat
Definition: Importer.hpp:47
std::string M_fileName
Name of the file to import.
Definition: Importer.hpp:238
void import(RegionMesh< LinearQuad > &mesh, markerID_Type regionFlag)
Import mesh with linear quadrangles.
Definition: Importer.cpp:92
void import2D(std::string const &fileName, MeshFormat const &format, RegionMesh< Elt > &mesh, markerID_Type regionFlag)
Definition: Importer.hpp:97
void import3D(std::string const &fileName, MeshFormat const &format, RegionMesh< Elt > &mesh, markerID_Type regionFlag)
Definition: Importer.hpp:62
void setFileName(std::string const &fileName)
Set the file name.
Definition: Importer.hpp:219
void setFormat(MeshFormat const &format)
Set the format of the mesh file.
Definition: Importer.hpp:228
MeshFormat M_format
Format of the file to import.
Definition: Importer.hpp:241