netgen/libsrc/meshing/clusters.cpp

365 lines
9.9 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#include <mystdlib.h>
#include "meshing.hpp"
namespace netgen
{
AnisotropicClusters :: AnisotropicClusters (const Mesh & amesh)
: mesh(amesh)
{
;
}
2009-01-13 04:40:13 +05:00
AnisotropicClusters :: ~AnisotropicClusters ()
{
;
}
2022-04-21 20:16:26 +05:00
2021-05-12 13:56:34 +05:00
void AnisotropicClusters :: Update()
{
2021-05-12 13:56:21 +05:00
static Timer timer("clusters");
2019-04-20 13:25:05 +05:00
// static int timer1 = NgProfiler::CreateTimer ("clusters1");
// static int timer2 = NgProfiler::CreateTimer ("clusters2");
// static int timer3 = NgProfiler::CreateTimer ("clusters3");
2021-05-12 13:56:21 +05:00
RegionTimer reg (timer);
2016-11-20 23:55:17 +05:00
const MeshTopology & top = mesh.GetTopology();
2009-01-13 04:40:13 +05:00
2019-02-25 20:20:43 +05:00
auto id = this->mesh.GetCommunicator().Rank();
2019-08-09 03:23:12 +05:00
// auto ntasks = this->mesh.GetCommunicator().Size();
2019-02-25 20:20:43 +05:00
bool hasedges = top.HasEdges();
bool hasfaces = top.HasFaces();
2009-01-13 04:40:13 +05:00
if (!hasedges || !hasfaces) return;
2009-01-13 04:40:13 +05:00
2011-07-15 03:36:19 +06:00
if (id == 0)
2012-02-12 08:21:34 +06:00
PrintMessage (3, "Update clusters");
2009-01-13 04:40:13 +05:00
nv = mesh.GetNV();
ned = top.GetNEdges();
nfa = top.GetNFaces();
ne = mesh.GetNE();
int nse = mesh.GetNSE();
2009-01-13 04:40:13 +05:00
cluster_reps.SetSize (nv+ned+nfa+ne);
cluster_reps = -1;
2019-07-09 13:39:16 +05:00
NgArray<int> llist (nv+ned+nfa+ne);
llist = 0;
2009-01-13 04:40:13 +05:00
2019-07-09 13:39:16 +05:00
NgArray<int> nnums, ednums, fanums;
int changed;
2009-01-13 04:40:13 +05:00
2019-04-20 13:25:05 +05:00
// NgProfiler::StartTimer(timer1);
2009-01-13 04:40:13 +05:00
2016-11-20 23:55:17 +05:00
/*
for (int i = 1; i <= ne; i++)
{
const Element & el = mesh.VolumeElement(i);
ELEMENT_TYPE typ = el.GetType();
2009-01-13 04:40:13 +05:00
top.GetElementEdges (i, ednums);
top.GetElementFaces (i, fanums);
2009-01-13 04:40:13 +05:00
int elnv = top.GetNVertices (typ);
int elned = ednums.Size();
int elnfa = fanums.Size();
2009-01-13 04:40:13 +05:00
nnums.SetSize(elnv+elned+elnfa+1);
for (int j = 1; j <= elnv; j++)
nnums.Elem(j) = el.PNum(j);
for (int j = 1; j <= elned; j++)
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
for (int j = 1; j <= elnfa; j++)
nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);
nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;
for (int j = 0; j < nnums.Size(); j++)
cluster_reps.Elem(nnums[j]) = nnums[j];
}
2016-11-20 23:55:17 +05:00
*/
2021-05-12 13:56:34 +05:00
ngcore::ParallelForRange
(mesh.VolumeElements().Range(),
[&] (auto myrange)
2016-11-20 23:55:17 +05:00
{
2019-07-09 13:39:16 +05:00
NgArray<int> nnums, ednums, fanums;
2021-05-12 13:56:34 +05:00
for (int i_ : myrange)
2016-11-20 23:55:17 +05:00
{
2021-05-12 13:56:34 +05:00
int i = i_+1;
2016-11-20 23:55:17 +05:00
const Element & el = mesh.VolumeElement(i);
ELEMENT_TYPE typ = el.GetType();
top.GetElementEdges (i, ednums);
top.GetElementFaces (i, fanums);
int elnv = top.GetNVertices (typ);
int elned = ednums.Size();
int elnfa = fanums.Size();
nnums.SetSize(elnv+elned+elnfa+1);
for (int j = 1; j <= elnv; j++)
2016-12-12 00:17:07 +05:00
nnums.Elem(j) = el.PNum(j)+1-PointIndex::BASE;
2016-11-20 23:55:17 +05:00
for (int j = 1; j <= elned; j++)
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
for (int j = 1; j <= elnfa; j++)
nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);
nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;
for (int j = 0; j < nnums.Size(); j++)
cluster_reps.Elem(nnums[j]) = nnums[j];
}
2021-05-12 13:56:34 +05:00
}, ngcore::TasksPerThread(4));
2016-11-20 23:55:17 +05:00
2019-04-20 13:25:05 +05:00
// NgProfiler::StopTimer(timer1);
// NgProfiler::StartTimer(timer2);
2017-04-07 00:41:26 +05:00
/*
for (int i = 1; i <= nse; i++)
{
const Element2d & el = mesh.SurfaceElement(i);
ELEMENT_TYPE typ = el.GetType();
2009-01-13 04:40:13 +05:00
top.GetSurfaceElementEdges (i, ednums);
int fanum = top.GetSurfaceElementFace (i);
2009-01-13 04:40:13 +05:00
int elnv = top.GetNVertices (typ);
int elned = ednums.Size();
2009-01-13 04:40:13 +05:00
nnums.SetSize(elnv+elned+1);
for (int j = 1; j <= elnv; j++)
2016-12-12 00:17:07 +05:00
nnums.Elem(j) = el.PNum(j)+1-PointIndex::BASE;
for (int j = 1; j <= elned; j++)
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
nnums.Elem(elnv+elned+1) = fanum;
for (int j = 0; j < nnums.Size(); j++)
cluster_reps.Elem(nnums[j]) = nnums[j];
}
2017-04-07 00:41:26 +05:00
*/
2021-05-12 13:56:34 +05:00
ngcore::ParallelForRange
(mesh.SurfaceElements().Range(),
[&] (auto myrange)
2017-04-07 00:41:26 +05:00
{
2019-07-09 21:00:12 +05:00
NgArrayMem<int,9> nnums, ednums;
2021-05-12 13:56:34 +05:00
for (int i_ : myrange)
2017-04-07 00:41:26 +05:00
{
2021-05-12 13:56:34 +05:00
int i = i_+1;
2017-04-07 00:41:26 +05:00
const Element2d & el = mesh.SurfaceElement(i);
ELEMENT_TYPE typ = el.GetType();
top.GetSurfaceElementEdges (i, ednums);
int fanum = top.GetSurfaceElementFace (i);
int elnv = top.GetNVertices (typ);
int elned = ednums.Size();
nnums.SetSize(elnv+elned+1);
for (int j = 1; j <= elnv; j++)
nnums.Elem(j) = el.PNum(j)+1-PointIndex::BASE;
for (int j = 1; j <= elned; j++)
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
nnums.Elem(elnv+elned+1) = fanum;
for (int j = 0; j < nnums.Size(); j++)
cluster_reps.Elem(nnums[j]) = nnums[j];
}
2021-05-12 13:56:34 +05:00
}, ngcore::TasksPerThread(4));
2017-04-07 00:41:26 +05:00
2019-04-20 13:25:05 +05:00
// NgProfiler::StopTimer(timer2);
// NgProfiler::StartTimer(timer3);
2017-04-07 00:41:26 +05:00
static const int hex_cluster[] =
{
1, 2, 3, 4, 1, 2, 3, 4,
5, 6, 7, 8, 5, 6, 7, 8, 1, 2, 3, 4,
9, 9, 5, 8, 6, 7,
9
};
static const int prism_cluster[] =
{
1, 2, 3, 1, 2, 3,
4, 5, 6, 4, 5, 6, 3, 1, 2,
7, 7, 4, 5, 6,
7
};
static const int pyramid_cluster[] =
{
1, 2, 2, 1, 3,
4, 2, 1, 4, 6, 5, 5, 6,
7, 5, 7, 6, 4,
7
};
static const int tet_cluster14[] =
{ 1, 2, 3, 1, 1, 4, 5, 4, 5, 6, 7, 5, 4, 7, 7 };
2009-01-13 04:40:13 +05:00
static const int tet_cluster12[] =
{ 1, 1, 2, 3, 4, 4, 5, 1, 6, 6, 7, 7, 4, 6, 7 };
2009-01-13 04:40:13 +05:00
static const int tet_cluster13[] =
{ 1, 2, 1, 3, 4, 6, 4, 5, 1, 5, 7, 4, 7, 5, 7 };
2009-01-13 04:40:13 +05:00
static const int tet_cluster23[] =
{ 2, 1, 1, 3, 6, 5, 5, 4, 4, 1, 5, 7, 7, 4, 7 };
2009-01-13 04:40:13 +05:00
static const int tet_cluster24[] =
{ 2, 1, 3, 1, 4, 1, 5, 4, 6, 5, 5, 7, 4, 7, 7 };
2009-01-13 04:40:13 +05:00
static const int tet_cluster34[] =
{ 2, 3, 1, 1, 4, 5, 1, 6, 4, 5, 5, 4, 7, 7, 7 };
2009-01-13 04:40:13 +05:00
int cnt = 0;
2009-01-13 04:40:13 +05:00
do
{
2021-05-12 13:56:21 +05:00
static Timer t("update cluster, identify");
RegionTimer rtr(t);
cnt++;
changed = 0;
2009-01-13 04:40:13 +05:00
for (int i = 1; i <= ne; i++)
{
const Element & el = mesh.VolumeElement(i);
ELEMENT_TYPE typ = el.GetType();
const int * clustertab = NULL;
switch (typ)
{
case PRISM:
case PRISM12:
clustertab = prism_cluster;
break;
case HEX:
clustertab = hex_cluster;
break;
case PYRAMID:
clustertab = pyramid_cluster;
break;
case TET:
case TET10:
2016-12-12 00:17:07 +05:00
if (cluster_reps.Get(el.PNum(1)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(2)+1-PointIndex::BASE))
clustertab = tet_cluster12;
2016-12-12 00:17:07 +05:00
else if (cluster_reps.Get(el.PNum(1)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(3)+1-PointIndex::BASE))
clustertab = tet_cluster13;
2016-12-12 00:17:07 +05:00
else if (cluster_reps.Get(el.PNum(1)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(4)+1-PointIndex::BASE))
clustertab = tet_cluster14;
2016-12-12 00:17:07 +05:00
else if (cluster_reps.Get(el.PNum(2)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(3)+1-PointIndex::BASE))
clustertab = tet_cluster23;
2016-12-12 00:17:07 +05:00
else if (cluster_reps.Get(el.PNum(2)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(4)+1-PointIndex::BASE))
clustertab = tet_cluster24;
2016-12-12 00:17:07 +05:00
else if (cluster_reps.Get(el.PNum(3)+1-PointIndex::BASE) ==
cluster_reps.Get(el.PNum(4)+1-PointIndex::BASE))
clustertab = tet_cluster34;
else
clustertab = NULL;
break;
default:
2009-01-13 04:40:13 +05:00
clustertab = NULL;
}
2009-01-13 04:40:13 +05:00
if (clustertab)
{
top.GetElementEdges (i, ednums);
top.GetElementFaces (i, fanums);
int elnv = top.GetNVertices (typ);
int elned = ednums.Size();
int elnfa = fanums.Size();
nnums.SetSize(elnv+elned+elnfa+1);
for (int j = 1; j <= elnv; j++)
nnums.Elem(j) = el.PNum(j)+1-PointIndex::BASE;
for (int j = 1; j <= elned; j++)
nnums.Elem(elnv+j) = nv+ednums.Elem(j);
for (int j = 1; j <= elnfa; j++)
nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);
nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;
for (int j = 0; j < nnums.Size(); j++)
for (int k = 0; k < j; k++)
if (clustertab[j] == clustertab[k])
{
int jj = nnums[j];
int kk = nnums[k];
if (cluster_reps.Get(kk) < cluster_reps.Get(jj))
swap (jj,kk);
if (cluster_reps.Get(jj) < cluster_reps.Get(kk))
{
/*
cluster_reps.Elem(kk) = cluster_reps.Get(jj);
changed = 1;
*/
2012-01-13 18:12:20 +06:00
int rep = cluster_reps.Get(jj);
2012-01-13 18:12:20 +06:00
int next = cluster_reps.Get(kk);
do
{
int cur = next;
next = llist.Elem(next);
cluster_reps.Elem(cur) = rep;
llist.Elem(cur) = llist.Elem(rep);
llist.Elem(rep) = cur;
}
while (next);
changed = 1;
}
}
}
/*
if (clustertab)
{
2009-01-13 04:40:13 +05:00
if (typ == PYRAMID)
(*testout) << "pyramid";
2009-01-13 04:40:13 +05:00
else if (typ == PRISM || typ == PRISM12)
(*testout) << "prism";
2009-01-13 04:40:13 +05:00
else if (typ == TET || typ == TET10)
(*testout) << "tet";
2009-01-13 04:40:13 +05:00
else
(*testout) << "unknown type" << endl;
2009-01-13 04:40:13 +05:00
(*testout) << ", nnums = ";
for (j = 0; j < nnums.Size(); j++)
(*testout) << "node " << j << " = " << nnums[j] << ", rep = "
<< cluster_reps.Get(nnums[j]) << endl;
}
*/
}
}
while (changed);
2019-04-20 13:25:05 +05:00
// NgProfiler::StopTimer(timer3);
/*
(*testout) << "cluster reps:" << endl;
for (i = 1; i <= cluster_reps.Size(); i++)
{
(*testout) << i << ": ";
if (i <= nv)
(*testout) << "v" << i << " ";
else if (i <= nv+ned)
(*testout) << "e" << i-nv << " ";
else if (i <= nv+ned+nfa)
(*testout) << "f" << i-nv-ned << " ";
else
(*testout) << "c" << i-nv-ned-nfa << " ";
(*testout) << cluster_reps.Get(i) << endl;
}
*/
}
2009-01-13 04:40:13 +05:00
}