2009-01-13 04:40:13 +05:00
|
|
|
#include <mystdlib.h>
|
|
|
|
#include "meshing.hpp"
|
|
|
|
|
|
|
|
namespace netgen
|
|
|
|
{
|
|
|
|
|
2011-03-04 02:42:20 +05:00
|
|
|
DLL_HEADER void Optimize2d (Mesh & mesh, MeshingParameters & mp)
|
2009-01-13 04:40:13 +05:00
|
|
|
{
|
2019-06-03 13:42:32 +05:00
|
|
|
static Timer timer("optimize2d"); RegionTimer reg(timer);
|
2009-01-13 04:40:13 +05:00
|
|
|
|
|
|
|
mesh.CalcSurfacesOfNode();
|
|
|
|
|
2019-06-24 22:29:38 +05:00
|
|
|
bool secondorder = mesh.GetNP() > mesh.GetNV();
|
|
|
|
|
|
|
|
|
|
|
|
if (secondorder)
|
|
|
|
{
|
|
|
|
for (SurfaceElementIndex ei = 0; ei < mesh.GetNSE(); ei++)
|
|
|
|
mesh[ei].SetType(TRIG);
|
|
|
|
}
|
|
|
|
mesh.Compress();
|
|
|
|
|
2014-08-31 18:12:31 +06:00
|
|
|
const char * optstr = mp.optimize2d.c_str();
|
2009-01-13 04:40:13 +05:00
|
|
|
int optsteps = mp.optsteps2d;
|
|
|
|
|
2013-02-03 20:40:27 +06:00
|
|
|
for (int i = 1; i <= optsteps; i++)
|
2009-01-13 04:40:13 +05:00
|
|
|
for (size_t j = 1; j <= strlen(optstr); j++)
|
|
|
|
{
|
|
|
|
if (multithread.terminate) break;
|
|
|
|
switch (optstr[j-1])
|
|
|
|
{
|
|
|
|
case 's':
|
|
|
|
{ // topological swap
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2014-12-02 18:23:36 +05:00
|
|
|
meshopt.SetMetricWeight (mp.elsizeweight);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.EdgeSwapping (0);
|
2009-01-13 04:40:13 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'S':
|
|
|
|
{ // metric swap
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2014-12-02 18:23:36 +05:00
|
|
|
meshopt.SetMetricWeight (mp.elsizeweight);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.EdgeSwapping (1);
|
2009-01-13 04:40:13 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'm':
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2014-12-02 18:23:36 +05:00
|
|
|
meshopt.SetMetricWeight (mp.elsizeweight);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.ImproveMesh(mp);
|
2009-01-13 04:40:13 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'c':
|
|
|
|
{
|
2019-10-02 23:29:18 +05:00
|
|
|
MeshOptimize2d meshopt(mesh);
|
2014-12-02 18:23:36 +05:00
|
|
|
meshopt.SetMetricWeight (mp.elsizeweight);
|
2019-10-02 23:29:18 +05:00
|
|
|
meshopt.CombineImprove();
|
2009-01-13 04:40:13 +05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
cerr << "Optimization code " << optstr[j-1] << " not defined" << endl;
|
|
|
|
}
|
|
|
|
}
|
2020-01-09 03:27:59 +05:00
|
|
|
mesh.Compress(); // better: compress in individual steps, if necessary
|
2019-06-24 22:29:38 +05:00
|
|
|
if (secondorder)
|
|
|
|
{
|
2019-07-30 15:40:22 +05:00
|
|
|
mesh.GetGeometry()->GetRefinement().MakeSecondOrder(mesh);
|
2019-06-24 22:29:38 +05:00
|
|
|
}
|
2009-01-13 04:40:13 +05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|