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

Revision history [back]

You could try using the following code, but I have set only a simple input variable that will set the temperature for the entire year. Monthly variation has not been provided for. You could create more input variables as per your convenience.

class AddGroundTemperatures < OpenStudio::Measure::ModelMeasure

  #define the name that a user will see
  def name
    return "Add user defined monthly Ground Temperatures"
  end

  # human readable description
  def description
    return 'Set the ground temperature to user-defined values for all months'
  end

  # human readable description of modeling approach
  def modeler_description
    return 'Adds a specific ground temperature overriding the default energyplus ground temperature of 18 degree celsius.'
  end

  #define the arguments that the user will input
  def arguments(model)

    args = OpenStudio::Measure::OSArgumentVector.new

    # Define input variables
    ground_temp = OpenStudio::Measure::OSArgument::makeDoubleArgument('ground_temp',true)
    ground_temp.setDisplayName('Ground Temperature')
    ground_temp.setDefaultValue(18)
    args << ground_temp

    return args
  end #end the arguments method


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

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

    #set user defined values to variables
    ground_temp = runner.getDoubleArgumentValue('ground_temp',user_arguments)

    # assign the user inputs to variables
    data=[ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp]
    # create ground temperature object    
    groundtemps = OpenStudio::Model::SiteGroundTemperatureBuildingSurface.new(model)
    # add monthly temperatures
    groundtemps.setAllMonthlyTemperatures(data)


    # check the ground temperature for reasonableness
    if ground_temp <=0
      runner.registerError("Please choose a temperature above 0")
      return false
    end


    # report final condition
    runner.registerFinalCondition("The model's ground temperature was changed to #{ground_temp}.")


    return true

  end #end the run method

end #end the measure

#this allows the measure to be used by the application
AddGroundTemperatures.new.registerWithApplication

You could try using the following code, but I have set only a simple single input variable that will set the temperature for the entire year. Monthly variation has not been provided for. You could create more input variables as per your convenience.

class AddGroundTemperatures < OpenStudio::Measure::ModelMeasure

  #define the name that a user will see
  def name
    return "Add user defined monthly Ground Temperatures"
  end

  # human readable description
  def description
    return 'Set the ground temperature to user-defined values for all months'
  end

  # human readable description of modeling approach
  def modeler_description
    return 'Adds a specific ground temperature overriding the default energyplus ground temperature of 18 degree celsius.'
  end

  #define the arguments that the user will input
  def arguments(model)

    args = OpenStudio::Measure::OSArgumentVector.new

    # Define input variables
    ground_temp = OpenStudio::Measure::OSArgument::makeDoubleArgument('ground_temp',true)
    ground_temp.setDisplayName('Ground Temperature')
    ground_temp.setDefaultValue(18)
    args << ground_temp

    return args
  end #end the arguments method


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

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

    #set user defined values to variables
    ground_temp = runner.getDoubleArgumentValue('ground_temp',user_arguments)

    # assign the user inputs to variables
    data=[ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp,ground_temp]
    # create ground temperature object    
    groundtemps = OpenStudio::Model::SiteGroundTemperatureBuildingSurface.new(model)
    # add monthly temperatures
    groundtemps.setAllMonthlyTemperatures(data)


    # check the ground temperature for reasonableness
    if ground_temp <=0
      runner.registerError("Please choose a temperature above 0")
      return false
    end


    # report final condition
    runner.registerFinalCondition("The model's ground temperature was changed to #{ground_temp}.")


    return true

  end #end the run method

end #end the measure

#this allows the measure to be used by the application
AddGroundTemperatures.new.registerWithApplication