preparations to switch T_POINTS to ngcore::Array

This commit is contained in:
Joachim Schöberl 2019-08-09 15:30:58 +02:00
parent c900e0380b
commit 9118ddc63a
17 changed files with 143 additions and 73 deletions

View File

@ -201,16 +201,21 @@ namespace ngcore
NETGEN_INLINE operator T* () const { return data; }
};
template <class T> class FlatArray;
template <typename T>
constexpr size_t IndexBASE () { return 0; }
template <class T, class IndexType = size_t> class FlatArray;
template <typename TELEM, typename TSIZE>
template <typename TELEM, typename IndexType>
class ArrayIterator
{
FlatArray<TELEM> ar;
TSIZE ind;
FlatArray<TELEM, IndexType> ar;
IndexType ind;
public:
NETGEN_INLINE ArrayIterator (FlatArray<TELEM> aar, TSIZE ai)
NETGEN_INLINE ArrayIterator (FlatArray<TELEM, IndexType> aar, IndexType ai)
: ar(aar), ind(ai) { ; }
NETGEN_INLINE ArrayIterator operator++ (int)
{ return ArrayIterator(ar, ind++); }
@ -381,23 +386,24 @@ namespace ngcore
Helper functions for printing.
Optional range check by macro NETGEN_CHECK_RANGE
*/
template <class T>
class FlatArray : public BaseArrayObject<FlatArray<T> >
template <class T, class IndexType>
class FlatArray : public BaseArrayObject<FlatArray<T,IndexType> >
{
protected:
static constexpr size_t BASE = IndexBASE<IndexType>();
/// the size
size_t size;
/// the data
T * __restrict data;
public:
using BaseArrayObject<FlatArray<T> >::ILLEGAL_POSITION;
using BaseArrayObject<FlatArray>::ILLEGAL_POSITION;
/// initialize array
NETGEN_INLINE FlatArray () = default;
// { ; } // size = 0; data = 0; }
/// copy constructor allows size-type conversion
NETGEN_INLINE FlatArray (const FlatArray<T> & a2) = default;
NETGEN_INLINE FlatArray (const FlatArray & a2) = default;
// : size(a2.Size()), data(a2.data) { ; }
/// provide size and memory
@ -473,10 +479,10 @@ namespace ngcore
}
/// Access array. range check by macro NETGEN_CHECK_RANGE
NETGEN_INLINE T & operator[] (size_t i) const
NETGEN_INLINE T & operator[] (IndexType i) const
{
NETGEN_CHECK_RANGE(i,0,size);
return data[i];
return data[i-BASE];
}
NETGEN_INLINE T_Range<size_t> Range () const
@ -552,10 +558,8 @@ namespace ngcore
return Pos(elem) != ILLEGAL_POSITION;
}
ArrayIterator<T, size_t> begin() const
{ return ArrayIterator<T,size_t> (*this, 0); }
ArrayIterator<T, size_t> end() const
{ return ArrayIterator<T,size_t> (*this, size); }
auto begin() const { return ArrayIterator<T,IndexType> (*this, BASE); }
auto end() const { return ArrayIterator<T,IndexType> (*this, size+BASE); }
};
template <typename T>
@ -591,8 +595,8 @@ namespace ngcore
Either the container takes care of memory allocation and deallocation,
or the user provides one block of data.
*/
template <class T>
class Array : public FlatArray<T>
template <class T, class IndexType = size_t>
class Array : public FlatArray<T, IndexType>
{
protected:
/// physical size of array
@ -600,20 +604,20 @@ namespace ngcore
/// that's the data we have to delete, nullptr for not owning the memory
T * mem_to_delete;
using FlatArray<T>::size;
using FlatArray<T>::data;
using FlatArray<T,IndexType>::size;
using FlatArray<T,IndexType>::data;
public:
/// Generate array of logical and physical size asize
NETGEN_INLINE explicit Array()
: FlatArray<T> (0, nullptr)
: FlatArray<T,IndexType> (0, nullptr)
{
allocsize = 0;
mem_to_delete = nullptr;
}
NETGEN_INLINE explicit Array(size_t asize)
: FlatArray<T> (asize, new T[asize])
: FlatArray<T,IndexType> (asize, new T[asize])
{
allocsize = asize;
mem_to_delete = data;
@ -654,19 +658,19 @@ namespace ngcore
/// array copy
NETGEN_INLINE explicit Array (const Array & a2)
: FlatArray<T> (a2.Size(), a2.Size() ? new T[a2.Size()] : nullptr)
: FlatArray<T,IndexType> (a2.Size(), a2.Size() ? new T[a2.Size()] : nullptr)
{
allocsize = size;
mem_to_delete = data;
for (size_t i = 0; i < size; i++)
data[i] = a2[i];
data[i] = a2.data[i];
}
template <typename TA>
explicit Array (const BaseArrayObject<TA> & a2)
: FlatArray<T> (a2.Size(),
a2.Size() ? new T[a2.Size()] : nullptr)
: FlatArray<T,IndexType> (a2.Size(),
a2.Size() ? new T[a2.Size()] : nullptr)
{
allocsize = size;
mem_to_delete = data;
@ -976,8 +980,8 @@ namespace ngcore
/// resize array, at least to size minsize. copy contents
template <class T>
NETGEN_INLINE void Array<T> :: ReSize (size_t minsize)
template <class T, class IndexType>
NETGEN_INLINE void Array<T, IndexType> :: ReSize (size_t minsize)
{
size_t nsize = 2 * allocsize;
if (nsize < minsize) nsize = minsize;

View File

@ -96,10 +96,15 @@ namespace netgen
ArrayIterator<T,BASE,TIND> end() const
{ return ArrayIterator<T,BASE,TIND> (*this, BASE+size); }
TIND Begin() const { return TIND(BASE); }
TIND End() const { return TIND(size+BASE); }
// TIND Begin() const { return TIND(BASE); }
// TIND End() const { return TIND(size+BASE); }
T_Range<TIND> Range() const { return T_Range<TIND>(BASE, size+BASE); }
[[deprecated("Use *Range().begin() instead")]]
auto Begin() const { return *Range().begin(); }
[[deprecated("Use *Range().end() instead")]]
auto End() const { return *Range().end(); }
/// Access array. BASE-based
T & operator[] (TIND i) const
{
@ -205,13 +210,13 @@ namespace netgen
template <typename T, int BASE, typename TIND>
inline ostream & operator<< (ostream & s, const NgFlatArray<T,BASE,TIND> & a)
{
for (TIND i = a.Begin(); i < a.End(); i++)
// for (TIND i = a.Begin(); i < a.End(); i++)
for (auto i : a.Range())
s << i << ": " << a[i] << endl;
return s;
}
/**
Dynamic array container.
@ -530,6 +535,9 @@ namespace netgen
int End() const { return ia.End(); }
const typename TA1::TELEM & operator[] (int i) const { return array[ia[i]]; }
auto Range() const { return ia.Range(); }
auto begin() const { return ia.begin(); }
auto end() const { return ia.end(); }
};

View File

@ -38,7 +38,8 @@ template <class T>
inline void BubbleSort (NgArray<T> & data)
{
if(data.Size() > 0)
BubbleSort (data.Size(), &data[data.Begin()]);
// BubbleSort (data.Size(), &data[data.Begin()]);
BubbleSort (data.Size(), &data[*data.Range().begin()]);
}
}

View File

@ -286,7 +286,8 @@ namespace netgen
template <typename T1, typename T2>
void Add (const IndirectArray<T1, T2> & points)
{
for (int i = points.Begin(); i < points.End(); i++)
// for (int i = points.Begin(); i < points.End(); i++)
for (int i : points.Range())
Add (points[i]);
}

View File

@ -494,7 +494,8 @@ namespace netgen
}
for(PointIndex i = mesh.Points().Begin(); i < mesh.Points().End(); i++)
// for(PointIndex i = mesh.Points().Begin(); i < mesh.Points().End(); i++)
for(PointIndex i : mesh.Points().Range())
{
if(nodenum[i] == -1)
continue;
@ -1063,7 +1064,8 @@ namespace netgen
for(int i=0; i<groups.Size(); i++)
groups[i]->SetSize(0);
for(PointIndex i = mesh.Points().Begin(); i < mesh.Points().End(); i++)
// for(PointIndex i = mesh.Points().Begin(); i < mesh.Points().End(); i++)
for(PointIndex i : mesh.Points().Range())
{
if(i-PointIndex::BASE < point_ids.Size())
{

View File

@ -39,7 +39,8 @@ namespace netgen
allflines = 0;
minval = 0;
starti = lines.Begin();
// starti = lines.Begin();
starti = *lines.Range().begin();
}
AdFront2 :: ~AdFront2 ()
@ -53,7 +54,8 @@ namespace netgen
if (nfl > 0)
{
ost << nfl << " open front segments left:" << endl;
for (int i = lines.Begin(); i < lines.End(); i++)
// for (int i = lines.Begin(); i < lines.End(); i++)
for (int i : lines.Range())
if (lines[i].Valid())
ost << i << ": "
<< GetGlobalIndex (lines[i].L().I1()) << "-"
@ -219,8 +221,9 @@ namespace netgen
int & qualclass)
{
int baselineindex = -1;
for (int i = starti; i < lines.End(); i++)
// for (int i = starti; i < lines.End(); i++)
for (int i = starti; i < *lines.Range().end(); i++)
{
if (lines[i].Valid())
{
@ -240,7 +243,8 @@ namespace netgen
if (baselineindex == -1)
{
minval = INT_MAX;
for (int i = lines.Begin(); i < lines.End(); i++)
// for (int i = lines.Begin(); i < lines.End(); i++)
for (int i : lines.Range())
if (lines[i].Valid())
{
int hi = lines[i].LineClass() +
@ -432,7 +436,8 @@ namespace netgen
void AdFront2 :: SetStartFront ()
{
for (int i = lines.Begin(); i < lines.End(); i++)
// for (int i = lines.Begin(); i < lines.End(); i++)
for (int i : lines.Range())
if (lines[i].Valid())
for (int j = 1; j <= 2; j++)
points[lines[i].L().I(j)].DecFrontNr(0);
@ -442,12 +447,14 @@ namespace netgen
void AdFront2 :: Print (ostream & ost) const
{
ost << points.Size() << " Points: " << endl;
for (int i = points.Begin(); i < points.End(); i++)
// for (int i = points.Begin(); i < points.End(); i++)
for (int i : points.Range())
if (points[i].Valid())
ost << i << " " << points[i].P() << endl;
ost << nfl << " Lines: " << endl;
for (int i = lines.Begin(); i < lines.End(); i++)
// for (int i = lines.Begin(); i < lines.End(); i++)
for (int i : lines.Range())
if (lines[i].Valid())
ost << lines[i].L().I1() << " - " << lines[i].L().I2() << endl;

View File

@ -86,9 +86,13 @@ AdFront3 :: ~AdFront3 ()
void AdFront3 :: GetPoints (NgArray<Point<3> > & apoints) const
{
/*
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
apoints.Append (points[pi].P());
*/
for (auto & p : points)
apoints.Append(p.P());
}
@ -105,7 +109,8 @@ PointIndex AdFront3 :: AddPoint (const Point<3> & p, PointIndex globind)
else
{
points.Append (FrontPoint3 (p, globind));
return --points.End();
// return --points.End();
return *points.Range().end()-1;
// return points.Size()-1+PointIndex::BASE;
}
}
@ -302,7 +307,8 @@ void AdFront3 :: RebuildInternalTables ()
int np = points.Size();
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
points[pi].cluster = pi;
NgProfiler::StopTimer (timer_a);
@ -395,12 +401,13 @@ void AdFront3 :: RebuildInternalTables ()
if (clvol[i] < 0)
negvol = 1;
}
if (negvol)
{
for (int i = 1; i <= faces.Size(); i++)
faces.Elem(i).cluster = 1;
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
points[pi].cluster = 1;
}

View File

@ -572,10 +572,11 @@ namespace netgen
// Lock all the prism points so that the rest of the mesh can be
// optimised without invalidating the entire mesh
for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++)
{
if(bndnodes.Test(pi)) mesh.AddLockedPoint(pi);
}
// for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++)
for (PointIndex pi : mesh.Points().Range())
{
if(bndnodes.Test(pi)) mesh.AddLockedPoint(pi);
}
// Now, actually pull back the old surface points to create
// the actual boundary layers

View File

@ -188,7 +188,8 @@ namespace netgen
timestamp = NextTimeStamp();
PointIndex pi = points.End();
// PointIndex pi = points.End();
PointIndex pi = *points.Range().end();
points.Append ( MeshPoint (p, layer, type) );
lock.UnLock();
@ -259,7 +260,8 @@ namespace netgen
points[el[i]].SetType(SURFACEPOINT);
}
*/
if (maxn < points.End())
// if (maxn < points.End())
if (maxn < *points.Range().end())
for (PointIndex pi : el.PNums())
if (points[pi].Type() > SURFACEPOINT)
points[pi].SetType(SURFACEPOINT);
@ -719,7 +721,8 @@ namespace netgen
if (cnt_sing)
{
outfile << "singular_points" << endl << cnt_sing << endl;
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
if ((*this)[pi].Singularity()>=1.)
outfile << int(pi) << "\t" << (*this)[pi].Singularity() << endl;
}
@ -1968,8 +1971,9 @@ namespace netgen
struct tval { int index; PointIndex p4; };
INDEX_3_CLOSED_HASHTABLE<tval> faceht(100);
openelements.SetSize(0);
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
if (selsonpoint[pi].Size()+elsonpoint[pi].Size())
{
faceht.SetSize (2 * selsonpoint[pi].Size() + 4 * elsonpoint[pi].Size());
@ -2149,7 +2153,8 @@ namespace netgen
for (int j = 1; j <= 3; j++)
{
PointIndex pi = sel.PNum(j);
if (pi < points.End())
// if (pi < points.End())
if (pi < *points.Range().end())
points[pi].SetType (FIXEDPOINT);
}
}
@ -3159,7 +3164,8 @@ namespace netgen
pmin = Point3d (1e10, 1e10, 1e10);
pmax = Point3d (-1e10, -1e10, -1e10);
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
{
pmin.SetToMin ( (*this) [pi] );
pmax.SetToMax ( (*this) [pi] );
@ -3208,7 +3214,8 @@ namespace netgen
pmin = Point3d (1e10, 1e10, 1e10);
pmax = Point3d (-1e10, -1e10, -1e10);
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
if (points[pi].Type() <= ptyp)
{
pmin.SetToMin ( (*this) [pi] );
@ -3331,10 +3338,11 @@ namespace netgen
*/
// pused.Set();
int npi = PointIndex::BASE-1;
for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi < points.End(); pi++)
for (PointIndex pi : points.Range())
if (pused.Test(pi))
{
npi++;

View File

@ -227,10 +227,18 @@ namespace netgen
auto GetNP () const { return points.Size(); }
// [[deprecated("Use Point(PointIndex) instead of int !")]]
MeshPoint & Point(int i) { return points.Elem(i); }
MeshPoint & Point(int i)
{
// return points.Elem(i);
return Point (PointIndex(i+PointIndex::BASE-1));
}
MeshPoint & Point(PointIndex pi) { return points[pi]; }
// [[deprecated("Use Point(PointIndex) instead of int !")]]
const MeshPoint & Point(int i) const { return points.Get(i); }
const MeshPoint & Point(int i) const
{
// return points.Get(i);
return Point (PointIndex(i+PointIndex::BASE-1));
}
const MeshPoint & Point(PointIndex pi) const { return points[pi]; }
const MeshPoint & operator[] (PointIndex pi) const { return points[pi]; }

View File

@ -145,7 +145,8 @@ namespace netgen
mpquad.check_impossible = qstep == 1; // for prisms only (air domain in trafo)
for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++)
// for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++)
for (PointIndex pi : mesh3d.Points().Range())
meshing.AddPoint (mesh3d[pi], pi);
/*
@ -241,7 +242,8 @@ namespace netgen
NgArray<int, PointIndex::BASE> glob2loc(mesh3d.GetNP());
glob2loc = -1;
for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++)
// for (PointIndex pi = mesh3d.Points().Begin(); pi < mesh3d.Points().End(); pi++)
for (PointIndex pi : mesh3d.Points().Range())
if (domain_bbox.IsIn (mesh3d[pi]))
glob2loc[pi] =
meshing.AddPoint (mesh3d[pi], pi);

View File

@ -188,6 +188,18 @@ namespace netgen
void DoArchive (Archive & ar) { ar & i; }
};
}
namespace ngcore
{
template<>
constexpr size_t IndexBASE<netgen::PointIndex> () { return netgen::PointIndex::BASE; }
}
namespace netgen
{
inline istream & operator>> (istream & ist, PointIndex & pi)
{
int i; ist >> i; pi = PointIndex(i); return ist;
@ -358,6 +370,7 @@ namespace netgen
typedef NgArray<MeshPoint, PointIndex::BASE, PointIndex> T_POINTS;
// typedef Array<MeshPoint, PointIndex> T_POINTS;

View File

@ -142,7 +142,8 @@ namespace netgen
NgArray<SurfaceElementIndex> locelements(0);
NgArray<int> locrots(0);
for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++)
// for (PointIndex pi = mesh.Points().Begin(); pi < mesh.Points().End(); pi++)
for (PointIndex pi : mesh.Points().Range())
{
if (mesh[pi].Type() != SURFACEPOINT)
continue;

View File

@ -1533,7 +1533,8 @@ void Mesh :: ImproveMeshJacobian (const MeshingParameters & mp,
const char * savetask = multithread.task;
multithread.task = "Smooth Mesh Jacobian";
for (PointIndex pi = points.Begin(); i < points.End(); pi++)
// for (PointIndex pi = points.Begin(); i < points.End(); pi++)
for (PointIndex pi : points.Range())
{
if ((*this)[pi].Type() != INNERPOINT)
continue;
@ -1687,7 +1688,8 @@ void Mesh :: ImproveMeshJacobianOnSurface (const MeshingParameters & mp,
const char * savetask = multithread.task;
multithread.task = "Smooth Mesh Jacobian";
for (PointIndex pi = points.Begin(); pi <= points.End(); pi++)
// for (PointIndex pi = points.Begin(); pi <= points.End(); pi++)
for (PointIndex pi : points.Range())
if ( usepoint.Test(i) )
{
//(*testout) << "improvejac, p = " << i << endl;

View File

@ -521,13 +521,15 @@ namespace netgen
// ensure all coarse grid and intermediate level edges
cnt = 0;
for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
// for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
for (int i : mesh->mlbetweennodes.Range())
{
INDEX_2 parents = Sort (mesh->mlbetweennodes[i]);
if (parents[0] >= PointIndex::BASE) cnt[parents[0]]++;
}
TABLE<int,PointIndex::BASE> vert2vertcoarse (cnt);
for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
// for (int i = mesh->mlbetweennodes.Begin(); i < mesh->mlbetweennodes.End(); i++)
for (int i : mesh->mlbetweennodes.Range())
{
INDEX_2 parents = Sort (mesh->mlbetweennodes[i]);
if (parents[0] >= PointIndex::BASE) vert2vertcoarse.AddSave (parents[0], parents[1]);

View File

@ -346,7 +346,8 @@ namespace netgen
(*testout) << "different vertices = " << mesh.GetNP() << endl;
// int first_ep = mesh.GetNP()+1;
PointIndex first_ep = mesh.Points().End();
// PointIndex first_ep = mesh.Points().End();
PointIndex first_ep = *mesh.Points().Range().end();
auto vertexrange = mesh.Points().Range();
NgArray<int> face2solid[2];
@ -500,7 +501,8 @@ namespace netgen
bool exists = 0;
tsearch.Start();
for (PointIndex j = first_ep; j < mesh.Points().End(); j++)
// for (PointIndex j = first_ep; j < mesh.Points().End(); j++)
for (PointIndex j = first_ep; j < *mesh.Points().Range().end(); j++)
if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)
{
exists = true;

View File

@ -4008,7 +4008,8 @@ namespace netgen
// NgProfiler::StartTimer (timer_vals);
NgArray<double,PointIndex::BASE> vertval(mesh->GetNP());
NgArray<bool,PointIndex::BASE> posval(mesh->GetNP());
for (PointIndex pi = vertval.Begin(); pi < vertval.End(); pi++)
// for (PointIndex pi = vertval.Begin(); pi < vertval.End(); pi++)
for (PointIndex pi : vertval.Range())
{
Point<3> vert = (*mesh)[pi];
vertval[pi] =