//
#include "NETGENPlugin_DriverParam.hxx"
-#include "NETGENPlugin_Hypothesis.hxx"
-
-#include <SMESH_Gen.hxx>
-#include <StdMeshers_MaxElementVolume.hxx>
#include <iostream>
#include <fstream>
* @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){
+void importNetgenParams(const std::string param_file, netgen_params& aParams){
std::ifstream myfile(param_file);
std::string 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
};
/**
#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 checkchartboundary;
int closeedgefac;
+ // Number of threads for the mesher
+ int nbThreads;
// True if we have a mesh size file or local size info
bool has_local_size = false;
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 importNetgenParams(const std::string param_file, netgen_params& aParams);
void exportNetgenParams(const std::string param_file, netgen_params& aParams);
#endif
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
)
{
if ( !aSubMeshDSFace ) continue;
SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
- if ( aParams._quadraticMesh &&
+ if ( _quadraticMesh &&
dynamic_cast< const SMESH_ProxyMesh::SubMesh*>( aSubMeshDSFace ))
{
// add medium nodes of proxy triangles to helper (#16843)
const SMDS_MeshElement* elem = iteratorElem->next();
// check mesh face
if ( !elem ){
- aParams._error = COMPERR_BAD_INPUT_MESH;
- aParams._comment = "Null element encounters";
- return true;
+ return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
}
if ( elem->NbCornerNodes() != 3 ){
- aParams._error = COMPERR_BAD_INPUT_MESH;
- aParams._comment = "Not triangle element encounters";
- return true;
+ return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
}
listElements[elem] = tuple(isRev, isInternalFace);
}
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.;
+ _progressByTic = -1.;
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
- aParams._quadraticMesh = helper.IsQuadraticSubMesh(aShape);
+ _quadraticMesh = helper.IsQuadraticSubMesh(aShape);
helper.SetElementsOnShape( true );
Netgen_NbOfNodes = 0;
bool isInternalFace=false;
SMESH_ProxyMesh::Ptr proxyMesh( new SMESH_ProxyMesh( aMesh ));
- if ( aParams._viscousLayersHyp )
+ if ( _viscousLayersHyp )
{
netgen::multithread.percent = 3;
- proxyMesh = aParams._viscousLayersHyp->Compute( aMesh, aShape );
+ proxyMesh = _viscousLayersHyp->Compute( aMesh, aShape );
if ( !proxyMesh )
return false;
}
}
std::map<const SMDS_MeshElement*, tuple<bool, bool>> listElements;
- bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, aParams, listElements);
+ bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, listElements);
if(ret)
return ret;
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen::OCCGeometry &occgeo,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
int &endWith)
{
NETGENPlugin_Mesher aMesher( &aMesh, helper.GetSubShape(), /*isVolume=*/true );
- if ( aParams._hypParameters )
+ if ( _hypParameters )
{
- aMesher.SetParameters( aParams._hypParameters );
+ aMesher.SetParameters( _hypParameters );
- if ( !aParams._hypParameters->GetLocalSizesAndEntries().empty() ||
- !aParams._hypParameters->GetMeshSizeFile().empty() )
+ if ( !_hypParameters->GetLocalSizesAndEntries().empty() ||
+ !_hypParameters->GetMeshSizeFile().empty() )
{
if ( ! &ngMesh->LocalHFunction() )
{
netgen::Point3d pmin, pmax;
ngMesh->GetBox( pmin, pmax, 0 );
- ngMesh->SetLocalH( pmin, pmax, aParams._hypParameters->GetGrowthRate() );
+ ngMesh->SetLocalH( pmin, pmax, _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;
+ return error( COMPERR_BAD_PARMETERS, ex.What() );
}
}
- if ( !aParams._hypParameters->GetOptimize() )
+ if ( !_hypParameters->GetOptimize() )
endWith = netgen::MESHCONST_MESHVOLUME;
}
- else if ( aParams._hypMaxElementVolume )
+ else if ( _hypMaxElementVolume )
{
- netgen::mparam.maxh = pow( 72, 1/6. ) * pow( aParams.maxElementVolume, 1/3. );
+ netgen::mparam.maxh = pow( 72, 1/6. ) * pow( _maxElementVolume, 1/3. );
// limitVolumeSize( ngMesh, mparam.maxh ); // result is unpredictable
}
else if ( aMesh.HasShapeToMesh() )
netgen::mparam.maxh = Dist(pmin, pmax)/2;
}
- if ( !aParams._hypParameters && aMesh.HasShapeToMesh() )
+ if ( !_hypParameters && aMesh.HasShapeToMesh() )
{
netgen::mparam.minh = aMesher.GetDefaultMinSize( helper.GetSubShape(), netgen::mparam.maxh );
}
vector< const SMDS_MeshNode* > &nodeVec,
netgen::Mesh* ngMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
- netgen_params &aParams,
int &startWith, int &endWith)
{
int err = 1;
if(netgen::multithread.terminate)
return false;
if ( err ){
- aParams._comment = SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task;
- return true;
+ error(SMESH_Comment("Error in netgen::OCCGenerateMesh() at ") << netgen::multithread.task);
}
}
catch (Standard_Failure& ex)
<< ": " << ex.DynamicType()->Name();
if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
str << ": " << ex.GetMessageString();
- aParams._comment = str;
- return true;
+ error(str);
}
catch (netgen::NgException& exc)
{
if ( strlen( netgen::multithread.task ) > 0 )
str << " at " << netgen::multithread.task;
str << ": " << exc.What();
- aParams._comment = str;
- return true;
+ error(str);
}
catch (...)
{
SMESH_Comment str("Exception in netgen::OCCGenerateMesh()");
if ( strlen( netgen::multithread.task ) > 0 )
str << " at " << netgen::multithread.task;
- aParams._comment = str;
- return true;
+ error(str);
}
if ( err )
{
SMESH_ComputeErrorPtr ce = NETGENPlugin_Mesher::ReadErrors(nodeVec);
if ( ce && ce->HasBadElems() ){
- aParams._error = ce->myName;
- aParams._comment = ce->myComment;
- return true;
+ error( ce );
}
}
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);
+ computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, Netgen_NbOfNodes);
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);
+ computePrepareParam(aMesh, ngLib, occgeo, helper, endWith);
+ computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, startWith, endWith);
- error(aParams._comment);
- return true;
- }
computeFillMesh(nodeVec, ngLib, helper, Netgen_NbOfNodes);
return false;
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
int &Netgen_NbOfNodes);
bool computePrepareParam(
NETGENPlugin_NetgenLibWrapper &ngLib,
netgen::OCCGeometry &occgeo,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
int &endWith);
bool computeRunMesher(
std::vector< const SMDS_MeshNode* > &nodeVec,
netgen::Mesh* ngMesh,
NETGENPlugin_NetgenLibWrapper &ngLib,
- netgen_params &aParams,
int &startWith, int &endWith);
bool computeFillMesh(
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,
// 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);
if ( !aSubMeshDSFace ) continue;
SMDS_ElemIteratorPtr iteratorElem = aSubMeshDSFace->GetElements();
- if ( aParams._quadraticMesh &&
+ if ( _quadraticMesh &&
dynamic_cast< const SMESH_ProxyMesh::SubMesh*>( aSubMeshDSFace ))
{
// add medium nodes of proxy triangles to helper (#16843)
exportNetgenParams(param_file.string(), aParams);
// Exporting element orientation
- exportElementOrientation(aMesh, aShape, aParams, element_orientation_file.string());
+ exportElementOrientation(aMesh, aShape, element_orientation_file.string());
}
// Calling run_mesher
protected:
void exportElementOrientation(SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape,
- netgen_params& aParams,
const std::string output_file);
void fillParameters(const NETGENPlugin_Hypothesis* hyp,
#include "NETGENPlugin_DriverParam.hxx"
#include "NETGENPlugin_Hypothesis.hxx"
+#include "StdMeshers_MaxElementVolume.hxx"
#include <SMESH_Gen.hxx>
#include <SMESH_Mesh.hxx>
}
+/*
+ *
+ */
+
+void NETGENPlugin_NETGEN_3D_SA::fillHyp(netgen_params aParams, SMESH_Gen* gen)
+{
+ if(aParams.has_netgen_param){
+ NETGENPlugin_Hypothesis * hypParameters = new NETGENPlugin_Hypothesis(0, gen);
+
+ hypParameters->SetMaxSize(aParams.maxh);
+ hypParameters->SetMinSize(aParams.minh);
+ hypParameters->SetNbSegPerEdge(aParams.segmentsperedge);
+ hypParameters->SetGrowthRate(aParams.grading);
+ hypParameters->SetNbSegPerRadius(aParams.curvaturesafety);
+ hypParameters->SetSecondOrder(aParams.secondorder);
+ hypParameters->SetQuadAllowed(aParams.quad);
+ hypParameters->SetOptimize(aParams.optimize);
+ hypParameters->SetFineness((NETGENPlugin_Hypothesis::Fineness)aParams.fineness);
+ hypParameters->SetSurfaceCurvature(aParams.uselocalh);
+ hypParameters->SetFuseEdges(aParams.merge_solids);
+ hypParameters->SetChordalErrorEnabled(aParams.chordalError);
+ if(aParams.optimize){
+ hypParameters->SetNbSurfOptSteps(aParams.optsteps2d);
+ hypParameters->SetNbVolOptSteps(aParams.optsteps3d);
+ }
+ hypParameters->SetElemSizeWeight(aParams.elsizeweight);
+ hypParameters->SetWorstElemMeasure(aParams.opterrpow);
+ hypParameters->SetUseDelauney(aParams.delaunay);
+ hypParameters->SetCheckOverlapping(aParams.checkoverlap);
+ hypParameters->SetCheckChartBoundary(aParams.checkchartboundary);
+ hypParameters->SetMeshSizeFile(aParams.meshsizefilename);
+
+ _hypParameters = dynamic_cast< const NETGENPlugin_Hypothesis *> (hypParameters);
+ }
+ if(aParams.has_maxelementvolume_hyp){
+ _hypMaxElementVolume = new StdMeshers_MaxElementVolume(1, gen);
+ _maxElementVolume = aParams.maxElementVolume;
+ }
+ // TODO: Handle viscous layer
+}
+
bool NETGENPlugin_NETGEN_3D_SA::computeFillNewElementFile(
std::vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
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)
+ std::string new_element_file, bool output_mesh)
{
// vector of nodes in which node index == netgen ID
vector< const SMDS_MeshNode* > nodeVec;
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);
+ NETGENPlugin_NETGEN_3D::computeFillNgMesh(aMesh, aShape, nodeVec, ngLib, helper, Netgen_NbOfNodes);
netgen::OCCGeometry occgeo;
- NETGENPlugin_NETGEN_3D::computePrepareParam(aMesh, ngLib, occgeo, helper, aParams, endWith);
+ NETGENPlugin_NETGEN_3D::computePrepareParam(aMesh, ngLib, occgeo, helper, 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;
- }
+ NETGENPlugin_NETGEN_3D::computeRunMesher(occgeo, nodeVec, ngLib._ngMesh, ngLib, startWith, endWith);
computeFillNewElementFile(nodeVec, ngLib, new_element_file, Netgen_NbOfNodes);
// Importing hypothesis
netgen_params myParams;
- importNetgenParams(hypo_file, myParams, &gen);
+ importNetgenParams(hypo_file, myParams);
+ fillHyp(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,
+ new_element_file,
!output_mesh_file.empty());
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
)
{
+ // To remove compilation warnings
+ (void) aShape;
+ (void) proxyMesh;
+ (void) internals;
+ (void) helper;
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
// Get list of elements + their orientation from element_orientation file
// Adding elements from Mesh
SMDS_ElemIteratorPtr iteratorElem = meshDS->elementsIterator(SMDSAbs_Face);
bool isRev;
- bool isInternalFace = false;
bool isIn;
// check mesh face
const SMDS_MeshElement* elem = iteratorElem->next();
if ( !elem ){
- aParams._error = COMPERR_BAD_INPUT_MESH;
- aParams._comment = "Null element encounters";
- return true;
+ return error( COMPERR_BAD_INPUT_MESH, "Null element encounters");
}
if ( elem->NbCornerNodes() != 3 ){
- aParams._error = COMPERR_BAD_INPUT_MESH;
- aParams._comment = "Not triangle element encounters";
- return true;
+ return error( COMPERR_BAD_INPUT_MESH, "Not triangle element encounters");
}
// Keeping only element that are in the element orientation file
isIn = elemOrientation.count(elem->GetID())==1;
NETGENPlugin_NETGEN_3D_SA();
virtual ~NETGENPlugin_NETGEN_3D_SA();
+ void fillHyp(netgen_params aParams, SMESH_Gen* gen);
bool Compute(TopoDS_Shape &aShape, SMESH_Mesh& aMesh, netgen_params& aParams,
- std::string new_element_file, std::string element_orientation_file,
- bool output_mesh);
+ std::string new_element_file, bool output_mesh);
int run(const std::string input_mesh_file,
const std::string shape_file,
SMESH_ProxyMesh::Ptr proxyMesh,
NETGENPlugin_Internals &internals,
SMESH_MesherHelper &helper,
- netgen_params &aParams,
std::map<const SMDS_MeshElement*, tuple<bool, bool>>& listElements
) override;