|
56 | 56 | Vector3D, |
57 | 57 | ) |
58 | 58 | from ansys.geometry.core.misc import DEFAULT_UNITS, UNITS, Accuracy, Angle, Distance |
59 | | -from ansys.geometry.core.shapes import Circle, Ellipse, Interval, ParamUV |
| 59 | +from ansys.geometry.core.shapes import ( |
| 60 | + Circle, |
| 61 | + Cone, |
| 62 | + Cylinder, |
| 63 | + Ellipse, |
| 64 | + Interval, |
| 65 | + ParamUV, |
| 66 | + Sphere, |
| 67 | + Torus, |
| 68 | +) |
| 69 | +from ansys.geometry.core.shapes.box_uv import BoxUV |
60 | 70 | from ansys.geometry.core.sketch import Sketch |
61 | 71 | from ansys.tools.visualization_interface.utils.color import Color |
62 | 72 |
|
@@ -2669,3 +2679,62 @@ def check_list_equality(lines, expected_lines): |
2669 | 2679 | " |---(body) nested_1_nested_1_comp_1_circle", |
2670 | 2680 | ] |
2671 | 2681 | assert check_list_equality(lines, ref) is True |
| 2682 | + |
| 2683 | + |
| 2684 | +def test_surface_body_creation(modeler: Modeler): |
| 2685 | + """Test surface body creation from trimmed surfaces.""" |
| 2686 | + design = modeler.create_design("Design1") |
| 2687 | + |
| 2688 | + # half sphere |
| 2689 | + surface = Sphere([0, 0, 0], 1) |
| 2690 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi * 2), Interval(0, np.pi / 2))) |
| 2691 | + body = design.create_body_from_surface("sphere", trimmed_surface) |
| 2692 | + assert len(design.bodies) == 1 |
| 2693 | + assert body.is_surface |
| 2694 | + assert body.faces[0].area.m == pytest.approx(np.pi * 2) |
| 2695 | + |
| 2696 | + # cylinder |
| 2697 | + surface = Cylinder([0, 0, 0], 1) |
| 2698 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi * 2), Interval(0, 1))) |
| 2699 | + body = design.create_body_from_surface("cylinder", trimmed_surface) |
| 2700 | + |
| 2701 | + assert len(design.bodies) == 2 |
| 2702 | + assert body.is_surface |
| 2703 | + assert body.faces[0].area.m == pytest.approx(np.pi * 2) |
| 2704 | + |
| 2705 | + # cone |
| 2706 | + surface = Cone([0, 0, 0], 1, np.pi / 4) |
| 2707 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi * 2), Interval(surface.apex.z.m, 0))) |
| 2708 | + body = design.create_body_from_surface("cone", trimmed_surface) |
| 2709 | + |
| 2710 | + assert len(design.bodies) == 3 |
| 2711 | + assert body.is_surface |
| 2712 | + assert body.faces[0].area.m == pytest.approx(4.44288293816) |
| 2713 | + |
| 2714 | + # half torus |
| 2715 | + surface = Torus([0, 0, 0], 2, 1) |
| 2716 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi), Interval(0, np.pi * 2))) |
| 2717 | + body = design.create_body_from_surface("torus", trimmed_surface) |
| 2718 | + |
| 2719 | + assert len(design.bodies) == 4 |
| 2720 | + assert body.is_surface |
| 2721 | + assert body.faces[0].area.m == pytest.approx(39.4784176044) |
| 2722 | + |
| 2723 | + # SOLID BODIES |
| 2724 | + |
| 2725 | + # sphere |
| 2726 | + surface = Sphere([0, 0, 0], 1) |
| 2727 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi * 2), Interval(-np.pi / 2, np.pi / 2))) |
| 2728 | + body = design.create_body_from_surface("sphere_solid", trimmed_surface) |
| 2729 | + assert len(design.bodies) == 5 |
| 2730 | + assert not body.is_surface |
| 2731 | + assert body.faces[0].area.m == pytest.approx(np.pi * 4) |
| 2732 | + |
| 2733 | + # torus |
| 2734 | + surface = Torus([0, 0, 0], 2, 1) |
| 2735 | + trimmed_surface = surface.trim(BoxUV(Interval(0, np.pi * 2), Interval(0, np.pi * 2))) |
| 2736 | + body = design.create_body_from_surface("torus_solid", trimmed_surface) |
| 2737 | + |
| 2738 | + assert len(design.bodies) == 6 |
| 2739 | + assert not body.is_surface |
| 2740 | + assert body.faces[0].area.m == pytest.approx(39.4784176044 * 2) |
0 commit comments