mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
mesh size and bcnames for 2d geometries
This commit is contained in:
parent
39cb1e0b14
commit
5bcf28d196
@ -355,15 +355,12 @@ namespace netgen
|
||||
{
|
||||
PrintMessage (1, "Generate Mesh from spline geometry");
|
||||
|
||||
double h = mp.maxh;
|
||||
|
||||
Box<2> bbox = geometry.GetBoundingBox ();
|
||||
|
||||
if (bbox.Diam() < h)
|
||||
{
|
||||
h = bbox.Diam();
|
||||
mp.maxh = h;
|
||||
}
|
||||
if (bbox.Diam() < mp.maxh)
|
||||
mp.maxh = bbox.Diam();
|
||||
|
||||
// double h = mp.maxh;
|
||||
|
||||
// mesh = make_shared<Mesh>();
|
||||
mesh->SetDimension (2);
|
||||
@ -372,11 +369,11 @@ namespace netgen
|
||||
Point3d pmax(bbox.PMax()(0), bbox.PMax()(1), bbox.Diam());
|
||||
|
||||
mesh->SetLocalH (pmin, pmax, mp.grading);
|
||||
mesh->SetGlobalH (h);
|
||||
mesh->SetGlobalH (mp.maxh);
|
||||
|
||||
|
||||
|
||||
geometry.PartitionBoundary (mp, h, *mesh);
|
||||
geometry.PartitionBoundary (mp, mp.maxh, *mesh);
|
||||
|
||||
PrintMessage (3, "Boundary mesh done, np = ", mesh->GetNP());
|
||||
|
||||
@ -518,6 +515,7 @@ namespace netgen
|
||||
{
|
||||
if (geometry.GetDomainTensorMeshing (domnr)) continue;
|
||||
|
||||
double h = mp.maxh;
|
||||
if ( geometry.GetDomainMaxh ( domnr ) > 0 )
|
||||
h = geometry.GetDomainMaxh(domnr);
|
||||
|
||||
|
@ -887,24 +887,47 @@ namespace netgen
|
||||
|
||||
|
||||
|
||||
|
||||
string SplineGeometry2d :: GetBCName( const int bcnr ) const
|
||||
void SplineGeometry2d :: SetBCName (int bcnr, string name)
|
||||
{
|
||||
if ( bcnames.Size() >= bcnr)
|
||||
if (bcnr < 1)
|
||||
throw NgException ("Illegal nr in SetBCName");
|
||||
int new_to_add = bcnr - bcnames.Size();
|
||||
for (int i = 0; i < new_to_add; i++)
|
||||
bcnames.Append (new string("default"));
|
||||
delete bcnames[bcnr-1];
|
||||
bcnames[bcnr-1] = new string(name);
|
||||
}
|
||||
|
||||
string SplineGeometry2d :: GetBCName( int bcnr ) const
|
||||
{
|
||||
if (bcnames.Size() >= bcnr)
|
||||
if (bcnames[bcnr-1] )
|
||||
return *bcnames[bcnr-1];
|
||||
return "default";
|
||||
}
|
||||
|
||||
string * SplineGeometry2d :: BCNamePtr( const int bcnr )
|
||||
string * SplineGeometry2d :: BCNamePtr( int bcnr )
|
||||
{
|
||||
if ( bcnr > bcnames.Size() )
|
||||
return 0;
|
||||
return nullptr;
|
||||
else
|
||||
return bcnames[bcnr-1];
|
||||
}
|
||||
|
||||
|
||||
int SplineGeometry2d :: GetBCNumber (string name) const
|
||||
{
|
||||
for (int i = 0; i < bcnames.Size(); i++)
|
||||
if (*bcnames[i] == name)
|
||||
return i+1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SplineGeometry2d :: AddBCName (string name)
|
||||
{
|
||||
bcnames.Append (new string(name));
|
||||
return bcnames.Size();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -951,9 +974,10 @@ namespace netgen
|
||||
maxh[i] = 1e99;
|
||||
|
||||
if (domnr >= 1)
|
||||
maxh[domnr] = h;
|
||||
maxh[domnr-1] = h;
|
||||
else
|
||||
throw NgException ("material index out of range");
|
||||
cout << "maxh = " << maxh << endl;
|
||||
}
|
||||
|
||||
|
||||
|
@ -182,7 +182,10 @@ namespace netgen
|
||||
}
|
||||
|
||||
|
||||
string GetBCName ( const int bcnr ) const;
|
||||
string GetBCName (int bcnr) const;
|
||||
void SetBCName (int bcnr, string name);
|
||||
int GetBCNumber (string name) const; // 0 if not exists
|
||||
int AddBCName (string name);
|
||||
|
||||
string * BCNamePtr ( const int bcnr );
|
||||
|
||||
|
@ -19,7 +19,9 @@ DLL_HEADER void ExportGeom2d()
|
||||
{
|
||||
ModuleScope module("geom2d");
|
||||
|
||||
bp::class_<SplineGeometry2d, shared_ptr<SplineGeometry2d>, boost::noncopyable>("SplineGeometry")
|
||||
bp::class_<SplineGeometry2d, shared_ptr<SplineGeometry2d>, boost::noncopyable>
|
||||
("SplineGeometry",
|
||||
"a 2d boundary representation geometry model by lines and splines")
|
||||
.def("__init__", bp::make_constructor
|
||||
(FunctionPointer
|
||||
([](const string & filename)
|
||||
@ -45,43 +47,57 @@ DLL_HEADER void ExportGeom2d()
|
||||
return self.geompoints.Size()-1;
|
||||
}),
|
||||
(bp::arg("self"), bp::arg("x"), bp::arg("y"), bp::arg("maxh") = 1e99))
|
||||
.def("Append", FunctionPointer([](SplineGeometry2d &self, bp::list segment, int leftdomain, int rightdomain, int bc)
|
||||
.def("Append", FunctionPointer([](SplineGeometry2d &self, bp::list segment, int leftdomain, int rightdomain, bp::object bc)
|
||||
{
|
||||
bp::extract<std::string> segtype(segment[0]);
|
||||
bp::extract<std::string> segtype(segment[0]);
|
||||
|
||||
SplineSegExt * seg;
|
||||
if (segtype().compare("line") == 0)
|
||||
{
|
||||
bp::extract<int> point_index1(segment[1]);
|
||||
bp::extract<int> point_index2(segment[2]);
|
||||
//point_index1.check()
|
||||
SplineSegExt * seg;
|
||||
if (segtype().compare("line") == 0)
|
||||
{
|
||||
bp::extract<int> point_index1(segment[1]);
|
||||
bp::extract<int> point_index2(segment[2]);
|
||||
//point_index1.check()
|
||||
|
||||
LineSeg<2> * l = new LineSeg<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()));
|
||||
seg = new SplineSegExt(*l);
|
||||
}
|
||||
else if (segtype().compare("spline3") == 0)
|
||||
{
|
||||
bp::extract<int> point_index1(segment[1]);
|
||||
bp::extract<int> point_index2(segment[2]);
|
||||
bp::extract<int> point_index3(segment[3]);
|
||||
LineSeg<2> * l = new LineSeg<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()));
|
||||
seg = new SplineSegExt(*l);
|
||||
}
|
||||
else if (segtype().compare("spline3") == 0)
|
||||
{
|
||||
bp::extract<int> point_index1(segment[1]);
|
||||
bp::extract<int> point_index2(segment[2]);
|
||||
bp::extract<int> point_index3(segment[3]);
|
||||
|
||||
SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()), self.GetPoint(point_index3()));
|
||||
seg = new SplineSegExt(*seg3);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Appended segment is not a line or a spline3" << endl;
|
||||
}
|
||||
seg->leftdom = leftdomain;
|
||||
seg->rightdom = rightdomain;
|
||||
seg->hmax = 1e99;
|
||||
seg->reffak = 1;
|
||||
seg->copyfrom = -1;
|
||||
seg->bc = (bc >= 0) ? bc : self.GetNSplines();
|
||||
self.AppendSegment(seg);
|
||||
}), (bp::arg("self"), bp::arg("point_indices"), bp::arg("leftdomain") = 1, bp::arg("rightdomain") = 0, bp::arg("bc")=-1))
|
||||
.def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, bp::list point_indices, int leftdomain, int rightdomain)
|
||||
{
|
||||
SplineSeg3<2> * seg3 = new SplineSeg3<2>(self.GetPoint(point_index1()), self.GetPoint(point_index2()), self.GetPoint(point_index3()));
|
||||
seg = new SplineSegExt(*seg3);
|
||||
}
|
||||
else
|
||||
{
|
||||
cout << "Appended segment is not a line or a spline3" << endl;
|
||||
}
|
||||
seg->leftdom = leftdomain;
|
||||
seg->rightdom = rightdomain;
|
||||
seg->hmax = 1e99;
|
||||
seg->reffak = 1;
|
||||
seg->copyfrom = -1;
|
||||
if (bp::extract<int>(bc).check())
|
||||
seg->bc = bp::extract<int>(bc)();
|
||||
else if (bp::extract<string>(bc).check())
|
||||
{
|
||||
string bcname = bp::extract<string>(bc)();
|
||||
int bcnum = self.GetBCNumber(bcname);
|
||||
if (bcnum == 0)
|
||||
bcnum = self.AddBCName(bcname);
|
||||
seg->bc = bcnum;
|
||||
}
|
||||
else
|
||||
seg->bc = self.GetNSplines()+1;
|
||||
self.AppendSegment(seg);
|
||||
}), (bp::arg("self"), bp::arg("point_indices"), bp::arg("leftdomain") = 1, bp::arg("rightdomain") = 0,
|
||||
bp::arg("bc")=bp::object()))
|
||||
|
||||
|
||||
.def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, bp::list point_indices, int leftdomain, int rightdomain)
|
||||
{
|
||||
int npts = bp::len(point_indices);
|
||||
SplineSegExt * seg;
|
||||
//int a = bp::extract<int>(point_indices[0]);
|
||||
@ -130,6 +146,10 @@ DLL_HEADER void ExportGeom2d()
|
||||
|
||||
|
||||
.def("SetMaterial", &SplineGeometry2d::SetMaterial)
|
||||
.def("SetDomainMaxH", &SplineGeometry2d::SetDomainMaxh)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
.def("PlotData", FunctionPointer([](SplineGeometry2d &self)
|
||||
|
@ -1,8 +1,6 @@
|
||||
from libngpy.geom2d import *
|
||||
from libngpy.meshing import *
|
||||
|
||||
|
||||
|
||||
tmp_generate_mesh = SplineGeometry.GenerateMesh
|
||||
|
||||
def geom2d_meshing_func (geom, **args):
|
||||
@ -22,7 +20,7 @@ pnums = [unit_square.AppendPoint(*p) for p in pnts]
|
||||
for l1,l2,bc in lines:
|
||||
unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bc)
|
||||
|
||||
all = ['SplineGeometry', 'unit_square']
|
||||
__all__ = ['SplineGeometry', 'unit_square']
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user