From 0d36c69c2525d8f4dad10972363f33a76fbe7ba0 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Fri, 2 Dec 2016 14:59:59 +0100 Subject: [PATCH 1/8] domainwise meshing and optimization enabled --- libsrc/meshing/improve3.cpp | 18 +++++++++++++----- libsrc/meshing/meshfunc.cpp | 4 ++++ libsrc/meshing/meshtype.hpp | 2 ++ libsrc/meshing/python_mesh.cpp | 9 ++++++--- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 435ba4cd..29458eb2 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -18,6 +18,7 @@ namespace netgen point is inner point. */ + void MeshOptimize3d :: CombineImprove (Mesh & mesh, OPTIMIZEGOAL goal) { @@ -41,6 +42,8 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, double totalbad = 0; for (ElementIndex ei = 0; ei < ne; ei++) { + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; double elerr = CalcBad (mesh.Points(), mesh[ei], 0); totalbad += elerr; elerrs[ei] = elerr; @@ -55,8 +58,9 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, for (ElementIndex ei = 0; ei < ne; ei++) if (!mesh[ei].IsDeleted()) - for (int j = 0; j < mesh[ei].GetNP(); j++) - elementsonnode.Add (mesh[ei][j], ei); + if(!(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())) + for (int j = 0; j < mesh[ei].GetNP(); j++) + elementsonnode.Add (mesh[ei][j], ei); INDEX_2_HASHTABLE edgetested (np+1); @@ -64,6 +68,8 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, for (ElementIndex ei = 0; ei < ne; ei++) { + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; if (multithread.terminate) break; @@ -238,7 +244,8 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, totalbad = 0; for (ElementIndex ei = 0; ei < mesh.GetNE(); ei++) - totalbad += CalcBad (mesh.Points(), mesh[ei], 0); + if(!(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())) + totalbad += CalcBad (mesh.Points(), mesh[ei], 0); if (goal == OPT_QUALITY) { @@ -247,8 +254,9 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, int cntill = 0; for (ElementIndex ei = 0; ei < ne; ei++) - if (!mesh.LegalTet (mesh[ei])) - cntill++; + if(!(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())) + if (!mesh.LegalTet (mesh[ei])) + cntill++; PrintMessage (5, cntill, " illegal tets"); } diff --git a/libsrc/meshing/meshfunc.cpp b/libsrc/meshing/meshfunc.cpp index 54f06a65..062c3e99 100644 --- a/libsrc/meshing/meshfunc.cpp +++ b/libsrc/meshing/meshfunc.cpp @@ -32,6 +32,8 @@ namespace netgen int nonconsist = 0; for (int k = 1; k <= mesh3d.GetNDomains(); k++) { + if(mp.only3D_domain_nr && mp.only3D_domain_nr !=k) + continue; PrintMessage (3, "Check subdomain ", k, " / ", mesh3d.GetNDomains()); mesh3d.FindOpenElements(k); @@ -63,6 +65,8 @@ namespace netgen for (int k = 1; k <= mesh3d.GetNDomains(); k++) { + if(mp.only3D_domain_nr && mp.only3D_domain_nr !=k) + continue; if (multithread.terminate) break; diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index fb6e66f0..b3950237 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1110,6 +1110,8 @@ namespace netgen double badellimit = 175; bool check_impossible = 0; + + int only3D_domain_nr = -1; /// int secondorder = 0; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index f8507890..c2923dab 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -590,18 +590,21 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::class_ (m, "MeshingParameters") .def(py::init<>()) .def("__init__", - [](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d) + [](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d, + int only3D_domain) { new (instance) MeshingParameters; instance->maxh = maxh; instance->quad = int(quad_dominated); instance->optsteps2d = optsteps2d; - instance->optsteps3d = optsteps3d; + instance->optsteps3d = optsteps3d; + instance->only3D_domain_nr = only3D_domain; }, py::arg("maxh")=1000, py::arg("quad_dominated")=false, py::arg("optsteps2d") = 3, - py::arg("optsteps3d") = 3 + py::arg("optsteps3d") = 3, + py::arg("only3D_domain") = 0 , "create meshing parameters" ) From ee833ff36260e0c067a50bf0f506f46dd85bf05a Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Fri, 2 Dec 2016 19:00:34 +0100 Subject: [PATCH 2/8] add onlySurface to generate only surface mesh --- libsrc/csg/csgeom.cpp | 3 +-- libsrc/csg/genmesh.cpp | 2 ++ libsrc/meshing/meshtype.hpp | 1 + libsrc/meshing/python_mesh.cpp | 6 ++++-- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/libsrc/csg/csgeom.cpp b/libsrc/csg/csgeom.cpp index fb89cd46..61950649 100644 --- a/libsrc/csg/csgeom.cpp +++ b/libsrc/csg/csgeom.cpp @@ -138,8 +138,7 @@ namespace netgen { return CSGGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend); } - - + const Refinement & CSGeometry :: GetRefinement () const { // cout << "get CSGeometry - Refinement" << endl; diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index ad67151f..49d671d3 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -794,6 +794,8 @@ namespace netgen if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE) return TCL_OK; + if(mparam.onlySurface) + return TCL_OK; if (perfstepsstart <= MESHCONST_MESHVOLUME) { diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index b3950237..2b8d816a 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1112,6 +1112,7 @@ namespace netgen bool check_impossible = 0; int only3D_domain_nr = -1; + bool onlySurface = false; /// int secondorder = 0; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index c2923dab..6c5d949a 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -591,7 +591,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init<>()) .def("__init__", [](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d, - int only3D_domain) + int only3D_domain, bool onlySurface) { new (instance) MeshingParameters; instance->maxh = maxh; @@ -599,12 +599,14 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) instance->optsteps2d = optsteps2d; instance->optsteps3d = optsteps3d; instance->only3D_domain_nr = only3D_domain; + instance->onlySurface = onlySurface; }, py::arg("maxh")=1000, py::arg("quad_dominated")=false, py::arg("optsteps2d") = 3, py::arg("optsteps3d") = 3, - py::arg("only3D_domain") = 0 + py::arg("only3D_domain") = 0, + py::arg("onlySurface") = false , "create meshing parameters" ) From a0326d490d544b13d7dcf4c26d9658b3575b1900 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 5 Dec 2016 13:15:06 +0100 Subject: [PATCH 3/8] some fixes --- libsrc/meshing/improve3.cpp | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 29458eb2..8cb8da58 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -58,9 +58,8 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, for (ElementIndex ei = 0; ei < ne; ei++) if (!mesh[ei].IsDeleted()) - if(!(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())) - for (int j = 0; j < mesh[ei].GetNP(); j++) - elementsonnode.Add (mesh[ei][j], ei); + for (int j = 0; j < mesh[ei].GetNP(); j++) + elementsonnode.Add (mesh[ei][j], ei); INDEX_2_HASHTABLE edgetested (np+1); @@ -314,6 +313,8 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, badmax = 0; for (ei = 0; ei < ne; ei++) { + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; elerrs[ei] = CalcBad (mesh.Points(), mesh[ei], 0); bad1 += elerrs[ei]; if (elerrs[ei] > badmax) badmax = elerrs[ei]; @@ -345,12 +346,12 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, int cntill = 0; for (ei = 0; ei < ne; ei++) { - // if (!LegalTet (volelements.Get(i))) - if (mesh[ei].flags.illegal) - { - cntill++; - illegaltet.Set (ei+1); - } + // if (!LegalTet (volelements.Get(i))) + if (mesh[ei].flags.illegal) + { + cntill++; + illegaltet.Set (ei+1); + } } // (*mycout) << cntill << " illegal tets" << endl; } @@ -358,6 +359,8 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, for (ei = 0; ei < ne; ei++) { + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; if (multithread.terminate) break; From 16ecf99cceefe73dece4e5dbfb886f51fa928939 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 5 Dec 2016 14:59:44 +0100 Subject: [PATCH 4/8] remove onlySurface again (use MeshingSteps instead) --- libsrc/csg/genmesh.cpp | 3 --- libsrc/meshing/meshtype.hpp | 1 - libsrc/meshing/python_mesh.cpp | 3 +-- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/libsrc/csg/genmesh.cpp b/libsrc/csg/genmesh.cpp index 49d671d3..76688ccd 100644 --- a/libsrc/csg/genmesh.cpp +++ b/libsrc/csg/genmesh.cpp @@ -794,9 +794,6 @@ namespace netgen if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE) return TCL_OK; - if(mparam.onlySurface) - return TCL_OK; - if (perfstepsstart <= MESHCONST_MESHVOLUME) { multithread.task = "Volume meshing"; diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index 2b8d816a..b3950237 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1112,7 +1112,6 @@ namespace netgen bool check_impossible = 0; int only3D_domain_nr = -1; - bool onlySurface = false; /// int secondorder = 0; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 6c5d949a..408eb8c9 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -591,7 +591,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) .def(py::init<>()) .def("__init__", [](MP *instance, double maxh, bool quad_dominated, int optsteps2d, int optsteps3d, - int only3D_domain, bool onlySurface) + int only3D_domain) { new (instance) MeshingParameters; instance->maxh = maxh; @@ -599,7 +599,6 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) instance->optsteps2d = optsteps2d; instance->optsteps3d = optsteps3d; instance->only3D_domain_nr = only3D_domain; - instance->onlySurface = onlySurface; }, py::arg("maxh")=1000, py::arg("quad_dominated")=false, From 181eea50386d2a60c6cda31ac295009d2594a65f Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 5 Dec 2016 15:10:34 +0100 Subject: [PATCH 5/8] typo fix --- libsrc/meshing/python_mesh.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 6c298d61..7efd2842 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -613,7 +613,6 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::arg("optsteps3d") = 3, py::arg("only3D_domain") = 0, py::arg("perfstepsend") = MESHCONST_OPTVOLUME, - , "create meshing parameters" ) .def("__str__", &ToString) From 1f314ae0ee79ffbab7be33cb99b2e300a16d07f6 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Mon, 5 Dec 2016 15:37:05 +0100 Subject: [PATCH 6/8] fix wrong order of arguments --- libsrc/meshing/improve3.cpp | 6 +++--- libsrc/meshing/python_mesh.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 8cb8da58..3575ffc9 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -68,7 +68,7 @@ void MeshOptimize3d :: CombineImprove (Mesh & mesh, for (ElementIndex ei = 0; ei < ne; ei++) { if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) - continue; + continue; if (multithread.terminate) break; @@ -314,7 +314,7 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, for (ei = 0; ei < ne; ei++) { if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) - continue; + continue; elerrs[ei] = CalcBad (mesh.Points(), mesh[ei], 0); bad1 += elerrs[ei]; if (elerrs[ei] > badmax) badmax = elerrs[ei]; @@ -360,7 +360,7 @@ void MeshOptimize3d :: SplitImprove (Mesh & mesh, for (ei = 0; ei < ne; ei++) { if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) - continue; + continue; if (multithread.terminate) break; diff --git a/libsrc/meshing/python_mesh.cpp b/libsrc/meshing/python_mesh.cpp index 7efd2842..8ac969c1 100644 --- a/libsrc/meshing/python_mesh.cpp +++ b/libsrc/meshing/python_mesh.cpp @@ -611,8 +611,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m) py::arg("quad_dominated")=false, py::arg("optsteps2d") = 3, py::arg("optsteps3d") = 3, - py::arg("only3D_domain") = 0, py::arg("perfstepsend") = MESHCONST_OPTVOLUME, + py::arg("only3D_domain") = 0, "create meshing parameters" ) .def("__str__", &ToString) From 7743503c1d2af109a53dda93f4b2f1713e644e28 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Tue, 6 Dec 2016 11:32:16 +0100 Subject: [PATCH 7/8] fix and use in swapimprove as well --- libsrc/meshing/improve3.cpp | 16 ++++++++++++---- libsrc/meshing/meshtype.hpp | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 3575ffc9..5ddf1fb2 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -648,6 +648,9 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, if (multithread.terminate) break; + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; + multithread.percent = 100.0 * (ei+1) / ne; if ((mesh.ElementType(ei)) == FIXEDELEMENT) @@ -1236,6 +1239,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, int oldpi = suroundpts[l-1]; int newpi = 0; + for (int k = 0; k < nsuround && !newpi; k++) if (!tetused[k]) { @@ -1247,13 +1251,14 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal, newpi = nel[0] + nel[1] + nel[2] + nel[3] - pi1 - pi2 - oldpi; - + tetused[k] = 1; suroundpts[l] = newpi; - } - } + + } + } } - + bad1 = 0; for (int k = 0; k < nsuround; k++) @@ -2391,6 +2396,9 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal) mesh.LegalTet (mesh[eli1]) && CalcBad (mesh.Points(), mesh[eli1], 0) < 1e3) continue; + + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + continue; // cout << "eli = " << eli1 << endl; // (*testout) << "swapimp2, eli = " << eli1 << "; el = " << mesh[eli1] << endl; diff --git a/libsrc/meshing/meshtype.hpp b/libsrc/meshing/meshtype.hpp index c66ed555..dfdf889a 100644 --- a/libsrc/meshing/meshtype.hpp +++ b/libsrc/meshing/meshtype.hpp @@ -1116,7 +1116,7 @@ namespace netgen bool check_impossible = 0; - int only3D_domain_nr = -1; + int only3D_domain_nr = 0; /// int secondorder = 0; From 9f9a5e43048566f99cc3fb92e84d3d29bd5f7e40 Mon Sep 17 00:00:00 2001 From: Christopher Lackner Date: Tue, 6 Dec 2016 13:38:18 +0100 Subject: [PATCH 8/8] fix typo --- libsrc/meshing/improve3.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index 5ddf1fb2..43b67947 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -2397,7 +2397,7 @@ void MeshOptimize3d :: SwapImprove2 (Mesh & mesh, OPTIMIZEGOAL goal) CalcBad (mesh.Points(), mesh[eli1], 0) < 1e3) continue; - if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex()) + if(mesh.GetDimension()==3 && mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(eli1).GetIndex()) continue; // cout << "eli = " << eli1 << endl;