Skip to content

Commit 49fcc60

Browse files
committed
fix function for connecting equipment
1 parent 43fbb17 commit 49fcc60

File tree

3 files changed

+35
-44
lines changed

3 files changed

+35
-44
lines changed

src/bim2fem/ifcplus/api/distribution_element.py

Lines changed: 9 additions & 24 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
16+
from typing import Literal, cast
1717
import ifcopenshell.api.system
1818
import ifcopenshell.api.root
1919
import ifcopenshell.api.spatial
@@ -26,7 +26,6 @@
2626
import numpy as np
2727
import bim2fem.ifcplus.api.system
2828
import ifcopenshell.util.representation
29-
import bim2fem.ifcplus.api.material
3029

3130

3231
ELBOW_RADIUS_TYPE = Literal["LONG", "SHORT"]
@@ -37,7 +36,7 @@ def create_elbow(
3736
horizontal_curve: bim2fem.ifcplus.util.geometry.HorizontalCurve,
3837
nominal_diameter: float,
3938
thickness: float,
40-
material: ifcopenshell.entity_instance | None = None,
39+
material: ifcopenshell.entity_instance,
4140
elbow: ifcopenshell.entity_instance | None = None,
4241
name: str | None = None,
4342
spatial_element: ifcopenshell.entity_instance | None = None,
@@ -93,13 +92,12 @@ def create_elbow(
9392
representation_type = ifcopenshell.util.representation.guess_type(
9493
items=[revolved_area_solid]
9594
)
96-
assert isinstance(representation_type, str)
9795

9896
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
9997
ifc4_file=ifc4_file,
10098
shape_model_class="IfcShapeRepresentation",
10199
representation_identifier="Body",
102-
representation_type=representation_type,
100+
representation_type=cast(str, representation_type),
103101
items=[revolved_area_solid],
104102
)
105103
ifcopenshell.api.geometry.assign_representation(
@@ -128,18 +126,6 @@ def create_elbow(
128126
place_object_relative_to_parent=place_object_relative_to_parent,
129127
)
130128

131-
if material is None:
132-
material = bim2fem.ifcplus.api.material.add_material_with_structural_properties(
133-
ifc4_file=ifc4_file,
134-
name="Galvanized Steel",
135-
category="steel",
136-
mass_density=7850.0,
137-
young_modulus=200.0e9,
138-
poisson_ratio=0.3,
139-
thermal_expansion_coefficient=1.2e-6,
140-
check_for_duplicate=True,
141-
)
142-
143129
ifcopenshell.api.material.assign_material(
144130
file=ifc4_file,
145131
products=[elbow],
@@ -298,13 +284,12 @@ def create_pipe_segment(
298284
representation_type = ifcopenshell.util.representation.guess_type(
299285
items=[extruded_area_solid]
300286
)
301-
assert isinstance(representation_type, str)
302287

303288
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
304289
ifc4_file=ifc4_file,
305290
shape_model_class="IfcShapeRepresentation",
306291
representation_identifier="Body",
307-
representation_type=representation_type,
292+
representation_type=cast(str, representation_type),
308293
items=[extruded_area_solid],
309294
)
310295
ifcopenshell.api.geometry.assign_representation(
@@ -450,14 +435,15 @@ def create_make_up_air_unit(
450435
boolean_result_or_primitive=boolean_results[-1],
451436
)
452437

453-
representation_type = ifcopenshell.util.representation.guess_type(items=[csg_solid])
454-
assert isinstance(representation_type, str)
438+
representation_type = ifcopenshell.util.representation.guess_type(
439+
items=[csg_solid],
440+
)
455441

456442
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
457443
ifc4_file=ifc4_file,
458444
shape_model_class="IfcShapeRepresentation",
459445
representation_identifier="Body",
460-
representation_type=representation_type,
446+
representation_type=cast(str, representation_type),
461447
items=[csg_solid],
462448
)
463449
ifcopenshell.api.geometry.assign_representation(
@@ -626,13 +612,12 @@ def create_air_filtration_containment_housing(
626612
)
627613

628614
representation_type = ifcopenshell.util.representation.guess_type(items=[csg_solid])
629-
assert isinstance(representation_type, str)
630615

631616
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
632617
ifc4_file=ifc4_file,
633618
shape_model_class="IfcShapeRepresentation",
634619
representation_identifier="Body",
635-
representation_type=representation_type,
620+
representation_type=cast(str, representation_type),
636621
items=[csg_solid],
637622
)
638623
ifcopenshell.api.geometry.assign_representation(

src/bim2fem/ifcplus/api/system.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,7 @@ def filter_out_colinear_points_from_polyline(
101101
) -> list[tuple[float, float, float]]:
102102

103103
def remove_items_by_indices(lst: list, indices: list) -> list:
104-
# Convert indices to a set for faster lookup
105104
indices_set = set(indices)
106-
# Use list comprehension to create a new list without the specified indices
107105
return [item for idx, item in enumerate(lst) if idx not in indices_set]
108106

109107
if len(polyline) < 3:
@@ -145,6 +143,7 @@ def remove_items_by_indices(lst: list, indices: list) -> list:
145143

146144

147145
def create_piping_system_from_polyline(
146+
ifc4_file: ifcopenshell.file,
148147
polyline: list[tuple[float, float, float]],
149148
nominal_diameter: float,
150149
thickness: float,
@@ -159,8 +158,6 @@ def create_piping_system_from_polyline(
159158
"""Create a single path pipe branch composed of IfcPipeSegments and
160159
IfcPipeFittings (Elbows)."""
161160

162-
ifc4_file = material.file
163-
164161
if len(polyline) < 2:
165162
return []
166163

@@ -235,6 +232,7 @@ def create_piping_system_from_polyline(
235232
)
236233

237234
elbow = bim2fem.ifcplus.api.distribution_element.create_elbow(
235+
ifc4_file=ifc4_file,
238236
horizontal_curve=horizontal_curve,
239237
nominal_diameter=nominal_diameter,
240238
thickness=thickness,
@@ -283,6 +281,7 @@ def create_piping_system_from_polyline(
283281

284282

285283
def connect_two_distribution_ports_via_piping_with_no_intelligence(
284+
ifc4_file: ifcopenshell.file,
286285
source_port: ifcopenshell.entity_instance,
287286
sink_port: ifcopenshell.entity_instance,
288287
nominal_diameter: float,
@@ -348,6 +347,7 @@ def connect_two_distribution_ports_via_piping_with_no_intelligence(
348347
)
349348

350349
piping_elements = create_piping_system_from_polyline(
350+
ifc4_file=ifc4_file,
351351
polyline=[
352352
source_port_origin,
353353
second_point,

tests/ifcplus/api/test_distribution_element.py

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from tests.conftest import OUTPUT_DIR_FOR_DISTRIBUTION_ELEMENT
1919
import bim2fem.ifcplus.util.geometry
2020
import numpy as np
21+
from typing import cast
2122

2223

2324
class TestAddEquipment:
@@ -151,12 +152,23 @@ def test_add_elbows(
151152
)
152153
)
153154

155+
material = bim2fem.ifcplus.api.material.add_material_with_structural_properties(
156+
ifc4_file=ifc_file_with_ventilation_distribution_system,
157+
name="Galvanized Steel",
158+
category="steel",
159+
mass_density=7850.0,
160+
young_modulus=200.0e9,
161+
poisson_ratio=0.3,
162+
thermal_expansion_coefficient=1.2e-6,
163+
check_for_duplicate=True,
164+
)
165+
154166
bim2fem.ifcplus.api.distribution_element.create_elbow(
155167
ifc4_file=ifc_file_with_ventilation_distribution_system,
156168
horizontal_curve=horizontal_curve_1,
157169
nominal_diameter=1.0,
158170
thickness=0.10,
159-
material=None,
171+
material=material,
160172
name="Elbow #1",
161173
spatial_element=site,
162174
distribution_system=distribution_system,
@@ -177,7 +189,7 @@ def test_add_elbows(
177189
horizontal_curve=horizontal_curve_2,
178190
nominal_diameter=1.0,
179191
thickness=0.10,
180-
material=None,
192+
material=material,
181193
name="Elbow #2",
182194
spatial_element=site,
183195
distribution_system=distribution_system,
@@ -198,7 +210,7 @@ def test_add_elbows(
198210
horizontal_curve=horizontal_curve_3,
199211
nominal_diameter=1.0,
200212
thickness=0.10,
201-
material=None,
213+
material=material,
202214
name="Elbow #3",
203215
spatial_element=site,
204216
distribution_system=distribution_system,
@@ -220,7 +232,7 @@ def test_add_elbows(
220232
horizontal_curve=horizontal_curve_4,
221233
nominal_diameter=1.0,
222234
thickness=0.10,
223-
material=None,
235+
material=material,
224236
name="Elbow #4",
225237
spatial_element=site,
226238
distribution_system=distribution_system,
@@ -241,7 +253,7 @@ def test_add_elbows(
241253
horizontal_curve=horizontal_curve_5,
242254
nominal_diameter=1.0,
243255
thickness=0.10,
244-
material=None,
256+
material=material,
245257
name="Elbow #5",
246258
spatial_element=site,
247259
distribution_system=distribution_system,
@@ -335,14 +347,13 @@ def test_connect_make_up_air_unit_and_hepa_filter_with_dumb_piping(
335347
)
336348
)
337349

338-
assert isinstance(steel_material, ifcopenshell.entity_instance)
339-
340350
bim2fem.ifcplus.api.system.connect_two_distribution_ports_via_piping_with_no_intelligence(
351+
ifc4_file=ifc_file_with_ventilation_distribution_system,
341352
source_port=mau_source_port,
342353
sink_port=hepa_sink_port,
343354
nominal_diameter=0.20,
344355
thickness=0.20 * 0.10,
345-
material=steel_material,
356+
material=cast(ifcopenshell.entity_instance, steel_material),
346357
distribution_system=distribution_system,
347358
elbow_radius_type="SHORT",
348359
branch_name="Branch #1",
@@ -437,15 +448,13 @@ def test_connect_make_up_air_unit_and_hepa_filter_using_ant_colony(
437448
)
438449
)
439450

440-
assert isinstance(steel_material, ifcopenshell.entity_instance)
441-
442451
bim2fem.ifcplus.api.system.connect_two_distribution_ports_via_piping_using_ant_colony(
443452
source_port=mau_source_port,
444453
sink_port=hepa_sink_port,
445454
obstacle=None,
446455
nominal_diameter=0.20,
447456
thickness=0.20 * 0.10,
448-
material=steel_material,
457+
material=cast(ifcopenshell.entity_instance, steel_material),
449458
distribution_system=distribution_system,
450459
elbow_radius_type="SHORT",
451460
branch_name="Branch #1",
@@ -540,12 +549,11 @@ def test_connect_make_up_air_unit_and_hepa_filter_using_ant_colony_with_obstacle
540549
representation_type = ifcopenshell.util.representation.guess_type(
541550
items=[csg_solid]
542551
)
543-
assert isinstance(representation_type, str)
544552
shape_model = bim2fem.ifcplus.api.geometry.add_shape_model(
545553
ifc4_file=ifc_file_with_ventilation_distribution_system,
546554
shape_model_class="IfcShapeRepresentation",
547555
representation_identifier="Body",
548-
representation_type=representation_type,
556+
representation_type=cast(str, representation_type),
549557
items=[csg_solid],
550558
)
551559
ifcopenshell.api.geometry.assign_representation(
@@ -596,15 +604,13 @@ def test_connect_make_up_air_unit_and_hepa_filter_using_ant_colony_with_obstacle
596604
)
597605
)
598606

599-
assert isinstance(steel_material, ifcopenshell.entity_instance)
600-
601607
bim2fem.ifcplus.api.system.connect_two_distribution_ports_via_piping_using_ant_colony(
602608
source_port=mau_source_port,
603609
sink_port=hepa_sink_port,
604610
obstacle=obstacle,
605611
nominal_diameter=0.20,
606612
thickness=0.20 * 0.10,
607-
material=steel_material,
613+
material=cast(ifcopenshell.entity_instance, steel_material),
608614
distribution_system=distribution_system,
609615
elbow_radius_type="SHORT",
610616
branch_name="Branch #1",

0 commit comments

Comments
 (0)