1 // Copyright (C) 2007-2023 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 : SMESH_DriverMesh.cxx
24 // Author : Yoann AUDOUIN, EDF
28 #include "utilities.h"
30 #include "SMESH_DriverMesh.hxx"
32 #include "SMESH_Mesh.hxx"
33 #include "SMESH_Gen.hxx"
35 #include <MEDFileMesh.hxx>
36 #include <MEDCouplingUMesh.hxx>
38 using namespace MEDCoupling;
41 * @brief Compares the mesh from two mesh files (MED)
43 * @param mesh_file1 First file
44 * @param mesh_file2 Second file
45 * @param mesh_name Name of the mesh in the files
47 * @return true if the mesh within the files are identical
49 bool SMESH_DriverMesh::diffMEDFile(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){
50 MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name);
51 MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name);
52 MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false);
53 MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false);
54 return m0_1->isEqual(m0_2, 1e-12);
57 std::string getMeshName(std::string mesh_file){
58 // TODO: Memory leak but desctructor private check with AG
59 MEDFileUMesh * myMedMesh = MEDFileUMesh::New(mesh_file);
61 return myMedMesh->getLevel0Mesh()->getName();
65 * @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object
67 * @param mesh_file the file
68 * @param aMesh the object
69 * @param mesh_name the name of the mesh in the file
73 int SMESH_DriverMesh::importMesh(const std::string mesh_file, SMESH_Mesh& aMesh){
74 // TODO: change that as it depends on the language
75 std::string mesh_name = getMeshName(mesh_file);
76 MESSAGE("Importing mesh from " << mesh_file << " mesh " << mesh_name);
77 int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
82 * @brief Export the content of a SMESH_Mesh into a mesh file (MED)
84 * @param mesh_file the file
85 * @param aMesh the object
86 * @param mesh_name name of the mesh in the file
91 int SMESH_DriverMesh::exportMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
93 MESSAGE("Exporting mesh to " << mesh_file);
94 aMesh.ExportMED(mesh_file.c_str(), // theFile
95 mesh_name.c_str(), // theMeshName
96 false, // theAutoGroups
98 nullptr, // theMeshPart
99 true, // theAutoDimension
100 true, // theAddODOnVertices
101 1e-8, // theZTolerance
102 true // theSaveNumbers