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

Measure Methods (is_initialized and to_) what they do

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

Saif's avatar

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

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("#{component.name} 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 = OpenStudio::OptionalDouble.new(target_cop) # not many objects need this step, this is an odd one
      single_speed_dx.setRatedCOP(optionalDoubleCOP)
      runner.registerInfo("The adjusted COP is #{single_speed_dx.ratedCOP}")

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

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

end
edit retag flag offensive close merge delete

Comments

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 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
4

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

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

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

Comments

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 -0600 )edit
1

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 -0600 )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

Careers

Question Tools

2 followers

Stats

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

Seen: 291 times

Last updated: Feb 14 '19