Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions bim2sim/elements/base_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,6 @@ def ifc_type(self):
if self.ifc:
return self.ifc.is_a()

@classmethod
def pre_validate(cls, ifc) -> bool:
"""Check if ifc meets conditions to create element from it"""
raise NotImplementedError

def _calc_position(self, name):
"""returns absolute position"""
if hasattr(self.ifc, 'ObjectPlacement'):
Expand Down
8 changes: 0 additions & 8 deletions bim2sim/elements/bps_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,6 @@ def _calc_position(self, name):

return position

@classmethod
def pre_validate(cls, ifc) -> bool:
return True

def validate_creation(self) -> bool:
if self.bound_area and self.bound_area < 1e-2 * ureg.meter ** 2:
return True
Expand Down Expand Up @@ -1281,10 +1277,6 @@ def get_id(prefix=""):
ifcopenshell_guid = guid.new()[prefix_length + 1:]
return f"{prefix}{ifcopenshell_guid}"

@classmethod
def pre_validate(cls, ifc) -> bool:
return True

def validate_creation(self) -> bool:
return True

Expand Down
105 changes: 11 additions & 94 deletions bim2sim/elements/graphs/hvac_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from networkx import json_graph

from bim2sim.elements.base_elements import ProductBased, ElementEncoder
from bim2sim.utilities.types import FlowSide, FlowDirection

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -118,7 +119,7 @@ def get_type_chains(
types: Iterable[Type[ProductBased]],
include_singles: bool = False):
"""Get lists of consecutive elements of the given types. Elements are
ordered in the same way as the are connected.
ordered in the same way as they are connected.

Args:
element_graph: Graph object with elements as nodes.
Expand Down Expand Up @@ -181,9 +182,6 @@ def get_connections(self):
return [edge for edge in self.edges
if not edge[0].parent is edge[1].parent]

# def get_nodes(self):
# """Returns list of nodes represented by graph"""
# return list(self.nodes)

def plot(self, path: Path = None, ports: bool = False, dpi: int = 400,
use_pyvis=False):
Expand All @@ -203,16 +201,15 @@ def plot(self, path: Path = None, ports: bool = False, dpi: int = 400,

# https://plot.ly/python/network-graphs/
edge_colors_flow_side = {
1: dict(edge_color='red'),
-1: dict(edge_color='blue'),
0: dict(edge_color='grey'),
None: dict(edge_color='grey'),
FlowSide.supply_flow: dict(edge_color='red'),
FlowSide.return_flow: dict(edge_color='blue'),
FlowSide.unknown: dict(edge_color='grey'),
}
node_colors_flow_direction = {
1: dict(node_color='white', edgecolors='blue'),
-1: dict(node_color='blue', edgecolors='black'),
0: dict(node_color='grey', edgecolors='black'),
None: dict(node_color='grey', edgecolors='black'),
FlowDirection.source: dict(node_color='white', edgecolors='blue'),
FlowDirection.sink: dict(node_color='blue', edgecolors='black'),
FlowDirection.sink_and_source: dict(node_color='grey', edgecolors='black'),
FlowDirection.unknown: dict(node_color='grey', edgecolors='black'),
}

kwargs = {}
Expand Down Expand Up @@ -293,6 +290,7 @@ def plot(self, path: Path = None, ports: bool = False, dpi: int = 400,
node['label'] = node['label'].split('<')[1]
except:
pass
# TODO #733 use is_generator(), is_consumer() etc.
node['label'] = node['label'].split('(ports')[0]
if 'agg' in node['label'].lower():
node['label'] = node['label'].split('Agg0')[0]
Expand Down Expand Up @@ -654,88 +652,7 @@ def group_parallels(graph, group_attr, cond, threshold=None):
graphs.append(_graph)
return graphs

def recurse_set_side(self, port, side, known: dict = None,
raise_error=True):
"""Recursive set flow_side to connected ports"""
if known is None:
known = {}

# set side suggestion
is_known = port in known
current_side = known.get(port, port.flow_side)
if not is_known:
known[port] = side
elif is_known and current_side == side:
return known
else:
# conflict
if raise_error:
raise AssertionError("Conflicting flow_side in %r" % port)
else:
logger.error("Conflicting flow_side in %r", port)
known[port] = None
return known

# call neighbours
for neigh in self.neighbors(port):
if (neigh.parent.is_consumer() or neigh.parent.is_generator()) \
and port.parent is neigh.parent:
# switch flag over consumers / generators
self.recurse_set_side(neigh, -side, known, raise_error)
else:
self.recurse_set_side(neigh, side, known, raise_error)

return known

def recurse_set_unknown_sides(self, port, visited: list = None,
masters: list = None):
"""Recursive checks neighbours flow_side.
:returns tuple of
common flow_side (None if conflict)
list of checked ports
list of ports on which flow_side s are determined"""

if visited is None:
visited = []
if masters is None:
masters = []

# mark as visited to prevent deadloops
visited.append(port)

if port.flow_side in (-1, 1):
# use port with known flow_side as master
masters.append(port)
return port.flow_side, visited, masters

# call neighbours
neighbour_sides = {}
for neigh in self.neighbors(port):
if neigh not in visited:
if (neigh.parent.is_consumer() or neigh.parent.is_generator()) \
and port.parent is neigh.parent:
# switch flag over consumers / generators
side, _, _ = self.recurse_set_unknown_sides(
neigh, visited, masters)
side = -side
else:
side, _, _ = self.recurse_set_unknown_sides(
neigh, visited, masters)
neighbour_sides[neigh] = side

sides = set(neighbour_sides.values())
if not sides:
return port.flow_side, visited, masters
elif len(sides) == 1:
# all neighbours have same site
side = sides.pop()
return side, visited, masters
elif len(sides) == 2 and 0 in sides:
side = (sides - {0}).pop()
return side, visited, masters
else:
# conflict
return None, visited, masters


@staticmethod
def get_dir_paths_between(graph, nodes, include_edges=False):
Expand Down
Loading