mirror of
https://github.com/NGSolve/netgen.git
synced 2025-02-11 12:53:08 +05:00
switch to ngcore::ClosedHashTable
This commit is contained in:
parent
abe18a9b74
commit
9c9b4ea880
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
|
#include <optional>
|
||||||
|
|
||||||
// #include "mpi_wrapper.hpp"
|
// #include "mpi_wrapper.hpp"
|
||||||
#include "ngcore_api.hpp"
|
#include "ngcore_api.hpp"
|
||||||
@ -591,6 +592,8 @@ namespace ngcore
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr inline T InvalidHash() { return T{-1}; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
A closed hash-table.
|
A closed hash-table.
|
||||||
@ -611,14 +614,16 @@ namespace ngcore
|
|||||||
///
|
///
|
||||||
Array<T> cont;
|
Array<T> cont;
|
||||||
///
|
///
|
||||||
T_HASH invalid = -1;
|
// T_HASH invalid = -1;
|
||||||
|
static constexpr T_HASH invalid = InvalidHash<T_HASH>();
|
||||||
public:
|
public:
|
||||||
///
|
///
|
||||||
ClosedHashTable (size_t asize = 128)
|
ClosedHashTable (size_t asize = 128)
|
||||||
: size(RoundUp2(asize)), hash(size), cont(size)
|
: size(RoundUp2(asize)), hash(size), cont(size)
|
||||||
{
|
{
|
||||||
mask = size-1;
|
mask = size-1;
|
||||||
hash = T_HASH(invalid);
|
// hash = T_HASH(invalid);
|
||||||
|
hash = InvalidHash<T_HASH>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosedHashTable (ClosedHashTable && ht2) = default;
|
ClosedHashTable (ClosedHashTable && ht2) = default;
|
||||||
@ -627,7 +632,8 @@ namespace ngcore
|
|||||||
ClosedHashTable (size_t asize, LocalHeap & lh)
|
ClosedHashTable (size_t asize, LocalHeap & lh)
|
||||||
: size(RoundUp2(asize)), mask(size-1), hash(size, lh), cont(size, lh)
|
: size(RoundUp2(asize)), mask(size-1), hash(size, lh), cont(size, lh)
|
||||||
{
|
{
|
||||||
hash = T_HASH(invalid);
|
// hash = T_HASH(invalid);
|
||||||
|
hash = InvalidHash<T_HASH>();
|
||||||
}
|
}
|
||||||
|
|
||||||
ClosedHashTable & operator= (ClosedHashTable && ht2) = default;
|
ClosedHashTable & operator= (ClosedHashTable && ht2) = default;
|
||||||
@ -719,6 +725,16 @@ namespace ngcore
|
|||||||
return (Position (ahash) != size_t(-1));
|
return (Position (ahash) != size_t(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline std::optional<T> GetIfUsed (const T_HASH & ahash) const
|
||||||
|
{
|
||||||
|
size_t pos = Position (ahash);
|
||||||
|
if (pos != size_t(-1))
|
||||||
|
return cont[pos];
|
||||||
|
else
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SetData (size_t pos, const T_HASH & ahash, const T & acont)
|
void SetData (size_t pos, const T_HASH & ahash, const T & acont)
|
||||||
{
|
{
|
||||||
hash[pos] = ahash;
|
hash[pos] = ahash;
|
||||||
|
@ -116,12 +116,15 @@ public:
|
|||||||
///
|
///
|
||||||
INDEX_2 () { }
|
INDEX_2 () { }
|
||||||
///
|
///
|
||||||
INDEX_2 (INDEX ai1, INDEX ai2)
|
constexpr INDEX_2 (INDEX ai1, INDEX ai2)
|
||||||
{ i[0] = ai1; i[1] = ai2; }
|
: i{ai1, ai2} { }
|
||||||
|
// { i[0] = ai1; i[1] = ai2; }
|
||||||
|
|
||||||
///
|
///
|
||||||
INDEX_2 (const INDEX_2 & in2)
|
constexpr INDEX_2 (const INDEX_2 & in2)
|
||||||
{ i[0] = in2.i[0]; i[1] = in2.i[1]; }
|
: i{in2.i[0], in2.i[1]} { }
|
||||||
|
|
||||||
|
// { i[0] = in2.i[0]; i[1] = in2.i[1]; }
|
||||||
|
|
||||||
///
|
///
|
||||||
int operator== (const INDEX_2 & in2) const
|
int operator== (const INDEX_2 & in2) const
|
||||||
@ -165,7 +168,7 @@ public:
|
|||||||
///
|
///
|
||||||
int & operator[] (int j) { return i[j]; }
|
int & operator[] (int j) { return i[j]; }
|
||||||
///
|
///
|
||||||
const int & operator[] (int j) const { return i[j]; }
|
constexpr const int & operator[] (int j) const { return i[j]; }
|
||||||
///
|
///
|
||||||
friend ostream & operator<<(ostream & s, const INDEX_2 & i2);
|
friend ostream & operator<<(ostream & s, const INDEX_2 & i2);
|
||||||
};
|
};
|
||||||
@ -464,4 +467,17 @@ void MergeSort (int size, T * data, T * help);
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace ngcore
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
constexpr inline netgen::INDEX_2 InvalidHash<netgen::INDEX_2> () { return netgen::INDEX_2{-1,-1}; }
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace netgen
|
||||||
|
{
|
||||||
|
constexpr inline size_t HashValue2 (const netgen::INDEX_2 & ind, size_t mask)
|
||||||
|
{
|
||||||
|
return HashValue2(IVec<2,netgen::INDEX>(ind[0], ind[1]), mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -294,10 +294,11 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename HASHTABLE_EDGENUMBER>
|
||||||
int BTSortEdges (const Mesh & mesh,
|
int BTSortEdges (const Mesh & mesh,
|
||||||
const NgArray<idmap_type*> & idmaps,
|
const NgArray<idmap_type*> & idmaps,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber)
|
// INDEX_2_CLOSED_HASHTABLE<int> & edgenumber)
|
||||||
|
HASHTABLE_EDGENUMBER & edgenumber)
|
||||||
{
|
{
|
||||||
PrintMessage(4,"sorting ... ");
|
PrintMessage(4,"sorting ... ");
|
||||||
|
|
||||||
@ -305,8 +306,8 @@ namespace netgen
|
|||||||
if (true)
|
if (true)
|
||||||
{
|
{
|
||||||
// new, fast version
|
// new, fast version
|
||||||
|
cout << "sort edges is used" << endl;
|
||||||
NgArray<INDEX_2> edges;
|
Array<PointIndices<2>> edges;
|
||||||
NgArray<int> eclasses;
|
NgArray<int> eclasses;
|
||||||
|
|
||||||
// int i, j, k;
|
// int i, j, k;
|
||||||
@ -597,13 +598,8 @@ namespace netgen
|
|||||||
edgelength.Elem(i) = 1e20;
|
edgelength.Elem(i) = 1e20;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
for (int i = 1; i <= cntedges; i++)
|
for (int i = 0; i < cntedges; i++)
|
||||||
{
|
edgelength[i] = Dist (mesh[edges[i][0]], mesh[edges[i][1]]);
|
||||||
INDEX_2 edge = edges.Get(i);
|
|
||||||
double elen = Dist (mesh.Point(edge.I1()),
|
|
||||||
mesh.Point(edge.I2()));
|
|
||||||
edgelength.Elem (i) = elen;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
for (i = 1; i <= mesh.GetNE(); i++)
|
for (i = 1; i <= mesh.GetNE(); i++)
|
||||||
@ -677,7 +673,7 @@ namespace netgen
|
|||||||
|
|
||||||
TABLE<int> eclasstab(cntedges);
|
TABLE<int> eclasstab(cntedges);
|
||||||
for (int i = 1; i <= cntedges; i++)
|
for (int i = 1; i <= cntedges; i++)
|
||||||
eclasstab.Add1 (eclasses.Get(i), i);
|
eclasstab.Add1 (eclasses.Get(i), i-1);
|
||||||
|
|
||||||
|
|
||||||
// sort edges:
|
// sort edges:
|
||||||
@ -690,10 +686,7 @@ namespace netgen
|
|||||||
{
|
{
|
||||||
int ii = sorted.Get(i);
|
int ii = sorted.Get(i);
|
||||||
for (int j = 1; j <= eclasstab.EntrySize(ii); j++)
|
for (int j = 1; j <= eclasstab.EntrySize(ii); j++)
|
||||||
{
|
edgenumber.Set (edges[eclasstab.Get(ii, j)], ++cnt);
|
||||||
cnt++;
|
|
||||||
edgenumber.Set (edges.Get(eclasstab.Get(ii, j)), cnt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return cnt;
|
return cnt;
|
||||||
}
|
}
|
||||||
@ -869,9 +862,9 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_EDGENUMBER>
|
||||||
void BTDefineMarkedTet (const Element & el,
|
void BTDefineMarkedTet (const Element & el,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber,
|
T_EDGENUMBER & edgenumber,
|
||||||
MarkedTet & mt)
|
MarkedTet & mt)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
@ -923,9 +916,9 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_EDGENUMBER>
|
||||||
void BTDefineMarkedPrism (const Element & el,
|
void BTDefineMarkedPrism (const Element & el,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber,
|
T_EDGENUMBER & edgenumber,
|
||||||
MarkedPrism & mp)
|
MarkedPrism & mp)
|
||||||
{
|
{
|
||||||
if (el.GetType() == PRISM ||
|
if (el.GetType() == PRISM ||
|
||||||
@ -978,9 +971,9 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_EDGENUMBER>
|
||||||
bool BTDefineMarkedId(const Element2d & el,
|
bool BTDefineMarkedId(const Element2d & el,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber,
|
T_EDGENUMBER & edgenumber,
|
||||||
const idmap_type & idmap,
|
const idmap_type & idmap,
|
||||||
MarkedIdentification & mi)
|
MarkedIdentification & mi)
|
||||||
{
|
{
|
||||||
@ -1028,9 +1021,10 @@ namespace netgen
|
|||||||
return identified;
|
return identified;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_EDGENUMBER>
|
||||||
void BTDefineMarkedTri (const Element2d & el,
|
void BTDefineMarkedTri (const Element2d & el,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber,
|
T_EDGENUMBER & edgenumber,
|
||||||
MarkedTri & mt)
|
MarkedTri & mt)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
@ -1049,9 +1043,12 @@ namespace netgen
|
|||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
for (int j = i+1; j < 3; j++)
|
for (int j = i+1; j < 3; j++)
|
||||||
{
|
{
|
||||||
|
/*
|
||||||
PointIndices<2> i2(mt.pnums[i], mt.pnums[j]);
|
PointIndices<2> i2(mt.pnums[i], mt.pnums[j]);
|
||||||
i2.Sort();
|
i2.Sort();
|
||||||
int hval = edgenumber.Get(i2);
|
int hval = edgenumber.Get(i2);
|
||||||
|
*/
|
||||||
|
int hval = edgenumber.Get(PointIndices<2>(mt.pnums[i], mt.pnums[j]).Sort());
|
||||||
if (hval > val)
|
if (hval > val)
|
||||||
{
|
{
|
||||||
val = hval;
|
val = hval;
|
||||||
@ -1084,9 +1081,9 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T_EDGENUMBER>
|
||||||
void BTDefineMarkedQuad (const Element2d & el,
|
void BTDefineMarkedQuad (const Element2d & el,
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> & edgenumber,
|
T_EDGENUMBER & edgenumber,
|
||||||
MarkedQuad & mq)
|
MarkedQuad & mq)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
@ -1463,7 +1460,6 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void BTBisectTri (const MarkedTri & oldtri, PointIndex newp, const PointGeomInfo & newpgi,
|
void BTBisectTri (const MarkedTri & oldtri, PointIndex newp, const PointGeomInfo & newpgi,
|
||||||
MarkedTri & newtri1, MarkedTri & newtri2)
|
MarkedTri & newtri1, MarkedTri & newtri2)
|
||||||
{
|
{
|
||||||
@ -1600,9 +1596,9 @@ namespace netgen
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename HASHTABLE_CUTEDGES>
|
||||||
int MarkHangingIdentifications(T_MIDS & mids,
|
int MarkHangingIdentifications(T_MIDS & mids,
|
||||||
const INDEX_2_CLOSED_HASHTABLE<PointIndex> & cutedges)
|
const HASHTABLE_CUTEDGES & cutedges)
|
||||||
{
|
{
|
||||||
int hanging = 0;
|
int hanging = 0;
|
||||||
for (int i = 1; i <= mids.Size(); i++)
|
for (int i = 1; i <= mids.Size(); i++)
|
||||||
@ -1695,8 +1691,9 @@ namespace netgen
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
template <typename HASHTABLE_CUTEDGES>
|
||||||
int MarkHangingTets (T_MTETS & mtets,
|
int MarkHangingTets (T_MTETS & mtets,
|
||||||
const INDEX_2_CLOSED_HASHTABLE<PointIndex> & cutedges,
|
const HASHTABLE_CUTEDGES & cutedges,
|
||||||
NgTaskManager tm)
|
NgTaskManager tm)
|
||||||
{
|
{
|
||||||
static int timer = NgProfiler::CreateTimer ("MarkHangingTets");
|
static int timer = NgProfiler::CreateTimer ("MarkHangingTets");
|
||||||
@ -1738,9 +1735,9 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename HASHTABLE_CUTEDGES>
|
||||||
int MarkHangingPrisms (T_MPRISMS & mprisms,
|
int MarkHangingPrisms (T_MPRISMS & mprisms,
|
||||||
const INDEX_2_CLOSED_HASHTABLE<PointIndex> & cutedges)
|
const HASHTABLE_CUTEDGES & cutedges)
|
||||||
{
|
{
|
||||||
int hanging = 0;
|
int hanging = 0;
|
||||||
for (int i = 1; i <= mprisms.Size(); i++)
|
for (int i = 1; i <= mprisms.Size(); i++)
|
||||||
@ -1772,9 +1769,9 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename HASHTABLE_CUTEDGES>
|
||||||
bool MarkHangingTris (T_MTRIS & mtris,
|
bool MarkHangingTris (T_MTRIS & mtris,
|
||||||
const INDEX_2_CLOSED_HASHTABLE<PointIndex> & cutedges,
|
const HASHTABLE_CUTEDGES & cutedges,
|
||||||
NgTaskManager tm)
|
NgTaskManager tm)
|
||||||
{
|
{
|
||||||
bool hanging = false;
|
bool hanging = false;
|
||||||
@ -1811,9 +1808,9 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename HASHTABLE_CUTEDGES>
|
||||||
int MarkHangingQuads (T_MQUADS & mquads,
|
int MarkHangingQuads (T_MQUADS & mquads,
|
||||||
const INDEX_2_CLOSED_HASHTABLE<PointIndex> & cutedges)
|
const HASHTABLE_CUTEDGES & cutedges)
|
||||||
{
|
{
|
||||||
int hanging = 0;
|
int hanging = 0;
|
||||||
for (int i = 1; i <= mquads.Size(); i++)
|
for (int i = 1; i <= mquads.Size(); i++)
|
||||||
@ -2050,8 +2047,8 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
// INDEX_2_HASHTABLE<int> edgenumber(np);
|
// INDEX_2_HASHTABLE<int> edgenumber(np);
|
||||||
INDEX_2_CLOSED_HASHTABLE<int> edgenumber(9*ne+4*nse);
|
// INDEX_2_CLOSED_HASHTABLE<int> edgenumber(9*ne+4*nse);
|
||||||
|
ClosedHashTable<INDEX_2, int> edgenumber(9*ne+4*nse);
|
||||||
BTSortEdges (mesh, idmaps, edgenumber);
|
BTSortEdges (mesh, idmaps, edgenumber);
|
||||||
|
|
||||||
|
|
||||||
@ -2908,7 +2905,8 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
// INDEX_2_HASHTABLE<int> cutedges(10 + 5 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size()));
|
// INDEX_2_HASHTABLE<int> cutedges(10 + 5 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size()));
|
||||||
INDEX_2_CLOSED_HASHTABLE<PointIndex> cutedges(10 + 9 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size()));
|
// INDEX_2_CLOSED_HASHTABLE<PointIndex> cutedges(10 + 9 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size()));
|
||||||
|
ClosedHashTable<INDEX_2, PointIndex> cutedges(10 + 9 * (mtets.Size()+mprisms.Size()+mtris.Size()+mquads.Size()));
|
||||||
|
|
||||||
bool noprojection = false;
|
bool noprojection = false;
|
||||||
NgProfiler::StopTimer (timer1a);
|
NgProfiler::StopTimer (timer1a);
|
||||||
@ -3898,6 +3896,7 @@ namespace netgen
|
|||||||
|
|
||||||
{
|
{
|
||||||
static Timer t("update mlbetween"); RegionTimer reg(t);
|
static Timer t("update mlbetween"); RegionTimer reg(t);
|
||||||
|
/*
|
||||||
for (int i = 0; i < cutedges.Size(); i++)
|
for (int i = 0; i < cutedges.Size(); i++)
|
||||||
if (cutedges.UsedPos0(i))
|
if (cutedges.UsedPos0(i))
|
||||||
{
|
{
|
||||||
@ -3907,7 +3906,15 @@ namespace netgen
|
|||||||
isnewpoint.SetBit(newpi);
|
isnewpoint.SetBit(newpi);
|
||||||
mesh.mlbetweennodes[newpi] = edge;
|
mesh.mlbetweennodes[newpi] = edge;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
for (auto [edge,newpi] : cutedges)
|
||||||
|
{
|
||||||
|
isnewpoint.SetBit(newpi);
|
||||||
|
mesh.mlbetweennodes[newpi] = edge;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
mesh.PrintMemInfo (cout);
|
mesh.PrintMemInfo (cout);
|
||||||
cout << "tets ";
|
cout << "tets ";
|
||||||
@ -4007,6 +4014,8 @@ namespace netgen
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
for (int j = 0; j < cutedges.Size(); j++)
|
for (int j = 0; j < cutedges.Size(); j++)
|
||||||
if (cutedges.UsedPos0(j))
|
if (cutedges.UsedPos0(j))
|
||||||
{
|
{
|
||||||
@ -4022,6 +4031,18 @@ namespace netgen
|
|||||||
mesh.GetIdentifications().Add (newpi, onewpi, i);
|
mesh.GetIdentifications().Add (newpi, onewpi, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
for (auto [i2, newpi] : cutedges)
|
||||||
|
{
|
||||||
|
PointIndices<2> oi2(identmap[i2[0]],
|
||||||
|
identmap[i2[1]]);
|
||||||
|
oi2.Sort();
|
||||||
|
if (cutedges.Used (oi2))
|
||||||
|
{
|
||||||
|
PointIndex onewpi = cutedges.Get(oi2);
|
||||||
|
mesh.GetIdentifications().Add (newpi, onewpi, i);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
(*opt.tracer)("Bisect", true);
|
(*opt.tracer)("Bisect", true);
|
||||||
|
Loading…
Reference in New Issue
Block a user