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

Measure Methods (is_initialized and to_) what they do

asked 2019-02-13 09:32:52 -0500

Saif's avatar

updated 2019-02-14 15:12:44 -0500

I want to change the COP for WSHP, so I am trying to modify the OS measure below that I found in here, but I did not understand what these two methods do (to_ZoneHVACPackagedTerminalAirConditioner and is_initialized). I searched the documentation for ZoneHVACPackagedTerminalAirConditioner, but did not find any information about what these methods do. Can someone shade some light on these methods and where I can find their documentation?

Thank you,

 # loop through zone equipment
model.getZoneHVACComponents.each do |component|

  # see if it is a PTAC
  if component.to_ZoneHVACPackagedTerminalAirConditioner.is_initialized
    runner.registerInfo("#{} is a PTAC")
    ptac = component.to_ZoneHVACPackagedTerminalAirConditioner.get

    # get the cooling coil
    coil_cooling = ptac.coolingCoil

    # see if it is single speed dx
    if coil_cooling.to_CoilCoolingDXSingleSpeed.is_initialized
      single_speed_dx = coil_cooling.to_CoilCoolingDXSingleSpeed.get
      runner.registerInfo("The intial COP is #{single_speed_dx.ratedCOP}")

      # set cop
      target_cop = 1.5 * single_speed_dx.ratedCOP.get # need the get because ratedCOP returns an optional, should check if it exists before doing a get
      optionalDoubleCOP = # not many objects need this step, this is an odd one
      runner.registerInfo("The adjusted COP is #{single_speed_dx.ratedCOP}")

      # could add in elsif to look for other types of cooling coils

    # could add in elsif to look for other kinds of zone equipment

edit retag flag offensive close merge delete


I suggest you rename the title because your question is very general (it sn't specific to setting COP).

shorowit's avatar shorowit  ( 2019-02-13 20:43:19 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-02-13 20:58:42 -0500

updated 2019-02-13 21:00:16 -0500

There are two concepts you should understand.

First, OpenStudio models are object-oriented and use inheritance. For example, the model.getZoneHVACComponents call returns a list of all ZoneHVACComponent objects in the model. In the link, if you click on "Inheritance diagram for openstudio::model::ZoneHVACComponent", you'll see all of the classes that inherit from this object. So, in reality, each of these generic ZoneHVACComponent objects could really be one of the inherited object types. One of those inherited object types is ZoneHVACPackagedTerminalAirConditioner. OpenStudio allows you to try to recast any object to another object by using .to_<ClassName>, so in the code above, the measure is trying to convert the ZoneHVACComponent to the more specific ZoneHVACPackagedTerminalAirConditioner (i.e., it's trying to see if the generic object is of type PTAC and if so, convert it to that object).

Second, OpenStudio sometimes returns optional values. You can read a lot about this here in the section "OpenStudio Measures and the boost::optional Type". Long story short, trying to convert the above ZoneHVACComponent object into a ZoneHVACPackagedTerminalAirConditioner object returns an optional ZoneHVACPackagedTerminalAirConditioner object -- which is to say, if it can't be converted, there's no object to get, and if it can be converted, you can retrieve the converted object. By calling .is_initialized (or .empty?) on the optional object, you can find out if there's actually a converted object inside, and if so, can access it with .get.

edit flag offensive delete link more


thank you @shorowit, is there a documentation for these methods on the OpnenStudio SDK Documentation website? I searched every class in the inheritance diagram but could not find these methods.

Saif's avatar Saif  ( 2019-02-14 08:23:41 -0500 )edit

That "OpenStudio Measures and the boost::optional Type" section in the link above is the only documentation I'm aware of that talks to all of this. As these methods are general convenience methods, not class-specific methods, you won't find them in the SDK documentation.

shorowit's avatar shorowit  ( 2019-02-14 09:30:18 -0500 )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



Asked: 2019-02-13 09:32:52 -0500

Seen: 208 times

Last updated: Feb 14 '19