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");
|
PrintMessage (1, "Generate Mesh from spline geometry");
|
||||||
|
|
||||||
double h = mp.maxh;
|
|
||||||
|
|
||||||
Box<2> bbox = geometry.GetBoundingBox ();
|
Box<2> bbox = geometry.GetBoundingBox ();
|
||||||
|
|
||||||
if (bbox.Diam() < h)
|
if (bbox.Diam() < mp.maxh)
|
||||||
{
|
mp.maxh = bbox.Diam();
|
||||||
h = bbox.Diam();
|
|
||||||
mp.maxh = h;
|
// double h = mp.maxh;
|
||||||
}
|
|
||||||
|
|
||||||
// mesh = make_shared<Mesh>();
|
// mesh = make_shared<Mesh>();
|
||||||
mesh->SetDimension (2);
|
mesh->SetDimension (2);
|
||||||
@ -372,11 +369,11 @@ namespace netgen
|
|||||||
Point3d pmax(bbox.PMax()(0), bbox.PMax()(1), bbox.Diam());
|
Point3d pmax(bbox.PMax()(0), bbox.PMax()(1), bbox.Diam());
|
||||||
|
|
||||||
mesh->SetLocalH (pmin, pmax, mp.grading);
|
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());
|
PrintMessage (3, "Boundary mesh done, np = ", mesh->GetNP());
|
||||||
|
|
||||||
@ -517,7 +514,8 @@ namespace netgen
|
|||||||
for (int domnr = 1; domnr <= maxdomnr; domnr++)
|
for (int domnr = 1; domnr <= maxdomnr; domnr++)
|
||||||
{
|
{
|
||||||
if (geometry.GetDomainTensorMeshing (domnr)) continue;
|
if (geometry.GetDomainTensorMeshing (domnr)) continue;
|
||||||
|
|
||||||
|
double h = mp.maxh;
|
||||||
if ( geometry.GetDomainMaxh ( domnr ) > 0 )
|
if ( geometry.GetDomainMaxh ( domnr ) > 0 )
|
||||||
h = geometry.GetDomainMaxh(domnr);
|
h = geometry.GetDomainMaxh(domnr);
|
||||||
|
|
||||||
|
@ -887,24 +887,47 @@ namespace netgen
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SplineGeometry2d :: SetBCName (int bcnr, string name)
|
||||||
string SplineGeometry2d :: GetBCName( const int bcnr ) const
|
|
||||||
{
|
{
|
||||||
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] )
|
if (bcnames[bcnr-1] )
|
||||||
return *bcnames[bcnr-1];
|
return *bcnames[bcnr-1];
|
||||||
return "default";
|
return "default";
|
||||||
}
|
}
|
||||||
|
|
||||||
string * SplineGeometry2d :: BCNamePtr( const int bcnr )
|
string * SplineGeometry2d :: BCNamePtr( int bcnr )
|
||||||
{
|
{
|
||||||
if ( bcnr > bcnames.Size() )
|
if ( bcnr > bcnames.Size() )
|
||||||
return 0;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return bcnames[bcnr-1];
|
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;
|
maxh[i] = 1e99;
|
||||||
|
|
||||||
if (domnr >= 1)
|
if (domnr >= 1)
|
||||||
maxh[domnr] = h;
|
maxh[domnr-1] = h;
|
||||||
else
|
else
|
||||||
throw NgException ("material index out of range");
|
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 );
|
string * BCNamePtr ( const int bcnr );
|
||||||
|
|
||||||
|
@ -19,7 +19,9 @@ DLL_HEADER void ExportGeom2d()
|
|||||||
{
|
{
|
||||||
ModuleScope module("geom2d");
|
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
|
.def("__init__", bp::make_constructor
|
||||||
(FunctionPointer
|
(FunctionPointer
|
||||||
([](const string & filename)
|
([](const string & filename)
|
||||||
@ -45,43 +47,57 @@ DLL_HEADER void ExportGeom2d()
|
|||||||
return self.geompoints.Size()-1;
|
return self.geompoints.Size()-1;
|
||||||
}),
|
}),
|
||||||
(bp::arg("self"), bp::arg("x"), bp::arg("y"), bp::arg("maxh") = 1e99))
|
(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()
|
||||||
|
|
||||||
|
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;
|
||||||
|
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()))
|
||||||
|
|
||||||
SplineSegExt * seg;
|
|
||||||
if (segtype().compare("line") == 0)
|
.def("AppendSegment", FunctionPointer([](SplineGeometry2d &self, bp::list point_indices, int leftdomain, int rightdomain)
|
||||||
{
|
{
|
||||||
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]);
|
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
|
||||||
int npts = bp::len(point_indices);
|
int npts = bp::len(point_indices);
|
||||||
SplineSegExt * seg;
|
SplineSegExt * seg;
|
||||||
//int a = bp::extract<int>(point_indices[0]);
|
//int a = bp::extract<int>(point_indices[0]);
|
||||||
@ -130,6 +146,10 @@ DLL_HEADER void ExportGeom2d()
|
|||||||
|
|
||||||
|
|
||||||
.def("SetMaterial", &SplineGeometry2d::SetMaterial)
|
.def("SetMaterial", &SplineGeometry2d::SetMaterial)
|
||||||
|
.def("SetDomainMaxH", &SplineGeometry2d::SetDomainMaxh)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
.def("PlotData", FunctionPointer([](SplineGeometry2d &self)
|
.def("PlotData", FunctionPointer([](SplineGeometry2d &self)
|
||||||
|
@ -9,7 +9,7 @@ if __platform.startswith('win'):
|
|||||||
|
|
||||||
# from libngpy import *
|
# from libngpy import *
|
||||||
import libngpy
|
import libngpy
|
||||||
|
|
||||||
from . import csg
|
from . import csg
|
||||||
from . import meshing
|
from . import meshing
|
||||||
|
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
from libngpy.geom2d import *
|
from libngpy.geom2d import *
|
||||||
from libngpy.meshing import *
|
from libngpy.meshing import *
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
tmp_generate_mesh = SplineGeometry.GenerateMesh
|
tmp_generate_mesh = SplineGeometry.GenerateMesh
|
||||||
|
|
||||||
def geom2d_meshing_func (geom, **args):
|
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:
|
for l1,l2,bc in lines:
|
||||||
unit_square.Append( ["line", pnums[l1], pnums[l2]], bc=bc)
|
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