mirror of
https://rs-loy-gitlab.concordia.ca/PMAU/DynamicBuildingSimulation.git
synced 2024-11-14 15:00:29 -05:00
version working with generation of all input files
This commit is contained in:
parent
bb1130c204
commit
33774a76c1
|
@ -2,6 +2,7 @@
|
|||
<dictionary name="Pilar">
|
||||
<words>
|
||||
<w>alkis</w>
|
||||
<w>ashrae</w>
|
||||
<w>incongruences</w>
|
||||
<w>nrcan</w>
|
||||
</words>
|
||||
|
|
|
@ -9,6 +9,7 @@ import pandas as pd
|
|||
from insel.insel import Insel
|
||||
import helpers.constants as cte
|
||||
from imports.weather.helpers.weather import Weather as wt
|
||||
from helpers.yearly_from_daily_schedules import YearlyFromDailySchedules as ys
|
||||
|
||||
|
||||
class ThermalDemandDynamicSimulation:
|
||||
|
@ -30,7 +31,7 @@ class ThermalDemandDynamicSimulation:
|
|||
"""
|
||||
|
||||
file = ""
|
||||
file += "%Thermal Demand Dynamic Calculation\n"
|
||||
file += "%Thermal Demand Dynamic Simulation\n"
|
||||
file += "%by Pilar Monsalvete Alvarez de Uribarri\n"
|
||||
file += "%email: pilar.monsalvete@concordia.ca\n"
|
||||
|
||||
|
@ -120,22 +121,20 @@ class ThermalDemandDynamicSimulation:
|
|||
else:
|
||||
n_records += 2
|
||||
inputs = [f"{n_hoy}.1"]
|
||||
parameters = [f"{n_records} %[Nrec]",
|
||||
f"{n_records * 12} %[RecLen]",
|
||||
parameters = [f"{n_records * 13} %[RecLen]",
|
||||
f"'{weather_path}' %[FileName]",
|
||||
f"'({n_records}F12.3)' %[FileFormat]"]
|
||||
file = Insel.add_block(file, i_block, 'READD', inputs, parameters)
|
||||
f"',' %[Separator]"]
|
||||
file = Insel.add_block(file, i_block, 'UBFAST_READD', inputs, parameters)
|
||||
|
||||
# internal gains and control blocks
|
||||
i_block += 1
|
||||
n_ig = i_block
|
||||
n_records = number_usage_zones * 6
|
||||
inputs = [f"{n_hoy}.1"]
|
||||
parameters = [f"{n_records} %[Nrec]",
|
||||
f"{n_records * 12} %[RecLen]",
|
||||
parameters = [f"{n_records * 13} %[RecLen]",
|
||||
f"'{ig_path}' %[FileName]",
|
||||
f"'({n_records}F12.3)' %[FileFormat]"]
|
||||
file = Insel.add_block(file, i_block, 'READD', inputs, parameters)
|
||||
f"',' %[Separator]"]
|
||||
file = Insel.add_block(file, i_block, 'UBFAST_READD', inputs, parameters)
|
||||
|
||||
# results blocks
|
||||
i_block += 1
|
||||
|
@ -262,7 +261,7 @@ class ThermalDemandDynamicSimulation:
|
|||
f"{n_ig}." + str(6 + 6 * i_zone), # set point heating
|
||||
f"{n_ig}." + str(4 + 6 * i_zone), # ventilation rate
|
||||
f"{n_weather}.1", # ventilation temperature
|
||||
f"{n_zone[i_zone] + 4}.1", # from chs
|
||||
f"{n_zone[i_zone] + 3}.1", # from chs
|
||||
]
|
||||
cooled = '1'
|
||||
if building.cooled:
|
||||
|
@ -394,7 +393,7 @@ class ThermalDemandDynamicSimulation:
|
|||
|
||||
i_block += 1
|
||||
inputs = [f"{i_block - 1}.1"]
|
||||
parameters = [f"{float(thermal_opening.area) * (1 - float(thermal_opening.frame_ratio))} %[AreaWindow]"]
|
||||
parameters = [f"{thermal_opening.area * (1 - thermal_opening.frame_ratio)} %[AreaWindow]"]
|
||||
file = Insel.add_block(file, i_block, 'GAIN', inputs=inputs, parameters=parameters)
|
||||
|
||||
inputs_next.append(f"{i_block}.1")
|
||||
|
@ -428,8 +427,8 @@ class ThermalDemandDynamicSimulation:
|
|||
i_surface += 1
|
||||
inputs = [f"{n_gain_moy}.1"]
|
||||
if (thermal_boundary.surface.type == cte.WALL) or (thermal_boundary.surface.type == cte.ROOF):
|
||||
inputs.append(f"{n_zone[i_tz] + 8}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 6}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 7}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 5}.{i_surface}")
|
||||
inputs.append(f"{n_ig}.{i_tz * 6 + 2}")
|
||||
inputs.append(f"{i_block + 2}.1")
|
||||
inputs.append(f"{n_weather}.1")
|
||||
|
@ -447,7 +446,7 @@ class ThermalDemandDynamicSimulation:
|
|||
for layer in thermal_boundary.layers:
|
||||
material = layer.material
|
||||
if material.no_mass:
|
||||
parameters.append(f"1 {1 / float(material.thermal_resistance)} 1 1 % [thick] + [lambda ] +[rho] +[cp]")
|
||||
parameters.append(f"1 {1 / material.thermal_resistance} 1 1 % [thick] + [lambda ] +[rho] +[cp]")
|
||||
else:
|
||||
parameters.append(f"{layer.thickness} {material.conductivity} {material.density} {material.specific_heat}"
|
||||
f" % [thick] + [lambda ] +[rho] +[cp]")
|
||||
|
@ -465,8 +464,8 @@ class ThermalDemandDynamicSimulation:
|
|||
else:
|
||||
i_weather += 2
|
||||
elif (thermal_boundary.surface.type == cte.GROUND) or (thermal_boundary.surface.type == cte.GROUND_WALL):
|
||||
inputs.append(f"{n_zone[i_tz] + 8}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 6}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 7}.{i_surface}")
|
||||
inputs.append(f"{n_zone[i_tz] + 5}.{i_surface}")
|
||||
inputs.append(f"{n_ig}.{i_tz * 6 + 2}")
|
||||
inputs.append(f"{n_weather}.3")
|
||||
inputs.append(f"{n_zone[i_tz] + 1}.1")
|
||||
|
@ -475,7 +474,7 @@ class ThermalDemandDynamicSimulation:
|
|||
for layer in thermal_boundary.layers:
|
||||
material = layer.material
|
||||
if material.no_mass:
|
||||
parameters.append(f"1 {1 / float(material.thermal_resistance)} 1 1 % [thick] + [lambda ] +[rho] +[cp]")
|
||||
parameters.append(f"1 {1 / material.thermal_resistance} 1 1 % [thick] + [lambda ] +[rho] +[cp]")
|
||||
else:
|
||||
parameters.append(f"{layer.thickness} {material.conductivity} {material.density} {material.specific_heat}"
|
||||
f" % [thick] + [lambda ] +[rho] +[cp]")
|
||||
|
@ -529,9 +528,8 @@ class ThermalDemandDynamicSimulation:
|
|||
f"{thermal_opening.radiative_coefficient} % [RadCoefeW]",
|
||||
f"0 % [Ubi]",
|
||||
f"1 % [Nlay]"]
|
||||
layer_conductivity = float(thermal_opening.thickness) / ((1/float(thermal_opening.overall_u_value)) -
|
||||
(1/float(thermal_opening.hi)) -
|
||||
(1/float(thermal_opening.he)))
|
||||
layer_conductivity = thermal_opening.thickness / ((1/thermal_opening.overall_u_value) -
|
||||
(1/thermal_opening.hi) - (1/thermal_opening.he))
|
||||
parameters_layer = f"{thermal_opening.thickness} {layer_conductivity} 1000 750 " \
|
||||
f"% [thick] + [lambda ] +[rho] +[cp]"
|
||||
parameters.append(parameters_layer)
|
||||
|
@ -541,7 +539,7 @@ class ThermalDemandDynamicSimulation:
|
|||
parameters = [f"{thermal_opening.area} %[AreaWindow]"]
|
||||
file = Insel.add_block(file, i_block, 'GAIN', inputs=inputs, parameters=parameters)
|
||||
i_block += 1
|
||||
inputs = [f"{n_zone[i_tz] + 6}.{i_surface}",
|
||||
inputs = [f"{n_zone[i_tz] + 5}.{i_surface}",
|
||||
f"{n_ig}.{i_tz * 6 + 2}"]
|
||||
file = Insel.add_block(file, i_block, 'SUM', inputs=inputs)
|
||||
if len(thermal_boundary.thermal_openings) > 0:
|
||||
|
@ -562,6 +560,7 @@ class ThermalDemandDynamicSimulation:
|
|||
content.rename(columns={content.columns[0]: 'ambient_temperature'})
|
||||
sky_temperature = wt.sky_temperature(building.external_temperature[cte.HOUR].to_numpy().T[0])
|
||||
content['sky_temperature'] = np.array(sky_temperature).astype(float)
|
||||
# todo calculate ground temperature
|
||||
# content['ground_temperature'] = building.ground_temperature
|
||||
content['ground_temperature'] = zeros
|
||||
for i_tb, thermal_boundary in enumerate(building.thermal_boundaries):
|
||||
|
@ -574,11 +573,6 @@ class ThermalDemandDynamicSimulation:
|
|||
content[f'darkness_value_{i_tb}'] = zeros
|
||||
content[f'wind_velocity_{i_tb}'] = zeros
|
||||
content.to_csv(weather_path, header=False, index=False, float_format='%12.3f')
|
||||
text = open(weather_path, 'r')
|
||||
text = ''.join([i for i in text]).replace(',', '')
|
||||
replaced_text = open(weather_path, 'w')
|
||||
replaced_text.writelines(text)
|
||||
replaced_text.close()
|
||||
|
||||
def generate_ig_file(self):
|
||||
"""
|
||||
|
@ -587,25 +581,66 @@ class ThermalDemandDynamicSimulation:
|
|||
building = self._building
|
||||
ig_path = self._ig_path
|
||||
content = pd.DataFrame()
|
||||
zeros = np.zeros(8760)
|
||||
for i_uz, usage_zone in enumerate(building.usage_zones):
|
||||
convective_part = 0
|
||||
radiative_part = 0
|
||||
convective_part = np.zeros(8760)
|
||||
radiative_part = np.zeros(8760)
|
||||
occupancy = []
|
||||
lighting = []
|
||||
appliances = []
|
||||
infiltration = []
|
||||
hvac_availability = []
|
||||
cooling_set_point = []
|
||||
heating_set_point = []
|
||||
for schedule in usage_zone.schedules:
|
||||
if schedule.type == cte.OCCUPANCY:
|
||||
occupancy.append(schedule)
|
||||
elif schedule.type == cte.LIGHTING:
|
||||
lighting.append(schedule)
|
||||
elif schedule.type == cte.RECEPTACLE:
|
||||
appliances.append(schedule)
|
||||
elif schedule.type == cte.INFILTRATION:
|
||||
infiltration.append(schedule)
|
||||
elif schedule.type == cte.HVAC_AVAILABILITY:
|
||||
hvac_availability.append(schedule)
|
||||
elif schedule.type == cte.COOLING_SET_POINT:
|
||||
cooling_set_point.append(schedule)
|
||||
elif schedule.type == cte.HEATING_SET_POINT:
|
||||
heating_set_point.append(schedule)
|
||||
|
||||
occupancy_yearly_schedule = ys(occupancy, 2015).yearly_schedule
|
||||
lighting_yearly_schedule = ys(lighting, 2015).yearly_schedule
|
||||
appliances_yearly_schedule = ys(appliances, 2015).yearly_schedule
|
||||
infiltration_yearly_schedule = ys(infiltration, 2015).yearly_schedule
|
||||
hvac_availability_yearly_schedule = ys(hvac_availability, 2015).yearly_schedule
|
||||
cooling_set_point_yearly_schedule = ys(cooling_set_point, 2015).yearly_schedule
|
||||
heating_set_point_yearly_schedule = ys(heating_set_point, 2015).yearly_schedule
|
||||
|
||||
mechanical_air_change = np.zeros(8760)
|
||||
for hour, value in enumerate(hvac_availability_yearly_schedule.values):
|
||||
mechanical_air_change[hour] += usage_zone.mechanical_air_change * value
|
||||
|
||||
for internal_gain in usage_zone.internal_gains:
|
||||
convective_part += internal_gain.average_internal_gain * internal_gain.convective_fraction
|
||||
radiative_part += internal_gain.average_internal_gain * internal_gain.radiative_fraction
|
||||
content[f'convective_part_{i_uz}'] = zeros
|
||||
content[f'radiative_part_{i_uz}'] = zeros
|
||||
content[f'infiltration_rate_{i_uz}'] = zeros
|
||||
content[f'ventilation_rate_{i_uz}'] = zeros
|
||||
content[f'set_point_cooling_{i_uz}'] = zeros
|
||||
content[f'set_point_heating_{i_uz}'] = zeros
|
||||
if internal_gain.type == cte.OCCUPANCY:
|
||||
for hour, value in enumerate(occupancy_yearly_schedule.values):
|
||||
convective_part[hour] += internal_gain.average_internal_gain * internal_gain.convective_fraction * value
|
||||
radiative_part[hour] += internal_gain.average_internal_gain * internal_gain.radiative_fraction * value
|
||||
elif internal_gain.type == cte.LIGHTING:
|
||||
for hour, value in enumerate(lighting_yearly_schedule.values):
|
||||
convective_part[hour] += internal_gain.average_internal_gain * internal_gain.convective_fraction * value
|
||||
radiative_part[hour] += internal_gain.average_internal_gain * internal_gain.radiative_fraction * value
|
||||
elif internal_gain.type == cte.RECEPTACLE:
|
||||
for hour, value in enumerate(appliances_yearly_schedule.values):
|
||||
convective_part[hour] += internal_gain.average_internal_gain * internal_gain.convective_fraction * value
|
||||
radiative_part[hour] += internal_gain.average_internal_gain * internal_gain.radiative_fraction * value
|
||||
|
||||
content[f'convective_part_{i_uz}'] = convective_part
|
||||
content[f'radiative_part_{i_uz}'] = radiative_part
|
||||
content[f'infiltration_rate_{i_uz}'] = np.zeros(8760)
|
||||
content[f'ventilation_rate_{i_uz}'] = mechanical_air_change
|
||||
# content[f'ventilation_rate_{i_uz}'] = np.zeros(8760)
|
||||
content[f'set_point_cooling_{i_uz}'] = cooling_set_point_yearly_schedule.values
|
||||
content[f'set_point_heating_{i_uz}'] = heating_set_point_yearly_schedule.values
|
||||
content.to_csv(ig_path, header=False, index=False, float_format='%12.3f')
|
||||
text = open(ig_path, 'r')
|
||||
text = ''.join([i for i in text]).replace(',', '')
|
||||
replaced_text = open(ig_path, 'w')
|
||||
replaced_text.writelines(text)
|
||||
replaced_text.close()
|
||||
|
||||
def generate_fij_files(self):
|
||||
"""
|
||||
|
|
54
main.py
54
main.py
|
@ -13,10 +13,10 @@ from city_model_structure.city import City
|
|||
name_gml = 'one_building_in_kelowna.gml'
|
||||
function_format = 'hft'
|
||||
construction_format = 'nrel'
|
||||
usage_format = 'hft'
|
||||
usage_format = 'comnet'
|
||||
schedules_format = 'comnet'
|
||||
climate_reference_city = 'Summerland'
|
||||
weather_file_name = 'CAN_BC_Summerland.717680_CWEC.epw'
|
||||
climate_reference_city = 'Montreal'
|
||||
weather_file_name = 'CAN_PQ_Montreal.Intl.AP.716270_CWEC.epw'
|
||||
|
||||
example_path = Path(__file__).parent
|
||||
full_path_gml = (example_path / 'tests' / 'tests_data' / name_gml).resolve()
|
||||
|
@ -24,14 +24,15 @@ outputs_path = (example_path / 'tests' / 'tests_outputs').resolve()
|
|||
tmp_path = (example_path / 'tests' / 'tmp').resolve()
|
||||
weather_path = (Path(__file__).parent.parent / 'libs' / 'data' / 'weather').resolve()
|
||||
keep_sra_file = True
|
||||
keep_insel_file = False
|
||||
keep_weather_file = False
|
||||
keep_ig_file = False
|
||||
keep_insel_file = True
|
||||
keep_weather_file = True
|
||||
keep_ig_file = True
|
||||
|
||||
pickle_geometry = True
|
||||
pickle_weather = False
|
||||
pickle_construction = False
|
||||
pickle_usage = False
|
||||
pickle_schedules = False
|
||||
pickle_weather = True
|
||||
pickle_construction = True
|
||||
pickle_usage = True
|
||||
pickle_schedules = True
|
||||
pickle_file = 'tests/tests_data/one_building_in_kelowna.pickle'
|
||||
|
||||
# Load geometry
|
||||
|
@ -55,34 +56,36 @@ if not pickle_weather:
|
|||
WeatherFactory(weather_format, city, base_path=weather_path, file_name=weather_file_name).enrich()
|
||||
|
||||
# calculate radiation on external surfaces
|
||||
max_buildings_handled_by_sra = 200
|
||||
path = (example_path / 'tests').resolve()
|
||||
total_number_of_buildings = len(city.buildings)
|
||||
if total_number_of_buildings > max_buildings_handled_by_sra:
|
||||
radius = 80
|
||||
for building in city.buildings:
|
||||
new_city = city.region(building.centroid, radius)
|
||||
sra = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
|
||||
sra.call_sra(weather_format, keep_files=keep_sra_file, selected_buildings=[building])
|
||||
sra.set_irradiance_surfaces(city, mode=1, building_name=building.name)
|
||||
else:
|
||||
sra = SimplifiedRadiosityAlgorithm(city, path, weather_file_name)
|
||||
sra.call_sra(weather_format, keep_files=keep_sra_file)
|
||||
sra.set_irradiance_surfaces(city, mode=1)
|
||||
radius = 80
|
||||
building = city.city_object('BLD109438')
|
||||
# building = city.city_object('1066157')
|
||||
new_city = city.region(building.centroid, radius)
|
||||
sra = SimplifiedRadiosityAlgorithm(new_city, path, weather_file_name)
|
||||
sra.call_sra(weather_format, keep_files=keep_sra_file, selected_buildings=[building])
|
||||
sra.set_irradiance_surfaces(city, mode=1, building_name=building.name)
|
||||
|
||||
# to save only the targeted building
|
||||
radius = 10
|
||||
city = city.region(building.centroid, radius)
|
||||
city.save(pickle_file)
|
||||
else:
|
||||
city = City.load(pickle_file)
|
||||
|
||||
# Enrich city with construction, usage and schedules
|
||||
# Enrich target building in the city with construction, usage and schedules
|
||||
if not pickle_construction or not pickle_usage or not pickle_schedules:
|
||||
|
||||
for building in city.buildings:
|
||||
building.function = 'large office'
|
||||
building.year_of_construction = 2010
|
||||
|
||||
if function_format == 'hft':
|
||||
building.function = GeometryHelper.hft_to_function[building.function]
|
||||
elif function_format == 'pluto':
|
||||
building.function = GeometryHelper.pluto_to_function[building.function]
|
||||
city = EnrichCity(city).enriched_city(construction_format, usage_format, schedules_format,
|
||||
pickle_construction, pickle_usage, pickle_schedules)
|
||||
|
||||
city.save(pickle_file)
|
||||
else:
|
||||
city = City.load(pickle_file)
|
||||
|
@ -138,8 +141,9 @@ for building in city.buildings:
|
|||
template.generate_fij_files()
|
||||
print(insel_file_name)
|
||||
insel = Insel(example_path, insel_file_name, content, mode=2, keep_files=keep_insel_file).results
|
||||
break
|
||||
|
||||
except:
|
||||
except ValueError:
|
||||
print(sys.exc_info()[1])
|
||||
print('Building ' + building.name + ' could not be processed')
|
||||
continue
|
||||
|
|
Loading…
Reference in New Issue
Block a user