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

Openstudio Python Bindings Set Optionals

asked 2015-07-01 13:49:39 -0600

updated 2015-07-11 13:39:24 -0600

I'm trying to set an optional double in the CoilCoolingDXTwoSpeed class. The SDK documentation mentions that the parameter will be set to autosize if the value is false or a value is specified if provided.

The C++ code for this component is:

  // N1 , \field Rated High Speed Total Cooling Capacity

 OptionalDouble CoilCoolingDXTwoSpeed_Impl::ratedHighSpeedTotalCoolingCapacity() const
  {
    return getDouble(OS_Coil_Cooling_DX_TwoSpeedFields::RatedHighSpeedTotalCoolingCapacity);
  }

  void CoilCoolingDXTwoSpeed_Impl::setRatedHighSpeedTotalCoolingCapacity( OptionalDouble value )
  {
    if(value)
    {
      setDouble(OS_Coil_Cooling_DX_TwoSpeedFields::RatedHighSpeedTotalCoolingCapacity,*value);
    }
    else
    {
      setString(OS_Coil_Cooling_DX_TwoSpeedFields::RatedHighSpeedTotalCoolingCapacity,"Autosize");
    }
  }

I'm struggling with the appropriate syntax in the Python bindings to make this work. The command:

coil.setRatedHighSpeedTotalCoolingCapacity(False)

gives the following error:

TypeError: in method 'CoilCoolingDXTwoSpeed_setRatedHighSpeedTotalCoolingCapacity', argument 2 of type 'boost::optional< double

I actually get the same error if a double value is provided.

coil.setRatedHighSpeedTotalCoolingCapacity(10000.0)

Is there a specific syntax required to provide the value as an optional double?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
6

answered 2015-07-01 13:54:04 -0600

updated 2016-10-14 12:41:54 -0600

I'm not sure of the exact syntax but you may need to do something like:

value = OpenStudio::OptionalDouble.new(10000.0)
coil.setRatedHighSpeedTotalCoolingCapacity(value)

Just as an FYI, that argument signature is against our normal patterns. We might change it to conform (e.g. just take a double as input) at some point.

@kylebenne

edit flag offensive delete link more

Comments

@macumber that is the Ruby version, right? In Python the syntax becomes:

value = openstudio.OptionalDouble(10000.0)

also to set the "autosize" flag you can use

value = openstudio.OptionalDouble()
jmcneill gravatar image jmcneill  ( 2015-07-01 14:10:38 -0600 )edit

Yeah we didn't have all of these conventions worked out in the early days. It should be setRatedHighSpeedTotalCoolingCapacity(double) and resetRatedHighSpeedTotalCoolingCapacity (). Furthermore I am trying to avoid optional fields altogether unless the mere presence of a field alters how E+ behaves.

Kyle Benne gravatar image Kyle Benne  ( 2015-07-01 14:25:05 -0600 )edit

@Kyle Benne will the older components like the CoilCoolingDXTwoSpeed be updated in future versions? I'm still using 1.6.0.

jmcneill gravatar image jmcneill  ( 2015-07-01 14:28:56 -0600 )edit

I'm thinking we should overload the setMethods with the setter that takes the non optional value, leaving but depreciating the old method so not to break our client code and Measures. But I admit this hasn't become a priority yet considering we are still trying to crank in new features.

Kyle Benne gravatar image Kyle Benne  ( 2015-07-01 14:48:50 -0600 )edit

1.8.0 will look just like 1.6.0 for these objects. I expect we may take a double in future versions but I think we would still also accept an optional double so that previously written measures will work. FYI - colingColingDXSingleSpeed.setRatedCOP also takes an optional double, however the low and high speed COP values on the two speed object do not take an optional double.

David Goldwasser gravatar image David Goldwasser  ( 2015-07-01 14:51:10 -0600 )edit

Your Answer

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

Add Answer

 

Question Tools

1 follower

Stats

Asked: 2015-07-01 13:49:39 -0600

Seen: 270 times

Last updated: Oct 14 '16