6

Openstudio Python Bindings Set Optionals

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?

jmcneill's avatar
1.7k
jmcneill
asked 2015-07-01 13:49:39 -0500
__AmirRoth__'s avatar
4.4k
__AmirRoth__
updated 2015-07-11 13:39:24 -0500
edit flag offensive 0 remove flag close merge delete

Comments

add a comment see more comments

1 Answer

6

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

macumber's avatar
12k
macumber
answered 2015-07-01 13:54:04 -0500
David Goldwasser's avatar
20.4k
David Goldwasser
updated 2016-10-14 12:41:54 -0500
edit flag offensive 0 remove flag delete link

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's avatar jmcneill (2015-07-01 14:10:38 -0500) 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's avatar Kyle Benne (2015-07-01 14:25:05 -0500) edit

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

jmcneill's avatar jmcneill (2015-07-01 14:28:56 -0500) 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's avatar Kyle Benne (2015-07-01 14:48:50 -0500) 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's avatar David Goldwasser (2015-07-01 14:51:10 -0500) edit
add a comment see more comments