Integration of run_mesher code

This commit is contained in:
Yoann Audouin 2022-08-31 16:06:31 +02:00
parent 402520f8f1
commit 26a2a23639
5 changed files with 312 additions and 0 deletions

View File

@ -92,6 +92,7 @@ SET(SMESHimpl_HEADERS
SMESH_Homard.hxx
ctpl.h
DriverMesh.hxx
DriverStep.hxx
)
# --- sources ---
@ -113,6 +114,7 @@ SET(SMESHimpl_SOURCES
MG_ADAPT.cxx
SMESH_Homard.cxx
DriverMesh.cxx
DriverStep.cxx
)
# --- rules ---

95
src/SMESH/DriverMesh.cxx Normal file
View File

@ -0,0 +1,95 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : DriverMesh.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "DriverMesh.hxx"
#include "SMESH_Mesh.hxx"
#include "SMESH_Gen.hxx"
#include <MEDFileMesh.hxx>
#include <MEDCouplingUMesh.hxx>
using namespace MEDCoupling;
/**
* @brief Compares the mesh from two mesh files (MED)
*
* @param mesh_file1 First file
* @param mesh_file2 Second file
* @param mesh_name Name of the mesh in the files
*
* @return true if the mesh within the files are identical
*/
bool diff_med_file(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){
MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name);
MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name);
MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false);
MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false);
return m0_1->isEqual(m0_2, 1e-12);
}
/**
* @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object
*
* @param mesh_file the file
* @param aMesh the object
* @param mesh_name the name of the mesh in the file
*
* @return error code
*/
int import_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
// TODO: change that as it depends on the language
std::cout << "Importing mesh from " << mesh_file << std::endl;
int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
return ret;
}
/**
* @brief Export the content of a SMESH_Mesh into a mesh file (MED)
*
* @param mesh_file the file
* @param aMesh the object
* @param mesh_name name of the mesh in the file
*
* @return error code
*/
int export_mesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
// TODO: See how to get the name of the mesh. Is it usefull ?
std::cout << "Exporting mesh to " << mesh_file << std::endl;
aMesh.ExportMED(mesh_file.c_str(), // theFile
mesh_name.c_str(), // theMeshName
false, // theAutoGroups
-1, // theVersion
nullptr, // theMeshPart
true, // theAutoDimension
true, // theAddODOnVertices
1e-8, // theZTolerance
true // theSaveNumbers
);
return true;
}

46
src/SMESH/DriverMesh.hxx Normal file
View File

@ -0,0 +1,46 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : DriverMesh.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#ifndef _DRIVERMESH_HXX_
#define _DRIVERMESH_HXX_
#include <string>
#include <cassert>
class SMESH_Mesh;
bool diff_med_file(const std::string mesh_file1,
const std::string mesh_file2,
const std::string mesh_name);
int import_mesh(const std::string mesh_file,
SMESH_Mesh& aMesh,
const std::string meshName);
int export_mesh(const std::string mesh_file,
SMESH_Mesh& aMesh,
const std::string meshName);
#endif

128
src/SMESH/DriverStep.cxx Normal file
View File

@ -0,0 +1,128 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : DriverStep.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "DriverStep.hxx"
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <Interface_Static.hxx>
//Occ include
#include <TopoDS.hxx>
/**
* @brief Compares two shape file (STEP)
*
* @param file1 first file
* @param file2 second file
*
* @return true if the files are the same
*/
bool diff_step_file(std::string file1, std::string file2){
std::ifstream sfile1(file1);
std::ifstream sfile2(file2);
std::string line1, line2;
int nb_lines = 0;
while(!sfile1.eof() && !sfile2.eof()){
std::getline(sfile1, line1);
std::getline(sfile2, line2);
nb_lines++;
// Skipping 4th line contain date of creation
if (nb_lines==4){
std::cout << "Skipping line" << std::endl;
continue;
}
// if lines are different end of read
if(line1 != line2){
return false;
}
}
// True if we reached the end of both files
return sfile1.eof() && sfile2.eof();
}
/**
* @brief Import the content of a shape file (STEP) into a TopDS_Shape object
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int import_shape(const std::string shape_file, TopoDS_Shape& aShape){
std::cout << "Importing shape from " << shape_file << std::endl;
STEPControl_Reader reader;
// Forcing Unit in meter
Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetIVal("read.step.ideas", 1);
Interface_Static::SetIVal("read.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
if(aStat != IFSelect_RetDone)
std::cout << "Reading error for " << shape_file << std::endl;
int NbTrans = reader.TransferRoots();
// There should be only one shape within the file
assert(NbTrans==1);
aShape = reader.OneShape();
return true;
}
/**
* @brief Export the content of a TopoDS_Shape into a shape file (STEP)
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int export_shape(const std::string shape_file, const TopoDS_Shape& aShape){
std::cout << "Exporting shape to " << shape_file << std::endl;
STEPControl_Writer aWriter;
// Forcing Unit in meter
Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetCVal("write.step.unit","M");
Interface_Static::SetIVal("write.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
if(aStat != IFSelect_RetDone)
std::cout << "Transfer error for " << shape_file << std::endl;
aStat = aWriter.Write(shape_file.c_str());
if(aStat != IFSelect_RetDone)
std::cout << "Writing error for " << shape_file << std::endl;
return aStat;
}

41
src/SMESH/DriverStep.hxx Normal file
View File

@ -0,0 +1,41 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
//
// This library 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 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : DriverStep.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#ifndef _DRIVERSTEP_HXX_
#define _DRIVERSTEP_HXX_
#include <string>
#include <cassert>
class TopoDS_Shape;
int import_shape(const std::string shape_file, TopoDS_Shape& aShape);
int export_shape(const std::string shape_file, const TopoDS_Shape& aShape);
bool diff_step_file(std::string file1, std::string file2);
#endif