Merge branch 'opt2d_fixes' into 'master'

Reset MeshTopology before 2d optimize

See merge request ngsolve/netgen!607
This commit is contained in:
Hochsteger, Matthias 2023-09-18 14:15:32 +02:00
commit d726b22561
3 changed files with 14 additions and 17 deletions

View File

@ -5,7 +5,7 @@ namespace netgen
{ {
// extern DLL_HEADER MeshingParameters mparam; // extern DLL_HEADER MeshingParameters mparam;
extern void Optimize2d (Mesh & mesh, MeshingParameters & mp); extern void Optimize2d (Mesh & mesh, MeshingParameters & mp, int faceindex=0);

View File

@ -4,7 +4,7 @@
namespace netgen namespace netgen
{ {
DLL_HEADER void Optimize2d (Mesh & mesh, MeshingParameters & mp) DLL_HEADER void Optimize2d (Mesh & mesh, MeshingParameters & mp, int faceindex)
{ {
static Timer timer("optimize2d"); RegionTimer reg(timer); static Timer timer("optimize2d"); RegionTimer reg(timer);
@ -33,19 +33,25 @@ namespace netgen
optimize_swap_separate_faces = true; optimize_swap_separate_faces = true;
} }
if(faceindex)
optimize_swap_separate_faces = false;
const char * optstr = mp.optimize2d.c_str(); const char * optstr = mp.optimize2d.c_str();
int optsteps = mp.optsteps2d; int optsteps = mp.optsteps2d;
// reset topology
mesh.GetTopology() = MeshTopology(mesh);
for (int i = 1; i <= optsteps; i++) for (int i = 1; i <= optsteps; i++)
for (size_t j = 1; j <= strlen(optstr); j++) for (size_t j = 1; j <= strlen(optstr); j++)
{ {
if (multithread.terminate) break; if (multithread.terminate) break;
MeshOptimize2d meshopt(mesh);
meshopt.SetMetricWeight (mp.elsizeweight);
meshopt.SetFaceIndex(faceindex);
switch (optstr[j-1]) switch (optstr[j-1])
{ {
case 's': case 's':
{ // topological swap { // topological swap
MeshOptimize2d meshopt(mesh);
meshopt.SetMetricWeight (mp.elsizeweight);
if(optimize_swap_separate_faces) if(optimize_swap_separate_faces)
{ {
@ -57,16 +63,12 @@ namespace netgen
} }
else else
{ {
meshopt.SetFaceIndex(0);
meshopt.EdgeSwapping (0); meshopt.EdgeSwapping (0);
} }
break; break;
} }
case 'S': case 'S':
{ // metric swap { // metric swap
MeshOptimize2d meshopt(mesh);
meshopt.SetMetricWeight (mp.elsizeweight);
if(optimize_swap_separate_faces) if(optimize_swap_separate_faces)
{ {
for(auto i : Range(1, mesh.GetNFD()+1)) for(auto i : Range(1, mesh.GetNFD()+1))
@ -77,22 +79,17 @@ namespace netgen
} }
else else
{ {
meshopt.SetFaceIndex(0);
meshopt.EdgeSwapping (1); meshopt.EdgeSwapping (1);
} }
break; break;
} }
case 'm': case 'm':
{ {
MeshOptimize2d meshopt(mesh);
meshopt.SetMetricWeight (mp.elsizeweight);
meshopt.ImproveMesh(mp); meshopt.ImproveMesh(mp);
break; break;
} }
case 'c': case 'c':
{ {
MeshOptimize2d meshopt(mesh);
meshopt.SetMetricWeight (mp.elsizeweight);
meshopt.CombineImprove(); meshopt.CombineImprove();
break; break;
} }

View File

@ -78,7 +78,7 @@ namespace netgen
{ {
extern bool netgen_executable_started; extern bool netgen_executable_started;
extern shared_ptr<NetgenGeometry> ng_geometry; extern shared_ptr<NetgenGeometry> ng_geometry;
extern void Optimize2d (Mesh & mesh, MeshingParameters & mp); extern void Optimize2d (Mesh & mesh, MeshingParameters & mp, int faceindex=0);
} }
@ -1283,7 +1283,7 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
OptimizeVolume (mp, self); OptimizeVolume (mp, self);
}, py::arg("mp"), py::call_guard<py::gil_scoped_release>()) }, py::arg("mp"), py::call_guard<py::gil_scoped_release>())
.def ("OptimizeMesh2d", [](Mesh & self, MeshingParameters* pars) .def ("OptimizeMesh2d", [](Mesh & self, MeshingParameters* pars, int faceindex)
{ {
self.CalcLocalH(0.5); self.CalcLocalH(0.5);
MeshingParameters mp; MeshingParameters mp;
@ -1291,8 +1291,8 @@ DLL_HEADER void ExportNetgenMeshing(py::module &m)
else mp.optsteps2d = 5; else mp.optsteps2d = 5;
if(!self.GetGeometry()) if(!self.GetGeometry())
throw Exception("Cannot optimize surface mesh without geometry!"); throw Exception("Cannot optimize surface mesh without geometry!");
Optimize2d (self, mp); Optimize2d (self, mp, faceindex);
}, py::arg("mp")=nullptr, py::call_guard<py::gil_scoped_release>()) }, py::arg("mp")=nullptr, py::arg("faceindex")=0, py::call_guard<py::gil_scoped_release>())
.def ("Refine", FunctionPointer .def ("Refine", FunctionPointer
([](Mesh & self, bool adaptive) ([](Mesh & self, bool adaptive)