In my OpenStudio model I wish to set the Ground Temperatures to be user-defined, at the moment my model assumes the Ground Temperature to be 18degC as default, because nothing is assigned. I came across THIS question where it was advised to write a measure for user inputting these values.
So I had a go with a simple measure, creating the Site:GroundTemperature:BuildingSurface as an EnergyPlus measure with some user input. I managed to import the measure into my OS model and was able to user define the Ground Temperature, however when I run my model it fails and does not even bring up an error file (without the measure it does run).
I wonder if I missed something or that my approach is not correct. I followed THIS example where a PV unit is user defined on some shading elements, the only difference to my measure is that it does not look for any existing objects.
Here is my measure.rb:
#start the measure
class AddGroundTemperatures < OpenStudio::Ruleset::WorkspaceUserScript
#define the name that a user will see
def name
return "Add user defined monthly Ground Temperatures"
end
#define the arguments that the user will input
def arguments(workspace)
args = OpenStudio::Ruleset::OSArgumentVector.new
# Fraction of surfaces to contain PV
jan_temp = OpenStudio::Ruleset::OSArgument::makeDoubleArgument("jan_temp",true)
jan_temp.setDisplayName("Ground Temperature in January")
jan_temp.setDefaultValue(18)
args << jan_temp
feb_temp = OpenStudio::Ruleset::OSArgument::makeDoubleArgument("feb_temp",true)
feb_temp.setDisplayName("Ground Temperature in February")
feb_temp.setDefaultValue(18)
args << feb_temp
return args
end #end the arguments method
#define what happens when the measure is run
def run(workspace, runner, user_arguments)
super(workspace, runner, user_arguments)
#use the built-in error checking
if not runner.validateUserArguments(arguments(workspace), user_arguments)
return false
end
#set user defined values to variables
jan_temp = runner.getDoubleArgumentValue("jan_temp",user_arguments)
feb_temp = runner.getDoubleArgumentValue("jan_temp",user_arguments)
if 0 < jan_temp
runner.registerError("Please choose a temperature above 0")
return false
end
# array to hold new IDF objects needed
string_objects = []
# add GroundTemperature Object
string_objects << "
Site:GroundTemperature:BuildingSurface,
#{jan_gtemp}, !- Ground Temperature in January
#{feb_gtemp}, !- Ground Temperature in February
20,20,20,20,20,20,20,20,20,20;
"
# add all of the strings to workspace
# this script won't behave well if added multiple times in the workflow. Need to address name conflicts
string_objects.each do |string_object|
idfObject = OpenStudio::IdfObject::load(string_object)
object = idfObject.get
wsObject = workspace.addObject(object)
end
return true
end #end the run method
end #end the measure
#this allows the measure to be used by the application
AddGroundTemperatures.new.registerWithApplication