mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-11 21:50:34 +05:00
Merge branch 'code_cleanup' into 'master'
Code cleanup See merge request jschoeberl/netgen!383
This commit is contained in:
commit
451dabb9bf
@ -351,6 +351,8 @@ namespace ngcore
|
||||
template <typename TEntry, typename TIndex, typename TRange, typename TFunc>
|
||||
Table<TEntry, TIndex> CreateTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt )
|
||||
{
|
||||
static Timer timer("CreateTable");
|
||||
RegionTimer rt(timer);
|
||||
std::unique_ptr<TableCreator<TEntry, TIndex>> pcreator;
|
||||
|
||||
if(cnt)
|
||||
@ -375,6 +377,8 @@ namespace ngcore
|
||||
template <typename TEntry, typename TIndex, typename TRange, typename TFunc>
|
||||
Table<TEntry, TIndex> CreateSortedTable( const TRange & range, const TFunc & func, std::optional< size_t > cnt )
|
||||
{
|
||||
static Timer timer("CreateSortedTable");
|
||||
RegionTimer rt(timer);
|
||||
Table<TEntry, TIndex> table = CreateTable<TEntry, TIndex>(range, func, cnt);
|
||||
ParallelForRange
|
||||
(table.Range(), [&] (auto myrange)
|
||||
|
@ -271,18 +271,18 @@ template <> NGX_INLINE DLL_HEADER const Ng_Node<0> Ngx_Mesh :: GetNode<0> (int v
|
||||
node.elements.ne = ia.Size();
|
||||
node.elements.ptr = (int*)&ia[0];
|
||||
|
||||
NgFlatArray<SegmentIndex> bia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
auto bia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
node.bnd_elements.ne = bia.Size();
|
||||
node.bnd_elements.ptr = (int*)&bia[0];
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
NgFlatArray<SegmentIndex> ia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
auto ia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
node.elements.ne = ia.Size();
|
||||
node.elements.ptr = (int*)&ia[0];
|
||||
|
||||
NgFlatArray<int> bia = mesh->GetTopology().GetVertexPointElements(vnr);
|
||||
auto bia = mesh->GetTopology().GetVertexPointElements(vnr);
|
||||
node.bnd_elements.ne = bia.Size();
|
||||
node.bnd_elements.ptr = (int*)&bia[0];
|
||||
break;
|
||||
|
@ -1653,7 +1653,7 @@ void Ng_GetVertexElements (int vnr, int * els)
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
NgFlatArray<SegmentIndex> ia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
auto ia = mesh->GetTopology().GetVertexSegments(vnr);
|
||||
for (int i = 0; i < ia.Size(); i++) els[i] = ia[i]+1;
|
||||
break;
|
||||
/*
|
||||
|
@ -16,13 +16,13 @@ namespace netgen
|
||||
;
|
||||
}
|
||||
|
||||
void AnisotropicClusters :: Update(NgTaskManager tm, NgTracer tracer)
|
||||
void AnisotropicClusters :: Update()
|
||||
{
|
||||
static int timer = NgProfiler::CreateTimer ("clusters");
|
||||
static Timer timer("clusters");
|
||||
// static int timer1 = NgProfiler::CreateTimer ("clusters1");
|
||||
// static int timer2 = NgProfiler::CreateTimer ("clusters2");
|
||||
// static int timer3 = NgProfiler::CreateTimer ("clusters3");
|
||||
NgProfiler::RegionTimer reg (timer);
|
||||
RegionTimer reg (timer);
|
||||
|
||||
const MeshTopology & top = mesh.GetTopology();
|
||||
|
||||
@ -81,13 +81,14 @@ namespace netgen
|
||||
cluster_reps.Elem(nnums[j]) = nnums[j];
|
||||
}
|
||||
*/
|
||||
ParallelForRange
|
||||
(tm, ne,
|
||||
[&] (size_t begin, size_t end)
|
||||
ngcore::ParallelForRange
|
||||
(mesh.VolumeElements().Range(),
|
||||
[&] (auto myrange)
|
||||
{
|
||||
NgArray<int> nnums, ednums, fanums;
|
||||
for (int i = begin+1; i <= end; i++)
|
||||
for (int i_ : myrange)
|
||||
{
|
||||
int i = i_+1;
|
||||
const Element & el = mesh.VolumeElement(i);
|
||||
ELEMENT_TYPE typ = el.GetType();
|
||||
|
||||
@ -110,7 +111,7 @@ namespace netgen
|
||||
for (int j = 0; j < nnums.Size(); j++)
|
||||
cluster_reps.Elem(nnums[j]) = nnums[j];
|
||||
}
|
||||
});
|
||||
}, ngcore::TasksPerThread(4));
|
||||
|
||||
// NgProfiler::StopTimer(timer1);
|
||||
// NgProfiler::StartTimer(timer2);
|
||||
@ -137,13 +138,14 @@ namespace netgen
|
||||
cluster_reps.Elem(nnums[j]) = nnums[j];
|
||||
}
|
||||
*/
|
||||
ParallelForRange
|
||||
(tm, nse,
|
||||
[&] (size_t begin, size_t end)
|
||||
ngcore::ParallelForRange
|
||||
(mesh.SurfaceElements().Range(),
|
||||
[&] (auto myrange)
|
||||
{
|
||||
NgArrayMem<int,9> nnums, ednums;
|
||||
for (int i = begin+1; i <= end; i++)
|
||||
for (int i_ : myrange)
|
||||
{
|
||||
int i = i_+1;
|
||||
const Element2d & el = mesh.SurfaceElement(i);
|
||||
ELEMENT_TYPE typ = el.GetType();
|
||||
|
||||
@ -163,7 +165,7 @@ namespace netgen
|
||||
for (int j = 0; j < nnums.Size(); j++)
|
||||
cluster_reps.Elem(nnums[j]) = nnums[j];
|
||||
}
|
||||
});
|
||||
}, ngcore::TasksPerThread(4));
|
||||
|
||||
|
||||
// NgProfiler::StopTimer(timer2);
|
||||
@ -215,7 +217,8 @@ namespace netgen
|
||||
|
||||
do
|
||||
{
|
||||
(*tracer) ("update cluster, identify", false);
|
||||
static Timer t("update cluster, identify");
|
||||
RegionTimer rtr(t);
|
||||
cnt++;
|
||||
changed = 0;
|
||||
|
||||
@ -338,7 +341,6 @@ namespace netgen
|
||||
}
|
||||
*/
|
||||
}
|
||||
(*tracer) ("update cluster, identify", true);
|
||||
}
|
||||
while (changed);
|
||||
// NgProfiler::StopTimer(timer3);
|
||||
|
@ -27,7 +27,7 @@ public:
|
||||
AnisotropicClusters (const Mesh & amesh);
|
||||
~AnisotropicClusters();
|
||||
|
||||
void Update(NgTaskManager tm = &DummyTaskManager, NgTracer trace = &DummyTracer);
|
||||
void Update();
|
||||
|
||||
int GetVertexRepresentant (int vnr) const
|
||||
{ return cluster_reps.Get(vnr); }
|
||||
|
@ -916,6 +916,7 @@ namespace netgen
|
||||
|
||||
void Mesh :: Load (istream & infile)
|
||||
{
|
||||
static Timer timer("Mesh::Load"); RegionTimer rt(timer);
|
||||
if (! (infile.good()) )
|
||||
{
|
||||
cout << "cannot load mesh" << endl;
|
||||
@ -956,6 +957,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "surfaceelements") == 0 || strcmp (str, "surfaceelementsgi")==0 || strcmp (str, "surfaceelementsuv") == 0)
|
||||
{
|
||||
static Timer t1("read surface elements"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
PrintMessage (3, n, " surface elements");
|
||||
|
||||
@ -1020,6 +1022,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "volumeelements") == 0)
|
||||
{
|
||||
static Timer t1("read volume elements"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
PrintMessage (3, n, " volume elements");
|
||||
for (i = 1; i <= n; i++)
|
||||
@ -1045,6 +1048,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "edgesegments") == 0)
|
||||
{
|
||||
static Timer t1("read edge segments"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
@ -1059,6 +1063,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "edgesegmentsgi") == 0)
|
||||
{
|
||||
static Timer t1("read edge segmentsgi"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
for (i = 1; i <= n; i++)
|
||||
{
|
||||
@ -1073,6 +1078,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "edgesegmentsgi2") == 0)
|
||||
{
|
||||
static Timer t1("read edge segmentsgi2"); RegionTimer rt1(t1);
|
||||
int a;
|
||||
infile >> a;
|
||||
n=a;
|
||||
@ -1106,6 +1112,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "points") == 0)
|
||||
{
|
||||
static Timer t1("read points"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
PrintMessage (3, n, " points");
|
||||
for (i = 1; i <= n; i++)
|
||||
@ -1122,6 +1129,7 @@ namespace netgen
|
||||
|
||||
if (strcmp (str, "pointelements") == 0)
|
||||
{
|
||||
static Timer t1("read point elements"); RegionTimer rt1(t1);
|
||||
infile >> n;
|
||||
PrintMessage (3, n, " pointelements");
|
||||
for (i = 1; i <= n; i++)
|
||||
@ -6698,7 +6706,7 @@ namespace netgen
|
||||
static Timer t("Update Topology"); RegionTimer reg(t);
|
||||
topology.Update(tm, tracer);
|
||||
(*tracer)("call update clusters", false);
|
||||
clusters->Update(tm, tracer);
|
||||
clusters->Update();
|
||||
(*tracer)("call update clusters", true);
|
||||
#ifdef PARALLEL
|
||||
if (paralleltop)
|
||||
|
@ -5,6 +5,7 @@ namespace netgen
|
||||
{
|
||||
using ngcore::ParallelForRange;
|
||||
using ngcore::INT;
|
||||
using ngcore::TasksPerThread;
|
||||
|
||||
template <class T>
|
||||
void QuickSortRec (NgFlatArray<T> data,
|
||||
@ -367,6 +368,7 @@ namespace netgen
|
||||
void MeshTopology :: Update (NgTaskManager tm_unused, NgTracer tracer)
|
||||
{
|
||||
static Timer timer("Topology::Update");
|
||||
static Timer timer_tables("Build vertex to element table");
|
||||
RegionTimer reg (timer);
|
||||
|
||||
#ifdef PARALLEL
|
||||
@ -405,46 +407,34 @@ namespace netgen
|
||||
vertex to segment
|
||||
*/
|
||||
|
||||
timer_tables.Start();
|
||||
vert2element = mesh->CreatePoint2ElementTable();
|
||||
vert2surfelement = mesh->CreatePoint2SurfaceElementTable(0);
|
||||
|
||||
cnt = 0;
|
||||
for (SegmentIndex si = 0; si < nseg; si++)
|
||||
{
|
||||
const Segment & seg = mesh->LineSegment(si);
|
||||
cnt[seg[0]]++;
|
||||
cnt[seg[1]]++;
|
||||
}
|
||||
|
||||
vert2segment = TABLE<SegmentIndex,PointIndex::BASE> (cnt);
|
||||
for (SegmentIndex si = 0; si < nseg; si++)
|
||||
{
|
||||
const Segment & seg = mesh->LineSegment(si);
|
||||
vert2segment.AddSave (seg[0], si);
|
||||
vert2segment.AddSave (seg[1], si);
|
||||
}
|
||||
vert2segment = ngcore::CreateSortedTable<SegmentIndex, PointIndex>( mesh->LineSegments().Range(),
|
||||
[&](auto & table, SegmentIndex segi)
|
||||
{
|
||||
const Segment & seg = (*mesh)[segi];
|
||||
table.Add (seg[0], segi);
|
||||
table.Add (seg[1], segi);
|
||||
}, np);
|
||||
|
||||
vert2pointelement = ngcore::CreateSortedTable<int, PointIndex>( mesh->pointelements.Range(),
|
||||
[&](auto & table, int pei)
|
||||
{
|
||||
const Element0d & pointel = mesh->pointelements[pei];
|
||||
table.Add(pointel.pnum, pei);
|
||||
}, np);
|
||||
timer_tables.Stop();
|
||||
|
||||
|
||||
cnt = 0;
|
||||
for (int pei = 0; pei < mesh->pointelements.Size(); pei++)
|
||||
{
|
||||
const Element0d & pointel = mesh->pointelements[pei];
|
||||
cnt[pointel.pnum]++;
|
||||
}
|
||||
|
||||
vert2pointelement = TABLE<int,PointIndex::BASE> (cnt);
|
||||
for (int pei = 0; pei < mesh->pointelements.Size(); pei++)
|
||||
{
|
||||
const Element0d & pointel = mesh->pointelements[pei];
|
||||
vert2pointelement.AddSave (pointel.pnum, pei);
|
||||
}
|
||||
(*tracer) ("Topology::Update setup tables", true);
|
||||
|
||||
|
||||
if (buildedges)
|
||||
{
|
||||
static int timer1 = NgProfiler::CreateTimer ("topology::buildedges");
|
||||
NgProfiler::RegionTimer reg1 (timer1);
|
||||
static Timer timer1("topology::buildedges");
|
||||
RegionTimer reg1(timer1);
|
||||
|
||||
if (id == 0)
|
||||
PrintMessage (5, "Update edges ");
|
||||
@ -535,7 +525,7 @@ namespace netgen
|
||||
});
|
||||
cnt[v] = cnti;
|
||||
}
|
||||
} );
|
||||
}, TasksPerThread(4) );
|
||||
|
||||
// accumulate number of edges
|
||||
int ned = edge2vert.Size();
|
||||
@ -624,7 +614,7 @@ namespace netgen
|
||||
}
|
||||
});
|
||||
}
|
||||
} );
|
||||
}, TasksPerThread(4) );
|
||||
|
||||
|
||||
if (build_parent_edges)
|
||||
@ -907,12 +897,12 @@ namespace netgen
|
||||
// generate faces
|
||||
if (buildfaces)
|
||||
{
|
||||
static int timer2 = NgProfiler::CreateTimer ("topology::buildfaces");
|
||||
static Timer timer2("topology::buildfaces");
|
||||
// static int timer2a = NgProfiler::CreateTimer ("topology::buildfacesa");
|
||||
// static int timer2b = NgProfiler::CreateTimer ("topology::buildfacesb");
|
||||
// static int timer2b1 = NgProfiler::CreateTimer ("topology::buildfacesb1");
|
||||
// static int timer2c = NgProfiler::CreateTimer ("topology::buildfacesc");
|
||||
NgProfiler::RegionTimer reg2 (timer2);
|
||||
RegionTimer reg2 (timer2);
|
||||
|
||||
if (id == 0)
|
||||
PrintMessage (5, "Update faces ");
|
||||
@ -1051,7 +1041,7 @@ namespace netgen
|
||||
});
|
||||
cnt[v] = cnti;
|
||||
}
|
||||
} );
|
||||
}, TasksPerThread(4) );
|
||||
// NgProfiler::StopTimer (timer2b1);
|
||||
|
||||
// accumulate number of faces
|
||||
@ -1156,7 +1146,7 @@ namespace netgen
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}, TasksPerThread(4) );
|
||||
|
||||
/*
|
||||
int oldnfa = face2vert.Size();
|
||||
@ -1485,7 +1475,7 @@ namespace netgen
|
||||
for (auto f : hfaces)
|
||||
AsAtomic(face_els[f-1])++;
|
||||
}
|
||||
});
|
||||
}, TasksPerThread(4));
|
||||
for (int i = 1; i <= nse; i++)
|
||||
face_surfels[GetSurfaceElementFace (i)-1]++;
|
||||
(*tracer) ("Topology::Update count face_els", true);
|
||||
|
@ -67,8 +67,8 @@ class MeshTopology
|
||||
Array<SegmentIndex> edge2segment;
|
||||
Table<ElementIndex, PointIndex> vert2element;
|
||||
Table<SurfaceElementIndex, PointIndex> vert2surfelement;
|
||||
TABLE<SegmentIndex,PointIndex::BASE> vert2segment;
|
||||
TABLE<int,PointIndex::BASE> vert2pointelement;
|
||||
Table<SegmentIndex,PointIndex> vert2segment;
|
||||
Table<int,PointIndex> vert2pointelement;
|
||||
int timestamp;
|
||||
public:
|
||||
int GetNSurfedges() const {return surfedges.Size();}
|
||||
@ -183,10 +183,10 @@ public:
|
||||
FlatArray<SurfaceElementIndex> GetVertexSurfaceElements(PointIndex vnr) const
|
||||
{ return vert2surfelement[vnr]; }
|
||||
|
||||
NgFlatArray<SegmentIndex> GetVertexSegments (int vnr) const
|
||||
FlatArray<SegmentIndex> GetVertexSegments (int vnr) const
|
||||
{ return vert2segment[vnr]; }
|
||||
|
||||
NgFlatArray<int> GetVertexPointElements (int vnr) const
|
||||
FlatArray<int> GetVertexPointElements (int vnr) const
|
||||
{ return vert2pointelement[vnr]; }
|
||||
|
||||
int GetVerticesEdge ( int v1, int v2) const;
|
||||
|
Loading…
Reference in New Issue
Block a user