From 19c86a9f3d0ba962c4b61ef25fa6b195c5e430c8 Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Mon, 14 Oct 2019 13:50:56 +0200 Subject: [PATCH] Move BuildEdgeList to improve2.hpp --- libsrc/meshing/improve2.hpp | 55 +++++++++++++++++++++++++++++++++++++ libsrc/meshing/improve3.cpp | 54 ------------------------------------ libsrc/meshing/improve3.hpp | 2 -- 3 files changed, 55 insertions(+), 56 deletions(-) diff --git a/libsrc/meshing/improve2.hpp b/libsrc/meshing/improve2.hpp index 03ff5559..bc4ad00d 100644 --- a/libsrc/meshing/improve2.hpp +++ b/libsrc/meshing/improve2.hpp @@ -1,6 +1,61 @@ #ifndef FILE_IMPROVE2 #define FILE_IMPROVE2 +template +void BuildEdgeList( const Mesh & mesh, const Table & elementsonnode, Array> & edges ) +{ + static Timer tbuild_edges("Build edges"); RegionTimer reg(tbuild_edges); + + static constexpr int tetedges[6][2] = + { { 0, 1 }, { 0, 2 }, { 0, 3 }, + { 1, 2 }, { 1, 3 }, { 2, 3 } }; + + int ntasks = 2*ngcore::TaskManager::GetMaxThreads(); + Array>> task_edges(ntasks); + + ParallelFor(IntRange(ntasks), [&] (int ti) + { + auto myrange = mesh.Points().Range().Split(ti, ntasks); + ArrayMem, 100> local_edges; + for (auto pi : myrange) + { + local_edges.SetSize(0); + + for(auto ei : elementsonnode[pi]) + { + const auto & elem = mesh[ei]; + if (elem.IsDeleted()) continue; + + for (int j = 0; j < 6; j++) + { + PointIndex pi0 = elem[tetedges[j][0]]; + PointIndex pi1 = elem[tetedges[j][1]]; + if (pi1 < pi0) Swap(pi0, pi1); + if(pi0==pi) + local_edges.Append(std::make_tuple(pi0, pi1)); + } + } + QuickSort(local_edges); + + auto edge_prev = std::make_tuple(-1,-1); + + for(auto edge : local_edges) + if(edge != edge_prev) + { + task_edges[ti].Append(edge); + edge_prev = edge; + } + } + }, ntasks); + + int num_edges = 0; + for (auto & edg : task_edges) + num_edges += edg.Size(); + edges.SetAllocSize(num_edges); + for (auto & edg : task_edges) + edges.Append(edg); +} + class Neighbour { diff --git a/libsrc/meshing/improve3.cpp b/libsrc/meshing/improve3.cpp index e5ee4e03..8400e541 100644 --- a/libsrc/meshing/improve3.cpp +++ b/libsrc/meshing/improve3.cpp @@ -409,60 +409,6 @@ void MeshOptimize3d :: CombineImproveSequential (Mesh & mesh, multithread.task = savetask; } -void MeshOptimize3d :: BuildEdgeList( const Mesh & mesh, const Table & elementsonnode, Array> & edges ) -{ - static Timer tbuild_edges("Build edges"); RegionTimer reg(tbuild_edges); - - static constexpr int tetedges[6][2] = - { { 0, 1 }, { 0, 2 }, { 0, 3 }, - { 1, 2 }, { 1, 3 }, { 2, 3 } }; - - int ntasks = 2*ngcore::TaskManager::GetMaxThreads(); - Array>> task_edges(ntasks); - - ParallelFor(IntRange(ntasks), [&] (int ti) - { - auto myrange = mesh.Points().Range().Split(ti, ntasks); - ArrayMem, 100> local_edges; - for (auto pi : myrange) - { - local_edges.SetSize(0); - - for(auto ei : elementsonnode[pi]) - { - const Element & elem = mesh[ei]; - if (elem.IsDeleted()) continue; - - for (int j = 0; j < 6; j++) - { - PointIndex pi0 = elem[tetedges[j][0]]; - PointIndex pi1 = elem[tetedges[j][1]]; - if (pi1 < pi0) Swap(pi0, pi1); - if(pi0==pi) - local_edges.Append(std::make_tuple(pi0, pi1)); - } - } - QuickSort(local_edges); - - auto edge_prev = std::make_tuple(-1,-1); - - for(auto edge : local_edges) - if(edge != edge_prev) - { - task_edges[ti].Append(edge); - edge_prev = edge; - } - } - }, ntasks); - - int num_edges = 0; - for (auto & edg : task_edges) - num_edges += edg.Size(); - edges.SetAllocSize(num_edges); - for (auto & edg : task_edges) - edges.Append(edg); -} - void MeshOptimize3d :: CombineImprove (Mesh & mesh, OPTIMIZEGOAL goal) { diff --git a/libsrc/meshing/improve3.hpp b/libsrc/meshing/improve3.hpp index 7507b64a..21fdcce6 100644 --- a/libsrc/meshing/improve3.hpp +++ b/libsrc/meshing/improve3.hpp @@ -12,8 +12,6 @@ class MeshOptimize3d { const MeshingParameters & mp; - void BuildEdgeList( const Mesh & mesh, const Table & elementsonnode, Array> & edges ); - public: MeshOptimize3d (const MeshingParameters & amp) : mp(amp) { ; }