Revert "Merge branch 'yan/parallel_mesh2'"

This reverts commit 4403c126a0, reversing
changes made to 4dc895105a.
This commit is contained in:
Yoann Audouin 2022-11-02 10:54:05 +01:00
parent b60e215be8
commit da9f965ac4
28 changed files with 382 additions and 1501 deletions

View File

@ -52,7 +52,7 @@ The mesh can include the following entities:
* **Node** - a mesh entity defining a position in 3D space with coordinates (x, y, z). * **Node** - a mesh entity defining a position in 3D space with coordinates (x, y, z).
* **Edge** (or segment) - 1D mesh element linking two nodes. * **Edge** (or segment) - 1D mesh element linking two nodes.
* **Face** - 2D mesh element representing a part of surface bound by links between face nodes. A face can be a triangle, quadrangle or polygon. * **Face** - 2D mesh element representing a part of surface bound by links between face nodes. A face can be a triangle, quadrangle or polygon.
* **Volume** - 3D mesh element representing a part of 3D space bound by volume facets. Nodes of a volume describing each facet are defined by the :ref:`connectivity convention <connectivity_page>`. A volume can be a tetrahedron, hexahedron, pentahedron, pyramid, hexagonal or polyhedron. * **Volume** - 3D mesh element representing a part of 3D space bound by volume facets. Nodes of a volume describing each facet are defined by the :ref:`connectivity convention <connectivity_page>`. A volume can be a tetrahedron, hexahedron, pentahedron, pyramid, hexagonal prism or polyhedron.
* **0D** element - mesh element defined by one node. * **0D** element - mesh element defined by one node.
* **Ball** element - discrete mesh element defined by a node and a diameter. * **Ball** element - discrete mesh element defined by a node and a diameter.

View File

@ -899,11 +899,6 @@ module SMESH
*/ */
boolean SetMeshOrder(in submesh_array_array theSubMeshArray); boolean SetMeshOrder(in submesh_array_array theSubMeshArray);
/*!
* \brief Set Number of Threads
*/
void SetNbThreads(in long nbThreads);
/*!
/*! /*!
* Get mesh description * Get mesh description

View File

@ -90,9 +90,6 @@ SET(SMESHimpl_HEADERS
SMESH_SMESH.hxx SMESH_SMESH.hxx
MG_ADAPT.hxx MG_ADAPT.hxx
SMESH_Homard.hxx SMESH_Homard.hxx
SMESH_DriverMesh.hxx
SMESH_DriverShape.hxx
SMESH_MeshLocker.hxx
) )
# --- sources --- # --- sources ---
@ -113,9 +110,6 @@ SET(SMESHimpl_SOURCES
SMESH_MesherHelper.cxx SMESH_MesherHelper.cxx
MG_ADAPT.cxx MG_ADAPT.cxx
SMESH_Homard.cxx SMESH_Homard.cxx
SMESH_DriverMesh.cxx
SMESH_DriverShape.cxx
SMESH_MeshLocker.cxx
) )
# --- rules --- # --- rules ---

View File

@ -277,9 +277,6 @@ public:
// 6 - if algo !NeedDiscreteBoundary() but requires presence of // 6 - if algo !NeedDiscreteBoundary() but requires presence of
// hypotheses of dimension <dim> to generate all-dimensional mesh. // hypotheses of dimension <dim> to generate all-dimensional mesh.
// This info is used not to issue warnings on hiding of lower global algos. // This info is used not to issue warnings on hiding of lower global algos.
//
virtual void setSubMeshesToCompute(SMESH_subMesh * aSubMesh) {SubMeshesToCompute().assign( 1, aSubMesh );}
public: public:
// ================================================================== // ==================================================================

View File

@ -1,104 +0,0 @@
// Copyright (C) 2007-2022 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 : SMESH_DriverMesh.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "utilities.h"
#include "SMESH_DriverMesh.hxx"
#include "SMESH_Mesh.hxx"
#include "SMESH_Gen.hxx"
#include <MEDFileMesh.hxx>
#include <MEDCouplingUMesh.hxx>
using namespace MEDCoupling;
/**
* @brief Compares the mesh from two mesh files (MED)
*
* @param mesh_file1 First file
* @param mesh_file2 Second file
* @param mesh_name Name of the mesh in the files
*
* @return true if the mesh within the files are identical
*/
bool diffMEDFile(const std::string mesh_file1, const std::string mesh_file2, const std::string mesh_name){
MEDFileUMesh* medmesh1 = MEDFileUMesh::New(mesh_file1, mesh_name);
MEDFileUMesh* medmesh2 = MEDFileUMesh::New(mesh_file2, mesh_name);
MEDCouplingUMesh *m0_1=medmesh1->getMeshAtLevel(0,false);
MEDCouplingUMesh *m0_2=medmesh2->getMeshAtLevel(0,false);
return m0_1->isEqual(m0_2, 1e-12);
}
std::string getMeshName(std::string mesh_file){
// TODO: Memory leak but desctructor private check with AG
MEDFileUMesh * myMedMesh = MEDFileUMesh::New(mesh_file);
return myMedMesh->getLevel0Mesh()->getName();
}
/**
* @brief Import a mesh from a mesh file (MED) into a SMESH_Mesh object
*
* @param mesh_file the file
* @param aMesh the object
* @param mesh_name the name of the mesh in the file
*
* @return error code
*/
int importMesh(const std::string mesh_file, SMESH_Mesh& aMesh){
// TODO: change that as it depends on the language
std::string mesh_name = getMeshName(mesh_file);
MESSAGE("Importing mesh from " << mesh_file << " mesh " << mesh_name);
int ret = aMesh.MEDToMesh(mesh_file.c_str(), mesh_name.c_str());
return ret;
}
/**
* @brief Export the content of a SMESH_Mesh into a mesh file (MED)
*
* @param mesh_file the file
* @param aMesh the object
* @param mesh_name name of the mesh in the file
*
* @return error code
*/
int exportMesh(const std::string mesh_file, SMESH_Mesh& aMesh, const std::string mesh_name){
MESSAGE("Exporting mesh to " << mesh_file);
aMesh.ExportMED(mesh_file.c_str(), // theFile
mesh_name.c_str(), // theMeshName
false, // theAutoGroups
-1, // theVersion
nullptr, // theMeshPart
true, // theAutoDimension
true, // theAddODOnVertices
1e-8, // theZTolerance
true // theSaveNumbers
);
return true;
}

View File

@ -1,45 +0,0 @@
// 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 : SMESH_DriverMesh.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#ifndef _SMESH_DRIVERMESH_HXX_
#define _SMESH_DRIVERMESH_HXX_
#include <string>
#include <cassert>
class SMESH_Mesh;
bool diffMEDFile(const std::string mesh_file1,
const std::string mesh_file2,
const std::string mesh_name);
int importMesh(const std::string mesh_file,
SMESH_Mesh& aMesh);
int exportMesh(const std::string mesh_file,
SMESH_Mesh& aMesh,
const std::string meshName);
#endif

View File

@ -1,179 +0,0 @@
// Copyright (C) 2007-2022 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 : SMESH_DriverShape.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include <utilities.h>
#include <Utils_SALOME_Exception.hxx>
#include "SMESH_DriverShape.hxx"
// step include
#include <STEPControl_Reader.hxx>
#include <STEPControl_Writer.hxx>
#include <Interface_Static.hxx>
// Brep include
#include <BRepTools.hxx>
#include <BRep_Builder.hxx>
//Occ include
#include <TopoDS.hxx>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
namespace fs = boost::filesystem;
/**
* @brief Import the content of a shape file (STEP) into a TopDS_Shape object
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int importSTEPShape(const std::string shape_file, TopoDS_Shape& aShape){
MESSAGE("Importing STEP shape from " << shape_file);
STEPControl_Reader reader;
// Forcing Unit in meter
Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetIVal("read.step.ideas", 1);
Interface_Static::SetIVal("read.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = reader.ReadFile(shape_file.c_str());
if(aStat != IFSelect_RetDone){
throw SALOME_Exception("Reading error for " + shape_file);
}
int NbTrans = reader.TransferRoots();
// There should be only one shape within the file
assert(NbTrans==1);
aShape = reader.OneShape();
return false;
}
/**
* @brief Export the content of a TopoDS_Shape into a shape file (STEP)
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int exportSTEPShape(const std::string shape_file, const TopoDS_Shape& aShape){
MESSAGE("Exporting STEP shape to " << shape_file);
STEPControl_Writer aWriter;
// Forcing Unit in meter
Interface_Static::SetCVal("xstep.cascade.unit","M");
Interface_Static::SetCVal("write.step.unit","M");
Interface_Static::SetIVal("write.step.nonmanifold", 1);
IFSelect_ReturnStatus aStat = aWriter.Transfer(aShape,STEPControl_AsIs);
if(aStat != IFSelect_RetDone){
throw SALOME_Exception("Reading error for " + shape_file);
}
aStat = aWriter.Write(shape_file.c_str());
if(aStat != IFSelect_RetDone){
throw SALOME_Exception("Writing error for " + shape_file);
}
return aStat;
}
/**
* @brief Import the content of a shape file (BREP) into a TopDS_Shape object
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int importBREPShape(const std::string shape_file, TopoDS_Shape& aShape){
MESSAGE("Importing BREP shape from " << shape_file);
BRep_Builder builder;
BRepTools::Read(aShape, shape_file.c_str(), builder);
return false;
}
/**
* @brief Export the content of a TopoDS_Shape into a shape file (BREP)
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int exportBREPShape(const std::string shape_file, const TopoDS_Shape& aShape){
MESSAGE("Exporting BREP shape to " << shape_file);
BRepTools::Write(aShape, shape_file.c_str());
return false;
}
/**
* @brief Import the content of a shape file into a TopDS_Shape object
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int importShape(const std::string shape_file, TopoDS_Shape& aShape){
std::string type = fs::path(shape_file).extension().string();
boost::algorithm::to_lower(type);
if (type == ".brep"){
return importBREPShape(shape_file, aShape);
} else if (type == ".step"){
return importSTEPShape(shape_file, aShape);
} else {
throw SALOME_Exception("Unknow format for importShape: " + type);
}
}
/**
* @brief Import the content of a shape file into a TopDS_Shape object
*
* @param shape_file the shape file
* @param aShape the object
*
* @return error code
*/
int exportShape(const std::string shape_file, const TopoDS_Shape& aShape){
std::string type = fs::path(shape_file).extension().string();
boost::algorithm::to_lower(type);
if (type == ".brep"){
return exportBREPShape(shape_file, aShape);
} else if (type == ".step"){
return exportSTEPShape(shape_file, aShape);
} else {
throw SALOME_Exception("Unknow format for exportShape: " + type);
}
}

View File

@ -1,39 +0,0 @@
// 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 : SMESH_DriverShape.hxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#ifndef _SMESH_DRIVERSHAPE_HXX_
#define _SMESH_DRIVERSHAPE_HXX_
#include <string>
#include <cassert>
class TopoDS_Shape;
int importShape(const std::string shape_file, TopoDS_Shape& aShape);
int exportShape(const std::string shape_file, const TopoDS_Shape& aShape);
#endif

View File

@ -30,7 +30,6 @@
#include "SMESH_Gen.hxx" #include "SMESH_Gen.hxx"
#include "SMESH_DriverMesh.hxx"
#include "SMDS_Mesh.hxx" #include "SMDS_Mesh.hxx"
#include "SMDS_MeshElement.hxx" #include "SMDS_MeshElement.hxx"
#include "SMDS_MeshNode.hxx" #include "SMDS_MeshNode.hxx"
@ -48,7 +47,6 @@
#include <TopoDS_Iterator.hxx> #include <TopoDS_Iterator.hxx>
#include "memoire.h" #include "memoire.h"
#include <functional>
#ifdef WIN32 #ifdef WIN32
#include <windows.h> #include <windows.h>
@ -57,9 +55,6 @@
#include <Basics_Utils.hxx> #include <Basics_Utils.hxx>
using namespace std; using namespace std;
#include <boost/filesystem.hpp>
#include <boost/asio.hpp>
namespace fs = boost::filesystem;
// Environment variable separator // Environment variable separator
#ifdef WIN32 #ifdef WIN32
@ -160,208 +155,6 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(bool theIsEmbeddedMode)
return aMesh; return aMesh;
} }
//=============================================================================
/*!
* Algo to run the computation of all the submeshes of a mesh in sequentila
*/
//=============================================================================
bool SMESH_Gen::sequentialComputeSubMeshes(
SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape,
const ::MeshDimension aDim,
TSetOfInt* aShapesId /*=0*/,
TopTools_IndexedMapOfShape* allowedSubShapes,
SMESH_subMesh::compute_event &computeEvent,
const bool includeSelf,
const bool complexShapeFirst,
const bool aShapeOnly)
{
MESSAGE("Compute submeshes sequentialy");
bool ret = true;
SMESH_subMeshIteratorPtr smIt;
SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
while ( smIt->more() )
{
SMESH_subMesh* smToCompute = smIt->next();
// do not mesh vertices of a pseudo shape
const TopoDS_Shape& shape = smToCompute->GetSubShape();
const TopAbs_ShapeEnum shapeType = shape.ShapeType();
if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
continue;
// check for preview dimension limitations
if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
{
// clear compute state not to show previous compute errors
// if preview invoked less dimension less than previous
smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
continue;
}
if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
{
if (_compute_canceled)
return false;
smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
setCurrentSubMesh( smToCompute );
smToCompute->ComputeStateEngine( computeEvent );
setCurrentSubMesh( nullptr );
smToCompute->SetAllowedSubShapes( nullptr );
}
// we check all the sub-meshes here and detect if any of them failed to compute
if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
ret = false;
else if ( aShapesId )
aShapesId->insert( smToCompute->GetId() );
}
//aMesh.GetMeshDS()->Modified();
return ret;
};
//=============================================================================
/*
* compute of a submesh
* This function is passed to the thread pool
*/
//=============================================================================
const std::function<void(SMESH_subMesh*,
SMESH_subMesh::compute_event,
SMESH_subMesh*,
bool,
TopTools_IndexedMapOfShape *,
TSetOfInt*)>
compute_function([&] (SMESH_subMesh* sm,
SMESH_subMesh::compute_event event,
SMESH_subMesh *shapeSM,
bool aShapeOnly,
TopTools_IndexedMapOfShape *allowedSubShapes,
TSetOfInt* aShapesId) -> void
{
if (sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
{
sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
//setCurrentSubMesh( sm );
sm->ComputeStateEngine(event);
//setCurrentSubMesh( nullptr );
sm->SetAllowedSubShapes( nullptr );
}
if ( aShapesId )
aShapesId->insert( sm->GetId() );
});
//=============================================================================
/*!
* Algo to run the computation of all the submeshes of a mesh in parallel
*/
//=============================================================================
bool SMESH_Gen::parallelComputeSubMeshes(
SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape,
const ::MeshDimension aDim,
TSetOfInt* aShapesId /*=0*/,
TopTools_IndexedMapOfShape* allowedSubShapes,
SMESH_subMesh::compute_event &computeEvent,
const bool includeSelf,
const bool complexShapeFirst,
const bool aShapeOnly)
{
bool ret = true;
SMESH_subMeshIteratorPtr smIt;
SMESH_subMesh *shapeSM = aMesh.GetSubMesh(aShape);
// Pool of thread for computation
// TODO: move when parallelMesh created
aMesh.InitPoolThreads();
TopAbs_ShapeEnum previousShapeType = TopAbs_VERTEX;
int nbThreads = aMesh.GetNbThreads();
MESSAGE("Compute submeshes with threads: " << nbThreads);
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
while ( smIt->more() )
{
SMESH_subMesh* smToCompute = smIt->next();
// do not mesh vertices of a pseudo shape
const TopoDS_Shape& shape = smToCompute->GetSubShape();
const TopAbs_ShapeEnum shapeType = shape.ShapeType();
// Not doing in parallel 1D and 2D meshes
if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
continue;
if(shapeType==TopAbs_FACE||shapeType==TopAbs_EDGE)
aMesh.SetNbThreads(0);
else
aMesh.SetNbThreads(nbThreads);
if (shapeType != previousShapeType) {
// Waiting for all threads for the previous type to end
aMesh.wait();
std::string file_name;
switch(previousShapeType){
case TopAbs_FACE:
file_name = "Mesh2D.med";
break;
case TopAbs_EDGE:
file_name = "Mesh1D.med";
break;
case TopAbs_VERTEX:
file_name = "Mesh0D.med";
break;
case TopAbs_SOLID:
default:
file_name = "";
break;
}
if(file_name != "")
{
fs::path mesh_file = fs::path(aMesh.tmp_folder) / fs::path(file_name);
exportMesh(mesh_file.string(), aMesh, "MESH");
}
//Resetting threaded pool info
previousShapeType = shapeType;
}
// check for preview dimension limitations
if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
{
// clear compute state not to show previous compute errors
// if preview invoked less dimension less than previous
smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
continue;
}
boost::asio::post(*(aMesh._pool), std::bind(compute_function, smToCompute, computeEvent,
shapeSM, aShapeOnly, allowedSubShapes,
aShapesId));
}
// Waiting for the thread for Solids to finish
aMesh.wait();
aMesh.GetMeshDS()->Modified();
return ret;
};
//============================================================================= //=============================================================================
/* /*
* Compute a mesh * Compute a mesh
@ -408,33 +201,57 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
// =============================================== // ===============================================
// Mesh all the sub-shapes starting from vertices // Mesh all the sub-shapes starting from vertices
// =============================================== // ===============================================
if (aMesh.IsParallel())
ret = parallelComputeSubMeshes(
aMesh, aShape, aDim,
aShapesId, allowedSubShapes,
computeEvent,
includeSelf,
complexShapeFirst,
aShapeOnly);
else
ret = sequentialComputeSubMeshes(
aMesh, aShape, aDim,
aShapesId, allowedSubShapes,
computeEvent,
includeSelf,
complexShapeFirst,
aShapeOnly);
smIt = shapeSM->getDependsOnIterator(includeSelf, !complexShapeFirst);
while ( smIt->more() )
{
SMESH_subMesh* smToCompute = smIt->next();
// do not mesh vertices of a pseudo shape
const TopoDS_Shape& shape = smToCompute->GetSubShape();
const TopAbs_ShapeEnum shapeType = shape.ShapeType();
if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
continue;
// check for preview dimension limitations
if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
{
// clear compute state not to show previous compute errors
// if preview invoked less dimension less than previous
smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
continue;
}
if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
{
if (_compute_canceled)
return false;
smToCompute->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
setCurrentSubMesh( smToCompute );
smToCompute->ComputeStateEngine( computeEvent );
setCurrentSubMesh( nullptr );
smToCompute->SetAllowedSubShapes( nullptr );
}
// we check all the sub-meshes here and detect if any of them failed to compute
if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
ret = false;
else if ( aShapesId )
aShapesId->insert( smToCompute->GetId() );
}
//aMesh.GetMeshDS()->Modified();
return ret; return ret;
} }
else else
{ {
// ================================================================ // ================================================================
// Apply algos that do NOT require discretized boundaries // Apply algos that do NOT require discreteized boundaries
// ("all-dimensional") and do NOT support sub-meshes, starting from // ("all-dimensional") and do NOT support sub-meshes, starting from
// the most complex shapes and collect sub-meshes with algos that // the most complex shapes and collect sub-meshes with algos that
// DO support sub-meshes // DO support sub-meshes
// ================================================================ // ================================================================
list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes[4]; // for each dim
// map to sort sm with same dim algos according to dim of // map to sort sm with same dim algos according to dim of
@ -631,7 +448,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes )); sm->SetAllowedSubShapes( fillAllowed( shapeSM, aShapeOnly, allowedSubShapes ));
setCurrentSubMesh( sm ); setCurrentSubMesh( sm );
sm->ComputeStateEngine( computeEvent ); sm->ComputeStateEngine( computeEvent );
setCurrentSubMesh( NULL ); setCurrentSubMesh( NULL );
sm->SetAllowedSubShapes( nullptr ); sm->SetAllowedSubShapes( nullptr );
if ( aShapesId ) if ( aShapesId )
@ -644,7 +460,6 @@ bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
// mesh the rest sub-shapes starting from vertices // mesh the rest sub-shapes starting from vertices
// ----------------------------------------------- // -----------------------------------------------
ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes ); ret = Compute( aMesh, aShape, aFlags | UPWARD, aDim, aShapesId, allowedSubShapes );
} }
MEMOSTAT; MEMOSTAT;

View File

@ -34,7 +34,6 @@
#include "SMESH_Algo.hxx" #include "SMESH_Algo.hxx"
#include "SMESH_ComputeError.hxx" #include "SMESH_ComputeError.hxx"
#include "SMESH_subMesh.hxx"
#include <map> #include <map>
#include <list> #include <list>
@ -42,7 +41,6 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
#include <TopTools_IndexedMapOfShape.hxx> #include <TopTools_IndexedMapOfShape.hxx>
@ -50,7 +48,7 @@ class SMESHDS_Document;
class SMESH_Algo; class SMESH_Algo;
class SMESH_Mesh; class SMESH_Mesh;
class TopoDS_Shape; class TopoDS_Shape;
class SMESH_subMesh;
typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName; typedef SMESH_Hypothesis::Hypothesis_Status TAlgoStateErrorName;
@ -169,28 +167,6 @@ public:
private: private:
bool parallelComputeSubMeshes(
SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape,
const ::MeshDimension aDim,
TSetOfInt* aShapesId,
TopTools_IndexedMapOfShape* allowedSubShapes,
SMESH_subMesh::compute_event &computeEvent,
const bool includeSelf,
const bool complexShapeFirst,
const bool aShapeOnly);
bool sequentialComputeSubMeshes(
SMESH_Mesh & aMesh,
const TopoDS_Shape & aShape,
const ::MeshDimension aDim,
TSetOfInt* aShapesId /*=0*/,
TopTools_IndexedMapOfShape* allowedSubShapes,
SMESH_subMesh::compute_event &computeEvent,
const bool includeSelf,
const bool complexShapeFirst,
const bool aShapeOnly);
int _localId; // unique Id of created objects, within SMESH_Gen entity int _localId; // unique Id of created objects, within SMESH_Gen entity
StudyContextStruct* _studyContext; StudyContextStruct* _studyContext;

View File

@ -80,9 +80,6 @@
#include <pthread.h> #include <pthread.h>
#endif #endif
#include <boost/filesystem.hpp>
namespace fs=boost::filesystem;
// maximum stored group name length in MED file // maximum stored group name length in MED file
#define MAX_MED_GROUP_NAME_LENGTH 80 #define MAX_MED_GROUP_NAME_LENGTH 80
@ -124,9 +121,6 @@ SMESH_Mesh::SMESH_Mesh(int theLocalId,
_callUp = NULL; _callUp = NULL;
_meshDS->ShapeToMesh( PseudoShape() ); _meshDS->ShapeToMesh( PseudoShape() );
_subMeshHolder = new SubMeshHolder; _subMeshHolder = new SubMeshHolder;
// Temporary folder that will be used by parallel computation
tmp_folder = fs::temp_directory_path()/fs::unique_path(fs::path("SMESH_%%%%-%%%%"));
fs::create_directories(tmp_folder);
// assure unique persistent ID // assure unique persistent ID
if ( _document->NbMeshes() > 1 ) if ( _document->NbMeshes() > 1 )
@ -174,11 +168,13 @@ namespace
#ifndef WIN32 #ifndef WIN32
void deleteMeshDS(SMESHDS_Mesh* meshDS) void deleteMeshDS(SMESHDS_Mesh* meshDS)
{ {
//cout << "deleteMeshDS( " << meshDS << endl;
delete meshDS; delete meshDS;
} }
#else #else
static void* deleteMeshDS(void* meshDS) static void* deleteMeshDS(void* meshDS)
{ {
//cout << "deleteMeshDS( " << meshDS << endl;
SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS; SMESHDS_Mesh* m = (SMESHDS_Mesh*)meshDS;
if(m) { if(m) {
delete m; delete m;
@ -239,12 +235,6 @@ SMESH_Mesh::~SMESH_Mesh()
int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS); int result=pthread_create(&thread, NULL, deleteMeshDS, (void*)_meshDS);
#endif #endif
} }
if(_pool)
DeletePoolThreads();
#ifndef _DEBUG_
fs::remove_all(tmp_folder);
#endif
} }
//================================================================================ //================================================================================
@ -542,7 +532,7 @@ int SMESH_Mesh::MEDToMesh(const char* theFileName, const char* theMeshName)
Driver_Mesh::Status status = myReader.Perform(); Driver_Mesh::Status status = myReader.Perform();
#ifdef _DEBUG_ #ifdef _DEBUG_
SMESH_ComputeErrorPtr er = myReader.GetError(); SMESH_ComputeErrorPtr er = myReader.GetError();
if ( er && !er->IsOK() ) MESSAGE(er->myComment); if ( er && !er->IsOK() ) std::cout << er->myComment << std::endl;
#endif #endif
// Reading groups (sub-meshes are out of scope of MED import functionality) // Reading groups (sub-meshes are out of scope of MED import functionality)
@ -1771,6 +1761,7 @@ double SMESH_Mesh::GetComputeProgress() const
rate = algo->GetProgressByTic(); rate = algo->GetProgressByTic();
computedCost += algoDoneCost + rate * algoNotDoneCost; computedCost += algoDoneCost + rate * algoNotDoneCost;
} }
// cout << "rate: "<<rate << " algoNotDoneCost: " << algoNotDoneCost << endl;
} }
// get cost of already treated sub-meshes // get cost of already treated sub-meshes
@ -1791,6 +1782,9 @@ double SMESH_Mesh::GetComputeProgress() const
} }
} }
} }
// cout << "Total: " << totalCost
// << " computed: " << computedCost << " progress: " << computedCost / totalCost
// << " nbElems: " << GetMeshDS()->GetMeshInfo().NbElements() << endl;
return computedCost / totalCost; return computedCost / totalCost;
} }

View File

@ -48,10 +48,6 @@
#include <vector> #include <vector>
#include <ostream> #include <ostream>
#include <boost/filesystem.hpp>
#include <boost/asio/thread_pool.hpp>
#include <boost/thread.hpp>
#ifdef WIN32 #ifdef WIN32
#pragma warning(disable:4251) // Warning DLL Interface ... #pragma warning(disable:4251) // Warning DLL Interface ...
#pragma warning(disable:4290) // Warning Exception ... #pragma warning(disable:4290) // Warning Exception ...
@ -386,26 +382,6 @@ class SMESH_EXPORT SMESH_Mesh
std::ostream& Dump(std::ostream & save); std::ostream& Dump(std::ostream & save);
// Parallel computation functions
void Lock() {_my_lock.lock();};
void Unlock() {_my_lock.unlock();};
int GetNbThreads(){return _NbThreads;};
void SetNbThreads(int nbThreads){_NbThreads=nbThreads;};
void InitPoolThreads(){_pool = new boost::asio::thread_pool(_NbThreads);};
void DeletePoolThreads(){delete _pool;};
void wait(){_pool->join(); DeletePoolThreads(); InitPoolThreads(); }
bool IsParallel(){return _NbThreads > 0;}
// Temporary folder used during parallel Computation
boost::filesystem::path tmp_folder;
boost::asio::thread_pool * _pool = nullptr; //thread pool for computation
private: private:
void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter, void exportMEDCommmon(DriverMED_W_SMESHDS_Mesh& myWriter,
@ -452,12 +428,9 @@ protected:
// 2) to forget not loaded mesh data at hyp modification // 2) to forget not loaded mesh data at hyp modification
TCallUp* _callUp; TCallUp* _callUp;
// Mutex for multhitreading write in SMESH_Mesh
boost::mutex _my_lock;
int _NbThreads=0;
protected: protected:
SMESH_Mesh(); SMESH_Mesh();
SMESH_Mesh(const SMESH_Mesh&) {}; SMESH_Mesh(const SMESH_Mesh&) {};
}; };
#endif #endif

View File

@ -1,46 +0,0 @@
// Copyright (C) 2007-2022 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 : SMESH_MeshLocker.cxx
// Author : Yoann AUDOUIN, EDF
// Module : SMESH
//
#include "SMESH_MeshLocker.hxx"
#include "SMESH_Mesh.hxx"
/*
* When instanced will run the command Lock from a SMESH_Mesh
*/
SMESH_MeshLocker::SMESH_MeshLocker(SMESH_Mesh * aMesh) : _myMesh(aMesh)
{
_myMesh->Lock();
}
/*
* When freed will run the command Unlock from the SMESH_Mesh associated
*/
SMESH_MeshLocker::~SMESH_MeshLocker()
{
_myMesh->Unlock();
}

View File

@ -1,44 +0,0 @@
// Copyright (C) 2007-2022 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 : SMESH_Mesh.hxx
// Author : Paul RASCLE, EDF
// Module : SMESH
//
#ifndef _SMESH_MESHLOCKER_HXX_
#define _SMESH_MESHLOCKER_HXX_
class SMESH_Mesh;
class SMESH_MeshLocker{
public:
SMESH_MeshLocker(SMESH_Mesh * aMesh);
~SMESH_MeshLocker();
protected:
SMESH_MeshLocker();
private:
SMESH_Mesh * _myMesh=nullptr;
};
#endif

View File

@ -3324,7 +3324,7 @@ double SMESH_MesherHelper::GetAngle( const TopoDS_Edge & theE1,
if ( ++nbLoops > 10 ) if ( ++nbLoops > 10 )
{ {
#ifdef _DEBUG_ #ifdef _DEBUG_
MESSAGE("SMESH_MesherHelper::GetAngle(): Captured in a singularity"); cout << "SMESH_MesherHelper::GetAngle(): Captured in a sigularity" << endl;
#endif #endif
return angle; return angle;
} }
@ -5588,6 +5588,8 @@ void SMESH_MesherHelper::WriteShape(const TopoDS_Shape& s)
{ {
const char* name = "/tmp/shape.brep"; const char* name = "/tmp/shape.brep";
BRepTools::Write( s, name ); BRepTools::Write( s, name );
MESSAGE(name); #ifdef _DEBUG_
std::cout << name << std::endl;
#endif
} }

View File

@ -37,7 +37,6 @@
#include "SMESH_Mesh.hxx" #include "SMESH_Mesh.hxx"
#include "SMESH_MesherHelper.hxx" #include "SMESH_MesherHelper.hxx"
#include "SMESH_subMeshEventListener.hxx" #include "SMESH_subMeshEventListener.hxx"
#include "SMESH_MeshLocker.hxx"
#include "utilities.h" #include "utilities.h"
#include "Basics_Utils.hxx" #include "Basics_Utils.hxx"
@ -63,7 +62,7 @@ using namespace std;
#ifdef _DEBUG_ #ifdef _DEBUG_
// enable printing algo + shape id + hypo used while meshing // enable printing algo + shape id + hypo used while meshing
#define PRINT_WHO_COMPUTE_WHAT //#define PRINT_WHO_COMPUTE_WHAT
#endif #endif
//============================================================================= //=============================================================================
@ -1393,7 +1392,6 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
else if (( event == COMPUTE || event == COMPUTE_SUBMESH ) else if (( event == COMPUTE || event == COMPUTE_SUBMESH )
&& !_alwaysComputed ) && !_alwaysComputed )
{ {
SMESH_MeshLocker myLocker(_father);
const TopoDS_Vertex & V = TopoDS::Vertex( _subShape ); const TopoDS_Vertex & V = TopoDS::Vertex( _subShape );
gp_Pnt P = BRep_Tool::Pnt(V); gp_Pnt P = BRep_Tool::Pnt(V);
if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) { if ( SMDS_MeshNode * n = _father->GetMeshDS()->AddNode(P.X(), P.Y(), P.Z()) ) {
@ -1513,10 +1511,9 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
break; break;
} }
TopoDS_Shape shape = _subShape; TopoDS_Shape shape = _subShape;
algo->setSubMeshesToCompute(this); algo->SubMeshesToCompute().assign( 1, this );
// check submeshes needed // check submeshes needed
// In parallel there would be no submesh to check if (_father->HasShapeToMesh() ) {
if (_father->HasShapeToMesh() && !_father->IsParallel()) {
bool subComputed = false, subFailed = false; bool subComputed = false, subFailed = false;
if (!algo->OnlyUnaryInput()) { if (!algo->OnlyUnaryInput()) {
// --- commented for bos#22320 to compute all sub-shapes at once if possible; // --- commented for bos#22320 to compute all sub-shapes at once if possible;
@ -1578,7 +1575,7 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
_computeError = SMESH_ComputeError::Worst( _computeError, algo->GetComputeError() ); _computeError = SMESH_ComputeError::Worst( _computeError, algo->GetComputeError() );
} }
catch ( ::SMESH_ComputeError& comperr ) { catch ( ::SMESH_ComputeError& comperr ) {
MESSAGE(" SMESH_ComputeError caught"); cout << " SMESH_ComputeError caught" << endl;
if ( !_computeError ) _computeError = SMESH_ComputeError::New(); if ( !_computeError ) _computeError = SMESH_ComputeError::New();
*_computeError = comperr; *_computeError = comperr;
} }
@ -1645,7 +1642,6 @@ bool SMESH_subMesh::ComputeStateEngine(compute_event event)
#ifdef PRINT_WHO_COMPUTE_WHAT #ifdef PRINT_WHO_COMPUTE_WHAT
for (subS.ReInit(); subS.More(); subS.Next()) for (subS.ReInit(); subS.More(); subS.Next())
{ {
SMESH_MeshLocker myLocker(_father);
const std::list <const SMESHDS_Hypothesis *> & hyps = const std::list <const SMESHDS_Hypothesis *> & hyps =
_algo->GetUsedHypothesis( *_father, _subShape ); _algo->GetUsedHypothesis( *_father, _subShape );
SMESH_Comment hypStr; SMESH_Comment hypStr;

View File

@ -79,7 +79,6 @@ class SMESH_EXPORT SMESH_subMesh
SMESH_subMesh *GetFirstToCompute(); SMESH_subMesh *GetFirstToCompute();
SMESH_Algo* GetAlgo() const; SMESH_Algo* GetAlgo() const;
SMESH_Algo* CopyAlgo() const;
const std::map < int, SMESH_subMesh * >& DependsOn(); const std::map < int, SMESH_subMesh * >& DependsOn();
bool DependsOn( const SMESH_subMesh* other ) const; bool DependsOn( const SMESH_subMesh* other ) const;

View File

@ -2212,8 +2212,7 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand )
"GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces", "GetElemNode","IsMediumNode","IsMediumNodeOfAnyElem","ElemNbEdges","ElemNbFaces",
"GetElemFaceNodes", "GetFaceNormal", "FindElementByNodes", "GetElemFaceNodes", "GetFaceNormal", "FindElementByNodes",
"IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor", "IsPoly","IsQuadratic","BaryCenter","GetHypothesisList", "SetAutoColor", "GetAutoColor",
"Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder", "Clear", "ConvertToStandalone", "GetMeshOrder", "SetMeshOrder"
"SetNbThreads"
,"" }; // <- mark of end ,"" }; // <- mark of end
sameMethods.Insert( names ); sameMethods.Insert( names );
} }

View File

@ -6645,6 +6645,8 @@ CORBA::Boolean SMESH_Gen_i::IsApplicable ( const char* theAlgoType,
SMESH_CATCH( SMESH::doNothing ); SMESH_CATCH( SMESH::doNothing );
MESSAGE("SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "")); #ifdef _DEBUG_
cout << "SMESH_Gen_i::IsApplicable(): exception in " << ( theAlgoType ? theAlgoType : "") << endl;
#endif
return true; return true;
} }

View File

@ -7037,16 +7037,6 @@ TListOfListOfInt SMESH_Mesh_i::findConcurrentSubMeshes()
return res; return res;
} }
//=============================================================================
/*!
* \brief Set the number of threads for a parallel computation
*/
//=============================================================================
void SMESH_Mesh_i::SetNbThreads(int nbThreads){
_impl->SetNbThreads(nbThreads);
}
//============================================================================= //=============================================================================
/*! /*!
* \brief Convert submesh ids into submesh interfaces * \brief Convert submesh ids into submesh interfaces

View File

@ -673,9 +673,6 @@ private:
SMESH::submesh_array_array& theSubMeshOrder, SMESH::submesh_array_array& theSubMeshOrder,
const bool theIsDump); const bool theIsDump);
void SetNbThreads(int nbThreads);
void SetMesherNbThreads(int nbThreads);
/*! /*!
* \brief Finds concurrent sub-meshes * \brief Finds concurrent sub-meshes
*/ */

View File

@ -462,21 +462,6 @@ class smeshBuilder( SMESH._objref_SMESH_Gen, object ):
obj,name = name,obj obj,name = name,obj
return Mesh(self, self.geompyD, obj, name) return Mesh(self, self.geompyD, obj, name)
def ParallelMesh(self, obj, param, nbThreads, name=0):
"""
Create a parallel mesh.
Parameters:
obj: geometrical object for meshing
name: the name for the new mesh.
param: full mesh parameters
nbThreads: Number of threads for parallelisation.
Returns:
an instance of class :class:`ParallelMesh`.
"""
return ParallelMesh(self, self.geompyD, obj, param, nbThreads, name)
def RemoveMesh( self, mesh ): def RemoveMesh( self, mesh ):
""" """
Delete a mesh Delete a mesh
@ -1878,6 +1863,7 @@ class Mesh(metaclass = MeshMeta):
geom = self.geom geom = self.geom
return self.smeshpyD.Evaluate(self.mesh, geom) return self.smeshpyD.Evaluate(self.mesh, geom)
def Compute(self, geom=0, discardModifs=False, refresh=False): def Compute(self, geom=0, discardModifs=False, refresh=False):
""" """
Compute the mesh and return the status of the computation Compute the mesh and return the status of the computation
@ -7501,121 +7487,6 @@ class Mesh(metaclass = MeshMeta):
pass # end of Mesh class pass # end of Mesh class
def _copy_netgen_param(dim, local_param, global_param):
if dim==1:
#TODO: Try to identify why we need to substract 1
local_param.NumberOfSegments(int(global_param.GetNbSegPerEdge())-1)
elif dim==2:
local_param.SetMaxSize(global_param.GetMaxSize())
local_param.SetMinSize(global_param.GetMinSize())
local_param.SetOptimize(global_param.GetOptimize())
local_param.SetFineness(global_param.GetFineness())
local_param.SetNbSegPerEdge(global_param.GetNbSegPerEdge())
local_param.SetNbSegPerRadius(global_param.GetNbSegPerRadius())
local_param.SetGrowthRate(global_param.GetGrowthRate()*0.9)
local_param.SetChordalError(global_param.GetChordalError())
local_param.SetChordalErrorEnabled(global_param.GetChordalErrorEnabled())
local_param.SetUseSurfaceCurvature(global_param.GetUseSurfaceCurvature())
local_param.SetUseDelauney(global_param.GetUseDelauney())
local_param.SetQuadAllowed(global_param.GetQuadAllowed())
local_param.SetWorstElemMeasure(global_param.GetWorstElemMeasure())
local_param.SetCheckChartBoundary(global_param.GetCheckChartBoundary())
local_param.SetNbThreads(global_param.GetNbThreads())
else:
local_param.SetMaxSize(global_param.GetMaxSize())
local_param.SetMinSize(global_param.GetMinSize())
local_param.SetOptimize(global_param.GetOptimize())
local_param.SetCheckOverlapping(global_param.GetCheckOverlapping())
local_param.SetCheckChartBoundary(global_param.GetCheckChartBoundary())
local_param.SetFineness(global_param.GetFineness())
local_param.SetNbSegPerEdge(global_param.GetNbSegPerEdge())
local_param.SetNbSegPerRadius(global_param.GetNbSegPerRadius())
local_param.SetGrowthRate(global_param.GetGrowthRate())
local_param.SetNbThreads(global_param.GetNbThreads())
class ParallelMesh(Mesh):
"""
Surcharge on Mesh for parallel computation of a mesh
"""
def __init__(self, smeshpyD, geompyD, geom, param, nbThreads, name=0):
"""
Create a parallel mesh.
Parameters:
geom: geometrical object for meshing
param: full mesh parameters
nbThreads: Number of threads for parallelisation.
name: the name for the new mesh.
Returns:
an instance of class :class:`ParallelMesh`.
"""
if not isinstance(geom, geomBuilder.GEOM._objref_GEOM_Object):
raise ValueError("geom argument must be a geometry")
if not isinstance(param, NETGENPlugin._objref_NETGENPlugin_Hypothesis):
raise ValueError("param must come from NETGENPlugin")
if nbThreads < 1:
raise ValueError("Number of threads must be stricly greater than 1")
# Splitting geometry into 3D elements and all the 2D/1D into one compound
object_solids = geompyD.ExtractShapes(geom, geompyD.ShapeType["SOLID"],
True)
solids = []
isolid = 0
for solid in object_solids:
isolid += 1
geompyD.addToStudyInFather( geom, solid, 'Solid_{}'.format(isolid) )
solids.append(solid)
faces = []
iface = 0
for isolid, solid in enumerate(solids):
solid_faces = geompyD.ExtractShapes(solid, geompyD.ShapeType["FACE"],
True)
for face in solid_faces:
faces.append(face)
iface += 1
geompyD.addToStudyInFather(solid, face,
'Face_{}'.format(iface))
# Creating submesh for edges 1D/2D part
all_faces = geompyD.MakeCompound(faces)
geompyD.addToStudy(all_faces, 'Compound_1')
all_faces = geompyD.MakeGlueEdges(all_faces, 1e-07)
all_faces = geompyD.MakeGlueFaces(all_faces, 1e-07)
geompyD.addToStudy(all_faces, 'global2D')
super(ParallelMesh, self).__init__(smeshpyD, geompyD, geom, name)
self.mesh.SetNbThreads(nbThreads)
self.UseExistingSegments()
self.UseExistingFaces()
algo2d = self.Triangle(geom=all_faces, algo="NETGEN_2D")
param2d = algo2d.Parameters()
_copy_netgen_param(2, param2d, param)
for solid_id, solid in enumerate(solids):
name = "Solid_{}".format(solid_id)
self.UseExistingSegments(geom=solid)
self.UseExistingFaces(geom=solid)
algo3d = self.Tetrahedron(geom=solid, algo="NETGEN_3D_Remote")
param3d = algo3d.Parameters()
_copy_netgen_param(3, param3d, param)
pass # End of ParallelMesh
class meshProxy(SMESH._objref_SMESH_Mesh): class meshProxy(SMESH._objref_SMESH_Mesh):
""" """
Private class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility Private class used to compensate change of CORBA API of SMESH_Mesh for backward compatibility

View File

@ -1,131 +0,0 @@
# contains function to compute a mesh in parallel
from platform import java_ver
import sys
from tkinter import W
import salome
import time
salome.salome_init()
import salome_notebook
notebook = salome_notebook.NoteBook()
###
### GEOM component
###
import GEOM
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
import math
import SALOMEDS
import numpy as np
geompy = geomBuilder.New()
smesh = smeshBuilder.New()
def build_seq_mesh(nbox, boxsize, offset):
# Create 3D faces
boxes = []
# First creating all the boxes
for i in range(nbox):
for j in range(nbox):
for k in range(nbox):
x_orig = i*(boxsize+offset)
y_orig = j*(boxsize+offset)
z_orig = k*(boxsize+offset)
tmp_box = geompy.MakeBoxDXDYDZ(boxsize, boxsize, boxsize)
if not i == j == k == 0:
box = geompy.MakeTranslation(tmp_box, x_orig,
y_orig, z_orig)
else:
box = tmp_box
geompy.addToStudy(box, 'box_{}:{}:{}'.format(i, j, k))
boxes.append(box)
# Create fuse of all boxes
all_boxes = geompy.MakeCompound(boxes)
geompy.addToStudy(all_boxes, 'Compound_1')
# Removing duplicates faces and edges
all_boxes = geompy.MakeGlueFaces(all_boxes, 1e-07)
geompy.addToStudy(all_boxes, 'Glued_Faces_1')
all_boxes = geompy.MakeGlueEdges(all_boxes, 1e-07)
geompy.addToStudy(all_boxes, 'rubik_cube')
# Building sequetial mesh
print("Creating mesh")
all_box_mesh = smesh.Mesh(all_boxes, "seq_mesh")
print("Adding algo")
algo3d = all_box_mesh.Tetrahedron(algo=smeshBuilder.NETGEN_1D2D3D)
netgen_parameters = algo3d.Parameters()
netgen_parameters.SetMaxSize(34.641)
netgen_parameters.SetMinSize(0.141421)
netgen_parameters.SetOptimize(1)
netgen_parameters.SetCheckOverlapping(0)
netgen_parameters.SetCheckChartBoundary(0)
netgen_parameters.SetFineness(5)
netgen_parameters.SetNbSegPerEdge(16*(boxsize//100))
netgen_parameters.SetNbSegPerRadius(1.5)
netgen_parameters.SetGrowthRate(0.15)
netgen_parameters.SetChordalError(-1)
netgen_parameters.SetChordalErrorEnabled(0)
netgen_parameters.SetUseSurfaceCurvature(1)
netgen_parameters.SetQuadAllowed(0)
netgen_parameters.SetCheckOverlapping(False)
netgen_parameters.SetNbThreads(2)
return all_boxes, all_box_mesh, netgen_parameters
def run_test(nbox=2, boxsize=100):
""" Run sequential mesh and parallel version of it
nbox: NUmber of boxes
boxsize: Size of each box
"""
geom, seq_mesh, netgen_parameters = build_seq_mesh(nbox, boxsize, 0)
par_mesh = smesh.ParallelMesh(geom, netgen_parameters, 6, name="par_mesh")
start = time.monotonic()
is_done = seq_mesh.Compute()
assert is_done
stop = time.monotonic()
time_seq = stop-start
start = time.monotonic()
is_done = par_mesh.Compute()
assert is_done
stop = time.monotonic()
time_par = stop-start
print(" Tetrahedron: ", seq_mesh.NbTetras(), par_mesh.NbTetras())
print(" Triangle: ", seq_mesh.NbTriangles(), par_mesh.NbTriangles())
print(" edge: ", seq_mesh.NbEdges(), par_mesh.NbEdges())
assert par_mesh.NbTetras() > 0
assert par_mesh.NbTriangles() > 0
assert par_mesh.NbEdges() > 0
print("Time elapsed (seq, par): ", time_seq, time_par)
def main():
nbox = 2
boxsize = 100
run_test(nbox, boxsize)
main()

View File

@ -1,129 +0,0 @@
#!/usr/bin/env python
import sys
import salome
salome.salome_init()
from os import path
import tempfile
import subprocess
import GEOM, SMESH, SALOMEDS
from salome.geom import geomBuilder
from salome.smesh import smeshBuilder
import math
smesh = smeshBuilder.New()
geompy = geomBuilder.New()
import medcoupling as mc
def create_param_file(param_file):
""" Create a parameter file for runner """
param = """1
34.64
0.14
16
0.15
1.5
0
0
1
5
1
1
-1
3
3
0.2
2
1
0
0
2
2
0
0
0
0"""
with open(param_file, "w") as ffile:
ffile.write(param)
def test_netgen3d():
""" Test netgen3d mesher """
# Building geometry
box = geompy.MakeBoxDXDYDZ(200, 200, 200)
geompy.ExtractShapes(box, geompy.ShapeType["FACE"], True)
groupe_1 = geompy.CreateGroup(box, geompy.ShapeType["FACE"])
geompy.UnionIDs(groupe_1, [3, 13, 23, 27, 31, 33])
[_, _, _, _, _, _, groupe_1] = geompy.GetExistingSubObjects(box, False)
# Creating 2D mesh
netgen_2d_parameters_1 = smesh.CreateHypothesisByAverageLength(
'NETGEN_Parameters_2D', 'NETGENEngine', 34.641, 0)
mesh_2d = smesh.Mesh(groupe_1, 'Maillage_1')
mesh_2d.AddHypothesis(groupe_1, netgen_2d_parameters_1)
mesh_2d.Triangle(algo=smeshBuilder.NETGEN_1D2D)
is_done = mesh_2d.Compute()
assert is_done
smesh.SetName(mesh_2d, 'Maillage_1')
with tempfile.TemporaryDirectory() as tmp_dir:
mesh_file = path.join(tmp_dir, "mesh.med")
shape_file = path.join(tmp_dir, "shape.step")
param_file = path.join(tmp_dir, "param.txt")
output_mesh = path.join(tmp_dir, "mesh3D.med")
print("Running in folder: ", tmp_dir)
create_param_file(param_file)
mesh_2d.ExportMED(mesh_file, 0, 41, 1, mesh_2d, 1, [], '', -1, 1)
geompy.ExportSTEP(box, shape_file, GEOM.LU_METER)
runner = path.join("${NETGENPLUGIN_ROOT_DIR}",
"bin",
"salome",
"NETGENPlugin_Runner")
if sys.platform == 'win32':
runner += ".exe"
cmd = "{runner} NETGEN3D {mesh_file} {shape_file} "\
"{param_file} NONE NONE {output_mesh}"\
.format(runner=runner,
mesh_file=mesh_file,
shape_file=shape_file,
param_file=param_file,
output_mesh=output_mesh)
print(cmd)
subprocess.check_call(cmd, shell=True)
mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", 0)
nb_tetras = mesh_read.getNumberOfCellsWithType(mc.NORM_TETRA4)
nb_points = mesh_read.getNumberOfNodes()
mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", -1)
nb_triangles = mesh_read.getNumberOfCellsWithType(mc.NORM_TRI3)
mesh_read = mc.ReadUMeshFromFile(output_mesh, "MESH", -2)
nb_segments = mesh_read.getNumberOfCellsWithType(mc.NORM_SEG2)
print("Nb Tetras:", nb_tetras)
print("Nb Triangles:", nb_triangles)
print("Nb Segments:", nb_segments)
print("Nb Points:", nb_points)
assert nb_points > 0
assert nb_segments > 0
assert nb_triangles > 0
assert nb_tetras > 0
if __name__ == "__main__":
test_netgen3d()

View File

@ -63,8 +63,6 @@ SET(BAD_TESTS
SMESH_test2.py SMESH_test2.py
SMESH_test4.py SMESH_test4.py
SMESH_create_dual_mesh_adapt.py SMESH_create_dual_mesh_adapt.py
netgen_runner.py
SMESH_ParallelCompute.py
) )
IF(NOT WIN32) IF(NOT WIN32)
LIST(APPEND BAD_TESTS LIST(APPEND BAD_TESTS