First time here? Check out the Help page!
1 | initial version |
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
.
2 | No.2 Revision |
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 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 ZoneHVACComponent
object into a ZoneHVACPackagedTerminalAirConditioner ZoneHVACPackagedTerminalAirConditioner
object returns an optional ZoneHVACPackagedTerminalAirConditioner 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
.
3 | No.3 Revision |
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 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
.