Class: OpenStudio::Metadata::BCVTBControlsSetup
- Inherits:
-
Object
- Object
- OpenStudio::Metadata::BCVTBControlsSetup
- Defined in:
- lib/openstudio/metadata/controls.rb
Instance Method Summary collapse
-
#add_ems_output_variables_to_bcvtb ⇒ Object
Adds all EMSOutputVariable variables to the bcvtb xml.
-
#add_ext_int_actuators_to_bcvtb ⇒ Object
Adds all ExternalInterface:Actuator variables to the bcvtb xml.
-
#add_ext_int_schedules_to_bcvtb ⇒ Object
Adds all ExternalInterface:Schedule variables to the bcvtb xml.
-
#add_ext_int_variables_to_bcvtb ⇒ Object
Adds all ExternalInterface:Variable variables to the bcvtb xml.
-
#add_output_variables_to_bcvtb ⇒ Object
Adds all OpenStudio OutputVariable variables to the bcvtb xml.
-
#add_xml_output(variable_name, key_value) ⇒ Object
Add either an OutputVariable or an EnergyManagementSystemOutputVariable to the bcvtb xml file.
-
#add_xml_ptolemy(type, name) ⇒ Object
Add an ExternalInterface:* object to the bcvtb xml file.
-
#initialize(model) ⇒ BCVTBControlsSetup
constructor
Returns new BCVTBControlsSetup.
-
#initialize_bcvtb_output_file(file_path: File.join(File.dirname(__FILE__ ) , 'report_variables.cfg')) ⇒ Object
Add xml declaration and doctyp to output file.
-
#replace_ems_globals_with_ext_variables ⇒ Object
Loops through all EMSGlobalVariables.
-
#write_bcvtb_to_output_file ⇒ Object
Add bcvtb element to xml doc, pretty format, and write to disk.
Constructor Details
#initialize(model) ⇒ BCVTBControlsSetup
Returns new BCVTBControlsSetup
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/openstudio/metadata/controls.rb', line 44 def initialize(model) @model = model @output_variables = @model.getOutputVariables.sort_by{ |m| [ m.keyValue.to_s, m.name.to_s.downcase]} @ems_output_variables = @model.getEnergyManagementSystemOutputVariables.sort_by{ |m| m.name.to_s.downcase } @ems_programs = @model.getEnergyManagementSystemPrograms @ems_subroutines = @model.getEnergyManagementSystemSubroutines @ems_global_variables = @model.getEnergyManagementSystemGlobalVariables @global_variables_swapped = false @ext_int_variables = nil # set after replace_ems_globals_with_ext_variables function is called @ext_int_schedules = @model.getExternalInterfaceSchedules.sort_by{ |m| m.name.to_s.downcase } @ext_int_actuators = @model.getExternalInterfaceActuators.sort_by{ |m| m.name.to_s.downcase } @bcvtb_output_file = nil # set by initialize_bcvtb_output_file initialize_bcvtb_output_file @xml_doc = REXML::Document.new @bcvtb = REXML::Element.new "BCVTB-variables" end |
Instance Method Details
#add_ems_output_variables_to_bcvtb ⇒ Object
These are added as sourcing from ‘EnergyPlus’
Adds all EMSOutputVariable variables to the bcvtb xml
172 173 174 175 176 177 178 |
# File 'lib/openstudio/metadata/controls.rb', line 172 def add_ems_output_variables_to_bcvtb @ems_output_variables.each do |outvar| if (outvar.exportToBCVTB) @bcvtb.add_element add_xml_output(outvar.nameString, "EMS") end end end |
#add_ext_int_actuators_to_bcvtb ⇒ Object
These are added as sourcing from ‘Ptolemy’
Adds all ExternalInterface:Actuator variables to the bcvtb xml
211 212 213 214 215 216 217 |
# File 'lib/openstudio/metadata/controls.rb', line 211 def add_ext_int_actuators_to_bcvtb @ext_int_actuators.each do |actuator| if (actuator.exportToBCVTB) @bcvtb.add_element add_xml_ptolemy("actuator", actuator.name) end end end |
#add_ext_int_schedules_to_bcvtb ⇒ Object
These are added as sourcing from ‘Ptolemy’
Adds all ExternalInterface:Schedule variables to the bcvtb xml.
199 200 201 202 203 204 205 |
# File 'lib/openstudio/metadata/controls.rb', line 199 def add_ext_int_schedules_to_bcvtb @ext_int_schedules.each do |schedule| if (schedule.exportToBCVTB) @bcvtb.add_element add_xml_ptolemy("schedule", schedule.name) end end end |
#add_ext_int_variables_to_bcvtb ⇒ Object
These are added as sourcing from ‘Ptolemy’
Adds all ExternalInterface:Variable variables to the bcvtb xml
184 185 186 187 188 189 190 191 192 193 |
# File 'lib/openstudio/metadata/controls.rb', line 184 def add_ext_int_variables_to_bcvtb if !@global_variables_swapped replace_ems_globals_with_ext_variables end @ext_int_variables.each do |outvar| if (outvar.exportToBCVTB) @bcvtb.add_element add_xml_ptolemy("variable", outvar.name) end end end |
#add_output_variables_to_bcvtb ⇒ Object
These are added as sourcing from ‘EnergyPlus’
Adds all OpenStudio OutputVariable variables to the bcvtb xml
160 161 162 163 164 165 166 |
# File 'lib/openstudio/metadata/controls.rb', line 160 def add_output_variables_to_bcvtb @output_variables.each do |outvar| if (outvar.exportToBCVTB && (outvar.keyValue != "*")) @bcvtb.add_element add_xml_output(outvar.variableName, outvar.keyValue) end end end |
#add_xml_output(variable_name, key_value) ⇒ Object
Add either an OutputVariable or an EnergyManagementSystemOutputVariable to the bcvtb xml file. The source attribute is set as ‘EnergyPlus’.
93 94 95 96 97 98 99 100 101 |
# File 'lib/openstudio/metadata/controls.rb', line 93 def add_xml_output(variable_name, key_value) variable = REXML::Element.new "variable" variable.attributes["source"] = "EnergyPlus" energyplus = REXML::Element.new "EnergyPlus" energyplus.attributes["name"] = key_value energyplus.attributes["type"] = variable_name variable.add_element energyplus @bcvtb.add_element variable end |
#add_xml_ptolemy(type, name) ⇒ Object
Add an ExternalInterface:* object to the bcvtb xml file. The source attribute is set as ‘Ptolemy’.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/openstudio/metadata/controls.rb', line 109 def add_xml_ptolemy(type, name) valid_types = ['variable', 'schedule', 'actuator'] raise "type must be one of #{valid_types}" unless valid_types.include? type variable = REXML::Element.new "variable" variable.attributes["source"] = "Ptolemy" energyplus = REXML::Element.new "EnergyPlus" energyplus.attributes[type] = name variable.add_element energyplus @bcvtb.add_element variable end |
#initialize_bcvtb_output_file(file_path: File.join(File.dirname(__FILE__ ) , 'report_variables.cfg')) ⇒ Object
Add xml declaration and doctyp to output file
69 70 71 72 73 74 75 |
# File 'lib/openstudio/metadata/controls.rb', line 69 def initialize_bcvtb_output_file(file_path: File.join(File.dirname(__FILE__ ) , 'report_variables.cfg')) @bcvtb_output_file = file_path File.open(@bcvtb_output_file, 'w') do |fo| fo.puts '<?xml version="1.0" encoding="ISO-8859-1"?>' fo.puts '<!DOCTYPE BCVTB-variables SYSTEM "variables.dtd">' end end |
#replace_ems_globals_with_ext_variables ⇒ Object
Loops through all EMSGlobalVariables. If exportToBCVTB, removes the variable from the model and creates a new ExternalInterfaceVariable to replace it. Handles of the old EMSGlobalVariable and the new ExternalInterfaceVariable are swapped in programs and subroutines.
Initial values for all are set to 0.
After, the @ext_int_variables attribute is populated.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/openstudio/metadata/controls.rb', line 129 def replace_ems_globals_with_ext_variables @ems_global_variables.each do |ems_var| if ( ems_var.exportToBCVTB ) ems_global_name = ems_var.nameString ems_global_handle = ems_var.handle.to_s ems_var.remove ext_int_var = OpenStudio::Model::ExternalInterfaceVariable.new(@model, ems_global_name, 0) ext_int_var_handle = ext_int_var.handle.to_s @ems_programs.each do |prog| body = prog.body body.gsub!(ems_global_handle, ext_int_var_handle) prog.setBody(body) end @ems_subroutines.each do |prog| body = prog.body body.gsub!(ems_global_handle, ext_int_var_handle) prog.setBody(body) end end end @global_variables_swapped = true @ext_int_variables = @model.getExternalInterfaceVariables.sort_by{ |m| m.name.to_s.downcase } end |
#write_bcvtb_to_output_file ⇒ Object
Add bcvtb element to xml doc, pretty format, and write to disk
80 81 82 83 84 85 |
# File 'lib/openstudio/metadata/controls.rb', line 80 def write_bcvtb_to_output_file @xml_doc.add_element @bcvtb formatter = REXML::Formatters::Pretty.new formatter.compact = true File.open(@bcvtb_output_file,"a"){|file| file.puts formatter.write(@xml_doc.root,"")} end |