_compatibleHypothesis.push_back("GHS3D_Parameters");
_compatibleHypothesis.push_back( StdMeshers_ViscousLayers::GetHypType() );
_requireShape = false; // can work without shape
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ _compute_canceled = false;
+#endif
}
//=============================================================================
//=======================================================================
-static bool readGMFFile(const char* theFile, SMESH_MesherHelper* theHelper,
- TIDSortedNodeSet & theEnforcedNodes,
- TIDSortedElemSet & theEnforcedTriangles,
- TIDSortedElemSet & theEnforcedQuadrangles)
+static bool readGMFFile(const char* theFile,
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ GHS3DPlugin_GHS3D* theAlgo,
+#endif
+ SMESH_MesherHelper* theHelper,
+ TIDSortedNodeSet & theEnforcedNodes,
+ TIDSortedElemSet & theEnforcedTriangles,
+ TIDSortedElemSet & theEnforcedQuadrangles)
{
SMESHDS_Mesh* theMesh = theHelper->GetMeshDS();
std::map <GmfKwdCod,int>::const_iterator it = tabRef.begin();
for ( ; it != tabRef.end() ; ++it)
{
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled()) {
+ GmfCloseMesh(InpMsh);
+ delete [] GMFNode;
+ delete [] nodeAssigne;
+ return false;
+ }
+#endif
int dummy;
GmfKwdCod token = it->first;
nbRef = it->second;
SMDS_MeshNode * aGMFNode;
for ( int iElem = 0; iElem < nbElem; iElem++ ) {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled()) {
+ GmfCloseMesh(InpMsh);
+ delete [] GMFNode;
+ delete [] nodeAssigne;
+ return false;
+ }
+#endif
aGMFID = iElem + 1;
if (ver == GmfFloat) {
GmfGetLin(InpMsh, token, &VerTab_f[nbElem][0], &VerTab_f[nbElem][1], &VerTab_f[nbElem][2], &dummy);
for ( int iElem = 0; iElem < nbElem; iElem++ )
{
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled()) {
+ GmfCloseMesh(InpMsh);
+ delete [] GMFNode;
+ delete [] nodeAssigne;
+ return false;
+ }
+#endif
for ( int iRef = 0; iRef < nbRef; iRef++ )
{
aGMFNodeID = id[iElem*tabRef[token]+iRef]; // read nbRef aGMFNodeID
}
shapeID = theHelper->GetSubShapeID();
- for ( int i = 0; i < nbVertices; ++i )
+ for ( int i = 0; i < nbVertices; ++i ) {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled()) {
+ GmfCloseMesh(InpMsh);
+ delete [] GMFNode;
+ delete [] nodeAssigne;
+ return false;
+ }
+#endif
if ( !nodeAssigne[ i+1 ])
theMesh->SetNodeInVolume( GMFNode[ i+1 ], shapeID );
+ }
GmfCloseMesh(InpMsh);
delete [] GMFNode;
int nbEnforcedVertices = theEnforcedVertices.size();
int nbEnforcedNodes = theEnforcedNodes.size();
+ int aGhs3dID = 1;
+ SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
+ const SMDS_MeshNode* node;
+
// Issue 020674: EDF 870 SMESH: Mesh generated by Netgen not usable by GHS3D
// The problem is in nodes on degenerated edges, we need to skip them
if ( theHelper.HasDegeneratedEdges() )
}
}
}
+
+ const bool isQuadMesh =
+ theHelper.GetMesh()->NbEdges( ORDER_QUADRATIC ) ||
+ theHelper.GetMesh()->NbFaces( ORDER_QUADRATIC ) ||
+ theHelper.GetMesh()->NbVolumes( ORDER_QUADRATIC );
+ if ( isQuadMesh )
+ {
+ // descrease nbNodes by nb of medium nodes
+ while ( it->more() )
+ {
+ node = it->next();
+ if ( !theHelper.IsDegenShape( node->getshapeId() ))
+ nbNodes -= int( theHelper.IsMedium( node ));
+ }
+ it = theMesh->nodesIterator();
+ }
+
const char* space = " ";
const int dummyint = 0;
- int aGhs3dID = 1;
- SMDS_NodeIteratorPtr it = theMesh->nodesIterator();
- const SMDS_MeshNode* node;
-
// NB_NODES
std::cout << std::endl;
std::cout << "The initial 2D mesh contains :" << std::endl;
while ( it->more() )
{
node = it->next();
- if ( node->GetPosition()->GetTypeOfPosition() == SMDS_TOP_EDGE &&
- theHelper.IsDegenShape( node->getshapeId() )) // Issue 020674
+ if (( isQuadMesh && theHelper.IsMedium( node )) || // Issue 0021238
+ theHelper.IsDegenShape( node->getshapeId() )) // Issue 0020674
continue;
theSmdsToGhs3dIdMap.insert( make_pair( node->GetID(), aGhs3dID ));
static bool readResultFile(const int fileOpen,
#ifdef WNT
const char* fileName,
+#endif
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ GHS3DPlugin_GHS3D* theAlgo,
#endif
SMESH_MesherHelper& theMesh,
// SMESH_Mesh& theMesh,
int fileStat;
int nbElems, nbNodes, nbInputNodes;
- int nodeId/*, triangleId*/;
+ int nodeId;
int nbTriangle;
int ID, shapeID, ghs3dShapeID;
int IdShapeRef = 1;
const SMDS_MeshNode **node;
tab = new int[3];
- //tabID = new int[nbShape];
nodeID = new int[4];
coord = new double[3];
node = new const SMDS_MeshNode*[4];
MESSAGE("nbEnforcedVertices: "<<nbEnforcedVertices);
// Reading the nodeCoor and update the nodeMap
for (int iNode=1; iNode <= nbNodes; iNode++) {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled())
+ return false;
+#endif
for (int iCoor=0; iCoor < 3; iCoor++)
coord[ iCoor ] = strtod(ptr, &ptr);
nodeAssigne[ iNode ] = 1;
tabID = new int[nbTriangle];
for (int i=0; i < nbTriangle; i++) {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled())
+ return false;
+#endif
tabID[i] = 0;
// find the solid corresponding to GHS3D sub-domain following
// the technique proposed in GHS3D manual in chapter
// Associating the tetrahedrons to the shapes
shapeID = compoundID;
for (int iElem = 0; iElem < nbElems; iElem++) {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(theAlgo->computeCanceled())
+ return false;
+#endif
for (int iNode = 0; iNode < 4; iNode++) {
ID = strtol(tetraPtr, &tetraPtr, 10);
itOnNode = theGhs3dIdToNodeMap.find(ID);
}
}
if ( toMeshHoles || shapeID != HOLE_ID ) {
- aTet = theMeshDS->AddVolume( node[1], node[0], node[2], node[3] );
+ aTet = theMesh.AddVolume( node[1], node[0], node[2], node[3],
+ /*id=*/0, /*force3d=*/false);
theMeshDS->SetMeshElementOnShape( aTet, shapeID );
}
#ifdef _DEBUG_
std::cout << "Ghs3d execution..." << std::endl;
std::cout << cmd << std::endl;
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ _compute_canceled = false;
+#endif
+
system( cmd.ToCString() ); // run
std::cout << std::endl;
Ok = false;
}
else {
+ bool toMeshHoles =
+ _hyp ? _hyp->GetToMeshHoles(true) : GHS3DPlugin_Hypothesis::DefaultMeshHoles();
+
+ helper.IsQuadraticSubMesh( theShape );
+ helper.SetElementsOnShape( false );
+
Ok = readResultFile( fileOpen,
#ifdef WNT
aResultFileName.ToCString(),
+#endif
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ this,
#endif
/*theMesh, */helper, tabShape, tabBox, _nbShape, aGhs3dIdToNodeMap,
toMeshHoles,
// #endif
removeFile( aSmdsToGhs3dIdMapFileName );
// The output .mesh file does not contain yet the subdomain-info (Ghs3D 4.2)
- removeFile( aResultFileName );
+
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if (! Ok)
+ if(_compute_canceled)
+ removeFile( aLogFileName );
+#endif
}
std::cout << "<" << aResultFileName.ToCString() << "> GHS3D output file ";
if ( !Ok )
*/
//=============================================================================
bool GHS3DPlugin_GHS3D::Compute(SMESH_Mesh& theMesh,
- SMESH_MesherHelper* aHelper)
+ SMESH_MesherHelper* theHelper)
{
MESSAGE("GHS3DPlugin_GHS3D::Compute()");
//SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
- TopoDS_Shape theShape = aHelper->GetSubShape();
+ TopoDS_Shape theShape = theHelper->GetSubShape();
// a unique working file name
// to avoid access to the same files by eg different users
TCollection_AsciiString aLogFileName = aGenericName + ".log"; // log
TCollection_AsciiString aResultFileName;
bool Ok;
-#if GHS3D_VERSION < 42
- TCollection_AsciiString aFacesFileName, aPointsFileName;
- TCollection_AsciiString aBadResFileName, aBbResFileName;
- aFacesFileName = aGenericName + ".faces"; // in faces
- aPointsFileName = aGenericName + ".points"; // in points
- aResultFileName = aGenericName + ".noboite";// out points and volumes
- aBadResFileName = aGenericName + ".boite"; // out bad result
- aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
-
- // -----------------
- // make input files
- // -----------------
-
- ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
- ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
- Ok = aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
- if (!Ok) {
- INFOS( "Can't write into " << aFacesFileName);
- return error( SMESH_Comment("Can't write into ") << aFacesFileName);
- }
-#else
+// #if GHS3D_VERSION < 42
+// TCollection_AsciiString aFacesFileName, aPointsFileName;
+// TCollection_AsciiString aBadResFileName, aBbResFileName;
+// aFacesFileName = aGenericName + ".faces"; // in faces
+// aPointsFileName = aGenericName + ".points"; // in points
+// aResultFileName = aGenericName + ".noboite";// out points and volumes
+// aBadResFileName = aGenericName + ".boite"; // out bad result
+// aBbResFileName = aGenericName + ".bb"; // out vertex stepsize
+//
+// // -----------------
+// // make input files
+// // -----------------
+//
+// ofstream aFacesFile ( aFacesFileName.ToCString() , ios::out);
+// ofstream aPointsFile ( aPointsFileName.ToCString() , ios::out);
+// Ok = aFacesFile.rdbuf()->is_open() && aPointsFile.rdbuf()->is_open();
+// if (!Ok) {
+// INFOS( "Can't write into " << aFacesFileName);
+// return error( SMESH_Comment("Can't write into ") << aFacesFileName);
+// }
+// #else
TCollection_AsciiString aGMFFileName, aRequiredVerticesFileName, aSolFileName;
#ifdef _DEBUG_
aGMFFileName = aGenericName + ".mesh"; // GMF mesh file
aRequiredVerticesFileName = aGenericName + "_required.meshb"; // GMF required vertices mesh file
aSolFileName = aGenericName + ".solb"; // GMF solution file
#endif
-#endif
+// #endif
std::map <int, int> nodeID2nodeIndexMap;
GHS3DPlugin_Hypothesis::TEnforcedVertexValues enforcedVertices = GHS3DPlugin_Hypothesis::GetEnforcedVertices(_hyp);
aQuad2Trias->Compute( theMesh );
proxyMesh.reset( aQuad2Trias );
}
-#if GHS3D_VERSION < 42
- Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
- enforcedEdges, enforcedTriangles, enforcedQuadrangles ) &&
- writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
- nodeIDToSizeMap, enforcedVertices, enforcedNodes));
- int nbEnforcedVertices = enforcedVertices.size();
- int nbEnforcedNodes = enforcedNodes.size();
-#else
+// #if GHS3D_VERSION < 42
+// Ok = (writeFaces ( aFacesFile, *proxyMesh, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
+// enforcedEdges, enforcedTriangles, enforcedQuadrangles ) &&
+// writePoints( aPointsFile, &theMesh, aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
+// nodeIDToSizeMap, enforcedVertices, enforcedNodes));
+// int nbEnforcedVertices = enforcedVertices.size();
+// int nbEnforcedNodes = enforcedNodes.size();
+// #else
Ok = writeGMFFile(aGMFFileName.ToCString(), aRequiredVerticesFileName.ToCString(), aSolFileName.ToCString(),
*proxyMesh, &theMesh,
aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
enforcedNodes, enforcedEdges, enforcedTriangles, enforcedQuadrangles,
enforcedVertices);
-#endif
+// #endif
}
TIDSortedNodeSet enforcedNodesFromEnforcedElem;
for (int i=0;i<anEnforcedNodeByGhs3dId.size();i++)
enforcedNodesFromEnforcedElem.insert(anEnforcedNodeByGhs3dId[i]);
-#if GHS3D_VERSION < 42
- aFacesFile.close();
- aPointsFile.close();
-
- if ( ! Ok ) {
- if ( !_keepFiles ) {
- removeFile( aFacesFileName );
- removeFile( aPointsFileName );
- }
- return error(COMPERR_BAD_INPUT_MESH);
- }
- removeFile( aResultFileName ); // needed for boundary recovery module usage
-#endif
+// #if GHS3D_VERSION < 42
+// aFacesFile.close();
+// aPointsFile.close();
+//
+// if ( ! Ok ) {
+// if ( !_keepFiles ) {
+// removeFile( aFacesFileName );
+// removeFile( aPointsFileName );
+// }
+// return error(COMPERR_BAD_INPUT_MESH);
+// }
+// removeFile( aResultFileName ); // needed for boundary recovery module usage
+// #endif
// -----------------
// run ghs3d mesher
// -----------------
TCollection_AsciiString cmd = TCollection_AsciiString((char*)GHS3DPlugin_Hypothesis::CommandToRun( _hyp, false ).c_str());
-#if GHS3D_VERSION < 42
- cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
-#else
+// #if GHS3D_VERSION < 42
+// cmd += TCollection_AsciiString(" -f ") + aGenericName; // file to read
+// #else
cmd += TCollection_AsciiString(" --in ") + aGenericName;
// cmd += TCollection_AsciiString(" --required_vertices ") + aRequiredVerticesFileName;
cmd += TCollection_AsciiString(" --out ") + aResultFileName;
-#endif
+// #endif
cmd += TCollection_AsciiString(" 1>" ) + aLogFileName; // dump into file
std::cout << std::endl;
std::cout << "Ghs3d execution..." << std::endl;
std::cout << cmd << std::endl;
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ _compute_canceled = false;
+#endif
+
system( cmd.ToCString() ); // run
std::cout << std::endl;
// --------------
// read a result
// --------------
-#if GHS3D_VERSION < 42
- int fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
- if ( fileOpen < 0 ) {
- std::cout << std::endl;
- std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl;
- std::cout << "Log: " << aLogFileName << std::endl;
- std::cout << std::endl;
- Ok = false;
- }
- else {
- Ok = readResultFile( fileOpen,
-#ifdef WNT
- aResultFileName.ToCString(),
+// #if GHS3D_VERSION < 42
+// int fileOpen = open( aResultFileName.ToCString(), O_RDONLY);
+// if ( fileOpen < 0 ) {
+// std::cout << std::endl;
+// std::cout << "Error when opening the " << aResultFileName.ToCString() << " file" << std::endl;
+// std::cout << "Log: " << aLogFileName << std::endl;
+// std::cout << std::endl;
+// Ok = false;
+// }
+// else {
+// Ok = readResultFile( fileOpen,
+// #ifdef WNT
+// aResultFileName.ToCString(),
+// #endif
+// #ifdef WITH_SMESH_CANCEL_COMPUTE
+// this,
+// #endif
+// theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
+// nbEnforcedVertices, nbEnforcedNodes,
+// enforcedEdges, enforcedTriangles, enforcedQuadrangles );
+// }
+// #else
+ Ok = readGMFFile(aResultFileName.ToCString(),
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ this,
#endif
- theMesh, theShape ,aNodeByGhs3dId, anEnforcedNodeByGhs3dId,
- nbEnforcedVertices, nbEnforcedNodes,
- enforcedEdges, enforcedTriangles, enforcedQuadrangles );
- }
-#else
- Ok = readGMFFile(aResultFileName.ToCString(), aHelper,
+ theHelper,
enforcedNodesFromEnforcedElem, enforcedTriangles, enforcedQuadrangles);
-#endif
+// #endif
// ---------------------
// remove working files
INFOS( "GHS3D Error, command '" << cmd.ToCString() << "' failed" );
error(COMPERR_ALGO_FAILED, "ghs3d: command not found" );
}
-#if GHS3D_VERSION < 42
+// #if GHS3D_VERSION < 42
if ( !_keepFiles )
{
- removeFile( aFacesFileName );
- removeFile( aPointsFileName );
- removeFile( aResultFileName );
- removeFile( aBadResFileName );
- removeFile( aBbResFileName );
- }
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if (! Ok)
+ if(_compute_canceled)
+ removeFile( aLogFileName );
#endif
+// removeFile( aFacesFileName );
+// removeFile( aPointsFileName );
+// removeFile( aResultFileName );
+// removeFile( aBadResFileName );
+// removeFile( aBbResFileName );
+ }
+// #endif
return Ok;
}
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+void GHS3DPlugin_GHS3D::CancelCompute()
+{
+ _compute_canceled = true;
+#ifdef WNT
+#else
+ TCollection_AsciiString aGenericName
+ = (char*) GHS3DPlugin_Hypothesis::GetFileName(_hyp).c_str();
+ TCollection_AsciiString cmd =
+ TCollection_AsciiString("ps ux | grep ") + aGenericName;
+ cmd += TCollection_AsciiString(" | grep -v grep | awk '{print $2}' | xargs kill -9 > /dev/null 2>&1");
+ system( cmd.ToCString() );
+#endif
+}
+#endif
+
//================================================================================
/*!
* \brief Provide human readable text by error code reported by ghs3d
bool GHS3DPlugin_GHS3D::storeErrorDescription(const TCollection_AsciiString& logFile,
const _Ghs2smdsConvertor & toSmdsConvertor )
{
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if(_compute_canceled)
+ return error(SMESH_Comment("interruption initiated by user"));
+#endif
// open file
#ifdef WNT
int file = ::_open (logFile.ToCString(), _O_RDONLY|_O_BINARY);
SMESH_MesherHelper* helper = new SMESH_MesherHelper(theMesh );
TIDSortedElemSet dummyElemSet;
TIDSortedNodeSet dummyNodeSet;
- return readGMFFile(theGMFFileName, helper, dummyNodeSet , dummyElemSet, dummyElemSet);
+ return readGMFFile(theGMFFileName,
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ this,
+#endif
+ helper, dummyNodeSet , dummyElemSet, dummyElemSet);
}