occ parameters from python, gui and meshsize parameters now the same

This commit is contained in:
Christopher Lackner 2019-08-27 10:10:17 +02:00
parent 7f442d14f2
commit 9d96c0e432
9 changed files with 127 additions and 94 deletions

View File

@ -989,7 +989,7 @@ namespace netgen
void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh, void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh,
const MeshingParameters & mparam) const MeshingParameters & mparam, const OCCParameters& occparam)
{ {
mesh.SetGlobalH (mparam.maxh); mesh.SetGlobalH (mparam.maxh);
mesh.SetMinimalH (mparam.minh); mesh.SetMinimalH (mparam.minh);
@ -1273,7 +1273,8 @@ namespace netgen
int OCCGenerateMesh (OCCGeometry & geom, shared_ptr<Mesh> & mesh, MeshingParameters & mparam) int OCCGenerateMesh (OCCGeometry & geom, shared_ptr<Mesh> & mesh, MeshingParameters & mparam,
const OCCParameters& occparam)
{ {
multithread.percent = 0; multithread.percent = 0;
@ -1283,7 +1284,7 @@ namespace netgen
mesh = make_shared<Mesh>(); mesh = make_shared<Mesh>();
mesh->geomtype = Mesh::GEOM_OCC; mesh->geomtype = Mesh::GEOM_OCC;
OCCSetLocalMeshSize(geom,*mesh, mparam); OCCSetLocalMeshSize(geom,*mesh, mparam, occparam);
} }
if (multithread.terminate || mparam.perfstepsend <= MESHCONST_ANALYSE) if (multithread.terminate || mparam.perfstepsend <= MESHCONST_ANALYSE)

View File

@ -1684,12 +1684,6 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
int OCCGeometry :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam)
{
return OCCGenerateMesh (*this, mesh, mparam);
}
const Refinement & OCCGeometry :: GetRefinement () const const Refinement & OCCGeometry :: GetRefinement () const
@ -1697,20 +1691,6 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
return * new OCCRefinementSurfaces (*this); return * new OCCRefinementSurfaces (*this);
} }
OCCParameters :: OCCParameters()
{
resthcloseedgefac = 1;
resthcloseedgeenable = 1;
resthminedgelen = 0.001;
resthminedgelenenable = 1;
}
void OCCParameters :: Print(ostream & ost) const void OCCParameters :: Print(ostream & ost) const
{ {
ost << "OCC Parameters:" << endl ost << "OCC Parameters:" << endl
@ -1720,11 +1700,13 @@ void STEP_GetEntityName(const TopoDS_Shape & theShape, STEPCAFControl_Reader * a
<< ", min len = " << resthminedgelen << endl; << ", min len = " << resthminedgelen << endl;
} }
DLL_HEADER extern OCCParameters occparam;
OCCParameters occparam;
int OCCGeometry :: GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam)
{
OCCParameters occparam; return OCCGenerateMesh (*this, mesh, mparam, occparam);
}
} }

View File

@ -404,26 +404,19 @@ namespace netgen
public: public:
/// Factor for meshing close edges /// Factor for meshing close edges
double resthcloseedgefac; double resthcloseedgefac = 2.;
/// Enable / Disable detection of close edges /// Enable / Disable detection of close edges
int resthcloseedgeenable; int resthcloseedgeenable = true;
/// Minimum edge length to be used for dividing edges to mesh points /// Minimum edge length to be used for dividing edges to mesh points
double resthminedgelen; double resthminedgelen = 0.001;
/// Enable / Disable use of the minimum edge length (by default use 1e-4) /// Enable / Disable use of the minimum edge length (by default use 1e-4)
int resthminedgelenenable; int resthminedgelenenable = true;
/*!
Default Constructor for the OpenCascade
Mesh generation parameter set
*/
OCCParameters();
/*! /*!
Dump all the OpenCascade specific meshing parameters Dump all the OpenCascade specific meshing parameters
@ -439,16 +432,14 @@ namespace netgen
DLL_HEADER OCCGeometry * LoadOCC_STEP (const char * filename); DLL_HEADER OCCGeometry * LoadOCC_STEP (const char * filename);
DLL_HEADER OCCGeometry * LoadOCC_BREP (const char * filename); DLL_HEADER OCCGeometry * LoadOCC_BREP (const char * filename);
DLL_HEADER extern OCCParameters occparam;
// Philippose - 31.09.2009 // Philippose - 31.09.2009
// External access to the mesh generation functions within the OCC // External access to the mesh generation functions within the OCC
// subsystem (Not sure if this is the best way to implement this....!!) // subsystem (Not sure if this is the best way to implement this....!!)
DLL_HEADER extern int OCCGenerateMesh (OCCGeometry & occgeometry, shared_ptr<Mesh> & mesh, DLL_HEADER extern int OCCGenerateMesh (OCCGeometry & occgeometry, shared_ptr<Mesh> & mesh,
MeshingParameters & mparam); MeshingParameters & mparam, const OCCParameters& occparam);
DLL_HEADER extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh, const MeshingParameters & mparam); DLL_HEADER extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh, const MeshingParameters & mparam,
const OCCParameters& occparam);
DLL_HEADER extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend, MeshingParameters & mparam); DLL_HEADER extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend, MeshingParameters & mparam);

View File

@ -28,6 +28,7 @@ namespace netgen
extern DLL_HEADER shared_ptr<NetgenGeometry> ng_geometry; extern DLL_HEADER shared_ptr<NetgenGeometry> ng_geometry;
extern DLL_HEADER shared_ptr<Mesh> mesh; extern DLL_HEADER shared_ptr<Mesh> mesh;
extern DLL_HEADER MeshingParameters mparam; extern DLL_HEADER MeshingParameters mparam;
extern DLL_HEADER OCCParameters occparam;
char * err_needsoccgeometry = (char*) "This operation needs an OCC geometry"; char * err_needsoccgeometry = (char*) "This operation needs an OCC geometry";
extern char * err_needsmesh; extern char * err_needsmesh;

View File

@ -15,6 +15,45 @@ namespace netgen
extern std::shared_ptr<NetgenGeometry> ng_geometry; extern std::shared_ptr<NetgenGeometry> ng_geometry;
} }
static string occparameter_description = R"delimiter(
OCC Specific Meshing Parameters
-------------------------------
closeedgefac: Optional[float] = 1.
Factor for meshing close edges, if None it is disabled.
minedgelen: Optional[float] = 0.001
Minimum edge length to be used for dividing edges to mesh points. If
None this is disabled.
)delimiter";
void CreateOCCParametersFromKwargs(OCCParameters& occparam, py::dict kwargs)
{
if(kwargs.contains("closeedgefac"))
{
auto val = kwargs.attr("pop")("closeedgefac");
if(val.is_none())
occparam.resthcloseedgeenable = false;
else
{
occparam.resthcloseedgefac = py::cast<double>(val);
occparam.resthcloseedgeenable = true;
}
}
if(kwargs.contains("minedgelen"))
{
auto val = kwargs.attr("pop")("minedgelen");
if(val.is_none())
occparam.resthminedgelenenable = false;
else
{
occparam.resthminedgelen = py::cast<double>(val);
occparam.resthminedgelenenable = true;
}
}
}
DLL_HEADER void ExportNgOCC(py::module &m) DLL_HEADER void ExportNgOCC(py::module &m)
{ {
@ -132,20 +171,27 @@ DLL_HEADER void ExportNgOCC(py::module &m)
MeshingParameters* pars, py::kwargs kwargs) MeshingParameters* pars, py::kwargs kwargs)
{ {
MeshingParameters mp; MeshingParameters mp;
if(pars) mp = *pars; OCCParameters occparam;
{ {
py::gil_scoped_acquire aq; py::gil_scoped_acquire aq;
if(pars)
{
auto mp_kwargs = CreateDictFromFlags(pars->geometrySpecificParameters);
CreateOCCParametersFromKwargs(occparam, mp_kwargs);
mp = *pars;
}
CreateOCCParametersFromKwargs(occparam, kwargs);
CreateMPfromKwargs(mp, kwargs); CreateMPfromKwargs(mp, kwargs);
} }
auto mesh = make_shared<Mesh>(); auto mesh = make_shared<Mesh>();
SetGlobalMesh(mesh); SetGlobalMesh(mesh);
mesh->SetGeometry(geo); mesh->SetGeometry(geo);
ng_geometry = geo; ng_geometry = geo;
geo->GenerateMesh(mesh,mp); OCCGenerateMesh(*geo, mesh, mp, occparam);
return mesh; return mesh;
}, py::arg("mp") = nullptr, }, py::arg("mp") = nullptr,
py::call_guard<py::gil_scoped_release>(), py::call_guard<py::gil_scoped_release>(),
meshingparameter_description.c_str()) (meshingparameter_description + occparameter_description).c_str())
; ;
m.def("LoadOCCGeometry",[] (const string & filename) m.def("LoadOCCGeometry",[] (const string & filename)

View File

@ -21,15 +21,21 @@ static string stlparameter_description = R"delimiter(
STL Specific Meshing Parameters STL Specific Meshing Parameters
------------------------------- -------------------------------
yangle: float = yangle: float = 30.
Angle for edge detection Angle for edge detection
contyangle: float = contyangle: float = 20.
Edges continue if angle > contyangle Edges continue if angle > contyangle
edgecornerangle: float = edgecornerangle: float = 60.
Angle of geometry edge at which the mesher should set a point. Angle of geometry edge at which the mesher should set a point.
closeedgefac: Optional[float] = 1.
Factor for meshing close edges, if None it is disabled.
minedgelen: Optional[float] = 0.001
Minimum edge length to be used for dividing edges to mesh points. If
None this is disabled.
)delimiter"; )delimiter";
void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs) void CreateSTLParametersFromKwargs(STLParameters& stlparam, py::dict kwargs)

View File

@ -235,7 +235,7 @@ class DLL_HEADER STLParameters
public: public:
/// angle for edge detection /// angle for edge detection
double yangle = 30.; double yangle = 30.;
double contyangle; //edges continued with contyangle double contyangle = 20.; //edges continued with contyangle
/// angle of geometry edge at which the mesher should set a point /// angle of geometry edge at which the mesher should set a point
double edgecornerangle = 60.; double edgecornerangle = 60.;
/// angle inside on chart /// angle inside on chart
@ -243,25 +243,25 @@ public:
/// angle for overlapping parts of char /// angle for overlapping parts of char
double outerchartangle = 70.; double outerchartangle = 70.;
/// 0 .. no, 1 .. local, (2 .. global) /// 0 .. no, 1 .. local, (2 .. global)
int usesearchtree; int usesearchtree = 0;
/// ///
double resthatlasfac; double resthatlasfac = 2.;
bool resthatlasenable; bool resthatlasenable = true;
double atlasminh; double atlasminh = 0.1;
double resthsurfcurvfac = 1.; double resthsurfcurvfac = 2.;
bool resthsurfcurvenable = false; bool resthsurfcurvenable = false;
double resthchartdistfac = 1.5; double resthchartdistfac = 1.2;
bool resthchartdistenable = true; bool resthchartdistenable = true;
double resthcloseedgefac = 2.; double resthcloseedgefac = 1.;
bool resthcloseedgeenable = true; bool resthcloseedgeenable = true;
double resthedgeanglefac = 1.; double resthedgeanglefac = 1.;
bool resthedgeangleenable = false; bool resthedgeangleenable = false;
double resthsurfmeshcurvfac = 2.; double resthsurfmeshcurvfac = 1.;
bool resthsurfmeshcurvenable = false; bool resthsurfmeshcurvenable = false;
double resthlinelengthfac = 0.5; double resthlinelengthfac = 0.5;

View File

@ -32,6 +32,7 @@ namespace netgen {
MeshingParameters & mp); MeshingParameters & mp);
extern MeshingParameters mparam; extern MeshingParameters mparam;
DLL_HEADER extern STLParameters stlparam; DLL_HEADER extern STLParameters stlparam;
DLL_HEADER extern OCCParameters occparam;
} }
@ -859,7 +860,7 @@ namespace nglib
// slate // slate
me->DeleteMesh(); me->DeleteMesh();
OCCSetLocalMeshSize(*occgeom, *me, mparam); OCCSetLocalMeshSize(*occgeom, *me, mparam, occparam);
return(NG_OK); return(NG_OK);
} }

View File

@ -6,61 +6,66 @@ class _MeshsizeObject:
return MeshingParameters(curvaturesafety=1, return MeshingParameters(curvaturesafety=1,
segmentsperedge=0.3, segmentsperedge=0.3,
grading=0.7, grading=0.7,
resthsurfcurvfac=0.25, surfcurvfac=0.25,
resthchartdistfac=0.8, chartdistfac=0.8,
resthlinelengthfac=0.2, linelengthfac=0.2,
resthcloseedgefac=0.5, closeedgefac=0.5,
resthminedgelen=0.002, minedgelen=0.002,
resthedgeanglefac=0.25, edgeanglefac=0.25,
resthsurfmeshcurvfac=1.) surfmeshcurvfac=1.,
optsteps3d=5)
@property @property
def coarse(self): def coarse(self):
return MeshingParameters(curvaturesafety=1.5, return MeshingParameters(curvaturesafety=1.5,
segmentsperedge=0.5, segmentsperedge=0.5,
grading=0.5, grading=0.5,
resthsurfcurvfac=0.5, surfcurvfac=0.5,
resthchartdistfac=1, chartdistfac=1,
resthlinelengthfac=0.35, linelengthfac=0.35,
resthcloseedgefac=1, closeedgefac=1,
resthminedgelen=0.02, minedgelen=0.02,
resthedgeanglefac=0.5, edgeanglefac=0.5,
resthsurfmeshcurvfac=1.5) surfmeshcurvfac=1.5,
optsteps3d=5)
@property @property
def moderate(self): def moderate(self):
return MeshingParameters(curvaturesafety=2, return MeshingParameters(curvaturesafety=2,
segmentsperedge=1, segmentsperedge=1,
grading=0.3, grading=0.3,
resthsurfcurvfac=1., surfcurvfac=1.,
resthchartdistfac=1.5, chartdistfac=1.5,
resthlinelengthfac=0.5, linelengthfac=0.5,
resthcloseedgefac=2, closeedgefac=2,
resthminedgelen=0.2, minedgelen=0.2,
resthedgeanglefac=1, edgeanglefac=1,
resthsurfmeshcurvfac=2.) surfmeshcurvfac=2.,
optsteps3d=5)
@property @property
def fine(self): def fine(self):
return MeshingParameters(curvaturesafety=3, return MeshingParameters(curvaturesafety=3,
segmentsperedge=2, segmentsperedge=2,
grading=0.2, grading=0.2,
resthsurfcurvfac=1.5, surfcurvfac=1.5,
resthchartdistfac=2, chartdistfac=2,
resthlinelengthfac=1.5, linelengthfac=1.5,
resthcloseedgefac=3.5, closeedgefac=3.5,
resthminedgelen=1., minedgelen=1.,
resthedgeanglefac=1.5, edgeanglefac=1.5,
resthsurfmeshcurvfac=3.) surfmeshcurvfac=3.,
optsteps3d=5)
@property @property
def very_fine(self): def very_fine(self):
return MeshingParameters(curvaturesafety=5, return MeshingParameters(curvaturesafety=5,
segmentsperedge=3, segmentsperedge=3,
grading=0.1, grading=0.1,
resthsurfcurvfac=3, surfcurvfac=3,
resthchartdistfac=5, chartdistfac=5,
resthlinelengthfac=3, linelengthfac=3,
resthcloseedgefac=5, closeedgefac=5,
resthminedgelen=2., minedgelen=2.,
resthedgeanglefac=3., edgeanglefac=3.,
resthsurfmeshcurvfac=5.) surfmeshcurvfac=5.,
optsteps3d=5)
meshsize = _MeshsizeObject() meshsize = _MeshsizeObject()