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

Changing Fuel Type in Coil:Heating:Fuel in OS

asked 2019-11-15 02:08:32 -0600

rtsuchiya's avatar

updated 2020-01-07 17:21:58 -0600

Dear all, now I am trying to modify the fuel type in Coil:Heating:Fuel with OpenStudio.

In my understanding, Coil:Heating:Gas was modified to Coil:Heating:Fuel in the current version of EP and OS have not prepare the input for fuel type.

So, I would like to modify the fuel type with OpenStudio measure (is this OK?).

Though I wrote the measure as below, it didn't work.

I think I don't understand so many things. So, any tips from you will be helpful.

# see the URL below for information on how to write OpenStudio measures
# http://nrel.github.io/OpenStudio-user-documentation/reference/measure_writing_guide/

# start the measure
class ChangeFuelTypeInCoilHeatingFuel < OpenStudio::Measure::ModelMeasure
  # human readable name
  def name
    return "Change Fuel Type in Coil:Heating:Fuel"
  end
  # human readable description
  def description
    return "This measure is used to change the type of fuel in Coil:Heating:Fuel of HVAC. This is currently not supported in OS. In the interface, the component is named Coil:Heating:Gas."
  end
  # human readable description of modeling approach
  def modeler_description
    return "Now construction"
  end
  # define the arguments that the user will input
  def arguments(workspace)
    args = OpenStudio::Measure::OSArgumentVector.new

    #The Name of the component 
    comp_name = OpenStudio::Measure::OSArgument.makeStringArgument("comp_name", true)
    comp_name.setDisplayName("The name of component modified by this measure")
    args << comp_name

    # the type of fuel
    vfuel_chs = OpenStudio::StringVector.new
    vfuel_chs << "Gas"
    vfuel_chs << "NaturalGas"
    vfuel_chs << "Propane"
    vfuel_chs << "FuelOil#1"
    vfuel_chs << "FuelOil#2"
    vfuel_chs << "Diesel"
    vfuel_chs << "Gasoline"
    vfuel_chs << "Coal"
    vfuel_chs << "Steam"    
    vfuel_chs << "OtherFuel1"   
    vfuel_chs << "OtherFuel2"       
    fueltype = OpenStudio::Measure::OSArgument::makeChoiceArgument('fueltype',vfuel_chs,true)
    fueltype.setDisplayName('Fuel type for Coil:Heating:Fuel(represented as Gas in the current OS)')
    fueltype.setDescription('Choose the fuel type used in your system.')
    fueltype.setDefaultValue("Gas")
    args << fueltype

    return args
  end

  # define what happens when the measure is run
  def run(workspace, runner, user_arguments)
    super(workspace, runner, user_arguments)

    # use the built-in error checking
    if !runner.validateUserArguments(arguments(workspace), user_arguments)
      return false
    end

    # assign the user inputs to variables
    comp_name = runner.getStringArgumentValue('comp_name',user_arguments)
    fueltype = runner.getStringArgumentValue('fueltype', user_arguments)

    # check the user_name for reasonableness
    if comp_name.empty?
      runner.registerError('Error')
      return false
    end

    # modifying fuel type of idf
    chgs = model.getCoilHeatingGases
    chgs.each do |chg|
      if CHG.name.get.match(comp_name)
        CHG.setfuelType(fueltype)
      end
    end
    runner.registerInfo("Completed.")
    return true
  end
end

# register the measure to be used by the application
ChangeFuelTypeInCoilHeatingFuel.new.registerWithApplication

The error message says

Applying ChangeFuelTypeInCoilHeatingFuel
  Result: Fail
  Error: undefined local variable or method `model' for #<ChangeFuelTypeInCoilHeatingFuel:0x00022952e03378>
    C:/xxx/measure.rb:71:in `run'
    :/ruby/2.2.0/gems/openstudio-workflow-1.3.4/lib/openstudio/workflow/util/measure.rb:502:in `apply_measure'
    :/ruby/2.2.0/gems/openstudio-workflow-1.3.4/lib/openstudio/workflow/util/measure.rb:109:in `block in apply_measures'
    :/ruby/2.2.0/gems/openstudio-workflow-1.3.4/lib/openstudio/workflow/util/measure.rb:67:in `each_index'
    :/ruby/2.2.0/gems/openstudio-workflow-1.3.4/lib/openstudio/workflow/util/measure.rb:67:in `apply_measures'
    :/ruby/2.2.0/gems/openstudio-workflow-1.3.4 ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-11-15 05:34:09 -0600

You probably did a bad copy paste from another measure. You should start fresh with a blank template (by click "Add New Measure" (the "+" sign) in the OS App on the Measures Tab).

Anyways, you probably copied from an EnergyPlus Measure (OpenStudio::Measure::EnergyPlusMeasure), while this one is an OpenStudio Measure OpenStudio::Measure::ModelMeasure

The signature of your methods uses workspace, that's why it can't find model.

The standard form for an OpenStudio Measure is this:

def arguments(model)

def run(model, runner, user_arguments)
    super(model, runner, user_arguments)
edit flag offensive delete link more

Comments

1

Ahh, thank you so much. I am still confused with that point.

In addition, how about the "chgs = model.getCoilHeatingGases".

I am not confident with how I can get the information of Coil:Heating:Gas.

rtsuchiya's avatar rtsuchiya  ( 2019-11-15 07:13:32 -0600 )edit
1

That part you can probably figure out yourself really (just open a terminal, load the ruby bindings, and you'll get autocompletion via pry...). But no, you have a typo, it's chgs = model.getCoilHeatingGass (follows the convention of get<ClassName>s)

Julien Marrec's avatar Julien Marrec  ( 2019-11-15 08:03:53 -0600 )edit
2

Don't forget to mark the answer as accepted if that solved your problem so the thread is flagged as being resolved.

Julien Marrec's avatar Julien Marrec  ( 2019-11-15 08:04:41 -0600 )edit
1

Thank you very much for your advice. I will try it.

rtsuchiya's avatar rtsuchiya  ( 2019-11-15 14:52:36 -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

Stats

Asked: 2019-11-15 02:08:32 -0600

Seen: 223 times

Last updated: Nov 15 '19