getfem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Getfem-commits] r4997 - in /trunk/getfem/src: getfem/getfem_import.h ge


From: andriy . andreykiv
Subject: [Getfem-commits] r4997 - in /trunk/getfem/src: getfem/getfem_import.h getfem_import.cc
Date: Thu, 21 May 2015 12:02:07 -0000

Author: andrico
Date: Thu May 21 14:02:07 2015
New Revision: 4997

URL: http://svn.gna.org/viewcvs/getfem?rev=4997&view=rev
Log:
Allow the user to decide whether or not to keep the last dimension in GMSH 
meshes

Modified:
    trunk/getfem/src/getfem/getfem_import.h
    trunk/getfem/src/getfem_import.cc

Modified: trunk/getfem/src/getfem/getfem_import.h
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem/getfem_import.h?rev=4997&r1=4996&r2=4997&view=diff
==============================================================================
--- trunk/getfem/src/getfem/getfem_import.h     (original)
+++ trunk/getfem/src/getfem/getfem_import.h     Thu May 21 14:02:07 2015
@@ -100,9 +100,9 @@
   void import_mesh(const std::string& filename, mesh& m);
 
   /** Import a mesh file in format generated by Gmsh.
-    
+
       The function works exactly like impot_mesh() functions
-      except that they return additional mapping of physical 
+      except that they return additional mapping of physical
       region names to their numbers.
 
       The example below shows how to print region names
@@ -114,36 +114,39 @@
         RegMap regmap;
         getfem::import_mesh_gmsh("mesh.msh", myMesh, regmap);
         std::cout << regmap.size() << "\n";
-        for (RegMapIter i=regmap.begin(); i != regmap.end(); i++) { 
+        for (RegMapIter i=regmap.begin(); i != regmap.end(); i++) {
            std::cout << i->first << " " << i->second << "\n";
         }
       @endcode
 
       Additionally, optional face_region_range pair will define a range
       of regions that faces that need to be imported explicitly as convexes.
-      
+
       add_all_element_type flag, if set to true, will import all the lower
       dimension elements defined as independent convexes, only if the elements
       are not face of another convex. Thus, a 3D model can have a mixture of
       3D solid, 2D plates and 1D rod elements. This feature is still yet to
       be tested.
   */
-  void import_mesh_gmsh(const std::string& filename, mesh& m, 
-                   std::map<std::string, bgeot::size_type> &region_map);
-  void import_mesh_gmsh(std::istream& f, mesh& m, 
-                   std::map<std::string, bgeot::size_type> &region_map);
+  void import_mesh_gmsh(const std::string& filename, mesh& m,
+                   std::map<std::string, bgeot::size_type> &region_map,
+                   bool remove_last_dimension = true);
+
+  void import_mesh_gmsh(std::istream& f, mesh& m,
+                   std::map<std::string, bgeot::size_type> &region_map,
+                   bool remove_last_dimension = true);
 
   void import_mesh_gmsh(const std::string& filename, mesh& m,
                         bool add_all_element_type = false,
                         std::pair<bgeot::size_type, bgeot::size_type> 
*face_region_range = NULL,
-                        std::map<std::string, bgeot::size_type> *region_map = 
NULL);
+                        std::map<std::string, bgeot::size_type> *region_map = 
NULL,
+                        bool remove_last_dimension = true);
 
   void import_mesh_gmsh(std::istream& f, mesh& m,
                         bool add_all_element_type = false,
                         std::pair<bgeot::size_type, bgeot::size_type> 
*face_region_range = NULL,
-                        std::map<std::string, bgeot::size_type> *region_map = 
NULL);
-
-
+                        std::map<std::string, bgeot::size_type> *region_map = 
NULL,
+                        bool remove_last_dimension = true);
 
   /** for gmsh and gid meshes, the mesh nodes are always 3D, so for a 2D mesh
       the z-component of nodes should be removed */

Modified: trunk/getfem/src/getfem_import.cc
URL: 
http://svn.gna.org/viewcvs/getfem/trunk/getfem/src/getfem_import.cc?rev=4997&r1=4996&r2=4997&view=diff
==============================================================================
--- trunk/getfem/src/getfem_import.cc   (original)
+++ trunk/getfem/src/getfem_import.cc   Thu May 21 14:02:07 2015
@@ -1,9 +1,9 @@
 /*===========================================================================
- 
+
  Copyright (C) 2000-2012 Julien Pommier
- 
+
  This file is a part of GETFEM++
- 
+
  Getfem++  is  free software;  you  can  redistribute  it  and/or modify it
  under  the  terms  of the  GNU  Lesser General Public License as published
  by  the  Free Software Foundation;  either version 3 of the License,  or
@@ -16,7 +16,7 @@
  You  should  have received a copy of the GNU Lesser General Public License
  along  with  this program;  if not, write to the Free Software Foundation,
  Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.
- 
+
 ===========================================================================*/
 
 #include <iostream>
@@ -141,7 +141,7 @@
 
     bool operator<(const gmsh_cv_info& other) const {
       unsigned this_dim = (type == 15) ? 0 : pgt->dim();
-      unsigned other_dim = (other.type == 15) ? 0 : other.pgt->dim();      
+      unsigned other_dim = (other.type == 15) ? 0 : other.pgt->dim();
       return this_dim > other_dim;
     }
   };
@@ -162,11 +162,15 @@
      If add_all_element_type is set to true, convexes with less dimension
      than highest dimension pgt and are not part of other element's face will
      be imported as independent convexes.
+
+     for gmsh and gid meshes, the mesh nodes are always 3D, so for a 2D mesh
+     if remove_last_dimension == true the z-component of nodes will be removed
   */
   static void import_gmsh_mesh_file(std::istream& f, mesh& m, int deprecate=0,
                                     std::map<std::string, size_type> 
*region_map=NULL,
                                     std::pair<size_type, size_type> 
*face_region_range=NULL,
-                                    bool add_all_element_type = false)
+                                    bool add_all_element_type = false,
+                                    bool remove_last_dimension = true)
   {
     gmm::stream_standard_locale sl(f);
     /* print general warning */
@@ -212,7 +216,7 @@
           if (pos != region_name.npos) {
             region_name.erase(0, pos+1);
             pos = region_name.find_last_of("\"");
-            region_name.erase(pos); 
+            region_name.erase(pos);
           }
           (*region_map)[region_name] = ri;
         }
@@ -298,13 +302,13 @@
       case 3 : std::swap(ci.nodes[2], ci.nodes[3]); break;
       case 5 : { /* First order hexaedron */
         std::vector<size_type> tmp_nodes(8);
-        tmp_nodes[0] = ci.nodes[0]; 
+        tmp_nodes[0] = ci.nodes[0];
         tmp_nodes[1] = ci.nodes[1];
-        tmp_nodes[2] = ci.nodes[3]; 
+        tmp_nodes[2] = ci.nodes[3];
         tmp_nodes[3] = ci.nodes[2];
-        tmp_nodes[4] = ci.nodes[4]; 
+        tmp_nodes[4] = ci.nodes[4];
         tmp_nodes[5] = ci.nodes[5];
-        tmp_nodes[6] = ci.nodes[7]; 
+        tmp_nodes[6] = ci.nodes[7];
         tmp_nodes[7] = ci.nodes[6];
         ci.nodes[0] = tmp_nodes[0], ci.nodes[1] = tmp_nodes[1],
           ci.nodes[2] = tmp_nodes[2];
@@ -398,7 +402,7 @@
         GMM_WARNING2("Only nodes defined in the mesh! No convexes are added.");
         return;
       }
-      
+
       unsigned N = cvlst.front().pgt->dim();
       for (size_type cv=0; cv < nb_cv; ++cv) {
         bool cvok = false;
@@ -410,7 +414,7 @@
 
         //main convex import
         if (ci_dim == N) {
-          size_type ic = m.add_convex(ci.pgt, ci.nodes.begin()); 
+          size_type ic = m.add_convex(ci.pgt, ci.nodes.begin());
           cvok = true;
           m.region(ci.region).add(ic);
 
@@ -464,7 +468,7 @@
         }
       }
     }
-    maybe_remove_last_dimension(m);
+    if (remove_last_dimension) maybe_remove_last_dimension(m);
   }
 
   /* mesh file from GiD [http://gid.cimne.upc.es/]
@@ -724,7 +728,7 @@
       sscanf(line.c_str(), node_info_fmt.c_str(), &nodeid, &pt[0], &pt[1], 
&pt[2]);
       cdb_node_2_getfem_node[nodeid] = m.add_point(pt);
     }
-    
+
     while (bgeot::casecmp(line.substr(0,6),"EBLOCK") != 0) {
       if (f.eof())
         return;
@@ -977,73 +981,71 @@
 
   /* mesh file from noboite [http://www.distene.com/fr/corp/newsroom16.html] */
   static void import_noboite_mesh_file(std::istream& f, mesh& m) {
-    
+
     using namespace std;
     gmm::stream_standard_locale sl(f);
-    
+
     ofstream fichier_GiD("noboite_to_GiD.gid",    ios::out | ios::trunc );  
//déclaration du flux et ouverture du fichier
-    
+
     fichier_GiD << "MESH    dimension 3 ElemType Tetrahedra  Nnode 4"<<endl;
-    
-    
+
+
     int i,NE,NP,ligne_debut_NP;
-    
+
     /*NE: nombre d'elements (premier nombre du fichier .noboite)
       NP: nombre de points (deuxieme nombre du fichier .noboite)
       ligne_debut_NP: la ligne commence la liste des coordonnees des points 
dans le            fichier .noboite*/
-    
+
     f >> NE>>NP;
     ligne_debut_NP=NE*4/6+3;
-    
+
     //passer 3 premiers lignes du fichier .noboite (la liste des elements 
commence a la                quatrieme ligne)
     string contenu;
     for (i=1; i<=ligne_debut_NP; i++){
       getline(f, contenu);
     }
-    
+
 
     /*-----------------------------------------------------------------------
       Lire les coordonnees dans .noboite
       -----------------------------------------------------------------------*/
     fichier_GiD << "Coordinates" <<endl;
-    
+
     for (i=1; i<=NP; i++){
       float coor_x,coor_y,coor_z;
-      
+
       fichier_GiD << i<<" ";
-      
+
       f>>coor_x >>coor_y >>coor_z;
       fichier_GiD<<coor_x<<" " <<coor_y <<" "<<coor_z <<endl;
-      
-    }
-    
+
+    }
+
     fichier_GiD << "end coordinates" <<endl<<endl;
-    
+
     /*-----------------------------------------------------------------------
       Lire les elements dans .noboite et ecrire au . gid
       
------------------------------------------------------------------------*/
-    
+
     //revenir au debut du fichier . noboite, puis passer les trois premiere 
lignes
     f.seekg(0, ios::beg);
     for (i=1; i<=3; i++){
       getline(f, contenu);
     }
-    
-    
+
+
     fichier_GiD << "Elements" <<endl;
-    
+
     for (i=1; i<=NE; i++){
       float elem_1,elem_2,elem_3,elem_4;
-      
+
       fichier_GiD << i<<" ";
       f>>elem_1>>elem_2>>elem_3>>elem_4;
       fichier_GiD<<elem_1<<" " <<elem_2 <<" "<<elem_3<<" "<<elem_4<<" 1"<<endl;
-      
+
     }
     fichier_GiD << "end elements" <<endl<<endl;
-    
-    
-    
+
     if(fichier_GiD)  // si l'ouverture a réussi
       {
        // instructions
@@ -1051,7 +1053,7 @@
       }
     else  // sinon
       cerr << "Erreur à l'ouverture !" << endl;
-    
+
     if(f)  // si l'ouverture a réussi
       {
        // instructions
@@ -1059,15 +1061,15 @@
       }
     else  // sinon
       cerr << "Erreur à l'ouverture !" << endl;
-    
+
     // appeler sunroutine import_gid_mesh_file
     //import_mesh(const std::string& "noboite_to_GiD.gid", mesh& msh)
     ifstream fichier1_GiD("noboite_to_GiD.gid", ios::in);
     import_gid_mesh_file(fichier1_GiD, m);
-    
+
     //      return 0;
   }
-  
+
   /* mesh file from emc2 
[http://pauillac.inria.fr/cdrom/prog/unix/emc2/eng.htm], am_fmt format
 
   (only triangular 2D meshes)
@@ -1159,28 +1161,34 @@
   }
 
   void import_mesh_gmsh(std::istream& f, mesh &m,
-                  std::map<std::string, size_type> &region_map) {
-    import_gmsh_mesh_file(f,m, 0, &region_map);
+                  std::map<std::string, size_type> &region_map,
+                   bool remove_last_dimension)
+  {
+    import_gmsh_mesh_file(f, m, 0, &region_map, nullptr, false, 
remove_last_dimension);
   }
 
   void import_mesh_gmsh(std::istream& f, mesh& m,
                         bool add_all_element_type,
                         std::pair<size_type, size_type> *face_region_range,
-                        std::map<std::string, size_type> *region_map) {
-    import_gmsh_mesh_file(f, m, 0, region_map, face_region_range, 
add_all_element_type);
+                        std::map<std::string, size_type> *region_map,
+                   bool remove_last_dimension)
+  {
+    import_gmsh_mesh_file(f, m, 0, region_map, face_region_range, 
add_all_element_type, remove_last_dimension);
   }
 
   void import_mesh_gmsh(const std::string& filename, mesh& m,
                         bool add_all_element_type,
                         std::pair<size_type, size_type> *face_region_range,
-                        std::map<std::string, size_type> *region_map){
+                        std::map<std::string, size_type> *region_map,
+                        bool remove_last_dimension)
+  {
     m.clear();
     try {
       std::ifstream f(filename.c_str());
       GMM_ASSERT1(f.good(), "can't open file " << filename);
       /* throw exceptions when an error occurs */
       f.exceptions(std::ifstream::badbit | std::ifstream::failbit);
-      import_gmsh_mesh_file(f, m, 0, region_map, face_region_range, 
add_all_element_type);
+      import_gmsh_mesh_file(f, m, 0, region_map, face_region_range, 
add_all_element_type, remove_last_dimension);
       f.close();
     }
     catch (failure_error& exc) {
@@ -1195,10 +1203,11 @@
   }
 
   void import_mesh_gmsh(const std::string& filename,
-    mesh& m, std::map<std::string, size_type> &region_map) {
-    import_mesh_gmsh(filename, m, false, NULL, &region_map);
-  }
-                                                     
+    mesh& m, std::map<std::string, size_type> &region_map,
+    bool remove_last_dimension) {
+    import_mesh_gmsh(filename, m, false, NULL, &region_map, 
remove_last_dimension);
+  }
+
   void import_mesh(std::istream& f, const std::string& format,
                    mesh& m) {
     if (bgeot::casecmp(format,"gmsh")==0)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]