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

Sample Code for Adding Ground Temps using OpenStudio Measure

asked 2016-11-14 11:29:58 -0600

Michael Pelton's avatar

I would like to add ground temperatures in my model using an OpenStudio measure (as opposed to an EnergyPlus measure). Does anyone have sample code for this?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2016-11-14 12:05:03 -0600

updated 2016-11-14 12:06:23 -0600

This is easy, since you can only have one Site:GroundTemperature:BuildingSurface object.

Say you have your monthly temperatures in an array data, you just need to do:

# create ground temperature object    
groundtemps = OpenStudio::Model::SiteGroundTemperatureBuildingSurface.new(model)
# add monthly temperatures
groundtemps.setAllMonthlyTemperatures(data)

Here are the rest of the class methods, if you need to assign temperatures to specific months or get already assigned temperatures. If you want the measure to take user input of monthly temperatures, you can either push those argument values to an array and use the 'setAll..' method, or set them individually by month.

edit flag offensive delete link more
1

answered 2016-11-14 12:07:10 -0600

Here is the link to API documentation for SiteGroundTemperatureBuildingSurface. There are similar pages for SiteGroundTemperatureShallow and SiteGroundTemperatureDeep.

To get the site ground objets in the model use this code.

ground_temps = model.getSiteGroundTemperatureBuildingSurface

You can then set each month's temperature manually using this method

ground_temps.setJanuaryGroundTemperature(10.0) # takes double value for degrees C

If you are going to set all of the months, you can save an array of temperatures and use setTemperatureByMonth method as shown below.

temps_array = [10.0,11.0,12.0,13.0,13.0,13.0,13.0,13.0,13.0,12.0,11.0,10.0]
temps_array.each_with_index do |temp,index|
  ground_temps.setTemperatureByMonth(index+1,temp)
end

You can just drop the code above in the run section of a new measure. You can ignore the existing measure argument and just have hard coded temperatures, or you can create either a series of double arguments for each month, or a single string argument that would take comma separated values. If you have a comma separated string you can convert it to an array with code below. If you use this when you use an array entry may need to add '.to_f' to make sure it functions as a number, but may not be necessary.

temps_array = argument_string.split(',')
edit flag offensive delete link more

Comments

This is the more complete answer. I suppose your each_with_index loop might be better if there's a chance of having more than 12 data points, but otherwise it's just repeating the helper method functionality.

Eric Ringold's avatar Eric Ringold  ( 2016-11-14 12:19:11 -0600 )edit

@Eric Ringold, I had never looked at setAllMonthlyTemperatures. I had assumed it was just for static temperature for the year, but it looks like it does take each month. The each_with_index approach would return false on any entries in array beyond 12. The only use case where it would be beneficial is if you only wanted to set the temperature for a few months vs. all 12.

David Goldwasser's avatar David Goldwasser  ( 2016-11-14 12:42:05 -0600 )edit

It seems like there are 2 different ways to "set up" the object in the OSM file using a measure...

  1. groundtemps = OpenStudio::Model::SiteGroundTemperatureBuildingSurface.new(model)

  2. groundtemps = model.getSiteGroundTemperatureBuildingSurface

The first way assumes that the OSM file doesn't have this object in it yet, so it creates one. Pretty straightforward (but I'm not sure what happens if the object is already there).

I'm not sure how the second one works, because it looks like it is trying to "get" something that doesn't exist yet?

Is one of these ways better than than the other?

Michael Pelton's avatar Michael Pelton  ( 2016-11-16 12:50:55 -0600 )edit

You are correct, method 1 creates a new object and method 2 gets an existing one. Your question asked about adding ground temps, so that's what I went with. If you want your measure to be really general and cover all possible cases, you would ideally check for an existing object using the get... method, and if no object is found create a new one.

Eric Ringold's avatar Eric Ringold  ( 2016-11-16 12:55:39 -0600 )edit

I don't know what would happen if you have more than one SiteGroundTemperatureBuildingSurface objects in the osm. It doesn't look like openstudio does any checks on the number of these objects on translation to idf, so I'm guessing EnergyPlus would just throw an error when you tried to simulate.

Eric Ringold's avatar Eric Ringold  ( 2016-11-16 13:00:04 -0600 )edit

Your Answer

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

Add Answer

Training Workshops

Question Tools

2 followers

Stats

Asked: 2016-11-14 11:29:58 -0600

Seen: 1,194 times

Last updated: Nov 14 '16