1 // Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library 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.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File : DriverMesh.cxx
24 // Author : Yoann AUDOUIN, EDF
28 #include "DriverMesh.hxx"
30 #include "SMESH_Mesh.hxx"
31 #include "SMESH_Gen.hxx"
33 #include <MEDFileMesh.hxx>
34 #include <MEDCouplingUMesh.hxx>
36 using namespace MEDCoupling;
39 * @brief Compares the mesh from two mesh files (MED)
41 * @param mesh_file1 First file
42 * @param mesh_file2 Second file
43 * @param mesh_name Name of the mesh in the files
45 * @return true if the mesh within the files are identical
47 bool diff_med_file(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){
48 MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name);
49 MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name);
50 MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false);
51 MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false);
52 return m0_1->isEqual(m0_2, 1e-12);
56 * @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object
58 * @param mesh_file the file
59 * @param aMesh the object
60 * @param mesh_name the name of the mesh in the file
64 int import_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
65 // TODO: change that as it depends on the language
66 std::cout << "Importing mesh from " << mesh_file << std::endl;
67 int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
72 * @brief Export the content of a SMESH_Mesh into a mesh file (MED)
74 * @param mesh_file the file
75 * @param aMesh the object
76 * @param mesh_name name of the mesh in the file
80 int export_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
82 // TODO: See how to get the name of the mesh. Is it usefull ?
83 std::cout << "Exporting mesh to " << mesh_file << std::endl;
84 aMesh.ExportMED(mesh_file.c_str(), // theFile
85 mesh_name.c_str(), // theMeshName
86 false, // theAutoGroups
88 nullptr, // theMeshPart
89 true, // theAutoDimension
90 true, // theAddODOnVertices
91 1e-8, // theZTolerance
92 true // theSaveNumbers