bim2sim.tasks.common package

Submodules

bim2sim.tasks.common.base_tasks module

class bim2sim.tasks.common.base_tasks.Quit(playground)

Bases: ITask

Quit interactive tasks

final = True
run()

Run tasks.

single_use = False
class bim2sim.tasks.common.base_tasks.Reset(playground)

Bases: ITask

Reset all progress

classmethod requirements_met(state, history)

Check if all requirements for this tasks are met.

Args:

state: state of playground history: history of playground

run()

Run tasks.

single_use = False
touches: Tuple[str] = '__reset__'

bim2sim.tasks.common.create_elements module

class bim2sim.tasks.common.create_elements.CreateElementsOnIfcTypes(playground: Playground)

Bases: ITask

Create bim2sim elements based on information of IFC types.

create_constituent(element: Element, ifc_material_constituents: entity_instance, quality_logger: Element)
Instantiate the constituent set and its materials and link to

element.

Constituent sets in IFC are used to describe the e.g. windows which consist out of different materials (glass, frame etc.) or mixtures like concrete (sand, cement etc.).

Args:

element: bim2sim element ifc_material_constituents: ifc entity of layerset quality_logger: element of bim2sim quality logger

create_layers_and_materials(element: Element)

Create all layers and materials associated with the given element.

Layers and materials are no IfcProducts and have no GUID. They are always associated to IfcProducts. To create the association between Product and layer or material we create layers and materials directly when creating the corresponding element and not directly based on their IFC type in the normal creation process. For more information how materials work in IFC have a look at

`wiki.osarch.org`_.

_wiki.osarch.org: https://wiki.osarch.org/index.php?title=IFC_-_ Industry_Foundation_Classes/IFC_materials

Args:

element: the already created bim2sim element

create_layersets(element: Element, ifc_layerset_entity: entity_instance)
Instantiate the layerset and its layers and materials and link to

element.

Layersets in IFC are used to describe the layer structure of e.g. walls.

Args:

element: bim2sim element ifc_layerset_entity: ifc entity of layerset

create_material(ifc_material_entity: entity_instance)

As materials are unique in IFC we only want to have on material instance per material.

create_with_validation(entities_dict: dict, warn=True, force=False) Tuple[List[ProductBased], List[Any]]

Instantiate ifc_entities using given element class.

The given ifc entities are used to create bim2sim elements via factory method. After the creation the associated layers and material are created (see create_layers_and_materials). All created elements (including material and layers) are checked against the provided conditions and classified into valid and invalid.

Args:

entities_dict: dict with ifc entities warn: boolean to warn if something condition fail force: boolean if conditions should be ignored

Returns:

valid: list of all valid items that fulfill the conditions invalid: list of all elements that do not fulfill the conditions

filter_by_text(text_filter: TextFilter, ifc_entities: entity_instance) Generator[DecisionBunch, None, Tuple[Dict[Any, Type[ProductBased]], List]]

Filter IFC elements by analyzing text fragments.

This method applies text-based filtering to identify elements. It handles: 1. Automatic classification for entities with single matching class 2. User decision for entities with multiple potential matching classes 3. Collection of unidentified entities

Args:

text_filter: The TextFilter instance to use. ifc_entities: IFC entities to filter.

Yields:

DecisionBunch: User decisions for ambiguous matches.

Returns:
tuple:
  • Dictionary mapping entities to their identified element

classes - List of unidentified entities

static get_ifc_types(relevant_elements: List[Type[ProductBased]]) Set[str]

Extract used ifc types from list of elements.

reads: Tuple[str] = ('ifc_files',)
run(ifc_files: [<class 'bim2sim.kernel.ifc_file.IfcFileClass'>]) Tuple[Dict[Any, Element], Dict[Any, Element], List[IfcFileClass]]

This task creates the bim2sim elements based on the ifc data.

For each ifc file a factory instance is created. The factory instance allows the easy creation of bim2sim elements based on ifc elements. As we might not want to create bim2sim elements for every existing ifc element, we use the concept of relevant_elements which are taken from the sim_setting relevant_elements. This way the user can describe which bim2sim elements are relevant for the respective simulation and only the fitting ifc elements are taken into account. During the creation of the bim2sim elements validations are performed, to make sure that the resulting bim2sim elements hold valid information.

The element creation process follows a three-stage classification approach:

  1. Validation-Based Classification: * Elements are initially processed based on relevant element types and IFC classifications * Each element undergoes validation against predefined criteria * Valid elements are immediately added to the “valids” collection * Elements failing validation are placed in “unknown_entities” for further processing

  2. Pattern Matching Classification: * For unidentified elements in “unknown_entities”, a text analysis is performed * The system examines IFC descriptions and compares them against regular expression patterns defined in element classes * Results are handled based on match confidence:

    • Single match: Element is automatically moved to “valids”

    • Multiple matches: User decision is requested to determine the

    correct classification - No matches: Element remains in “unknown_entities” for final classification stage

  3. User-Assisted Classification: * Remaining unidentified elements are processed through the set_class_by_user function * To optimize user experience, similar elements are intelligently grouped using one of these strategies:

    • Exact name matching: Groups elements with identical names

    • Name and description matching: Groups elements with identical

    names and descriptions - Fuzzy matching: Groups elements with similar names based on a configurable similarity threshold

    • This grouping significantly reduces the number of required user

    decisions * User decisions determine the final classification of each element or group

Args:

ifc_files: list of ifc files in bim2sim structured format

Returns:

elements: bim2sim elements created based on ifc data ifc_files: list of ifc files in bim2sim structured format

set_class_by_user(unknown_entities: list, sim_settings: BaseSimSettings, best_guess_dict: dict)

Ask user for every given ifc_entity to specify matching element class.

This function allows to define unknown classes based on user feedback. To reduce the number of decisions we implemented fuzzy search. If and how fuzzy search is used can be set the sim_settings group_unidentified and fuzzy_threshold. See group_similar_entities() for more information.

Args:

unknown_entities: list of unknown entities sim_settings: sim_settings used for this project best_guess_dict: dict that holds the best guesses for every element

touches: Tuple[str] = ('elements', '_initial_elements', 'ifc_files')

bim2sim.tasks.common.create_relations module

class bim2sim.tasks.common.create_relations.CreateRelations(playground)

Bases: ITask

Relations of elements, run() method holds detailed information.

reads: Tuple[str] = ('elements',)
run(elements: dict[str, bim2sim.elements.base_elements.IFCBased])

Bind ThermalZone to ProductBased/Storey/Building and vice versa.

This is needed as our CreateElements task does not work hierarchic. So we need to create the relations after initial creation. Problem: Following IFC-schema rules a space that is stretched over multiple storeys should only be assigned to one of these storeys. From IFC-Schema: “NOTE: Multi storey spaces shall be spatially contained by only a single building storey, usually it is the building storey where the base of the space lies. TODO: this might me solved via PyOCCTools.obj2_in_obj1 but this needs

all shapes to be existing for ThermalZone instances and Storeys

Args:

elements: dict[guid: element]

bim2sim.tasks.common.deserialize_elements module

class bim2sim.tasks.common.deserialize_elements.DeserializeElements(playground)

Bases: ITask

Deserialize elements, run() method holds detailed information.

run()

Deserializes the elements from a previous run.

Loads the serialized_elements from a previous run from the pickled object.

Returns:
serialized_elements: dict[guid: serializedElement] of serialized

elements

single_use = True
touches: Tuple[str] = ('elements',)

bim2sim.tasks.common.inner_loop_remover module

This module contains functions which, given a TopoDS shapes with holes (“inner loops”), calculate an equivalent shape without holes by adding cuts along triangulation edges. Using the triangulation as a graph, it finds a spanning tree between the main polygon and its holes using Kruskal’s algorithm and places the cuts along the edges of this spanning tree.

bim2sim.tasks.common.inner_loop_remover.convex_decomposition(shape: TopoDS_Shape, opening_shapes: List[TopoDS_Shape] = []) List[TopoDS_Shape]
bim2sim.tasks.common.inner_loop_remover.convex_decomposition_base(shape: TopoDS_Shape, opening_shapes: List[TopoDS_Shape] = []) List[List[Tuple[float, float, float]]]

Convex decomposition base: removes common edges of triangles unless a non-convex shape is created. In case of openings: In a first round, remove all cutting triangle edges with the opening polygons regardless of non-convex shapes. Then, check for resulting angles. This may lead to non-convex shapes, but should work in most cases.

bim2sim.tasks.common.inner_loop_remover.fuse_pieces(pieces: List[List[Tuple[float, float, float]]], shapes_to_consider: List[TopoDS_Shape] = []) List[List[Tuple[float, float, float]]]
bim2sim.tasks.common.inner_loop_remover.is_convex_no_holes(shape: TopoDS_Shape) bool

check if TopoDS_Shape is convex. Returns False if shape is non-convex

bim2sim.tasks.common.inner_loop_remover.is_convex_slow(shape: TopoDS_Shape) bool

Computational expensive check if a TopoDS_Shape is convex. Args:

shape: TopoDS_Shape

Returns:

bool, True if shape is convex.

bim2sim.tasks.common.inner_loop_remover.is_polygon_convex_no_holes(pnts: List[Tuple[float, float, float]]) bool

check if polygon made from tuples of floats is convex. Returns False if shape is non-convex

bim2sim.tasks.common.inner_loop_remover.remove_inner_loops(shape: TopoDS_Shape) TopoDS_Shape

bim2sim.tasks.common.load_ifc module

class bim2sim.tasks.common.load_ifc.LoadIFC(playground)

Bases: ITask

Load all IFC files from PROJECT.ifc_base path.

This tasks reads the IFC files of one or multiple domains inside bim2sim.

Returns:

ifc: list of one or multiple IfcFileClass elements

load_ifc_files(base_path: Path)

Load all ifc files/file given in base_path.

Loads the ifc files inside the different domain folders in the base

path, and initializes the bim2sim ifc file classes.

Args:
base_path: Pathlib path that holds the different domain folders,

which hold the ifc files.

run()

Run function of LoadIFC.

touches: Tuple[str] = ('ifc_files',)
bim2sim.tasks.common.load_ifc.extract_ifc_file_names(base_path)

Extract ifc file names of a given directory.

Args:
base_path: Pathlib path that holds the different domain folders,

which hold the ifc files.

Returns:

list: of ifc file names

bim2sim.tasks.common.serialize_elements module

class bim2sim.tasks.common.serialize_elements.SerializeElements(playground)

Bases: ITask

Serialize element structure, run() method holds detailed information.

reads: Tuple[str] = ('elements',)
run(elements: dict) Tuple[Dict]

Make the element structure serializable.

As due to swigPy objects coming from IfcOpenShell we can’t directly serialize a whole bim2sim project or even the elements structure with serializers like pickle. To still keep the element structure information after a project run, we just copy the relevant information like the attributes from the AttributeManager, guid and type of the element to a simple SerializedElement instance and store it with pickle.

Args:

elements: dict[guid: element] of bim2sim element structure

Returns:
serialized_elements: dict[guid: serializedElement] of serialized

elements

single_use = True
touches: Tuple[str] = ('serialized_elements',)

bim2sim.tasks.common.weather module

class bim2sim.tasks.common.weather.Weather(playground)

Bases: ITask

Task to get the weather file for later simulation

check_file_ending(weather_file: WindowsPath)

Check if the file ending fits the simulation model type.

get_location_lat_long_from_ifc(elements: dict) [<class 'float'>]

Returns the location in form of latitude and longitude based on IfcSite.

The location of the site and therefore the building are taken from the IfcSite in form of latitude and longitude. Latitude and Longitude each are a tuple of (degrees, minutes, seconds) and, optionally, millionths of seconds. See IfcSite Documentation for further information. Args:

elements: dict with bim2sim elements

Returns:

latitude, longitude: two float values for latitude and longitude

get_location_name(latitude: tuple, longitude: tuple) str

Returns the name of the location based on latitude and longitude.

Args:

latitude: tuple of degrees, minutes and seconds longitude: tuple of degrees, minutes and seconds

Returns:

location_name: str of the location name

get_weatherfile_from_dwd(lat: tuple, long: tuple)
reads: Tuple[str] = ('elements',)
run(elements: dict)

Run tasks.

touches: Tuple[str] = ('weather_file',)