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

boost::optional argument for WSHP in ruby

asked 2016-10-14 11:32:50 -0500

gokul gravatar image

updated 2016-10-14 11:55:18 -0500

Hi, I am trying to set the value of outdoor air flow rate in my ZoneHVAC:WatertoAirHeatPump to zero, through a measure. For this object, the setOutdoorAirFlowRateDuringCoolingOperation() accepts a boost::optional argument, as per the OS Class Runner reference. I am looking for ways to initialise a boost::optional argument in ruby, and I think I maybe getting confused between an OptionalDouble and a boost::optional addresses this question, and one of the answers says I need to use the following syntax:

                             value =

This doesn't seem to be working though, and Ruby says this method is not recognised. Is there something I should add before/after these lines to have 'value' be initialised as a boost::optional type? I tried initialising the object as an Optional double with a default value, but this still gives a run time error. My code block is as such: In the arguments section: def arguments(model) args = zero = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('zero',false) zero.setDefaultValue(0.00) args << zero

In the runner: do |zone_equip| wshp = zone_equip.to_ZoneHVACWaterToAirHeatPump if wshp.is_initialized wshp = wshp.get if zero.is_initialized wshp.setOutdoorAirFlowRateDuringCoolingOperation(zero.get) wshp.setOutdoorAirFlowRateDuringHeatingOperation(zero.get) wshp.setOutdoorAirFlowRateWhenNoCoolingorHeatingisNeeded(zero.get) #wshp.setSupplyAirFlowRateWhenNoCoolingorHeatingisNeeded(0) end end end

Am I missing something here?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-10-14 12:40:37 -0500

updated 2016-10-14 12:43:44 -0500

Try this. Notice the double colon vs. period.

value =
edit flag offensive delete link more


Thank you for the answer. I did try this, and it throws the same runtime error:

"C:/Users/gparanjothi/AppData/Local/Temp/OpenStudio.nH5236/ApplyMeasureNow/UserScript/user_script.rb:130:in `setOutdoorAirFlowRateDuringCoolingOperation': Expected argument 1 of type boost::optional< double >, but got Float 0.0 (TypeError)

in SWIG method 'setOutdoorAirFlowRateDuringCoolingOperation'

As a related question, Is SWIG a source to source compiler which just doesn't recognise Ruby's boost::optional initialization?

gokul gravatar image gokul  ( 2016-10-14 14:05:51 -0500 )edit

I can't answer details of how boost works, but very odd that you get an error that says you are passing in a float.

If you add this code

puts "class is #{value}"

You should get something like this

class is OpenStudio::OptionalDouble

If instead you had a value.get then it would return a 'Float' for class instead of 'OpenStudio::OptionalDouble'

David Goldwasser gravatar image David Goldwasser  ( 2016-10-14 14:35:18 -0500 )edit

@goldwasser, sorry, I was able to get this to work with the above line you had mentioned, through this method of initialisation:


Somehow, trying to initialize the optional double outside the function and passing that value to the function was not working! This one seems to work fine now though!

gokul gravatar image gokul  ( 2016-10-14 15:17:53 -0500 )edit

Your Answer


Add Answer


Question Tools

1 follower


Asked: 2016-10-14 11:32:50 -0500

Seen: 226 times

Last updated: Oct 14 '16