Skip to content

Commit fd05253

Browse files
committed
Update 3.9.0 to 3.8.0 (and fix an issue in the eatPump:PlantLoop:EIR:Cooling translation)
1 parent bcdc398 commit fd05253

File tree

2 files changed

+19
-113
lines changed

2 files changed

+19
-113
lines changed
Lines changed: 18 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import openstudio
22
from loguru import logger
33

4+
from openstudiobackporter.helpers import copy_object_as_is, copy_with_cutoff_fields, copy_with_deleted_fields
5+
46

57
def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
68
"""Backport an IdfFile from 3.9.0 to 3.8.0."""
@@ -16,34 +18,25 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
1618
for obj in idf_3_9_0.objects():
1719
iddname = obj.iddObject().name()
1820

21+
iddObject = idd_3_8_0.getObject(iddname).get()
22+
newObject = openstudio.IdfObject(iddObject)
23+
1924
if iddname == "OS:Controller:OutdoorAir":
2025

2126
# 2 Fields have been made required from 3.8.0 to 3.9.0:
2227
# ----------------------------------------------
2328
# * High Humidity Outdoor Air Flow Ratio * 24
2429
# * Control High Indoor Humidity Based on Outdoor Humidity Ratio * 25
2530
# Fields were made required, so they filled in the default value. I don't see the point reverting that.
26-
targetIdf.addObject(obj)
31+
copy_object_as_is(obj=obj, newObject=newObject)
32+
targetIdf.addObject(newObject)
2733

2834
elif iddname == "OS:OutputControl:Files":
2935
# 1 Field has been added from 3.8.0 to 3.9.0:
3036
# ----------------------------------------------
3137
# * Output Space Sizing * 9
32-
iddObject = idd_3_8_0.getObject(iddname).get()
33-
newObject = openstudio.IdfObject(iddObject)
34-
35-
skip = 9
36-
37-
for i in range(obj.numFields()):
38-
if i == skip:
39-
continue
40-
elif i < skip:
41-
if value := obj.getString(i):
42-
newObject.setString(i, value.get())
43-
else:
44-
if value := obj.getString(i):
45-
newObject.setString(i - 1, value.get())
4638

39+
copy_with_deleted_fields(obj=obj, newObject=newObject, skip_indices={9})
4740
targetIdf.addObject(newObject)
4841

4942
elif iddname == "OS:HeatPump:PlantLoop:EIR:Heating":
@@ -57,28 +50,8 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
5750
# 1 required Field has been added from 3.8.0 to 3.9.0:
5851
# ----------------------------------------------
5952
# * Minimum Heat Recovery Outlet Temperature * 36
60-
iddObject = idd_3_8_0.getObject(iddname).get()
61-
newObject = openstudio.IdfObject(iddObject)
62-
63-
for i in range(obj.numFields()):
64-
value = obj.getString(i)
65-
if value.is_initialized():
66-
if i < 7:
67-
# fields before the inserted ones → same index
68-
newObject.setString(i, value.get())
69-
elif i < 9:
70-
# 7 and 8 are new fields we are deleting
71-
continue
72-
elif i < 12:
73-
# fields between old 7–9 were shifted by +2
74-
newObject.setString(i - 2, value.get())
75-
elif i < 36:
76-
# fields after 10 were shifted by +3
77-
newObject.setString(i - 3, value.get())
78-
else:
79-
# Field 36 was added, we remove it
80-
continue
8153

54+
copy_with_deleted_fields(obj=obj, newObject=newObject, skip_indices={7, 8, 12, 36})
8255
targetIdf.addObject(newObject)
8356

8457
elif iddname == "OS:HeatPump:PlantLoop:EIR:Cooling":
@@ -89,35 +62,12 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
8962
# * Heat Recovery Outlet Node Name * 8
9063
# * Heat Recovery Reference Flow Rate * 12
9164

92-
# 2 required Fields have been added from 3.8.0 to 3.9.0:
65+
# 5 fields added at end, 2 are required Fields, from 3.8.0 to 3.9.0:
9366
# ----------------------------------------------
9467
# * Maximum Heat Recovery Outlet Temperature * 26
9568
# * Minimum Thermosiphon Minimum Temperature Difference * 30
96-
iddObject = idd_3_8_0.getObject(iddname).get()
97-
newObject = openstudio.IdfObject(iddObject)
98-
99-
for i in range(obj.numFields()):
100-
value = obj.getString(i)
101-
if value.is_initialized():
102-
if i < 7:
103-
# fields before the inserted ones → same index
104-
newObject.setString(i, value.get())
105-
elif i < 9:
106-
# 7 and 8 are new fields we are deleting
107-
continue
108-
elif i < 12:
109-
# fields between old 7–9 were shifted by +2
110-
newObject.setString(i - 2, value.get())
111-
elif i < 26:
112-
# fields after 10 were shifted by +3
113-
newObject.setString(i - 3, value.get())
114-
elif i < 30:
115-
# fields between old 26–30 were shifted by +4
116-
newObject.setString(i - 4, value.get())
117-
else:
118-
# Field 30 was added, we remove it
119-
continue
12069

70+
copy_with_deleted_fields(obj=obj, newObject=newObject, skip_indices={7, 8, 12, 26, 27, 28, 29, 30})
12171
targetIdf.addObject(newObject)
12272

12373
elif iddname == "OS:AirTerminal:SingleDuct:SeriesPIU:Reheat":
@@ -129,15 +79,7 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
12979
# * Design Heating Discharge Air Temperature * 19
13080
# * High Limit Heating Discharge Air Temperature * 20
13181

132-
iddObject = idd_3_8_0.getObject(iddname).get()
133-
newObject = openstudio.IdfObject(iddObject)
134-
135-
for i in range(obj.numFields()):
136-
value = obj.getString(i)
137-
if value.is_initialized():
138-
if i < 16:
139-
newObject.setString(i, value.get())
140-
82+
copy_with_cutoff_fields(obj=obj, newObject=newObject, cutoff_index=16)
14183
targetIdf.addObject(newObject)
14284

14385
elif iddname == "OS:AirTerminal:SingleDuct:ParallelPIU:Reheat":
@@ -148,15 +90,8 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
14890
# * Heating Control Type * 19
14991
# * Design Heating Discharge Air Temperature * 20
15092
# * High Limit Heating Discharge Air Temperature * 21
151-
iddObject = idd_3_8_0.getObject(iddname).get()
152-
newObject = openstudio.IdfObject(iddObject)
153-
154-
for i in range(obj.numFields()):
155-
value = obj.getString(i)
156-
if value.is_initialized():
157-
if i < 17:
158-
newObject.setString(i, value.get())
15993

94+
copy_with_cutoff_fields(obj=obj, newObject=newObject, cutoff_index=17)
16095
targetIdf.addObject(newObject)
16196

16297
elif iddname == "OS:Chiller:Electric:EIR":
@@ -165,19 +100,8 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
165100
# * Condenser Flow Control * 35
166101
# * Condenser Minimum Flow Fraction * 38
167102
# * Thermosiphon Minimum Temperature Difference * 40
168-
iddObject = idd_3_8_0.getObject(iddname).get()
169-
newObject = openstudio.IdfObject(iddObject)
170-
171-
for i in range(obj.numFields()):
172-
value = obj.getString(i)
173-
if value.is_initialized():
174-
if i < 35:
175-
# fields before the inserted ones, same index
176-
newObject.setString(i, value.get())
177-
else:
178-
# Field 35 to 40 were added at the end, removing
179-
continue
180103

104+
copy_with_cutoff_fields(obj=obj, newObject=newObject, cutoff_index=35)
181105
targetIdf.addObject(newObject)
182106

183107
elif iddname == "OS:Chiller:Electric:ReformulatedEIR":
@@ -187,37 +111,19 @@ def run_translation(idf_3_9_0: openstudio.IdfFile) -> openstudio.IdfFile:
187111
# * Condenser Minimum Flow Fraction * 34
188112
# * Thermosiphon Minimum Temperature Difference * 36 (at end)
189113

190-
iddObject = idd_3_8_0.getObject(iddname).get()
191-
newObject = openstudio.IdfObject(iddObject)
192-
193-
for i in range(obj.numFields()):
194-
value = obj.getString(i)
195-
if value.is_initialized():
196-
if i < 31:
197-
# fields before the inserted ones, same index
198-
newObject.setString(i, value.get())
199-
else:
200-
# Field 31 to 36 were added at the end, removing
201-
continue
202-
114+
copy_with_cutoff_fields(obj=obj, newObject=newObject, cutoff_index=31)
203115
targetIdf.addObject(newObject)
204116

205117
elif iddname == "OS:Sizing:Zone":
206118
# 1 required Field has been added from 3.8.0 to 3.9.0:
207119
# ----------------------------------------------
208120
# * Sizing Option * 39 (at end)
209-
iddObject = idd_3_8_0.getObject(iddname).get()
210-
newObject = openstudio.IdfObject(iddObject)
211-
212-
for i in range(obj.numFields()):
213-
value = obj.getString(i)
214-
if value.is_initialized():
215-
if i < 39:
216-
newObject.setString(i, value.get())
217121

122+
copy_with_cutoff_fields(obj=obj, newObject=newObject, cutoff_index=39)
218123
targetIdf.addObject(newObject)
219124

220125
else:
221-
targetIdf.addObject(obj)
126+
copy_object_as_is(obj=obj, newObject=newObject)
127+
targetIdf.addObject(newObject)
222128

223129
return targetIdf

tests/test_3_9_0_to_3_8_0.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def test_vt_HeatPumpPlantLoopEIR():
144144

145145
assert hp_cooling.getDouble(20).get() == 100.0 # Maximum Source Inlet Temperature {C}
146146
assert hp_cooling.isEmpty(21) # Minimum Supply Water Temperature Curve Name
147-
assert hp_cooling.getDouble(22).get() == 60.0 # Maximum Supply Water Temperature Curve Name
147+
assert hp_cooling.isEmpty(22) # Maximum Supply Water Temperature Curve Name
148148

149149
# Two last fields deleted Minimum/Maximum Supply Water Temperature Curve Name
150150
assert hp_cooling.numFields() == 23

0 commit comments

Comments
 (0)