Skip to content

Commit

Permalink
Lots more cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
shorowit committed Apr 11, 2019
1 parent 1ed766a commit e69b541
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 229 deletions.
100 changes: 71 additions & 29 deletions measure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,10 @@ def self.create(hpxml_doc, runner, model, weather, map_tsv_dir)

# HVAC

control_zone = get_space_of_type(spaces, Constants.SpaceTypeLiving).thermalZone.get
slave_zones = get_spaces_of_type(spaces, [Constants.SpaceTypeFinishedBasement]).map { |z| z.thermalZone.get }.compact
@control_slave_zones_hash = { control_zone => slave_zones }

success = add_cooling_system(runner, model, building, loop_hvacs, zone_hvacs, use_only_ideal_air)
return false if not success

Expand All @@ -288,7 +292,7 @@ def self.create(hpxml_doc, runner, model, weather, map_tsv_dir)
success = add_residual_hvac(runner, model, building, use_only_ideal_air)
return false if not success

success = add_setpoints(runner, model, building, weather)
success = add_setpoints(runner, model, building, weather, spaces)
return false if not success

success = add_ceiling_fans(runner, model, building)
Expand All @@ -314,7 +318,7 @@ def self.create(hpxml_doc, runner, model, weather, map_tsv_dir)
success = add_mels(runner, model, building, spaces)
return false if not success

success = add_lighting(runner, model, building, weather)
success = add_lighting(runner, model, building, weather, spaces)
return false if not success

# Other
Expand Down Expand Up @@ -1778,8 +1782,6 @@ def self.apply_adiabatic_construction(runner, model, surfaces, type)
end

def self.add_hot_water_and_appliances(runner, model, building, weather, spaces, loop_dhws)
living_space = create_or_get_space(model, spaces, Constants.SpaceTypeLiving)

# Clothes Washer
clothes_washer_values = HPXML.get_clothes_washer_values(clothes_washer: building.elements["BuildingDetails/Appliances/ClothesWasher"])
if not clothes_washer_values.nil?
Expand Down Expand Up @@ -1988,8 +1990,10 @@ def self.add_hot_water_and_appliances(runner, model, building, weather, spaces,
end
end

wh_setpoint = Waterheater.get_default_hot_water_temperature(@eri_version)
living_space = get_space_of_type(spaces, Constants.SpaceTypeLiving)
success = HotWaterAndAppliances.apply(model, runner, weather, living_space,
@cfa, @nbeds, @ncfl, @has_uncond_bsmnt,
@cfa, @nbeds, @ncfl, @has_uncond_bsmnt, wh_setpoint,
cw_mef, cw_ler, cw_elec_rate, cw_gas_rate,
cw_agc, cw_cap, cw_space, cd_fuel, cd_ef, cd_control,
cd_space, dw_ef, dw_cap, fridge_annual_kwh, fridge_space,
Expand Down Expand Up @@ -2043,7 +2047,7 @@ def self.add_cooling_system(runner, model, building, loop_hvacs, zone_hvacs, use
success = HVAC.apply_central_ac_1speed(model, runner, seer, eers, shrs,
fan_power_installed, crankcase_kw, crankcase_temp,
eer_capacity_derates, cool_capacity_btuh,
dse_cool, load_frac)
dse_cool, load_frac, @control_slave_zones_hash)
return false if not success

elsif num_speeds == "2-Speed"
Expand All @@ -2058,7 +2062,7 @@ def self.add_cooling_system(runner, model, building, loop_hvacs, zone_hvacs, use
capacity_ratios, fan_speed_ratios,
fan_power_installed, crankcase_kw, crankcase_temp,
eer_capacity_derates, cool_capacity_btuh,
dse_cool, load_frac)
dse_cool, load_frac, @control_slave_zones_hash)
return false if not success

elsif num_speeds == "Variable-Speed"
Expand All @@ -2073,7 +2077,7 @@ def self.add_cooling_system(runner, model, building, loop_hvacs, zone_hvacs, use
capacity_ratios, fan_speed_ratios,
fan_power_installed, crankcase_kw, crankcase_temp,
eer_capacity_derates, cool_capacity_btuh,
dse_cool, load_frac)
dse_cool, load_frac, @control_slave_zones_hash)
return false if not success

else
Expand All @@ -2088,8 +2092,8 @@ def self.add_cooling_system(runner, model, building, loop_hvacs, zone_hvacs, use
shr = 0.65
airflow_rate = 350.0

success = HVAC.apply_room_ac(model, runner, eer, shr,
airflow_rate, cool_capacity_btuh, load_frac)
success = HVAC.apply_room_ac(model, runner, eer, shr, airflow_rate, cool_capacity_btuh,
load_frac, @control_slave_zones_hash)
return false if not success

end
Expand Down Expand Up @@ -2129,7 +2133,8 @@ def self.add_heating_system(runner, model, building, loop_hvacs, zone_hvacs, use
attached_to_multispeed_ac = get_attached_to_multispeed_ac(heating_system_values, building)
success = HVAC.apply_furnace(model, runner, fuel, afue,
heat_capacity_btuh, fan_power, dse_heat,
load_frac, attached_to_multispeed_ac)
load_frac, attached_to_multispeed_ac,
@control_slave_zones_hash)
return false if not success

elsif htg_type == "WallFurnace"
Expand All @@ -2140,7 +2145,8 @@ def self.add_heating_system(runner, model, building, loop_hvacs, zone_hvacs, use
# TODO: Allow DSE
success = HVAC.apply_unit_heater(model, runner, fuel,
afue, heat_capacity_btuh, fan_power,
airflow_rate, load_frac)
airflow_rate, load_frac,
@control_slave_zones_hash)
return false if not success

elsif htg_type == "Boiler"
Expand All @@ -2155,15 +2161,17 @@ def self.add_heating_system(runner, model, building, loop_hvacs, zone_hvacs, use
design_temp = 180.0
success = HVAC.apply_boiler(model, runner, fuel, system_type, afue,
oat_reset_enabled, oat_high, oat_low, oat_hwst_high, oat_hwst_low,
heat_capacity_btuh, design_temp, dse_heat, load_frac)
heat_capacity_btuh, design_temp, dse_heat, load_frac,
@control_slave_zones_hash)
return false if not success

elsif htg_type == "ElectricResistance"

efficiency = heating_system_values[:heating_efficiency_percent]
# TODO: Allow DSE
success = HVAC.apply_electric_baseboard(model, runner, efficiency,
heat_capacity_btuh, load_frac)
heat_capacity_btuh, load_frac,
@control_slave_zones_hash)
return false if not success

elsif htg_type == "Stove"
Expand All @@ -2174,7 +2182,8 @@ def self.add_heating_system(runner, model, building, loop_hvacs, zone_hvacs, use
# TODO: Allow DSE
success = HVAC.apply_unit_heater(model, runner, fuel,
efficiency, heat_capacity_btuh, fan_power,
airflow_rate, load_frac)
airflow_rate, load_frac,
@control_slave_zones_hash)
return false if not success

end
Expand Down Expand Up @@ -2246,7 +2255,8 @@ def self.add_heat_pump(runner, model, building, weather, loop_hvacs, zone_hvacs,
eer_capacity_derates, cop_capacity_derates,
cool_capacity_btuh, supplemental_efficiency,
backup_heat_capacity_btuh, dse_heat,
load_frac_heat, load_frac_cool)
load_frac_heat, load_frac_cool,
@control_slave_zones_hash)
return false if not success

elsif num_speeds == "2-Speed"
Expand All @@ -2268,7 +2278,8 @@ def self.add_heat_pump(runner, model, building, weather, loop_hvacs, zone_hvacs,
eer_capacity_derates, cop_capacity_derates,
cool_capacity_btuh, supplemental_efficiency,
backup_heat_capacity_btuh, dse_heat,
load_frac_heat, load_frac_cool)
load_frac_heat, load_frac_cool,
@control_slave_zones_hash)
return false if not success

elsif num_speeds == "Variable-Speed"
Expand All @@ -2290,7 +2301,8 @@ def self.add_heat_pump(runner, model, building, weather, loop_hvacs, zone_hvacs,
eer_capacity_derates, cop_capacity_derates,
cool_capacity_btuh, supplemental_efficiency,
backup_heat_capacity_btuh, dse_heat,
load_frac_heat, load_frac_cool)
load_frac_heat, load_frac_cool,
@control_slave_zones_hash)
return false if not success

else
Expand Down Expand Up @@ -2329,7 +2341,8 @@ def self.add_heat_pump(runner, model, building, weather, loop_hvacs, zone_hvacs,
cap_retention_temp, pan_heater_power, fan_power,
is_ducted, cool_capacity_btuh,
supplemental_efficiency, backup_heat_capacity_btuh,
dse_heat, load_frac_heat, load_frac_cool)
dse_heat, load_frac_heat, load_frac_cool,
@control_slave_zones_hash)
return false if not success

elsif hp_type == "ground-to-air"
Expand Down Expand Up @@ -2366,7 +2379,8 @@ def self.add_heat_pump(runner, model, building, weather, loop_hvacs, zone_hvacs,
u_tube_leg_spacing, u_tube_spacing_type,
fan_power, heat_pump_capacity, supplemental_efficiency,
supplemental_capacity, dse_heat,
load_frac_heat, load_frac_cool)
load_frac_heat, load_frac_cool,
@control_slave_zones_hash)
return false if not success

end
Expand Down Expand Up @@ -2409,10 +2423,12 @@ def self.add_residual_hvac(runner, model, building, use_only_ideal_air)
return true
end

def self.add_setpoints(runner, model, building, weather)
def self.add_setpoints(runner, model, building, weather, spaces)
hvac_control_values = HPXML.get_hvac_control_values(hvac_control: building.elements["BuildingDetails/Systems/HVAC/HVACControl"])
return true if hvac_control_values.nil?

conditioned_zones = get_spaces_of_type(spaces, [Constants.SpaceTypeLiving, Constants.SpaceTypeFinishedBasement]).map { |z| z.thermalZone.get }.compact

control_type = hvac_control_values[:control_type]
heating_temp = hvac_control_values[:setpoint_temp_heating_season]
if not heating_temp.nil? # Use provided value
Expand All @@ -2435,7 +2451,8 @@ def self.add_setpoints(runner, model, building, weather)
htg_season_start_month = 1
htg_season_end_month = 12
success = HVAC.apply_heating_setpoints(model, runner, weather, htg_weekday_setpoints, htg_weekend_setpoints,
htg_use_auto_season, htg_season_start_month, htg_season_end_month)
htg_use_auto_season, htg_season_start_month, htg_season_end_month,
conditioned_zones)
return false if not success

cooling_temp = hvac_control_values[:setpoint_temp_cooling_season]
Expand Down Expand Up @@ -2469,7 +2486,8 @@ def self.add_setpoints(runner, model, building, weather)
clg_season_start_month = 1
clg_season_end_month = 12
success = HVAC.apply_cooling_setpoints(model, runner, weather, clg_weekday_setpoints, clg_weekend_setpoints,
clg_use_auto_season, clg_season_start_month, clg_season_end_month)
clg_use_auto_season, clg_season_start_month, clg_season_end_month,
conditioned_zones)
return false if not success

return true
Expand All @@ -2495,7 +2513,9 @@ def self.add_ceiling_fans(runner, model, building)
end
annual_kwh = UnitConversions.convert(quantity * medium_cfm / cfm_per_w * hrs_per_day * 365.0, "Wh", "kWh")

success = HVAC.apply_ceiling_fans(model, runner, annual_kwh, weekday_sch, weekend_sch, @cfa)
conditioned_spaces = get_spaces_of_type(spaces, [Constants.SpaceTypeLiving, Constants.SpaceTypeFinishedBasement])
success = HVAC.apply_ceiling_fans(model, runner, annual_kwh, weekday_sch, weekend_sch,
@cfa, conditioned_spaces)
return false if not success

return true
Expand Down Expand Up @@ -2595,8 +2615,6 @@ def self.update_loop_dhws(loop_dhws, model, sys, orig_plant_loops)
end

def self.add_mels(runner, model, building, spaces)
living_space = create_or_get_space(model, spaces, Constants.SpaceTypeLiving)

# Misc
plug_load_values = HPXML.get_plug_load_values(plug_load: building.elements["BuildingDetails/MiscLoads/PlugLoad[PlugLoadType='other']"])
if not plug_load_values.nil?
Expand Down Expand Up @@ -2645,14 +2663,16 @@ def self.add_mels(runner, model, building, spaces)
tv_annual_kwh = 0
end

conditioned_spaces = get_spaces_of_type(spaces, [Constants.SpaceTypeLiving, Constants.SpaceTypeFinishedBasement])
success, sch = MiscLoads.apply_plug(model, runner, misc_annual_kwh, misc_sens_frac, misc_lat_frac,
misc_weekday_sch, misc_weekend_sch, misc_monthly_sch, tv_annual_kwh, @cfa)
misc_weekday_sch, misc_weekend_sch, misc_monthly_sch, tv_annual_kwh,
@cfa, conditioned_spaces)
return false if not success

return true
end

def self.add_lighting(runner, model, building, weather)
def self.add_lighting(runner, model, building, weather, spaces)
lighting = building.elements["BuildingDetails/Lighting"]
return true if lighting.nil?

Expand All @@ -2677,7 +2697,10 @@ def self.add_lighting(runner, model, building, weather)
lighting_values[:fraction_tier_ii_garage])

gfa = 0 # garage floor area FIXME
success, sch = Lighting.apply(model, runner, weather, int_kwh, grg_kwh, ext_kwh, @cfa, gfa)
conditioned_spaces = get_spaces_of_type(spaces, [Constants.SpaceTypeLiving, Constants.SpaceTypeFinishedBasement])
garage_spaces = get_spaces_of_type(spaces, [Constants.SpaceTypeGarage])
success, sch = Lighting.apply(model, runner, weather, int_kwh, grg_kwh, ext_kwh, @cfa, gfa,
conditioned_spaces, garage_spaces)
return false if not success

return true
Expand Down Expand Up @@ -3762,6 +3785,25 @@ def self.get_space_from_location(location, object_name, model, spaces)

return space
end

def self.get_spaces_of_type(spaces, space_types_list)
spaces_of_type = []
space_types_list.each do |space_type|
spaces_of_type << spaces[space_type] unless spaces[space_type].nil?
end
return spaces_of_type
end

def self.get_space_of_type(spaces, space_type)
spaces_of_type = self.get_spaces_of_type(spaces, [space_type])
if spaces_of_type.size > 1
fail "Unexpected number of spaces."
elsif spaces_of_type.size == 1
return spaces_of_type[0]
end

return nil
end
end

class WoodStudConstructionSet
Expand Down
34 changes: 0 additions & 34 deletions resources/geometry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@
require_relative "util"

class Geometry
def self.get_abs_azimuth(azimuth_type, relative_azimuth, building_orientation, offset = 180.0)
azimuth = nil
if azimuth_type == Constants.CoordRelative
azimuth = relative_azimuth + building_orientation + offset
elsif azimuth_type == Constants.CoordAbsolute
azimuth = relative_azimuth + offset
end

# Ensure azimuth is >=0 and <=360
while azimuth < 0.0
azimuth += 360.0
end

while azimuth >= 360.0
azimuth -= 360.0
end

return azimuth
end

def self.get_abs_tilt(tilt_type, relative_tilt, roof_tilt, latitude)
if tilt_type == Constants.TiltPitch
return relative_tilt + roof_tilt
elsif tilt_type == Constants.TiltLatitude
return relative_tilt + latitude
elsif tilt_type == Constants.CoordAbsolute
return relative_tilt
end
end

def self.initialize_transformation_matrix(m)
m[0, 0] = 1
m[1, 1] = 1
Expand Down Expand Up @@ -80,10 +50,6 @@ def self.get_above_grade_finished_volume(model, runner = nil)
return volume
end

def self.space_height(space)
return Geometry.get_height_of_spaces([space])
end

# Calculates space heights as the max z coordinate minus the min z coordinate
def self.get_height_of_spaces(spaces)
minzs = []
Expand Down
16 changes: 2 additions & 14 deletions resources/hotwater_appliances.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class HotWaterAndAppliances
def self.apply(model, runner, weather, living_space,
cfa, nbeds, ncfl, has_uncond_bsmnt,
cfa, nbeds, ncfl, has_uncond_bsmnt, wh_setpoint,
cw_mef, cw_ler, cw_elec_rate, cw_gas_rate,
cw_agc, cw_cap, cw_space, cd_fuel, cd_ef, cd_control,
cd_space, dw_ef, dw_cap, fridge_annual_kwh, fridge_space,
Expand Down Expand Up @@ -37,7 +37,6 @@ def self.apply(model, runner, weather, living_space,

water_use_connections = {}
setpoint_scheds = {}
setpoint_temps = {}

dhw_loop_fracs.each do |dhw_loop, dhw_load_frac|
water_use_connections[dhw_loop] = OpenStudio::Model::WaterUseConnections.new(model)
Expand All @@ -48,18 +47,7 @@ def self.apply(model, runner, weather, living_space,
if setpoint_scheds[dhw_loop].nil?
return false
end

setpoint_temps[dhw_loop] = Waterheater.get_water_heater_setpoint(model, dhw_loop, runner)
if setpoint_temps[dhw_loop].nil?
return false
end
end

if setpoint_temps.values.max - setpoint_temps.values.min > 0.1
runner.registerError("Cannot handle different water heater setpoints.")
return false
end
setpoint_temp = setpoint_temps.values.reduce(:+) / setpoint_temps.size.to_f # average

# Create hot water draw profile schedule
fractions_hw = []
Expand All @@ -78,7 +66,7 @@ def self.apply(model, runner, weather, living_space,
# Create mixed water draw profile schedule
dwhr_eff_adj, dwhr_iFrac, dwhr_plc, dwhr_locF, dwhr_fixF = get_dwhr_factors(nbeds, dist_type, std_pipe_length, recirc_branch_length, dwhr_is_equal_flow, dwhr_facilities_connected, has_low_flow_fixtures)
daily_wh_inlet_temperatures = calc_water_heater_daily_inlet_temperatures(weather, dwhr_present, dwhr_iFrac, dwhr_efficiency, dwhr_eff_adj, dwhr_plc, dwhr_locF, dwhr_fixF)
daily_mw_fractions = calc_mixed_water_daily_fractions(daily_wh_inlet_temperatures, setpoint_temp)
daily_mw_fractions = calc_mixed_water_daily_fractions(daily_wh_inlet_temperatures, wh_setpoint)
fractions_mw = []
for day in 0..364
for hr in 0..23
Expand Down
Loading

0 comments on commit e69b541

Please sign in to comment.