more ngcore arrays

This commit is contained in:
Joachim Schoeberl 2024-12-29 17:23:35 +01:00
parent 7afcaf3406
commit fd0421d573
5 changed files with 75 additions and 57 deletions

View File

@ -300,7 +300,7 @@ namespace ngcore
template <int N, typename TI> template <int N, typename TI>
NETGEN_INLINE size_t HashValue2 (const IVec<N,TI> & ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (const IVec<N,TI> & ind, size_t mask)
{ {
IVec<N,size_t> lind = ind; IVec<N,size_t> lind = ind;
size_t sum = 0; size_t sum = 0;
@ -311,14 +311,14 @@ namespace ngcore
/// hash value of 1 int /// hash value of 1 int
template <typename TI> template <typename TI>
NETGEN_INLINE size_t HashValue2 (const IVec<1,TI> & ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (const IVec<1,TI> & ind, size_t mask)
{ {
return ind[0] & mask; return ind[0] & mask;
} }
/// hash value of 2 int /// hash value of 2 int
template <typename TI> template <typename TI>
NETGEN_INLINE size_t HashValue2 (const IVec<2,TI> & ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (const IVec<2,TI> & ind, size_t mask)
{ {
IVec<2,size_t> lind = ind; IVec<2,size_t> lind = ind;
return (113*lind[0]+lind[1]) & mask; return (113*lind[0]+lind[1]) & mask;
@ -326,17 +326,17 @@ namespace ngcore
/// hash value of 3 int /// hash value of 3 int
template <typename TI> template <typename TI>
NETGEN_INLINE size_t HashValue2 (const IVec<3,TI> & ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (const IVec<3,TI> & ind, size_t mask)
{ {
IVec<3,size_t> lind = ind; IVec<3,size_t> lind = ind;
return (113*lind[0]+59*lind[1]+lind[2]) & mask; return (113*lind[0]+59*lind[1]+lind[2]) & mask;
} }
NETGEN_INLINE size_t HashValue2 (size_t ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (size_t ind, size_t mask)
{ {
return ind & mask; return ind & mask;
} }
NETGEN_INLINE size_t HashValue2 (int ind, size_t mask) NETGEN_INLINE constexpr size_t HashValue2 (int ind, size_t mask)
{ {
return size_t(ind) & mask; return size_t(ind) & mask;
} }

View File

@ -31,6 +31,7 @@ Meshing3 :: Meshing3 (const string & rulefilename)
canuse.SetSize (rules.Size()); canuse.SetSize (rules.Size());
ruleused.SetSize (rules.Size()); ruleused.SetSize (rules.Size());
/*
for (int i = 1; i <= rules.Size(); i++) for (int i = 1; i <= rules.Size(); i++)
{ {
problems.Elem(i) = new char[255]; problems.Elem(i) = new char[255];
@ -38,6 +39,11 @@ Meshing3 :: Meshing3 (const string & rulefilename)
canuse.Elem(i) = 0; canuse.Elem(i) = 0;
ruleused.Elem(i) = 0; ruleused.Elem(i) = 0;
} }
*/
foundmap = 0;
canuse = 0;
ruleused = 0;
} }
@ -53,6 +59,7 @@ Meshing3 :: Meshing3 (const char ** rulep)
canuse.SetSize (rules.Size()); canuse.SetSize (rules.Size());
ruleused.SetSize (rules.Size()); ruleused.SetSize (rules.Size());
/*
for (int i = 0; i < rules.Size(); i++) for (int i = 0; i < rules.Size(); i++)
{ {
problems[i] = new char[255]; problems[i] = new char[255];
@ -60,16 +67,22 @@ Meshing3 :: Meshing3 (const char ** rulep)
canuse[i] = 0; canuse[i] = 0;
ruleused[i] = 0; ruleused[i] = 0;
} }
*/
foundmap = 0;
canuse = 0;
ruleused = 0;
} }
Meshing3 :: ~Meshing3 () Meshing3 :: ~Meshing3 ()
{ {
// delete adfront; // delete adfront;
/*
for (int i = 0; i < rules.Size(); i++) for (int i = 0; i < rules.Size(); i++)
{ {
delete [] problems[i]; delete [] problems[i];
delete rules[i]; delete rules[i];
} }
*/
} }
@ -184,12 +197,13 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
Array<Point3d, PointIndex> locpoints; // local points Array<Point3d, PointIndex> locpoints; // local points
Array<MiniElement2d> locfaces; // local faces Array<MiniElement2d> locfaces; // local faces
Array<PointIndex, PointIndex> pindex; // mapping from local to front point numbering Array<PointIndex, PointIndex> pindex; // mapping from local to front point numbering
Array<int, PointIndex> allowpoint; // point is allowed ? Array<int, PointIndex> allowpoint; // point is allowed (0/1/2) ?
Array<INDEX> findex; // mapping from local to front face numbering Array<INDEX> findex; // mapping from local to front face numbering
//INDEX_2_HASHTABLE<int> connectedpairs(100); // connecgted pairs for prism meshing //INDEX_2_HASHTABLE<int> connectedpairs(100); // connecgted pairs for prism meshing
Array<Point3d, PointIndex> plainpoints; // points in reference coordinates Array<Point3d, PointIndex> plainpoints; // points in reference coordinates
NgArray<int> delpoints, delfaces; // points and lines to be deleted // NgArray<int> delpoints; // points to be deleted
NgArray<int> delfaces; // lines to be deleted
NgArray<Element> locelements; // new generated elements NgArray<Element> locelements; // new generated elements
int j, oldnp, oldnf; int j, oldnp, oldnf;
@ -378,9 +392,9 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
{ {
(*testout) << "inner point found" << endl; (*testout) << "inner point found" << endl;
for(int i = 1; i <= groupfaces.Size(); i++) for(int i = 0; i < groupfaces.Size(); i++)
adfront -> DeleteFace (groupfindex[i-1]); adfront -> DeleteFace (groupfindex[i]);
for(int i = 1; i <= groupfaces.Size(); i++) for(int i = 1; i <= groupfaces.Size(); i++)
for (j = 1; j <= locfaces.Size(); j++) for (j = 1; j <= locfaces.Size(); j++)
if (findex[j-1] == groupfindex[i-1]) if (findex[j-1] == groupfindex[i-1])
@ -469,12 +483,12 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
if (stat.cnttrials % 100 == 0) if (stat.cnttrials % 100 == 0)
{ {
(*testout) << "\n"; (*testout) << "\n";
for(int i = 1; i <= canuse.Size(); i++) for(int i : canuse.Range())
{ {
(*testout) << foundmap.Get(i) << "/" (*testout) << foundmap[i] << "/"
<< canuse.Get(i) << "/" << canuse[i] << "/"
<< ruleused.Get(i) << " map/can/use rule " << rules.Get(i)->Name() << "\n"; << ruleused[i] << " map/can/use rule " << rules[i]->Name() << "\n";
} }
(*testout) << endl; (*testout) << endl;
} }
@ -545,8 +559,8 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
if (found) if (found)
ruleused.Elem(found)++; ruleused[found-1]++;
// plotstat->Plot(stat); // plotstat->Plot(stat);
@ -710,7 +724,7 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
} }
locelements.SetSize (0); locelements.SetSize (0);
delpoints.SetSize(0); // delpoints.SetSize(0);
delfaces.SetSize(0); delfaces.SetSize(0);
if (stat.qualclass >= mp.giveuptol) if (stat.qualclass >= mp.giveuptol)
@ -719,9 +733,9 @@ GenerateMesh (Mesh & mesh, const MeshingParameters & mp)
PrintMessage (5, ""); // line feed after statistics PrintMessage (5, ""); // line feed after statistics
for(int i = 1; i <= ruleused.Size(); i++) for(int i : ruleused.Range())
(*testout) << setw(4) << ruleused.Get(i) (*testout) << setw(4) << ruleused[i]
<< " times used rule " << rules.Get(i) -> Name() << endl; << " times used rule " << rules[i] -> Name() << endl;
if (!mp.baseelnp && adfront->Empty()) if (!mp.baseelnp && adfront->Empty())

View File

@ -24,11 +24,11 @@ class Meshing3
/// current state of front /// current state of front
unique_ptr<AdFront3> adfront; unique_ptr<AdFront3> adfront;
/// 3d generation rules /// 3d generation rules
NgArray<vnetrule*> rules; Array<unique_ptr<vnetrule>> rules;
/// counts how often a rule is used /// counts how often a rule is used
NgArray<int> ruleused, canuse, foundmap; Array<int> ruleused, canuse, foundmap;
/// describes, why a rule is not applied /// describes, why a rule is not applied
NgArray<char*> problems; Array<string> problems;
/// tolerance criterion /// tolerance criterion
double tolfak; double tolfak;
public: public:

View File

@ -1014,14 +1014,15 @@ void Meshing3 :: LoadRules (const char * filename, const char ** prules)
if (strcmp (buf, "rule") == 0) if (strcmp (buf, "rule") == 0)
{ {
vnetrule * rule = new vnetrule; // vnetrule * rule = new vnetrule;
auto rule = make_unique<vnetrule>();
rule -> LoadRule(*ist); rule -> LoadRule(*ist);
rules.Append (rule);
if (!rule->TestOk()) if (!rule->TestOk())
{ {
PrintSysError ("Parser3d: Rule ", rules.Size(), " not ok"); PrintSysError ("Parser3d: Rule ", rules.Size(), " not ok");
exit (1); exit (1);
} }
rules.Append (std::move(rule));
} }
else if (strcmp (buf, "tolfak") == 0) else if (strcmp (buf, "tolfak") == 0)
{ {

View File

@ -226,16 +226,17 @@ int Meshing3 :: ApplyRules
// check each rule: // check each rule:
// tstart.Stop(); // tstart.Stop();
// tloop.Start(); // tloop.Start();
for (int ri = 1; ri <= rules.Size(); ri++) for (int rim = 0; rim < rules.Size(); rim++)
{ {
int base = (lfaces[0].GetNP() == 3) ? 100 : 200; int base = (lfaces[0].GetNP() == 3) ? 100 : 200;
NgProfiler::RegionTimer regx1(base); NgProfiler::RegionTimer regx1(base);
NgProfiler::RegionTimer regx(base+ri); NgProfiler::RegionTimer regx(base+rim+1);
// sprintf (problems.Elem(ri), ""); // sprintf (problems.Elem(ri), "");
*problems.Elem(ri) = '\0'; // *problems.Elem(ri) = '\0';
problems[rim] = "";
vnetrule * rule = rules.Get(ri); vnetrule * rule = rules[rim].get();
if (rule->GetNP(1) != lfaces[0].GetNP()) if (rule->GetNP(1) != lfaces[0].GetNP())
continue; continue;
@ -245,17 +246,17 @@ int Meshing3 :: ApplyRules
if (rule->GetQuality() < 100) impossible = 0; if (rule->GetQuality() < 100) impossible = 0;
if (testmode) if (testmode)
snprintf (problems.Elem(ri), 255, "Quality not ok"); problems[rim] = "Quality not ok";
continue; continue;
} }
if (testmode) if (testmode)
snprintf (problems.Elem(ri), 255, "no mapping found"); problems[rim] = "no mapping found";
loktestmode = testmode || rule->TestFlag ('t') || tolerance > 5; loktestmode = testmode || rule->TestFlag ('t') || tolerance > 5;
if (loktestmode) if (loktestmode)
(*testout) << "Rule " << ri << " = " << rule->Name() << endl; (*testout) << "Rule " << rim+1 << " = " << rule->Name() << endl;
pmap.SetSize (rule->GetNP()); pmap.SetSize (rule->GetNP());
fmapi.SetSize (rule->GetNF()); fmapi.SetSize (rule->GetNF());
@ -287,7 +288,7 @@ int Meshing3 :: ApplyRules
int nfok = 2; int nfok = 2;
NgProfiler::RegionTimer regfa(300); NgProfiler::RegionTimer regfa(300);
NgProfiler::RegionTimer regx2(base+50+ri); NgProfiler::RegionTimer regx2(base+50+rim+1);
while (nfok >= 2) while (nfok >= 2)
{ {
@ -419,7 +420,7 @@ int Meshing3 :: ApplyRules
if (loktestmode) if (loktestmode)
{ {
(*testout) << "Faces Ok" << endl; (*testout) << "Faces Ok" << endl;
snprintf (problems.Elem(ri), 255, "Faces Ok"); problems[rim] = "Faces Ok";
} }
int npok = 1; int npok = 1;
@ -527,7 +528,7 @@ int Meshing3 :: ApplyRules
for (auto pi : pmap) for (auto pi : pmap)
(*testout) << pi << " "; (*testout) << pi << " ";
(*testout) << endl; (*testout) << endl;
snprintf (problems.Elem(ri), 255, "mapping found"); problems[rim] = "mapping found";
(*testout) << rule->GetNP(1) << " = " << lfaces[0].GetNP() << endl; (*testout) << rule->GetNP(1) << " = " << lfaces[0].GetNP() << endl;
} }
@ -594,10 +595,7 @@ int Meshing3 :: ApplyRules
if (ok) if (ok)
{ foundmap[rim]++;
foundmap.Elem(ri)++;
}
@ -642,7 +640,7 @@ int Meshing3 :: ApplyRules
if (!rule->ConvexFreeZone()) if (!rule->ConvexFreeZone())
{ {
ok = 0; ok = 0;
snprintf (problems.Elem(ri), 255, "Freezone not convex"); problems[rim] = "Freezone not convex";
if (loktestmode) if (loktestmode)
(*testout) << "Freezone not convex" << endl; (*testout) << "Freezone not convex" << endl;
@ -674,8 +672,7 @@ int Meshing3 :: ApplyRules
{ {
(*testout) << "Point " << i (*testout) << "Point " << i
<< " in Freezone" << endl; << " in Freezone" << endl;
snprintf (problems.Elem(ri), 255, problems[rim] = "locpoint " + ToString(i) + " in Freezone";
"locpoint %d in Freezone", int(i));
} }
ok = 0; ok = 0;
break; break;
@ -788,10 +785,9 @@ int Meshing3 :: ApplyRules
<< lpoints[lfacei.PNum(4)] << lpoints[lfacei.PNum(4)]
<< endl; << endl;
snprintf (problems.Elem(ri), 255, "triangle (%d, %d, %d) in Freezone", problems[rim] = "triangle ("+ToString(lfaces[i-1].PNum(1))+", "
int(lfaces[i-1].PNum(1)), + ToString(lfaces[i-1].PNum(2)) + ", "
int(lfaces[i-1].PNum(2)), + ToString(lfaces[i-1].PNum(3)) + ") in Freezone";
int(lfaces[i-1].PNum(3)));
} }
hc = 0; hc = 0;
@ -817,7 +813,7 @@ int Meshing3 :: ApplyRules
// << " - " << pmap.Get (rule->GetPointNr(k, 3)) << " ) " // << " - " << pmap.Get (rule->GetPointNr(k, 3)) << " ) "
// << endl; // << endl;
strcpy (problems.Elem(ri), "other"); problems[rim] = "other";
} }
} }
} }
@ -831,10 +827,17 @@ int Meshing3 :: ApplyRules
<< lfaces[i-1].PNum(2) << " - " << lfaces[i-1].PNum(2) << " - "
<< lfaces[i-1].PNum(3) << endl; << lfaces[i-1].PNum(3) << endl;
/*
snprintf (problems.Elem(ri), 255, "triangle (%d, %d, %d) in Freezone", snprintf (problems.Elem(ri), 255, "triangle (%d, %d, %d) in Freezone",
int (lfaces[i-1].PNum(1)), int (lfaces[i-1].PNum(1)),
int (lfaces[i-1].PNum(2)), int (lfaces[i-1].PNum(2)),
int (lfaces[i-1].PNum(3))); int (lfaces[i-1].PNum(3)));
*/
problems[rim] = "triangle ("
+ ToString(lfaces[i-1].PNum(1))+", "
+ ToString(lfaces[i-1].PNum(2)) + ", "
+ ToString(lfaces[i-1].PNum(3)) + ") in Freezone";
} }
ok = 0; ok = 0;
} }
@ -858,7 +861,7 @@ int Meshing3 :: ApplyRules
if (loktestmode) if (loktestmode)
{ {
(*testout) << "Rule ok" << endl; (*testout) << "Rule ok" << endl;
snprintf (problems.Elem(ri), 255, "Rule ok, err = %f", err); problems[rim] = "Rule ok, err = "+ToString(err);
} }
@ -923,7 +926,7 @@ int Meshing3 :: ApplyRules
{ {
if (loktestmode) if (loktestmode)
{ {
snprintf (problems.Elem(ri), 255, "Orientation wrong"); problems[rim] = "Orientation wrong";
(*testout) << "Orientation wrong ("<< n*v3 << ")" << endl; (*testout) << "Orientation wrong ("<< n*v3 << ")" << endl;
} }
ok = 0; ok = 0;
@ -940,7 +943,7 @@ int Meshing3 :: ApplyRules
{ {
(*testout) << "Newpoint " << lpoints[pmap.Get(i)] (*testout) << "Newpoint " << lpoints[pmap.Get(i)]
<< " outside convex hull" << endl; << " outside convex hull" << endl;
snprintf (problems.Elem(ri), 255, "newpoint outside convex hull"); problems[rim] = "newpoint outside convex hull";
} }
ok = 0; ok = 0;
@ -1015,7 +1018,7 @@ int Meshing3 :: ApplyRules
{ {
ok = 0; ok = 0;
if (loktestmode) if (loktestmode)
snprintf (problems.Elem(ri), 255, "oldlen < newlen"); problems[rim] = "oldlen < newlen";
} }
} }
@ -1028,7 +1031,7 @@ int Meshing3 :: ApplyRules
if (ok && teterr < tolerance) if (ok && teterr < tolerance)
{ {
canuse.Elem(ri) ++; canuse[rim] ++;
/* /*
(*testout) << "can use rule " << rule->Name() (*testout) << "can use rule " << rule->Name()
<< ", err = " << teterr << endl; << ", err = " << teterr << endl;
@ -1037,7 +1040,7 @@ int Meshing3 :: ApplyRules
(*testout) << endl; (*testout) << endl;
*/ */
if (strcmp (problems.Elem(ri), "other") == 0) if (problems[rim] == "other")
{ {
if (teterr < minother) if (teterr < minother)
minother = teterr; minother = teterr;
@ -1058,7 +1061,7 @@ int Meshing3 :: ApplyRules
if (loktestmode) if (loktestmode)
(*testout) << "use rule" << endl; (*testout) << "use rule" << endl;
found = ri; found = rim+1;
minteterr = teterr; minteterr = teterr;
if (testmode) if (testmode)