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 2015-09-16 02:38:16 -0600

Chris's avatar

updated 2017-08-05 13:08:57 -0600

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
edit retag flag offensive close merge delete

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  ( 2017-11-06 13:00:39 -0600 )edit

2 Answers

Sort by ยป oldest newest most voted
5

answered 2015-09-16 10:05:36 -0600

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.

edit flag offensive delete link more

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  ( 2015-09-17 03:04:04 -0600 )edit

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  ( 2021-04-09 07:52:48 -0600 )edit

Agreed with above check causing measure to return false.

sashadf1's avatar sashadf1  ( 2021-04-09 07:53:35 -0600 )edit
1

answered 2017-11-03 02:30:16 -0600

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

edit flag offensive delete link more

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: 2015-09-16 02:37:07 -0600

Seen: 1,655 times

Last updated: Nov 03 '17