Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
7

OpenStudio Measure for user-defined Ground Temperatures

asked 9 years ago

Chris's avatar

updated 7 years ago

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

    # Define input variables
    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
Preview: (hide)

Comments

Note that you don't need to use an EnergyPlus measure. The Site:GroundTemperature:BuildingSurface object is wrapped in OpenStudio: https://openstudio-sdk-documentation....

shorowit's avatar shorowit  ( 7 years ago )

2 Answers

Sort by » oldest newest most voted
5

answered 9 years ago

if 0 < jan_temp <- this check is causing the measure to return false.

Also, the variables jan_gtemp and feb_gtemp that you're inserting into the string are not defined, and should be jan_temp and feb_temp to match the argument variables.

Other than that, there's no real need to insert the string into an array, since you will only ever have one ground temperature object. I don't think the way you have it would cause a problem with the measure, but FYI.

Preview: (hide)
link

Comments

Thank you, I was too focussed on reproducing the measure that I didn't look at my own code properly and made some mistakes. It now shows up in my new idf file.

Chris's avatar Chris  ( 9 years ago )

I noticed that in this line, feb_temp = runner.getDoubleArgumentValue("jan_temp",user_arguments), "jan_temp" in the call of .getDoubleArgumentValue should be "feb_temp."

sashadf1's avatar sashadf1  ( 4 years ago )

Agreed with above check causing measure to return false.

sashadf1's avatar sashadf1  ( 4 years ago )
1

answered 7 years ago

Other possibilty is create an idf file with ground temperatures and use the Inject idf measure.

Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 9 years ago

Seen: 1,713 times

Last updated: Nov 03 '17