-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_hvac.py
More file actions
454 lines (409 loc) · 13.8 KB
/
generate_hvac.py
File metadata and controls
454 lines (409 loc) · 13.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
""""hvac generator"""
import os
from idfhub.hvac import (
PLANT, DEMAND,
EPApi, EPValues,
add_plantloop,
add_baseboard,
create_branch,
Branches,
plantloop_split_mix
)
# autocompletion use
from idfhub.idf_autocomplete.v24_1_0.idf_helpers_short import (
Timestep, SizingperiodDesignday, Runperiod, Version, Simulationcontrol,
Building, Globalgeometryrules,
Scheduletypelimits,
ThermostatsetpointDualsetpoint, ZonecontrolThermostat,
SizingParameters, SizingZone, SizingPlant,
ZonehvacEquipmentlist, ZonehvacEquipmentconnections,
OutputEnergymanagementsystem,
OutputVariabledictionary,
OutputTableSummaryreports, OutputcontrolTableStyle,
OutputVariable, OutputSqlite,
FluidpropertiesGlycolconcentration,FluidpropertiesGlycolconcentrationMeta
)
from idfhub.idf_autocomplete.v24_1_0.idf_types_short import (
TimestepType, SizingperiodDesigndayType, RunperiodType, VersionType, SimulationcontrolType,
BuildingType, GlobalgeometryrulesType,
ScheduletypelimitsType,
ThermostatsetpointDualsetpointType, ZonecontrolThermostatType,
SizingParametersType, SizingZoneType, SizingPlantType,
ZonehvacEquipmentlistType, ZonehvacEquipmentconnectionsType,
OutputEnergymanagementsystemType,
OutputVariabledictionaryType,
OutputTableSummaryreportsType, OutputcontrolTableStyleType,
OutputVariableType, OutputSqliteType,
FluidpropertiesGlycolconcentrationType,
)
from idfhub.common import (
idf, get_logger,
BUILDING_NAME, PROJECT_NAME,
CONF, ZONES, LOOPS,
EQUIPMENTS, SENSORS
)
from idfhub.hvac24_1_0 import (
loops, equipments,
consigne_cool, consigne_heat,
ground_temperature,
vertical_geoexchanger,
pump,
water_to_water_heatpump,
water_law, constant_set_point,
adjust_nodes_branch, generate_operation_list,
control_manager,
constant_schedule, basic_compact_schedule,
gas_boiler,
air_to_water_heatpump_eir
)
FORMAT = (
'%(asctime)s | %(levelname).1s | '
'%(name)s:%(lineno)d | '
'%(message)s'
)
LOGGER = get_logger(format=FORMAT)
MESSAGE = f"idf hvac injection for energyplus {idf.idd_version}"
LOGGER.info(MESSAGE)
EP_SIM_PATH = "ep_simulations"
SOIL = "soil"
WATER_HEATING = "water_heating"
WATER_LAW = "water_law"
CONSTANT = "constant"
BOREHOLE = "borehole"
PUMP = "pump"
HP = "hp"
HPWTW = "hpwtw"
HPATW = "hpatw"
BOILER = "boiler"
Timestep(
idf,
**TimestepType(
Number_of_Timesteps_per_Hour=6
)
)
Version(idf, **VersionType())
Simulationcontrol(
idf,
**SimulationcontrolType(
Do_Zone_Sizing_Calculation="Yes",
Do_Plant_Sizing_Calculation="Yes",
Do_System_Sizing_Calculation="Yes",
Do_HVAC_Sizing_Simulation_for_Sizing_Periods="Yes",
Maximum_Number_of_HVAC_Sizing_Simulation_Passes=2
)
)
SizingperiodDesignday(
idf,
**SizingperiodDesigndayType(
Name="design_day",
Month=1,
Day_of_Month=1,
Day_Type=EPValues.WINTER_DESIGN_DAY,
Maximum_DryBulb_Temperature=-5,
Wind_Speed=0,
Wind_Direction=0,
Wetbulb_or_DewPoint_at_Maximum_DryBulb=-10,
Humidity_Condition_Type="DewPoint"
)
)
Runperiod(
idf,
**RunperiodType(
Name="run period",
Begin_Month=1,
Begin_Day_of_Month=1,
End_Month=12,
End_Day_of_Month=31,
Use_Weather_File_Holidays_and_Special_Days="No",
Use_Weather_File_Daylight_Saving_Period="No"
)
)
SizingParameters(
idf,
**SizingParametersType(
Heating_Sizing_Factor=1.25,
Cooling_Sizing_Factor=1.15
)
)
Building(
idf,
**BuildingType(
Name="CeremaCF",
Loads_Convergence_Tolerance_Value=0.04,
Temperature_Convergence_Tolerance_Value=0.4
)
)
Globalgeometryrules(
idf,
**GlobalgeometryrulesType(
Starting_Vertex_Position="UpperLeftCorner",
Vertex_Entry_Direction="Counterclockwise",
Coordinate_System="Relative"
)
)
#------------------------------------------------------------------------------
# Schedules and Thermostats
#------------------------------------------------------------------------------
# generate_geometry nécessite un schedule constant appelé Always On utilisant Fractional ????
fractional_typelimits = Scheduletypelimits(
idf,
**ScheduletypelimitsType(
Name="Fractional",
Lower_Limit_Value=0,
Upper_Limit_Value=1,
Numeric_Type=EPValues.CONTINUOUS,
)
)
consigne_heat = basic_compact_schedule(20, schedule_name="heating_schedule")
zone_thermostat = ThermostatsetpointDualsetpoint(
idf,
**ThermostatsetpointDualsetpointType(
Name="zone_thermostat",
Heating_Setpoint_Temperature_Schedule_Name=consigne_heat.Name,
Cooling_Setpoint_Temperature_Schedule_Name=consigne_cool.Name
)
)
# Control types are integers:
# 0 - Uncontrolled (floating, no thermostat),
# 1 = ThermostatSetpoint:SingleHeating,
# 2 = ThermostatSetpoint:SingleCooling,
# 3 = ThermostatSetpoint:SingleHeatingOrCooling,
# 4 = ThermostatSetpoint:DualSetpoint
control_typelimits = Scheduletypelimits(
idf,
**ScheduletypelimitsType(
Name="control_types",
Lower_Limit_Value=0,
Upper_Limit_Value=4,
Numeric_Type=EPValues.DISCRETE
)
)
control_type_schedule = basic_compact_schedule(
4,
schedule_name="control_type_schedule",
typelimits=control_typelimits
)
control_type_constant_schedule = constant_schedule(
4,
name= "AlwaysDualSetpoint",
typelimits=control_typelimits
)
for zone in ZONES:
ZonecontrolThermostat(
idf,
**ZonecontrolThermostatType(
Name=f"{zone}_thermostat",
Zone_or_ZoneList_Name=zone,
Control_Type_Schedule_Name=control_type_constant_schedule.Name,
Control_1_Object_Type=zone_thermostat.key,
Control_1_Name=zone_thermostat.Name
)
)
#------------------------------------------------------------------------------
# End Of Schedules and Thermostats
#------------------------------------------------------------------------------
#------------------------------------------------------------------------------
# Plant Loops
#------------------------------------------------------------------------------
for loop in LOOPS:
conf = CONF.get(loop, {})
if SOIL in loop or TANK in loop:
liquid_name = "eau glycol 30pourcent"
glycol_water_30 = idf.getobject(
FluidpropertiesGlycolconcentrationMeta.idf_name,
liquid_name
)
if glycol_water_30 is None:
glycol_water_30 = FluidpropertiesGlycolconcentration(
idf,
**FluidpropertiesGlycolconcentrationType(
Name=liquid_name,
Glycol_Type="PropyleneGlycol",
Glycol_Concentration=0.3
)
)
plant_loop = add_plantloop(idf, loop, 35, -5)
plant_loop.Fluid_Type = "UserDefinedFluidType"
plant_loop.User_Defined_Fluid_Type = glycol_water_30.Name
loops[loop] = plant_loop
if WATER_HEATING in loop:
heating_loop = add_plantloop(idf, loop, 100, 0)
loops[loop] = heating_loop
# à supprimer
heating_loop_branches = Branches(loop)
SizingPlant(
idf,
**SizingPlantType(
Plant_or_Condenser_Loop_Name=loop,
Loop_Type=conf.get("Loop_Type", "Heating"),
Design_Loop_Exit_Temperature=conf.get("Design_Loop_Exit_Temperature", 70),
Loop_Design_Temperature_Difference=conf.get("Loop_Design_Temperature_Difference", 10),
Sizing_Option="NonCoincident",
Zone_Timesteps_in_Averaging_Window=1,
)
)
def basic_zone_sizing(zone_name: str):
"""basic zone sizing"""
return SizingZone(
idf,
**SizingZoneType(
Zone_or_ZoneList_Name=zone_name,
Zone_Cooling_Design_Supply_Air_Humidity_Ratio=0.008,
Zone_Heating_Design_Supply_Air_Humidity_Ratio=0.008,
Zone_Heating_Design_Supply_Air_Temperature=40,
)
)
for zone in ZONES:
basic_zone_sizing(zone)
for equipment_name in EQUIPMENTS:
if PUMP in equipment_name:
pump_type = "constant"
if "variable" in equipment_name:
pump_type = "variable"
equipments[equipment_name] = pump(equipment_name, pump_type=pump_type)
continue
if BOREHOLE in equipment_name:
ground_temperature()
borehole = vertical_geoexchanger(equipment_name)
equipments[equipment_name] = borehole
continue
if HPWTW in equipment_name:
hpwtw = water_to_water_heatpump(equipment_name)
equipments[equipment_name] = hpwtw
continue
if HPATW in equipment_name:
hpatw = air_to_water_heatpump_eir(equipment_name)
equipments[equipment_name] = hpatw
continue
if BOILER in equipment_name:
boiler = gas_boiler(equipment_name)
equipments[equipment_name] = boiler
if SENSORS:
for sensor, conf in SENSORS.items():
if conf.get("active", 1):
control_manager(sensor, conf)
for loop in LOOPS:
setpoint = CONF[loop].get("setpoint")
branches_descr: dict[str, list[str]]
branches_descr = CONF[loop].get("branches", {})
if WATER_LAW in setpoint:
water_law(loop, setpoint)
if CONSTANT in setpoint:
constant_set_point(loop, setpoint)
for loop_side in [PLANT, DEMAND]:
if loop_side in branches_descr:
adjust_nodes_branch(
loop,
loop_side=loop_side,
branches_descr=branches_descr
)
generate_operation_list(loop)
#------------------------------------------------------------------------------
# EMISSION SYSTEMS
#------------------------------------------------------------------------------
baseboards = {}
baseboard_branches = {}
for zone in ZONES:
baseboards[zone] = add_baseboard(idf, zone)
baseboard_branches[zone] = create_branch(
idf,
name = f"{heating_loop_branches.demand_branch} {zone}",
objects = [baseboards[zone]],
sides = [None]
)
plantloop_split_mix(
idf=idf,
plantloop=heating_loop,
side=EPApi.DEMAND_SIDE,
branches=list(baseboard_branches.values())
)
#------------------------------------------------------------------------------
# ZONE EQUIPMENTS DECLARATION
#------------------------------------------------------------------------------
equipment_list = {}
for zone in ZONES:
equipment_list[zone] = ZonehvacEquipmentlist(
idf,
**ZonehvacEquipmentlistType(
Name=f"{zone} equipment list",
Zone_Equipment_1_Name=baseboards[zone].Name,
Zone_Equipment_1_Object_Type=baseboards[zone].key,
Zone_Equipment_1_Cooling_Sequence=1,
Zone_Equipment_1_Heating_or_NoLoad_Sequence=1
)
)
ZonehvacEquipmentconnections(
idf,
**ZonehvacEquipmentconnectionsType(
Zone_Name=zone,
Zone_Conditioning_Equipment_List_Name=equipment_list[zone].Name,
Zone_Air_Node_Name=f"{zone} air node"
)
)
#------------------------------------------------------------------------------
# OUTPUT CONFIGURATION
#------------------------------------------------------------------------------
OutputVariabledictionary(
idf,
**OutputVariabledictionaryType(
Key_Field="IDF",
Sort_Option="Unsorted"
)
)
OutputTableSummaryreports(idf, **OutputTableSummaryreportsType(Report_1_Name="AllSummary"))
OutputcontrolTableStyle(idf, **OutputcontrolTableStyleType(Column_Separator="HTML"))
OutputEnergymanagementsystem(idf, **OutputEnergymanagementsystemType(
Actuator_Availability_Dictionary_Reporting="Verbose",
Internal_Variable_Availability_Dictionary_Reporting="Verbose",
EMS_Runtime_Language_Debug_Output_Level="None"
))
def add_variable(name):
"""add a variable to the ep output"""
OutputVariable(
idf,
**OutputVariableType(
Key_Value="*",
Variable_Name=name,
Reporting_Frequency="Timestep"
)
)
# tout ce tuning des variables de sortie peut être raisonnablement fait avec IDFEditor
add_variable("Site Outdoor Air Drybulb Temperature")
add_variable("Zone Air Temperature")
add_variable("Zone Thermostat Heating Setpoint Temperature")
for equipment_name in EQUIPMENTS:
if BOREHOLE in equipment_name:
add_variable("Ground Heat Exchanger Heat Transfer Rate")
add_variable("Ground Heat Exchanger Inlet Temperature")
add_variable("Ground Heat Exchanger Outlet Temperature")
if HP in equipment_name:
suffix = "Heat Pump"
add_variable(f"{suffix} Load Side Outlet Temperature")
add_variable(f"{suffix} Load Side Inlet Temperature")
add_variable(f"{suffix} Source Side Outlet Temperature")
add_variable(f"{suffix} Source Side Inlet Temperature")
add_variable(f"{suffix} Source Side Mass Flow Rate")
add_variable(f"{suffix} Electricity Rate")
add_variable(f"{suffix} Load Side Heat Transfer Rate")
add_variable(f"{suffix} Source Side Heat Transfer Rate")
if BOILER in equipment_name:
add_variable("Boiler Heating Rate")
add_variable("Baseboard Total Heating Rate")
add_variable("Baseboard Water Inlet Temperature")
add_variable("Baseboard Water Outlet Temperature")
add_variable("Pump Mass Flow Rate")
OutputSqlite(
idf,
**OutputSqliteType(
Option_Type="SimpleAndTabular"
)
)
input("press")
if not os.path.exists(EP_SIM_PATH):
os.mkdir(EP_SIM_PATH)
if not os.path.exists(f"{EP_SIM_PATH}/{BUILDING_NAME}"):
os.mkdir(f"{EP_SIM_PATH}/{BUILDING_NAME}")
if not os.path.exists(f"{EP_SIM_PATH}/{BUILDING_NAME}/{PROJECT_NAME}"):
os.mkdir(f"{EP_SIM_PATH}/{BUILDING_NAME}/{PROJECT_NAME}")
final_name = f"{EP_SIM_PATH}/{BUILDING_NAME}/{PROJECT_NAME}/{PROJECT_NAME}.idf"
idf.save(final_name)