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

Revision history [back]

I believe the problem is that your variable UFactorTimeArea beings with a capital letter and ruby treats that as a constant. Ruby does not allow you to make assignments to constants inside of methods, only within the class declaration. If you make the variable begin with a lower case letter I think you will be ok.

The very next line is troubling though. CoilHeatingWater::isUFactorTimesAreaValueAutoSized returns a bool so UFactortimeArea is going to be a bool, however you are trying to call the method isUFactorTimesAreaValueAutoSized on it. This method is going to be undefined for bool. Instead just say if( uFactortimeArea ) and then call heating_coil.setUFactorTimesAreaValue(foo).

Finally there is a simpler method of grabbing the hot water coils off the loop. Just do this...

air_loop.supply_components(OpenStudio::Model::CoilHeatingWater::iddObjectType) Thats going to give you generic ModelObjects which you will still need to cast into heating coils, but it will save you a check to is_initialized. The full thing will probably look something like this....

air_loops.each do |air_loop|
  supply_components = air_loop.supplyComponents(OpenStudio::Model::CoilHeatingWater::iddObjectType)

  supply_components.each do |supply_component|
    heating_coil = supply_component.to_CoilHeatingWater.get # <-- this is safe because of how we called supplComps...
    uFactorTimeArea= heating_coil.isUFactorTimesAreaValueAutoSized

    if (uFactorTimeArea)
      heating_coil.setUFactorTimesAreaValue(user_input) # Or just leave autosized
    else
       # Or just leave the hardsized value that was already there
       heating_coil.setUFactorTimesAreaValue(some_other_user_input)
    end
  end

end

I believe the problem is that your variable UFactorTimeArea beings with a capital letter and ruby treats that as a constant. Ruby does not allow you to make assignments to constants inside of methods, only within the class declaration. If you make the variable begin with a lower case letter I think you will be ok.

The very next line is troubling though. CoilHeatingWater::isUFactorTimesAreaValueAutoSized returns a bool so UFactortimeArea is going to be a bool, however you are trying to call the method isUFactorTimesAreaValueAutoSized on it. This method is going to be undefined for bool. Instead just say if( uFactortimeArea ) and then call heating_coil.setUFactorTimesAreaValue(foo).

Finally there is a simpler method of grabbing the hot water coils off the loop. Just do this...

air_loop.supply_components(OpenStudio::Model::CoilHeatingWater::iddObjectType) Thats going to give you only the hot water coils as generic ModelObjects which you ModelObjects. You will still need to cast them into heating coils, but it will save you a check to is_initialized. The full thing will probably look something like this....

air_loops.each do |air_loop|
  supply_components = air_loop.supplyComponents(OpenStudio::Model::CoilHeatingWater::iddObjectType)

  supply_components.each do |supply_component|
    heating_coil = supply_component.to_CoilHeatingWater.get # <-- this is safe because of how we called supplComps...
    uFactorTimeArea= heating_coil.isUFactorTimesAreaValueAutoSized

    if (uFactorTimeArea)
      heating_coil.setUFactorTimesAreaValue(user_input) # Or just leave autosized
    else
       # Or just leave the hardsized value that was already there
       heating_coil.setUFactorTimesAreaValue(some_other_user_input)
    end
  end

end

I believe the problem is that your variable UFactorTimeArea beings begins with a capital letter and ruby treats that as a constant. Ruby does not allow you to make assignments to constants inside of methods, only within the class declaration. If you make the variable begin with a lower case letter I think you will be ok.

The very next line is troubling though. CoilHeatingWater::isUFactorTimesAreaValueAutoSized returns a bool so UFactortimeArea is going to be a bool, however you are trying to call the method isUFactorTimesAreaValueAutoSized on it. This method is going to be undefined for bool. Instead just say if( uFactortimeArea ) and then call heating_coil.setUFactorTimesAreaValue(foo).

Finally there is a simpler method of grabbing the hot water coils off the loop. Just do this...

air_loop.supply_components(OpenStudio::Model::CoilHeatingWater::iddObjectType) Thats going to give you only the hot water coils as generic ModelObjects. You will still need to cast them into heating coils, but it will save you a check to is_initialized. The full thing will probably look something like this....

air_loops.each do |air_loop|
  supply_components = air_loop.supplyComponents(OpenStudio::Model::CoilHeatingWater::iddObjectType)

  supply_components.each do |supply_component|
    heating_coil = supply_component.to_CoilHeatingWater.get # <-- this is safe because of how we called supplComps...
    uFactorTimeArea= heating_coil.isUFactorTimesAreaValueAutoSized

    if (uFactorTimeArea)
      heating_coil.setUFactorTimesAreaValue(user_input) # Or just leave autosized
    else
       # Or just leave the hardsized value that was already there
       heating_coil.setUFactorTimesAreaValue(some_other_user_input)
    end
  end

end

I believe the problem is that your variable UFactorTimeArea begins with a capital letter and ruby treats that as a constant. Ruby does not allow you to make assignments to constants inside of methods, only within the class declaration. If you make the variable begin with a lower case letter I think you will be ok.

The very next line is troubling though. CoilHeatingWater::isUFactorTimesAreaValueAutoSized returns a bool so UFactortimeArea is going to be a bool, however you are trying to call the method isUFactorTimesAreaValueAutoSized on it. This method is going to be undefined for bool. Instead just say if( uFactortimeArea ) and then call heating_coil.setUFactorTimesAreaValue(foo).

Finally there is a simpler method of grabbing the hot water coils off the loop. Just do this...

air_loop.supply_components(OpenStudio::Model::CoilHeatingWater::iddObjectType) Thats going to give you only the hot water coils as generic ModelObjects. You will still need to cast them into heating coils, but it will save you a check to is_initialized. The full thing will probably look something like this....

air_loops.each do |air_loop|
  supply_components = air_loop.supplyComponents(OpenStudio::Model::CoilHeatingWater::iddObjectType)

  supply_components.each do |supply_component|
    heating_coil = supply_component.to_CoilHeatingWater.get # <-- this is safe because of how we called supplComps...
    uFactorTimeArea= heating_coil.isUFactorTimesAreaValueAutoSized

    if (uFactorTimeArea)
      heating_coil.setUFactorTimesAreaValue(user_input) # Or just leave autosized
    else
       # Or just leave the hardsized value that was already there
       heating_coil.setUFactorTimesAreaValue(some_other_user_input)
    end
  end

end

Alternatively if you wanted to get all of the heating coils in the model you could just do...

hot_water_coils = model.getCoilHeatingWaters

If you wanted to then go back and retrieve the air system you could do hot_water_coil.airLoopHVAC. I suspect you already know about this though since you probably had to do model.getAirLoopHVACs to fill your air_loops variable.