mirror of
https://github.com/NGSolve/netgen.git
synced 2024-12-24 21:10:33 +05:00
export Polyhedra to Python and add test case
This commit is contained in:
parent
4cdaa6e3df
commit
1a051ec555
@ -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
27
tests/pytest/test_csg.py
Normal 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)
|
Loading…
Reference in New Issue
Block a user