GetFEM  5.4.2
getfem_import.h
Go to the documentation of this file.
1 /* -*- c++ -*- (enables emacs c++ mode) */
2 /*===========================================================================
3 
4  Copyright (C) 2000-2020 Julien Pommier
5 
6  This file is a part of GetFEM
7 
8  GetFEM is free software; you can redistribute it and/or modify it
9  under the terms of the GNU Lesser General Public License as published
10  by the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version along with the GCC Runtime Library
12  Exception either version 3.1 or (at your option) any later version.
13  This program is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  License and GCC Runtime Library Exception for more details.
17  You should have received a copy of the GNU Lesser General Public License
18  along with this program; if not, write to the Free Software Foundation,
19  Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 
21  As a special exception, you may use this file as it is a part of a free
22  software library without restriction. Specifically, if other files
23  instantiate templates or use macros or inline functions from this file,
24  or you compile this file and link it with other files to produce an
25  executable, this file does not by itself cause the resulting executable
26  to be covered by the GNU Lesser General Public License. This exception
27  does not however invalidate any other reasons why the executable file
28  might be covered by the GNU Lesser General Public License.
29 
30 ===========================================================================*/
31 
32 /**@file getfem_import.h
33  @author Julien Pommier <Julien.Pommier@insa-toulouse.fr>
34  @date Januar 17, 2003.
35  @brief Import mesh files from various formats.
36 */
37 
38 #ifndef GETFEM_IMPORT_H__
39 #define GETFEM_IMPORT_H__
40 
41 #include <string>
42 #include <iostream>
43 #include <map>
44 #include <set>
45 #include "bgeot_config.h" /* for bgeot::size_type */
46 
47 namespace getfem {
48  using bgeot::size_type;
49  class mesh;
50 
51  /** imports a mesh file.
52  format can be:
53 
54  - "gid" for meshes generated by GiD http://gid.cimne.upc.es/
55  -- mesh nodes are always 3D
56 
57 
58  - "gmsh" for meshes generated by Gmsh http://www.geuz.org/gmsh/
59  IMPORTANT NOTE: if you do not assign a physical surface/volume
60  to your 3D mesh, the file will also contain the mesh of the
61  boundary (2D elements) and the boundary of the boundary (line
62  elements!).
63 
64  GetFEM makes use of the physical "region" number stored with
65  each element in the gmsh file to fill the corresponding region
66  of the mesh object.
67 
68  For a mesh of dimension N, getfem builds a mesh with the
69  convexes listed in the gmsh file whose dimension are N, the
70  convexes of dim N-1 are used to tag "region" of faces,
71  according to their gmsh "physical region number" (physical
72  region number 'n' is mapped to the getfem region), and
73  the convexes of lower dimension are ignored.
74 
75  All regions must have different number! This means that the
76  parametrization of the mesh in Gmsh .geo file must assign a
77  different number to each region, the problem exists because in
78  Gmsh can coexist, for example, "Physical Surface (200)" and
79  "Physical Line (200)", as they are different "types of regions"
80  in Gmsh, that which does not occur in GetFEM since there is
81  only one "type of region".
82 
83 
84  - "cdb" for meshes generated by ANSYS (in blocked format).
85 
86  Currently, plane and solid elements of types 42,45,73,82,87,89,
87  90,92,95,162,182,183,185,186,187 and 191 are supported.
88  This however does not include any finite element techology linked
89  to these elements but only their geometry.
90 
91  By default GetFEM will define mesh regions corresponding to
92  material ids found in the imported cdb file, if there are more
93  than one material ids available.
94 
95  Using "cdb:N" as format specifier, only elements with material
96  id equal to an integer N will be imported.
97 
98  The recommended ANSYS command for generating a mesh file is:
99 
100  cdwrite,db,filename,cdb
101 
102 
103  - "am_fmt" for 2D meshes from emc2
104  [http://pauillac.inria.fr/cdrom/prog/unix/emc2/eng.htm]
105 
106  */
107  void import_mesh(const std::string& filename, const std::string& format,
108  mesh& m);
109  void import_mesh(std::istream& f, const std::string& format,
110  mesh& m);
111  void import_mesh(const std::string& filename, mesh& m);
112 
113  /** Import a mesh file in format generated by Gmsh.
114 
115  The function works exactly like impot_mesh() functions
116  except that they return additional mapping of physical
117  region names to their numbers.
118 
119  The example below shows how to print region names
120  and their numbers:
121  @code
122  getfem::mesh myMesh;
123  typedef std::map<std::string, size_type> RegMap;
124  typedef RegMap::iterator RegMapIter;
125  RegMap regmap;
126  getfem::import_mesh_gmsh("mesh.msh", myMesh, regmap);
127  std::cout << regmap.size() << "\n";
128  for (RegMapIter i=regmap.begin(); i != regmap.end(); i++) {
129  std::cout << i->first << " " << i->second << "\n";
130  }
131  @endcode
132 
133  Additionally, the optional lower_dim_convex_rg defines a set
134  of face regions that need to be imported explicitly as convexes.
135 
136  add_all_element_type flag, if set to true, will import all the lower
137  dimension elements defined as independent convexes, only if the elements
138  are not face of another convex. Thus, a 3D model can have a mixture of
139  3D solid, 2D plates and 1D rod elements. This feature is still yet to
140  be tested.
141  */
142  void import_mesh_gmsh(const std::string& filename, mesh& m,
143  std::map<std::string, size_type> &region_map,
144  bool remove_last_dimension = true,
145  std::map<size_type, std::set<size_type>> *nodal_map = NULL,
146  bool remove_duplicated_nodes = true);
147 
148  void import_mesh_gmsh(std::istream& f, mesh& m,
149  std::map<std::string, size_type> &region_map,
150  bool remove_last_dimension = true,
151  std::map<size_type, std::set<size_type>> *nodal_map = NULL,
152  bool remove_duplicated_nodes = true);
153 
154  void import_mesh_gmsh(const std::string& filename, mesh& m,
155  bool add_all_element_type = false,
156  std::set<size_type> *lower_dim_convex_rg = NULL,
157  std::map<std::string, size_type> *region_map = NULL,
158  bool remove_last_dimension = true,
159  std::map<size_type, std::set<size_type>> *nodal_map = NULL,
160  bool remove_duplicated_nodes = true);
161 
162  void import_mesh_gmsh(std::istream& f, mesh& m,
163  bool add_all_element_type = false,
164  std::set<size_type> *lower_dim_convex_rg = NULL,
165  std::map<std::string, size_type> *region_map = NULL,
166  bool remove_last_dimension = true,
167  std::map<size_type, std::set<size_type>> *nodal_map = NULL,
168  bool remove_duplicated_nodes = true);
169 
170  /** for gmsh and gid meshes, the mesh nodes are always 3D, so for a 2D mesh
171  the z-component of nodes should be removed */
172  void maybe_remove_last_dimension(mesh &msh);
173 
174  /** for gmsh meshes, create table linking region name to region_id. */
175  std::map<std::string, size_type> read_region_names_from_gmsh_mesh_file(std::istream& f);
176 }
177 #endif /* GETFEM_IMPORT_H__ */
bgeot::size_type
size_t size_type
used as the common size type in the library
Definition: bgeot_poly.h:49
getfem
GEneric Tool for Finite Element Methods.
Definition: getfem_accumulated_distro.h:46
getfem::import_mesh_gmsh
void import_mesh_gmsh(const std::string &filename, mesh &m, std::map< std::string, size_type > &region_map, bool remove_last_dimension=true, std::map< size_type, std::set< size_type >> *nodal_map=NULL, bool remove_duplicated_nodes=true)
Import a mesh file in format generated by Gmsh.
Definition: getfem_import.cc:1531
getfem::read_region_names_from_gmsh_mesh_file
std::map< std::string, size_type > read_region_names_from_gmsh_mesh_file(std::istream &f)
for gmsh meshes, create table linking region name to region_id.
Definition: getfem_import.cc:179
getfem::import_mesh
void import_mesh(const std::string &filename, const std::string &format, mesh &m)
imports a mesh file.
Definition: getfem_import.cc:1442
bgeot_config.h
defines and typedefs for namespace bgeot
getfem::maybe_remove_last_dimension
void maybe_remove_last_dimension(mesh &msh)
for gmsh and gid meshes, the mesh nodes are always 3D, so for a 2D mesh the z-component of nodes shou...
Definition: getfem_import.cc:1587