From 6813c519b6cdfb01fd8186ecf056295b2a426542 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Tue, 20 Feb 2024 08:47:09 +0100 Subject: [PATCH 1/5] feature check macro for transition from INT to IVec --- libsrc/core/hashtable.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libsrc/core/hashtable.hpp b/libsrc/core/hashtable.hpp index 4ba73451..1be25b86 100644 --- a/libsrc/core/hashtable.hpp +++ b/libsrc/core/hashtable.hpp @@ -37,8 +37,10 @@ namespace ngcore }; - + // feature check macro for transition from INT to IVec +#define NGCORE_HAS_IVEC + /// N integers template class IVec From 4f0b15ef5553096bd768a9d70598d21d7d1cef80 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 21 Feb 2024 08:41:17 +0100 Subject: [PATCH 2/5] use FlatArray for edges and faces in mesh interface V2 --- libsrc/include/nginterface_v2.hpp | 8 +++- libsrc/include/nginterface_v2_impl.hpp | 51 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/libsrc/include/nginterface_v2.hpp b/libsrc/include/nginterface_v2.hpp index 1b624b9d..788f7395 100644 --- a/libsrc/include/nginterface_v2.hpp +++ b/libsrc/include/nginterface_v2.hpp @@ -111,6 +111,7 @@ namespace netgen int operator[] (size_t i) const { return ptr[i]-POINTINDEX_BASE; } }; + /* class Ng_Edges { public: @@ -130,6 +131,7 @@ namespace netgen size_t Size() const { return num; } int operator[] (size_t i) const { return ptr[i]; } }; + */ class Ng_Facets { @@ -151,8 +153,10 @@ namespace netgen int GetIndex() const { return index-1; } Ng_Points points; // all points Ng_Vertices vertices; - Ng_Edges edges; - Ng_Faces faces; + // Ng_Edges edges; + FlatArray edges; + // Ng_Faces faces; + FlatArray faces; Ng_Facets facets; bool is_curved; }; diff --git a/libsrc/include/nginterface_v2_impl.hpp b/libsrc/include/nginterface_v2_impl.hpp index 69278f22..a6f56df8 100644 --- a/libsrc/include/nginterface_v2_impl.hpp +++ b/libsrc/include/nginterface_v2_impl.hpp @@ -56,15 +56,20 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<0> (size_t nr) const ret.vertices.num = 1; ret.vertices.ptr = (int*)&el.pnum; - + + /* ret.edges.num = 0; ret.edges.ptr = NULL; - + */ + ret.edges.Assign ( FlatArray (0, nullptr) ); + /* ret.faces.num = 0; ret.faces.ptr = NULL; - + */ + ret.faces.Assign ( { 0, nullptr } ); + ret.facets.num = 1; - ret.facets.base = 1; + ret.facets.base = POINTINDEX_BASE; ret.facets.ptr = (int*)&el.pnum; if (mesh->GetDimension() == 1) @@ -107,12 +112,18 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const ret.vertices.num = 2; ret.vertices.ptr = (int*)&(el[0]); + /* ret.edges.num = 1; ret.edges.ptr = mesh->GetTopology().GetSegmentElementEdgesPtr (nr); + */ + ret.edges.Assign ( FlatArray (1, const_cast( mesh->GetTopology().GetSegmentElementEdgesPtr (nr)))); + /* ret.faces.num = 0; ret.faces.ptr = NULL; - + */ + ret.faces.Assign ( { 0, nullptr }); + if (mesh->GetDimension() == 3) { ret.facets.num = 0; @@ -123,7 +134,7 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<1> (size_t nr) const { ret.facets.num = 1; ret.facets.base = 0; - ret.facets.ptr = ret.edges.ptr; + ret.facets.ptr = ret.edges.Data(); } else { @@ -157,23 +168,27 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<2> (size_t nr) const ret.vertices.num = el.GetNV(); ret.vertices.ptr = (int*)&(el[0]); + /* ret.edges.num = MeshTopology::GetNEdges (el.GetType()); ret.edges.ptr = mesh->GetTopology().GetSurfaceElementEdgesPtr (nr); - + */ + ret.edges.Assign (mesh->GetTopology().GetEdges (SurfaceElementIndex(nr))); + /* ret.faces.num = MeshTopology::GetNFaces (el.GetType()); ret.faces.ptr = mesh->GetTopology().GetSurfaceElementFacesPtr (nr); - + */ + ret.faces.Assign ( { 1, const_cast(mesh->GetTopology().GetSurfaceElementFacesPtr (nr)) }); if (mesh->GetDimension() == 3) { - ret.facets.num = ret.faces.num; + ret.facets.num = ret.faces.Size(); ret.facets.base = 0; - ret.facets.ptr = ret.faces.ptr; + ret.facets.ptr = ret.faces.Data(); } else { - ret.facets.num = ret.edges.num; + ret.facets.num = ret.edges.Size(); ret.facets.base = 0; - ret.facets.ptr = ret.edges.ptr; + ret.facets.ptr = ret.edges.Data(); } ret.is_curved = el.IsCurved(); return ret; @@ -194,15 +209,21 @@ NGX_INLINE DLL_HEADER Ng_Element Ngx_Mesh :: GetElement<3> (size_t nr) const ret.vertices.num = el.GetNV(); ret.vertices.ptr = (int*)&(el[0]); + /* ret.edges.num = MeshTopology::GetNEdges (el.GetType()); ret.edges.ptr = mesh->GetTopology().GetElementEdgesPtr (nr); + */ + ret.edges.Assign (mesh->GetTopology().GetEdges (ElementIndex(nr))); + /* ret.faces.num = MeshTopology::GetNFaces (el.GetType()); ret.faces.ptr = mesh->GetTopology().GetElementFacesPtr (nr); - - ret.facets.num = ret.faces.num; + */ + ret.faces.Assign (mesh->GetTopology().GetFaces (ElementIndex(nr))); + + ret.facets.num = ret.faces.Size(); ret.facets.base = 0; - ret.facets.ptr = ret.faces.ptr; + ret.facets.ptr = ret.faces.Data(); ret.is_curved = el.IsCurved(); return ret; From b9596765341d69910dd97f73c47598696323495e Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 21 Feb 2024 15:14:33 +0100 Subject: [PATCH 3/5] check for infinite shape --- libsrc/occ/occgenmesh.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 7eb2d77d..1e373ca5 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -669,9 +669,15 @@ namespace netgen BRepMesh_IncrementalMesh (geom.shape, 0.01, true); triangulation = BRep_Tool::Triangulation (face, loc); } + if(triangulation.IsNull()) - throw Exception("OCC-Triangulation could not be built. Do you have a bounded shape?"); - + { + if (geom.shape.Infinite()) + throw Exception("Cannot generate mesh for an infinite geometry"); + else + throw Exception("OCC-Triangulation could not be built"); + } + BRepAdaptor_Surface sf(face, Standard_True); // one prop for evaluating and one for derivatives BRepLProp_SLProps prop(sf, 0, 1e-5); From a65e61c95ebe80afd197ab2575f402dddd09a247 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 21 Feb 2024 20:00:59 +0100 Subject: [PATCH 4/5] OCC generation of visualization mesh using IMeshTools_Parameters --- libsrc/occ/python_occ_shapes.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index 9c50261c..6614a418 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -1219,7 +1219,26 @@ DLL_HEADER void ExportNgOCCShapes(py::module &m) { BRepTools::Clean (shape); double deflection = 0.01; - BRepMesh_IncrementalMesh (shape, deflection, true); + + // BRepMesh_IncrementalMesh mesher(shape, deflection,Standard_True, 0.01, true); + // mesher.Perform(); + + + // https://dev.opencascade.org/doc/overview/html/occt_user_guides__mesh.html + // from Standard_Boolean meshing_imeshtools_parameters() + IMeshTools_Parameters aMeshParams; + aMeshParams.Deflection = 0.01; + aMeshParams.Angle = 0.5; + aMeshParams.Relative = Standard_False; + aMeshParams.InParallel = Standard_True; + aMeshParams.MinSize = Precision::Confusion(); + aMeshParams.InternalVerticesMode = Standard_True; + aMeshParams.ControlSurfaceDeflection = Standard_True; + + BRepMesh_IncrementalMesh aMesher (shape, aMeshParams); + const Standard_Integer aStatus = aMesher.GetStatusFlags(); + // cout << "status = " << aStatus << endl; + // triangulation = BRep_Tool::Triangulation (face, loc); std::vector p[3]; From 4ff7a2261b6a4b3eaf20d86e636427e5afa7afb0 Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 21 Feb 2024 21:42:34 +0100 Subject: [PATCH 5/5] use IMeshTools in SetLocalMeshSize --- libsrc/occ/occgenmesh.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/libsrc/occ/occgenmesh.cpp b/libsrc/occ/occgenmesh.cpp index 1e373ca5..45565a2b 100644 --- a/libsrc/occ/occgenmesh.cpp +++ b/libsrc/occ/occgenmesh.cpp @@ -666,8 +666,24 @@ namespace netgen if (triangulation.IsNull()) { BRepTools::Clean (geom.shape); - BRepMesh_IncrementalMesh (geom.shape, 0.01, true); - triangulation = BRep_Tool::Triangulation (face, loc); + // BRepMesh_IncrementalMesh (geom.shape, 0.01, true); + + // https://dev.opencascade.org/doc/overview/html/occt_user_guides__mesh.html + IMeshTools_Parameters aMeshParams; + aMeshParams.Deflection = 0.01; + aMeshParams.Angle = 0.5; + aMeshParams.Relative = Standard_False; + aMeshParams.InParallel = Standard_True; + aMeshParams.MinSize = Precision::Confusion(); + aMeshParams.InternalVerticesMode = Standard_True; + aMeshParams.ControlSurfaceDeflection = Standard_True; + + BRepMesh_IncrementalMesh aMesher (geom.shape, aMeshParams); + const Standard_Integer aStatus = aMesher.GetStatusFlags(); + if (aStatus != 0) + cout << "BRepMesh_IncrementalMesh.status = " << aStatus << endl; + + triangulation = BRep_Tool::Triangulation (face, loc); } if(triangulation.IsNull())