Compare commits

...

21 Commits

Author SHA1 Message Date
Yoann Audouin
3a6a1c7888 Cleanup of NETGEN_2D_Only 2022-09-28 08:06:51 +02:00
Yoann Audouin
4264181864 cout replaced by MESSAGE + clean up 2022-09-21 16:36:10 +02:00
Yoann Audouin
b3018b01b0 Removing hard coded meshname from Mesh import 2022-09-21 15:15:31 +02:00
Yoann Audouin
5e49461800 Creating Remote and SA NETGEN_3D plugins 2022-09-21 14:21:30 +02:00
Yoann Audouin
a52ccf7016 Refactoring of runner 2022-09-19 15:13:31 +02:00
Yoann Audouin
9ca5a5ccb4 Refactor in runner 2022-09-19 11:49:00 +02:00
Yoann Audouin
7b58079a8f Refactoring of normal Compute 2022-09-19 11:18:08 +02:00
Yoann Audouin
f48857dd37 Now filling param _hypParameters and _stdMaxvolume 2022-09-19 11:15:26 +02:00
Yoann Audouin
9a8699d341 Adding support for BRep for shape 2022-09-15 15:12:50 +02:00
Yoann Audouin
f6f53b135d Switchin to QProcess instead of sytem for remote compute 2022-09-15 14:06:22 +02:00
Yoann Audouin
75a1472981 Better handle of deletion of temporary folder + missing delete of temporary SMESH_Mesh 2022-09-15 11:01:41 +02:00
Yoann Audouin
01afecee31 Renaming functions and files + minor corrections in runner_main to detect what to do 2022-09-14 16:37:56 +02:00
Yoann Audouin
80e4ccd74d Using RAII to remove file.close 2022-09-13 14:33:19 +02:00
Yoann Audouin
6859939db1 Adding support of number of thread for the mesher 2022-09-13 09:48:51 +02:00
Yoann Audouin
92df63b99d Renaming netgen2d/3d internal calls 2022-09-12 08:11:15 +02:00
Yoann Audouin
9b35f0cc86 partial work for netgen2d in run_mesher + corrections for netgen3d nodeVec + restoring sequential netgen2D_only 2022-09-09 09:50:30 +02:00
Yoann Audouin
cd7fb05959 Generic path for executable 2022-08-31 16:29:01 +02:00
Yoann Audouin
c249924b3a Integration of run_mesher code 2022-08-31 16:07:16 +02:00
Yoann Audouin
a90203eab4 restoring original compute + Cleanup 2022-08-31 09:34:02 +02:00
Yoann Audouin
6cd4dbe17e Working version for run_mesher for netgen 3d 2022-08-26 11:36:21 +02:00
Yoann Audouin
58c0c7e37e Using provider for occgeom and nglib 2022-07-25 10:34:43 +02:00
18 changed files with 1881 additions and 214 deletions

View File

@ -44,6 +44,13 @@ module NETGENPlugin
{
};
/*!
* NETGENPlugin_NETGEN_3D: interface of "Remote Tetrahedron (Netgen)" algorithm
*/
interface NETGENPlugin_NETGEN_3D_Remote : NETGENPlugin::NETGENPlugin_NETGEN_3D
{
};
/*!
* NETGENPlugin_NETGEN_2D: interface of "Netgen 1D-2D" algorithm
*/

View File

@ -17,9 +17,12 @@
# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
#
INCLUDE(UseQtExt)
# --- options ---
# additional include directories
INCLUDE_DIRECTORIES(
${QT_INCLUDES}
${KERNEL_INCLUDE_DIRS}
${GUI_INCLUDE_DIRS}
${GEOM_INCLUDE_DIRS}
@ -35,6 +38,7 @@ INCLUDE_DIRECTORIES(
# additional preprocessor / compiler flags
ADD_DEFINITIONS(
${QT_DEFINITIONS}
${OMNIORB_DEFINITIONS}
${OpenCASCADE_DEFINITIONS}
${BOOST_DEFINITIONS}
@ -63,7 +67,10 @@ SET(_link_LIBRARIES
${KERNEL_SalomeNS}
${KERNEL_SALOMELocalTrace}
${KERNEL_OpUtil}
VTK::CommonCore
VTK::CommonDataModel
SalomeIDLNETGENPLUGIN
Qt5::Core
)
# --- headers ---
@ -91,6 +98,10 @@ SET(NETGENEngine_HEADERS
NETGENPlugin_Mesher.hxx
NETGENPlugin_Remesher_2D.hxx
NETGENPlugin_Defs.hxx
NETGENPlugin_DriverParam.hxx
NETGENPlugin_NETGEN_3D_SA.hxx
NETGENPlugin_NETGEN_3D_Remote.hxx
NETGENPlugin_NETGEN_3D_Remote_i.hxx
)
# --- sources ---
@ -118,6 +129,14 @@ SET(NETGENEngine_SOURCES
NETGENPlugin_SimpleHypothesis_3D_i.cxx
NETGENPlugin_Remesher_2D.cxx
NETGENPlugin_i.cxx
NETGENPlugin_DriverParam.cxx
NETGENPlugin_NETGEN_3D_SA.cxx
NETGENPlugin_NETGEN_3D_Remote.cxx
NETGENPlugin_NETGEN_3D_Remote_i.cxx
)
SET(NetgenRunner_SOURCES
NETGENPlugin_Runner_main.cxx
)
# --- scripts ---
@ -134,6 +153,10 @@ ADD_LIBRARY(NETGENEngine ${NETGENEngine_SOURCES})
TARGET_LINK_LIBRARIES(NETGENEngine ${_link_LIBRARIES} )
INSTALL(TARGETS NETGENEngine EXPORT ${PROJECT_NAME}TargetGroup DESTINATION ${SALOME_INSTALL_LIBS})
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})
SALOME_INSTALL_SCRIPTS("${_bin_SCRIPTS}" ${SALOME_INSTALL_PYTHON}/salome/NETGENPlugin)

View File

@ -42,6 +42,7 @@ NETGEN_VERSION_MAJOR = NETGENPlugin.NETGEN_VERSION_MAJOR
## Algorithm type: Netgen tetrahedron 3D algorithm, see NETGEN_3D_Algorithm
NETGEN_3D = "NETGEN_3D"
NETGEN_3D_Remote = "NETGEN_3D_Remote"
## Algorithm type: Netgen tetrahedron 1D-2D-3D algorithm, see NETGEN_1D2D3D_Algorithm
NETGEN_1D2D3D = "NETGEN_2D3D"
## Algorithm type: Netgen triangle 1D-2D algorithm, see NETGEN_1D2D_Algorithm
@ -328,6 +329,7 @@ class NETGEN_1D2D_Algorithm(NETGEN_1D2D3D_Algorithm):
# @internal
docHelper = "Creates triangle 2D algorithm for faces"
## Private constructor.
# @param mesh parent mesh object algorithm is assigned to
# @param geom geometry (shape/sub-shape) algorithm is assigned to;
@ -358,6 +360,8 @@ class NETGEN_2D_Only_Algorithm(NETGEN_Algorithm):
# @internal
docHelper = "Creates triangle 2D algorithm for faces"
isDefault = True
## Private constructor.
# @param mesh parent mesh object algorithm is assigned to
# @param geom geometry (shape/sub-shape) algorithm is assigned to;
@ -467,6 +471,37 @@ class NETGEN_3D_Algorithm(NETGEN_Algorithm):
pass # end of NETGEN_3D_Algorithm class
## Tetrahedron 3D algorithm
#
# It can be created by calling smeshBuilder.Mesh.Tetrahedron() or smeshBuilder.Mesh.Tetrahedron( smeshBuilder.NETGEN, geom=0 )
#
# This algorithm generates only 3D (volumes) elements for given geometrical shape
# and, in contrast to NETGEN_1D2D3D_Algorithm class, should be used in conjunction
# with other 1D and 2D meshing algorithms.
class NETGEN_3D_Remote_Algorithm(NETGEN_3D_Algorithm):
## type of algorithm used with helper function in smeshBuilder.Mesh class
# @internal
algoType = NETGEN_3D_Remote
## flag pointing either this algorithm should be used by default in dynamic method
# of smeshBuilder.Mesh class
# @internal
isDefault = False
## doc string of the method
# @internal
docHelper = "Remotely Creates tetrahedron 3D algorithm for solids"
## Private constructor.
# @param mesh parent mesh object algorithm is assigned to
# @param geom geometry (shape/sub-shape) algorithm is assigned to;
# if it is @c 0 (default), the algorithm is assigned to the main shape
def __init__(self, mesh, geom=0):
NETGEN_3D_Algorithm.__init__(self, mesh, geom)
pass
pass # end of NETGEN_3D_Remote_Algorithm class
## Triangle (helper) 1D-2D algorithm
#

View File

@ -0,0 +1,202 @@
// 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_DriverParam.hxx
// Author : Yoann AUDOUIN, EDF
// Module : NETGEN
//
#include "NETGENPlugin_DriverParam.hxx"
#include "NETGENPlugin_Hypothesis.hxx"
#include <SMESH_Gen.hxx>
#include <StdMeshers_MaxElementVolume.hxx>
#include <iostream>
#include <fstream>
#include <string>
#include <cassert>
/**
* @brief Print content of a netgen_params
*
* @param aParams The object to display
*/
void printNetgenParams(netgen_params& aParams){
std::cout << "has_netgen_param: " << aParams.has_netgen_param << std::endl;
std::cout << "maxh: " << aParams.maxh << std::endl;
std::cout << "minh: " << aParams.minh << std::endl;
std::cout << "segmentsperedge: " << aParams.segmentsperedge << std::endl;
std::cout << "grading: " << aParams.grading << std::endl;
std::cout << "curvaturesafety: " << aParams.curvaturesafety << std::endl;
std::cout << "secondorder: " << aParams.secondorder << std::endl;
std::cout << "quad: " << aParams.quad << std::endl;
std::cout << "optimize: " << aParams.optimize << std::endl;
std::cout << "fineness: " << aParams.fineness << std::endl;
std::cout << "uselocalh: " << aParams.uselocalh << std::endl;
std::cout << "merge_solids: " << aParams.merge_solids << std::endl;
std::cout << "chordalError: " << aParams.chordalError << std::endl;
std::cout << "optsteps2d: " << aParams.optsteps2d << std::endl;
std::cout << "optsteps3d: " << aParams.optsteps3d << std::endl;
std::cout << "elsizeweight: " << aParams.elsizeweight << std::endl;
std::cout << "opterrpow: " << aParams.opterrpow << std::endl;
std::cout << "delaunay: " << aParams.delaunay << std::endl;
std::cout << "checkoverlap: " << aParams.checkoverlap << std::endl;
std::cout << "checkchartboundary: " << aParams.checkchartboundary << std::endl;
std::cout << "closeedgefac: " << aParams.closeedgefac << std::endl;
std::cout << "has_local_size: " << aParams.has_local_size << std::endl;
std::cout << "meshsizefilename: " << aParams.meshsizefilename << std::endl;
std::cout << "has_maxelementvolume_hyp: " << aParams.has_maxelementvolume_hyp << std::endl;
std::cout << "maxElementVolume: " << aParams.maxElementVolume << std::endl;
std::cout << "has_LengthFromEdges_hyp: " << aParams.has_LengthFromEdges_hyp << std::endl;
}
/**
* @brief Import a param_file into a netgen_params structure
*
* @param param_file Name of the file
* @param aParams Structure to fill
*/
void importNetgenParams(const std::string param_file, netgen_params& aParams, SMESH_Gen *gen){
std::ifstream myfile(param_file);
std::string line;
std::getline(myfile, line);
aParams.has_netgen_param = std::stoi(line);
std::getline(myfile, line);
aParams.maxh = std::stod(line);
std::getline(myfile, line);
aParams.minh = std::stod(line);
std::getline(myfile, line);
aParams.segmentsperedge = std::stod(line);
std::getline(myfile, line);
aParams.grading = std::stod(line);
std::getline(myfile, line);
aParams.curvaturesafety = std::stod(line);
std::getline(myfile, line);
aParams.secondorder = std::stoi(line);
std::getline(myfile, line);
aParams.quad = std::stoi(line);
std::getline(myfile, line);
aParams.optimize = std::stoi(line);
std::getline(myfile, line);
aParams.fineness = std::stoi(line);
std::getline(myfile, line);
aParams.uselocalh = std::stoi(line);
std::getline(myfile, line);
aParams.merge_solids = std::stoi(line);
std::getline(myfile, line);
aParams.chordalError = std::stod(line);
std::getline(myfile, line);
aParams.optsteps2d = std::stoi(line);
std::getline(myfile, line);
aParams.optsteps3d = std::stoi(line);
std::getline(myfile, line);
aParams.elsizeweight = std::stod(line);
std::getline(myfile, line);
aParams.opterrpow = std::stoi(line);
std::getline(myfile, line);
aParams.delaunay = std::stoi(line);
std::getline(myfile, line);
aParams.checkoverlap = std::stoi(line);
std::getline(myfile, line);
aParams.checkchartboundary = std::stoi(line);
std::getline(myfile, line);
aParams.closeedgefac = std::stoi(line);
std::getline(myfile, line);
aParams.has_local_size = std::stoi(line);
std::getline(myfile, line);
aParams.meshsizefilename = line;
std::getline(myfile, line);
aParams.has_maxelementvolume_hyp = std::stoi(line);
std::getline(myfile, line);
aParams.maxElementVolume = std::stod(line);
std::getline(myfile, line);
aParams.maxElementVolume = std::stoi(line);
if(aParams.has_netgen_param){
aParams._hypParameters = new NETGENPlugin_Hypothesis(0, gen);
aParams._hypParameters->SetMaxSize(aParams.maxh);
aParams._hypParameters->SetMinSize(aParams.minh);
aParams._hypParameters->SetNbSegPerEdge(aParams.segmentsperedge);
aParams._hypParameters->SetGrowthRate(aParams.grading);
aParams._hypParameters->SetNbSegPerRadius(aParams.curvaturesafety);
aParams._hypParameters->SetSecondOrder(aParams.secondorder);
aParams._hypParameters->SetQuadAllowed(aParams.quad);
aParams._hypParameters->SetOptimize(aParams.optimize);
aParams._hypParameters->SetFineness((NETGENPlugin_Hypothesis::Fineness)aParams.fineness);
aParams._hypParameters->SetSurfaceCurvature(aParams.uselocalh);
aParams._hypParameters->SetFuseEdges(aParams.merge_solids);
aParams._hypParameters->SetChordalErrorEnabled(aParams.chordalError);
if(aParams.optimize){
aParams._hypParameters->SetNbSurfOptSteps(aParams.optsteps2d);
aParams._hypParameters->SetNbVolOptSteps(aParams.optsteps3d);
}
aParams._hypParameters->SetElemSizeWeight(aParams.elsizeweight);
aParams._hypParameters->SetWorstElemMeasure(aParams.opterrpow);
aParams._hypParameters->SetUseDelauney(aParams.delaunay);
aParams._hypParameters->SetCheckOverlapping(aParams.checkoverlap);
aParams._hypParameters->SetCheckChartBoundary(aParams.checkchartboundary);
aParams._hypParameters->SetMeshSizeFile(aParams.meshsizefilename);
}
if(aParams.has_maxelementvolume_hyp){
aParams._hypMaxElementVolume = new StdMeshers_MaxElementVolume(1, gen);
}
// TODO: Handle viscous layer
};
/**
* @brief Writes the content of a netgen_param into a file
*
* @param param_file the file
* @param aParams the object
*/
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;
myfile << aParams.minh << std::endl;
myfile << aParams.segmentsperedge << std::endl;
myfile << aParams.grading << std::endl;
myfile << aParams.curvaturesafety << std::endl;
myfile << aParams.secondorder << std::endl;
myfile << aParams.quad << std::endl;
myfile << aParams.optimize << std::endl;
myfile << aParams.fineness << std::endl;
myfile << aParams.uselocalh << std::endl;
myfile << aParams.merge_solids << std::endl;
myfile << aParams.chordalError << std::endl;
myfile << aParams.optsteps2d << std::endl;
myfile << aParams.optsteps3d << std::endl;
myfile << aParams.elsizeweight << std::endl;
myfile << aParams.opterrpow << std::endl;
myfile << aParams.delaunay << std::endl;
myfile << aParams.checkoverlap << std::endl;
myfile << aParams.checkchartboundary << std::endl;
myfile << aParams.closeedgefac << std::endl;
myfile << aParams.has_local_size << std::endl;
myfile << aParams.meshsizefilename << std::endl;
myfile << aParams.has_maxelementvolume_hyp << std::endl;
myfile << aParams.maxElementVolume << std::endl;
myfile << aParams.has_LengthFromEdges_hyp << std::endl;
};

View File

@ -0,0 +1,93 @@
// 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_DriverParam.hxx
// Author : Yoann AUDOUIN, EDF
// Module : NETGEN
//
#ifndef _NETGENPLUGIN_DRIVERPARAM_HXX_
#define _NETGENPLUGIN_DRIVERPARAM_HXX_
#include <string>
class NETGENPlugin_Hypothesis;
class StdMeshers_MaxElementVolume;
class StdMeshers_ViscousLayers;
class SMESH_Gen;
struct netgen_params{
// Params from NETGENPlugin_Mesher
// True if _hypParameters is not null
bool has_netgen_param=true;
double maxh;
double minh;
double segmentsperedge;
double grading;
double curvaturesafety;
int secondorder;
int quad;
bool optimize;
int fineness;
bool uselocalh;
bool merge_solids;
double chordalError;
int optsteps2d;
int optsteps3d;
double elsizeweight;
int opterrpow;
bool delaunay;
bool checkoverlap;
bool checkchartboundary;
int closeedgefac;
// True if we have a mesh size file or local size info
bool has_local_size = false;
std::string meshsizefilename;
// Params from NETGEN3D
// True if _hypMaxElementVolume is not null
bool has_maxelementvolume_hyp=false;
double maxElementVolume=0.0;
NETGENPlugin_Hypothesis * _hypParameters=nullptr;
StdMeshers_MaxElementVolume* _hypMaxElementVolume=nullptr;
StdMeshers_ViscousLayers* _viscousLayersHyp=nullptr;
double _progressByTic;
bool _quadraticMesh=false;
int _error=0;
std::string _comment;
// Params from NETGEN2D
bool has_LengthFromEdges_hyp=false;
// Number of threads for the mesher
int nbThreads;
};
void printNetgenParams(netgen_params& aParams);
void importNetgenParams(const std::string param_file, netgen_params& aParams, SMESH_Gen * gen);
void exportNetgenParams(const std::string param_file, netgen_params& aParams);
#endif

View File

@ -92,12 +92,15 @@ struct NETGENPLUGIN_EXPORT NETGENPlugin_NetgenLibWrapper
void setMesh( nglib::Ng_Mesh* mesh );
nglib::Ng_Mesh* ngMesh() { return (nglib::Ng_Mesh*)(void*)_ngMesh; }
static int GenerateMesh(netgen::OCCGeometry& occgeo, int startWith, int endWith,
netgen::Mesh* & ngMesh);
int GenerateMesh(netgen::OCCGeometry& occgeo, int startWith, int endWith )
{
return GenerateMesh( occgeo, startWith, endWith, _ngMesh );
}
static void CalcLocalH( netgen::Mesh * ngMesh );
static void RemoveTmpFiles();

View File

@ -32,6 +32,9 @@
#include "NETGENPlugin_Hypothesis.hxx"
// TODO: remove use of netgen_param
#include "NETGENPlugin_DriverParam.hxx"
#include <SMDS_MeshElement.hxx>
#include <SMDS_MeshNode.hxx>
#include <SMESHDS_Mesh.hxx>
@ -45,6 +48,8 @@
#include <StdMeshers_MaxElementVolume.hxx>
#include <StdMeshers_QuadToTriaAdaptor.hxx>
#include <StdMeshers_ViscousLayers.hxx>
#include <SMESH_subMesh.hxx>
#include <BRepGProp.hxx>
#include <BRep_Tool.hxx>
@ -63,6 +68,8 @@
#include <vector>
#include <map>
#include <cstdlib>
/*
Netgen include files
*/
@ -143,8 +150,8 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh,
_maxElementVolume = DBL_MAX;
// for correct work of GetProgress():
netgen::multithread.percent = 0.;
netgen::multithread.task = "Volume meshing";
//netgen::multithread.percent = 0.;
//netgen::multithread.task = "Volume meshing";
_progressByTic = -1.;
list<const SMESHDS_Hypothesis*>::const_iterator itl;
@ -186,71 +193,33 @@ bool NETGENPlugin_NETGEN_3D::CheckHypothesis (SMESH_Mesh& aMesh,
return aStatus == HYP_OK;
}
//=============================================================================
/*!
*Here we are going to use the NETGEN mesher
*/
//=============================================================================
bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
{
netgen::multithread.terminate = 0;
netgen::multithread.task = "Volume meshing";
_progressByTic = -1.;
/**
* @brief Get an iterator on the Surface element with their orientation
*
*/
bool NETGENPlugin_NETGEN_3D::getSurfaceElements(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
)
{
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
SMESH_MesherHelper helper(aMesh);
_quadraticMesh = helper.IsQuadraticSubMesh(aShape);
helper.SetElementsOnShape( true );
int Netgen_NbOfNodes = 0;
double Netgen_point[3];
int Netgen_triangle[3];
NETGENPlugin_NetgenLibWrapper ngLib;
Ng_Mesh * Netgen_mesh = (Ng_Mesh*)ngLib._ngMesh;
// vector of nodes in which node index == netgen ID
vector< const SMDS_MeshNode* > nodeVec;
{
const int invalid_ID = -1;
SMESH::Controls::Area areaControl;
SMESH::Controls::TSequenceOfXYZ nodesCoords;
// maps nodes to ng ID
typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
typedef TNodeToIDMap::value_type TN2ID;
TNodeToIDMap nodeToNetgenID;
// find internal shapes
NETGENPlugin_Internals internals( aMesh, aShape, /*is3D=*/true );
// ---------------------------------
// Feed the Netgen with surface mesh
// ---------------------------------
TopAbs_ShapeEnum mainType = aMesh.GetShapeToMesh().ShapeType();
bool checkReverse = ( mainType == TopAbs_COMPOUND || mainType == TopAbs_COMPSOLID );
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
if ( _viscousLayersHyp )
{
netgen::multithread.percent = 3;
proxyMesh = _viscousLayersHyp->Compute( aMesh, aShape );
if ( !proxyMesh )
return false;
}
if ( aMesh.NbQuadrangles() > 0 )
{
netgen::multithread.percent = 6;
StdMeshers_QuadToTriaAdaptor* Adaptor = new StdMeshers_QuadToTriaAdaptor;
Adaptor->Compute(aMesh,aShape,proxyMesh.get());
proxyMesh.reset( Adaptor );
}
for ( TopExp_Explorer exFa( aShape, TopAbs_FACE ); exFa.More(); exFa.Next())
{
const TopoDS_Shape& aShapeFace = exFa.Current();
@ -267,7 +236,7 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
if ( !aSubMeshDSFace ) continue;
SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
if ( _quadraticMesh &&
if ( aParams._quadraticMesh &&
dynamic_cast< const SMESH_ProxyMesh::SubMesh*>( aSubMeshDSFace ))
{
// add medium nodes of proxy triangles to helper (#16843)
@ -276,15 +245,96 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
iteratorElem = aSubMeshDSFace->GetElements();
}
while ( iteratorElem->more() ) // loop on elements on a geom face
{
// check mesh face
while(iteratorElem->more()){
const SMDS_MeshElement* elem = iteratorElem->next();
if ( !elem )
return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
if ( elem->NbCornerNodes() != 3 )
return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
// check mesh face
if ( !elem ){
aParams._error = COMPERR_BAD_INPUT_MESH;
aParams._comment = "Null element encounters";
return true;
}
if ( elem->NbCornerNodes() != 3 ){
aParams._error = COMPERR_BAD_INPUT_MESH;
aParams._comment = "Not triangle element encounters";
return true;
}
listElements[elem] = tuple(isRev, isInternalFace);
}
}
return false;
}
bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
SMESH_MesherHelper &helper,
netgen_params &aParams,
int &Netgen_NbOfNodes)
{
netgen::multithread.terminate = 0;
netgen::multithread.task = "Volume meshing";
aParams._progressByTic = -1.;
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
aParams._quadraticMesh = helper.IsQuadraticSubMesh(aShape);
helper.SetElementsOnShape( true );
Netgen_NbOfNodes = 0;
double Netgen_point[3];
int Netgen_triangle[3];
Ng_Mesh * Netgen_mesh = (Ng_Mesh*)ngLib._ngMesh;
{
const int invalid_ID = -1;
SMESH::Controls::Area areaControl;
SMESH::Controls::TSequenceOfXYZ nodesCoords;
// maps nodes to ng ID
typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
typedef TNodeToIDMap::value_type TN2ID;
TNodeToIDMap nodeToNetgenID;
// find internal shapes
NETGENPlugin_Internals internals( aMesh, aShape, /*is3D=*/true );
// ---------------------------------
// Feed the Netgen with surface mesh
// ---------------------------------
bool isRev=false;
bool isInternalFace=false;
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
if ( aParams._viscousLayersHyp )
{
netgen::multithread.percent = 3;
proxyMesh = aParams._viscousLayersHyp->Compute( aMesh, aShape );
if ( !proxyMesh )
return false;
}
if ( aMesh.NbQuadrangles() > 0 )
{
netgen::multithread.percent = 6;
StdMeshers_QuadToTriaAdaptor* Adaptor = new StdMeshers_QuadToTriaAdaptor;
Adaptor->Compute(aMesh,aShape,proxyMesh.get());
proxyMesh.reset( Adaptor );
}
std::map<const SMDS_MeshElement*, tuple<bool, bool>> listElements;
bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, aParams, listElements);
if(ret)
return ret;
for ( auto const& [elem, info] : listElements ) // loop on elements on a geom face
{
isRev = get<0>(info);
isInternalFace = get<1>(info);
// Add nodes of triangles and triangles them-selves to netgen mesh
// add three nodes of triangle
@ -326,7 +376,6 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
Ng_AddSurfaceElement(Netgen_mesh, NG_TRIG, Netgen_triangle);
}
} // loop on elements on a face
} // loop on faces of a SOLID or SHELL
// insert old nodes into nodeVec
nodeVec.resize( nodeToNetgenID.size() + 1, 0 );
@ -344,85 +393,228 @@ bool NETGENPlugin_NETGEN_3D::Compute(SMESH_Mesh& aMesh,
internals);
}
}
// -------------------------
// Generate the volume mesh
// -------------------------
return ( ngLib._isComputeOk = compute( aMesh, helper, nodeVec, ngLib ));
Netgen_NbOfNodes = Ng_GetNP( Netgen_mesh );
return false;
}
// namespace
// {
// void limitVolumeSize( netgen::Mesh* ngMesh,
// double maxh )
// {
// // get average h of faces
// double faceh = 0;
// int nbh = 0;
// for (int i = 1; i <= ngMesh->GetNSE(); i++)
// {
// const netgen::Element2d& face = ngMesh->SurfaceElement(i);
// for (int j=1; j <= face.GetNP(); ++j)
// {
// const netgen::PointIndex & i1 = face.PNumMod(j);
// const netgen::PointIndex & i2 = face.PNumMod(j+1);
// if ( i1 < i2 )
// {
// const netgen::Point3d & p1 = ngMesh->Point( i1 );
// const netgen::Point3d & p2 = ngMesh->Point( i2 );
// faceh += netgen::Dist2( p1, p2 );
// nbh++;
// }
// }
// }
// faceh = Sqrt( faceh / nbh );
bool NETGENPlugin_NETGEN_3D::computePrepareParam(
SMESH_Mesh& aMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen::OCCGeometry &occgeo,
SMESH_MesherHelper &helper,
netgen_params &aParams,
int &endWith)
// double compareh;
// if ( faceh < 0.5 * maxh ) compareh = -1;
// else if ( faceh > 1.5 * maxh ) compareh = 1;
// else compareh = 0;
// // cerr << "faceh " << faceh << endl;
// // cerr << "init maxh " << maxh << endl;
// // cerr << "compareh " << compareh << endl;
{
netgen::multithread.terminate = 0;
// if ( compareh > 0 )
// maxh *= 1.2;
// else
// maxh *= 0.8;
// // cerr << "maxh " << maxh << endl;
netgen::Mesh* ngMesh = ngLib._ngMesh;
// // get bnd box
// netgen::Point3d pmin, pmax;
// ngMesh->GetBox( pmin, pmax, 0 );
// const double dx = pmax.X() - pmin.X();
// const double dy = pmax.Y() - pmin.Y();
// const double dz = pmax.Z() - pmin.Z();
NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true );
// if ( ! & ngMesh->LocalHFunction() )
// ngMesh->SetLocalH( pmin, pmax, compareh <= 0 ? 0.1 : 0.5 );
// // adjusted by SALOME_TESTS/Grids/smesh/bugs_08/I8
// const int nbX = Max( 2, int( dx / maxh * 2 ));
// const int nbY = Max( 2, int( dy / maxh * 2 ));
// const int nbZ = Max( 2, int( dz / maxh * 2 ));
if ( aParams._hypParameters )
{
aMesher.SetParameters( aParams._hypParameters );
// netgen::Point3d p;
// for ( int i = 0; i <= nbX; ++i )
// {
// p.X() = pmin.X() + i * dx / nbX;
// for ( int j = 0; j <= nbY; ++j )
// {
// p.Y() = pmin.Y() + j * dy / nbY;
// for ( int k = 0; k <= nbZ; ++k )
// {
// p.Z() = pmin.Z() + k * dz / nbZ;
// ngMesh->RestrictLocalH( p, maxh );
// }
// }
// }
// }
// }
if ( !aParams._hypParameters->GetLocalSizesAndEntries().empty() ||
!aParams._hypParameters->GetMeshSizeFile().empty() )
{
if ( ! &ngMesh->LocalHFunction() )
{
netgen::Point3d pmin, pmax;
ngMesh->GetBox( pmin, pmax, 0 );
ngMesh->SetLocalH( pmin, pmax, aParams._hypParameters->GetGrowthRate() );
}
aMesher.SetLocalSize( occgeo, *ngMesh );
try {
ngMesh->LoadLocalMeshSize( netgen::mparam.meshsizefilename );
} catch (netgen::NgException & ex) {
aParams._error = COMPERR_BAD_PARMETERS;
aParams._comment = ex.What();
return false;
}
}
if ( !aParams._hypParameters->GetOptimize() )
endWith = netgen::MESHCONST_MESHVOLUME;
}
else if ( aParams._hypMaxElementVolume )
{
netgen::mparam.maxh = pow( 72, 1/6. ) * pow( aParams.maxElementVolume, 1/3. );
// limitVolumeSize( ngMesh, mparam.maxh ); // result is unpredictable
}
else if ( aMesh.HasShapeToMesh() )
{
aMesher.PrepareOCCgeometry( occgeo, helper.GetSubShape(), aMesh );
netgen::mparam.maxh = occgeo.GetBoundingBox().Diam()/2;
}
else
{
netgen::Point3d pmin, pmax;
ngMesh->GetBox (pmin, pmax);
netgen::mparam.maxh = Dist(pmin, pmax)/2;
}
if ( !aParams._hypParameters && aMesh.HasShapeToMesh() )
{
netgen::mparam.minh = aMesher.GetDefaultMinSize( helper.GetSubShape(), netgen::mparam.maxh );
}
return false;
}
bool NETGENPlugin_NETGEN_3D::computeRunMesher(
netgen::OCCGeometry &occgeo,
vector< const SMDS_MeshNode* > &nodeVec,
netgen::Mesh* ngMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen_params &aParams,
int &startWith, int &endWith)
{
int err = 1;
try
{
OCC_CATCH_SIGNALS;
ngLib.CalcLocalH(ngMesh);
err = ngLib.GenerateMesh(occgeo, startWith, endWith);
if(netgen::multithread.terminate)
return false;
if ( err ){
aParams._comment = SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task;
return true;
}
}
catch (Standard_Failure& ex)
{
SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
str << " at " << netgen::multithread.task
<< ": " << ex.DynamicType()->Name();
if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
str << ": " << ex.GetMessageString();
aParams._comment = str;
return true;
}
catch (netgen::NgException& exc)
{
SMESH_Comment str("NgException");
if ( strlen( netgen::multithread.task ) > 0 )
str << " at " << netgen::multithread.task;
str << ": " << exc.What();
aParams._comment = str;
return true;
}
catch (...)
{
SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
if ( strlen( netgen::multithread.task ) > 0 )
str << " at " << netgen::multithread.task;
aParams._comment = str;
return true;
}
if ( err )
{
SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::ReadErrors(nodeVec);
if ( ce && ce->HasBadElems() ){
aParams._error = ce->myName;
aParams._comment = ce->myComment;
return true;
}
}
return false;
}
bool NETGENPlugin_NETGEN_3D::computeFillMesh(
vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
SMESH_MesherHelper &helper,
int &Netgen_NbOfNodes
)
{
Ng_Mesh* Netgen_mesh = ngLib.ngMesh();
int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh);
int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh);
bool isOK = ( /*status == NG_OK &&*/ Netgen_NbOfTetra > 0 );// get whatever built
if ( isOK )
{
double Netgen_point[3];
int Netgen_tetrahedron[4];
// create and insert new nodes into nodeVec
nodeVec.resize( Netgen_NbOfNodesNew + 1, 0 );
int nodeIndex = Netgen_NbOfNodes + 1;
for ( ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
{
Ng_GetPoint( Netgen_mesh, nodeIndex, Netgen_point );
nodeVec.at(nodeIndex) = helper.AddNode(Netgen_point[0], Netgen_point[1], Netgen_point[2]);
}
// create tetrahedrons
for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
{
Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
try
{
helper.AddVolume (nodeVec.at( Netgen_tetrahedron[0] ),
nodeVec.at( Netgen_tetrahedron[1] ),
nodeVec.at( Netgen_tetrahedron[2] ),
nodeVec.at( Netgen_tetrahedron[3] ));
}
catch (...)
{
}
}
}
return false;
}
bool NETGENPlugin_NETGEN_3D::Compute(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
{
// vector of nodes in which node index == netgen ID
vector< const SMDS_MeshNode* > nodeVec;
NETGENPlugin_NetgenLibWrapper ngLib;
SMESH_MesherHelper helper(aMesh);
int startWith = netgen::MESHCONST_MESHVOLUME;
int endWith = netgen::MESHCONST_OPTVOLUME;
int Netgen_NbOfNodes;
netgen_params aParams;
aParams._hypParameters = const_cast<NETGENPlugin_Hypothesis*>(_hypParameters);
aParams._hypMaxElementVolume = const_cast<StdMeshers_MaxElementVolume*>(_hypMaxElementVolume);
aParams.maxElementVolume = _maxElementVolume;
aParams._progressByTic = _progressByTic;
aParams._quadraticMesh = _quadraticMesh;
aParams._viscousLayersHyp = const_cast<StdMeshers_ViscousLayers*>(_viscousLayersHyp);
bool ret;
ret = computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, aParams, Netgen_NbOfNodes);
if(ret)
return error( aParams._error, aParams._comment);
netgen::OCCGeometry occgeo;
computePrepareParam(aMesh, ngLib, occgeo, helper, aParams, endWith);
ret = computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, aParams, startWith, endWith);
if(ret){
if(aParams._error)
return error(aParams._error, aParams._comment);
error(aParams._comment);
return true;
}
computeFillMesh(nodeVec, ngLib, helper, Netgen_NbOfNodes);
return false;
}
//================================================================================
/*!
@ -475,7 +667,7 @@ bool NETGENPlugin_NETGEN_3D::compute(SMESH_Mesh& aMesh,
else if ( _hypMaxElementVolume )
{
netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. );
// limitVolumeSize( ngMesh, netgen::mparam.maxh ); // result is unpredictable
// limitVolumeSize( ngMesh, mparam.maxh ); // result is unpredictable
}
else if ( aMesh.HasShapeToMesh() )
{
@ -701,14 +893,12 @@ double NETGENPlugin_NETGEN_3D::GetProgress() const
strncmp( netgen::multithread.task, volMeshing, 3 ) == 0 ))
{
res = 0.001 + meshingRatio * netgen::multithread.percent / 100.;
//cout << netgen::multithread.task << " " <<_progressTic << "-" << netgen::multithread.percent << endl;
}
else // different otimizations
{
if ( _progressByTic < 0. )
((NETGENPlugin_NETGEN_3D*)this)->_progressByTic = meshingRatio / _progressTic;
res = _progressByTic * _progressTic;
//cout << netgen::multithread.task << " " << _progressTic << " " << res << endl;
}
return Min ( res, 0.98 );
}

View File

@ -37,10 +37,15 @@
#include "SMESH_Algo.hxx"
#include "Utils_SALOME_Exception.hxx"
#include <vector>
#include <tuple>
class StdMeshers_ViscousLayers;
class StdMeshers_MaxElementVolume;
class NETGENPlugin_Hypothesis;
class NETGENPlugin_NetgenLibWrapper;
class netgen_params;
class SMDS_MeshNode;
class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo
{
@ -66,8 +71,48 @@ class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D: public SMESH_3D_Algo
const TopoDS_Shape& aShape,
MapShapeNbElems& aResMap);
bool computeFillNgMesh(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
SMESH_MesherHelper &helper,
netgen_params &aParams,
int &Netgen_NbOfNodes);
bool computePrepareParam(
SMESH_Mesh& aMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen::OCCGeometry &occgeo,
SMESH_MesherHelper &helper,
netgen_params &aParams,
int &endWith);
bool computeRunMesher(
netgen::OCCGeometry &occgeo,
std::vector< const SMDS_MeshNode* > &nodeVec,
netgen::Mesh* ngMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen_params &aParams,
int &startWith, int &endWith);
bool computeFillMesh(
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
SMESH_MesherHelper &helper,
int &Netgen_NbOfNodes);
protected:
virtual bool getSurfaceElements(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
netgen_params &aParams,
std::map<const SMDS_MeshElement*, std::tuple<bool, bool>>& listElements);
bool compute(SMESH_Mesh& mesh,
SMESH_MesherHelper& helper,
std::vector< const SMDS_MeshNode* >& nodeVec,

View File

@ -0,0 +1,350 @@
// 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_NETGEN_3D_Remote.cxx
// Created : lundi 19 Septembre 2022
// Author : Yoann AUDOUIN (CEA)
// Project : SALOME
//=============================================================================
//
//
#include "NETGENPlugin_NETGEN_3D_Remote.hxx"
#include "NETGENPlugin_NETGEN_3D.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include "NETGENPlugin_Hypothesis.hxx"
#include <SMESH_Gen.hxx>
#include <SMESH_Mesh.hxx>
#include <SMESH_MesherHelper.hxx>
#include <SMESH_DriverShape.hxx>
#include <SMESH_DriverMesh.hxx>
#include <SMESHDS_Mesh.hxx>
#include <QString>
#include <QProcess>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
/*
Netgen include files
*/
#ifndef OCCGEOMETRY
#define OCCGEOMETRY
#endif
#include <occgeom.hpp>
#ifdef NETGEN_V5
#include <ngexception.hpp>
#endif
#ifdef NETGEN_V6
#include <core/exception.hpp>
#endif
namespace nglib {
#include <nglib.h>
}
namespace netgen {
NETGENPLUGIN_DLL_HEADER
extern MeshingParameters mparam;
NETGENPLUGIN_DLL_HEADER
extern volatile multithreadt multithread;
}
using namespace nglib;
//=============================================================================
/*!
*
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_Remote::NETGENPlugin_NETGEN_3D_Remote(int hypId, SMESH_Gen * gen)
: NETGENPlugin_NETGEN_3D(hypId, gen)
{
_name = "NETGEN_3D_Remote";
}
//=============================================================================
/*!
*
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_Remote::~NETGENPlugin_NETGEN_3D_Remote()
{
}
void NETGENPlugin_NETGEN_3D_Remote::fillParameters(const NETGENPlugin_Hypothesis* hyp, netgen_params &aParams)
{
aParams.maxh = hyp->GetMaxSize();
aParams.minh = hyp->GetMinSize();
aParams.segmentsperedge = hyp->GetNbSegPerEdge();
aParams.grading = hyp->GetGrowthRate();
aParams.curvaturesafety = hyp->GetNbSegPerRadius();
aParams.secondorder = hyp->GetSecondOrder() ? 1 : 0;
aParams.quad = hyp->GetQuadAllowed() ? 1 : 0;
aParams.optimize = hyp->GetOptimize();
aParams.fineness = hyp->GetFineness();
aParams.uselocalh = hyp->GetSurfaceCurvature();
aParams.merge_solids = hyp->GetFuseEdges();
aParams.chordalError = hyp->GetChordalErrorEnabled() ? hyp->GetChordalError() : -1.;
aParams.optsteps2d = aParams.optimize ? hyp->GetNbSurfOptSteps() : 0;
aParams.optsteps3d = aParams.optimize ? hyp->GetNbVolOptSteps() : 0;
aParams.elsizeweight = hyp->GetElemSizeWeight();
aParams.opterrpow = hyp->GetWorstElemMeasure();
aParams.delaunay = hyp->GetUseDelauney();
aParams.checkoverlap = hyp->GetCheckOverlapping();
aParams.checkchartboundary = hyp->GetCheckChartBoundary();
#ifdef NETGEN_V6
// std::string
aParams.meshsizefilename = hyp->GetMeshSizeFile();
#else
// const char*
aParams.meshsizefilename = hyp->GetMeshSizeFile();
#endif
#ifdef NETGEN_V6
aParams.closeedgefac = 2;
#else
aParams.closeedgefac = 0;
#endif
}
// write in a binary file the orientation for each 2D element of the mesh
void NETGENPlugin_NETGEN_3D_Remote::exportElementOrientation(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
netgen_params& aParams,
const std::string output_file)
{
SMESH_MesherHelper helper(aMesh);
NETGENPlugin_Internals internals( aMesh, aShape, /*is3D=*/true );
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
std::map<vtkIdType, bool> elemOrientation;
for ( TopExp_Explorer exFa( aShape, TopAbs_FACE ); exFa.More(); exFa.Next())
{
const TopoDS_Shape& aShapeFace = exFa.Current();
int faceID = aMesh.GetMeshDS()->ShapeToIndex( aShapeFace );
bool isInternalFace = internals.isInternalShape( faceID );
bool isRev = false;
if ( !isInternalFace &&
helper.NbAncestors(aShapeFace, aMesh, aShape.ShapeType()) > 1 )
// IsReversedSubMesh() can work wrong on strongly curved faces,
// so we use it as less as possible
isRev = helper.IsReversedSubMesh( TopoDS::Face( aShapeFace ));
const SMESHDS_SubMesh * aSubMeshDSFace = proxyMesh->GetSubMesh( aShapeFace );
if ( !aSubMeshDSFace ) continue;
SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
if ( aParams._quadraticMesh &&
dynamic_cast< const SMESH_ProxyMesh::SubMesh*>( aSubMeshDSFace ))
{
// add medium nodes of proxy triangles to helper (#16843)
while ( iteratorElem->more() )
helper.AddTLinks( static_cast< const SMDS_MeshFace* >( iteratorElem->next() ));
iteratorElem = aSubMeshDSFace->GetElements();
}
while ( iteratorElem->more() ) // loop on elements on a geom face
{
// check mesh face
const SMDS_MeshElement* elem = iteratorElem->next();
if ( !elem )
error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
if ( elem->NbCornerNodes() != 3 )
error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
elemOrientation[elem->GetID()] = isRev;
} // loop on elements on a face
} // loop on faces of a SOLID or SHELL
{
std::ofstream df(output_file, ios::out|ios::binary);
int size=elemOrientation.size();
df.write((char*)&size, sizeof(int));
for(auto const& [id, orient]:elemOrientation){
df.write((char*)&id, sizeof(vtkIdType));
df.write((char*)&orient, sizeof(bool));
}
}
}
bool NETGENPlugin_NETGEN_3D_Remote::Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
{
aMesh.Lock();
SMESH_Hypothesis::Hypothesis_Status hypStatus;
NETGENPlugin_NETGEN_3D::CheckHypothesis(aMesh, aShape, hypStatus);
// Temporary folder for run
fs::path tmp_folder = aMesh.tmp_folder / fs::unique_path(fs::path("Volume-%%%%-%%%%"));
fs::create_directories(tmp_folder);
// Using MESH2D generated after all triangles where created.
fs::path mesh_file=aMesh.tmp_folder / fs::path("Mesh2D.med");
fs::path element_orientation_file=tmp_folder / fs::path("element_orientation.dat");
fs::path new_element_file=tmp_folder / fs::path("new_elements.dat");
fs::path tmp_mesh_file=tmp_folder / fs::path("tmp_mesh.med");
// Not used kept for debug
//fs::path output_mesh_file=tmp_folder / fs::path("output_mesh.med");
fs::path shape_file=tmp_folder / fs::path("shape.brep");
fs::path param_file=tmp_folder / fs::path("netgen3d_param.txt");
fs::path log_file=tmp_folder / fs::path("run.log");
fs::path cmd_file=tmp_folder / fs::path("cmd.log");
//TODO: Handle variable mesh_name
std::string mesh_name = "MESH";
//Writing Shape
exportShape(shape_file.string(), aShape);
//Writing hypo
netgen_params aParams;
fillParameters(_hypParameters, aParams);
exportNetgenParams(param_file.string(), aParams);
// Exporting element orientation
exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string());
aMesh.Unlock();
// Calling run_mesher
// TODO: check if we need to handle the .exe for windows
std::string cmd;
fs::path run_mesher_exe =
fs::path(std::getenv("NETGENPLUGIN_ROOT_DIR"))/
fs::path("bin")/
fs::path("salome")/
fs::path("NETGENPlugin_Runner");
cmd = run_mesher_exe.string() +
" NETGEN3D " + mesh_file.string() + " "
+ shape_file.string() + " "
+ param_file.string() + " "
+ element_orientation_file.string() + " "
+ std::to_string(aMesh.GetMesherNbThreads()) + " "
+ new_element_file.string() + " "
+ "NONE";
// Writing command in log
{
std::ofstream flog(cmd_file.string());
flog << cmd << endl;
flog << endl;
}
MESSAGE("Running command: ");
MESSAGE(cmd);
// Building arguments for QProcess
QString program = run_mesher_exe.c_str();
QStringList arguments;
arguments << "NETGEN3D";
arguments << mesh_file.c_str();
arguments << shape_file.c_str();
arguments << param_file.c_str();
arguments << element_orientation_file.c_str();
arguments << std::to_string(aMesh.GetMesherNbThreads()).c_str();
arguments << new_element_file.c_str();
arguments << "NONE";
QString out_file = log_file.c_str();
QProcess myProcess;
myProcess.setStandardOutputFile(out_file);
myProcess.start(program, arguments);
myProcess.waitForFinished();
int ret = myProcess.exitStatus();
if(ret != 0){
// Run crahed
std::cerr << "Issue with command: " << std::endl;
std::cerr << "See log for more details: " << log_file.string() << std::endl;
std::cerr << cmd << std::endl;
return false;
}
aMesh.Lock();
{
std::ifstream df(new_element_file.string(), ios::binary);
int Netgen_NbOfNodes;
int Netgen_NbOfNodesNew;
int Netgen_NbOfTetra;
double Netgen_point[3];
int Netgen_tetrahedron[4];
int nodeID;
SMESH_MesherHelper helper(aMesh);
// This function is mandatory for setElementsOnShape to work
helper.IsQuadraticSubMesh(aShape);
helper.SetElementsOnShape( true );
// Number of nodes in intial mesh
df.read((char*) &Netgen_NbOfNodes, sizeof(int));
// Number of nodes added by netgen
df.read((char*) &Netgen_NbOfNodesNew, sizeof(int));
// Filling nodevec (correspondence netgen numbering mesh numbering)
vector< const SMDS_MeshNode* > nodeVec ( Netgen_NbOfNodesNew + 1 );
//vector<int> nodeTmpVec ( Netgen_NbOfNodesNew + 1 );
SMESHDS_Mesh * meshDS = helper.GetMeshDS();
for (int nodeIndex = 1 ; nodeIndex <= Netgen_NbOfNodes; ++nodeIndex )
{
//Id of the point
df.read((char*) &nodeID, sizeof(int));
nodeVec.at(nodeIndex) = meshDS->FindNode(nodeID);
}
// Add new points and update nodeVec
for (int nodeIndex = Netgen_NbOfNodes +1 ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
{
df.read((char *) &Netgen_point, sizeof(double)*3);
nodeVec.at(nodeIndex) = helper.AddNode(Netgen_point[0],
Netgen_point[1],
Netgen_point[2]);
}
// Add tetrahedrons
df.read((char*) &Netgen_NbOfTetra, sizeof(int));
for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
{
df.read((char*) &Netgen_tetrahedron, sizeof(int)*4);
helper.AddVolume(
nodeVec.at( Netgen_tetrahedron[0] ),
nodeVec.at( Netgen_tetrahedron[1] ),
nodeVec.at( Netgen_tetrahedron[2] ),
nodeVec.at( Netgen_tetrahedron[3] ));
}
}
aMesh.Unlock();
return true;
}

View File

@ -0,0 +1,74 @@
// 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_NETGEN_3D_Remote.hxx
// Created : lundi 19 Septembre 2022
// Author : Yoann AUDOUIN (EDF)
// Project : SALOME
//=============================================================================
//
#ifndef _NETGENPlugin_NETGEN_3D_REMOTE_HXX_
#define _NETGENPlugin_NETGEN_3D_REMOTE_HXX_
#include "NETGENPlugin_NETGEN_3D.hxx"
#include <vector>
#include <map>
class StdMeshers_ViscousLayers;
class StdMeshers_MaxElementVolume;
class NETGENPlugin_Hypothesis;
class NETGENPlugin_NetgenLibWrapper;
class netgen_params;
class SMDS_MeshNode;
using namespace std;
class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D_Remote: public NETGENPlugin_NETGEN_3D
{
public:
NETGENPlugin_NETGEN_3D_Remote(int hypId, SMESH_Gen* gen);
virtual ~NETGENPlugin_NETGEN_3D_Remote();
// Function whould not be used with remote Computing
bool CheckHypothesis (SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
Hypothesis_Status& aStatus){aStatus = HYP_OK;return true;};
bool Compute(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape);
protected:
void exportElementOrientation(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
netgen_params& aParams,
const std::string output_file);
void fillParameters(const NETGENPlugin_Hypothesis* hyp,
netgen_params &aParams);
};
#endif

View File

@ -0,0 +1,80 @@
// 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
//
// SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
// File : NETGENPlugin_NETGEN_3D_Remote_i.cxx
// Author : Yoann AUDOUIN (EDF)
// Module : NETGENPlugin
// $Header$
//
#include "NETGENPlugin_NETGEN_3D_Remote_i.hxx"
#include "SMESH_Gen.hxx"
#include "Utils_CorbaException.hxx"
#include "utilities.h"
using namespace std;
//=============================================================================
/*!
* NETGENPlugin_NETGEN_3D_Remote_i::NETGENPlugin_NETGEN_3D_Remote_i
*
* Constructor
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_Remote_i::NETGENPlugin_NETGEN_3D_Remote_i( PortableServer::POA_ptr thePOA,
::SMESH_Gen* theGenImpl )
: SALOME::GenericObj_i( thePOA ),
SMESH_Hypothesis_i( thePOA ),
SMESH_Algo_i( thePOA ),
SMESH_3D_Algo_i( thePOA )
{
myBaseImpl = new ::NETGENPlugin_NETGEN_3D_Remote( theGenImpl->GetANewId(),
theGenImpl );
}
//=============================================================================
/*!
* NETGENPlugin_NETGEN_3D_Remote_i::~NETGENPlugin_NETGEN_3D_Remote_i
*
* Destructor
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_Remote_i::~NETGENPlugin_NETGEN_3D_Remote_i()
{
}
//=============================================================================
/*!
* NETGENPlugin_NETGEN_3D_Remote_i::GetImpl
*
* Get implementation
*/
//=============================================================================
::NETGENPlugin_NETGEN_3D_Remote* NETGENPlugin_NETGEN_3D_Remote_i::GetImpl()
{
return ( ::NETGENPlugin_NETGEN_3D_Remote* )myBaseImpl;
}

View File

@ -0,0 +1,58 @@
// 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
//
// SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
// File : NETGENPlugin_NETGEN_3D_Remote_i.hxx
// Author : Yoann AUDOUIN (EDF)
// Module : NETGENPlugin
// $Header$
//
#ifndef _NETGENPlugin_NETGEN_3D_REMOTE_I_HXX_
#define _NETGENPlugin_NETGEN_3D_REMOTE_I_HXX_
#include "NETGENPlugin_Defs.hxx"
#include <SALOMEconfig.h>
#include CORBA_SERVER_HEADER(NETGENPlugin_Algorithm)
#include "SMESH_3D_Algo_i.hxx"
#include "NETGENPlugin_NETGEN_3D_Remote.hxx"
// ======================================================
// NETGEN 3d algorithm
// ======================================================
class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D_Remote_i:
public virtual POA_NETGENPlugin::NETGENPlugin_NETGEN_3D_Remote,
public virtual SMESH_3D_Algo_i
{
public:
// Constructor
NETGENPlugin_NETGEN_3D_Remote_i( PortableServer::POA_ptr thePOA,
::SMESH_Gen* theGenImpl );
// Destructor
virtual ~NETGENPlugin_NETGEN_3D_Remote_i();
// Get implementation
::NETGENPlugin_NETGEN_3D_Remote* GetImpl();
};
#endif

View File

@ -0,0 +1,315 @@
// 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_NETGEN_3D_SA.cxx
// Created : lundi 19 Septembre 2022
// Author : Yoann AUDOUIN (CEA)
// Project : SALOME
//=============================================================================
//
//
#include "NETGENPlugin_NETGEN_3D_SA.hxx"
#include "NETGENPlugin_DriverParam.hxx"
#include "NETGENPlugin_Hypothesis.hxx"
#include <SMESH_Gen.hxx>
#include <SMESH_Mesh.hxx>
#include <SMESH_MesherHelper.hxx>
#include <SMESH_DriverShape.hxx>
#include <SMESH_DriverMesh.hxx>
#include <SMESHDS_Mesh.hxx>
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
/*
Netgen include files
*/
#ifndef OCCGEOMETRY
#define OCCGEOMETRY
#endif
#include <occgeom.hpp>
#ifdef NETGEN_V5
#include <ngexception.hpp>
#endif
#ifdef NETGEN_V6
#include <core/exception.hpp>
#endif
namespace nglib {
#include <nglib.h>
}
namespace netgen {
NETGENPLUGIN_DLL_HEADER
extern MeshingParameters mparam;
NETGENPLUGIN_DLL_HEADER
extern volatile multithreadt multithread;
}
using namespace nglib;
//=============================================================================
/*!
*
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_SA::NETGENPlugin_NETGEN_3D_SA()
: NETGENPlugin_NETGEN_3D(0, _gen=new SMESH_Gen())
{
_name = "NETGEN_3D_SA";
}
//=============================================================================
/*!
*
*/
//=============================================================================
NETGENPlugin_NETGEN_3D_SA::~NETGENPlugin_NETGEN_3D_SA()
{
if(_gen)
delete _gen;
}
bool NETGENPlugin_NETGEN_3D_SA::computeFillNewElementFile(
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
std::string new_element_file,
int &Netgen_NbOfNodes
)
{
Ng_Mesh* Netgen_mesh = ngLib.ngMesh();
int Netgen_NbOfNodesNew = Ng_GetNP(Netgen_mesh);
int Netgen_NbOfTetra = Ng_GetNE(Netgen_mesh);
bool isOK = ( Netgen_NbOfTetra > 0 );
if ( isOK && !new_element_file.empty() )
{
std::ofstream df(new_element_file, ios::out|ios::binary);
double Netgen_point[3];
int Netgen_tetrahedron[4];
// Writing nodevec (correspondence netgen numbering mesh numbering)
// Number of nodes
df.write((char*) &Netgen_NbOfNodes, sizeof(int));
df.write((char*) &Netgen_NbOfNodesNew, sizeof(int));
for (int nodeIndex = 1 ; nodeIndex <= Netgen_NbOfNodes; ++nodeIndex )
{
//Id of the point
int id = nodeVec.at(nodeIndex)->GetID();
df.write((char*) &id, sizeof(int));
}
// Writing info on new points
for (int nodeIndex = Netgen_NbOfNodes +1 ; nodeIndex <= Netgen_NbOfNodesNew; ++nodeIndex )
{
Ng_GetPoint(Netgen_mesh, nodeIndex, Netgen_point );
// Coordinates of the point
df.write((char *) &Netgen_point, sizeof(double)*3);
}
// create tetrahedrons
df.write((char*) &Netgen_NbOfTetra, sizeof(int));
for ( int elemIndex = 1; elemIndex <= Netgen_NbOfTetra; ++elemIndex )
{
Ng_GetVolumeElement(Netgen_mesh, elemIndex, Netgen_tetrahedron);
df.write((char*) &Netgen_tetrahedron, sizeof(int)*4);
}
}
return false;
}
bool NETGENPlugin_NETGEN_3D_SA::Compute(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
std::string new_element_file, std::string element_orientation_file,
bool output_mesh)
{
// vector of nodes in which node index == netgen ID
vector< const SMDS_MeshNode* > nodeVec;
NETGENPlugin_NetgenLibWrapper ngLib;
SMESH_MesherHelper helper(aMesh);
int startWith = netgen::MESHCONST_MESHVOLUME;
int endWith = netgen::MESHCONST_OPTVOLUME;
int Netgen_NbOfNodes=0;
bool ret;
ret = NETGENPlugin_NETGEN_3D::computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, aParams, Netgen_NbOfNodes);
if(ret)
return error( aParams._error, aParams._comment);
netgen::OCCGeometry occgeo;
NETGENPlugin_NETGEN_3D::computePrepareParam(aMesh, ngLib, occgeo, helper, aParams, endWith);
ret = NETGENPlugin_NETGEN_3D::computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, aParams, startWith, endWith);
if(ret){
if(aParams._error)
return error(aParams._error, aParams._comment);
error(aParams._comment);
return true;
}
computeFillNewElementFile(nodeVec, ngLib, new_element_file, Netgen_NbOfNodes);
if(output_mesh)
NETGENPlugin_NETGEN_3D::computeFillMesh(nodeVec, ngLib, helper, Netgen_NbOfNodes);
return false;
}
int NETGENPlugin_NETGEN_3D_SA::run(const std::string input_mesh_file,
const std::string shape_file,
const std::string hypo_file,
const std::string element_orientation_file,
const std::string new_element_file,
const std::string output_mesh_file,
int nbThreads)
{
_element_orientation_file = element_orientation_file;
// Importing mesh
SMESH_Gen gen;
std::unique_ptr<SMESH_Mesh> myMesh(gen.CreateMesh(false));
importMesh(input_mesh_file, *myMesh);
// Importing shape
TopoDS_Shape myShape;
importShape(shape_file, myShape);
// Importing hypothesis
netgen_params myParams;
importNetgenParams(hypo_file, myParams, &gen);
// Setting number of threads for netgen
myParams.nbThreads = nbThreads;
MESSAGE("Meshing with netgen3d");
int ret = Compute(myShape, *myMesh, myParams,
new_element_file, element_orientation_file,
!output_mesh_file.empty());
if(ret){
std::cerr << "Meshing failed" << std::endl;
return ret;
}
if(!output_mesh_file.empty()){
std::string meshName = "MESH";
exportMesh(output_mesh_file, *myMesh, meshName);
}
return ret;
}
bool NETGENPlugin_NETGEN_3D_SA::getSurfaceElements(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
)
{
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
// 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()){
MESSAGE("No element orientation file");
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 {
MESSAGE("Reading from elements from file: " << _element_orientation_file);
std::ifstream df(_element_orientation_file, ios::binary|ios::in);
int nbElement;
bool orient;
// Warning of the use of vtkIdType (I had issue when run_mesher was compiled with internal vtk) and salome not
// Sizeof was the same but how he othered the type was different
// Maybe using another type (uint64_t) instead would be better
vtkIdType id;
df.read((char*)&nbElement, sizeof(int));
for(int ielem=0;ielem<nbElement;++ielem){
df.read((char*) &id, sizeof(vtkIdType));
df.read((char*) &orient, sizeof(bool));
elemOrientation[id] = orient;
}
}
}
// Adding elements from Mesh
SMDS_ElemIteratorPtr iteratorElem = meshDS->elementsIterator(SMDSAbs_Face);
bool isRev;
bool isInternalFace = false;
bool isIn;
while ( iteratorElem->more() ) // loop on elements on a geom face
{
// check mesh face
const SMDS_MeshElement* elem = iteratorElem->next();
if ( !elem ){
aParams._error = COMPERR_BAD_INPUT_MESH;
aParams._comment = "Null element encounters";
return true;
}
if ( elem->NbCornerNodes() != 3 ){
aParams._error = COMPERR_BAD_INPUT_MESH;
aParams._comment = "Not triangle element encounters";
return true;
}
// Keeping only element that are in the element orientation file
isIn = elemOrientation.count(elem->GetID())==1;
if(!isIn)
continue;
// Get orientation
// Netgen requires that all the triangle point outside
isRev = elemOrientation[elem->GetID()];
listElements[elem] = tuple(isRev, false);
}
return false;
}

View File

@ -0,0 +1,88 @@
// 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_NETGEN_3D_SA.hxx
// Created : lundi 19 Septembre 2022
// Author : Yoann AUDOUIN (EDF)
// Project : SALOME
//=============================================================================
//
#ifndef _NETGENPlugin_NETGEN_3D_SA_HXX_
#define _NETGENPlugin_NETGEN_3D_SA_HXX_
#include "NETGENPlugin_NETGEN_3D.hxx"
#include <vector>
#include <map>
class NETGENPlugin_NetgenLibWrapper;
class netgen_params;
class SMDS_MeshNode;
class SMESH_Gen;
using namespace std;
class NETGENPLUGIN_EXPORT NETGENPlugin_NETGEN_3D_SA: public NETGENPlugin_NETGEN_3D
{
public:
NETGENPlugin_NETGEN_3D_SA();
virtual ~NETGENPlugin_NETGEN_3D_SA();
bool Compute(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
std::string new_element_file, std::string element_orientation_file,
bool output_mesh);
int run(const std::string input_mesh_file,
const std::string shape_file,
const std::string hypo_file,
const std::string element_orientation_file,
const std::string new_element_file,
const std::string output_mesh_file,
int nbThreads);
protected:
bool computeFillNewElementFile(
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
std::string new_element_file,
int &Netgen_NbOfNodes);
bool getSurfaceElements(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
);
std::string _element_orientation_file="";
SMESH_Gen *_gen=nullptr;
};
#endif

View File

@ -0,0 +1,101 @@
// 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_NETGEN_3D_SA.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];
//std::string thing;
//std::cin >> thing;
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();
NETGENPlugin_NETGEN_3D_SA myplugin;
myplugin.run(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 {
std::cerr << "Unknown mesher:" << mesher << std::endl;
}
return 0;
}

View File

@ -36,6 +36,7 @@
#include "NETGENPlugin_NETGEN_2D_ONLY_i.hxx"
#include "NETGENPlugin_NETGEN_2D_i.hxx"
#include "NETGENPlugin_NETGEN_3D_i.hxx"
#include "NETGENPlugin_NETGEN_3D_Remote_i.hxx"
#include "NETGENPlugin_SimpleHypothesis_2D_i.hxx"
#include "NETGENPlugin_SimpleHypothesis_3D_i.hxx"
@ -63,6 +64,8 @@ extern "C"
// Algorithms
if (strcmp(aHypName, "NETGEN_3D") == 0)
aCreator = new NETGENPlugin_Creator_i<NETGENPlugin_NETGEN_3D_i>;
else if (strcmp(aHypName, "NETGEN_3D_Remote") == 0)
aCreator = new NETGENPlugin_Creator_i<NETGENPlugin_NETGEN_3D_Remote_i>;
else if (strcmp(aHypName, "NETGEN_2D") == 0)
aCreator = new NETGENPlugin_Creator_i<NETGENPlugin_NETGEN_2D_i>;
else if (strcmp(aHypName, "NETGEN_2D_ONLY") == 0)