Skip to content

Commit

Permalink
Add: Geometric calculation of shared areas
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nb4 committed Jan 28, 2025
1 parent e8b828c commit 82ca37d
Show file tree
Hide file tree
Showing 5 changed files with 17,496 additions and 13 deletions.
67 changes: 62 additions & 5 deletions districtgenerator/classes/datahandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from ..functions import weather_handling as weather_handling
from ..functions import path_checks as path_checks
from ..functions import calculate_holidays as calculate_holidays
from ..functions import update_surfaces as update_surfaces


RESIDENTIAL_BUILDING_TYPES = ["SFH", "TH", "MFH", "AB"]
Expand Down Expand Up @@ -153,17 +154,19 @@ def setResultPath(self, new_path=None):
new_path = path_checks.check_path(new_path)
self.resultPath = new_path

def setAdvancedModel(self, pathAdvancedModel=None):
def setAdvancedModel(self, pathAdvancedModel: str) -> None:
"""
Sets the path and loads data for advanded modelling
Sets the path and loads data for advanded modelling. This includes geometry.
Args:
new_path (str, optional): The new path to set. If not provided, the default path will be used.
pathAdvancedModel (str): The path to the advanced model JSON file that contains
further attributes about geometry in TEASER coordinates.
Returns:
None
"""
self.advancedModel = pathAdvancedModel if pathAdvancedModel is not None else None
with open(pathAdvancedModel, 'r') as f:
self.advancedModel_data = json.load(f)

def setWeatherFile(self, pathWeatherFile=None):
"""
Expand Down Expand Up @@ -1212,5 +1215,59 @@ def import_building_data(self):
"""
Import building data from a csv file
"""
# TODO: Implement this function to load advanced building data
# TODO Implement this function to load advanced building data
pass


def updateGeometry(self):
"""
Update building data from the advanced model.
Updates envelope data for each building based on the advanced model data.
Update building data from the advanced model.
Updates envelope data for each building based on the advanced model data.
"""
if self.advancedModel_data is None:
print("No geometry model provided. Cannot update building data.")
return

# Update each building's envelope data
for building in self.district:
building_id = building["buildingFeatures"]["gml_id"]

# Find matching building data in advanced model
building_data = self.advancedModel_data.get(building_id)

if building_data is None:
print(f"No data found for building ID {building_id} in advanced model")
continue
free_areas, opaque_areas = update_surfaces.extract_surface_areas(building_data)
window_areas = update_surfaces.extract_window_areas(free_areas, opaque_areas, building)

# Calculate total window area
total_window_area = sum(window_areas.values())

# Update window areas with validation
building["envelope"].A["window"] = {
"south": window_areas.get("south", building["envelope"].A["window"]["south"]),
"north": window_areas.get("north", building["envelope"].A["window"]["north"]),
"west": window_areas.get("west", building["envelope"].A["window"]["west"]),
"east": window_areas.get("east", building["envelope"].A["window"]["east"]),
"sum": total_window_area
}

# Calculate total internal wall area including connected walls
total_opaque_area = sum(opaque_areas.values())
internal_wall_area = building["envelope"].A["opaque"].get("intWall", 0)
total_internal_area = internal_wall_area + total_opaque_area

# Update opaque areas with validation
building["envelope"].A["opaque"] = {
"south": max(0, opaque_areas.get("south", 0)),
"north": max(0, opaque_areas.get("north", 0)),
"west": max(0, opaque_areas.get("west", 0)),
"east": max(0, opaque_areas.get("east", 0)),
"roof": building["envelope"].A["opaque"].get("roof", 0), # Preserve existing roof area
"floor": building["envelope"].A["opaque"].get("floor", 0), # Preserve existing floor area
"intWall": max(0, total_internal_area)
}
15 changes: 7 additions & 8 deletions districtgenerator/functions/update_surfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ def extract_surface_areas(building_data):
angle = angle % 360

# Determine cardinal direction based on angle
# TODO check Teaser data model
if 315 <= angle or angle < 45:
direction = 'south'
elif 135 <= angle < 225:
direction = 'north'
elif 45 <= angle < 135:
elif 225 <= angle < 315:
direction = 'east'
elif 135 <= angle < 225:
direction = 'south'
else: # 225 <= angle < 315
else: # 45 <= angle < 135
direction = 'west'

# Add areas to corresponding direction
Expand Down Expand Up @@ -74,9 +73,9 @@ def extract_window_areas(free_areas, opaque_areas, building_data):
for direction in updated_window_areas:
free_area = free_areas[direction]
if free_area > 0:
# Calculate window area as percentage of free wall area
window_area = ( free_area / ( opaque_areas[direction] + free_area ) ) * building_data[direction]
# Ensure window area doesn't exceed free wall area
window_area = ( free_area / ( opaque_areas[direction] + free_area ) ) * building_data["envelope"].A["window"][direction]
updated_window_areas[direction] = min(window_area, free_area)
else:
updated_window_areas[direction] = 0

return updated_window_areas
Loading

0 comments on commit 82ca37d

Please sign in to comment.