From 2e69b39339b3b91bea3513335fa034ca46a61cbf Mon Sep 17 00:00:00 2001 From: Joachim Schoeberl Date: Wed, 10 Feb 2021 19:39:52 +0100 Subject: [PATCH] cleanup parent_edges --- libsrc/meshing/topology.cpp | 93 ++++++++++++------------------------- 1 file changed, 30 insertions(+), 63 deletions(-) diff --git a/libsrc/meshing/topology.cpp b/libsrc/meshing/topology.cpp index e2446f87..f128c10e 100644 --- a/libsrc/meshing/topology.cpp +++ b/libsrc/meshing/topology.cpp @@ -683,74 +683,49 @@ namespace netgen { static Timer t("build_hierarchy"); RegionTimer reg(t); cnt = 0; - for (size_t i = 0; i < edge2vert.Size(); i++) - cnt[edge2vert[i][0]]++; + for (auto verts : edge2vert) cnt[verts[0]]++; TABLE vert2edge (cnt); - for (size_t i = 0; i < edge2vert.Size(); i++) + for (auto i : edge2vert.Range()) vert2edge.AddSave (edge2vert[i][0], i); - + // build edge hierarchy: parent_edges.SetSize (ned); parent_edges = { -1, { -1, -1, -1 } }; - /* - cout << "mlbetween = " << mesh->mlbetweennodes.Size() << endl; - cout << "mlbetween = " << endl << mesh->mlbetweennodes << endl; - cout << "v2e = " << endl << vert2edge << endl; - cout << "e2v = " << endl << edge2vert << endl; - cout << "ned = " << ned << endl; - */ + for (size_t i = 0; i < ned; i++) { - // cout << " ref edge " << i << "/" << ned << endl; - /* - int pa1[2], pa2[2]; - ma->GetParentNodes (i2[0], pa1); - ma->GetParentNodes (i2[1], pa2); - */ - auto i2 = edge2vert[i]; // 2 vertices of edge + auto verts = edge2vert[i]; // 2 vertices of edge - if (i2[0] > mesh->mlbetweennodes.Size()+PointIndex::BASE || - i2[1] > mesh->mlbetweennodes.Size()+PointIndex::BASE) + if (verts[0] > mesh->mlbetweennodes.Size()+PointIndex::BASE || + verts[1] > mesh->mlbetweennodes.Size()+PointIndex::BASE) continue; - - // cout << "i2 = " << i2 << endl; - auto pa1 = mesh->mlbetweennodes[i2[0]]; // two parent vertices of v0 - auto pa2 = mesh->mlbetweennodes[i2[1]]; // two parent vertices of v1 - - // cout << "pa1 = " << pa1 << endl; - // cout << "pa2 = " << pa2 << endl; - //if (pa1[0] == -1 && pa2[0] == -1) - // continue; + + auto pa0 = mesh->mlbetweennodes[verts[0]]; // two parent vertices of v0 + auto pa1 = mesh->mlbetweennodes[verts[1]]; // two parent vertices of v1 // both vertices are on coarsest mesh - if (!pa1[0].IsValid() && !pa2[0].IsValid()) + if (!pa0[0].IsValid() && !pa1[0].IsValid()) continue; - int issplitedge = 0; - if (pa1[0] == i2[1] || pa1[1] == i2[1]) + if (pa0[0] == verts[1] || pa0[1] == verts[1]) issplitedge = 1; - if (pa2[0] == i2[0] || pa2[1] == i2[0]) + if (pa1[0] == verts[0] || pa1[1] == verts[0]) issplitedge = 2; if (issplitedge) { // cout << "split edge " << endl; // edge is obtained by splitting one edge into two parts: - INT<2> paedge; - if (issplitedge == 1) - paedge = INT<2> (pa1[0], pa1[1]); - else - paedge = INT<2> (pa2[0], pa2[1]); - + auto paedge = issplitedge == 1 ? pa0 : pa1; + if (paedge[0] > paedge[1]) Swap (paedge[0], paedge[1]); - + for (int ednr : vert2edge[paedge[0]]) - if (auto ic2 = edge2vert[ednr]; ic2[1] == paedge[1]) + if (auto cverts = edge2vert[ednr]; cverts[1] == paedge[1]) { - // cout << "matching: " << ednr << endl; - int orient = (paedge[0] == i2[0] || paedge[1] == i2[1]) ? 1 : 0; + int orient = (paedge[0] == verts[0] || paedge[1] == verts[1]) ? 1 : 0; parent_edges[i] = { orient, { ednr, -1, -1 } }; } } @@ -763,16 +738,16 @@ namespace netgen int orient_inner = 0; if (j == 1) { - paedge1 = INT<2> (pa1[0], i2[1]); - paedge2 = INT<2> (pa1[1], i2[1]); - paedge3 = INT<2> (pa1[0], pa1[1]); + paedge1 = INT<2> (pa0[0], verts[1]); + paedge2 = INT<2> (pa0[1], verts[1]); + paedge3 = INT<2> (pa0[0], pa0[1]); orient_inner = 0; } else { - paedge1 = INT<2> (pa2[0], i2[0]); - paedge2 = INT<2> (pa2[1], i2[0]); - paedge3 = INT<2> (pa2[0], pa2[1]); + paedge1 = INT<2> (pa1[0], verts[0]); + paedge2 = INT<2> (pa1[1], verts[0]); + paedge3 = INT<2> (pa1[0], pa1[1]); orient_inner = 1; } if (paedge1[0] > paedge1[1]) @@ -782,35 +757,27 @@ namespace netgen if (paedge3[0] > paedge3[1]) Swap (paedge3[0], paedge3[1]); - // cout << "paedge1 = " << paedge1 << ", paedge2 = " << paedge2 << endl; // if first vertex number is -1, then don't try to find entry in node2edge hash table if ( paedge1[0] == PointIndex::BASE-1 || paedge2[0] == PointIndex::BASE-1 ) continue; int paedgenr1=-1, paedgenr2=-1, paedgenr3=-1, orient1 = 0, orient2 = 0; for (int ednr : vert2edge[paedge1[0]]) - if (auto ic2 = edge2vert[ednr]; ic2[1] == paedge1[1]) + if (auto cverts = edge2vert[ednr]; cverts[1] == paedge1[1]) { paedgenr1 = ednr; - // cout << "ednr = " << ednr << ", i2 = " << i2 << endl; - orient1 = (paedge1[0] == i2[0] || paedge1[1] == i2[1]) ? 1 : 0; - // cout << "orient1 = " << orient1 << endl; + orient1 = (paedge1[0] == verts[0] || paedge1[1] == verts[1]) ? 1 : 0; } for (int ednr : vert2edge[paedge2[0]]) - if (auto ic2 = edge2vert[ednr]; ic2[1] == paedge2[1]) + if (auto cverts = edge2vert[ednr]; cverts[1] == paedge2[1]) { paedgenr2 = ednr; - // cout << "ednr = " << ednr << ", i2 = " << i2 << endl; - orient2 = (paedge2[0] == i2[0] || paedge2[1] == i2[1]) ? 1 : 0; - // cout << "orient2 = " << orient2 << endl; + orient2 = (paedge2[0] == verts[0] || paedge2[1] == verts[1]) ? 1 : 0; } for (int ednr : vert2edge[paedge3[0]]) - if (auto ic2 = edge2vert[ednr]; ic2[1] == paedge3[1]) - { - paedgenr3 = ednr; - // cout << "ednr = " << ednr << ", i2 = " << i2 << endl; - } + if (auto cverts = edge2vert[ednr]; cverts[1] == paedge3[1]) + paedgenr3 = ednr; if (paedgenr1 != -1 && paedgenr2 != -1) parent_edges[i] = { orient1+2*orient2+4*orient_inner, { paedgenr1, paedgenr2, paedgenr3 } };