Renaming functions and files + minor corrections in runner_main to detect what to do

This commit is contained in:
Yoann Audouin 2022-09-13 16:46:00 +02:00
parent 80e4ccd74d
commit 01afecee31
11 changed files with 212 additions and 496 deletions

View File

@ -93,9 +93,8 @@ SET(NETGENEngine_HEADERS
NETGENPlugin_Mesher.hxx
NETGENPlugin_Remesher_2D.hxx
NETGENPlugin_Defs.hxx
NETGENPlugin_Provider.hxx
netgen_param.hxx
netgen_mesher.hxx
NETGENPlugin_DriverParam.hxx
NETGENPlugin_Runner.hxx
)
# --- sources ---
@ -123,12 +122,12 @@ SET(NETGENEngine_SOURCES
NETGENPlugin_SimpleHypothesis_3D_i.cxx
NETGENPlugin_Remesher_2D.cxx
NETGENPlugin_i.cxx
netgen_mesher.cxx
netgen_param.cxx
NETGENPlugin_Runner.cxx
NETGENPlugin_DriverParam.cxx
)
SET(Run_Mesher_SOURCES
run_mesher.cxx
SET(NetgenRunner_SOURCES
NETGENPlugin_Runner_main.cxx
)
# --- scripts ---
@ -145,9 +144,9 @@ ADD_LIBRARY(NETGENEngine ${NETGENEngine_SOURCES})
TARGET_LINK_LIBRARIES(NETGENEngine ${_link_LIBRARIES} )
INSTALL(TARGETS NETGENEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
ADD_EXECUTABLE(run_mesher ${Run_Mesher_SOURCES})
TARGET_LINK_LIBRARIES(run_mesher ${_link_LIBRARIES} NETGENEngine )
INSTALL(TARGETS run_mesher EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS})
ADD_EXECUTABLE(NETGENPlugin_Runner ${NetgenRunner_SOURCES})
TARGET_LINK_LIBRARIES(NETGENPlugin_Runner ${_link_LIBRARIES} NETGENEngine )
INSTALL(TARGETS NETGENPlugin_Runner EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_BINS})
INSTALL(FILES ${NETGENEngine_HEADERS} DESTINATION ${SALOME_INSTALL_HEADERS})

View File

@ -20,11 +20,11 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : netgen_param.hxx
// File : NETGENPlugin_DriverParam.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
// Module : NETGEN
//
#include "netgen_param.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include <iostream>
#include <fstream>
@ -39,7 +39,7 @@
*
* @param aParams The object to display
*/
void print_netgen_params(netgen_params& aParams){
void printNetgenParams(netgen_params& aParams){
// TODO: prettier print
// TODO: Add call to print in log
std::cout << "has_netgen_param: " << aParams.has_netgen_param << std::endl;
@ -76,7 +76,7 @@ void print_netgen_params(netgen_params& aParams){
* @param param_file Name of the file
* @param aParams Structure to fill
*/
void import_netgen_params(const std::string param_file, netgen_params& aParams){
void importNetgenParams(const std::string param_file, netgen_params& aParams){
std::ifstream myfile(param_file);
std::string line;
@ -142,7 +142,7 @@ void import_netgen_params(const std::string param_file, netgen_params& aParams){
* @param param_file the file
* @param aParams the object
*/
void export_netgen_params(const std::string param_file, netgen_params& aParams){
void exportNetgenParams(const std::string param_file, netgen_params& aParams){
std::ofstream myfile(param_file);
myfile << aParams.has_netgen_param << std::endl;
myfile << aParams.maxh << std::endl;
@ -182,7 +182,7 @@ void export_netgen_params(const std::string param_file, netgen_params& aParams){
* @return true if the two object are identical
*/
bool diff_netgen_params(netgen_params params1, netgen_params params2){
bool diffNetgenParams(netgen_params params1, netgen_params params2){
bool ret = true;
ret &= params1.maxh == params2.maxh;
ret &= params1.minh == params2.minh;

View File

@ -20,13 +20,13 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : netgen_param.hxx
// File : NETGENPlugin_DriverParam.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
// Module : NETGEN
//
#ifndef _NETGEN_PARAM_HXX_
#define _NETGEN_PARAM_HXX_
#ifndef _NETGENPLUGIN_DRIVERPARAM_HXX_
#define _NETGENPLUGIN_DRIVERPARAM_HXX_
#include <string>
@ -86,11 +86,11 @@ struct netgen_params{
int nbThreads;
};
void print_netgen_params(netgen_params& aParams);
void printNetgenParams(netgen_params& aParams);
void import_netgen_params(const std::string param_file, netgen_params& aParams);
void export_netgen_params(const std::string param_file, netgen_params& aParams);
void importNetgenParams(const std::string param_file, netgen_params& aParams);
void exportNetgenParams(const std::string param_file, netgen_params& aParams);
bool diff_netgen_params(netgen_params params1, netgen_params params2);
bool diffNetgenParams(netgen_params params1, netgen_params params2);
#endif

View File

@ -1,4 +1,3 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
@ -25,8 +24,7 @@
#include "NETGENPlugin_Mesher.hxx"
#include "NETGENPlugin_Hypothesis_2D.hxx"
#include "NETGENPlugin_Provider.hxx"
#include "netgen_param.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include <SMDS_MeshElement.hxx>
#include <SMDS_MeshNode.hxx>
@ -41,8 +39,8 @@
#include <StdMeshers_MaxElementArea.hxx>
#include <StdMeshers_QuadranglePreference.hxx>
#include <StdMeshers_ViscousLayers2D.hxx>
#include "DriverStep.hxx"
#include "DriverMesh.hxx"
#include "SMESH_DriverStep.hxx"
#include "SMESH_DriverMesh.hxx"
#include <Precision.hxx>
@ -324,17 +322,17 @@ bool NETGENPlugin_NETGEN_2D_ONLY::RemoteCompute(SMESH_Mesh& aMesh,
fs::path output_mesh_file=tmp_folder / fs::path("output_mesh.med");
fs::path shape_file=tmp_folder / fs::path("shape.step");
fs::path param_file=tmp_folder / fs::path("netgen2d_param.txt");
fs::path log_file=tmp_folder / fs::path("run_mesher.log");
fs::path log_file=tmp_folder / fs::path("run.log");
//TODO: Handle variable mesh_name
std::string mesh_name = "Maillage_1";
//Writing Shape
export_shape(shape_file.string(), aShape);
exportShape(shape_file.string(), aShape);
//Writing hypo
netgen_params aParams;
FillParameters(_hypParameters, aParams);
export_netgen_params(param_file.string(), aParams);
exportNetgenParams(param_file.string(), aParams);
// Exporting element orientation
exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string());
@ -347,7 +345,7 @@ bool NETGENPlugin_NETGEN_2D_ONLY::RemoteCompute(SMESH_Mesh& aMesh,
fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/
fs::path("bin")/
fs::path("salome")/
fs::path("run_mesher");
fs::path("NETGENPlugin_Runner");
cmd = run_mesher_exe.string() +
" NETGEN2D " + mesh_file.string() + " "
+ shape_file.string() + " "

View File

@ -32,9 +32,7 @@
#include "NETGENPlugin_Hypothesis.hxx"
#include "DriverStep.hxx"
#include "DriverMesh.hxx"
#include "netgen_param.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include <SMDS_MeshElement.hxx>
#include <SMDS_MeshNode.hxx>
@ -50,6 +48,9 @@
#include <StdMeshers_QuadToTriaAdaptor.hxx>
#include <StdMeshers_ViscousLayers.hxx>
#include <SMESH_subMesh.hxx>
#include <SMESH_DriverStep.hxx>
#include <SMESH_DriverMesh.hxx>
#include <BRepGProp.hxx>
#include <BRep_Tool.hxx>
@ -196,7 +197,7 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh,
}
void NETGENPlugin_NETGEN_3D::FillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams)
void NETGENPlugin_NETGEN_3D::fillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams)
{
aParams.maxh = hyp->GetMaxSize();
aParams.minh = hyp->GetMinSize();
@ -315,21 +316,21 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
fs::path output_mesh_file=tmp_folder / fs::path("output_mesh.med");
fs::path shape_file=tmp_folder / fs::path("shape.step");
fs::path param_file=tmp_folder / fs::path("netgen3d_param.txt");
fs::path log_file=tmp_folder / fs::path("run_mesher.log");
fs::path log_file=tmp_folder / fs::path("run.log");
//TODO: Handle variable mesh_name
std::string mesh_name = "Maillage_1";
//Writing Shape
export_shape(shape_file.string(), aShape);
exportShape(shape_file.string(), aShape);
auto time2 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time2-time1);
std::cout << "Time for export_shape: " << elapsed.count() * 1e-9 << std::endl;
std::cout << "Time for exportShape: " << elapsed.count() * 1e-9 << std::endl;
//Writing hypo
netgen_params aParams;
FillParameters(_hypParameters, aParams);
fillParameters(_hypParameters, aParams);
export_netgen_params(param_file.string(), aParams);
exportNetgenParams(param_file.string(), aParams);
auto time3 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time3-time2);
std::cout << "Time for fill+export param: " << elapsed.count() * 1e-9 << std::endl;
@ -338,7 +339,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string());
auto time4 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time4-time3);
std::cout << "Time for exportElemnOrient: " << elapsed.count() * 1e-9 << std::endl;
std::cout << "Time for exportElemOrient: " << elapsed.count() * 1e-9 << std::endl;
aMesh.Unlock();
// Calling run_mesher
@ -348,7 +349,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/
fs::path("bin")/
fs::path("salome")/
fs::path("run_mesher");
fs::path("NETGENPlugin_Runner");
cmd = run_mesher_exe.string() +
" NETGEN3D " + mesh_file.string() + " "
+ shape_file.string() + " "
@ -356,8 +357,7 @@ int NETGENPlugin_NETGEN_3D::RemoteCompute(SMESH_Mesh& aMesh,
+ element_orientation_file.string() + " "
+ std::to_string(aMesh.GetMesherNbThreads()) + " "
+ new_element_file.string() + " "
+ std::to_string(0) + " "
+ output_mesh_file.string() +
+ "NONE" +
" >> " + log_file.string();
//std::cout << "Running command: " << std::endl;

View File

@ -31,7 +31,6 @@
#ifndef _NETGENPlugin_NETGEN_3D_HXX_
#define _NETGENPlugin_NETGEN_3D_HXX_
#include "NETGENPlugin_Provider.hxx"
#include "NETGENPlugin_Defs.hxx"
#include "NETGENPlugin_Mesher.hxx"
@ -75,7 +74,7 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo
netgen_params& aParams,
const std::string output_file);
void FillParameters(const NETGENPlugin_Hypothesis* hyp,
void fillParameters(const NETGENPlugin_Hypothesis* hyp,
netgen_params &aParams);
int RemoteCompute(SMESH_Mesh& aMesh,

View File

@ -1,152 +0,0 @@
// Copyright (C) 2007-2021 CEA/DEN, EDF R&D, OPEN CASCADE
//
// 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 : NETGENPlugin_Provider.hxx
// Author : Yoann AUDOUIN (EDF)
// Project : SALOME
//
#ifndef _NETGENPlugin_Provider_HXX_
#define _NETGENPlugin_Provider_HXX_
#include <iostream>
#include <thread>
#include <array>
#include <vector>
#include <unistd.h>
#include <mutex>
namespace nglib {
#include <nglib.h>
}
#ifndef OCCGEOMETRY
#define OCCGEOMETRY
#endif
#include <occgeom.hpp>
#include <meshing.hpp>
template<class T, int NDATA>
class ProviderPtr{
public:
ProviderPtr(){
for(int i=0;i<NDATA;i++){
this->_mydata[i] = nullptr;
this->_useddata[i] = false;
}
}
int take(T** data){
this->_mymutex.lock();
*data = nullptr;
for(int i=0;i<NDATA;i++){
if(!this->_useddata[i]){
if (this->_mydata[i] == nullptr)
this->_mydata[i] = new T();
this->_useddata[i] = true;
*data = this->_mydata[i];
this->_mymutex.unlock();
return i;
}
}
this->_mymutex.unlock();
return -1;
};
bool release(int i, bool clean){
this->_mymutex.lock();
if(clean){
delete this->_mydata[i];
this->_mydata[i] = nullptr;
}
this->_useddata[i] = false;
this->_mymutex.unlock();
return true;
};
void dump(){
std::cout << "Dumping provider:" << std::endl;
for(int i=0;i<NDATA;i++){
std::cout << " - " << i << " used: " << this->_useddata[i] << std::endl;
std::cout << " - adress: " << this->_mydata[i] << std::endl;
if (this->_mydata[i] != nullptr)
std::cout << " - i: " << this->_mydata[i]->i << " d: " << this->_mydata[i]->d << std::endl;
}
};
private:
std::array<T*, NDATA> _mydata;
std::array<bool, NDATA> _useddata;
std::mutex _mymutex;
};
template<class T, int NDATA>
class Provider{
public:
Provider() = default;
int take(T& data){
this->_mymutex.lock();
for(int i=0;i<NDATA;i++){
if(!this->_useddata[i]){
this->_useddata[i] = true;
data = this->_mydata[i];
this->_mymutex.unlock();
return i;
}
}
this->_mymutex.unlock();
return -1;
};
bool release(int i){
this->_mymutex.lock();
this->_useddata[i] = false;
this->_mymutex.unlock();
return true;
};
void dump(){
std::cout << "Dumping provider:" << std::endl;
for(int i=0;i<NDATA;i++){
std::cout << " - " << i << " used: " << this->_useddata[i] << std::endl;
std::cout << " - i: " << this->_mydata[i].i << " d: " << this->_mydata[i].d << std::endl;
}
};
private:
std::array<T, NDATA> _mydata;
std::array<bool, NDATA> _useddata;
std::mutex _mymutex;
};
#endif

View File

@ -20,21 +20,20 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : netgen_mesher.cxx
// File : NETGENPlugin_Runner.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "netgen_mesher.hxx"
#include "NETGENPlugin_Runner.hxx"
#include "DriverStep.hxx"
#include "DriverMesh.hxx"
#include "netgen_param.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include <fstream>
#include <vector>
#include <filesystem>
namespace fs = std::filesystem;
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include <chrono>
// SMESH include
@ -51,6 +50,8 @@ namespace fs = std::filesystem;
#include <StdMeshers_QuadToTriaAdaptor.hxx>
#include <StdMeshers_ViscousLayers.hxx>
#include <StdMeshers_ViscousLayers2D.hxx>
#include <SMESH_DriverStep.hxx>
#include <SMESH_DriverMesh.hxx>
// NETGENPlugin
@ -186,7 +187,6 @@ int netgen3d(const std::string input_mesh_file,
const std::string hypo_file,
const std::string element_orientation_file,
const std::string new_element_file,
bool output_mesh,
const std::string output_mesh_file,
int nbThreads)
{
@ -198,22 +198,22 @@ int netgen3d(const std::string input_mesh_file,
//TODO: To define
std::string mesh_name = "Maillage_1";
import_mesh(input_mesh_file, *myMesh, mesh_name);
importMesh(input_mesh_file, *myMesh, mesh_name);
auto time1 = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time1-time0);
std::cout << "Time for import_mesh: " << elapsed.count() * 1e-9 << std::endl;
std::cout << "Time for importMesh: " << elapsed.count() * 1e-9 << std::endl;
// Importing shape
TopoDS_Shape myShape;
import_shape(shape_file, myShape);
importShape(shape_file, myShape);
auto time2 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time2-time1);
std::cout << "Time for import_shape: " << elapsed.count() * 1e-9 << std::endl;
std::cout << "Time for importShape: " << elapsed.count() * 1e-9 << std::endl;
// Importing hypothesis
netgen_params myParams;
import_netgen_params(hypo_file, myParams);
importNetgenParams(hypo_file, myParams);
auto time3 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time3-time2);
std::cout << "Time for import_netgen_param: " << elapsed.count() * 1e-9 << std::endl;
@ -221,9 +221,9 @@ int netgen3d(const std::string input_mesh_file,
myParams.nbThreads = nbThreads;
std::cout << "Meshing with netgen3d" << std::endl;
int ret = netgen3d_internal(myShape, *myMesh, myParams,
int ret = netgen3dInternal(myShape, *myMesh, myParams,
new_element_file, element_orientation_file,
output_mesh);
!output_mesh_file.empty());
if(!ret){
@ -231,12 +231,12 @@ int netgen3d(const std::string input_mesh_file,
return ret;
}
if(output_mesh){
if(!output_mesh_file.empty()){
auto time4 = std::chrono::high_resolution_clock::now();
export_mesh(output_mesh_file, *myMesh, mesh_name);
exportMesh(output_mesh_file, *myMesh, mesh_name);
auto time5 = std::chrono::high_resolution_clock::now();
elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(time5-time4);
std::cout << "Time for export_mesh: " << elapsed.count() * 1e-9 << std::endl;
std::cout << "Time for exportMesh: " << elapsed.count() * 1e-9 << std::endl;
}
return ret;
@ -249,10 +249,12 @@ int netgen3d(const std::string input_mesh_file,
* @param aMesh the mesh
* @param aParams the netgen parameters
* @param new_element_file file containing data on the new point/tetra added by netgen
* @param element_orientation_file file containing data on the orientation of each element to add to netgen
* @param output_mesh if true add element created by netgen into aMesh
*
* @return error code
*/
int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
int netgen3dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
std::string new_element_file, std::string element_orientation_file,
bool output_mesh)
{
@ -317,6 +319,16 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
// Get list of elements + their orientation from element_orientation file
std::map<vtkIdType, bool> elemOrientation;
{
// Setting all element orientation to false if there no element orientation file
if(element_orientation_file.empty()){
SMDS_ElemIteratorPtr iteratorElem = meshDS->elementsIterator(SMDSAbs_Face);
while ( iteratorElem->more() ) // loop on elements on a geom face
{
// check mesh face
const SMDS_MeshElement* elem = iteratorElem->next();
elemOrientation[elem->GetID()] = false;
}
} else {
std::ifstream df(element_orientation_file, ios::binary|ios::in);
int nbElement;
bool orient;
@ -333,6 +345,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
elemOrientation[id] = orient;
}
}
}
// Adding elements from Mesh
SMDS_ElemIteratorPtr iteratorElem = meshDS->elementsIterator(SMDSAbs_Face);
@ -356,7 +369,6 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
if(!isIn)
continue;
// Get orientation
// Netgen requires that all the triangle point outside
isRev = elemOrientation[elem->GetID()];
@ -542,7 +554,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
std::cout << "Time for netgen_compute: " << elapsed.count() * 1e-9 << std::endl;
bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built
if ( isOK )
if ( isOK && !new_element_file.empty() )
{
std::ofstream df(new_element_file, ios::out|ios::binary);
@ -581,7 +593,7 @@ int netgen3d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aP
std::cout << "Time for write_new_elem: " << elapsed.count() * 1e-9 << std::endl;
// Adding new files in aMesh as well
// Adding new elements in aMesh as well
if ( output_mesh )
{
double Netgen_point[3];
@ -639,7 +651,6 @@ int netgen2d(const std::string input_mesh_file,
const std::string hypo_file,
const std::string element_orientation_file,
const std::string new_element_file,
bool output_mesh,
const std::string output_mesh_file)
{
@ -650,29 +661,29 @@ int netgen2d(const std::string input_mesh_file,
//TODO: To define
std::string mesh_name = "Maillage_1";
import_mesh(input_mesh_file, *myMesh, mesh_name);
importMesh(input_mesh_file, *myMesh, mesh_name);
// Importing shape
TopoDS_Shape myShape;
import_shape(shape_file, myShape);
importShape(shape_file, myShape);
// Importing hypothesis
netgen_params myParams;
import_netgen_params(hypo_file, myParams);
importNetgenParams(hypo_file, myParams);
std::cout << "Meshing with netgen3d" << std::endl;
int ret = netgen2d_internal(myShape, *myMesh, myParams,
int ret = netgen2dInternal(myShape, *myMesh, myParams,
new_element_file, element_orientation_file,
output_mesh);
!output_mesh_file.empty());
if(!ret){
std::cout << "Meshing failed" << std::endl;
return ret;
}
if(output_mesh)
export_mesh(output_mesh_file, *myMesh, mesh_name);
if(!output_mesh_file.empty())
exportMesh(output_mesh_file, *myMesh, mesh_name);
return ret;
}
@ -689,7 +700,7 @@ int netgen2d(const std::string input_mesh_file,
*
* @return error code
*/
int netgen2d_internal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
int netgen2dInternal(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
std::string new_element_file, std::string element_orientation_file,
bool output_mesh)
{

View File

@ -20,13 +20,13 @@
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
// File : netgen_mesher.hxx
// File : NETGENPlugin_Runner.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
// Module : NETGEN
//
#ifndef _NETGEN_MESHER_HXX_
#define _NETGEN_MESHER_HXX_
#ifndef _NETGENPLUGIN_RUNNER_HXX_
#define _NETGENPLUGIN_RUNNER_HXX_
#include <string>
#include <iostream>
@ -36,7 +36,7 @@ class SMESH_Mesh;
class SMESH_Comment;
class netgen_params;
int netgen2d_internal(TopoDS_Shape &aShape,
int netgen2dInternal(TopoDS_Shape &aShape,
SMESH_Mesh& aMesh,
netgen_params& aParams,
std::string new_element_file,
@ -45,12 +45,11 @@ int netgen2d_internal(TopoDS_Shape &aShape,
int netgen2d(const std::string input_mesh_file,
const std::string shape_file,
const std::string hypo_file,
const std::string element_orienation_file,
const std::string element_orientation_file,
const std::string new_element_file,
bool output_mesh,
const std::string output_mesh_file);
int netgen3d_internal(TopoDS_Shape &aShape,
int netgen3dInternal(TopoDS_Shape &aShape,
SMESH_Mesh& aMesh,
netgen_params& aParams,
std::string new_element_file,
@ -59,9 +58,8 @@ int netgen3d_internal(TopoDS_Shape &aShape,
int netgen3d(const std::string input_mesh_file,
const std::string shape_file,
const std::string hypo_file,
const std::string element_orienation_file,
const std::string element_orientation_file,
const std::string new_element_file,
bool output_mesh,
const std::string output_mesh_file,
int nbThreads);

View File

@ -0,0 +1,105 @@
// 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 : NETGENplugin_Runnner_main.cxx
// Author : Yoann AUDOUIN, EDF
// Module : NETGEN
//
#include "NETGENPlugin_Runner.hxx"
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <chrono>
/**
* @brief Main function
*
* @param argc Number of arguments
* @param argv Arguments
*
* @return error code
*/
int main(int argc, char *argv[]){
if(argc!=9||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){
std::cout << "Error in number of arguments "<< argc<<" given expected 8" <<std::endl;
std::cout << "Syntax:"<<std::endl;
std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl;
std::cout << " ELEM_ORIENT_FILE NB_THREADS" << std::endl;
std::cout << " NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl;
std::cout << std::endl;
std::cout << " Set argument to NONE to ignore them " << std::endl;
std::cout << std::endl;
std::cout << "Args:" << std::endl;
std::cout << " MESHER: mesher to use from (NETGEN3D, NETGEN2D)" << std::endl;
std::cout << " INPUT_MESH_FILE: MED File containing lower-dimension-elements already meshed" << std::endl;
std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl;
std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl;
std::cout << " (optional) ELEM_ORIENT_FILE: binary file containing the list of element from INPUT_MESH_FILE associated to the shape and their orientation" << std::endl;
std::cout << " NB_THREADS: Number of thread to use for the mesher" << std::endl;
std::cout << " (optional) NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl;
std::cout << " (optional) OUTPUT_MESH_FILE: (out) MED File containing the mesh after the run of the mesher" << std::endl;
return 0;
}
std::string mesher=argv[1];
std::string input_mesh_file=argv[2];
std::string shape_file=argv[3];
std::string hypo_file=argv[4];
std::string element_orientation_file=argv[5];
int nbThreads=std::stoi(argv[6]);
std::string new_element_file=argv[7];
std::string output_mesh_file=argv[8];
if (output_mesh_file == "NONE")
output_mesh_file = "";
if (element_orientation_file == "NONE")
element_orientation_file = "";
if (new_element_file == "NONE")
new_element_file = "";
if (mesher=="NETGEN3D"){
auto begin = std::chrono::high_resolution_clock::now();
netgen3d(input_mesh_file,
shape_file,
hypo_file,
element_orientation_file,
new_element_file,
output_mesh_file,
nbThreads);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl;
} else if (mesher=="NETGEN2D"){
netgen2d(input_mesh_file,
shape_file,
hypo_file,
element_orientation_file,
new_element_file,
output_mesh_file);
} else {
std::cerr << "Unknown mesher:" << mesher << std::endl;
}
return 0;
}

View File

@ -1,242 +0,0 @@
// 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 : run_mesher.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "DriverStep.hxx"
#include "DriverMesh.hxx"
#include "netgen_param.hxx"
#include "netgen_mesher.hxx"
#include <SMESH_Mesh.hxx>
#include <SMESH_Gen.hxx>
#include <TopoDS_Shape.hxx>
#include <iostream>
#include <chrono>
/**
* @brief Test of shape Import/Export
*
* @param shape_file
*/
void test_shape(){
std::cout << "Testing Shape Import/Export" << std::endl;
std::string shape_file = "box.step";
TopoDS_Shape myShape;
// Test 1 import -> export cmp files
std::string shape_file2 = "/tmp/shape.step";
import_shape(shape_file, myShape);
export_shape(shape_file2, myShape);
assert(diff_step_file(shape_file, shape_file2));
// Test 2 import->export->import cmp TopoDS_Shape
std::string shape_file3 = "/tmp/shape2.step";
TopoDS_Shape myShape1, myShape2;
import_shape(shape_file, myShape1);
export_shape(shape_file3, myShape1);
import_shape(shape_file3, myShape2);
// TODO: See why this does not work
// TShape seems to be different
//assert(myShape1.IsSame(myShape2));
}
/**
* @brief test of mesh import/export
*
* @param mesh_file
*/
void test_mesh(){
std::cout << "Testing Mesh Import/Export" << std::endl;
std::string mesh_file = "box.med";
SMESH_Gen gen;
SMESH_Mesh *myMesh = gen.CreateMesh(false);
std::string mesh_name = "Maillage_1";
// Test 1 import -> export cmp files
std::string mesh_file2 = "/tmp/mesh.med";
import_mesh(mesh_file, *myMesh, mesh_name);
export_mesh(mesh_file2, *myMesh, mesh_name);
assert(diff_med_file(mesh_file, mesh_file2, mesh_name));
// TODO: Compare the two med files via dump ?
// Test 2 import->export->import cmp TopoDS_Shape
std::string mesh_file3 = "/tmp/mesh2.med";
SMESH_Mesh *myMesh1 = gen.CreateMesh(false);
SMESH_Mesh *myMesh2 = gen.CreateMesh(false);
import_mesh(mesh_file, *myMesh1, mesh_name);
export_mesh(mesh_file3, *myMesh1, mesh_name);
import_mesh(mesh_file3, *myMesh2, mesh_name);
// TODO: Compare SMESH_Mesh
//assert(myMesh1==myMesh2);
}
/**
* @brief Test of import/export of netgen param
*
*/
void test_netgen_params(){
std::string param_file = "/tmp/netgen_param.txt";
netgen_params myParams, myParams2;
myParams.has_netgen_param = true;
myParams.maxh = 34.64;
myParams.minh = 0.14;
myParams.segmentsperedge = 15;
myParams.grading = 0.2;
myParams.curvaturesafety = 1.5;
myParams.secondorder = false;
myParams.quad = false;
myParams.optimize = true;
myParams.fineness = 5;
myParams.uselocalh = true;
myParams.merge_solids = true;
myParams.chordalError = -1;
myParams.optsteps2d = 3;
myParams.optsteps3d = 3;
myParams.elsizeweight = 0.2;
myParams.opterrpow = 2;
myParams.delaunay = true;
myParams.checkoverlap = true;
myParams.checkchartboundary = false;
myParams.closeedgefac = 2;
myParams.has_local_size = false;
myParams.meshsizefilename = "";
myParams.has_maxelementvolume_hyp = false;
myParams.maxElementVolume = 0.0;
export_netgen_params(param_file, myParams);
import_netgen_params(param_file, myParams2);
assert(diff_netgen_params(myParams, myParams2));
};
void test_netgen3d(){
std::cout << "Testing NETGEN 3D mesher" << std::endl;
netgen3d("box_partial2D1D-2.med",
"box-2.step",
"box_param.txt",
"element_orient.dat",
"new_element.dat",
true,
"box_with3D.med",
1);
// TODO: Check result
}
/**
* @brief Main function
*
* @param argc Number of arguments
* @param argv Arguments
*
* @return error code
*/
int main(int argc, char *argv[]){
if(argc!=10||(argc==2 && (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help")==0))){
std::cout << "Error in number of argument"<<std::endl;
std::cout << "Syntax:"<<std::endl;
std::cout << "run_mesher MESHER INPUT_MESH_FILE SHAPE_FILE HYPO_FILE" << std::endl;
std::cout << " ELEM_ORIENT_FILE NB_THREADS" << std::endl;
std::cout << " NEW_ELEMENT_FILE OUTPUT_MESH_FILE" << std::endl;
std::cout << std::endl;
std::cout << "Args:" << std::endl;
std::cout << " MESHER: mesher to use from (NETGEN3D, NETGEN2D)" << std::endl;
std::cout << " INPUT_MESH_FILE: MED File containing lower-dimension-elements already meshed" << std::endl;
std::cout << " SHAPE_FILE: STEP file containing the shape to mesh" << std::endl;
std::cout << " HYPO_FILE: Ascii file containint the list of parameters" << std::endl;
std::cout << " ELEM_ORIENT_FILE: binary file containing the list of element from INPUT_MESH_FILE associated to the shape and their orientation" << std::endl;
std::cout << " NB_THREADS: Number of thread to use for the mesher" << std::endl;
std::cout << " NEW_ELEMENT_FILE: (out) contains elements and nodes added by the meshing" << std::endl;
std::cout << " OUTPUT_MESH: If !=0 will export mesh into OUTPUT_MESH_FILE " << std::endl;
std::cout << " OUTPUT_MESH_FILE: MED File containing the mesh after the run of the mesher" << std::endl;
return 0;
}
std::string mesher=argv[1];
std::string input_mesh_file=argv[2];
std::string shape_file=argv[3];
std::string hypo_file=argv[4];
std::string element_orientation_file=argv[5];
int nbThreads=std::stoi(argv[6]);
std::string new_element_file=argv[7];
bool output_mesh = std::stoi(argv[8]) != 0;
std::string output_mesh_file=argv[9];
if (mesher=="test"){
std::cout << "Running tests" << std::endl;
test_shape();
test_mesh();
test_netgen_params();
test_netgen3d();
} else if (mesher=="NETGEN3D"){
auto begin = std::chrono::high_resolution_clock::now();
netgen3d(input_mesh_file,
shape_file,
hypo_file,
element_orientation_file,
new_element_file,
output_mesh,
output_mesh_file,
nbThreads);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
std::cout << "Time elapsed: " << elapsed.count()*1e-9 << std::endl;
} else if (mesher=="NETGEN2D"){
netgen2d(input_mesh_file,
shape_file,
hypo_file,
element_orientation_file,
new_element_file,
output_mesh,
output_mesh_file);
} else {
std::cerr << "Unknown mesher:" << mesher << std::endl;
}
return 0;
}