Restructure code in GetElementOfPoint

This commit is contained in:
mhochsteger@cerbsim.com 2021-09-22 17:04:28 +02:00
parent 06af8111e8
commit 286f63f002

View File

@ -5609,52 +5609,8 @@ namespace netgen
return -1;
if (dimension == 2 || (dimension==3 && !GetNE() && GetNSE()))
{
int ne;
int ps_startelement = 0; // disable global buffering
return GetSurfaceElementOfPoint(p, lami, indices, build_searchtree, allowindex);
if(ps_startelement != 0 && ps_startelement <= GetNSE() && PointContainedIn2DElement(p,lami,ps_startelement))
return ps_startelement;
NgArray<int> locels;
if (elementsearchtree || build_searchtree)
{
// update if necessary:
const_cast<Mesh&>(*this).BuildElementSearchTree ();
// double tol = elementsearchtree->Tolerance();
// netgen::Point<3> pmin = p - Vec<3> (tol, tol, tol);
// netgen::Point<3> pmax = p + Vec<3> (tol, tol, tol);
elementsearchtree->GetIntersecting (p, p, locels);
ne = locels.Size();
}
else
ne = GetNSE();
for (int i = 1; i <= ne; i++)
{
int ii;
if (elementsearchtree)
ii = locels.Get(i);
else
ii = i;
if(ii == ps_startelement) continue;
if(indices != NULL && indices->Size() > 0)
{
bool contained = indices->Contains(SurfaceElement(ii).GetIndex());
if((allowindex && !contained) || (!allowindex && contained)) continue;
}
if(PointContainedIn2DElement(p,lami,ii)) return ii;
}
return 0;
}
else
{
int ps_startelement = 0; // disable global buffering
// int i, j;
int ne;
@ -5723,11 +5679,8 @@ namespace netgen
return ii;
}
}
return 0;
}
}
@ -5809,14 +5762,9 @@ namespace netgen
//(*testout) << "p " << p << endl;
//(*testout) << "velement " << velement << endl;
if (!GetNE() && GetNSE() )
// first try to find a volume element containing p and project to face
if(velement!=0)
{
lami[0] = vlam[0];
lami[1] = vlam[1];
lami[2] = vlam[2];
return velement;
}
NgArray<int> faces;
topology.GetElementFaces(velement,faces);
@ -5868,17 +5816,44 @@ namespace netgen
}
}
}
}
NgArray<int> faces2;
topology.GetElementFaces(velement,faces2);
/*
cout << "no matching surf element" << endl
<< "p = " << p << endl
<< "faces-orig = " << faces2 << endl
<< "faces = " << faces << endl
<< ", vol el = " << velement
<< ", vlam = " << vlam[0] << "," << vlam[1] << "," << vlam[2] << endl;
*/
// Did't find any matching face of a volume element, search 2d elements directly
int ne;
NgArray<int> locels;
// TODO: build search tree for surface elements
if (!GetNE() && GetNSE() && (elementsearchtree || build_searchtree))
{
// update if necessary:
const_cast<Mesh&>(*this).BuildElementSearchTree ();
// double tol = elementsearchtree->Tolerance();
// netgen::Point<3> pmin = p - Vec<3> (tol, tol, tol);
// netgen::Point<3> pmax = p + Vec<3> (tol, tol, tol);
elementsearchtree->GetIntersecting (p, p, locels);
ne = locels.Size();
}
else
ne = GetNSE();
for (int i = 1; i <= ne; i++)
{
int ii;
if (locels.Size())
ii = locels.Get(i);
else
ii = i;
if(indices != NULL && indices->Size() > 0)
{
bool contained = indices->Contains(SurfaceElement(ii).GetIndex());
if((allowindex && !contained) || (!allowindex && contained)) continue;
}
if(PointContainedIn2DElement(p,lami,ii)) return ii;
}
}
return 0;