Coverage for bim2sim/elements/bps_elements.py: 50%
802 statements
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-12 13:34 +0000
« prev ^ index » next coverage.py v7.10.3, created at 2025-08-12 13:34 +0000
1"""Module contains the different classes for all HVAC elements"""
2import inspect
3import logging
4import math
5import re
6import sys
7from datetime import date
8from typing import Set, List, Union
10import ifcopenshell
11import ifcopenshell.geom
12from OCC.Core.BRepBndLib import brepbndlib_Add
13from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_Transform
14from OCC.Core.BRepExtrema import BRepExtrema_DistShapeShape
15from OCC.Core.BRepGProp import brepgprop_SurfaceProperties
16from OCC.Core.BRepLib import BRepLib_FuseEdges
17from OCC.Core.Bnd import Bnd_Box
18from OCC.Core.Extrema import Extrema_ExtFlag_MIN
19from OCC.Core.GProp import GProp_GProps
20from OCC.Core.ShapeUpgrade import ShapeUpgrade_UnifySameDomain
21from OCC.Core.gp import gp_Trsf, gp_Vec, gp_XYZ, gp_Pnt, \
22 gp_Mat, gp_Quaternion
23from ifcopenshell import guid
25from bim2sim.elements.mapping import condition, attribute
26from bim2sim.elements.base_elements import ProductBased, RelationBased
27from bim2sim.elements.mapping.units import ureg
28from bim2sim.tasks.common.inner_loop_remover import remove_inner_loops
29from bim2sim.utilities.common_functions import vector_angle, angle_equivalent
30from bim2sim.utilities.pyocc_tools import PyOCCTools
31from bim2sim.utilities.types import IFCDomain, BoundaryOrientation
33logger = logging.getLogger(__name__)
36class BPSProduct(ProductBased):
37 domain = 'BPS'
39 def __init__(self, *args, **kwargs):
40 super().__init__(*args, **kwargs)
41 self.thermal_zones = []
42 self.space_boundaries = []
43 self.storeys = []
44 self.material = None
45 self.disaggregations = []
46 self.building = None
47 self.site = None
49 def __repr__(self):
50 return "<%s (guid: %s)>" % (
51 self.__class__.__name__, self.guid)
53 def get_bound_area(self, name) -> ureg.Quantity:
54 """ get gross bound area (including opening areas) of the element"""
55 return sum(sb.bound_area for sb in self.sbs_without_corresponding)
57 def get_net_bound_area(self, name) -> ureg.Quantity:
58 """get net area (including opening areas) of the element"""
59 return self.gross_area - self.opening_area
61 @property
62 def is_external(self) -> bool or None:
63 """Checks if the corresponding element has contact with external
64 environment (e.g. ground, roof, wall)"""
65 if hasattr(self, 'parent'):
66 return self.parent.is_external
67 elif hasattr(self, 'ifc'):
68 if hasattr(self.ifc, 'ProvidesBoundaries'):
69 if len(self.ifc.ProvidesBoundaries) > 0:
70 ext_int = list(
71 set([boundary.InternalOrExternalBoundary for boundary
72 in self.ifc.ProvidesBoundaries]))
73 if len(ext_int) == 1:
74 if ext_int[0].lower() == 'external':
75 return True
76 if ext_int[0].lower() == 'internal':
77 return False
78 else:
79 return ext_int
80 return None
82 def calc_cost_group(self) -> int:
83 """Default cost group for building elements is 300"""
84 return 300
86 def _calc_teaser_orientation(self, name) -> Union[int, None]:
87 """Calculate the orientation of the bps product based on SB direction.
89 For buildings elements we can use the more reliable space boundaries
90 normal vector to calculate the orientation if the space boundaries
91 exists. Otherwise the base calc_orientation of IFCBased will be used.
93 Returns:
94 Orientation angle between 0 and 360.
95 (0 : north, 90: east, 180: south, 270: west)
96 """
97 true_north = self.get_true_north()
98 if len(self.space_boundaries):
99 new_orientation = self.group_orientation(
100 [vector_angle(space_boundary.bound_normal.Coord())
101 for space_boundary in self.space_boundaries])
102 if new_orientation is not None:
103 return int(angle_equivalent(new_orientation + true_north))
104 # return int(angle_equivalent(super().calc_orientation() + true_north))
105 return None
107 @staticmethod
108 def group_orientation(orientations: list):
109 dict_orientations = {}
110 for orientation in orientations:
111 rounded_orientation = round(orientation)
112 if rounded_orientation not in dict_orientations:
113 dict_orientations[rounded_orientation] = 0
114 dict_orientations[rounded_orientation] += 1
115 if len(dict_orientations):
116 return max(dict_orientations, key=dict_orientations.get)
117 return None
119 def _get_sbs_without_corresponding(self, name) -> list:
120 """get a list with only not duplicated space boundaries"""
121 sbs_without_corresponding = list(self.space_boundaries)
122 for sb in self.space_boundaries:
123 if sb in sbs_without_corresponding:
124 if sb.related_bound and sb.related_bound in \
125 sbs_without_corresponding:
126 sbs_without_corresponding.remove(sb.related_bound)
127 return sbs_without_corresponding
129 def _get_opening_area(self, name):
130 """get sum of opening areas of the element"""
131 return sum(sb.opening_area for sb in self.sbs_without_corresponding)
133 teaser_orientation = attribute.Attribute(
134 description="Orientation of element in TEASER conventions. 0-360 for "
135 "orientation of vertical elements and -1 for roofs and "
136 "ceiling, -2 for groundfloors and floors.",
137 functions=[_calc_teaser_orientation],
138 )
140 gross_area = attribute.Attribute(
141 functions=[get_bound_area],
142 unit=ureg.meter ** 2
143 )
145 net_area = attribute.Attribute(
146 functions=[get_net_bound_area],
147 unit=ureg.meter ** 2
148 )
150 sbs_without_corresponding = attribute.Attribute(
151 description="A list with only not duplicated space boundaries",
152 functions=[_get_sbs_without_corresponding]
153 )
155 opening_area = attribute.Attribute(
156 description="Sum of opening areas of the element",
157 functions=[_get_opening_area]
158 )
161class ThermalZone(BPSProduct):
162 ifc_types = {
163 "IfcSpace":
164 ['*', 'SPACE', 'PARKING', 'GFA', 'INTERNAL', 'EXTERNAL']
165 }
167 pattern_ifc_type = [
168 re.compile('Space', flags=re.IGNORECASE),
169 re.compile('Zone', flags=re.IGNORECASE)
170 ]
172 def __init__(self, *args, **kwargs):
173 self.bound_elements = kwargs.pop('bound_elements', [])
174 super().__init__(*args, **kwargs)
176 @property
177 def outer_walls(self) -> list:
178 """List of all outer wall elements bounded to the thermal zone"""
179 return [
180 ele for ele in self.bound_elements if isinstance(ele, OuterWall)]
182 @property
183 def windows(self) -> list:
184 """List of all window elements bounded to the thermal zone"""
185 return [ele for ele in self.bound_elements if isinstance(ele, Window)]
187 @property
188 def is_external(self) -> bool:
189 """determines if a thermal zone is external or internal based on the
190 presence of outer walls"""
191 return len(self.outer_walls) > 0
193 def _get_external_orientation(self, name) -> str or float:
194 """determines the orientation of the thermal zone based on its elements
195 it can be a corner (list of 2 angles) or an edge (1 angle)"""
196 if self.is_external is True:
197 orientations = [ele.teaser_orientation for ele in self.outer_walls]
198 calc_temp = list(set(orientations))
199 sum_or = sum(calc_temp)
200 if 0 in calc_temp:
201 if sum_or > 180:
202 sum_or += 360
203 return sum_or / len(calc_temp)
204 return 'Internal'
206 def _get_glass_percentage(self, name) -> float or ureg.Quantity:
207 """determines the glass area/facade area ratio for all the windows in
208 the space in one of the 4 following ranges
209 0%-30%: 15
210 30%-50%: 40
211 50%-70%: 60
212 70%-100%: 85"""
213 glass_area = sum(wi.gross_area for wi in self.windows)
214 facade_area = sum(wa.gross_area for wa in self.outer_walls)
215 if facade_area > 0:
216 return 100 * (glass_area / (facade_area + glass_area)).m
217 else:
218 return 'Internal'
220 def _get_space_neighbors(self, name) -> list:
221 """determines the neighbors of the thermal zone"""
222 neighbors = []
223 for sb in self.space_boundaries:
224 if sb.related_bound is not None:
225 tz = sb.related_bound.bound_thermal_zone
226 # todo: check if computation of neighbors works as expected
227 # what if boundary has no related bound but still has a
228 # neighbor?
229 # hint: neighbors != related bounds
230 if (tz is not self) and (tz not in neighbors):
231 neighbors.append(tz)
232 return neighbors
234 def _get_space_shape(self, name):
235 """returns topods shape of the IfcSpace"""
236 settings = ifcopenshell.geom.main.settings()
237 settings.set(settings.USE_PYTHON_OPENCASCADE, True)
238 settings.set(settings.USE_WORLD_COORDS, True)
239 settings.set(settings.EXCLUDE_SOLIDS_AND_SURFACES, False)
240 settings.set(settings.INCLUDE_CURVES, True)
241 return ifcopenshell.geom.create_shape(settings, self.ifc).geometry
243 def _get_space_center(self, name) -> float:
244 """
245 This function returns the center of the bounding box of an ifc space
246 shape
247 :return: center of space bounding box (gp_Pnt)
248 """
249 bbox = Bnd_Box()
250 brepbndlib_Add(self.space_shape, bbox)
251 bbox_center = ifcopenshell.geom.utils.get_bounding_box_center(bbox)
252 return bbox_center
254 def _get_footprint_shape(self, name):
255 """
256 This function returns the footprint of a space shape. This can be
257 used e.g., to visualize floor plans.
258 """
259 footprint = PyOCCTools.get_footprint_of_shape(self.space_shape)
260 return footprint
262 def _get_space_shape_volume(self, name):
263 """
264 This function returns the volume of a space shape
265 """
266 return PyOCCTools.get_shape_volume(self.space_shape)
268 def _get_volume_geometric(self, name):
269 """
270 This function returns the volume of a space geometrically
271 """
272 return self.gross_area * self.height
274 def _get_usage(self, name):
275 """
276 This function returns the usage of a space
277 """
278 if self.zone_name is not None:
279 usage = self.zone_name
280 elif self.ifc.LongName is not None and \
281 "oldSpaceGuids_" not in self.ifc.LongName:
282 # todo oldSpaceGuids_ is hardcode for erics tool
283 usage = self.ifc.LongName
284 else:
285 usage = self.name
286 return usage
288 def _get_name(self, name):
289 """
290 This function returns the name of a space
291 """
292 if self.zone_name:
293 space_name = self.zone_name
294 else:
295 space_name = self.ifc.Name
296 return space_name
298 def get_bound_floor_area(self, name):
299 """Get bound floor area of zone. This is currently set by sum of all
300 horizontal gross area and take half of it due to issues with
301 TOP BOTTOM"""
302 leveled_areas = {}
303 for height, sbs in self.horizontal_sbs.items():
304 if height not in leveled_areas:
305 leveled_areas[height] = 0
306 leveled_areas[height] += sum([sb.bound_area for sb in sbs])
308 return sum(leveled_areas.values()) / 2
310 def get_net_bound_floor_area(self, name):
311 """Get net bound floor area of zone. This is currently set by sum of all
312 horizontal net area and take half of it due to issues with TOP BOTTOM."""
313 leveled_areas = {}
314 for height, sbs in self.horizontal_sbs.items():
315 if height not in leveled_areas:
316 leveled_areas[height] = 0
317 leveled_areas[height] += sum([sb.net_bound_area for sb in sbs])
319 return sum(leveled_areas.values()) / 2
321 def _get_horizontal_sbs(self, name):
322 """get all horizonal SBs in a zone and convert them into a dict with
323 key z-height in room and the SB as value."""
324 # todo: use only bottom when TOP bottom is working correctly
325 valid = [BoundaryOrientation.top, BoundaryOrientation.bottom]
326 leveled_sbs = {}
327 for sb in self.sbs_without_corresponding:
328 if sb.top_bottom in valid:
329 pos = round(sb.position[2], 1)
330 if pos not in leveled_sbs:
331 leveled_sbs[pos] = []
332 leveled_sbs[pos].append(sb)
334 return leveled_sbs
336 def _area_specific_post_processing(self, value):
337 return value / self.net_area
339 def _get_heating_profile(self, name) -> list:
340 """returns a heating profile using the heat temperature in the IFC"""
341 # todo make this "dynamic" with a night set back
342 if self.t_set_heat is not None:
343 return [self.t_set_heat.to(ureg.kelvin).m] * 24
345 def _get_cooling_profile(self, name) -> list:
346 """returns a cooling profile using the cool temperature in the IFC"""
347 # todo make this "dynamic" with a night set back
348 if self.t_set_cool is not None:
349 return [self.t_set_cool.to(ureg.kelvin).m] * 24
351 def _get_persons(self, name):
352 if self.area_per_occupant:
353 return 1 / self.area_per_occupant
355 external_orientation = attribute.Attribute(
356 description="Orientation of the thermal zone, either 'Internal' or a "
357 "list of 2 angles or a single angle as value between 0 and "
358 "360.",
359 functions=[_get_external_orientation]
360 )
362 glass_percentage = attribute.Attribute(
363 description="Determines the glass area/facade area ratio for all the "
364 "windows in the space in one of the 4 following ranges:"
365 " 0%-30%: 15, 30%-50%: 40, 50%-70%: 60, 70%-100%: 85.",
366 functions=[_get_glass_percentage]
367 )
369 space_neighbors = attribute.Attribute(
370 description="Determines the neighbors of the thermal zone.",
371 functions=[_get_space_neighbors]
372 )
374 space_shape = attribute.Attribute(
375 description="Returns topods shape of the IfcSpace.",
376 functions=[_get_space_shape]
377 )
379 space_center = attribute.Attribute(
380 description="Returns the center of the bounding box of an ifc space "
381 "shape.",
382 functions=[_get_space_center]
383 )
385 footprint_shape = attribute.Attribute(
386 description="Returns the footprint of a space shape, which can be "
387 "used e.g., to visualize floor plans.",
388 functions=[_get_footprint_shape]
389 )
391 horizontal_sbs = attribute.Attribute(
392 description="All horizontal space boundaries in a zone as dict. Key is"
393 " the z-zeight in the room and value the SB.",
394 functions=[_get_horizontal_sbs]
395 )
397 zone_name = attribute.Attribute(
398 default_ps=("Pset_SpaceCommon", "Reference")
399 )
401 name = attribute.Attribute(
402 functions=[_get_name]
403 )
405 usage = attribute.Attribute(
406 default_ps=("Pset_SpaceOccupancyRequirements", "OccupancyType"),
407 functions=[_get_usage]
408 )
410 t_set_heat = attribute.Attribute(
411 default_ps=("Pset_SpaceThermalRequirements", "SpaceTemperatureMin"),
412 unit=ureg.degC,
413 )
415 t_set_cool = attribute.Attribute(
416 default_ps=("Pset_SpaceThermalRequirements", "SpaceTemperatureMax"),
417 unit=ureg.degC,
418 )
420 t_ground = attribute.Attribute(
421 unit=ureg.degC,
422 default=13,
423 )
425 max_humidity = attribute.Attribute(
426 default_ps=("Pset_SpaceThermalRequirements", "SpaceHumidityMax"),
427 unit=ureg.dimensionless,
428 )
430 min_humidity = attribute.Attribute(
431 default_ps=("Pset_SpaceThermalRequirements", "SpaceHumidityMin"),
432 unit=ureg.dimensionless,
433 )
435 natural_ventilation = attribute.Attribute(
436 default_ps=("Pset_SpaceThermalRequirements", "NaturalVentilation"),
437 )
439 natural_ventilation_rate = attribute.Attribute(
440 default_ps=("Pset_SpaceThermalRequirements", "NaturalVentilationRate"),
441 unit=1 / ureg.hour,
442 )
444 mechanical_ventilation_rate = attribute.Attribute(
445 default_ps=("Pset_SpaceThermalRequirements",
446 "MechanicalVentilationRate"),
447 unit=1 / ureg.hour,
448 )
450 with_ahu = attribute.Attribute(
451 default_ps=("Pset_SpaceThermalRequirements", "AirConditioning"),
452 )
454 central_ahu = attribute.Attribute(
455 default_ps=("Pset_SpaceThermalRequirements", "AirConditioningCentral"),
456 )
458 gross_area = attribute.Attribute(
459 default_ps=("Qto_SpaceBaseQuantities", "GrossFloorArea"),
460 functions=[get_bound_floor_area],
461 unit=ureg.meter ** 2
462 )
464 net_area = attribute.Attribute(
465 default_ps=("Qto_SpaceBaseQuantities", "NetFloorArea"),
466 functions=[get_net_bound_floor_area],
467 unit=ureg.meter ** 2
468 )
470 net_wall_area = attribute.Attribute(
471 default_ps=("Qto_SpaceBaseQuantities", "NetWallArea"),
472 unit=ureg.meter ** 2
473 )
475 net_ceiling_area = attribute.Attribute(
476 default_ps=("Qto_SpaceBaseQuantities", "NetCeilingArea"),
477 unit=ureg.meter ** 2
478 )
480 net_volume = attribute.Attribute(
481 default_ps=("Qto_SpaceBaseQuantities", "NetVolume"),
482 functions=[_get_space_shape_volume, _get_volume_geometric],
483 unit=ureg.meter ** 3,
484 )
485 gross_volume = attribute.Attribute(
486 default_ps=("Qto_SpaceBaseQuantities", "GrossVolume"),
487 functions=[_get_volume_geometric],
488 unit=ureg.meter ** 3,
489 )
491 height = attribute.Attribute(
492 default_ps=("Qto_SpaceBaseQuantities", "Height"),
493 unit=ureg.meter,
494 )
496 length = attribute.Attribute(
497 default_ps=("Qto_SpaceBaseQuantities", "Length"),
498 unit=ureg.meter,
499 )
501 width = attribute.Attribute(
502 default_ps=("Qto_SpaceBaseQuantities", "Width"),
503 unit=ureg.m
504 )
506 area_per_occupant = attribute.Attribute(
507 default_ps=("Pset_SpaceOccupancyRequirements", "AreaPerOccupant"),
508 unit=ureg.meter ** 2
509 )
511 space_shape_volume = attribute.Attribute(
512 functions=[_get_space_shape_volume],
513 unit=ureg.meter ** 3,
514 )
516 clothing_persons = attribute.Attribute(
517 default_ps=("", "")
518 )
520 surround_clo_persons = attribute.Attribute(
521 default_ps=("", "")
522 )
524 heating_profile = attribute.Attribute(
525 functions=[_get_heating_profile],
526 )
528 cooling_profile = attribute.Attribute(
529 functions=[_get_cooling_profile],
530 )
532 persons = attribute.Attribute(
533 functions=[_get_persons],
534 )
536 # use conditions
537 with_cooling = attribute.Attribute(
538 )
540 with_heating = attribute.Attribute(
541 )
543 T_threshold_heating = attribute.Attribute(
544 )
546 activity_degree_persons = attribute.Attribute(
547 )
549 fixed_heat_flow_rate_persons = attribute.Attribute(
550 default_ps=("Pset_SpaceThermalLoad", "People"),
551 unit=ureg.W,
552 )
554 internal_gains_moisture_no_people = attribute.Attribute(
555 )
557 T_threshold_cooling = attribute.Attribute(
558 )
560 ratio_conv_rad_persons = attribute.Attribute(
561 default=0.5,
562 )
564 ratio_conv_rad_machines = attribute.Attribute(
565 default=0.5,
566 )
568 ratio_conv_rad_lighting = attribute.Attribute(
569 default=0.5,
570 )
572 machines = attribute.Attribute(
573 description="Specific internal gains through machines, if taken from"
574 " IFC property set a division by thermal zone area is"
575 " needed.",
576 default_ps=("Pset_SpaceThermalLoad", "EquipmentSensible"),
577 ifc_postprocessing=_area_specific_post_processing,
578 unit=ureg.W / (ureg.meter ** 2),
579 )
581 def _calc_lighting_power(self, name) -> float:
582 if self.use_maintained_illuminance:
583 return self.maintained_illuminance / self.lighting_efficiency_lumen
584 else:
585 return self.fixed_lighting_power
587 lighting_power = attribute.Attribute(
588 description="Specific lighting power in W/m2. If taken from IFC"
589 " property set a division by thermal zone area is needed.",
590 default_ps=("Pset_SpaceThermalLoad", "Lighting"),
591 ifc_postprocessing=_area_specific_post_processing,
592 functions=[_calc_lighting_power],
593 unit=ureg.W / (ureg.meter ** 2),
594 )
596 fixed_lighting_power = attribute.Attribute(
597 description="Specific fixed electrical power for lighting in W/m2. "
598 "This value is taken from SIA 2024.",
599 unit=ureg.W / (ureg.meter ** 2)
600 )
602 maintained_illuminance = attribute.Attribute(
603 description="Maintained illuminance value for lighting. This value is"
604 " taken from SIA 2024.",
605 unit=ureg.lumen / (ureg.meter ** 2)
606 )
608 use_maintained_illuminance = attribute.Attribute(
609 description="Decision variable to determine if lighting_power will"
610 " be given by fixed_lighting_power or by calculation "
611 "using the variables maintained_illuminance and "
612 "lighting_efficiency_lumen. This is not available in IFC "
613 "and can be set through the sim_setting with equivalent "
614 "name. "
615 )
617 lighting_efficiency_lumen = attribute.Attribute(
618 description="Lighting efficiency in lm/W_el, in german: Lichtausbeute.",
619 unit=ureg.lumen / ureg.W
620 )
622 use_constant_infiltration = attribute.Attribute(
623 )
625 base_infiltration = attribute.Attribute(
626 )
628 max_user_infiltration = attribute.Attribute(
629 )
631 max_overheating_infiltration = attribute.Attribute(
632 )
634 max_summer_infiltration = attribute.Attribute(
635 )
637 winter_reduction_infiltration = attribute.Attribute(
638 )
640 min_ahu = attribute.Attribute(
641 )
643 max_ahu = attribute.Attribute(
644 default_ps=("Pset_AirSideSystemInformation", "TotalAirflow"),
645 unit=ureg.meter ** 3 / ureg.s
646 )
648 with_ideal_thresholds = attribute.Attribute(
649 )
651 persons_profile = attribute.Attribute(
652 )
654 machines_profile = attribute.Attribute(
655 )
657 lighting_profile = attribute.Attribute(
658 )
660 def get__elements_by_type(self, type):
661 raise NotImplementedError
663 def __repr__(self):
664 return "<%s (usage: %s)>" \
665 % (self.__class__.__name__, self.usage)
667class ExternalSpatialElement(ThermalZone):
668 ifc_types = {
669 "IfcExternalSpatialElement":
670 ['*']
671 }
674class SpaceBoundary(RelationBased):
675 ifc_types = {'IfcRelSpaceBoundary': ['*']}
677 def __init__(self, *args, elements: dict, **kwargs):
678 """spaceboundary __init__ function"""
679 super().__init__(*args, **kwargs)
680 self.disaggregation = []
681 self.bound_element = None
682 self.disagg_parent = None
683 self.bound_thermal_zone = None
684 self._elements = elements
685 self.parent_bound = None
686 self.opening_bounds = []
688 def _calc_position(self, name):
689 """
690 calculates the position of the spaceboundary, using the relative
691 position of resultant disaggregation
692 """
693 if hasattr(self.ifc.ConnectionGeometry.SurfaceOnRelatingElement,
694 'BasisSurface'):
695 position = self.ifc.ConnectionGeometry.SurfaceOnRelatingElement. \
696 BasisSurface.Position.Location.Coordinates
697 else:
698 position = self.ifc.ConnectionGeometry.SurfaceOnRelatingElement. \
699 Position.Location.Coordinates
701 return position
703 @classmethod
704 def pre_validate(cls, ifc) -> bool:
705 return True
707 def validate_creation(self) -> bool:
708 if self.bound_area and self.bound_area < 1e-2 * ureg.meter ** 2:
709 return True
710 return False
712 def get_bound_area(self, name) -> ureg.Quantity:
713 """compute area of a space boundary"""
714 bound_prop = GProp_GProps()
715 brepgprop_SurfaceProperties(self.bound_shape, bound_prop)
716 area = bound_prop.Mass()
717 return area * ureg.meter ** 2
719 bound_area = attribute.Attribute(
720 description="The area bound by the space boundary.",
721 unit=ureg.meter ** 2,
722 functions=[get_bound_area]
723 )
725 def _get_top_bottom(self, name) -> BoundaryOrientation:
726 """
727 Determines if a boundary is a top (ceiling/roof) or bottom (floor/slab)
728 element based solely on its normal vector orientation.
730 Classification is based on the dot product between the boundary's
731 normal vector and the vertical vector (0, 0, 1):
732 - TOP: when normal points upward (dot product > cos(89°))
733 - BOTTOM: when normal points downward (dot product < cos(91°))
734 - VERTICAL: when normal is perpendicular to vertical (dot product ≈ 0)
736 Returns:
737 BoundaryOrientation: Enumerated orientation classification
738 """
739 vertical_vector = gp_XYZ(0.0, 0.0, 1.0)
740 cos_angle_top = math.cos(math.radians(89))
741 cos_angle_bottom = math.cos(math.radians(91))
743 normal_dot_vertical = vertical_vector.Dot(self.bound_normal)
745 # Classify based on dot product
746 if normal_dot_vertical > cos_angle_top:
747 return BoundaryOrientation.top
748 elif normal_dot_vertical < cos_angle_bottom:
749 return BoundaryOrientation.bottom
751 return BoundaryOrientation.vertical
753 def _get_bound_center(self, name):
754 """ compute center of the bounding box of a space boundary"""
755 p = GProp_GProps()
756 brepgprop_SurfaceProperties(self.bound_shape, p)
757 return p.CentreOfMass().XYZ()
759 def _get_related_bound(self, name):
760 """
761 Get corresponding space boundary in another space,
762 ensuring that corresponding space boundaries have a matching number of
763 vertices.
764 """
765 if hasattr(self.ifc, 'CorrespondingBoundary') and \
766 self.ifc.CorrespondingBoundary is not None:
767 corr_bound = self._elements.get(
768 self.ifc.CorrespondingBoundary.GlobalId)
769 if corr_bound:
770 nb_vert_this = PyOCCTools.get_number_of_vertices(
771 self.bound_shape)
772 nb_vert_other = PyOCCTools.get_number_of_vertices(
773 corr_bound.bound_shape)
774 # if not nb_vert_this == nb_vert_other:
775 # print("NO VERT MATCH!:", nb_vert_this, nb_vert_other)
776 if nb_vert_this == nb_vert_other:
777 return corr_bound
778 else:
779 # deal with a mismatch of vertices, due to different
780 # triangulation or for other reasons. Only applicable for
781 # small differences in the bound area between the
782 # corresponding surfaces
783 if abs(self.bound_area.m - corr_bound.bound_area.m) < 0.01:
784 # get points of the current space boundary
785 p = PyOCCTools.get_points_of_face(self.bound_shape)
786 # reverse the points and create a new face. Points
787 # have to be reverted, otherwise it would result in an
788 # incorrectly oriented surface normal
789 p.reverse()
790 new_corr_shape = PyOCCTools.make_faces_from_pnts(p)
791 # move the new shape of the corresponding boundary to
792 # the original position of the corresponding boundary
793 new_moved_corr_shape = (
794 PyOCCTools.move_bounds_to_vertical_pos([
795 new_corr_shape], corr_bound.bound_shape))[0]
796 # assign the new shape to the original shape and
797 # return the new corresponding boundary
798 corr_bound.bound_shape = new_moved_corr_shape
799 return corr_bound
800 if self.bound_element is None:
801 # return None
802 # check for virtual bounds
803 if not self.physical:
804 corr_bound = None
805 # cover virtual space boundaries without related IfcVirtualElement
806 if not self.ifc.RelatedBuildingElement:
807 vbs = [b for b in self._elements.values() if
808 isinstance(b, SpaceBoundary) and not
809 b.ifc.RelatedBuildingElement]
810 for b in vbs:
811 if b is self:
812 continue
813 if b.ifc.RelatingSpace == self.ifc.RelatingSpace:
814 continue
815 if not (b.bound_area.m - self.bound_area.m) ** 2 < 1e-2:
816 continue
817 center_dist = gp_Pnt(self.bound_center).Distance(
818 gp_Pnt(b.bound_center)) ** 2
819 if center_dist > 0.5:
820 continue
821 corr_bound = b
822 return corr_bound
823 return None
824 # cover virtual space boundaries related to an IfcVirtualElement
825 if self.ifc.RelatedBuildingElement.is_a('IfcVirtualElement'):
826 if len(self.ifc.RelatedBuildingElement.ProvidesBoundaries) == 2:
827 for bound in self.ifc.RelatedBuildingElement.ProvidesBoundaries:
828 if bound.GlobalId != self.ifc.GlobalId:
829 corr_bound = self._elements[bound.GlobalId]
830 return corr_bound
831 elif len(self.bound_element.space_boundaries) == 1:
832 return None
833 elif len(self.bound_element.space_boundaries) >= 2:
834 own_space_id = self.bound_thermal_zone.ifc.GlobalId
835 min_dist = 1000
836 corr_bound = None
837 for bound in self.bound_element.space_boundaries:
838 if bound.level_description != "2a":
839 continue
840 if bound is self:
841 continue
842 # if bound.bound_normal.Dot(self.bound_normal) != -1:
843 # continue
844 other_area = bound.bound_area
845 if (other_area.m - self.bound_area.m) ** 2 > 1e-1:
846 continue
847 center_dist = gp_Pnt(self.bound_center).Distance(
848 gp_Pnt(bound.bound_center)) ** 2
849 if abs(center_dist) > 0.5:
850 continue
851 distance = BRepExtrema_DistShapeShape(
852 bound.bound_shape,
853 self.bound_shape,
854 Extrema_ExtFlag_MIN
855 ).Value()
856 if distance > min_dist:
857 continue
858 min_dist = abs(center_dist)
859 # self.check_for_vertex_duplicates(bound)
860 nb_vert_this = PyOCCTools.get_number_of_vertices(
861 self.bound_shape)
862 nb_vert_other = PyOCCTools.get_number_of_vertices(
863 bound.bound_shape)
864 # if not nb_vert_this == nb_vert_other:
865 # print("NO VERT MATCH!:", nb_vert_this, nb_vert_other)
866 if nb_vert_this == nb_vert_other:
867 corr_bound = bound
868 return corr_bound
869 else:
870 return None
872 def _get_related_adb_bound(self, name):
873 adb_bound = None
874 if self.bound_element is None:
875 return None
876 # check for visual bounds
877 if not self.physical:
878 return None
879 if self.related_bound:
880 if self.bound_thermal_zone == self.related_bound.bound_thermal_zone:
881 adb_bound = self.related_bound
882 return adb_bound
883 for bound in self.bound_element.space_boundaries:
884 if bound == self:
885 continue
886 if not bound.bound_thermal_zone == self.bound_thermal_zone:
887 continue
888 if abs(bound.bound_area.m - self.bound_area.m) > 1e-3:
889 continue
890 if all([abs(i) < 1e-3 for i in
891 ((self.bound_normal - bound.bound_normal).Coord())]):
892 continue
893 if gp_Pnt(bound.bound_center).Distance(
894 gp_Pnt(self.bound_center)) < 0.4:
895 adb_bound = bound
896 return adb_bound
898 related_adb_bound = attribute.Attribute(
899 description="Related adiabatic boundary.",
900 functions=[_get_related_adb_bound]
901 )
903 def _get_is_physical(self, name) -> bool:
904 """
905 This function returns True if the spaceboundary is physical
906 """
907 return self.ifc.PhysicalOrVirtualBoundary.lower() == 'physical'
909 def _get_bound_shape(self, name):
910 settings = ifcopenshell.geom.settings()
911 settings.set(settings.USE_PYTHON_OPENCASCADE, True)
912 settings.set(settings.USE_WORLD_COORDS, True)
913 settings.set(settings.EXCLUDE_SOLIDS_AND_SURFACES, False)
914 settings.set(settings.INCLUDE_CURVES, True)
916 # check if the space boundary shapes need a unit conversion (i.e.,
917 # an additional transformation to the correct size and position)
918 length_unit = self.ifc_units.get('IfcLengthMeasure'.lower())
919 conv_required = length_unit != ureg.meter
921 try:
922 sore = self.ifc.ConnectionGeometry.SurfaceOnRelatingElement
923 # if sore.get_info()["InnerBoundaries"] is None:
924 shape = ifcopenshell.geom.create_shape(settings, sore)
926 if sore.InnerBoundaries:
927 # shape = remove_inner_loops(shape) # todo: return None if not horizontal shape
928 # if not shape:
929 if self.bound_element.ifc.is_a(
930 'IfcWall'): # todo: remove this hotfix (generalize)
931 ifc_new = ifcopenshell.file()
932 temp_sore = ifc_new.create_entity('IfcCurveBoundedPlane',
933 OuterBoundary=sore.OuterBoundary,
934 BasisSurface=sore.BasisSurface)
935 temp_sore.InnerBoundaries = ()
936 shape = ifcopenshell.geom.create_shape(settings, temp_sore)
937 else:
938 shape = remove_inner_loops(shape)
939 if not (sore.InnerBoundaries and not self.bound_element.ifc.is_a(
940 'IfcWall')):
941 faces = PyOCCTools.get_faces_from_shape(shape)
942 if len(faces) > 1:
943 unify = ShapeUpgrade_UnifySameDomain()
944 unify.Initialize(shape)
945 unify.Build()
946 shape = unify.Shape()
947 faces = PyOCCTools.get_faces_from_shape(shape)
948 face = faces[0]
949 face = PyOCCTools.remove_coincident_and_collinear_points_from_face(
950 face)
951 shape = face
952 except:
953 try:
954 sore = self.ifc.ConnectionGeometry.SurfaceOnRelatingElement
955 ifc_new = ifcopenshell.file()
956 temp_sore = ifc_new.create_entity('IfcCurveBoundedPlane',
957 OuterBoundary=sore.OuterBoundary,
958 BasisSurface=sore.BasisSurface)
959 temp_sore.InnerBoundaries = ()
960 shape = ifcopenshell.geom.create_shape(settings, temp_sore)
961 except:
962 poly = self.ifc.ConnectionGeometry.SurfaceOnRelatingElement.OuterBoundary.Points
963 pnts = []
964 for p in poly:
965 p.Coordinates = (p.Coordinates[0], p.Coordinates[1], 0.0)
966 pnts.append((p.Coordinates[:]))
967 shape = PyOCCTools.make_faces_from_pnts(pnts)
968 shape = BRepLib_FuseEdges(shape).Shape()
970 if conv_required:
971 # scale newly created shape of space boundary to correct size
972 conv_factor = (1 * length_unit).to(
973 ureg.metre).m
974 # shape scaling seems to be covered by ifcopenshell, obsolete
975 # shape = PyOCCTools.scale_shape(shape, conv_factor, gp_Pnt(0, 0,
976 # 0))
978 if self.ifc.RelatingSpace.ObjectPlacement:
979 lp = PyOCCTools.local_placement(
980 self.ifc.RelatingSpace.ObjectPlacement).tolist()
981 # transform newly created shape of space boundary to correct
982 # position if a unit conversion is required.
983 if conv_required:
984 for i in range(len(lp)):
985 for j in range(len(lp[i])):
986 coord = lp[i][j] * length_unit
987 lp[i][j] = coord.to(ureg.meter).m
988 mat = gp_Mat(lp[0][0], lp[0][1], lp[0][2], lp[1][0], lp[1][1],
989 lp[1][2], lp[2][0], lp[2][1], lp[2][2])
990 vec = gp_Vec(lp[0][3], lp[1][3], lp[2][3])
991 trsf = gp_Trsf()
992 trsf.SetTransformation(gp_Quaternion(mat), vec)
993 shape = BRepBuilderAPI_Transform(shape, trsf).Shape()
995 # shape = shape.Reversed()
996 unify = ShapeUpgrade_UnifySameDomain()
997 unify.Initialize(shape)
998 unify.Build()
999 shape = unify.Shape()
1001 if self.bound_element is not None:
1002 bi = self.bound_element
1003 if not hasattr(bi, "related_openings"):
1004 return shape
1005 if len(bi.related_openings) == 0:
1006 return shape
1007 shape = PyOCCTools.get_face_from_shape(shape)
1008 return shape
1010 def get_level_description(self, name) -> str:
1011 """
1012 This function returns the level description of the spaceboundary
1013 """
1014 return self.ifc.Description
1016 def _get_is_external(self, name) -> Union[None, bool]:
1017 """
1018 This function returns True if the spaceboundary is external
1019 """
1020 if self.ifc.InternalOrExternalBoundary is not None:
1021 ifc_ext_internal = self.ifc.InternalOrExternalBoundary.lower()
1022 if ifc_ext_internal == 'internal':
1023 return False
1024 elif 'external' in ifc_ext_internal:
1025 return True
1026 else:
1027 return None
1028 # return not self.ifc.InternalOrExternalBoundary.lower() == 'internal'
1030 def _get_opening_area(self, name):
1031 """
1032 This function returns the opening area of the spaceboundary
1033 """
1034 if self.opening_bounds:
1035 return sum(opening_boundary.bound_area for opening_boundary
1036 in self.opening_bounds)
1037 return 0
1039 def _get_net_bound_area(self, name):
1040 """
1041 This function returns the net bound area of the spaceboundary
1042 """
1043 return self.bound_area - self.opening_area
1045 is_external = attribute.Attribute(
1046 description="True if the Space Boundary is external",
1047 functions=[_get_is_external]
1048 )
1050 bound_shape = attribute.Attribute(
1051 description="Bound shape element of the SB.",
1052 functions=[_get_bound_shape]
1053 )
1055 top_bottom = attribute.Attribute(
1056 description="Info if the SB is top "
1057 "(ceiling etc.) or bottom (floor etc.).",
1058 functions=[_get_top_bottom]
1059 )
1061 bound_center = attribute.Attribute(
1062 description="The center of the space boundary.",
1063 functions=[_get_bound_center]
1064 )
1066 related_bound = attribute.Attribute(
1067 description="Related space boundary.",
1068 functions=[_get_related_bound]
1069 )
1071 physical = attribute.Attribute(
1072 description="If the Space Boundary is physical or not.",
1073 functions=[_get_is_physical]
1074 )
1076 opening_area = attribute.Attribute(
1077 description="Opening area of the Space Boundary.",
1078 functions = [_get_opening_area]
1079 )
1081 net_bound_area = attribute.Attribute(
1082 description="Net bound area of the Space Boundary",
1083 functions=[_get_net_bound_area]
1084 )
1086 def _get_bound_normal(self, name):
1087 """
1088 This function returns the normal vector of the spaceboundary
1089 """
1090 return PyOCCTools.simple_face_normal(self.bound_shape)
1092 bound_normal = attribute.Attribute(
1093 description="Normal vector of the Space Boundary.",
1094 functions=[_get_bound_normal]
1095 )
1097 level_description = attribute.Attribute(
1098 functions=[get_level_description],
1099 # Todo this should be removed in near future. We should either
1100 # find # a way to distinguish the level of SB by something
1101 # different or should check this during the creation of SBs
1102 # and throw an error if the level is not defined.
1103 default='2a'
1104 # HACK: Rou's Model has 2a boundaries but, the description is None,
1105 # default set to 2a to temporary solve this problem
1106 )
1108 internal_external_type = attribute.Attribute(
1109 description="Defines, whether the Space Boundary is internal"
1110 " (Internal), or external, i.e. adjacent to open space "
1111 "(that can be an partially enclosed space, such as terrace"
1112 " (External",
1113 ifc_attr_name="InternalOrExternalBoundary"
1114 )
1117class ExtSpatialSpaceBoundary(SpaceBoundary):
1118 """describes all space boundaries related to an IfcExternalSpatialElement instead of an IfcSpace"""
1119 pass
1122class SpaceBoundary2B(SpaceBoundary):
1123 """describes all newly created space boundaries of type 2b to fill gaps within spaces"""
1125 def __init__(self, *args, elements=None, **kwargs):
1126 super(SpaceBoundary2B, self).__init__(*args, elements=None, **kwargs)
1127 self.ifc = ifcopenshell.create_entity('IfcRelSpaceBoundary')
1128 self.guid = None
1129 self.bound_shape = None
1130 self.thermal_zones = []
1131 self.bound_element = None
1132 self.physical = True
1133 self.is_external = False
1134 self.related_bound = None
1135 self.related_adb_bound = None
1136 self.level_description = '2b'
1139class BPSProductWithLayers(BPSProduct):
1140 ifc_types = {}
1142 def __init__(self, *args, **kwargs):
1143 """BPSProductWithLayers __init__ function.
1145 Convention in bim2sim for layerset is layer 0 is inside,
1146 layer n is outside.
1147 """
1148 super().__init__(*args, **kwargs)
1149 self.layerset = None
1151 def get_u_value(self, name):
1152 """wall get_u_value function"""
1153 layers_r = 0
1154 for layer in self.layerset.layers:
1155 if layer.thickness:
1156 if layer.material.thermal_conduc and \
1157 layer.material.thermal_conduc > 0:
1158 layers_r += layer.thickness / layer.material.thermal_conduc
1160 if layers_r > 0:
1161 return 1 / layers_r
1162 return None
1164 def get_thickness_by_layers(self, name):
1165 """calculate the total thickness of the product based on the thickness
1166 of each layer."""
1167 thickness = 0
1168 for layer in self.layerset.layers:
1169 if layer.thickness:
1170 thickness += layer.thickness
1171 return thickness
1174class Wall(BPSProductWithLayers):
1175 """Abstract wall class, only its subclasses Inner- and Outerwalls are used.
1177 Every element where self.is_external is not True, is an InnerWall.
1178 """
1179 ifc_types = {
1180 "IfcWall":
1181 ['*', 'MOVABLE', 'PARAPET', 'PARTITIONING', 'PLUMBINGWALL',
1182 'SHEAR', 'SOLIDWALL', 'POLYGONAL', 'DOOR', 'GATE', 'TRAPDOOR'],
1183 "IfcWallStandardCase":
1184 ['*', 'MOVABLE', 'PARAPET', 'PARTITIONING', 'PLUMBINGWALL',
1185 'SHEAR', 'SOLIDWALL', 'POLYGONAL', 'DOOR', 'GATE', 'TRAPDOOR'],
1186 # "IfcElementedCase": "?" # TODO
1187 }
1189 conditions = [
1190 condition.RangeCondition('u_value',
1191 0 * ureg.W / ureg.K / ureg.meter ** 2,
1192 5 * ureg.W / ureg.K / ureg.meter ** 2,
1193 critical_for_creation=False),
1194 condition.UValueCondition('u_value',
1195 threshold=0.2,
1196 critical_for_creation=False),
1197 ]
1199 pattern_ifc_type = [
1200 re.compile('Wall', flags=re.IGNORECASE),
1201 re.compile('Wand', flags=re.IGNORECASE)
1202 ]
1204 def __init__(self, *args, **kwargs):
1205 """wall __init__ function"""
1206 super().__init__(*args, **kwargs)
1208 def get_better_subclass(self):
1209 return OuterWall if self.is_external else InnerWall
1211 net_area = attribute.Attribute(
1212 default_ps=("Qto_WallBaseQuantities", "NetSideArea"),
1213 functions=[BPSProduct.get_net_bound_area],
1214 unit=ureg.meter ** 2
1215 )
1217 gross_area = attribute.Attribute(
1218 default_ps=("Qto_WallBaseQuantities", "GrossSideArea"),
1219 functions=[BPSProduct.get_bound_area],
1220 unit=ureg.meter ** 2
1221 )
1223 tilt = attribute.Attribute(
1224 default=90
1225 )
1227 u_value = attribute.Attribute(
1228 default_ps=("Pset_WallCommon", "ThermalTransmittance"),
1229 unit=ureg.W / ureg.K / ureg.meter ** 2,
1230 functions=[BPSProductWithLayers.get_u_value],
1231 )
1233 width = attribute.Attribute(
1234 default_ps=("Qto_WallBaseQuantities", "Width"),
1235 functions=[BPSProductWithLayers.get_thickness_by_layers],
1236 unit=ureg.m
1237 )
1239 inner_convection = attribute.Attribute(
1240 unit=ureg.W / ureg.K / ureg.meter ** 2,
1241 default=0.6
1242 )
1244 is_load_bearing = attribute.Attribute(
1245 default_ps=("Pset_WallCommon", "LoadBearing"),
1246 )
1248 net_volume = attribute.Attribute(
1249 default_ps=("Qto_WallBaseQuantities", "NetVolume"),
1250 unit=ureg.meter ** 3
1251 )
1253 gross_volume = attribute.Attribute(
1254 default_ps=("Qto_WallBaseQuantities", "GrossVolume")
1255 )
1258class Layer(BPSProduct):
1259 """Represents the IfcMaterialLayer class."""
1260 ifc_types = {
1261 "IfcMaterialLayer": ["*"],
1262 }
1263 guid_prefix = "Layer_"
1265 conditions = [
1266 condition.RangeCondition('thickness',
1267 0 * ureg.m,
1268 10 * ureg.m,
1269 critical_for_creation=False, incl_edges=False)
1270 ]
1272 def __init__(self, *args, **kwargs):
1273 """layer __init__ function"""
1274 super().__init__(*args, **kwargs)
1275 self.to_layerset: List[LayerSet] = []
1276 self.parent = None
1277 self.material = None
1279 @staticmethod
1280 def get_id(prefix=""):
1281 prefix_length = len(prefix)
1282 if prefix_length > 10:
1283 raise AttributeError("Max prefix length is 10!")
1284 ifcopenshell_guid = guid.new()[prefix_length + 1:]
1285 return f"{prefix}{ifcopenshell_guid}"
1287 @classmethod
1288 def pre_validate(cls, ifc) -> bool:
1289 return True
1291 def validate_creation(self) -> bool:
1292 return True
1294 def _get_thickness(self, name):
1295 """layer thickness function"""
1296 if hasattr(self.ifc, 'LayerThickness'):
1297 return self.ifc.LayerThickness * ureg.meter
1298 else:
1299 return float('nan') * ureg.meter
1301 thickness = attribute.Attribute(
1302 unit=ureg.m,
1303 functions=[_get_thickness]
1304 )
1306 is_ventilated = attribute.Attribute(
1307 description="Indication of whether the material layer represents an "
1308 "air layer (or cavity).",
1309 ifc_attr_name="IsVentilated",
1310 )
1312 description = attribute.Attribute(
1313 description="Definition of the material layer in more descriptive "
1314 "terms than given by attributes Name or Category.",
1315 ifc_attr_name="Description",
1316 )
1318 category = attribute.Attribute(
1319 description="Category of the material layer, e.g. the role it has in"
1320 " the layer set it belongs to (such as 'load bearing', "
1321 "'thermal insulation' etc.). The list of keywords might be"
1322 " extended by model view definitions, however the "
1323 "following keywords shall apply in general:",
1324 ifc_attr_name="Category",
1325 )
1327 def __repr__(self):
1328 return "<%s (material: %s>" \
1329 % (self.__class__.__name__, self.material)
1332class LayerSet(BPSProduct):
1333 """Represents a Layerset in bim2sim.
1335 Convention in bim2sim for layerset is layer 0 is inside,
1336 layer n is outside.
1338 # TODO: when not enriching we currently don't check layer orientation.
1339 """
1341 ifc_types = {
1342 "IfcMaterialLayerSet": ["*"],
1343 }
1345 guid_prefix = "LayerSet_"
1346 conditions = [
1347 condition.ListCondition('layers',
1348 critical_for_creation=False),
1349 condition.ThicknessCondition('total_thickness',
1350 threshold=0.2,
1351 critical_for_creation=False),
1352 ]
1354 def __init__(self, *args, **kwargs):
1355 """layerset __init__ function"""
1356 super().__init__(*args, **kwargs)
1357 self.parents: List[BPSProductWithLayers] = []
1358 self.layers: List[Layer] = []
1360 @staticmethod
1361 def get_id(prefix=""):
1362 prefix_length = len(prefix)
1363 if prefix_length > 10:
1364 raise AttributeError("Max prefix length is 10!")
1365 ifcopenshell_guid = guid.new()[prefix_length + 1:]
1366 return f"{prefix}{ifcopenshell_guid}"
1368 def get_total_thickness(self, name):
1369 if hasattr(self.ifc, 'TotalThickness'):
1370 if self.ifc.TotalThickness:
1371 return self.ifc.TotalThickness * ureg.m
1372 return sum(layer.thickness for layer in self.layers)
1374 def _get_volume(self, name):
1375 if hasattr(self, "net_volume"):
1376 if self.net_volume:
1377 vol = self.net_volume
1378 return vol
1379 # TODO This is not working currently, because with multiple parents
1380 # we dont know the area or width of the parent
1381 # elif self.parent.width:
1382 # vol = self.parent.volume * self.parent.width / self.thickness
1383 else:
1384 vol = float('nan') * ureg.meter ** 3
1385 # TODO see above
1386 # elif self.parent.width:
1387 # vol = self.parent.volume * self.parent.width / self.thickness
1388 else:
1389 vol = float('nan') * ureg.meter ** 3
1390 return vol
1392 thickness = attribute.Attribute(
1393 unit=ureg.m,
1394 functions=[get_total_thickness],
1395 )
1397 name = attribute.Attribute(
1398 description="The name by which the IfcMaterialLayerSet is known.",
1399 ifc_attr_name="LayerSetName",
1400 )
1402 volume = attribute.Attribute(
1403 description="Volume of layer set",
1404 functions=[_get_volume],
1405 )
1407 def __repr__(self):
1408 if self.name:
1409 return "<%s (name: %s, layers: %d)>" \
1410 % (self.__class__.__name__, self.name, len(self.layers))
1411 else:
1412 return "<%s (layers: %d)>" % (self.__class__.__name__, len(self.layers))
1415class OuterWall(Wall):
1416 ifc_types = {}
1418 def calc_cost_group(self) -> int:
1419 """Calc cost group for OuterWall
1421 Load bearing outer walls: 331
1422 Not load bearing outer walls: 332
1423 Rest: 330
1424 """
1426 if self.is_load_bearing:
1427 return 331
1428 elif not self.is_load_bearing:
1429 return 332
1430 else:
1431 return 330
1434class InnerWall(Wall):
1435 """InnerWalls are assumed to be always symmetric."""
1436 ifc_types = {}
1438 def calc_cost_group(self) -> int:
1439 """Calc cost group for InnerWall
1441 Load bearing inner walls: 341
1442 Not load bearing inner walls: 342
1443 Rest: 340
1444 """
1446 if self.is_load_bearing:
1447 return 341
1448 elif not self.is_load_bearing:
1449 return 342
1450 else:
1451 return 340
1454class Window(BPSProductWithLayers):
1455 ifc_types = {"IfcWindow": ['*', 'WINDOW', 'SKYLIGHT', 'LIGHTDOME']}
1457 pattern_ifc_type = [
1458 re.compile('Window', flags=re.IGNORECASE),
1459 re.compile('Fenster', flags=re.IGNORECASE)
1460 ]
1462 def get_glazing_area(self, name):
1463 """returns only the glazing area of the windows"""
1464 if self.glazing_ratio:
1465 return self.gross_area * self.glazing_ratio
1466 return self.opening_area
1468 def calc_cost_group(self) -> int:
1469 """Calc cost group for Windows
1471 Outer door: 334
1472 """
1474 return 334
1476 net_area = attribute.Attribute(
1477 functions=[get_glazing_area],
1478 unit=ureg.meter ** 2,
1479 )
1481 gross_area = attribute.Attribute(
1482 default_ps=("Qto_WindowBaseQuantities", "Area"),
1483 functions=[BPSProduct.get_bound_area],
1484 unit=ureg.meter ** 2
1485 )
1487 glazing_ratio = attribute.Attribute(
1488 default_ps=("Pset_WindowCommon", "GlazingAreaFraction"),
1489 )
1491 width = attribute.Attribute(
1492 default_ps=("Qto_WindowBaseQuantities", "Depth"),
1493 functions=[BPSProductWithLayers.get_thickness_by_layers],
1494 unit=ureg.m
1495 )
1496 u_value = attribute.Attribute(
1497 default_ps=("Pset_WindowCommon", "ThermalTransmittance"),
1498 unit=ureg.W / ureg.K / ureg.meter ** 2,
1499 functions=[BPSProductWithLayers.get_u_value],
1500 )
1502 g_value = attribute.Attribute( # material
1503 )
1505 a_conv = attribute.Attribute(
1506 )
1508 shading_g_total = attribute.Attribute(
1509 )
1511 shading_max_irr = attribute.Attribute(
1512 )
1514 inner_convection = attribute.Attribute(
1515 unit=ureg.W / ureg.K / ureg.meter ** 2,
1516 )
1518 inner_radiation = attribute.Attribute(
1519 unit=ureg.W / ureg.K / ureg.meter ** 2,
1520 )
1522 outer_radiation = attribute.Attribute(
1523 unit=ureg.W / ureg.K / ureg.meter ** 2,
1524 )
1526 outer_convection = attribute.Attribute(
1527 unit=ureg.W / ureg.K / ureg.meter ** 2,
1528 )
1531class Door(BPSProductWithLayers):
1532 ifc_types = {"IfcDoor": ['*', 'DOOR', 'GATE', 'TRAPDOOR']}
1534 pattern_ifc_type = [
1535 re.compile('Door', flags=re.IGNORECASE),
1536 re.compile('Tuer', flags=re.IGNORECASE)
1537 ]
1539 conditions = [
1540 condition.RangeCondition('glazing_ratio',
1541 0 * ureg.dimensionless,
1542 1 * ureg.dimensionless, True,
1543 critical_for_creation=False),
1544 ]
1546 def get_better_subclass(self):
1547 return OuterDoor if self.is_external else InnerDoor
1549 def get_net_area(self, name):
1550 if self.glazing_ratio:
1551 return self.gross_area * (1 - self.glazing_ratio)
1552 return self.gross_area - self.opening_area
1554 net_area = attribute.Attribute(
1555 functions=[get_net_area, ],
1556 unit=ureg.meter ** 2,
1557 )
1559 gross_area = attribute.Attribute(
1560 default_ps=("Qto_DoorBaseQuantities", "Area"),
1561 functions=[BPSProduct.get_bound_area],
1562 unit=ureg.meter ** 2
1563 )
1565 glazing_ratio = attribute.Attribute(
1566 default_ps=("Pset_DoorCommon", "GlazingAreaFraction"),
1567 )
1569 width = attribute.Attribute(
1570 default_ps=("Qto_DoorBaseQuantities", "Width"),
1571 functions=[BPSProductWithLayers.get_thickness_by_layers],
1572 unit=ureg.m
1573 )
1575 u_value = attribute.Attribute(
1576 unit=ureg.W / ureg.K / ureg.meter ** 2,
1577 functions=[BPSProductWithLayers.get_u_value],
1578 )
1580 inner_convection = attribute.Attribute(
1581 unit=ureg.W / ureg.K / ureg.meter ** 2,
1582 default=0.6
1583 )
1585 inner_radiation = attribute.Attribute(
1586 unit=ureg.W / ureg.K / ureg.meter ** 2,
1587 )
1589 outer_radiation = attribute.Attribute(
1590 unit=ureg.W / ureg.K / ureg.meter ** 2,
1591 )
1593 outer_convection = attribute.Attribute(
1594 unit=ureg.W / ureg.K / ureg.meter ** 2,
1595 )
1598class InnerDoor(Door):
1599 ifc_types = {}
1601 def calc_cost_group(self) -> int:
1602 """Calc cost group for Innerdoors
1604 Inner door: 344
1605 """
1607 return 344
1610class OuterDoor(Door):
1611 ifc_types = {}
1613 def calc_cost_group(self) -> int:
1614 """Calc cost group for Outerdoors
1616 Outer door: 334
1617 """
1619 return 334
1622class Slab(BPSProductWithLayers):
1623 ifc_types = {
1624 "IfcSlab": ['*', 'LANDING']
1625 }
1627 def __init__(self, *args, **kwargs):
1628 """slab __init__ function"""
1629 super().__init__(*args, **kwargs)
1631 def _calc_teaser_orientation(self, name) -> int:
1632 """Returns the orientation of the slab in TEASER convention."""
1633 return -1
1635 net_area = attribute.Attribute(
1636 default_ps=("Qto_SlabBaseQuantities", "NetArea"),
1637 functions=[BPSProduct.get_net_bound_area],
1638 unit=ureg.meter ** 2
1639 )
1641 gross_area = attribute.Attribute(
1642 default_ps=("Qto_SlabBaseQuantities", "GrossArea"),
1643 functions=[BPSProduct.get_bound_area],
1644 unit=ureg.meter ** 2
1645 )
1647 width = attribute.Attribute(
1648 default_ps=("Qto_SlabBaseQuantities", "Width"),
1649 functions=[BPSProductWithLayers.get_thickness_by_layers],
1650 unit=ureg.m
1651 )
1653 u_value = attribute.Attribute(
1654 default_ps=("Pset_SlabCommon", "ThermalTransmittance"),
1655 unit=ureg.W / ureg.K / ureg.meter ** 2,
1656 functions=[BPSProductWithLayers.get_u_value],
1657 )
1659 net_volume = attribute.Attribute(
1660 default_ps=("Qto_SlabBaseQuantities", "NetVolume"),
1661 unit=ureg.meter ** 3
1662 )
1664 is_load_bearing = attribute.Attribute(
1665 default_ps=("Pset_SlabCommon", "LoadBearing"),
1666 )
1669class Roof(Slab):
1670 # todo decomposed roofs dont have materials, layers etc. because these
1671 # information are stored in the slab itself and not the decomposition
1672 # is_external = True
1673 ifc_types = {
1674 "IfcRoof":
1675 ['*', 'FLAT_ROOF', 'SHED_ROOF', 'GABLE_ROOF', 'HIP_ROOF',
1676 'HIPPED_GABLE_ROOF', 'GAMBREL_ROOF', 'MANSARD_ROOF',
1677 'BARREL_ROOF', 'RAINBOW_ROOF', 'BUTTERFLY_ROOF', 'PAVILION_ROOF',
1678 'DOME_ROOF', 'FREEFORM'],
1679 "IfcSlab": ['ROOF']
1680 }
1682 def calc_cost_group(self) -> int:
1683 """Calc cost group for Roofs
1686 Load bearing: 361
1687 Not load bearing: 363
1688 """
1689 if self.is_load_bearing:
1690 return 361
1691 elif not self.is_load_bearing:
1692 return 363
1693 else:
1694 return 300
1697class InnerFloor(Slab):
1698 """In bim2sim we handle all inner slabs as floors/inner floors.
1700 Orientation of layerset is layer 0 is inside (floor surface of this room),
1701 layer n is outside (ceiling surface of room below).
1702 """
1703 ifc_types = {
1704 "IfcSlab": ['FLOOR']
1705 }
1707 def calc_cost_group(self) -> int:
1708 """Calc cost group for Floors
1710 Floor: 351
1711 """
1712 return 351
1715class GroundFloor(Slab):
1716 # is_external = True # todo to be removed
1717 ifc_types = {
1718 "IfcSlab": ['BASESLAB']
1719 }
1721 def _calc_teaser_orientation(self, name) -> int:
1722 """Returns the orientation of the groundfloor in TEASER convention."""
1723 return -2
1725 def calc_cost_group(self) -> int:
1726 """Calc cost group for groundfloors
1728 groundfloors: 322
1729 """
1731 return 322
1734 # pattern_ifc_type = [
1735 # re.compile('Bodenplatte', flags=re.IGNORECASE),
1736 # re.compile('')
1737 # ]
1740class Site(BPSProduct):
1741 def __init__(self, *args, **kwargs):
1742 super().__init__(*args, **kwargs)
1743 del self.building
1744 self.buildings = []
1746 # todo move this to base elements as this relevant for other domains as well
1747 ifc_types = {"IfcSite": ['*']}
1749 gross_area = attribute.Attribute(
1750 default_ps=("Qto_SiteBaseQuantities", "GrossArea"),
1751 unit=ureg.meter ** 2
1752 )
1754 location_latitude = attribute.Attribute(
1755 ifc_attr_name="RefLatitude",
1756 )
1758 location_longitude = attribute.Attribute(
1759 ifc_attr_name="RefLongitude"
1760 )
1763class Building(BPSProduct):
1764 def __init__(self, *args, **kwargs):
1765 super().__init__(*args, **kwargs)
1766 self.thermal_zones = []
1767 self.storeys = []
1768 self.elements = []
1770 ifc_types = {"IfcBuilding": ['*']}
1771 from_ifc_domains = [IFCDomain.arch]
1773 conditions = [
1774 condition.RangeCondition('year_of_construction',
1775 1900 * ureg.year,
1776 date.today().year * ureg.year,
1777 critical_for_creation=False),
1778 ]
1780 def _get_building_name(self, name):
1781 """get building name"""
1782 bldg_name = self.get_ifc_attribute('Name')
1783 if bldg_name:
1784 return bldg_name
1785 else:
1786 # todo needs to be adjusted for multiple buildings #165
1787 bldg_name = 'Building'
1788 return bldg_name
1790 def _get_number_of_storeys(self, name):
1791 return len(self.storeys)
1793 def _get_avg_storey_height(self, name):
1794 """Calculates the average height of all storeys."""
1795 storey_height_sum = 0
1796 avg_height = None
1797 if hasattr(self, "storeys"):
1798 if len(self.storeys) > 0:
1799 for storey in self.storeys:
1800 if storey.height:
1801 height = storey.height
1802 elif storey.gross_height:
1803 height = storey.gross_height
1804 elif storey.net_height:
1805 height = storey.net_height
1806 else:
1807 height = None
1808 if height:
1809 storey_height_sum += height
1810 avg_height = storey_height_sum / len(self.storeys)
1811 return avg_height
1813 def _check_tz_ahu(self, name):
1814 """Check if any TZs have AHU, then the building has one as well."""
1815 with_ahu = False
1816 for tz in self.thermal_zones:
1817 if tz.with_ahu:
1818 with_ahu = True
1819 break
1820 return with_ahu
1822 bldg_name = attribute.Attribute(
1823 functions=[_get_building_name],
1824 )
1826 year_of_construction = attribute.Attribute(
1827 default_ps=("Pset_BuildingCommon", "YearOfConstruction"),
1828 unit=ureg.year
1829 )
1831 gross_area = attribute.Attribute(
1832 default_ps=("Qto_BuildingBaseQuantities", "GrossFloorArea"),
1833 unit=ureg.meter ** 2
1834 )
1836 net_area = attribute.Attribute(
1837 default_ps=("Qto_BuildingBaseQuantities", "NetFloorArea"),
1838 unit=ureg.meter ** 2
1839 )
1841 number_of_storeys = attribute.Attribute(
1842 unit=ureg.dimensionless,
1843 functions=[_get_number_of_storeys]
1844 )
1846 occupancy_type = attribute.Attribute(
1847 default_ps=("Pset_BuildingCommon", "OccupancyType"),
1848 )
1850 avg_storey_height = attribute.Attribute(
1851 unit=ureg.meter,
1852 functions=[_get_avg_storey_height]
1853 )
1855 with_ahu = attribute.Attribute(
1856 functions=[_check_tz_ahu]
1857 )
1859 ahu_heating = attribute.Attribute(
1860 attr_type=bool
1861 )
1863 ahu_cooling = attribute.Attribute(
1864 attr_type=bool
1865 )
1867 ahu_dehumidification = attribute.Attribute(
1868 attr_type=bool
1869 )
1871 ahu_humidification = attribute.Attribute(
1872 attr_type=bool
1873 )
1875 ahu_heat_recovery = attribute.Attribute(
1876 attr_type=bool
1877 )
1879 ahu_heat_recovery_efficiency = attribute.Attribute(
1880 )
1883class Storey(BPSProduct):
1884 ifc_types = {'IfcBuildingStorey': ['*']}
1885 from_ifc_domains = [IFCDomain.arch]
1887 def __init__(self, *args, **kwargs):
1888 """storey __init__ function"""
1889 super().__init__(*args, **kwargs)
1890 self.elements = []
1892 spec_machines_internal_load = attribute.Attribute(
1893 default_ps=("Pset_ThermalLoadDesignCriteria",
1894 "ReceptacleLoadIntensity"),
1895 unit=ureg.kilowatt / (ureg.meter ** 2)
1896 )
1898 spec_lighting_internal_load = attribute.Attribute(
1899 default_ps=("Pset_ThermalLoadDesignCriteria", "LightingLoadIntensity"),
1900 unit=ureg.kilowatt / (ureg.meter ** 2)
1901 )
1903 cooling_load = attribute.Attribute(
1904 default_ps=("Pset_ThermalLoadAggregate", "TotalCoolingLoad"),
1905 unit=ureg.kilowatt
1906 )
1908 heating_load = attribute.Attribute(
1909 default_ps=("Pset_ThermalLoadAggregate", "TotalHeatingLoad"),
1910 unit=ureg.kilowatt
1911 )
1913 air_per_person = attribute.Attribute(
1914 default_ps=("Pset_ThermalLoadDesignCriteria", "OutsideAirPerPerson"),
1915 unit=ureg.meter ** 3 / ureg.hour
1916 )
1918 percent_load_to_radiant = attribute.Attribute(
1919 default_ps=("Pset_ThermalLoadDesignCriteria",
1920 "AppliancePercentLoadToRadiant"),
1921 unit=ureg.percent
1922 )
1924 gross_floor_area = attribute.Attribute(
1925 default_ps=("Qto_BuildingStoreyBaseQuantities", "GrossFloorArea"),
1926 unit=ureg.meter ** 2
1927 )
1929 # todo make the lookup for height hierarchical
1930 net_height = attribute.Attribute(
1931 default_ps=("Qto_BuildingStoreyBaseQuantities", "NetHeight"),
1932 unit=ureg.meter
1933 )
1935 gross_height = attribute.Attribute(
1936 default_ps=("Qto_BuildingStoreyBaseQuantities", "GrossHeight"),
1937 unit=ureg.meter
1938 )
1940 height = attribute.Attribute(
1941 default_ps=("Qto_BuildingStoreyBaseQuantities", "Height"),
1942 unit=ureg.meter
1943 )
1946# collect all domain classes
1947items: Set[BPSProduct] = set()
1948for name, cls in inspect.getmembers(
1949 sys.modules[__name__],
1950 lambda member: inspect.isclass(member) # class at all
1951 and issubclass(member, BPSProduct) # domain subclass
1952 and member is not BPSProduct # but not base class
1953 and member.__module__ == __name__): # declared here
1954 items.add(cls)