Path: blob/devel/ElmerGUI/netgen/libsrc/meshing/clusters.cpp
3206 views
#include <mystdlib.h>12#include "meshing.hpp"34namespace netgen5{67AnisotropicClusters :: AnisotropicClusters (const Mesh & amesh)8: mesh(amesh)9{10;11}1213AnisotropicClusters :: ~AnisotropicClusters ()14{15;16}1718void AnisotropicClusters :: Update()19{20int i, j, k;2122const MeshTopology & top = mesh.GetTopology();2324bool hasedges = top.HasEdges();25bool hasfaces = top.HasFaces();2627if (!hasedges || !hasfaces) return;282930PrintMessage (3, "Update Clusters");3132nv = mesh.GetNV();33ned = top.GetNEdges();34nfa = top.GetNFaces();35ne = mesh.GetNE();36int nse = mesh.GetNSE();3738cluster_reps.SetSize (nv+ned+nfa+ne);3940ARRAY<int> nnums, ednums, fanums;41int changed;4243for (i = 1; i <= cluster_reps.Size(); i++)44cluster_reps.Elem(i) = -1;454647for (i = 1; i <= ne; i++)48{49const Element & el = mesh.VolumeElement(i);50ELEMENT_TYPE typ = el.GetType();5152top.GetElementEdges (i, ednums);53top.GetElementFaces (i, fanums);5455int elnv = top.GetNVertices (typ);56int elned = ednums.Size();57int elnfa = fanums.Size();5859nnums.SetSize(elnv+elned+elnfa+1);60for (j = 1; j <= elnv; j++)61nnums.Elem(j) = el.PNum(j);62for (j = 1; j <= elned; j++)63nnums.Elem(elnv+j) = nv+ednums.Elem(j);64for (j = 1; j <= elnfa; j++)65nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);66nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;6768for (j = 0; j < nnums.Size(); j++)69cluster_reps.Elem(nnums[j]) = nnums[j];70}71727374for (i = 1; i <= nse; i++)75{76const Element2d & el = mesh.SurfaceElement(i);77ELEMENT_TYPE typ = el.GetType();7879top.GetSurfaceElementEdges (i, ednums);80int fanum = top.GetSurfaceElementFace (i);8182int elnv = top.GetNVertices (typ);83int elned = ednums.Size();8485nnums.SetSize(elnv+elned+1);86for (j = 1; j <= elnv; j++)87nnums.Elem(j) = el.PNum(j);88for (j = 1; j <= elned; j++)89nnums.Elem(elnv+j) = nv+ednums.Elem(j);90nnums.Elem(elnv+elned+1) = fanum;9192for (j = 0; j < nnums.Size(); j++)93cluster_reps.Elem(nnums[j]) = nnums[j];94}9596static const int hex_cluster[] =97{981, 2, 3, 4, 1, 2, 3, 4,995, 6, 7, 8, 5, 6, 7, 8, 1, 2, 3, 4,1009, 9, 5, 8, 6, 7,1019102};103104static const int prism_cluster[] =105{1061, 2, 3, 1, 2, 3,1074, 5, 6, 4, 5, 6, 3, 1, 2,1087, 7, 4, 5, 6,1097110};111112static const int pyramid_cluster[] =113{1141, 2, 2, 1, 3,1154, 2, 1, 4, 6, 5, 5, 6,1167, 5, 7, 6, 4,1177118};119static const int tet_cluster14[] =120{ 1, 2, 3, 1, 1, 4, 5, 4, 5, 6, 7, 5, 4, 7, 7 };121122static const int tet_cluster12[] =123{ 1, 1, 2, 3, 4, 4, 5, 1, 6, 6, 7, 7, 4, 6, 7 };124125static const int tet_cluster13[] =126{ 1, 2, 1, 3, 4, 6, 4, 5, 1, 5, 7, 4, 7, 5, 7 };127128static const int tet_cluster23[] =129{ 2, 1, 1, 3, 6, 5, 5, 4, 4, 1, 5, 7, 7, 4, 7 };130131static const int tet_cluster24[] =132{ 2, 1, 3, 1, 4, 1, 5, 4, 6, 5, 5, 7, 4, 7, 7 };133134static const int tet_cluster34[] =135{ 2, 3, 1, 1, 4, 5, 1, 6, 4, 5, 5, 4, 7, 7, 7 };136137int cnt = 0;138139do140{141142cnt++;143changed = 0;144145for (i = 1; i <= ne; i++)146{147const Element & el = mesh.VolumeElement(i);148ELEMENT_TYPE typ = el.GetType();149150top.GetElementEdges (i, ednums);151top.GetElementFaces (i, fanums);152153int elnv = top.GetNVertices (typ);154int elned = ednums.Size();155int elnfa = fanums.Size();156157nnums.SetSize(elnv+elned+elnfa+1);158for (j = 1; j <= elnv; j++)159nnums.Elem(j) = el.PNum(j);160for (j = 1; j <= elned; j++)161nnums.Elem(elnv+j) = nv+ednums.Elem(j);162for (j = 1; j <= elnfa; j++)163nnums.Elem(elnv+elned+j) = nv+ned+fanums.Elem(j);164nnums.Elem(elnv+elned+elnfa+1) = nv+ned+nfa+i;165166167const int * clustertab = NULL;168switch (typ)169{170case PRISM:171case PRISM12:172clustertab = prism_cluster;173break;174case HEX:175clustertab = hex_cluster;176break;177case PYRAMID:178clustertab = pyramid_cluster;179break;180case TET:181case TET10:182if (cluster_reps.Get(el.PNum(1)) ==183cluster_reps.Get(el.PNum(2)))184clustertab = tet_cluster12;185else if (cluster_reps.Get(el.PNum(1)) ==186cluster_reps.Get(el.PNum(3)))187clustertab = tet_cluster13;188else if (cluster_reps.Get(el.PNum(1)) ==189cluster_reps.Get(el.PNum(4)))190clustertab = tet_cluster14;191else if (cluster_reps.Get(el.PNum(2)) ==192cluster_reps.Get(el.PNum(3)))193clustertab = tet_cluster23;194else if (cluster_reps.Get(el.PNum(2)) ==195cluster_reps.Get(el.PNum(4)))196clustertab = tet_cluster24;197else if (cluster_reps.Get(el.PNum(3)) ==198cluster_reps.Get(el.PNum(4)))199clustertab = tet_cluster34;200201else202clustertab = NULL;203break;204default:205clustertab = NULL;206}207208if (clustertab)209for (j = 0; j < nnums.Size(); j++)210for (k = 0; k < j; k++)211if (clustertab[j] == clustertab[k])212{213int jj = nnums[j];214int kk = nnums[k];215if (cluster_reps.Get(jj) < cluster_reps.Get(kk))216{217cluster_reps.Elem(kk) = cluster_reps.Get(jj);218changed = 1;219}220else if (cluster_reps.Get(kk) < cluster_reps.Get(jj))221{222cluster_reps.Elem(jj) = cluster_reps.Get(kk);223changed = 1;224}225}226227/*228if (clustertab)229{230if (typ == PYRAMID)231(*testout) << "pyramid";232else if (typ == PRISM || typ == PRISM12)233(*testout) << "prism";234else if (typ == TET || typ == TET10)235(*testout) << "tet";236else237(*testout) << "unknown type" << endl;238239(*testout) << ", nnums = ";240for (j = 0; j < nnums.Size(); j++)241(*testout) << "node " << j << " = " << nnums[j] << ", rep = "242<< cluster_reps.Get(nnums[j]) << endl;243}244*/245}246}247while (changed);248249/*250(*testout) << "cluster reps:" << endl;251for (i = 1; i <= cluster_reps.Size(); i++)252{253(*testout) << i << ": ";254if (i <= nv)255(*testout) << "v" << i << " ";256else if (i <= nv+ned)257(*testout) << "e" << i-nv << " ";258else if (i <= nv+ned+nfa)259(*testout) << "f" << i-nv-ned << " ";260else261(*testout) << "c" << i-nv-ned-nfa << " ";262(*testout) << cluster_reps.Get(i) << endl;263}264*/265}266}267268269