Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JSchoeberl committed Dec 15, 2024
1 parent b560719 commit 8f73a00
Show file tree
Hide file tree
Showing 17 changed files with 164 additions and 141 deletions.
67 changes: 36 additions & 31 deletions libsrc/meshing/adfront3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,13 @@ void AdFront3 :: DeleteFace (INDEX fi)
{
nff--;

/*
for (int i = 1; i <= faces.Get(fi).Face().GetNP(); i++)
{
PointIndex pi = faces.Get(fi).Face().PNum(i);
*/
for (PointIndex pi : faces.Get(fi).Face().PNums())
{
points[pi].RemoveFace();
if (!points[pi].Valid())
delpointl.Append (pi);
Expand Down Expand Up @@ -397,16 +401,10 @@ void AdFront3 :: RebuildInternalTables ()



int negvol = 0;
/*
for (int i = PointIndex::BASE;
i < clvol.Size()+PointIndex::BASE; i++)
*/
bool negvol = false;
for (auto i : clvol.Range())
{
if (clvol[i] < 0)
negvol = 1;
}
if (clvol[i] < 0)
negvol = true;

if (negvol)
{
Expand All @@ -427,8 +425,6 @@ void AdFront3 :: RebuildInternalTables ()

int AdFront3 :: SelectBaseElement ()
{
int i, hi, fstind;

/*
static int minval = -1;
static int lasti = 0;
Expand All @@ -453,12 +449,12 @@ int AdFront3 :: SelectBaseElement ()
}
*/

fstind = 0;
int fstind = 0;

for (i = lasti+1; i <= faces.Size() && !fstind; i++)
for (int i = lasti+1; i <= faces.Size() && !fstind; i++)
if (faces.Elem(i).Valid())
{
hi = faces.Get(i).QualClass() +
int hi = faces.Get(i).QualClass() +
points[faces.Get(i).Face().PNum(1)].FrontNr() +
points[faces.Get(i).Face().PNum(2)].FrontNr() +
points[faces.Get(i).Face().PNum(3)].FrontNr();
Expand All @@ -474,10 +470,10 @@ int AdFront3 :: SelectBaseElement ()
if (!fstind)
{
minval = INT_MAX;
for (i = 1; i <= faces.Size(); i++)
for (int i = 1; i <= faces.Size(); i++)
if (faces.Elem(i).Valid())
{
hi = faces.Get(i).QualClass() +
int hi = faces.Get(i).QualClass() +
points[faces.Get(i).Face().PNum(1)].FrontNr() +
points[faces.Get(i).Face().PNum(2)].FrontNr() +
points[faces.Get(i).Face().PNum(3)].FrontNr();
Expand All @@ -499,9 +495,9 @@ int AdFront3 :: SelectBaseElement ()

int AdFront3 :: GetLocals (int fstind,
Array<Point3d, PointIndex> & locpoints,
NgArray<MiniElement2d> & locfaces, // local index
Array<MiniElement2d> & locfaces, // local index
Array<PointIndex, PointIndex> & pindex,
NgArray<INDEX> & findex,
Array<INDEX> & findex,
INDEX_2_HASHTABLE<int> & getconnectedpairs,
float xh,
float relh,
Expand All @@ -518,7 +514,7 @@ int AdFront3 :: GetLocals (int fstind,
hashcreated=1;
}

INDEX i, j;
INDEX i;
PointIndex pstind;
Point3d midp, p0;

Expand Down Expand Up @@ -599,28 +595,37 @@ int AdFront3 :: GetLocals (int fstind,


invpindex.SetSize (points.Size());
/*
for (i = 1; i <= locfaces.Size(); i++)
for (j = 1; j <= locfaces.Get(i).GetNP(); j++)
{
PointIndex pi = locfaces.Get(i).PNum(j);
invpindex[pi] = PointIndex::INVALID;
}
*/
for (auto & f : locfaces)
for (int j = 1; j <= f.GetNP(); j++)
{
PointIndex pi = f.PNum(j);
invpindex[pi] = PointIndex::INVALID;
}

for (i = 1; i <= locfaces.Size(); i++)
// for (i = 1; i <= locfaces.Size(); i++)
for (auto & f : locfaces)
{
for (j = 1; j <= locfaces.Get(i).GetNP(); j++)
// for (j = 1; j <= locfaces.Get(i).GetNP(); j++)
for (int j = 1; j <= f.GetNP(); j++)
{
PointIndex pi = locfaces.Get(i).PNum(j);
// PointIndex pi = locfaces.Get(i).PNum(j);
PointIndex pi = f.PNum(j);
if (!invpindex[pi].IsValid())
{
pindex.Append (pi);
locpoints.Append (points[pi].P());
invpindex[pi] = pindex.Size()-1+IndexBASE<PointIndex>();
}
// locfaces.Elem(i).PNum(j) = locpoints.Append (points[pi].P());
// }
// else
locfaces.Elem(i).PNum(j) = invpindex[pi];
// locfaces.Elem(i).PNum(j) = invpindex[pi];
f.PNum(j) = invpindex[pi];
}
}

Expand Down Expand Up @@ -675,10 +680,10 @@ int AdFront3 :: GetLocals (int fstind,

// returns all points connected with fi
void AdFront3 :: GetGroup (int fi,
NgArray<MeshPoint, PointIndex::BASE> & grouppoints,
NgArray<MiniElement2d> & groupelements,
Array<MeshPoint, PointIndex> & grouppoints,
Array<MiniElement2d> & groupelements,
Array<PointIndex, PointIndex> & pindex,
NgArray<INDEX> & findex)
Array<INDEX> & findex)
{
// static NgArray<char> pingroup;
int changed;
Expand Down Expand Up @@ -796,8 +801,8 @@ void AdFront3 :: SetStartFront (int /* baseelnp */)
*/
}

bool AdFront3 :: PointInsideGroup(const Array<PointIndex, PointIndex> &grouppindex,
const NgArray<MiniElement2d> &groupfaces) const
bool AdFront3 :: PointInsideGroup(const Array<PointIndex, PointIndex> &grouppindex,
const Array<MiniElement2d> &groupfaces) const
{
for(auto pi : Range(points))
{
Expand Down
23 changes: 12 additions & 11 deletions libsrc/meshing/adfront3.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ class MiniElement2d
const PointIndex PNum (int i) const { return pnum[i-1]; }
PointIndex & PNum (int i) { return pnum[i-1]; }
const PointIndex PNumMod (int i) const { return pnum[(i-1)%np]; }
auto PNums() const { return NgFlatArray<const PointIndex> (np, &pnum[0]); }
auto PNums() { return FlatArray<PointIndex> (np, &pnum[0]); }
auto PNums() const { return FlatArray<const PointIndex> (np, &pnum[0]); }
void Delete () { deleted = true; for (PointIndex & p : pnum) p.Invalidate(); }
bool IsDeleted () const { return deleted; }
};
Expand Down Expand Up @@ -238,9 +239,9 @@ class AdFront3
///
int GetNF() const
{ return nff; }
///
/// 1-based
const MiniElement2d & GetFace (int i) const
{ return faces.Get(i).Face(); }
{ return faces[i-1].Face(); }
const auto & Faces() const { return faces; }
///
void Print () const;
Expand All @@ -265,28 +266,28 @@ class AdFront3
NgArray<int> & ifaces) const;

bool PointInsideGroup(const Array<PointIndex, PointIndex> &grouppindex,
const NgArray<MiniElement2d>& groupfaces) const;
const Array<MiniElement2d>& groupfaces) const;

///
void GetFaceBoundingBox (int i, Box3d & box) const;

///
int GetLocals (int baseelement,
Array<Point3d, PointIndex> & locpoints,
NgArray<MiniElement2d> & locfaces, // local index
Array<MiniElement2d> & locfaces, // local index
Array<PointIndex, PointIndex> & pindex,
NgArray<INDEX> & findex,
Array<INDEX> & findex,
INDEX_2_HASHTABLE<int> & connectedpairs,
float xh,
float relh,
INDEX& facesplit);

///
void GetGroup (int fi,
NgArray<MeshPoint, PointIndex::BASE> & grouppoints,
NgArray<MiniElement2d> & groupelements,
Array<MeshPoint, PointIndex> & grouppoints,
Array<MiniElement2d> & groupelements,
Array<PointIndex, PointIndex> & pindex,
NgArray<INDEX> & findex);
Array<INDEX> & findex);

///
void DeleteFace (INDEX fi);
Expand All @@ -298,11 +299,11 @@ class AdFront3
INDEX AddConnectedPair (PointIndices<2> pair);
///
void IncrementClass (INDEX fi)
{ faces.Elem(fi).IncrementQualClass(); }
{ faces[fi-1].IncrementQualClass(); }

///
void ResetClass (INDEX fi)
{ faces.Elem(fi).ResetQualClass(); }
{ faces[fi-1].ResetQualClass(); }

///
void SetStartFront (int baseelnp = 0);
Expand Down
17 changes: 9 additions & 8 deletions libsrc/meshing/bisect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,12 +527,12 @@ namespace netgen
{
PointIndices<2> e1(el2d[i], el2d[(i+1) % el2d.GetNP()]);
e1.Sort();
INDEX_2 e2;
PointIndices<2> e2;

for(k = 0; k < idmaps.Size(); k++)
{
e2.I1() = (*idmaps[k])[e1.I1()];
e2.I2() = (*idmaps[k])[e1.I2()];
e2[0] = (*idmaps[k])[e1[0]];
e2[1] = (*idmaps[k])[e1[1]];

if(e2.I1() == 0 || e2.I2() == 0 ||
e1.I1() == e2.I1() || e1.I2() == e2.I2())
Expand Down Expand Up @@ -985,7 +985,7 @@ namespace netgen
if(j == 0 || mi.pnums[j+mi.np] < min2)
min2 = mi.pnums[j+mi.np];

identified = (mi.pnums[j+mi.np] != 0 && mi.pnums[j+mi.np] != mi.pnums[j]);
identified = (mi.pnums[j+mi.np].IsValid() && mi.pnums[j+mi.np] != mi.pnums[j]);
}

identified = identified && (min1 < min2);
Expand Down Expand Up @@ -1929,13 +1929,14 @@ namespace netgen

ist >> size;
mtets.SetSize(size);
constexpr auto PI0 = IndexBASE<PointIndex>();
for(int i=0; i<size; i++)
{
ist >> mtets[i];
if(mtets[i].pnums[0] > mesh.GetNV() ||
mtets[i].pnums[1] > mesh.GetNV() ||
mtets[i].pnums[2] > mesh.GetNV() ||
mtets[i].pnums[3] > mesh.GetNV())
if(mtets[i].pnums[0] >= PI0+mesh.GetNV() ||
mtets[i].pnums[1] >= PI0+mesh.GetNV() ||
mtets[i].pnums[2] >= PI0+mesh.GetNV() ||
mtets[i].pnums[3] >= PI0+mesh.GetNV())
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions libsrc/meshing/boundarylayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ namespace netgen
auto & seg = mesh[segi];
if(seg.edgenr != edgenr+1)
continue;
PointIndex other = seg[0]+seg[1]-pi;
PointIndex other = seg[0]-pi+seg[1];
if(!pts.Contains(other))
pts.Append(other);
}
Expand Down Expand Up @@ -1353,7 +1353,8 @@ namespace netgen
nel[1] = p2;
nel[2] = p3;
nel[3] = p4;
nel[4] = el[0] + el[1] + el[2] + el[3] - fixed[0] - moved[0] - moved[1];
// nel[4] = el[0] + el[1] + el[2] + el[3] - fixed[0] - moved[0] - moved[1];
nel[4] = el[0]-fixed[0] + el[1]-moved[0] + el[2]-moved[1] + el[3];
if(Cross(mesh[p2]-mesh[p1], mesh[p4]-mesh[p1]) * (mesh[nel[4]]-mesh[nel[1]]) > 0)
Swap(nel[1], nel[3]);
nel.SetIndex(el.GetIndex());
Expand Down Expand Up @@ -1399,7 +1400,8 @@ namespace netgen
nel[1] = p2;
nel[2] = p3;
nel[3] = p4;
nel[4] = el[0] + el[1] + el[2] + el[3] + el[4] - fixed[0] - fixed[1] - moved[0] - moved[1];
// nel[4] = el[0] + el[1] + el[2] + el[3] + el[4] - fixed[0] - fixed[1] - moved[0] - moved[1];
nel[4] = el[0]-fixed[0] + el[1]-fixed[1] + el[2]-moved[0] + el[3]-moved[1] + el[4];
if(Cross(mesh[p2] - mesh[p1], mesh[p4]-mesh[p1]) * (mesh[nel[4]]-mesh[nel[1]]) > 0)
Swap(nel[1], nel[3]);
nel.SetIndex(el.GetIndex());
Expand Down
3 changes: 2 additions & 1 deletion libsrc/meshing/classifyhpel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ HPREF_ELEMENT_TYPE ClassifyTet(HPRefElement & el, INDEX_2_HASHTABLE<int> & edges
HPREF_ELEMENT_TYPE type = HP_NONE;

int debug = 0;
/*
for (int j = 0;j < 4; j++)
{
if (el.pnums[j] == 444) debug++;
Expand All @@ -18,7 +19,7 @@ HPREF_ELEMENT_TYPE ClassifyTet(HPRefElement & el, INDEX_2_HASHTABLE<int> & edges
if (el.pnums[j] == 281) debug++;
}
if (debug < 4) debug = 0;

*/

// *testout << "new el" << endl;

Expand Down
Loading

0 comments on commit 8f73a00

Please sign in to comment.