mesh size and bcnames for 2d geometries

This commit is contained in:
Joachim Schöberl 2015-10-30 19:50:40 +01:00
parent 39cb1e0b14
commit 5bcf28d196
6 changed files with 100 additions and 57 deletions

View File

@ -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);

View File

@ -887,8 +887,18 @@ namespace netgen
void SplineGeometry2d :: SetBCName (int bcnr, string name)
{
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( const int bcnr ) const
string SplineGeometry2d :: GetBCName( int bcnr ) const
{
if (bcnames.Size() >= bcnr)
if (bcnames[bcnr-1] )
@ -896,15 +906,28 @@ namespace netgen
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;
}

View File

@ -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 );

View File

@ -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,7 +47,7 @@ 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]);
@ -77,9 +79,23 @@ DLL_HEADER void ExportGeom2d()
seg->hmax = 1e99;
seg->reffak = 1;
seg->copyfrom = -1;
seg->bc = (bc >= 0) ? bc : self.GetNSplines();
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")=-1))
}), (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);
@ -130,6 +146,10 @@ DLL_HEADER void ExportGeom2d()
.def("SetMaterial", &SplineGeometry2d::SetMaterial)
.def("SetDomainMaxH", &SplineGeometry2d::SetDomainMaxh)
.def("PlotData", FunctionPointer([](SplineGeometry2d &self)

View File

@ -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']