-// Copyright (C) 2007-2022 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 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
#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>
*/
//=============================================================================
+
/**
- * @brief Get an iterator on the Surface element with their orientation
+ * @brief Compute the list of already meshed Surface elements and info
+ * on their orientation and if they are internal
*
+ * @param aMesh Global Mesh
+ * @param aShape Shape associated to the mesh
+ * @param proxyMesh pointer to mesh used fo find the elements
+ * @param internals information on internal sub shapes
+ * @param helper helper associated to the mesh
+ * @param listElements map of surface element associated with
+ * their orientation and internal status
+ * @return true if their was some error
*/
-
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
+ std::map<const SMDS_MeshElement*, tuple<bool, bool>, TIDCompare>& listElements
)
{
SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
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);
}
return false;
}
+/**
+ * @brief Part of Compute: adding already meshed elements
+ * into netgen structure
+ *
+ * @param aMesh Global mesh
+ * @param aShape Shape associated with the mesh
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngLib Wrapper on netgen lib
+ * @param helper helper assocaited to the mesh
+ * @param Netgen_NbOfNodes Number of nodes in netge structure
+ * @return true if there was some error
+ */
bool NETGENPlugin_NETGEN_3D::computeFillNgMesh(
SMESH_Mesh& aMesh,
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;
SMESH::Controls::TSequenceOfXYZ nodesCoords;
// maps nodes to ng ID
+ // map must be sorted by ID to ensure that we will have the same number of
+ // 3D element if we recompute
typedef map< const SMDS_MeshNode*, int, TIDCompare > TNodeToIDMap;
typedef TNodeToIDMap::value_type TN2ID;
TNodeToIDMap nodeToNetgenID;
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;
}
proxyMesh.reset( Adaptor );
}
- std::map<const SMDS_MeshElement*, tuple<bool, bool>> listElements;
- bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, aParams, listElements);
+ // map must be sorted by ID to ensure that we will have the same number of
+ // 3D element if we recompute
+ std::map<const SMDS_MeshElement*, tuple<bool, bool>, TIDCompare> listElements;
+ bool ret = getSurfaceElements(aMesh, aShape, proxyMesh, internals, helper, listElements);
if(ret)
return ret;
return false;
}
+/**
+ * @brief Part of Compute: Setting the netgen parameters from the Hypothesis
+ *
+ * @param aMesh Global mesh
+ * @param ngLib Wrapper on netgen lib
+ * @param occgeo Mapping between nodes mesh id and netgen structure id
+ * @param helper helper assocaited to the mesh
+ * @param endWith end step of netgen
+ * @return true if there was some error
+ */
bool NETGENPlugin_NETGEN_3D::computePrepareParam(
SMESH_Mesh& aMesh,
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 );
}
return false;
}
+/**
+ * @brief Part of Compute: call to the netgen mesher
+ *
+ * @param occgeo netgen geometry structure
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngMesh netgen mesh structure
+ * @param ngLib Wrapper on netgen lib
+ * @param startWith starting step of netgen
+ * @param endWith end step of netgen
+ * @return true if there was some error
+ */
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;
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 );
}
}
return false;
}
+/**
+ * @brief Part of Compute: Adding new element created by mesher to SMESH_Mesh
+ *
+ * @param nodeVec Mapping between nodes mesh id and netgen structure id
+ * @param ngLib Wrapper on netgen lib
+ * @param helper tool associated to the mesh to add element
+ * @param Netgen_NbOfNodes Number of nodes in netgen structure
+ * @return true if there was some error
+ */
bool NETGENPlugin_NETGEN_3D::computeFillMesh(
vector< const SMDS_MeshNode* > &nodeVec,
NETGENPlugin_NetgenLibWrapper &ngLib,
return false;
}
+
+/**
+ * @brief Compute mesh associate to shape
+ *
+ * @param aMesh The mesh
+ * @param aShape The shape
+ * @return true fi there are some error
+ */
bool NETGENPlugin_NETGEN_3D::Compute(
SMESH_Mesh& aMesh,
const TopoDS_Shape& aShape)
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;