Skip to content

Commit

Permalink
Fix tests. Use kwargs in new model.rb methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
shorowit committed Sep 27, 2024
1 parent 59986a8 commit 40d31b4
Show file tree
Hide file tree
Showing 10 changed files with 470 additions and 250 deletions.
30 changes: 18 additions & 12 deletions HPXMLtoOpenStudio/measure.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<schema_version>3.1</schema_version>
<name>hpxm_lto_openstudio</name>
<uid>b1543b30-9465-45ff-ba04-1d1f85e763bc</uid>
<version_id>3e4ea1b3-d604-45af-b4ab-26d7a547eae1</version_id>
<version_modified>2024-09-27T00:56:02Z</version_modified>
<version_id>5c67ecce-f8a5-4a5d-9407-2fdb6831e9ed</version_id>
<version_modified>2024-09-27T03:44:30Z</version_modified>
<xml_checksum>D8922A73</xml_checksum>
<class_name>HPXMLtoOpenStudio</class_name>
<display_name>HPXML to OpenStudio Translator</display_name>
Expand Down Expand Up @@ -189,13 +189,13 @@
<filename>airflow.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>92C7CF97</checksum>
<checksum>75466EF1</checksum>
</file>
<file>
<filename>battery.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>01C783CF</checksum>
<checksum>16BC6859</checksum>
</file>
<file>
<filename>calendar.rb</filename>
Expand Down Expand Up @@ -327,7 +327,7 @@
<filename>energyplus.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>D01BA3EF</checksum>
<checksum>102BE9DA</checksum>
</file>
<file>
<filename>generator.rb</filename>
Expand All @@ -345,7 +345,7 @@
<filename>hotwater_appliances.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>743776B5</checksum>
<checksum>BE80A8AD</checksum>
</file>
<file>
<filename>hpxml.rb</filename>
Expand Down Expand Up @@ -387,7 +387,7 @@
<filename>hvac.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>6938C0F9</checksum>
<checksum>DEE68AC1</checksum>
</file>
<file>
<filename>hvac_sizing.rb</filename>
Expand All @@ -399,13 +399,13 @@
<filename>internal_gains.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>0063AB09</checksum>
<checksum>A6D2B4D1</checksum>
</file>
<file>
<filename>lighting.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>327965F6</checksum>
<checksum>DA934DC4</checksum>
</file>
<file>
<filename>location.rb</filename>
Expand Down Expand Up @@ -441,13 +441,13 @@
<filename>misc_loads.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>8BF763AF</checksum>
<checksum>FBAF9307</checksum>
</file>
<file>
<filename>model.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>617CD183</checksum>
<checksum>21A66158</checksum>
</file>
<file>
<filename>output.rb</filename>
Expand Down Expand Up @@ -627,7 +627,7 @@
<filename>waterheater.rb</filename>
<filetype>rb</filetype>
<usage_type>resource</usage_type>
<checksum>BCBFF2E3</checksum>
<checksum>FD2B6E78</checksum>
</file>
<file>
<filename>weather.rb</filename>
Expand All @@ -647,6 +647,12 @@
<usage_type>resource</usage_type>
<checksum>93120E27</checksum>
</file>
<file>
<filename>in.schedules.csv</filename>
<filetype>csv</filetype>
<usage_type>test</usage_type>
<checksum>61EDE63A</checksum>
</file>
<file>
<filename>test_airflow.rb</filename>
<filetype>rb</filetype>
Expand Down
137 changes: 92 additions & 45 deletions HPXMLtoOpenStudio/resources/airflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,15 @@ def self.apply_natural_ventilation_and_whole_house_fan(runner, model, spaces, hp
whf_flow.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeWholeHouseFan)

# Whole house fan electricity consumption
space = conditioned_space # no heat gain, so assign the equipment to an arbitrary space
obj_name = Constants::ObjectTypeWholeHouseFan
whf_equip = Model.add_electric_equipment(model, obj_name, obj_name, space, nil, 0, 0, 1, model.alwaysOnDiscreteSchedule)
whf_equip = Model.add_electric_equipment(model,
name: Constants::ObjectTypeWholeHouseFan,
end_use: Constants::ObjectTypeWholeHouseFan,
space: conditioned_space, # no heat gain, so assign the equipment to an arbitrary space
design_level: nil, # will be EMS-actuated
frac_radiant: 0,
frac_latent: 0,
frac_lost: 1,
schedule: model.alwaysOnDiscreteSchedule)

whf_elec_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(whf_equip, *EPlus::EMSActuatorElectricEquipmentPower, whf_equip.space.get)
whf_elec_actuator.setName("#{whf_equip.name} act")
Expand Down Expand Up @@ -630,35 +636,6 @@ def self.create_return_air_duct_zone(model, loop_name, unit_multiplier, adiabati
return ra_duct_zone, adiabatic_const
end

# TODO
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
# @param name [TODO] TODO
# @param space [OpenStudio::Model::Space] an OpenStudio::Model::Space object
# @param frac_lat [TODO] TODO
# @param frac_lost [TODO] TODO
# @param hpxml_fuel_type [String] HPXML fuel type (HPXML::FuelTypeXXX)
# @param end_use [TODO] TODO
# @return [TODO] TODO
def self.create_other_equipment_object_and_actuator(model:, name:, space:, frac_lat:, frac_lost:, hpxml_fuel_type: nil, end_use: nil)
other_equip_def = OpenStudio::Model::OtherEquipmentDefinition.new(model)
other_equip_def.setName("#{name} equip")
other_equip = OpenStudio::Model::OtherEquipment.new(other_equip_def)
other_equip.setName(other_equip_def.name.to_s)
other_equip.setFuelType(EPlus.fuel_type(hpxml_fuel_type))
if not end_use.nil?
other_equip.setEndUseSubcategory(end_use)
end
other_equip.setSchedule(model.alwaysOnDiscreteSchedule)
other_equip.setSpace(space)
other_equip_def.setFractionLost(frac_lost)
other_equip_def.setFractionLatent(frac_lat)
other_equip_def.setFractionRadiant(0.0)
actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(other_equip, *EPlus::EMSActuatorOtherEquipmentPower, other_equip.space.get)
actuator.setName("#{other_equip.name} act")
return actuator
end

# TODO
#
# @param model [OpenStudio::Model::Model] OpenStudio Model object
Expand Down Expand Up @@ -1050,7 +1027,18 @@ def self.apply_ducts(model, spaces, hpxml_bldg, ducts, object, vent_fans, cfis_d
if not is_cfis
duct_vars[var_name] = OpenStudio::Model::EnergyManagementSystemGlobalVariable.new(model, object_name)
end
duct_actuators[var_name] = create_other_equipment_object_and_actuator(model: model, name: object_name, space: space, frac_lat: frac_lat, frac_lost: frac_lost, end_use: end_use)
other_equip = Model.add_other_equipment(model,
name: object_name,
end_use: end_use,
space: space,
design_level: nil,
frac_radiant: 0,
frac_latent: frac_lat,
frac_lost: frac_lost,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: nil)
duct_actuators[var_name] = OpenStudio::Model::EnergyManagementSystemActuator.new(other_equip, *EPlus::EMSActuatorOtherEquipmentPower, other_equip.space.get)
duct_actuators[var_name].setName("#{other_equip.name} act")
end
end

Expand Down Expand Up @@ -1540,10 +1528,15 @@ def self.apply_local_ventilation(model, spaces, vent_object, obj_type_name, inde
obj_sch_sensor.setName("#{obj_name} sch s")
obj_sch_sensor.setKeyName(obj_sch.schedule.name.to_s)

space = spaces[HPXML::LocationConditionedSpace] # no heat gain, so assign the equipment to an arbitrary space
design_level = vent_object.fan_power * vent_object.count

Model.add_electric_equipment(model, obj_name, Constants::ObjectTypeMechanicalVentilation, space, design_level, 0, 0, 1, obj_sch.schedule)
Model.add_electric_equipment(model,
name: obj_name,
end_use: Constants::ObjectTypeMechanicalVentilation,
space: spaces[HPXML::LocationConditionedSpace], # no heat gain, so assign the equipment to an arbitrary space
design_level: vent_object.fan_power * vent_object.count,
frac_radiant: 0,
frac_latent: 0,
frac_lost: 1,
schedule: obj_sch.schedule)

return obj_sch_sensor
end
Expand Down Expand Up @@ -1812,7 +1805,15 @@ def self.add_ee_for_vent_fan_power(model, spaces, obj_name, sup_fans = [], exh_f
# Availability Schedule
avail_sch = ScheduleConstant.new(model, obj_name + ' schedule', 1.0, EPlus::ScheduleTypeLimitsFraction, unavailable_periods: unavailable_periods)

equip = Model.add_electric_equipment(model, obj_name, Constants::ObjectTypeMechanicalVentilation, spaces[HPXML::LocationConditionedSpace], tot_fans_w, 0, 0, fan_heat_lost_fraction, avail_sch.schedule)
equip = Model.add_electric_equipment(model,
name: obj_name,
end_use: Constants::ObjectTypeMechanicalVentilation,
space: spaces[HPXML::LocationConditionedSpace],
design_level: tot_fans_w,
frac_radiant: 0,
frac_latent: 0,
frac_lost: fan_heat_lost_fraction,
schedule: avail_sch.schedule)

equip_actuator = nil
if [Constants::ObjectTypeMechanicalVentilationHouseFanCFIS,
Expand All @@ -1835,11 +1836,31 @@ def self.setup_mech_vent_vars_actuators(model, spaces, program, sensors)
conditioned_space = spaces[HPXML::LocationConditionedSpace]

# Actuators for mech vent fan
sens_name = "#{Constants::ObjectTypeMechanicalVentilationHouseFan} sensible load"
fan_sens_load_actuator = create_other_equipment_object_and_actuator(model: model, name: sens_name, space: conditioned_space, frac_lat: 0.0, frac_lost: 0.0, end_use: Constants::ObjectTypeMechanicalVentilationHouseFan)

lat_name = "#{Constants::ObjectTypeMechanicalVentilationHouseFan} latent load"
fan_lat_load_actuator = create_other_equipment_object_and_actuator(model: model, name: lat_name, space: conditioned_space, frac_lat: 1.0, frac_lost: 0.0, end_use: Constants::ObjectTypeMechanicalVentilationHouseFan)
sens_equip = Model.add_other_equipment(model,
name: "#{Constants::ObjectTypeMechanicalVentilationHouseFan} sensible load",
end_use: Constants::ObjectTypeMechanicalVentilationHouseFan,
space: conditioned_space,
design_level: nil,
frac_radiant: 0,
frac_latent: 0,
frac_lost: 0,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: nil)
fan_sens_load_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(sens_equip, *EPlus::EMSActuatorOtherEquipmentPower, sens_equip.space.get)
fan_sens_load_actuator.setName("#{sens_equip.name} act")

lat_equip = Model.add_other_equipment(model,
name: "#{Constants::ObjectTypeMechanicalVentilationHouseFan} latent load",
end_use: Constants::ObjectTypeMechanicalVentilationHouseFan,
space: conditioned_space,
design_level: nil,
frac_radiant: 0,
frac_latent: 1,
frac_lost: 0,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: nil)
fan_lat_load_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(lat_equip, *EPlus::EMSActuatorOtherEquipmentPower, lat_equip.space.get)
fan_lat_load_actuator.setName("#{lat_equip.name} act")

program.addLine("Set #{fan_sens_load_actuator.name} = 0.0")
program.addLine("Set #{fan_lat_load_actuator.name} = 0.0")
Expand Down Expand Up @@ -2068,9 +2089,22 @@ def self.calculate_precond_loads(model, spaces, infil_program, vent_fans, hrv_er
end
vent_fans[:mech_preheat].each_with_index do |f_preheat, i|
infil_program.addLine("If (OASupInTemp < HtgStp) && (#{clg_ssn_sensor.name} < 1)")

cnt = model.getOtherEquipments.select { |e| e.endUseSubcategory.start_with? Constants::ObjectTypeMechanicalVentilationPreheating }.size # Ensure unique meter for each preheating system
htg_energy_actuator = create_other_equipment_object_and_actuator(model: model, name: "shared mech vent preheating energy #{i}", space: conditioned_space, frac_lat: 0.0, frac_lost: 1.0, hpxml_fuel_type: f_preheat.preheating_fuel, end_use: "#{Constants::ObjectTypeMechanicalVentilationPreheating}#{cnt + 1}")
other_equip = Model.add_other_equipment(model,
name: "shared mech vent preheating energy #{i}",
end_use: "#{Constants::ObjectTypeMechanicalVentilationPreheating}#{cnt + 1}",
space: conditioned_space,
design_level: nil,
frac_radiant: 0,
frac_latent: 0,
frac_lost: 1,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: f_preheat.preheating_fuel)
htg_energy_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(other_equip, *EPlus::EMSActuatorOtherEquipmentPower, other_equip.space.get)
htg_energy_actuator.setName("#{other_equip.name} act")
htg_energy_actuator.actuatedComponent.get.additionalProperties.setFeature('HPXML_ID', f_preheat.id) # Used by reporting measure

infil_program.addLine(" Set Qpreheat = #{UnitConversions.convert(f_preheat.average_oa_unit_flow_rate, 'cfm', 'm^3/s').round(4)}")
if [HPXML::MechVentTypeERV, HPXML::MechVentTypeHRV].include? f_preheat.fan_type
vent_mech_erv_hrv_tot = [f_preheat]
Expand All @@ -2094,9 +2128,22 @@ def self.calculate_precond_loads(model, spaces, infil_program, vent_fans, hrv_er
end
vent_fans[:mech_precool].each_with_index do |f_precool, i|
infil_program.addLine("If (OASupInTemp > ClgStp) && (#{clg_ssn_sensor.name} > 0)")

cnt = model.getOtherEquipments.select { |e| e.endUseSubcategory.start_with? Constants::ObjectTypeMechanicalVentilationPrecooling }.size # Ensure unique meter for each precooling system
clg_energy_actuator = create_other_equipment_object_and_actuator(model: model, name: "shared mech vent precooling energy #{i}", space: conditioned_space, frac_lat: 0.0, frac_lost: 1.0, hpxml_fuel_type: f_precool.precooling_fuel, end_use: "#{Constants::ObjectTypeMechanicalVentilationPrecooling}#{cnt + 1}")
other_equip = Model.add_other_equipment(model,
name: "shared mech vent precooling energy #{i}",
end_use: "#{Constants::ObjectTypeMechanicalVentilationPrecooling}#{cnt + 1}",
space: conditioned_space,
design_level: nil,
frac_radiant: 0,
frac_latent: 0,
frac_lost: 1,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: f_precool.precooling_fuel)
clg_energy_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(other_equip, *EPlus::EMSActuatorOtherEquipmentPower, other_equip.space.get)
clg_energy_actuator.setName("#{other_equip.name} act")
clg_energy_actuator.actuatedComponent.get.additionalProperties.setFeature('HPXML_ID', f_precool.id) # Used by reporting measure

infil_program.addLine(" Set Qprecool = #{UnitConversions.convert(f_precool.average_oa_unit_flow_rate, 'cfm', 'm^3/s').round(4)}")
if [HPXML::MechVentTypeERV, HPXML::MechVentTypeHRV].include? f_precool.fan_type
vent_mech_erv_hrv_tot = [f_precool]
Expand Down
23 changes: 10 additions & 13 deletions HPXMLtoOpenStudio/resources/battery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,19 +184,16 @@ def self.apply_battery(runner, model, spaces, hpxml_bldg, battery, schedules_fil
discharge_sensor.setName('battery_discharge')
discharge_sensor.setKeyName(elcs.name.to_s)

loss_adj_object_def = OpenStudio::Model::OtherEquipmentDefinition.new(model)
loss_adj_object = OpenStudio::Model::OtherEquipment.new(loss_adj_object_def)
obj_name = Constants::ObjectTypeBatteryLossesAdjustment
loss_adj_object.setName(obj_name)
loss_adj_object.setEndUseSubcategory(obj_name)
loss_adj_object.setFuelType(EPlus.fuel_type(HPXML::FuelTypeElectricity))
loss_adj_object.setSpace(space)
loss_adj_object_def.setName(obj_name)
loss_adj_object_def.setDesignLevel(0.01)
loss_adj_object_def.setFractionRadiant(0)
loss_adj_object_def.setFractionLatent(0)
loss_adj_object_def.setFractionLost(frac_lost)
loss_adj_object.setSchedule(model.alwaysOnDiscreteSchedule)
loss_adj_object = Model.add_other_equipment(model,
name: Constants::ObjectTypeBatteryLossesAdjustment,
end_use: Constants::ObjectTypeBatteryLossesAdjustment,
space: space,
design_level: 0.01,
frac_radiant: 0,
frac_latent: 0,
frac_lost: frac_lost,
schedule: model.alwaysOnDiscreteSchedule,
fuel_type: HPXML::FuelTypeElectricity)
loss_adj_object.additionalProperties.setFeature('ObjectType', Constants::ObjectTypeBatteryLossesAdjustment)

battery_adj_actuator = OpenStudio::Model::EnergyManagementSystemActuator.new(loss_adj_object, *EPlus::EMSActuatorOtherEquipmentPower, loss_adj_object.space.get)
Expand Down
Loading

0 comments on commit 40d31b4

Please sign in to comment.