polishing improve2, IndirectArray iterator + element access

This commit is contained in:
Joachim Schöberl 2019-08-18 12:20:43 +02:00
parent a51292bcf6
commit e89550ec9c
3 changed files with 55 additions and 44 deletions

View File

@ -228,8 +228,10 @@ namespace ngcore
{ return ArrayIterator(ar, ind++); }
NETGEN_INLINE ArrayIterator operator++ ()
{ return ArrayIterator(ar, ++ind); }
NETGEN_INLINE TELEM operator*() const { return ar[ind]; }
NETGEN_INLINE TELEM & operator*() { return ar[ind]; }
// NETGEN_INLINE const TELEM & operator*() const { return ar[ind]; }
// NETGEN_INLINE TELEM & operator*() { return ar[ind]; }
NETGEN_INLINE auto operator*() const -> decltype(ar[ind]) { return ar[ind]; }
NETGEN_INLINE auto operator*() -> decltype(ar[ind]) { return ar[ind]; }
NETGEN_INLINE bool operator != (ArrayIterator d2) { return ind != d2.ind; }
NETGEN_INLINE bool operator == (ArrayIterator d2) { return ind == d2.ind; }
};
@ -366,8 +368,8 @@ namespace ngcore
: ba(aba), ia(aia) { ; }
NETGEN_INLINE size_t Size() const { return ia.Size(); }
NETGEN_INLINE T operator[] (size_t i) const { return ba[ia[i]]; }
NETGEN_INLINE T & operator[] (size_t i) { return ba[ia[i]]; }
NETGEN_INLINE T & operator[] (size_t i) const { return ba[ia[i]]; }
// NETGEN_INLINE T & operator[] (size_t i) { return ba[ia[i]]; }
NETGEN_INLINE IndirectArray operator= (const T & val)
{
@ -384,6 +386,8 @@ namespace ngcore
return IndirectArray (ba, ia);
}
NETGEN_INLINE AOWrapperIterator<IndirectArray> begin() const { return { *this, 0 }; }
NETGEN_INLINE AOWrapperIterator<IndirectArray> end() const { return { *this, Size() }; }
};

View File

@ -94,11 +94,11 @@ namespace netgen
int surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr();
NgArray<Neighbour> neighbors(mesh.GetNSE());
Array<Neighbour> neighbors(mesh.GetNSE());
INDEX_2_HASHTABLE<trionedge> other(seia.Size() + 2);
NgArray<bool> swapped(mesh.GetNSE());
Array<bool> swapped(mesh.GetNSE());
NgArray<int,PointIndex::BASE> pdef(mesh.GetNP());
NgArray<double,PointIndex::BASE> pangle(mesh.GetNP());
@ -153,21 +153,25 @@ namespace netgen
}
}
/*
for (int i = 0; i < seia.Size(); i++)
{
const Element2d & sel = mesh[seia[i]];
for (int j = 0; j < 3; j++)
pdef[sel[j]]++;
}
for (int i = 0; i < seia.Size(); i++)
{
for (int j = 0; j < 3; j++)
{
neighbors[seia[i]].SetNr (j, -1);
neighbors[seia[i]].SetOrientation (j, 0);
}
}
*/
for (SurfaceElementIndex sei : seia)
for (PointIndex pi : mesh[sei].PNums<3>())
pdef[pi]++;
// for (int i = 0; i < seia.Size(); i++)
for (SurfaceElementIndex sei : seia)
for (int j = 0; j < 3; j++)
{
neighbors[sei].SetNr (j, -1);
neighbors[sei].SetOrientation (j, 0);
}
/*
NgArray<Vec3d> normals(mesh.GetNP());
@ -228,9 +232,9 @@ namespace netgen
}
}
for (int i = 0; i < seia.Size(); i++)
swapped[seia[i]] = false;
for (SurfaceElementIndex sei : seia)
swapped[sei] = false;
NgProfiler::StopTimer (timerstart);
@ -466,16 +470,11 @@ namespace netgen
int np = mesh.GetNP();
TABLE<SurfaceElementIndex,PointIndex::BASE> elementsonnode(np);
NgArray<SurfaceElementIndex> hasonepi, hasbothpi;
Array<SurfaceElementIndex> hasonepi, hasbothpi;
for (SurfaceElementIndex sei : seia)
{
// Element2d & el = mesh[sei];
// for (int j = 0; j < el.GetNP(); j++)
// elementsonnode.Add (el[j], sei);
for (PointIndex pi : mesh[sei].PNums())
elementsonnode.Add (pi, sei);
}
for (PointIndex pi : mesh[sei].PNums<3>())
elementsonnode.Add (pi, sei);
Array<bool,PointIndex> fixed(np);
fixed = false;
@ -515,7 +514,7 @@ namespace netgen
fixed[pi] = true;
NgArray<Vec<3>,PointIndex::BASE> normals(np);
Array<Vec<3>,PointIndex> normals(np);
// for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++)
for (PointIndex pi : mesh.Points().Range())
@ -596,21 +595,22 @@ namespace netgen
hasonepi.SetSize(0);
hasbothpi.SetSize(0);
for (int k = 0; k < elementsonnode[pi1].Size(); k++)
// for (int k = 0; k < elementsonnode[pi1].Size(); k++)
for (SurfaceElementIndex sei2 : elementsonnode[pi1])
{
const Element2d & el2 = mesh[elementsonnode[pi1][k]];
const Element2d & el2 = mesh[sei2];
if (el2.IsDeleted()) continue;
if (el2[0] == pi2 || el2[1] == pi2 || el2[2] == pi2)
{
hasbothpi.Append (elementsonnode[pi1][k]);
hasbothpi.Append (sei2);
nv = Cross (Vec3d (mesh[el2[0]], mesh[el2[1]]),
Vec3d (mesh[el2[0]], mesh[el2[2]]));
}
else
{
hasonepi.Append (elementsonnode[pi1][k]);
hasonepi.Append (sei2);
}
}
@ -628,29 +628,32 @@ namespace netgen
// nv = normals.Get(pi1);
for (int k = 0; k < elementsonnode[pi2].Size(); k++)
for (SurfaceElementIndex sei2 : elementsonnode[pi2])
{
const Element2d & el2 = mesh[elementsonnode[pi2][k]];
const Element2d & el2 = mesh[sei2];
if (el2.IsDeleted()) continue;
if (el2[0] == pi1 || el2[1] == pi1 || el2[2] == pi1)
;
else
hasonepi.Append (elementsonnode[pi2][k]);
if (!el2.PNums<3>().Contains (pi1))
hasonepi.Append (sei2);
}
double bad1 = 0;
int illegal1 = 0, illegal2 = 0;
for (int k = 0; k < hasonepi.Size(); k++)
{
const Element2d & el = mesh[hasonepi[k]];
/*
for (SurfaceElementIndex sei : hasonepi)
{
const Element2d & el = mesh[sei];
bad1 += CalcTriangleBadness (mesh[el[0]], mesh[el[1]], mesh[el[2]],
nv, -1, loch);
illegal1 += 1-mesh.LegalTrig(el);
}
*/
for (const Element2d & el : mesh.SurfaceElements()[hasonepi])
{
bad1 += CalcTriangleBadness (mesh[el[0]], mesh[el[1]], mesh[el[2]],
nv, -1, loch);
illegal1 += 1-mesh.LegalTrig(el);
}
for (int k = 0; k < hasbothpi.Size(); k++)
{
const Element2d & el = mesh[hasbothpi[k]];

View File

@ -504,6 +504,8 @@ namespace netgen
auto PNums () const { return FlatArray<const PointIndex> (np, &pnum[0]); }
auto PNums () { return FlatArray<PointIndex> (np, &pnum[0]); }
template <int NP>
auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); }
auto Vertices() const { return FlatArray<const PointIndex> (GetNV(), &pnum[0]); }
auto GeomInfo() const { return FlatArray<const PointGeomInfo> (np, &geominfo[0]); }
@ -796,6 +798,8 @@ namespace netgen
auto PNums () const
{ return FlatArray<const PointIndex> (np, &pnum[0]); }
template <int NP>
auto PNums() const { return FlatArray<const PointIndex> (NP, &pnum[0]); }
FlatArray<const PointIndex> Vertices() const { return { GetNV(), &pnum[0] }; }