2

boost::optional argument for WSHP in ruby

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

https://unmethours.com/question/8806/... addresses this question, and one of the answers says I need to use the following syntax:

                             value = OpenStudio.OptionalDouble.new(10000.0)
                             coil.setRatedHighSpeedTotalCoolingCapacity(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 = OpenStudio::Ruleset::OSArgumentVector.new zero = OpenStudio::Ruleset::OSArgument::makeDoubleArgument('zero',false) zero.setDefaultValue(0.00) args << zero

In the runner: zone.equipment.each 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?

gokul's avatar
684
gokul
asked 2016-10-14 11:32:50 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2016-10-14 11:55:18 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

1

Try this. Notice the double colon vs. period.

value = OpenStudio::OptionalDouble.new(10000.0)
David Goldwasser's avatar
20.4k
David Goldwasser
answered 2016-10-14 12:40:37 -0500, updated 2016-10-14 12:43:44 -0500
edit flag offensive 0 remove flag delete link

Comments

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's avatar 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's avatar 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:

"wshp.setOutdoorAirFlowRateDuringCoolingOperation(OpenStudio::OptionalDouble.new(0.0))"

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's avatar gokul (2016-10-14 15:17:53 -0500) edit
add a comment see more comments