Skip to content

Commit 65c7c4c

Browse files
authored
Merge pull request #11 from idaholab/test/add-system-tests.py
Test/add system tests.py
2 parents 9e02f69 + 865e376 commit 65c7c4c

35 files changed

+1614
-1385
lines changed

src/bim2fem/ifcplus/api/distribution_element.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import ifcopenshell.api.type
1414
import numpy as np
1515
import ifcopenshell.util.representation
16-
from typing import Literal, cast
16+
from typing import cast
1717
import ifcopenshell.api.system
1818
import ifcopenshell.api.root
1919
import ifcopenshell.api.spatial
@@ -241,18 +241,6 @@ def create_pipe_segment(
241241
object_z_axis_in_global_coordinates,
242242
)
243243

244-
object_z_axis_in_global_coordinates = (
245-
bim2fem.ifcplus.util.geometry.convert_3pt_ndarray_to_tuple_of_floats(
246-
numpy_3pt_array=object_z_axis_in_global_coordinates,
247-
)
248-
)
249-
250-
object_x_axis_in_global_coordinates = (
251-
bim2fem.ifcplus.util.geometry.convert_3pt_ndarray_to_tuple_of_floats(
252-
numpy_3pt_array=object_x_axis_in_global_coordinates,
253-
)
254-
)
255-
256244
length = float(np.linalg.norm(object_z_axis_in_global_coordinates))
257245

258246
outer_radius = nominal_diameter / 2 + thickness / 2
@@ -291,8 +279,8 @@ def create_pipe_segment(
291279
bim2fem.ifcplus.api.placement.edit_object_placement(
292280
product=pipe_segment,
293281
repositioned_origin=object_origin_in_global_coordinates,
294-
repositioned_z_axis=object_z_axis_in_global_coordinates,
295-
repositioned_x_axis=object_x_axis_in_global_coordinates,
282+
repositioned_z_axis=tuple(object_z_axis_in_global_coordinates.tolist()),
283+
repositioned_x_axis=tuple(object_x_axis_in_global_coordinates.tolist()),
296284
place_object_relative_to_parent=place_object_relative_to_parent,
297285
)
298286

src/bim2fem/ifcplus/api/geometry.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -420,35 +420,32 @@ def add_vertex_point(
420420

421421

422422
def add_edge(
423-
edge_start: ifcopenshell.entity_instance,
424-
edge_end: ifcopenshell.entity_instance,
423+
edge_start_as_vertex_point: ifcopenshell.entity_instance,
424+
edge_end_as_vertex_point: ifcopenshell.entity_instance,
425425
) -> ifcopenshell.entity_instance:
426426
"""Add an IfcEdge"""
427427

428-
assert edge_start.is_a("IfcVertexPoint")
429-
assert edge_end.is_a("IfcVertexPoint")
428+
ifc4_file = edge_start_as_vertex_point.file
430429

431-
ifc4_file = edge_start.file
432-
433-
edge = ifc4_file.createIfcEdge(edge_start, edge_end)
430+
edge = ifc4_file.createIfcEdge(
431+
edge_start_as_vertex_point,
432+
edge_end_as_vertex_point,
433+
)
434434

435435
return edge
436436

437437

438438
def add_curved_edge(
439-
vertex_point_at_point_of_curvature: ifcopenshell.entity_instance,
440-
vertex_point_at_point_of_tangency: ifcopenshell.entity_instance,
439+
point_of_curvature_as_vertex_point: ifcopenshell.entity_instance,
440+
point_of_tangency_as_vertex_point: ifcopenshell.entity_instance,
441441
center_of_curvature: tuple[float, float, float],
442442
) -> ifcopenshell.entity_instance:
443443
"""Add an IfcEdgeCurve"""
444444

445-
assert vertex_point_at_point_of_curvature.is_a("IfcVertexPoint")
446-
assert vertex_point_at_point_of_tangency.is_a("IfcVertexPoint")
447-
448-
ifc4_file = vertex_point_at_point_of_curvature.file
445+
ifc4_file = point_of_curvature_as_vertex_point.file
449446

450-
point_of_curvature = vertex_point_at_point_of_curvature.VertexGeometry.Coordinates
451-
point_of_tangency = vertex_point_at_point_of_tangency.VertexGeometry.Coordinates
447+
point_of_curvature = point_of_curvature_as_vertex_point.VertexGeometry.Coordinates
448+
point_of_tangency = point_of_tangency_as_vertex_point.VertexGeometry.Coordinates
452449

453450
radius_of_curvature = float(
454451
np.linalg.norm(np.array(point_of_curvature) - np.array(center_of_curvature))
@@ -484,8 +481,8 @@ def add_curved_edge(
484481
same_sense = True
485482

486483
edge_curve = ifc4_file.createIfcEdgeCurve(
487-
vertex_point_at_point_of_curvature,
488-
vertex_point_at_point_of_tangency,
484+
point_of_curvature_as_vertex_point,
485+
point_of_tangency_as_vertex_point,
489486
edge_geometry,
490487
same_sense,
491488
)
@@ -508,7 +505,7 @@ def add_face_bound(
508505
v2 = vertex_points_of_bound[0]
509506
else:
510507
v2 = vertex_points_of_bound[index + 1]
511-
edge = add_edge(edge_start=v1, edge_end=v2)
508+
edge = add_edge(edge_start_as_vertex_point=v1, edge_end_as_vertex_point=v2)
512509
oriented_edge = ifc4_file.create_entity(
513510
type="IfcOrientedEdge",
514511
EdgeElement=edge,

src/bim2fem/ifcplus/api/structural.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def create_linear_structural_curve_member(
105105

106106
# Add and assign representation
107107
representation_item = bim2fem.ifcplus.api.geometry.add_edge(
108-
edge_start=vertex_points[0],
109-
edge_end=vertex_points[1],
108+
edge_start_as_vertex_point=vertex_points[0],
109+
edge_end_as_vertex_point=vertex_points[1],
110110
)
111111
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
112112
ifc4_file=ifc4_file,
@@ -218,8 +218,8 @@ def create_curved_structural_curve_member(
218218

219219
# Add and assign representation
220220
representation_item = bim2fem.ifcplus.api.geometry.add_curved_edge(
221-
vertex_point_at_point_of_curvature=vertex_points[0],
222-
vertex_point_at_point_of_tangency=vertex_points[1],
221+
point_of_curvature_as_vertex_point=vertex_points[0],
222+
point_of_tangency_as_vertex_point=vertex_points[1],
223223
center_of_curvature=horizontal_curve.center_of_curvature,
224224
)
225225
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(

src/bim2fem/ifcplus/api/system.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Copyright 2025, Battelle Energy Alliance, LLC All Rights Reserved
22

3-
43
import ifcopenshell.api.system
54
import ifcopenshell.util.system
65
import bim2fem.ifcplus.api.distribution_element
@@ -156,20 +155,20 @@ def add_shape_representation_to_distribution_ports(
156155
)
157156

158157

159-
def create_piping_system_from_polyline(
158+
def create_pipe_run_from_polyline(
160159
ifc4_file: ifcopenshell.file,
161160
polyline: list[tuple[float, float, float]],
162161
nominal_diameter: float,
163162
thickness: float,
164163
material: ifcopenshell.entity_instance,
165164
distribution_system: ifcopenshell.entity_instance,
166165
elbow_radius_type: ELBOW_RADIUS_TYPE = "LONG",
167-
branch_name: str = "Unnamed Branch",
166+
branch_name: str = "Pipe Run",
168167
spatial_element: ifcopenshell.entity_instance | None = None,
169168
place_objects_relative_to_parent: bool = False,
170169
add_shape_representation_to_ports: bool = False,
171170
) -> list[ifcopenshell.entity_instance]:
172-
"""Create a single path pipe branch composed of IfcPipeSegments and
171+
"""Create a single path pipe run composed of IfcPipeSegments and
173172
IfcPipeFittings (Elbows)."""
174173

175174
if len(polyline) < 2:
@@ -299,7 +298,7 @@ def create_piping_system_from_polyline(
299298
return piping_elements
300299

301300

302-
def connect_two_distribution_ports_via_piping_with_no_intelligence(
301+
def connect_two_distribution_ports_via_pipe_run(
303302
ifc4_file: ifcopenshell.file,
304303
source_port: ifcopenshell.entity_instance,
305304
sink_port: ifcopenshell.entity_instance,
@@ -312,7 +311,7 @@ def connect_two_distribution_ports_via_piping_with_no_intelligence(
312311
spatial_element: ifcopenshell.entity_instance | None = None,
313312
add_shape_representation_to_ports: bool = False,
314313
) -> list[ifcopenshell.entity_instance]:
315-
"""Connect two IfcDistributionPorts using a single path pipe branch formed via no
314+
"""Connect two IfcDistributionPorts using a pipe run formed via no
316315
intelligent method."""
317316

318317
source_port_origin = bim2fem.ifcplus.util.system.get_port_location(
@@ -345,11 +344,13 @@ def connect_two_distribution_ports_via_piping_with_no_intelligence(
345344
).tolist()
346345
)
347346

348-
(
349-
delta_x_between_second_and_penultimate_point,
350-
delta_y_between_second_and_penultimate_point,
351-
_,
352-
) = tuple((np.array(penultimate_point) - np.array(second_point)).tolist())
347+
delta_x_between_second_and_penultimate_point = (
348+
np.array(penultimate_point) - np.array(second_point)
349+
)[0]
350+
351+
delta_y_between_second_and_penultimate_point = (
352+
np.array(penultimate_point) - np.array(second_point)
353+
)[1]
353354

354355
third_point = tuple(
355356
(
@@ -365,7 +366,7 @@ def connect_two_distribution_ports_via_piping_with_no_intelligence(
365366
).tolist()
366367
)
367368

368-
piping_elements = create_piping_system_from_polyline(
369+
piping_elements = create_pipe_run_from_polyline(
369370
ifc4_file=ifc4_file,
370371
polyline=[
371372
source_port_origin,

src/bim2fem/ifcplus/util/geometry.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -651,19 +651,11 @@ def from_3pt_polyline(
651651
- np.array(unit_vector_from_PC_to_PI) * tangent_length
652652
)
653653

654-
point_of_curvature = convert_3pt_ndarray_to_tuple_of_floats(
655-
numpy_3pt_array=point_of_curvature
656-
)
657-
658654
point_of_tangency = (
659655
np.array(point_of_intersection)
660656
+ np.array(unit_vector_from_PI_to_PT) * tangent_length
661657
)
662658

663-
point_of_tangency = convert_3pt_ndarray_to_tuple_of_floats(
664-
numpy_3pt_array=point_of_tangency
665-
)
666-
667659
unit_vector_from_PC_to_CC = calculate_cross_product_of_two_vectors(
668660
vector1=axis_of_rotation,
669661
vector2=unit_vector_from_PC_to_PI,
@@ -674,18 +666,14 @@ def from_3pt_polyline(
674666
+ np.array(unit_vector_from_PC_to_CC) * radius_of_curvature
675667
)
676668

677-
center_of_curvature = convert_3pt_ndarray_to_tuple_of_floats(
678-
numpy_3pt_array=center_of_curvature
679-
)
680-
681669
return cls(
682670
point_of_intersection=point_of_intersection,
683671
central_angle=float(central_angle),
684672
radius_of_curvature=float(radius_of_curvature),
685673
direction_of_axis_of_rotation=axis_of_rotation,
686-
point_of_curvature=point_of_curvature,
687-
point_of_tangency=point_of_tangency,
688-
center_of_curvature=center_of_curvature,
674+
point_of_curvature=tuple(point_of_curvature.tolist()),
675+
point_of_tangency=tuple(point_of_tangency.tolist()),
676+
center_of_curvature=tuple(center_of_curvature.tolist()),
689677
)
690678

691679
@classmethod
@@ -736,18 +724,14 @@ def from_PC_and_PT_and_PI(
736724
+ np.array(unit_vector_from_PC_to_CC) * radius_of_curvature
737725
)
738726

739-
center_of_curvature = convert_3pt_ndarray_to_tuple_of_floats(
740-
numpy_3pt_array=center_of_curvature
741-
)
742-
743727
return cls(
744728
point_of_intersection=point_of_intersection,
745729
central_angle=float(central_angle_of_curvature),
746730
radius_of_curvature=float(radius_of_curvature),
747731
direction_of_axis_of_rotation=axis_of_rotation,
748732
point_of_curvature=point_of_curvature,
749733
point_of_tangency=point_of_tangency,
750-
center_of_curvature=center_of_curvature,
734+
center_of_curvature=tuple(center_of_curvature.tolist()),
751735
)
752736

753737
@classmethod
@@ -801,14 +785,10 @@ def from_PC_and_PT_and_CC(
801785
* np.array(unit_vector_from_from_CC_to_PI)
802786
)
803787

804-
point_of_intersection = convert_3pt_ndarray_to_tuple_of_floats(
805-
numpy_3pt_array=point_of_intersection,
806-
)
807-
808788
return cls.from_PC_and_PT_and_PI(
809789
point_of_curvature=point_of_curvature,
810790
point_of_tangency=point_of_tangency,
811-
point_of_intersection=point_of_intersection,
791+
point_of_intersection=tuple(point_of_intersection.tolist()),
812792
)
813793

814794
@classmethod
@@ -846,13 +826,9 @@ def from_PC_and_CC_and_angle(
846826
rotated_vector
847827
)
848828

849-
point_of_tangency = convert_3pt_ndarray_to_tuple_of_floats(
850-
numpy_3pt_array=point_of_tangency
851-
)
852-
853829
return cls.from_PC_and_PT_and_CC(
854830
point_of_curvature=point_of_curvature,
855-
point_of_tangency=point_of_tangency,
831+
point_of_tangency=tuple(point_of_tangency.tolist()),
856832
point_on_center_of_curvature_side=point_of_center_of_curvature,
857833
radius_of_curvature=radius_of_curvature,
858834
)
@@ -900,11 +876,7 @@ def rotate_vector_about_axis(
900876
v * cos_angle + np.cross(k, v) * sin_angle + k * np.dot(k, v) * (1 - cos_angle)
901877
)
902878

903-
rotated_vector = convert_3pt_ndarray_to_tuple_of_floats(
904-
numpy_3pt_array=rotated_vector
905-
)
906-
907-
return rotated_vector
879+
return tuple(rotated_vector.tolist())
908880

909881

910882
def calculate_endpoint_coordinates_of_shortest_line_connecting_two_lines(

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT = OUTPUT_DIR / "distribution_element"
2929
OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT.mkdir(exist_ok=True)
3030

31+
OUTPUT_DIR_FOR_SYSTEM = OUTPUT_DIR / "system"
32+
OUTPUT_DIR_FOR_SYSTEM.mkdir(exist_ok=True)
33+
3134

3235
@pytest.fixture
3336
def empty_ifc_file() -> ifcopenshell.file:

0 commit comments

Comments
 (0)