netgen/libsrc/geom2d/geometry2d.hpp

281 lines
7.0 KiB
C++
Raw Normal View History

2009-01-13 04:40:13 +05:00
#ifndef FILE_GEOMETRY2D
#define FILE_GEOMETRY2D
/* *************************************************************************/
/* File: geometry2d.hpp */
/* Author: Joachim Schoeberl */
/* Date: 20. Jul. 02 */
/* *************************************************************************/
#include <myadt.hpp>
#include <gprim.hpp>
2020-08-19 19:46:32 +05:00
#include <meshing.hpp>
2009-01-13 04:40:13 +05:00
2009-09-07 17:50:13 +06:00
2011-02-28 18:34:54 +05:00
// #include "../gprim/spline.hpp"
2011-02-28 19:17:25 +05:00
// #include "../gprim/splinegeometry.hpp"
2009-09-07 17:50:13 +06:00
2011-02-28 17:59:27 +05:00
namespace netgen
{
class SplineSegExt : public SplineSeg<2>
{
public:
2018-12-06 21:53:44 +05:00
SplineSeg<2>* seg;
2011-02-28 17:59:27 +05:00
/// left domain
int leftdom;
/// right domain
int rightdom;
/// refinement at line
double reffak;
/// maximal h;
double hmax;
/// boundary condition number
int bc;
/// copy spline mesh from other spline (-1.. do not copy)
int copyfrom;
2018-01-08 20:45:53 +05:00
/// perform anisotropic refinement (hp-refinement) to edge
double hpref_left;
2018-01-08 20:45:53 +05:00
/// perform anisotropic refinement (hp-refinement) to edge
double hpref_right;
2011-02-28 17:59:27 +05:00
///
int layer;
2018-12-06 21:53:44 +05:00
SplineSegExt (SplineSeg<2> & hseg)
: seg(&hseg)
2011-02-28 17:59:27 +05:00
{
layer = 1;
}
2018-12-06 21:53:44 +05:00
// default constructor for archive
SplineSegExt() {}
2011-02-28 17:59:27 +05:00
2013-02-06 18:55:47 +06:00
~SplineSegExt ()
{
2018-12-06 21:53:44 +05:00
delete seg;
}
virtual void DoArchive(Archive& ar)
{
ar & seg & leftdom & rightdom & reffak & hmax & bc & copyfrom
& hpref_left & hpref_right & layer;
2013-02-06 18:55:47 +06:00
}
2011-02-28 17:59:27 +05:00
virtual const GeomPoint<2> & StartPI () const
{
2018-12-06 21:53:44 +05:00
return seg->StartPI();
2011-02-28 17:59:27 +05:00
}
virtual const GeomPoint<2> & EndPI () const
{
2018-12-06 21:53:44 +05:00
return seg->EndPI();
2011-02-28 17:59:27 +05:00
}
virtual Point<2> GetPoint (double t) const
{
2018-12-06 21:53:44 +05:00
return seg->GetPoint(t);
2011-02-28 17:59:27 +05:00
}
virtual Vec<2> GetTangent (const double t) const
{
2018-12-06 21:53:44 +05:00
return seg->GetTangent(t);
2011-02-28 17:59:27 +05:00
}
virtual void GetDerivatives (const double t,
Point<2> & point,
Vec<2> & first,
Vec<2> & second) const
{
2018-12-06 21:53:44 +05:00
seg->GetDerivatives (t, point, first, second);
2011-02-28 17:59:27 +05:00
}
virtual void GetCoeff (Vector & coeffs) const
{
2018-12-06 21:53:44 +05:00
seg->GetCoeff (coeffs);
2011-02-28 17:59:27 +05:00
}
2019-07-09 13:39:16 +05:00
virtual void GetPoints (int n, NgArray<Point<2> > & points) const
2011-02-28 17:59:27 +05:00
{
2018-12-06 21:53:44 +05:00
seg->GetPoints (n, points);
2011-02-28 17:59:27 +05:00
}
virtual double MaxCurvature () const
{
2018-12-06 21:53:44 +05:00
return seg->MaxCurvature();
2011-02-28 17:59:27 +05:00
}
virtual string GetType () const
{
2018-12-06 21:53:44 +05:00
return seg->GetType();
2011-02-28 17:59:27 +05:00
}
2012-08-27 22:07:27 +06:00
virtual double CalcCurvature (double t) const
{
Point<2> point;
Vec<2> first, second;
GetDerivatives (t, point, first, second);
double curv = fabs(first(0)*second(1)-first(1)*second(0)) / pow(first.Length(), 3);
return curv;
}
2016-09-07 12:05:03 +05:00
virtual bool InConvexHull (Point<2> p, double eps) const
{
2018-12-06 21:53:44 +05:00
return seg->InConvexHull (p, eps);
2016-09-07 12:05:03 +05:00
}
2011-02-28 17:59:27 +05:00
};
2018-12-30 19:27:48 +05:00
class SplineGeometry2d : public SplineGeometry<2>, public NetgenGeometry
2011-02-28 17:59:27 +05:00
{
protected:
2019-07-09 13:39:16 +05:00
NgArray<char*> materials;
NgArray<double> maxh;
NgArray<bool> quadmeshing;
Array<bool> tensormeshing;
2019-07-09 13:39:16 +05:00
NgArray<int> layer;
NgArray<string*> bcnames;
double elto0 = 1.0;
2011-02-28 17:59:27 +05:00
public:
2011-09-02 18:36:54 +06:00
DLL_HEADER virtual ~SplineGeometry2d();
2011-02-28 17:59:27 +05:00
2011-09-02 18:36:54 +06:00
DLL_HEADER void Load (const char * filename);
2011-02-28 17:59:27 +05:00
2011-09-02 18:36:54 +06:00
DLL_HEADER void LoadData( ifstream & infile );
DLL_HEADER void LoadDataNew ( ifstream & infile );
DLL_HEADER void LoadDataV2 ( ifstream & infile );
2011-02-28 17:59:27 +05:00
void TestComment ( ifstream & infile ) ;
void DoArchive(Archive& ar) override
2018-12-14 16:01:58 +05:00
{
SplineGeometry<2>::DoArchive(ar);
ar & materials & maxh & quadmeshing & tensormeshing & layer & bcnames & elto0;
}
2011-02-28 17:59:27 +05:00
bool ProjectPointGI (int surfind, Point<3> & p, PointGeomInfo & gi) const override
{
p(2) = 0.0;
return true;
}
void PointBetween(const Point<3> & p1, const Point<3> & p2, double secpoint,
int surfi,
const PointGeomInfo & gi1,
const PointGeomInfo & gi2,
Point<3> & newp, PointGeomInfo & newgi) const override
{
newp = p1+secpoint*(p2-p1);
newgi.trignum = 1;
}
void PointBetweenEdge(const Point<3> & p1, const Point<3> & p2, double secpoint,
int surfi1, int surfi2,
const EdgePointGeomInfo & ap1,
const EdgePointGeomInfo & ap2,
Point<3> & newp, EdgePointGeomInfo & newgi) const override;
Vec<3> GetTangent (const Point<3> & p, int surfi1, int surfi2,
const EdgePointGeomInfo & ap1) const override;
Vec<3> GetNormal(int surfi1, const Point<3> & p,
const PointGeomInfo* gi) const override;
2011-02-28 17:59:27 +05:00
const SplineSegExt & GetSpline (const int i) const
{
return dynamic_cast<const SplineSegExt&> (*splines[i]);
}
SplineSegExt & GetSpline (const int i)
{
return dynamic_cast<SplineSegExt&> (*splines[i]);
}
DLL_HEADER int GenerateMesh (shared_ptr<Mesh> & mesh, MeshingParameters & mparam) override;
2011-02-28 17:59:27 +05:00
2012-08-27 22:07:27 +06:00
void PartitionBoundary (MeshingParameters & mp, double h, Mesh & mesh2d);
2011-02-28 17:59:27 +05:00
void CopyEdgeMesh (int from, int to, Mesh & mesh2d, Point3dTree & searchtree);
size_t GetNDomains() const { return materials.Size(); }
2020-09-24 19:58:59 +05:00
DLL_HEADER void GetMaterial (int domnr, char* & material );
DLL_HEADER void SetMaterial (int domnr, const string & material);
2011-02-28 17:59:27 +05:00
double GetDomainMaxh ( const int domnr );
2015-10-21 20:49:23 +05:00
void SetDomainMaxh ( const int domnr, double maxh );
2011-02-28 17:59:27 +05:00
bool GetDomainQuadMeshing ( int domnr )
{
if ( quadmeshing.Size() ) return quadmeshing[domnr-1];
else return false;
}
2020-09-11 12:05:53 +05:00
void SetDomainQuadMeshing ( int domnr, bool quad_meshing )
{
auto oldsize = quadmeshing.Size();
if ( oldsize<domnr )
{
quadmeshing.SetSize(domnr);
for(auto dom : IntRange(oldsize, domnr-1))
quadmeshing[dom] = false;
}
quadmeshing[domnr-1] = quad_meshing;
}
2011-02-28 17:59:27 +05:00
bool GetDomainTensorMeshing ( int domnr )
{
if ( tensormeshing.Size()>=domnr ) return tensormeshing[domnr-1];
2011-02-28 17:59:27 +05:00
else return false;
}
void SetDomainTensorMeshing ( int domnr, bool tm )
{
if ( tensormeshing.Size()<domnr )
{
auto oldsize = tensormeshing.Size();
tensormeshing.SetSize(domnr);
for(auto i : IntRange(oldsize, domnr-1))
tensormeshing[i] = false;
}
tensormeshing[domnr-1] = tm;
}
2011-02-28 17:59:27 +05:00
int GetDomainLayer ( int domnr )
{
if ( layer.Size() ) return layer[domnr-1];
else return 1;
}
2021-09-01 17:34:30 +05:00
void SetDomainLayer (int domnr, int layernr)
{
auto old_size = layer.Size();
if(domnr > old_size)
{
layer.SetSize(domnr);
for(size_t i = old_size; i < domnr; i++)
layer[i] = 1;
}
layer[domnr-1] = layernr;
}
2011-02-28 17:59:27 +05:00
string GetBCName (int bcnr) const;
void SetBCName (int bcnr, string name);
int GetBCNumber (string name) const; // 0 if not exists
int AddBCName (string name);
2011-02-28 17:59:27 +05:00
string * BCNamePtr ( const int bcnr );
};
}
2009-01-13 04:40:13 +05:00
#endif