export Polyhedra to Python and add test case

This commit is contained in:
Christopher Lackner 2020-10-16 12:05:03 +02:00
parent 4cdaa6e3df
commit 1a051ec555
2 changed files with 56 additions and 0 deletions

View File

@ -354,6 +354,35 @@ When r =1, the truncated elliptic cone becomes an elliptic cylinder.
When r tends to zero, the truncated elliptic cone tends to a full elliptic cone.
However, when r = 0, the top part becomes a point(tip) and meshing fails!
)raw_string");
m.def("Polyhedron", [](py::list points, py::list faces)
{
auto poly = new Polyhedra();
for(auto p : points)
poly->AddPoint(py::cast<Point<3>>(p));
int fnr = 0;
for(auto face : faces)
{
auto lface = py::cast<py::list>(face);
if(py::len(lface) == 3)
poly->AddFace(py::cast<int>(lface[0]),
py::cast<int>(lface[1]),
py::cast<int>(lface[2]),
fnr++);
else if(py::len(lface) == 4)
{
poly->AddFace(py::cast<int>(lface[0]),
py::cast<int>(lface[1]),
py::cast<int>(lface[2]),
fnr);
poly->AddFace(py::cast<int>(lface[0]),
py::cast<int>(lface[2]),
py::cast<int>(lface[3]),
fnr++);
}
}
return make_shared<SPSolid>(new Solid(poly));
});
m.def ("Or", FunctionPointer([](shared_ptr<SPSolid> s1, shared_ptr<SPSolid> s2)
{

27
tests/pytest/test_csg.py Normal file
View File

@ -0,0 +1,27 @@
from netgen.csg import *
def test_2_polyhedra():
geo = CSGeometry()
first = Polyhedron([(0,0,0), (0,1,0), (3,1,0), (3,0,0),
(0,1,1), (3,1,1), (3,0,1), (0,0,1)],
[(0,1,2,3), (1,4,5,2), (2,5,6,3), (3,6,7,0),
(0,7,4,1), (7,6,5,4)])
# TODO: height = 0.1 not working!
height = 0.3
second = Polyhedron([(0,0,1), (0,1,1), (3,1,1), (3,0,1),
(0,1,1+height), (3,1,1+height),
(3,0,1+height), (0,0,1+height)],
[(0,1,2,3), (1,4,5,2), (2,5,6,3), (3,6,7,0),
(0,7,4,1), (7,6,5,4)])
geo.Add(first)
geo.Add(second)
Draw(geo)
mesh = geo.GenerateMesh()
return mesh
if __name__ == "__main__":
from ngsolve import Mesh, Draw
mesh = Mesh(test_2_polyhedra())
Draw(mesh)