mirror of
https://github.com/NGSolve/netgen.git
synced 2025-01-25 04:10:33 +05:00
Merge branch 'netgen-matthias' into 'master'
Netgen matthias Several enhancements of the Python interface: - Cone in csg - Set/Get transparency and visibility of top level objects - Set background color (useful to display csg objects in opengl windows created with python) Changes in cpp code (and python interface): - Boundary layers with different heights/materials See merge request !1
This commit is contained in:
commit
3f944ec7d7
@ -251,6 +251,12 @@ DLL_HEADER void ExportCSG()
|
|||||||
Solid * sol = new Solid (sp);
|
Solid * sol = new Solid (sp);
|
||||||
return make_shared<SPSolid> (sol);
|
return make_shared<SPSolid> (sol);
|
||||||
}));
|
}));
|
||||||
|
bp::def ("Cone", FunctionPointer([](Point<3> a, Point<3> b, double ra, double rb)
|
||||||
|
{
|
||||||
|
Cone * cyl = new Cone (a, b, ra, rb);
|
||||||
|
Solid * sol = new Solid (cyl);
|
||||||
|
return make_shared<SPSolid> (sol);
|
||||||
|
}));
|
||||||
bp::def ("Cylinder", FunctionPointer([](Point<3> a, Point<3> b, double r)
|
bp::def ("Cylinder", FunctionPointer([](Point<3> a, Point<3> b, double r)
|
||||||
{
|
{
|
||||||
Cylinder * cyl = new Cylinder (a, b, r);
|
Cylinder * cyl = new Cylinder (a, b, r);
|
||||||
@ -350,11 +356,48 @@ DLL_HEADER void ExportCSG()
|
|||||||
}
|
}
|
||||||
delete bcname;
|
delete bcname;
|
||||||
}
|
}
|
||||||
|
return tlonr;
|
||||||
|
|
||||||
}),
|
}),
|
||||||
(bp::arg("self"), bp::arg("solid"), bp::arg("bcmod")=bp::list())
|
(bp::arg("self"), bp::arg("solid"), bp::arg("bcmod")=bp::list())
|
||||||
)
|
)
|
||||||
|
|
||||||
|
.def("CloseSurfaces", FunctionPointer
|
||||||
|
([] (CSGeometry & self, shared_ptr<SPSolid> s1, shared_ptr<SPSolid> s2, bp::list aslices )
|
||||||
|
{
|
||||||
|
Array<int> si1, si2;
|
||||||
|
s1->GetSolid()->GetSurfaceIndices (si1);
|
||||||
|
s2->GetSolid()->GetSurfaceIndices (si2);
|
||||||
|
cout << "surface ids1 = " << si1 << endl;
|
||||||
|
cout << "surface ids2 = " << si2 << endl;
|
||||||
|
|
||||||
|
Flags flags;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int n = bp::len(aslices);
|
||||||
|
Array<double> slices(n);
|
||||||
|
for(int i=0; i<n; i++)
|
||||||
|
{
|
||||||
|
slices[i]= bp::extract<double>(aslices[i])();
|
||||||
|
}
|
||||||
|
flags.SetFlag("slices", slices);
|
||||||
|
}
|
||||||
|
catch( bp::error_already_set const & ) {
|
||||||
|
cout << "caught python error:" << endl;
|
||||||
|
PyErr_Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
const TopLevelObject * domain = nullptr;
|
||||||
|
self.AddIdentification
|
||||||
|
(new CloseSurfaceIdentification
|
||||||
|
(self.GetNIdentifications()+1, self,
|
||||||
|
self.GetSurface (si1[0]), self.GetSurface (si2[0]),
|
||||||
|
domain,
|
||||||
|
flags));
|
||||||
|
}),
|
||||||
|
(bp::arg("self"), bp::arg("solid1"), bp::arg("solid2"), bp::arg("slices"))
|
||||||
|
)
|
||||||
.def("CloseSurfaces", FunctionPointer
|
.def("CloseSurfaces", FunctionPointer
|
||||||
([] (CSGeometry & self, shared_ptr<SPSolid> s1, shared_ptr<SPSolid> s2, int reflevels)
|
([] (CSGeometry & self, shared_ptr<SPSolid> s1, shared_ptr<SPSolid> s2, int reflevels)
|
||||||
{
|
{
|
||||||
@ -375,6 +418,35 @@ DLL_HEADER void ExportCSG()
|
|||||||
}),
|
}),
|
||||||
(bp::arg("self"), bp::arg("solid1"), bp::arg("solid2"), bp::arg("reflevels")=2)
|
(bp::arg("self"), bp::arg("solid1"), bp::arg("solid2"), bp::arg("reflevels")=2)
|
||||||
)
|
)
|
||||||
|
.def("GetTransparent", FunctionPointer
|
||||||
|
([] (CSGeometry & self, int tlonr)
|
||||||
|
{
|
||||||
|
return self.GetTopLevelObject(tlonr)->GetTransparent();
|
||||||
|
}),
|
||||||
|
(bp::arg("self"), bp::arg("tlonr"))
|
||||||
|
)
|
||||||
|
.def("SetTransparent", FunctionPointer
|
||||||
|
([] (CSGeometry & self, int tlonr, bool transparent)
|
||||||
|
{
|
||||||
|
self.GetTopLevelObject(tlonr)->SetTransparent(transparent);
|
||||||
|
}),
|
||||||
|
(bp::arg("self"), bp::arg("tlonr"), bp::arg("transparent"))
|
||||||
|
)
|
||||||
|
|
||||||
|
.def("GetVisible", FunctionPointer
|
||||||
|
([] (CSGeometry & self, int tlonr)
|
||||||
|
{
|
||||||
|
return self.GetTopLevelObject(tlonr)->GetVisible();
|
||||||
|
}),
|
||||||
|
(bp::arg("self"), bp::arg("tlonr"))
|
||||||
|
)
|
||||||
|
.def("SetVisible", FunctionPointer
|
||||||
|
([] (CSGeometry & self, int tlonr, bool visible)
|
||||||
|
{
|
||||||
|
self.GetTopLevelObject(tlonr)->SetVisible(visible);
|
||||||
|
}),
|
||||||
|
(bp::arg("self"), bp::arg("tlonr"), bp::arg("visible"))
|
||||||
|
)
|
||||||
|
|
||||||
.add_property ("ntlo", &CSGeometry::GetNTopLevelObjects)
|
.add_property ("ntlo", &CSGeometry::GetNTopLevelObjects)
|
||||||
;
|
;
|
||||||
|
@ -503,6 +503,8 @@ DLL_HEADER void ExportCSGVis()
|
|||||||
.def("Draw", &VisualSceneGeometry::DrawScene)
|
.def("Draw", &VisualSceneGeometry::DrawScene)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
bp::def("SetBackGroundColor", &VisualSceneGeometry::SetBackGroundColor);
|
||||||
|
|
||||||
bp::def("VS", FunctionPointer
|
bp::def("VS", FunctionPointer
|
||||||
([](CSGeometry & geom)
|
([](CSGeometry & geom)
|
||||||
{
|
{
|
||||||
|
@ -155,6 +155,7 @@ namespace netgen
|
|||||||
int prismlayers = blp.prismlayers;
|
int prismlayers = blp.prismlayers;
|
||||||
double hfirst = blp.hfirst;
|
double hfirst = blp.hfirst;
|
||||||
double growthfactor = blp.growthfactor;
|
double growthfactor = blp.growthfactor;
|
||||||
|
Array<double> heights (blp.heights);
|
||||||
|
|
||||||
bool grow_edges = false; // grow layer at edges
|
bool grow_edges = false; // grow layer at edges
|
||||||
|
|
||||||
@ -179,6 +180,12 @@ namespace netgen
|
|||||||
|
|
||||||
double layerht = hfirst;
|
double layerht = hfirst;
|
||||||
|
|
||||||
|
if(heights.Size()>0)
|
||||||
|
{
|
||||||
|
layerht = heights[layer-1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if(growthfactor == 1)
|
if(growthfactor == 1)
|
||||||
{
|
{
|
||||||
layerht = layer * hfirst;
|
layerht = layer * hfirst;
|
||||||
@ -187,6 +194,7 @@ namespace netgen
|
|||||||
{
|
{
|
||||||
layerht = hfirst*(pow(growthfactor,(layer+1)) - 1)/(growthfactor - 1);
|
layerht = hfirst*(pow(growthfactor,(layer+1)) - 1)/(growthfactor - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
cout << "Layer Height = " << layerht << endl;
|
cout << "Layer Height = " << layerht << endl;
|
||||||
|
|
||||||
@ -510,6 +518,9 @@ namespace netgen
|
|||||||
Element el(types[classify]);
|
Element el(types[classify]);
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 6; i++)
|
||||||
el[i] = nums[vertices[classify][i]];
|
el[i] = nums[vertices[classify][i]];
|
||||||
|
if(blp.new_matnrs.Size() > 0)
|
||||||
|
el.SetIndex(blp.new_matnrs[layer-1]);
|
||||||
|
else
|
||||||
el.SetIndex(blp.new_matnr);
|
el.SetIndex(blp.new_matnr);
|
||||||
// cout << "el = " << el << endl;
|
// cout << "el = " << el << endl;
|
||||||
if (classify != 0)
|
if (classify != 0)
|
||||||
|
@ -13,6 +13,8 @@ class BoundaryLayerParameters
|
|||||||
public:
|
public:
|
||||||
// parameters by Philippose ..
|
// parameters by Philippose ..
|
||||||
Array<int> surfid;
|
Array<int> surfid;
|
||||||
|
Array<double> heights;
|
||||||
|
Array<double> new_matnrs;
|
||||||
int prismlayers = 1;
|
int prismlayers = 1;
|
||||||
int bulk_matnr = 1;
|
int bulk_matnr = 1;
|
||||||
int new_matnr = 1;
|
int new_matnr = 1;
|
||||||
|
@ -337,6 +337,37 @@ DLL_HEADER void ExportNetgenMeshing()
|
|||||||
self.GetGeometry()->GetRefinement().Refine(self);
|
self.GetGeometry()->GetRefinement().Refine(self);
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
.def ("BoundaryLayer", FunctionPointer
|
||||||
|
([](Mesh & self, int bc, bp::list thicknesses, int volnr, bp::list materials)
|
||||||
|
{
|
||||||
|
int n = bp::len(thicknesses);
|
||||||
|
BoundaryLayerParameters blp;
|
||||||
|
|
||||||
|
for (int i = 1; i <= self.GetNFD(); i++)
|
||||||
|
if (self.GetFaceDescriptor(i).BCProperty() == bc)
|
||||||
|
blp.surfid.Append (i);
|
||||||
|
|
||||||
|
cout << "add layer at surfaces: " << blp.surfid << endl;
|
||||||
|
|
||||||
|
blp.prismlayers = n;
|
||||||
|
blp.growthfactor = 1.0;
|
||||||
|
|
||||||
|
// find max domain nr
|
||||||
|
int maxind = 0;
|
||||||
|
for (ElementIndex ei = 0; ei < self.GetNE(); ei++)
|
||||||
|
maxind = max (maxind, self[ei].GetIndex());
|
||||||
|
cout << "maxind = " << maxind << endl;
|
||||||
|
for ( int i=0; i<n; i++ )
|
||||||
|
{
|
||||||
|
blp.heights.Append( bp::extract<double>(thicknesses[i])()) ;
|
||||||
|
blp.new_matnrs.Append( maxind+1+i );
|
||||||
|
self.SetMaterial (maxind+1+i, bp::extract<string>(materials[i])().c_str());
|
||||||
|
}
|
||||||
|
blp.bulk_matnr = volnr;
|
||||||
|
GenerateBoundaryLayer (self, blp);
|
||||||
|
}
|
||||||
|
))
|
||||||
|
|
||||||
.def ("BoundaryLayer", FunctionPointer
|
.def ("BoundaryLayer", FunctionPointer
|
||||||
([](Mesh & self, int bc, double thickness, int volnr, string material)
|
([](Mesh & self, int bc, double thickness, int volnr, string material)
|
||||||
{
|
{
|
||||||
|
@ -14,6 +14,7 @@ if __platform.startswith('win'):
|
|||||||
|
|
||||||
|
|
||||||
CSGeometry.VS = csgvis.VS
|
CSGeometry.VS = csgvis.VS
|
||||||
|
SetBackGroundColor = csgvis.SetBackGroundColor
|
||||||
del csgvis
|
del csgvis
|
||||||
|
|
||||||
def VS (obj):
|
def VS (obj):
|
||||||
|
Loading…
Reference in New Issue
Block a user