2009-01-13 04:40:13 +05:00
|
|
|
#include <mystdlib.h>
|
|
|
|
|
|
|
|
#include "meshing.hpp"
|
|
|
|
#include <opti.hpp>
|
|
|
|
|
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
class trionedge
|
|
|
|
{
|
|
|
|
public:
|
2019-08-18 16:10:58 +05:00
|
|
|
SurfaceElementIndex tnr;
|
2009-11-16 13:18:00 +05:00
|
|
|
int sidenr;
|
|
|
|
|
|
|
|
trionedge () { tnr = 0; sidenr = 0; }
|
2019-08-18 16:10:58 +05:00
|
|
|
trionedge (SurfaceElementIndex atnr, int asidenr)
|
2009-01-13 04:40:13 +05:00
|
|
|
{ tnr = atnr; sidenr = asidenr; }
|
2009-11-16 13:18:00 +05:00
|
|
|
};
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-10-08 20:03:49 +05:00
|
|
|
bool MeshOptimize2d :: EdgeSwapping (Mesh & mesh, const int usemetric,
|
|
|
|
Array<Neighbour> &neighbors,
|
|
|
|
Array<bool> &swapped,
|
|
|
|
const SurfaceElementIndex t1, const int o1,
|
|
|
|
const int t,
|
2019-10-08 21:35:20 +05:00
|
|
|
Array<int,PointIndex> &pdef,
|
2019-10-08 20:03:49 +05:00
|
|
|
const bool check_only)
|
|
|
|
{
|
|
|
|
bool should;
|
|
|
|
bool do_swap = false;
|
|
|
|
|
|
|
|
SurfaceElementIndex t2 = neighbors[t1].GetNr (o1);
|
|
|
|
int o2 = neighbors[t1].GetOrientation (o1);
|
|
|
|
|
|
|
|
if (t2 == -1) return false;
|
|
|
|
if (swapped[t1] || swapped[t2]) return false;
|
|
|
|
|
2019-10-08 21:12:10 +05:00
|
|
|
const int faceindex = mesh[t1].GetIndex();
|
|
|
|
const int surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr();
|
2019-10-08 20:03:49 +05:00
|
|
|
|
|
|
|
PointIndex pi1 = mesh[t1].PNumMod(o1+1+1);
|
|
|
|
PointIndex pi2 = mesh[t1].PNumMod(o1+1+2);
|
|
|
|
PointIndex pi3 = mesh[t1].PNumMod(o1+1);
|
|
|
|
PointIndex pi4 = mesh[t2].PNumMod(o2+1);
|
|
|
|
|
|
|
|
PointGeomInfo gi1 = mesh[t1].GeomInfoPiMod(o1+1+1);
|
|
|
|
PointGeomInfo gi2 = mesh[t1].GeomInfoPiMod(o1+1+2);
|
|
|
|
PointGeomInfo gi3 = mesh[t1].GeomInfoPiMod(o1+1);
|
|
|
|
PointGeomInfo gi4 = mesh[t2].GeomInfoPiMod(o2+1);
|
|
|
|
|
|
|
|
bool allowswap = true;
|
|
|
|
|
|
|
|
Vec<3> auxvec1 = mesh[pi3]-mesh[pi4];
|
|
|
|
Vec<3> auxvec2 = mesh[pi1]-mesh[pi4];
|
|
|
|
|
|
|
|
allowswap = allowswap && fabs(1.-(auxvec1*auxvec2)/(auxvec1.Length()*auxvec2.Length())) > 1e-4;
|
|
|
|
|
|
|
|
if(!allowswap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// normal of new
|
|
|
|
Vec<3> nv1 = Cross (auxvec1, auxvec2);
|
|
|
|
|
|
|
|
auxvec1 = mesh.Point(pi4)-mesh.Point(pi3);
|
|
|
|
auxvec2 = mesh.Point(pi2)-mesh.Point(pi3);
|
|
|
|
allowswap = allowswap && fabs(1.-(auxvec1*auxvec2)/(auxvec1.Length()*auxvec2.Length())) > 1e-4;
|
|
|
|
|
|
|
|
|
|
|
|
if(!allowswap)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
Vec<3> nv2 = Cross (auxvec1, auxvec2);
|
|
|
|
|
|
|
|
|
|
|
|
// normals of original
|
|
|
|
Vec<3> nv3 = Cross (mesh[pi1]-mesh[pi4], mesh[pi2]-mesh[pi4]);
|
|
|
|
Vec<3> nv4 = Cross (mesh[pi2]-mesh[pi3], mesh[pi1]-mesh[pi3]);
|
|
|
|
|
|
|
|
nv3 *= -1;
|
|
|
|
nv4 *= -1;
|
|
|
|
nv3.Normalize();
|
|
|
|
nv4.Normalize();
|
|
|
|
|
|
|
|
nv1.Normalize();
|
|
|
|
nv2.Normalize();
|
|
|
|
|
|
|
|
Vec<3> nvp3, nvp4;
|
|
|
|
GetNormalVector (surfnr, mesh.Point(pi3), gi3, nvp3);
|
|
|
|
|
|
|
|
nvp3.Normalize();
|
|
|
|
|
|
|
|
GetNormalVector (surfnr, mesh.Point(pi4), gi4, nvp4);
|
|
|
|
|
|
|
|
nvp4.Normalize();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double critval = cos (M_PI / 6); // 30 degree
|
|
|
|
allowswap = allowswap &&
|
|
|
|
(nv1 * nvp3 > critval) &&
|
|
|
|
(nv1 * nvp4 > critval) &&
|
|
|
|
(nv2 * nvp3 > critval) &&
|
|
|
|
(nv2 * nvp4 > critval) &&
|
|
|
|
(nvp3 * nv3 > critval) &&
|
|
|
|
(nvp4 * nv4 > critval);
|
|
|
|
|
|
|
|
|
|
|
|
double horder = Dist (mesh[pi1], mesh[pi2]);
|
|
|
|
|
|
|
|
if ( // nv1 * nv2 >= 0 &&
|
|
|
|
nv1.Length() > 1e-3 * horder * horder &&
|
|
|
|
nv2.Length() > 1e-3 * horder * horder &&
|
|
|
|
allowswap )
|
|
|
|
{
|
|
|
|
if (!usemetric)
|
|
|
|
{
|
|
|
|
int e = pdef[pi1] + pdef[pi2] - pdef[pi3] - pdef[pi4];
|
|
|
|
double d =
|
|
|
|
Dist2 (mesh[pi1], mesh[pi2]) -
|
|
|
|
Dist2 (mesh[pi3], mesh[pi4]);
|
|
|
|
|
|
|
|
should = e >= t && (e > 2 || d > 0);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
double loch = mesh.GetH(mesh[pi1]);
|
|
|
|
should =
|
|
|
|
CalcTriangleBadness (mesh[pi4], mesh[pi3], mesh[pi1], metricweight, loch) +
|
|
|
|
CalcTriangleBadness (mesh[pi3], mesh[pi4], mesh[pi2], metricweight, loch) <
|
|
|
|
CalcTriangleBadness (mesh[pi1], mesh[pi2], mesh[pi3], metricweight, loch) +
|
|
|
|
CalcTriangleBadness (mesh[pi2], mesh[pi1], mesh[pi4], metricweight, loch);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (allowswap)
|
|
|
|
{
|
|
|
|
Element2d sw1 (pi4, pi3, pi1);
|
|
|
|
Element2d sw2 (pi3, pi4, pi2);
|
|
|
|
|
|
|
|
int legal1 =
|
|
|
|
mesh.LegalTrig (mesh[t1]) +
|
|
|
|
mesh.LegalTrig (mesh[t2]);
|
|
|
|
int legal2 =
|
|
|
|
mesh.LegalTrig (sw1) + mesh.LegalTrig (sw2);
|
|
|
|
|
|
|
|
if (legal1 < legal2) should = true;
|
|
|
|
if (legal2 < legal1) should = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
do_swap = should;
|
|
|
|
if (should && !check_only)
|
|
|
|
{
|
|
|
|
// do swapping !
|
|
|
|
|
|
|
|
mesh[t1] = { { pi1, gi1 }, { pi4, gi4 }, { pi3, gi3 } };
|
|
|
|
mesh[t2] = { { pi2, gi2 }, { pi3, gi3 }, { pi4, gi4 } };
|
|
|
|
|
|
|
|
pdef[pi1]--;
|
|
|
|
pdef[pi2]--;
|
|
|
|
pdef[pi3]++;
|
|
|
|
pdef[pi4]++;
|
|
|
|
|
|
|
|
swapped[t1] = true;
|
|
|
|
swapped[t2] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return do_swap;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
void MeshOptimize2d :: EdgeSwapping (Mesh & mesh, int usemetric)
|
|
|
|
{
|
2019-09-30 11:53:32 +05:00
|
|
|
static Timer timer("EdgeSwapping (2D)"); RegionTimer reg(timer);
|
2019-10-08 21:35:20 +05:00
|
|
|
static Timer timer_nb("EdgeSwapping-Find neighbors");
|
2019-10-08 21:12:10 +05:00
|
|
|
if (usemetric)
|
|
|
|
PrintMessage (3, "Edgeswapping, metric");
|
|
|
|
else
|
|
|
|
PrintMessage (3, "Edgeswapping, topological");
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
static Timer timerstart("EdgeSwapping 2D start");
|
|
|
|
timerstart.Start();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-08 11:44:59 +05:00
|
|
|
Array<SurfaceElementIndex> seia;
|
2019-10-08 21:12:10 +05:00
|
|
|
bool mixed = false;
|
2019-10-08 22:26:43 +05:00
|
|
|
|
2019-10-08 21:12:10 +05:00
|
|
|
if(faceindex==0)
|
|
|
|
{
|
|
|
|
seia.SetSize(mesh.GetNSE());
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 21:12:10 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
SurfaceElementIndex sei(i);
|
|
|
|
seia[i] = sei;
|
|
|
|
if (mesh[sei].GetNP() != 3)
|
|
|
|
mixed = true;
|
2019-10-08 21:12:10 +05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mesh.GetSurfaceElementsOfFace (faceindex, seia);
|
|
|
|
for (SurfaceElementIndex sei : seia)
|
|
|
|
if (mesh[sei].GetNP() != 3)
|
|
|
|
mixed = true;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-08 21:12:10 +05:00
|
|
|
if(mixed)
|
|
|
|
return GenericImprove(mesh);
|
2019-08-08 11:44:59 +05:00
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
Array<Neighbour> neighbors(mesh.GetNSE());
|
2019-10-08 22:26:43 +05:00
|
|
|
auto elements_on_node = mesh.CreatePoint2SurfaceElementTable(faceindex);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
Array<bool> swapped(mesh.GetNSE());
|
2019-10-08 21:35:20 +05:00
|
|
|
Array<int,PointIndex> pdef(mesh.GetNP());
|
|
|
|
Array<double,PointIndex> pangle(mesh.GetNP());
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
static const double minangle[] = { 0, 1.481, 2.565, 3.627, 4.683, 5.736, 7, 9 };
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-10-08 21:35:20 +05:00
|
|
|
if(faceindex == 0)
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(pangle), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
pangle[i] = 0.0;
|
2019-10-08 21:35:20 +05:00
|
|
|
});
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
2019-10-08 21:35:20 +05:00
|
|
|
else
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
const Element2d & sel = mesh[seia[i]];
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
pangle[sel[j]] = 0.0;
|
2019-10-08 21:35:20 +05:00
|
|
|
});
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
const Element2d & sel = mesh[seia[i]];
|
|
|
|
for (int j = 0; j < 3; j++)
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
POINTTYPE typ = mesh[sel[j]].Type();
|
|
|
|
if (typ == FIXEDPOINT || typ == EDGEPOINT)
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
AtomicAdd(pangle[sel[j]],
|
|
|
|
Angle (mesh[sel[(j+1)%3]] - mesh[sel[j]],
|
|
|
|
mesh[sel[(j+2)%3]] - mesh[sel[j]]));
|
2019-10-08 21:35:20 +05:00
|
|
|
}
|
2019-10-09 12:57:37 +05:00
|
|
|
}
|
2019-10-08 21:35:20 +05:00
|
|
|
});
|
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
const Element2d & sel = mesh[seia[i]];
|
|
|
|
for (int j = 0; j < 3; j++)
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
PointIndex pi = sel[j];
|
|
|
|
if (mesh[pi].Type() == INNERPOINT || mesh[pi].Type() == SURFACEPOINT)
|
|
|
|
pdef[pi] = -6;
|
|
|
|
else
|
|
|
|
for (int j = 0; j < 8; j++)
|
|
|
|
if (pangle[pi] >= minangle[j])
|
|
|
|
pdef[pi] = -1-j;
|
2019-10-08 21:35:20 +05:00
|
|
|
}
|
|
|
|
});
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&pdef, &neighbors, &mesh, &seia, &elements_on_node] (auto i) NETGEN_LAMBDA_INLINE
|
2019-08-18 15:20:43 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
auto sei = seia[i];
|
|
|
|
for (PointIndex pi : mesh[sei].template PNums<3>())
|
|
|
|
AsAtomic(pdef[pi])++;
|
|
|
|
for (int j = 0; j < 3; j++)
|
2019-10-08 21:35:20 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
neighbors[sei].SetNr (j, -1);
|
|
|
|
neighbors[sei].SetOrientation (j, 0);
|
|
|
|
}
|
2019-10-08 22:26:43 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
const auto sel = mesh[sei];
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
PointIndex pi1 = sel.PNumMod(j+2);
|
|
|
|
PointIndex pi2 = sel.PNumMod(j+3);
|
2019-10-08 22:26:43 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
for (auto sei_other : elements_on_node[pi1])
|
|
|
|
{
|
|
|
|
if(sei_other==sei) continue;
|
|
|
|
const auto & other = mesh[sei_other];
|
|
|
|
int pi1_other = -1;
|
|
|
|
int pi2_other = -1;
|
|
|
|
bool common_edge = false;
|
|
|
|
for (int k = 0; k < 3; k++)
|
2019-10-08 22:26:43 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
if(other[k] == pi1)
|
|
|
|
pi1_other = k;
|
|
|
|
if(other[k] == pi2)
|
2019-10-08 22:26:43 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
pi2_other = k;
|
|
|
|
common_edge = true;
|
2019-10-08 22:26:43 +05:00
|
|
|
}
|
2019-10-09 12:57:37 +05:00
|
|
|
}
|
2019-10-08 22:26:43 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
if(common_edge)
|
|
|
|
{
|
|
|
|
neighbors[sei].SetNr (j, sei_other);
|
|
|
|
neighbors[sei].SetOrientation (j, 3-pi1_other-pi2_other);
|
2019-10-08 22:26:43 +05:00
|
|
|
}
|
|
|
|
}
|
2019-10-08 21:35:20 +05:00
|
|
|
}
|
|
|
|
});
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
for (SurfaceElementIndex sei : seia)
|
|
|
|
swapped[sei] = false;
|
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
timerstart.Stop();
|
2009-11-16 13:18:00 +05:00
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-10-08 20:29:38 +05:00
|
|
|
Array<std::pair<SurfaceElementIndex,int>> improvement_candidates(3*seia.Size());
|
|
|
|
atomic<int> cnt(0);
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
int t = 4;
|
2019-08-08 10:36:26 +05:00
|
|
|
bool done = false;
|
2009-11-16 13:18:00 +05:00
|
|
|
while (!done && t >= 2)
|
|
|
|
{
|
2019-10-08 20:29:38 +05:00
|
|
|
cnt = 0;
|
2019-10-09 12:57:37 +05:00
|
|
|
ParallelFor( Range(seia), [&] (auto i) NETGEN_LAMBDA_INLINE
|
2019-10-08 20:29:38 +05:00
|
|
|
{
|
2019-10-09 12:57:37 +05:00
|
|
|
SurfaceElementIndex t1 = seia[i];
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
if (mesh[t1].IsDeleted())
|
|
|
|
return;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
if (mesh[t1].GetIndex() != faceindex)
|
|
|
|
return;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
if (multithread.terminate)
|
|
|
|
throw NgException ("Meshing stopped");
|
2009-11-16 13:18:00 +05:00
|
|
|
|
2019-10-09 12:57:37 +05:00
|
|
|
for (int o1 = 0; o1 < 3; o1++)
|
|
|
|
if(EdgeSwapping(mesh, usemetric, neighbors, swapped, t1, o1, t, pdef, true))
|
|
|
|
improvement_candidates[cnt++]= std::make_pair(t1,o1);
|
2019-10-08 20:29:38 +05:00
|
|
|
});
|
|
|
|
|
|
|
|
auto elements_with_improvement = improvement_candidates.Range(cnt.load());
|
|
|
|
QuickSort(elements_with_improvement);
|
|
|
|
|
|
|
|
for (auto [t1,o1] : elements_with_improvement)
|
2019-10-08 21:12:10 +05:00
|
|
|
done |= EdgeSwapping(mesh, usemetric, neighbors, swapped, t1, o1, t, pdef, false);
|
2009-11-16 13:18:00 +05:00
|
|
|
t--;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
mesh.SetNextTimeStamp();
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
void MeshOptimize2d :: CombineImprove (Mesh & mesh)
|
|
|
|
{
|
|
|
|
if (!faceindex)
|
|
|
|
{
|
2019-09-27 23:49:12 +05:00
|
|
|
SplitImprove(mesh);
|
2009-11-16 13:18:00 +05:00
|
|
|
PrintMessage (3, "Combine improve");
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
for (faceindex = 1; faceindex <= mesh.GetNFD(); faceindex++)
|
|
|
|
{
|
|
|
|
CombineImprove (mesh);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (multithread.terminate)
|
|
|
|
throw NgException ("Meshing stopped");
|
|
|
|
}
|
|
|
|
faceindex = 0;
|
|
|
|
return;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
static Timer timer ("Combineimprove 2D");
|
|
|
|
RegionTimer reg (timer);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
static Timer timerstart ("Combineimprove 2D start");
|
|
|
|
timerstart.Start();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
static Timer timerstart1 ("Combineimprove 2D start1");
|
|
|
|
timerstart1.Start();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-08 11:44:59 +05:00
|
|
|
|
|
|
|
Array<SurfaceElementIndex> seia;
|
2009-11-16 13:18:00 +05:00
|
|
|
mesh.GetSurfaceElementsOfFace (faceindex, seia);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-08-08 11:44:59 +05:00
|
|
|
for (SurfaceElementIndex sei : seia)
|
|
|
|
if (mesh[sei].GetNP() != 3)
|
2009-11-16 13:18:00 +05:00
|
|
|
return;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
int surfnr = 0;
|
|
|
|
if (faceindex)
|
|
|
|
surfnr = mesh.GetFaceDescriptor (faceindex).SurfNr();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
Vec<3> nv;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
int np = mesh.GetNP();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 14:28:29 +05:00
|
|
|
auto elementsonnode = mesh.CreatePoint2SurfaceElementTable(faceindex);
|
2019-08-18 15:20:43 +05:00
|
|
|
Array<SurfaceElementIndex> hasonepi, hasbothpi;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 16:51:25 +05:00
|
|
|
int ntasks = ngcore::TaskManager::GetMaxThreads();
|
|
|
|
Array<std::tuple<PointIndex, PointIndex>> edges;
|
|
|
|
|
|
|
|
BuildEdgeList( mesh, elementsonnode, edges );
|
|
|
|
|
2019-08-10 03:21:37 +05:00
|
|
|
Array<bool,PointIndex> fixed(np);
|
2019-10-14 14:28:29 +05:00
|
|
|
ParallelFor( fixed.Range(), [&fixed] (auto i) NETGEN_LAMBDA_INLINE
|
|
|
|
{ fixed[i] = false; });
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 16:51:25 +05:00
|
|
|
ParallelFor( edges.Range(), [&] (auto i) NETGEN_LAMBDA_INLINE
|
|
|
|
{
|
|
|
|
auto [pi0, pi1] = edges[i];
|
|
|
|
if (mesh.IsSegment (pi0, pi1))
|
|
|
|
{
|
|
|
|
fixed[pi0] = true;
|
|
|
|
fixed[pi1] = true;
|
|
|
|
}
|
|
|
|
});
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 16:51:25 +05:00
|
|
|
timerstart1.Stop();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 16:51:25 +05:00
|
|
|
ParallelFor( mesh.LockedPoints().Range(), [&] (auto i) NETGEN_LAMBDA_INLINE
|
|
|
|
{
|
|
|
|
fixed[mesh.LockedPoints()[i]] = true;
|
|
|
|
});
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
Array<Vec<3>,PointIndex> normals(np);
|
2009-11-16 13:18:00 +05:00
|
|
|
|
2019-10-14 16:51:25 +05:00
|
|
|
ParallelFor( mesh.Points().Range(), [&] (auto pi) NETGEN_LAMBDA_INLINE
|
|
|
|
{
|
|
|
|
if (elementsonnode[pi].Size())
|
|
|
|
{
|
|
|
|
Element2d & hel = mesh[elementsonnode[pi][0]];
|
|
|
|
for (int k = 0; k < 3; k++)
|
|
|
|
if (hel[k] == pi)
|
|
|
|
{
|
|
|
|
GetNormalVector (surfnr, mesh[pi], hel.GeomInfoPi(k+1), normals[pi]);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-04 20:05:40 +05:00
|
|
|
timerstart.Stop();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 17:04:10 +05:00
|
|
|
for (auto e : edges)
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2019-10-14 17:04:10 +05:00
|
|
|
auto [pi1, pi2] = e;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-08 02:32:14 +05:00
|
|
|
/*
|
2009-11-16 13:18:00 +05:00
|
|
|
if (pi1 < PointIndex::BASE ||
|
|
|
|
pi2 < PointIndex::BASE)
|
|
|
|
continue;
|
2019-08-08 02:32:14 +05:00
|
|
|
*/
|
|
|
|
if (!pi1.IsValid() || !pi2.IsValid())
|
|
|
|
continue;
|
2009-11-16 13:18:00 +05:00
|
|
|
/*
|
|
|
|
INDEX_2 i2(pi1, pi2);
|
|
|
|
i2.Sort();
|
|
|
|
if (segmentht.Used(i2))
|
|
|
|
continue;
|
|
|
|
*/
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
bool debugflag = 0;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (debugflag)
|
|
|
|
{
|
|
|
|
(*testout) << "Combineimprove, face = " << faceindex
|
|
|
|
<< "pi1 = " << pi1 << " pi2 = " << pi2 << endl;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
/*
|
|
|
|
// save version:
|
|
|
|
if (fixed.Get(pi1) || fixed.Get(pi2))
|
2009-01-13 04:40:13 +05:00
|
|
|
continue;
|
2009-11-16 13:18:00 +05:00
|
|
|
if (pi2 < pi1) swap (pi1, pi2);
|
|
|
|
*/
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
// more general
|
|
|
|
if (fixed[pi2])
|
|
|
|
Swap (pi1, pi2);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (fixed[pi2])
|
|
|
|
continue;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
double loch = mesh.GetH (mesh[pi1]);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-08 02:32:14 +05:00
|
|
|
// INDEX_2 si2 (pi1, pi2);
|
|
|
|
// si2.Sort();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
/*
|
|
|
|
if (edgetested.Used (si2))
|
|
|
|
continue;
|
|
|
|
edgetested.Set (si2, 1);
|
|
|
|
*/
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
hasonepi.SetSize(0);
|
|
|
|
hasbothpi.SetSize(0);
|
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
// for (int k = 0; k < elementsonnode[pi1].Size(); k++)
|
|
|
|
for (SurfaceElementIndex sei2 : elementsonnode[pi1])
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2019-08-18 15:20:43 +05:00
|
|
|
const Element2d & el2 = mesh[sei2];
|
2009-11-16 13:18:00 +05:00
|
|
|
|
|
|
|
if (el2.IsDeleted()) continue;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (el2[0] == pi2 || el2[1] == pi2 || el2[2] == pi2)
|
|
|
|
{
|
2019-08-18 15:20:43 +05:00
|
|
|
hasbothpi.Append (sei2);
|
2009-11-16 13:18:00 +05:00
|
|
|
nv = Cross (Vec3d (mesh[el2[0]], mesh[el2[1]]),
|
|
|
|
Vec3d (mesh[el2[0]], mesh[el2[2]]));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-08-18 15:20:43 +05:00
|
|
|
hasonepi.Append (sei2);
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-14 17:04:10 +05:00
|
|
|
if(hasbothpi.Size()==0)
|
|
|
|
continue;
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
Element2d & hel = mesh[hasbothpi[0]];
|
|
|
|
for (int k = 0; k < 3; k++)
|
|
|
|
if (hel[k] == pi1)
|
|
|
|
{
|
|
|
|
GetNormalVector (surfnr, mesh[pi1], hel.GeomInfoPi(k+1), nv);
|
|
|
|
break;
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
// nv = normals.Get(pi1);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2019-08-18 15:20:43 +05:00
|
|
|
for (SurfaceElementIndex sei2 : elementsonnode[pi2])
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2019-08-18 15:20:43 +05:00
|
|
|
const Element2d & el2 = mesh[sei2];
|
2009-11-16 13:18:00 +05:00
|
|
|
if (el2.IsDeleted()) continue;
|
2019-08-18 15:20:43 +05:00
|
|
|
if (!el2.PNums<3>().Contains (pi1))
|
|
|
|
hasonepi.Append (sei2);
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
|
2019-08-08 11:44:59 +05:00
|
|
|
double bad1 = 0;
|
2009-11-16 13:18:00 +05:00
|
|
|
int illegal1 = 0, illegal2 = 0;
|
2019-08-18 15:20:43 +05:00
|
|
|
/*
|
|
|
|
for (SurfaceElementIndex sei : hasonepi)
|
|
|
|
{
|
|
|
|
const Element2d & el = mesh[sei];
|
2009-11-16 13:18:00 +05:00
|
|
|
bad1 += CalcTriangleBadness (mesh[el[0]], mesh[el[1]], mesh[el[2]],
|
|
|
|
nv, -1, loch);
|
|
|
|
illegal1 += 1-mesh.LegalTrig(el);
|
|
|
|
}
|
2019-08-18 15:20:43 +05:00
|
|
|
*/
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
for (int k = 0; k < hasbothpi.Size(); k++)
|
|
|
|
{
|
|
|
|
const Element2d & el = mesh[hasbothpi[k]];
|
|
|
|
bad1 += CalcTriangleBadness (mesh[el[0]], mesh[el[1]], mesh[el[2]],
|
|
|
|
nv, -1, loch);
|
|
|
|
illegal1 += 1-mesh.LegalTrig(el);
|
|
|
|
}
|
|
|
|
bad1 /= (hasonepi.Size()+hasbothpi.Size());
|
|
|
|
|
2019-08-08 11:44:59 +05:00
|
|
|
double bad2 = 0;
|
2009-11-16 13:18:00 +05:00
|
|
|
for (int k = 0; k < hasonepi.Size(); k++)
|
|
|
|
{
|
2019-10-13 15:27:29 +05:00
|
|
|
Element2d el = mesh[hasonepi[k]];
|
|
|
|
for (auto i : Range(3))
|
|
|
|
if(el[i]==pi2)
|
|
|
|
el[i] = pi1;
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
double err =
|
|
|
|
CalcTriangleBadness (mesh[el[0]], mesh[el[1]], mesh[el[2]],
|
|
|
|
nv, -1, loch);
|
|
|
|
bad2 += err;
|
|
|
|
|
|
|
|
Vec<3> hnv = Cross (Vec3d (mesh[el[0]],
|
|
|
|
mesh[el[1]]),
|
|
|
|
Vec3d (mesh[el[0]],
|
|
|
|
mesh[el[2]]));
|
|
|
|
if (hnv * nv < 0)
|
2009-01-13 04:40:13 +05:00
|
|
|
bad2 += 1e10;
|
2009-11-16 13:18:00 +05:00
|
|
|
|
|
|
|
for (int l = 0; l < 3; l++)
|
|
|
|
if ( (normals[el[l]] * nv) < 0.5)
|
|
|
|
bad2 += 1e10;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-10-13 15:27:29 +05:00
|
|
|
illegal2 += 1-mesh.LegalTrig(el);
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
bad2 /= hasonepi.Size();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (debugflag)
|
|
|
|
{
|
|
|
|
(*testout) << "bad1 = " << bad1 << ", bad2 = " << bad2 << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool should = (bad2 < bad1 && bad2 < 1e4);
|
|
|
|
if (bad2 < 1e4)
|
|
|
|
{
|
2019-08-08 10:36:26 +05:00
|
|
|
if (illegal1 > illegal2) should = true;
|
|
|
|
if (illegal2 > illegal1) should = false;
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
if (should)
|
|
|
|
{
|
2014-12-02 18:23:36 +05:00
|
|
|
/*
|
|
|
|
(*testout) << "combine !" << endl;
|
|
|
|
(*testout) << "bad1 = " << bad1 << ", bad2 = " << bad2 << endl;
|
|
|
|
(*testout) << "illegal1 = " << illegal1 << ", illegal2 = " << illegal2 << endl;
|
|
|
|
(*testout) << "loch = " << loch << endl;
|
|
|
|
*/
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
PointGeomInfo gi;
|
2012-07-05 19:02:01 +06:00
|
|
|
// bool gi_set(false);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-08-08 10:36:26 +05:00
|
|
|
/*
|
2009-11-16 13:18:00 +05:00
|
|
|
Element2d *el1p(NULL);
|
|
|
|
int l = 0;
|
2019-08-08 02:32:14 +05:00
|
|
|
while(mesh[elementsonnode[pi1][l]].IsDeleted() && l<elementsonnode[pi1].Size()) l++;
|
|
|
|
if(l<elementsonnode[pi1].Size())
|
2009-11-16 13:18:00 +05:00
|
|
|
el1p = &mesh[elementsonnode[pi1][l]];
|
|
|
|
else
|
|
|
|
cerr << "OOPS!" << endl;
|
|
|
|
|
|
|
|
for (l = 0; l < el1p->GetNP(); l++)
|
|
|
|
if ((*el1p)[l] == pi1)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2009-11-16 13:18:00 +05:00
|
|
|
gi = el1p->GeomInfoPi (l+1);
|
2012-07-05 19:02:01 +06:00
|
|
|
// gi_set = true;
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
2019-08-08 10:36:26 +05:00
|
|
|
*/
|
|
|
|
for (SurfaceElementIndex sei : elementsonnode[pi1])
|
|
|
|
{
|
|
|
|
const Element2d & el1p = mesh[sei];
|
|
|
|
if (el1p.IsDeleted()) continue;
|
|
|
|
|
|
|
|
for (int l = 0; l < el1p.GetNP(); l++)
|
|
|
|
if (el1p[l] == pi1)
|
|
|
|
// gi = el1p.GeomInfoPi (l+1);
|
|
|
|
gi = el1p.GeomInfo()[l];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
// (*testout) << "Connect point " << pi2 << " to " << pi1 << "\n";
|
2019-08-08 10:36:26 +05:00
|
|
|
// for (int k = 0; k < elementsonnode[pi2].Size(); k++)
|
|
|
|
for (SurfaceElementIndex sei2 : elementsonnode[pi2])
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
2019-08-08 10:36:26 +05:00
|
|
|
Element2d & el = mesh[sei2];
|
2019-08-08 11:44:59 +05:00
|
|
|
if (el.IsDeleted()) continue;
|
2019-08-08 10:36:26 +05:00
|
|
|
if (el.PNums().Contains(pi1)) continue;
|
2019-08-08 11:44:59 +05:00
|
|
|
|
|
|
|
for (auto l : Range(el.GetNP()))
|
2009-11-16 13:18:00 +05:00
|
|
|
{
|
|
|
|
if (el[l] == pi2)
|
|
|
|
{
|
|
|
|
el[l] = pi1;
|
2019-08-08 11:44:59 +05:00
|
|
|
el.GeomInfo()[l] = gi;
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
fixed[el[l]] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-08 10:36:26 +05:00
|
|
|
for (auto sei : hasbothpi)
|
|
|
|
mesh[sei].Delete();
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
// mesh.Compress();
|
|
|
|
mesh.SetNextTimeStamp();
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2019-09-27 23:49:12 +05:00
|
|
|
void MeshOptimize2d :: SplitImprove (Mesh & mesh)
|
|
|
|
{
|
|
|
|
if (!faceindex)
|
|
|
|
{
|
|
|
|
PrintMessage (3, "Split improve");
|
|
|
|
|
|
|
|
mesh.CalcSurfacesOfNode(); // TODO: needed?
|
|
|
|
for (faceindex = 1; faceindex <= mesh.GetNFD(); faceindex++)
|
|
|
|
{
|
|
|
|
SplitImprove (mesh);
|
|
|
|
|
|
|
|
if (multithread.terminate)
|
|
|
|
throw NgException ("Meshing stopped");
|
|
|
|
}
|
|
|
|
|
|
|
|
faceindex = 0;
|
|
|
|
mesh.Compress(); // TODO: needed?
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Array<SurfaceElementIndex> elements;
|
|
|
|
mesh.GetSurfaceElementsOfFace (faceindex, elements);
|
|
|
|
|
|
|
|
// return if we have quads in this surface
|
|
|
|
for (auto & ei : elements)
|
|
|
|
if (mesh[ei].GetNP() != 3)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// maps from edges to adjacent trigs
|
|
|
|
INDEX_2_HASHTABLE<tuple<SurfaceElementIndex, SurfaceElementIndex>> els_on_edge(2*elements.Size() + 2);
|
|
|
|
|
|
|
|
// build els_on_edge table
|
|
|
|
for (SurfaceElementIndex sei : elements)
|
|
|
|
{
|
|
|
|
const Element2d & sel = mesh[sei];
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
PointIndex pi1 = sel.PNumMod(j+2);
|
|
|
|
PointIndex pi2 = sel.PNumMod(j+3);
|
|
|
|
|
|
|
|
if (mesh.IsSegment (pi1, pi2)) continue;
|
|
|
|
|
|
|
|
INDEX_2 ii2 (pi1, pi2);
|
|
|
|
ii2.Sort();
|
|
|
|
if (els_on_edge.Used (ii2))
|
|
|
|
{
|
|
|
|
auto els = els_on_edge.Get(ii2);
|
|
|
|
get<1>(els) = sei;
|
|
|
|
els_on_edge.Set(ii2, els);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
els_on_edge.Set (ii2, make_tuple(sei, sei));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// split edges of illegal trigs
|
|
|
|
for (SurfaceElementIndex sei : elements)
|
|
|
|
{
|
|
|
|
Element2d & sel = mesh[sei];
|
|
|
|
|
|
|
|
if (sel.IsDeleted()) continue;
|
|
|
|
|
|
|
|
// TODO: split also bad trigs, nut just illegal ones
|
|
|
|
if (mesh.LegalTrig(sel)) continue;
|
|
|
|
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
{
|
|
|
|
PointIndex pi1 = sel.PNumMod(j+2);
|
|
|
|
PointIndex pi2 = sel.PNumMod(j+3);
|
|
|
|
PointIndex pi3 = sel.PNumMod(j+1);
|
|
|
|
PointIndex pi4;
|
|
|
|
PointGeomInfo gi1 = sel.GeomInfoPiMod(j+2);
|
|
|
|
PointGeomInfo gi2 = sel.GeomInfoPiMod(j+3);
|
|
|
|
PointGeomInfo gi3 = sel.GeomInfoPiMod(j+1);
|
|
|
|
PointGeomInfo gi4;
|
|
|
|
|
|
|
|
if (mesh.IsSegment (pi1, pi2)) continue;
|
|
|
|
|
|
|
|
// get neighbor element
|
|
|
|
INDEX_2 ii2 (pi1, pi2);
|
|
|
|
ii2.Sort();
|
|
|
|
auto els = els_on_edge.Get(ii2);
|
|
|
|
SurfaceElementIndex other_i = get<0>(els);
|
|
|
|
if(other_i==sei) other_i = get<1>(els);
|
|
|
|
auto & other = mesh[other_i];
|
|
|
|
|
|
|
|
// find opposite point of neighbor element
|
|
|
|
for (int j = 0; j < 3; j++)
|
|
|
|
if(other[j]!=pi1 && other[j]!=pi2)
|
|
|
|
{
|
|
|
|
pi4 = other[j];
|
|
|
|
gi4 = other.GeomInfoPi(j);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// split edge pi1,pi2
|
|
|
|
Point<3> p5;
|
|
|
|
PointIndex pi5;
|
|
|
|
PointGeomInfo gi5;
|
|
|
|
|
|
|
|
mesh.GetGeometry()->GetRefinement().PointBetween (mesh[pi1], mesh[pi2], 0.5,
|
|
|
|
faceindex,
|
|
|
|
gi1, gi2, p5, gi5);
|
|
|
|
|
|
|
|
pi5 = mesh.AddPoint(p5);
|
|
|
|
|
|
|
|
Element2d e1(3);
|
|
|
|
e1.SetIndex(faceindex);
|
|
|
|
e1={ {pi1,gi1}, {pi5,gi5}, {pi3,gi3} };
|
|
|
|
mesh.AddSurfaceElement( e1 );
|
|
|
|
|
|
|
|
Element2d e2(3);
|
|
|
|
e2.SetIndex(faceindex);
|
|
|
|
e2 ={ {pi5,gi5}, {pi2,gi2}, {pi3,gi3} };
|
|
|
|
mesh.AddSurfaceElement( e2 );
|
|
|
|
|
|
|
|
Element2d e3(3);
|
|
|
|
e3.SetIndex(faceindex);
|
|
|
|
e3 ={ {pi1,gi1}, {pi4,gi4}, {pi5,gi5} };
|
|
|
|
mesh.AddSurfaceElement( e3 );
|
|
|
|
|
|
|
|
Element2d e4(3);
|
|
|
|
e4.SetIndex(faceindex);
|
|
|
|
e4 ={ {pi4,gi4}, {pi2,gi2}, {pi5,gi5} };
|
|
|
|
mesh.AddSurfaceElement( e4 );
|
|
|
|
|
|
|
|
sel.Delete();
|
|
|
|
other.Delete();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mesh.SetNextTimeStamp();
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
void MeshOptimize2d :: CheckMeshApproximation (Mesh & mesh)
|
|
|
|
{
|
|
|
|
// Check angles between elements and normals at corners
|
|
|
|
/*
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
int i, j;
|
|
|
|
int ne = mesh.GetNSE();
|
|
|
|
int surfnr;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
Vec3d n, ng;
|
2019-07-09 13:39:16 +05:00
|
|
|
NgArray<Vec3d> ngs(3);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2017-12-05 02:32:47 +05:00
|
|
|
(*mycout) << "Check Surface Approximation" << endl;
|
|
|
|
(*testout) << "Check Surface Approximation" << endl;
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
for (i = 1; i <= ne; i++)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2009-11-16 13:18:00 +05:00
|
|
|
const Element2d & el = mesh.SurfaceElement(i);
|
|
|
|
surfnr = mesh.GetFaceDescriptor (el.GetIndex()).SurfNr();
|
|
|
|
Vec3d n = Cross (mesh.Point (el.PNum(1)) - mesh.Point (el.PNum(2)),
|
|
|
|
mesh.Point (el.PNum(1)) - mesh.Point (el.PNum(3)));
|
|
|
|
n /= n.Length();
|
2009-01-13 04:40:13 +05:00
|
|
|
|
2009-11-16 13:18:00 +05:00
|
|
|
for (j = 1; j <= el.GetNP(); j++)
|
|
|
|
{
|
|
|
|
SelectSurfaceOfPoint (mesh.Point(el.PNum(j)), el.GeomInfoPi(j));
|
|
|
|
GetNormalVector (surfnr, mesh.Point(el.PNum(j)), ng);
|
|
|
|
ng /= ng.Length();
|
|
|
|
ngs.Elem(j) = ng;
|
|
|
|
|
|
|
|
double angle = (180.0 / M_PI) * Angle (n, ng);
|
|
|
|
if (angle > 60)
|
|
|
|
{
|
|
|
|
(*testout) << "el " << i << " node " << el.PNum(j)
|
|
|
|
<< "has angle = " << angle << endl;
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
2009-11-16 13:18:00 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (j = 1; j <= 3; j++)
|
|
|
|
{
|
|
|
|
double angle = (180.0 / M_PI) * Angle (ngs.Get(j), ngs.Get(j%3+1));
|
|
|
|
if (angle > 60)
|
|
|
|
{
|
|
|
|
(*testout) << "el " << i << " node-node "
|
|
|
|
<< ngs.Get(j) << " - " << ngs.Get(j%3+1)
|
|
|
|
<< " has angle = " << angle << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|