X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2FHYBRIDPlugin%2FHYBRIDPlugin_HYBRID.cxx;h=862a704bcb8d67037ebee8e3ff212334a2295d6c;hb=f8c36b86176359bdd035a030615ee991bb437f0f;hp=30fdd6b4f071b3c7293997715daa5154ce424004;hpb=0b67c2b63e6abfd764031232f80dc3fe26231a9e;p=plugins%2Fhybridplugin.git diff --git a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx index 30fdd6b..862a704 100644 --- a/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx +++ b/src/HYBRIDPlugin/HYBRIDPlugin_HYBRID.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D +// Copyright (C) 2007-2022 CEA/DEN, EDF R&D // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public @@ -70,6 +70,7 @@ #include #include +#include #include #define castToNode(n) static_cast( n ); @@ -101,8 +102,8 @@ static void removeFile( const std::string& fileName ) */ //============================================================================= -HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, int studyId, SMESH_Gen* gen) - : SMESH_3D_Algo(hypId, studyId, gen) +HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, SMESH_Gen* gen) + : SMESH_3D_Algo(hypId, gen) { _name = Name(); _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);// 1 bit /shape type @@ -110,15 +111,7 @@ HYBRIDPlugin_HYBRID::HYBRIDPlugin_HYBRID(int hypId, int studyId, SMESH_Gen* gen) _iShape=0; _nbShape=0; _compatibleHypothesis.push_back( HYBRIDPlugin_Hypothesis::GetHypType()); - _requireShape = false; // can work without shape_studyId - - smeshGen_i = SMESH_Gen_i::GetSMESHGen(); - CORBA::Object_var anObject = smeshGen_i->GetNS()->Resolve("/myStudyManager"); - SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject); - - myStudy = NULL; - myStudy = aStudyMgr->GetStudyByID(_studyId); - + _requireShape = false; // can work without shape _computeCanceled = false; } @@ -175,18 +168,18 @@ bool HYBRIDPlugin_HYBRID::CheckHypothesis ( SMESH_Mesh& aMesh, TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry) { - if ( myStudy->_is_nil() ) + if ( SMESH_Gen_i::GetSMESHGen()->getStudyServant()->_is_nil() ) throw SALOME_Exception("MG-HYBRID plugin can't work w/o publishing in the study"); GEOM::GEOM_Object_var aGeomObj; TopoDS_Shape S = TopoDS_Shape(); - SALOMEDS::SObject_var aSObj = myStudy->FindObjectID( entry.c_str() ); + SALOMEDS::SObject_var aSObj = SMESH_Gen_i::GetSMESHGen()->getStudyServant()->FindObjectID( entry.c_str() ); if (!aSObj->_is_nil() ) { CORBA::Object_var obj = aSObj->GetObject(); aGeomObj = GEOM::GEOM_Object::_narrow(obj); aSObj->UnRegister(); } if ( !aGeomObj->_is_nil() ) - S = smeshGen_i->GeomObjectToShape( aGeomObj.in() ); + S = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( aGeomObj.in() ); return S; } @@ -198,7 +191,7 @@ TopoDS_Shape HYBRIDPlugin_HYBRID::entryToShape(std::string entry) static void addElemInMeshGroup(SMESH_Mesh* theMesh, const SMDS_MeshElement* anElem, std::string& groupName, - std::set& groupsToRemove) + std::set& /*groupsToRemove*/) { if ( !anElem ) return; // issue 0021776 @@ -219,8 +212,7 @@ static void addElemInMeshGroup(SMESH_Mesh* theMesh, if (!groupDone) { - int groupId; - SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str(), groupId); + SMESH_Group* aGroup = theMesh->AddGroup(anElem->GetType(), groupName.c_str()); aGroup->SetName( groupName.c_str() ); SMESHDS_Group* aGroupDS = static_cast( aGroup->GetGroupDS() ); aGroupDS->SMDSGroup().Add(anElem); @@ -311,13 +303,12 @@ static void makeDomainGroups( std::vector< std::vector< const SMDS_MeshElement* } // create and fill the groups size_t iElem = 0; - int groupID; do { SMESH_Group* group = groupOfType[ elems[ iElem ]->GetType() ]; if ( !group ) group = theHelper->GetMesh()->AddGroup( elems[ iElem ]->GetType(), - domainName.c_str(), groupID ); + domainName.c_str() ); SMDS_MeshGroup& groupDS = static_cast< SMESHDS_Group* >( group->GetGroupDS() )->SMDSGroup(); @@ -339,32 +330,69 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, SMESH_MesherHelper* theHelper, std::vector & theNodeByHybridId, std::vector & theFaceByHybridId, - std::map & theNodeToHybridIdMap, + std::map & /*theNodeToHybridIdMap*/, std::vector & aNodeGroupByHybridId, std::vector & anEdgeGroupByHybridId, std::vector & aFaceGroupByHybridId, std::set & groupsToRemove, bool toMakeGroupsOfDomains=false, - bool toMeshHoles=true) + bool /*toMeshHoles*/=true) { std::string tmpStr; SMESHDS_Mesh* theMeshDS = theHelper->GetMeshDS(); const bool hasGeom = ( theHelper->GetMesh()->HasShapeToMesh() ); + // if imprinting, the original mesh faces are modified + // => we clear all the faces to retrieve them from Hybrid output mesh. + std::vector facesWithImprinting; + if (theAlgo->getHyp()) + facesWithImprinting = theAlgo->getHyp()->GetFacesWithImprinting(); + + if ( ! facesWithImprinting.empty() ) { +#ifdef _DEBUG_ + std::cout << "Imprinting => Clear original mesh" << std::endl; +#endif + SMESH_subMesh* smOfSolid = + theHelper->GetMesh()->GetSubMesh( theHelper->GetSubShape() ); + SMESH_subMeshIteratorPtr smIt = + smOfSolid->getDependsOnIterator(/*includeSelf=*/false, /*complexShapeFirst=*/true); + while ( smIt->more() ) + { + SMESH_subMesh* sm = smIt->next(); + if ( SMESHDS_SubMesh * smDS = sm->GetSubMeshDS() ) + { + SMDS_ElemIteratorPtr eIt = smDS->GetElements(); + while( eIt->more() ) + { + theMeshDS->RemoveFreeElement( eIt->next(), smDS ); + } + SMDS_NodeIteratorPtr nIt = smDS->GetNodes(); + while ( nIt->more() ) + { + const SMDS_MeshNode* n = nIt->next(); + if ( n->NbInverseElements() == 0 ) + theMeshDS->RemoveFreeNode( n, smDS ); + } + } + } + theNodeByHybridId.clear(); + theFaceByHybridId.clear(); + } + int nbInitialNodes = theNodeByHybridId.size(); + +#ifdef _DEBUG_ int nbMeshNodes = theMeshDS->NbNodes(); - - const bool isQuadMesh = + const bool isQuadMesh = theHelper->GetMesh()->NbEdges( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbFaces( ORDER_QUADRATIC ) || theHelper->GetMesh()->NbVolumes( ORDER_QUADRATIC ); - -#ifdef _DEBUG_ + std::cout << "theNodeByHybridId.size(): " << nbInitialNodes << std::endl; std::cout << "theHelper->GetMesh()->NbNodes(): " << nbMeshNodes << std::endl; std::cout << "isQuadMesh: " << isQuadMesh << std::endl; #endif - + // --------------------------------- // Read generated elements and nodes // --------------------------------- @@ -582,20 +610,38 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, case GmfEdges: if (fullyCreatedElement) { aCreatedElem = theHelper->AddEdge( node[0], node[1], noID, force3d ); - if (anEdgeGroupByHybridId.size() && !anEdgeGroupByHybridId[iElem].empty()) + if ( !anEdgeGroupByHybridId.empty() && !anEdgeGroupByHybridId[iElem].empty()) addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, anEdgeGroupByHybridId[iElem], groupsToRemove); } break; case GmfTriangles: if (fullyCreatedElement) { aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], noID, force3d ); - if (aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty()) + // add iElem < aFaceGroupByHybridId.size() to avoid crash if imprinting with hexa core with MeshGems <= 2.4-5 + if ( iElem < (int)aFaceGroupByHybridId.size() && !aFaceGroupByHybridId[iElem].empty() ) { addElemInMeshGroup(theHelper->GetMesh(), aCreatedElem, aFaceGroupByHybridId[iElem], groupsToRemove); + } + // add element in shape for groups on geom to work + if ( domainID[iElem] > 0 ) + { + theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] ); + for ( int iN = 0; iN < 3; ++iN ) + if ( node[iN]->getshapeId() < 1 ) + theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] ); + } } break; case GmfQuadrilaterals: if (fullyCreatedElement) { aCreatedElem = theHelper->AddFace( node[0], node[1], node[2], node[3], noID, force3d ); + // add element in shape for groups on geom to work + if ( domainID[iElem] > 0 ) + { + theMeshDS->SetMeshElementOnShape( aCreatedElem, domainID[iElem] ); + for ( int iN = 0; iN < 3; ++iN ) + if ( node[iN]->getshapeId() < 1 ) + theMeshDS->SetNodeOnFace( node[iN], domainID[iElem] ); + } } break; case GmfTetrahedra: @@ -770,7 +816,7 @@ static bool readGMFFile(MG_HYBRID_API* MGOutput, std::map >::const_iterator subdomainIt = subdomainId2tetraId.begin(); std::string aSubdomainFileName = theFile; aSubdomainFileName = aSubdomainFileName + ".subdomain"; - ofstream aSubdomainFile ( aSubdomainFileName , ios::out); + std::ofstream aSubdomainFile ( aSubdomainFileName , ios::out); aSubdomainFile << "Nb subdomains " << subdomainId2tetraId.size() << std::endl; for(;subdomainIt != subdomainId2tetraId.end() ; ++subdomainIt) { @@ -1444,7 +1490,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // Write aSmdsToHybridIdMap to temp file std::string aSmdsToHybridIdMapFileName; aSmdsToHybridIdMapFileName = aGenericName + ".ids"; // ids relation - ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out); + std::ofstream aIdsFile ( aSmdsToHybridIdMapFileName , ios::out); Ok = aIdsFile.rdbuf()->is_open(); if (!Ok) { INFOS( "Can't write into " << aSmdsToHybridIdMapFileName); @@ -1474,7 +1520,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp ); if ( mgHybrid.IsExecutable() ) { @@ -1676,7 +1722,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, // run hybrid mesher // ----------------- - std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp, theMesh ); + std::string cmd = HYBRIDPlugin_Hypothesis::CommandToRun( _hyp ); if ( mgHybrid.IsExecutable() ) { @@ -1762,8 +1808,7 @@ bool HYBRIDPlugin_HYBRID::Compute(SMESH_Mesh& theMesh, void HYBRIDPlugin_HYBRID::CancelCompute() { _computeCanceled = true; -#ifdef WIN32 -#else +#if !defined(WIN32) && !defined(__APPLE__) std::string cmd = "ps xo pid,args | grep " + _genericName; //cmd += " | grep -e \"^ *[0-9]\\+ \\+" + HYBRIDPlugin_Hypothesis::GetExeName() + "\""; cmd += " | awk '{print $1}' | xargs kill -9 > /dev/null 2>&1"; @@ -2161,9 +2206,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, "Submesh can not be evaluated",this)); return false; } - std::vector aVec = (*anIt).second; - nbtri += Max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]); - nbqua += Max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]); + std::vector aVec = (*anIt).second; + nbtri += std::max(aVec[SMDSEntity_Triangle],aVec[SMDSEntity_Quad_Triangle]); + nbqua += std::max(aVec[SMDSEntity_Quadrangle],aVec[SMDSEntity_Quad_Quadrangle]); GProp_GProps G; BRepGProp::SurfaceProperties(F,G); double anArea = G.Mass(); @@ -2182,9 +2227,9 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, tmpMap.Add(E); SMESH_subMesh *aSubMesh = aMesh.GetSubMesh(exp.Current()); MapShapeNbElemsItr anIt = aResMap.find(aSubMesh); - std::vector aVec = (*anIt).second; + std::vector aVec = (*anIt).second; nb0d_e += aVec[SMDSEntity_Node]; - nb1d_e += Max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); + nb1d_e += std::max(aVec[SMDSEntity_Edge],aVec[SMDSEntity_Quad_Edge]); if(IsFirst) { IsQuadratic = (aVec[SMDSEntity_Quad_Edge] > aVec[SMDSEntity_Edge]); IsFirst = false; @@ -2202,7 +2247,7 @@ bool HYBRIDPlugin_HYBRID::Evaluate(SMESH_Mesh& aMesh, int nbVols = int(aVolume/tetrVol/CoeffQuality); int nb1d_f = (nbtri*3 + nbqua*4 - nb1d_e) / 2; int nb1d_in = (int) ( nbVols*6 - nb1d_e - nb1d_f ) / 5; - std::vector aVec(SMDSEntity_Last); + std::vector aVec(SMDSEntity_Last); for(int i=SMDSEntity_Node; iGetAlgo() )