From 4e8fe77098075241a9cedb8e6702e0d7a69c0755 Mon Sep 17 00:00:00 2001 From: "mhochsteger@cerbsim.com" Date: Wed, 2 Mar 2022 14:14:38 +0100 Subject: [PATCH 1/2] fix some warnings --- libsrc/core/taskmanager.cpp | 2 +- libsrc/meshing/hprefinement.cpp | 8 ++++---- libsrc/meshing/meshing2.cpp | 2 +- libsrc/meshing/refine.cpp | 10 +++++----- libsrc/meshing/smoothing3.cpp | 4 ++-- libsrc/occ/occgeom.cpp | 26 +++++++++++++------------- libsrc/occ/python_occ_shapes.cpp | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/libsrc/core/taskmanager.cpp b/libsrc/core/taskmanager.cpp index 419f7a08..875746ec 100644 --- a/libsrc/core/taskmanager.cpp +++ b/libsrc/core/taskmanager.cpp @@ -242,7 +242,7 @@ namespace ngcore TNestedTask (const function & _func, int _mynr, int _total, atomic & _endcnt, int prod_tid) - : func(&_func), mynr(_mynr), total(_total), endcnt(&_endcnt), producing_thread(prod_tid) + : func(&_func), mynr(_mynr), total(_total), producing_thread(prod_tid), endcnt(&_endcnt) { ; } diff --git a/libsrc/meshing/hprefinement.cpp b/libsrc/meshing/hprefinement.cpp index d27f7a29..e536d8a7 100644 --- a/libsrc/meshing/hprefinement.cpp +++ b/libsrc/meshing/hprefinement.cpp @@ -33,7 +33,7 @@ namespace netgen } HPRefElement :: HPRefElement(Element & el) : - np(el.GetNV()), index(el.GetIndex()), levelx(0), levely(0), levelz(0), type(HP_NONE), domin(-1), domout(-1) //domin,out for segements + type(HP_NONE), index(el.GetIndex()), levelx(0), levely(0), levelz(0), np(el.GetNV()), domin(-1), domout(-1) //domin,out for segements { //Reset(); for (int i=0; i & aboundingbox) - : geo(ageo), adfront(aboundingbox), boundingbox(aboundingbox) + : adfront(aboundingbox), boundingbox(aboundingbox), geo(ageo) { static Timer t("Mesing2::Meshing2"); RegionTimer r(t); diff --git a/libsrc/meshing/refine.cpp b/libsrc/meshing/refine.cpp index d8d49870..b745bf43 100644 --- a/libsrc/meshing/refine.cpp +++ b/libsrc/meshing/refine.cpp @@ -663,8 +663,8 @@ namespace netgen // if (elrev) // swap (pnums.Elem(3), pnums.Elem(4)); - for (int j = 0; j < 9; j++) - { + for (int j = 0; j < 9; j++) + { INDEX_2 i2; i2.I1() = pnums.Get(betw[j][0]); i2.I2() = pnums.Get(betw[j][1]); @@ -679,10 +679,10 @@ namespace netgen mesh.Point(i2.I2()))); between.Set (i2, pnums.Elem(7+j)); } - } + } - for (int j = 0; j < 3; j++) - { + for (int j = 0; j < 3; j++) + { INDEX_2 i2a, i2b; i2a.I1() = pnums.Get(fbetw[2*j][0]); i2a.I2() = pnums.Get(fbetw[2*j][1]); diff --git a/libsrc/meshing/smoothing3.cpp b/libsrc/meshing/smoothing3.cpp index 99c18839..165f37f1 100644 --- a/libsrc/meshing/smoothing3.cpp +++ b/libsrc/meshing/smoothing3.cpp @@ -338,7 +338,7 @@ namespace netgen : points(apoints), elements(aelements), elementsonpoint(* new Table()), own_elementsonpoint(true), mp(amp) { static Timer tim("PointFunction - build elementsonpoint table"); RegionTimer reg(tim); - elementsonpoint = std::move(ngcore::CreateSortedTable( elements.Range(), + elementsonpoint = ngcore::CreateSortedTable( elements.Range(), [&](auto & table, ElementIndex ei) { const auto & el = elements[ei]; @@ -348,7 +348,7 @@ namespace netgen for (PointIndex pi : el.PNums()) table.Add (pi, ei); - }, points.Size())); + }, points.Size()); } void PointFunction :: SetPointIndex (PointIndex aactpind) diff --git a/libsrc/occ/occgeom.cpp b/libsrc/occ/occgeom.cpp index ea1d138d..097d93fe 100644 --- a/libsrc/occ/occgeom.cpp +++ b/libsrc/occ/occgeom.cpp @@ -203,20 +203,20 @@ namespace netgen if(auto quad_dominated = OCCGeometry::global_shape_properties[face.TShape()].quad_dominated; quad_dominated.has_value()) local_mp.quad = *quad_dominated; - bool failed = OCCMeshFace(*this, mesh, glob2loc, local_mp, nr, PARAMETERSPACE, true); - if(failed) - failed = OCCMeshFace(*this, mesh, glob2loc, local_mp, nr, PLANESPACE, false); + bool failed = OCCMeshFace(*this, mesh, glob2loc, local_mp, nr, PARAMETERSPACE, true); + if(failed) + failed = OCCMeshFace(*this, mesh, glob2loc, local_mp, nr, PLANESPACE, false); - if(failed) - { - facemeshstatus[nr] = -1; - PrintError ("Problem in Surface mesh generation"); - } - else - { - facemeshstatus[nr] = 1; - } - return failed; + if(failed) + { + facemeshstatus[nr] = -1; + PrintError ("Problem in Surface mesh generation"); + } + else + { + facemeshstatus[nr] = 1; + } + return failed; } void OCCGeometry :: PrintNrShapes () diff --git a/libsrc/occ/python_occ_shapes.cpp b/libsrc/occ/python_occ_shapes.cpp index efcc112b..86a5ebc2 100644 --- a/libsrc/occ/python_occ_shapes.cpp +++ b/libsrc/occ/python_occ_shapes.cpp @@ -2372,7 +2372,7 @@ degen_tol : double vector wires; for(auto& w : *swires) wires.push_back(TopoDS::Wire(w)); - return std::move(wires); + return wires; }, py::arg("edges"), py::arg("tol")=1e-8, py::arg("shared")=true); py::class_> (m, "WorkPlane") From 43382d4be85fe5e5145c8e3d8a4dc6bf6882186f Mon Sep 17 00:00:00 2001 From: "mhochsteger@cerbsim.com" Date: Wed, 2 Mar 2022 14:58:39 +0100 Subject: [PATCH 2/2] fix parallel surface optimization with occ --- libsrc/meshing/basegeom.cpp | 3 +- libsrc/meshing/improve2.cpp | 91 ++++++++++++++---------------------- libsrc/meshing/meshclass.cpp | 38 ++++----------- 3 files changed, 46 insertions(+), 86 deletions(-) diff --git a/libsrc/meshing/basegeom.cpp b/libsrc/meshing/basegeom.cpp index ca1b7651..9241e5e3 100644 --- a/libsrc/meshing/basegeom.cpp +++ b/libsrc/meshing/basegeom.cpp @@ -982,11 +982,10 @@ namespace netgen static Timer timer_opt2d("Optimization 2D"); RegionTimer reg(timer_opt2d); auto meshopt = MeshOptimize2d(mesh); + meshopt.SetFaceIndex(0); for(auto i : Range(mparam.optsteps2d)) - for(auto k : Range(mesh.GetNFD())) { PrintMessage(3, "Optimization step ", i); - meshopt.SetFaceIndex(k+1); int innerstep = 0; for(auto optstep : mparam.optimize2d) { diff --git a/libsrc/meshing/improve2.cpp b/libsrc/meshing/improve2.cpp index 2503d4eb..817c6c21 100644 --- a/libsrc/meshing/improve2.cpp +++ b/libsrc/meshing/improve2.cpp @@ -18,6 +18,27 @@ namespace netgen { tnr = atnr; sidenr = asidenr; } }; + // check if element is quad with at least one surface point -> relevant for optimization + // (quads with 4 edge points are not optimized and can be ignored) + bool checkMixedElement(const Mesh & mesh, FlatArray seia) + { + bool mixed = false; + ParallelForRange( Range(seia), [&] (auto myrange) NETGEN_LAMBDA_INLINE + { + for (SurfaceElementIndex i : myrange) + { + const auto & sel = mesh[i]; + + if(sel.GetNP() == 3) + continue; + + for(auto i : Range(sel.GetNP())) + if(mesh[sel[i]].Type() == SURFACEPOINT) + mixed = true; + } + }); + return mixed; + } bool MeshOptimize2d :: EdgeSwapping (const int usemetric, Array &neighbors, @@ -181,35 +202,14 @@ namespace netgen timerstart.Start(); Array seia; - bool mixed = false; + mesh.GetSurfaceElementsOfFace (faceindex, seia); - if(faceindex==0) - { - seia.SetSize(mesh.GetNSE()); - ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE - { - SurfaceElementIndex sei(i); - seia[i] = sei; - if (mesh[sei].GetNP() != 3) - { - const auto & sel = mesh[sei]; - for(auto i : Range(sel.GetNP())) - if(mesh[sel[i]].Type() == INNERPOINT) - mixed = true; - } - }); - } - else - { - mesh.GetSurfaceElementsOfFace (faceindex, seia); - for (SurfaceElementIndex sei : seia) - if (mesh[sei].GetNP() != 3) - mixed = true; - } - - if(mixed) + if(checkMixedElement(mesh, seia)) + { + timerstart.Stop(); return GenericImprove(); - + } + Array neighbors(mesh.GetNSE()); auto elements_on_node = mesh.CreatePoint2SurfaceElementTable(faceindex); @@ -595,25 +595,14 @@ namespace netgen Array seia; + mesh.GetSurfaceElementsOfFace (faceindex, seia); - if(faceindex) - mesh.GetSurfaceElementsOfFace (faceindex, seia); - else - { - seia.SetSize(mesh.GetNSE()); - ParallelFor( IntRange(mesh.GetNSE()), [&seia] (auto i) NETGEN_LAMBDA_INLINE - { seia[i] = i; }); - } - - bool mixed = false; - ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE - { - if (mesh[seia[i]].GetNP() != 3) - mixed = true; - }); - - if(mixed) + if(checkMixedElement(mesh, seia)) + { + timerstart1.Stop(); + timerstart.Stop(); return; + } int np = mesh.GetNP(); @@ -625,18 +614,8 @@ namespace netgen BuildEdgeList( mesh, elementsonnode, edges ); Array fixed(np); - ParallelFor( fixed.Range(), [&fixed] (auto i) NETGEN_LAMBDA_INLINE - { fixed[i] = false; }); - - ParallelFor( edges.Range(), [&] (auto i) NETGEN_LAMBDA_INLINE - { - auto [pi0, pi1] = edges[i]; - if (mesh.IsSegment (pi0, pi1)) - { - fixed[pi0] = true; - fixed[pi1] = true; - } - }); + ParallelFor( fixed.Range(), [&] (auto i) NETGEN_LAMBDA_INLINE + { fixed[i] = mesh[i].Type() != SURFACEPOINT; }); timerstart1.Stop(); diff --git a/libsrc/meshing/meshclass.cpp b/libsrc/meshing/meshclass.cpp index b381f760..c3f85386 100644 --- a/libsrc/meshing/meshclass.cpp +++ b/libsrc/meshing/meshclass.cpp @@ -6412,25 +6412,17 @@ namespace netgen static int timer = NgProfiler::CreateTimer ("GetSurfaceElementsOfFace"); NgProfiler::RegionTimer reg (timer); - /* - sei.SetSize (0); - for (SurfaceElementIndex i = 0; i < GetNSE(); i++) - { - if ( (*this)[i].GetIndex () == facenr && (*this)[i][0] >= PointIndex::BASE && - !(*this)[i].IsDeleted() ) - { - sei.Append (i); - } - } - */ + if(facenr==0) + { + sei.SetSize(GetNSE()); + ParallelForRange( IntRange(GetNSE()), [&sei] (auto myrange) + { + for(auto i : myrange) + sei[i] = i; + }); + return; + } - /* Philippose - 01/10/2009 - Commented out the following lines, and activated the originally - commented out lines above because of a bug which causes corruption - of the variable "facedecoding" when a mesh is converted to second order - */ - - // int size1 = sei.Size(); sei.SetSize(0); SurfaceElementIndex si = facedecoding[facenr-1].firstelement; @@ -6444,16 +6436,6 @@ namespace netgen si = (*this)[si].next; } - - /* - // *testout << "with list = " << endl << sei << endl; - - if (size1 != sei.Size()) - { - cout << "size mismatch" << endl; - exit(1); - } - */ }