netgen/libsrc/meshing/improve3.hpp

152 lines
4.5 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_IMPROVE3
#define FILE_IMPROVE3
namespace netgen
{
2009-01-13 04:40:13 +05:00
///
class MeshOptimize3d
{
2024-02-23 21:41:15 +05:00
Mesh & mesh;
2024-03-02 00:35:31 +05:00
const MeshingParameters & mp;
2024-02-23 21:41:15 +05:00
OPTIMIZEGOAL goal = OPT_QUALITY;
2024-02-23 22:20:14 +05:00
double min_badness = 0;
bool HasBadElement(FlatArray<ElementIndex> els);
bool HasIllegalElement(FlatArray<ElementIndex> els);
bool NeedsOptimization(FlatArray<ElementIndex> els);
2009-01-13 04:40:13 +05:00
public:
2019-08-13 21:47:35 +05:00
2024-02-23 21:41:15 +05:00
MeshOptimize3d (Mesh & m, const MeshingParameters & amp, OPTIMIZEGOAL agoal = OPT_QUALITY) :
mesh(m), mp(amp), goal(agoal) { ; }
void SetGoal(OPTIMIZEGOAL agoal) { goal = agoal; }
2024-02-23 22:20:14 +05:00
void SetMinBadness(double badness) { min_badness = badness; }
2024-02-23 21:41:15 +05:00
tuple<double, double, int> UpdateBadness();
2024-02-23 21:41:15 +05:00
double CombineImproveEdge (
Table<ElementIndex, PointIndex> & elements_of_point,
2024-02-23 22:20:14 +05:00
PointIndex pi0, PointIndex pi1,
2019-08-13 21:47:35 +05:00
FlatArray<bool, PointIndex> is_point_removed, bool check_only=false);
2024-02-23 21:41:15 +05:00
void CombineImprove ();
2019-08-13 21:47:35 +05:00
2024-02-23 21:41:15 +05:00
void SplitImprove ();
2024-02-23 22:20:14 +05:00
double SplitImproveEdge (Table<ElementIndex,PointIndex> & elementsonnode, NgArray<INDEX_3> &locfaces, double badmax, PointIndex pi1, PointIndex pi2, PointIndex ptmp, bool check_only=false);
2024-02-23 21:41:15 +05:00
void SplitImprove2 ();
2024-02-23 22:20:14 +05:00
double SplitImprove2Element (ElementIndex ei, const Table<ElementIndex, PointIndex> & elements_of_point, bool check_only);
2019-10-25 17:57:00 +05:00
2019-09-24 18:12:39 +05:00
2024-02-23 21:41:15 +05:00
double SwapImproveEdge (const NgBitArray * working_elements, Table<ElementIndex,PointIndex> & elementsonnode, INDEX_3_HASHTABLE<int> & faces, PointIndex pi1, PointIndex pi2, bool check_only=false);
void SwapImprove (const NgBitArray * working_elements = NULL);
void SwapImproveSurface (const NgBitArray * working_elements = NULL,
2019-07-09 13:39:16 +05:00
const NgArray< NgArray<int,PointIndex::BASE>* > * idmaps = NULL);
2024-02-23 21:41:15 +05:00
void SwapImprove2 ();
double SwapImprove2 (ElementIndex eli1, int face, Table<ElementIndex, PointIndex> & elementsonnode, TABLE<SurfaceElementIndex, PointIndex::BASE> & belementsonnode, bool check_only=false );
void ImproveMesh() { mesh.ImproveMesh(mp, goal); }
2009-01-13 04:40:13 +05:00
2011-07-25 17:33:19 +06:00
double
CalcBad (const Mesh::T_POINTS & points, const Element & elem, double h)
{
if (elem.GetType() == TET)
return CalcTetBadness (points[elem[0]], points[elem[1]],
points[elem[2]], points[elem[3]], h, mp);
return 0;
}
2011-07-25 17:33:19 +06:00
2024-03-12 01:10:56 +05:00
double GetLegalPenalty()
{
return goal == OPT_LEGAL ? 1e15 : 1e6;
}
2011-07-25 17:33:19 +06:00
};
2009-01-13 04:40:13 +05:00
inline double
CalcBad (const Mesh::T_POINTS & points, const Element & elem, double h, const MeshingParameters & mp)
{
if (elem.GetType() == TET)
return CalcTetBadness (points[elem[0]], points[elem[1]],
points[elem[2]], points[elem[3]], h, mp);
return 0;
}
2009-01-13 04:40:13 +05:00
extern int WrongOrientation (const Mesh::T_POINTS & points, const Element & el);
/* Functional depending of inner point inside triangular surface */
class MinFunctionSum : public MinFunction
{
protected:
2019-07-09 13:39:16 +05:00
NgArray<MinFunction*> functions;
2009-01-13 04:40:13 +05:00
public:
virtual double Func (const Vector & x) const;
virtual void Grad (const Vector & x, Vector & g) const;
virtual double FuncGrad (const Vector & x, Vector & g) const;
virtual double FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const;
virtual double GradStopping (const Vector & x) const;
void AddFunction(MinFunction & fun);
const MinFunction & Function(int i) const;
MinFunction & Function(int i);
};
class PointFunction1 : public MinFunction
{
Mesh::T_POINTS & points;
2019-07-09 13:39:16 +05:00
const NgArray<INDEX_3> & faces;
2011-07-25 17:33:19 +06:00
const MeshingParameters & mp;
2009-01-13 04:40:13 +05:00
double h;
public:
PointFunction1 (Mesh::T_POINTS & apoints,
2019-07-09 13:39:16 +05:00
const NgArray<INDEX_3> & afaces,
2011-07-25 17:33:19 +06:00
const MeshingParameters & amp,
2009-01-13 04:40:13 +05:00
double ah);
virtual double Func (const Vector & x) const;
virtual double FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const;
virtual double FuncGrad (const Vector & x, Vector & g) const;
virtual double GradStopping (const Vector & x) const;
};
class JacobianPointFunction : public MinFunction
{
public:
Mesh::T_POINTS & points;
const Array<Element, ElementIndex> & elements;
2009-01-13 04:40:13 +05:00
TABLE<INDEX> elementsonpoint;
PointIndex actpind;
bool onplane;
Vec<3> nv;
public:
JacobianPointFunction (Mesh::T_POINTS & apoints,
const Array<Element, ElementIndex> & aelements);
2014-08-19 17:01:15 +06:00
virtual ~JacobianPointFunction () { ; }
2009-01-13 04:40:13 +05:00
virtual void SetPointIndex (PointIndex aactpind);
virtual double Func (const Vector & x) const;
virtual double FuncGrad (const Vector & x, Vector & g) const;
virtual double FuncDeriv (const Vector & x, const Vector & dir, double & deriv) const;
inline void SetNV(const Vec<3> & anv) {nv = anv; onplane = true;}
inline void UnSetNV(void) {onplane = false;}
};
} // namespace netgen
2009-01-13 04:40:13 +05:00
#endif