mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-12 22:20:35 +05:00
Sort edges by improvement in SwapImprove
This commit is contained in:
parent
ffcf2c7373
commit
6fb8f90a73
@ -1698,7 +1698,7 @@ void MeshOptimize3d :: SwapImproveSequential (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
double MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
||||||
const NgBitArray * working_elements,
|
const NgBitArray * working_elements,
|
||||||
Table<ElementIndex, PointIndex> & elementsonnode,
|
Table<ElementIndex, PointIndex> & elementsonnode,
|
||||||
INDEX_3_HASHTABLE<int> & faces,
|
INDEX_3_HASHTABLE<int> & faces,
|
||||||
@ -1714,10 +1714,10 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
Element el1b(TET), el2b(TET), el3b(TET), el4b(TET);
|
Element el1b(TET), el2b(TET), el3b(TET), el4b(TET);
|
||||||
ArrayMem<ElementIndex, 20> hasbothpoints;
|
ArrayMem<ElementIndex, 20> hasbothpoints;
|
||||||
|
|
||||||
bool do_swap = false;
|
double d_badness = 0.0;
|
||||||
if (pi2 < pi1) Swap (pi1, pi2);
|
if (pi2 < pi1) Swap (pi1, pi2);
|
||||||
|
|
||||||
if (mesh.BoundaryEdge (pi1, pi2)) return false;
|
if (mesh.BoundaryEdge (pi1, pi2)) return 0.0;
|
||||||
|
|
||||||
|
|
||||||
hasbothpoints.SetSize (0);
|
hasbothpoints.SetSize (0);
|
||||||
@ -1726,7 +1726,7 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
bool has1 = 0, has2 = 0;
|
bool has1 = 0, has2 = 0;
|
||||||
const Element & elem = mesh[elnr];
|
const Element & elem = mesh[elnr];
|
||||||
|
|
||||||
if (elem.IsDeleted()) return false;
|
if (elem.IsDeleted()) return 0.0;
|
||||||
|
|
||||||
for (int l = 0; l < elem.GetNP(); l++)
|
for (int l = 0; l < elem.GetNP(); l++)
|
||||||
{
|
{
|
||||||
@ -1749,27 +1749,27 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
for (ElementIndex ei : hasbothpoints)
|
for (ElementIndex ei : hasbothpoints)
|
||||||
{
|
{
|
||||||
if (mesh[ei].GetType () != TET)
|
if (mesh[ei].GetType () != TET)
|
||||||
return false;
|
return 0.0;
|
||||||
|
|
||||||
if (mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())
|
if (mp.only3D_domain_nr && mp.only3D_domain_nr != mesh.VolumeElement(ei).GetIndex())
|
||||||
return false;
|
return 0.0;
|
||||||
|
|
||||||
|
|
||||||
if ((mesh.ElementType(ei)) == FIXEDELEMENT)
|
if ((mesh.ElementType(ei)) == FIXEDELEMENT)
|
||||||
return false;
|
return 0.0;
|
||||||
|
|
||||||
if(working_elements &&
|
if(working_elements &&
|
||||||
ei < working_elements->Size() &&
|
ei < working_elements->Size() &&
|
||||||
!working_elements->Test(ei))
|
!working_elements->Test(ei))
|
||||||
return false;
|
return 0.0;
|
||||||
|
|
||||||
if (mesh[ei].IsDeleted())
|
if (mesh[ei].IsDeleted())
|
||||||
return false;
|
return 0.0;
|
||||||
|
|
||||||
if ((goal == OPT_LEGAL) &&
|
if ((goal == OPT_LEGAL) &&
|
||||||
mesh.LegalTet (mesh[ei]) &&
|
mesh.LegalTet (mesh[ei]) &&
|
||||||
CalcBad (mesh.Points(), mesh[ei], 0) < 1e3)
|
CalcBad (mesh.Points(), mesh[ei], 0) < 1e3)
|
||||||
return false;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int nsuround = hasbothpoints.Size();
|
int nsuround = hasbothpoints.Size();
|
||||||
@ -1883,8 +1883,9 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
{
|
{
|
||||||
// (*mycout) << "3->2 " << flush;
|
// (*mycout) << "3->2 " << flush;
|
||||||
// (*testout) << "3->2 conversion" << endl;
|
// (*testout) << "3->2 conversion" << endl;
|
||||||
do_swap = true;
|
d_badness = bad2-bad1;
|
||||||
if(check_only) return do_swap;
|
if(check_only)
|
||||||
|
return d_badness;
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -2079,12 +2080,9 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
swap3 = !swap2 && (bad3 < bad1);
|
swap3 = !swap2 && (bad3 < bad1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d_badness = swap2 ? bad2-bad1 : bad3-bad1;
|
||||||
if (swap2 || swap3)
|
if(check_only)
|
||||||
{
|
return d_badness;
|
||||||
do_swap = true;
|
|
||||||
if(check_only) return do_swap;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swap2)
|
if (swap2)
|
||||||
{
|
{
|
||||||
@ -2279,8 +2277,9 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
if (bestl != -1)
|
if (bestl != -1)
|
||||||
{
|
{
|
||||||
// (*mycout) << nsuround << "->" << 2 * (nsuround-2) << " " << flush;
|
// (*mycout) << nsuround << "->" << 2 * (nsuround-2) << " " << flush;
|
||||||
do_swap = true;
|
d_badness = badopt-bad1;
|
||||||
if(check_only) return do_swap;
|
if(check_only)
|
||||||
|
return d_badness;
|
||||||
|
|
||||||
for (int k = bestl+1; k <= nsuround + bestl - 2; k++)
|
for (int k = bestl+1; k <= nsuround + bestl - 2; k++)
|
||||||
{
|
{
|
||||||
@ -2323,7 +2322,7 @@ bool MeshOptimize3d :: SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return do_swap;
|
return d_badness;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
|
void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
|
||||||
@ -2373,7 +2372,7 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
Array<std::tuple<PointIndex,PointIndex>> edges;
|
Array<std::tuple<PointIndex,PointIndex>> edges;
|
||||||
BuildEdgeList(mesh, elementsonnode, edges);
|
BuildEdgeList(mesh, elementsonnode, edges);
|
||||||
|
|
||||||
Array<int> candidate_edges(edges.Size());
|
Array<std::tuple<double, int>> candidate_edges(edges.Size());
|
||||||
std::atomic<int> improvement_counter(0);
|
std::atomic<int> improvement_counter(0);
|
||||||
|
|
||||||
tloop.Start();
|
tloop.Start();
|
||||||
@ -2386,18 +2385,22 @@ void MeshOptimize3d :: SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
auto [pi0, pi1] = edges[i];
|
auto [pi0, pi1] = edges[i];
|
||||||
if(SwapImproveEdge (mesh, goal, working_elements, elementsonnode, faces, pi0, pi1, true))
|
double d_badness = SwapImproveEdge (mesh, goal, working_elements, elementsonnode, faces, pi0, pi1, true);
|
||||||
candidate_edges[improvement_counter++] = i;
|
if(d_badness<0.0)
|
||||||
|
{
|
||||||
|
int index = improvement_counter++;
|
||||||
|
candidate_edges[index] = make_tuple(d_badness, i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
auto edges_with_improvement = candidate_edges.Part(0, improvement_counter.load());
|
auto edges_with_improvement = candidate_edges.Part(0, improvement_counter.load());
|
||||||
QuickSort(edges_with_improvement);
|
QuickSort(edges_with_improvement);
|
||||||
|
|
||||||
for(auto ei : edges_with_improvement)
|
for(auto [d_badness, ei] : edges_with_improvement)
|
||||||
{
|
{
|
||||||
auto [pi0,pi1] = edges[ei];
|
auto [pi0,pi1] = edges[ei];
|
||||||
if(SwapImproveEdge (mesh, goal, working_elements, elementsonnode, faces, pi0, pi1, false))
|
if(SwapImproveEdge (mesh, goal, working_elements, elementsonnode, faces, pi0, pi1, false) < 0.0)
|
||||||
cnt++;
|
cnt++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public:
|
|||||||
|
|
||||||
void SplitImprove (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY);
|
void SplitImprove (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY);
|
||||||
|
|
||||||
bool SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal, const NgBitArray * working_elements, Table<ElementIndex,PointIndex> & elementsonnode, INDEX_3_HASHTABLE<int> & faces, PointIndex pi1, PointIndex pi2, bool check_only=false);
|
double SwapImproveEdge (Mesh & mesh, OPTIMIZEGOAL goal, const NgBitArray * working_elements, Table<ElementIndex,PointIndex> & elementsonnode, INDEX_3_HASHTABLE<int> & faces, PointIndex pi1, PointIndex pi2, bool check_only=false);
|
||||||
void SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY,
|
void SwapImprove (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY,
|
||||||
const NgBitArray * working_elements = NULL);
|
const NgBitArray * working_elements = NULL);
|
||||||
void SwapImproveSequential (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY,
|
void SwapImproveSequential (Mesh & mesh, OPTIMIZEGOAL goal = OPT_QUALITY,
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user