Class: URBANopt::Scenario::HoneybeeMapper

Inherits:
SimulationMapperBase
  • Object
show all
Defined in:
lib/files/Honeybee.rb

Constant Summary collapse

@@instance_lock =

class level variables

Mutex.new
@@osw =
nil
@@mapper_measures =
nil
@@geometry =
nil

Instance Method Summary collapse

Constructor Details

#initializeHoneybeeMapper

Returns a new instance of HoneybeeMapper.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/files/Honeybee.rb', line 48

def initialize()
  # do initialization of class variables in thread safe way
  @@instance_lock.synchronize do
    # load the OSW for this class
    if @@osw.nil?
      osw_path = File.join(File.dirname(__FILE__), 'honeybee_workflow.osw')
      File.open(osw_path, 'r') do |file|
        @@osw = JSON.parse(file.read, symbolize_names: true)
      end
    # configure OSW with extension gem paths for measures and files
    # all extension gems must be required before this line
    @@osw = OpenStudio::Extension.configure_osw(@@osw)
    end

    # load the mapper measure variables if the file exists
    if @@mapper_measures.nil?
      map_meas_path = File.join(File.dirname(__FILE__), 'mapper_measures.json')
      if File.file?(map_meas_path)
        File.open(map_meas_path, 'r') do |file|
          @@mapper_measures = JSON.parse(file.read)
        end
      end
    end

  end
end

Instance Method Details

#create_osw(scenario, features, feature_names) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/files/Honeybee.rb', line 75

def create_osw(scenario, features, feature_names)

  if features.size != 1
    raise "Mapper currently cannot simulate more than one feature at a time."
  end
  feature = features[0]
  feature_id = feature.id
  feature_type = feature.type
  feature_name = feature.name

  # take the centroid of the vertices as the location of the building
  feature_vertices_coordinates = feature.feature_json[:geometry][:coordinates][0]
  feature_location = feature.find_feature_center(feature_vertices_coordinates).to_s
  if feature_names.size == 1
    feature_name = feature_names[0]
  end

  # deep clone of @@osw before we configure it
  osw = Marshal.load(Marshal.dump(@@osw))

  # set the name and description of the OSW to reference this particular feature
  osw[:name] = feature_name
  osw[:description] = feature_name

  if feature_type == 'Building'
      # set the honeybee JSON key to the honeybee_model measure
      OpenStudio::Extension.set_measure_argument(
          osw, 'from_honeybee_model', 'model_json', feature.detailed_model_filename)

      # add any of the mapper measure variables
      if not @@mapper_measures.nil?
        @@mapper_measures.each do |map_measure_param|
          # get the attribute from the feature
          feature_param = feature.send(map_measure_param[2])
          # set the measure argument
          OpenStudio::Extension.set_measure_argument(
            osw, map_measure_param[0], map_measure_param[1], feature_param)
        end
      end

      # add the feature id and name to the reporting measure
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_id', feature_id)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_name', feature_name)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_type', feature_type)
      OpenStudio::Extension.set_measure_argument(
        osw, 'default_feature_reports', 'feature_location', feature_location)

  end
  return osw
end