Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix #4240 (and more): add missing \ip-units gal/min via a script #4243

Merged
merged 3 commits into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions developer/ruby/FindAndAddMissingIPUnits.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
require 'openstudio'
require 'optparse'

# define the input parameters
options = Hash.new

optparse = OptionParser.new do |opts|

opts.on("-f", "--[no-]fix", "Add the missing ipUnits to the OpenSutdio.idd (note: LOTS of whitespace changes...)") do |fix|
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would require running the "iddWrapper.save" once to do the whitespace changes once. I don't think it's really worth it here...

options[:fix] = fix
end

opts.on( '-i', '--idd-path IDD_PATH',
String,
"Path to the OpenStudio.idd") do |iddPath|
options[:iddPath] = iddPath
end

end

# parse the input parameters
optparse.parse!

puts options


iddWrapper = nil
if options[:iddPath]
IDD_PATH = options[:iddPath]
else
IDD_PATH = File.absolute_path(File.join(File.dirname(__FILE__), "../../resources/model/OpenStudio.idd"))
#iddWrapper = OpenStudio::IddFileAndFactoryWrapper.new("OpenStudio".to_IddFileType)
end

if !File.exist?(IDD_PATH)
puts "The OpenStudio.idd at '#{IDD_PATH}' does not exist. Pass it via `-i PATH`"
puts ""
puts optparse.help
exit 1
end

oIddFile = OpenStudio::IddFile::load(OpenStudio::toPath(IDD_PATH))
raise "Couldn't load #{IDD_PATH}" if oIddFile.empty?
iddWrapper = oIddFile.get

def apply_water_flow_rate(iddWrapper)

puts "Looking for missing gal/min in Water Flow Rate fields"
include_words = ['water', 'flow', 'rate']
exclude_words = ['ratio', 'fraction', 'curve', 'length', 'mass']


n_missing = 0

iddWrapper.objects.each do |iddObject|
num_fields = iddObject.numFields
for i in 0..num_fields-1
f = iddObject.getField(i).get
f_name = f.name
props = f.properties
siUnits = props.units
ipUnits = props.ipUnits
if include_words.all? { |w| f_name.downcase.include?(w) } and exclude_words.none? { |w| f_name.downcase.include?(w) }
if siUnits.empty?
puts "#{iddObject.name} is missing units in field '#{f_name}'"
elsif siUnits.get != "m3/s"
puts "#{iddObject.name} has wrong units=#{siUnits.get} in field '#{f_name}'"
elsif ipUnits.empty?
puts "#{iddObject.name} is missing ipUnits in field '#{f_name}'"
props.ipUnits = OpenStudio::OptionalString.new('gal/min')
n_missing += 1
elsif ipUnits.get != "gal/min"
puts "#{iddObject.name} has wrong ipUnits=#{ipUnits.get} in field '#{f_name}'"
props.ipUnits = OpenStudio::OptionalString.new('gal/min')
n_missing += 1
end
end
end
end

return n_missing
end

n_missing = 0
n_missing += apply_water_flow_rate(iddWrapper)

if options[:fix]
puts "Fixing in place at #{IDD_PATH}"
# LOTS of whitespace changes
iddWrapper.save(OpenStudio::toPath(IDD_PATH), true)
else
puts "Not fixing in place"
end

if n_missing > 0
exit 1
else
exit 0
end
12 changes: 12 additions & 0 deletions resources/model/OpenStudio.idd
Original file line number Diff line number Diff line change
Expand Up @@ -8176,12 +8176,14 @@ OS:Refrigeration:Condenser:WaterCooled,
N5, \field Water Design Flow Rate
\type real
\units m3/s
\ip-units gal/min
\minimum> 0.0
\note Note required units must be converted from L/s as specified in ARI 450-2007
\note Applicable only when loop flow type is Constant Flow.
N6, \field Water Maximum Flow Rate
\type real
\units m3/s
\ip-units gal/min
\minimum> 0.0
N7, \field Water Maximum Water Outlet Temperature
\type real
Expand Down Expand Up @@ -10406,6 +10408,7 @@ OS:AirLoopHVAC:UnitaryHeatPump:AirToAir:MultiSpeed,
\note If non-zero, then the heat recovery inlet and outlet node names must be entered.
\note Used for heat recovery to an EnergyPlus plant loop.
\units m3/s
\ip-units gal/min
\minimum 0.0
\required-field
N7, \field Maximum Temperature for Heat Recovery
Expand Down Expand Up @@ -11183,6 +11186,7 @@ OS:AirLoopHVAC:UnitarySystem,
N25, \field Design Heat Recovery Water Flow Rate
\type real
\units m3/s
\ip-units gal/min
\minimum 0.0
\default 0.0
\note If non-zero, then the heat recovery inlet and outlet node names must be entered.
Expand Down Expand Up @@ -11810,6 +11814,7 @@ OS:AirTerminal:SingleDuct:ConstantVolume:CooledBeam,
N2, \field Maximum Total Chilled Water Volumetric Flow Rate
\type real
\units m3/s
\ip-units gal/min
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the actual specific fix for #4240

\minimum 0.0
\autosizable
\default autosize
Expand Down Expand Up @@ -17686,6 +17691,7 @@ OS:Coil:WaterHeating:Desuperheater,
\required-field
\type real
\units m3/s
\ip-units gal/min
\minimum> 0
\note The operating water flow rate.
N7, \field Water Pump Power
Expand Down Expand Up @@ -18023,6 +18029,7 @@ OS:Coil:Heating:Water:Baseboard:Radiant,
\autosizable
\type real
\units m3/s
\ip-units gal/min
N7; \field Convergence Tolerance
\required-field
\type real
Expand Down Expand Up @@ -18593,6 +18600,7 @@ OS:Coil:Heating:WaterToAirHeatPump:VariableSpeedEquationFit,
\required-field
N4, \field Rated Water Flow Rate At Selected Nominal Speed Level
\units m3/s
\ip-units gal/min
\type real
\autosizable
\required-field
Expand Down Expand Up @@ -18633,6 +18641,7 @@ OS:Coil:Heating:WaterToAirHeatPump:VariableSpeedEquationFit:SpeedData,
\required-field
N4, \field Reference Unit Rated Water Flow Rate
\units m3/s
\ip-units gal/min
\type real
\minimum 0
\required-field
Expand Down Expand Up @@ -18720,6 +18729,7 @@ OS:Coil:Cooling:WaterToAirHeatPump:VariableSpeedEquationFit,
\required-field
N4, \field Rated Water Flow Rate At Selected Nominal Speed Level
\units m3/s
\ip-units gal/min
\type real
\autosizable
\required-field
Expand Down Expand Up @@ -18780,6 +18790,7 @@ OS:Coil:Cooling:WaterToAirHeatPump:VariableSpeedEquationFit:SpeedData,
\required-field
N5, \field Reference Unit Rated Water Flow Rate
\units m3/s
\ip-units gal/min
\type real
\minimum 0
\required-field
Expand Down Expand Up @@ -27701,6 +27712,7 @@ OS:Coil:WaterHeating:AirToWaterHeatPump,
N8 , \field Rated Condenser Water Flow Rate
\type real
\units m3/s
\ip-units gal/min
\minimum> 0
\autosizable
\required-field
Expand Down