openstudio-extension 0.2.0 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -41,6 +41,7 @@ require 'openstudio'
41
41
  require 'yaml'
42
42
  require 'fileutils'
43
43
  require 'parallel'
44
+ require 'bcl'
44
45
 
45
46
  module OpenStudio
46
47
  module Extension
@@ -55,31 +56,41 @@ module OpenStudio
55
56
  # compatible with the OpenStudio CLI.
56
57
  ##
57
58
  # @param [String] dirname Directory to run commands in, defaults to Dir.pwd. If directory includes a Gemfile then create a local bundle.
58
- # @param bundle_without [Hash] Hash describing the distribution of the variable.
59
- # @param options [Hash] Hash describing options for running the simulation. These are the defaults for all runs unless overriden within the run_* methods.
59
+ # @param bundle_without [Array] List of strings of the groups to exclude when running the bundle command
60
+ # @param options [Hash] Hash describing options for running the simulation. These are the defaults for all runs unless overriden within the run_* methods. Note if options is used, then a local runner.conf file will not be loaded.
60
61
  # @option options [String] :max_datapoints Max number of datapoints to run
61
62
  # @option options [String] :num_parallel Number of simulations to run in parallel at a time
62
63
  # @option options [String] :run_simulations Set to true to run the simulations
63
64
  # @option options [String] :verbose Set to true to receive extra information while running simulations
64
65
  def initialize(dirname = Dir.pwd, bundle_without = [], options = {})
65
66
  # DLM: I am not sure if we want to use the main root directory to create these bundles
66
- # had the idea of passing in a Gemfile name/alias and path to Gemfile, then doing the bundle in ~/OpenStudio/#{alias} or something like that?
67
+ # had the idea of passing in a Gemfile name/alias and path to Gemfile, then doing the bundle
68
+ # in ~/OpenStudio/#{alias} or something like that?
67
69
 
68
70
  # if the dirname contains a runner.conf file, then use the config file to specify the parameters
69
- if File.exist?(File.join(dirname, OpenStudio::Extension::RunnerConfig::FILENAME)) && !options
71
+
72
+ @options = OpenStudio::Extension::RunnerConfig.default_config
73
+ # ORDER of PRECEDENCE: default config < runner.conf file < options passed in directly
74
+ if File.exist?(File.join(dirname, OpenStudio::Extension::RunnerConfig::FILENAME)) && options.empty?
70
75
  puts 'Using runner options from runner.conf file'
71
76
  runner_config = OpenStudio::Extension::RunnerConfig.new(dirname)
72
- @options = runner_config.options
73
- else
74
- # use the passed values or defaults overriden by passed options
75
- @options = OpenStudio::Extension::RunnerConfig.default_config.merge(options)
77
+ # use the default values overriden with runner.conf values
78
+ @options = @options.merge(runner_config.options)
76
79
  end
77
-
80
+
81
+ # use the passed values or defaults overriden by passed options
82
+ @options = @options.merge(options)
83
+
78
84
  puts "Initializing runner with dirname: '#{dirname}' and options: #{@options}"
79
85
  @dirname = File.absolute_path(dirname)
80
- @gemfile_path = File.join(@dirname, 'Gemfile')
81
- @bundle_install_path = File.join(@dirname, '.bundle/install/')
86
+
87
+ # use passed options, otherwise assume @dirname
88
+ @gemfile_path = (!@options.key?(:gemfile_path) || @options[:gemfile_path] === '') ? File.join(@dirname, 'Gemfile') : @options[:gemfile_path]
89
+ @bundle_install_path = (!@options.key?(:bundle_install_path) || @options[:bundle_install_path] === '')? File.join(@dirname, '.bundle/install/') : @options[:bundle_install_path]
82
90
  @original_dir = Dir.pwd
91
+ # puts "DIRNAME: #{@dirname}"
92
+ # puts "@gemfile_path set to: #{@gemfile_path}"
93
+ # puts "@bundle_install_path set to: #{@bundle_install_path}"
83
94
 
84
95
  @bundle_without = bundle_without || []
85
96
  @bundle_without_string = @bundle_without.join(' ')
@@ -153,7 +164,9 @@ module OpenStudio
153
164
 
154
165
  puts "needs_update = #{needs_update}"
155
166
  if needs_update
156
- run_command('bundle update', get_clean_env)
167
+ # run_command('bundle update', get_clean_env)
168
+ # KAF: updated to include specified gemfile_path...this didn't seem to work before
169
+ run_command("bundle update --gemfile=#{@gemfile_path}", get_clean_env)
157
170
  end
158
171
  ensure
159
172
  Dir.chdir(@original_dir)
@@ -559,21 +572,21 @@ module OpenStudio
559
572
  puts "Encoding.default_internal = #{Encoding.default_internal}"
560
573
 
561
574
  paths.each do |path|
562
- Dir[path[:glob]].each do |file|
563
- puts "Updating license in file #{file}"
564
- f = File.read(file)
565
- if f =~ path[:regex]
575
+ Dir[path[:glob]].each do |dir_file|
576
+ puts "Updating license in file #{dir_file}"
577
+ f = File.read(dir_file)
578
+ if f.match?(path[:regex])
566
579
  puts ' License found -- updating'
567
- File.open(file, 'w') { |write| write << f.gsub(path[:regex], path[:license]) }
580
+ File.open(dir_file, 'w') { |write| write << f.gsub(path[:regex], path[:license]) }
568
581
  elsif f =~ /\(C\)/i || f =~ /\(Copyright\)/i
569
582
  puts ' File already has copyright -- skipping'
570
583
  else
571
584
  puts ' No license found -- adding'
572
- if f =~ /#!/
585
+ if f.match?(/#!/)
573
586
  puts ' CANNOT add license to file automatically, add it manually and it will update automatically in the future'
574
587
  next
575
588
  end
576
- File.open(file, 'w') { |write| write << f.insert(0, path[:license] + "\n") }
589
+ File.open(dir_file, 'w') { |write| write << f.insert(0, path[:license] + "\n") }
577
590
  end
578
591
  end
579
592
  end
@@ -78,7 +78,9 @@ module OpenStudio
78
78
  max_datapoints: 1E9.to_i,
79
79
  num_parallel: 2,
80
80
  run_simulations: true,
81
- verbose: false
81
+ verbose: false,
82
+ gemfile_path: '',
83
+ bundle_install_path: ''
82
84
  }
83
85
  end
84
86
 
@@ -104,6 +106,19 @@ module OpenStudio
104
106
  end
105
107
  end
106
108
 
109
+ ##
110
+ # Update a runner config value
111
+ #
112
+ # @param [String] key, The name of the key to update
113
+ # @param [Variant] new_value, The new value to set the `key` to.
114
+ def update_config(key, new_value)
115
+ if @data.key? key.to_sym
116
+ @data[key.to_sym] = new_value
117
+ else
118
+ raise "Could not find key '#{key}' to update in RunnerConfig."
119
+ end
120
+ end
121
+
107
122
  ##
108
123
  # Return the options as hash
109
124
  def options
@@ -35,6 +35,6 @@
35
35
 
36
36
  module OpenStudio
37
37
  module Extension
38
- VERSION = '0.2.0'.freeze
38
+ VERSION = '0.2.5'.freeze
39
39
  end
40
40
  end
@@ -13,14 +13,14 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = 'openstudio base gem for creating generic extensions with encapsulated data and measures.'
14
14
  spec.description = 'openstudio base gem for creating generic extensions with encapsulated data and measures.'
15
15
  spec.metadata = {
16
- 'bug_tracker_uri' => 'https://github.com/NREL/openstudio-extension-gem/issues',
17
- 'changelog_uri' => 'https://github.com/NREL/openstudio-extension-gem/blob/develop/CHANGELOG.md',
18
- #'documentation_uri' => 'https://www.rubydoc.info/gems/openstudio-extension-gem/#{gem.version}',
19
- 'source_code_uri' => "https://github.com/NREL/openstudio-extension-gem/tree/v#{spec.version}"
16
+ 'bug_tracker_uri' => 'https://github.com/NREL/openstudio-extension-gem/issues',
17
+ 'changelog_uri' => 'https://github.com/NREL/openstudio-extension-gem/blob/develop/CHANGELOG.md',
18
+ # 'documentation_uri' => 'https://www.rubydoc.info/gems/openstudio-extension-gem/#{gem.version}',
19
+ 'source_code_uri' => "https://github.com/NREL/openstudio-extension-gem/tree/v#{spec.version}"
20
20
  }
21
21
 
22
22
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
23
- f.match(%r{^(test|spec|features)/})
23
+ f.match(%r{^(test|lib.measures.*tests|spec|features)/})
24
24
  end
25
25
  spec.bindir = 'exe'
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -28,13 +28,13 @@ Gem::Specification.new do |spec|
28
28
 
29
29
  spec.required_ruby_version = '~> 2.5.0'
30
30
 
31
+ spec.add_dependency 'bcl', '~> 0.6.1'
31
32
  spec.add_dependency 'bundler', '~> 2.1'
32
- spec.add_dependency 'openstudio-workflow', '~> 1.3.4'
33
- spec.add_dependency 'openstudio_measure_tester', '~> 0.2.0'
34
- spec.add_dependency 'parallel', '~> 1.12.0'
33
+ spec.add_dependency 'octokit', '~> 4.18.0' # for change logs
34
+ spec.add_dependency 'openstudio-workflow', '~> 2.0.0'
35
+ spec.add_dependency 'openstudio_measure_tester', '~> 0.2.3'
36
+ spec.add_dependency 'parallel', '~> 1.19.1'
35
37
 
36
- spec.add_development_dependency 'github_api', '~> 0.18.0'
37
- spec.add_development_dependency 'rake', '~> 12.3'
38
- spec.add_development_dependency 'rspec', '~> 3.7'
39
- spec.add_development_dependency 'rubocop', '~> 0.54.0'
38
+ spec.add_development_dependency 'rake', '~> 13.0'
39
+ spec.add_development_dependency 'rspec', '~> 3.9'
40
40
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openstudio-extension
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Katherine Fleming
@@ -10,120 +10,120 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-02-18 00:00:00.000000000 Z
13
+ date: 2020-08-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- name: bundler
16
+ name: bcl
17
17
  requirement: !ruby/object:Gem::Requirement
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: '2.1'
21
+ version: 0.6.1
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: '2.1'
28
+ version: 0.6.1
29
29
  - !ruby/object:Gem::Dependency
30
- name: openstudio-workflow
30
+ name: bundler
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: 1.3.4
35
+ version: '2.1'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: 1.3.4
42
+ version: '2.1'
43
43
  - !ruby/object:Gem::Dependency
44
- name: openstudio_measure_tester
44
+ name: octokit
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 0.2.0
49
+ version: 4.18.0
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 0.2.0
56
+ version: 4.18.0
57
57
  - !ruby/object:Gem::Dependency
58
- name: parallel
58
+ name: openstudio-workflow
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 1.12.0
63
+ version: 2.0.0
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 1.12.0
70
+ version: 2.0.0
71
71
  - !ruby/object:Gem::Dependency
72
- name: github_api
72
+ name: openstudio_measure_tester
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - "~>"
76
76
  - !ruby/object:Gem::Version
77
- version: 0.18.0
78
- type: :development
77
+ version: 0.2.3
78
+ type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - "~>"
83
83
  - !ruby/object:Gem::Version
84
- version: 0.18.0
84
+ version: 0.2.3
85
85
  - !ruby/object:Gem::Dependency
86
- name: rake
86
+ name: parallel
87
87
  requirement: !ruby/object:Gem::Requirement
88
88
  requirements:
89
89
  - - "~>"
90
90
  - !ruby/object:Gem::Version
91
- version: '12.3'
92
- type: :development
91
+ version: 1.19.1
92
+ type: :runtime
93
93
  prerelease: false
94
94
  version_requirements: !ruby/object:Gem::Requirement
95
95
  requirements:
96
96
  - - "~>"
97
97
  - !ruby/object:Gem::Version
98
- version: '12.3'
98
+ version: 1.19.1
99
99
  - !ruby/object:Gem::Dependency
100
- name: rspec
100
+ name: rake
101
101
  requirement: !ruby/object:Gem::Requirement
102
102
  requirements:
103
103
  - - "~>"
104
104
  - !ruby/object:Gem::Version
105
- version: '3.7'
105
+ version: '13.0'
106
106
  type: :development
107
107
  prerelease: false
108
108
  version_requirements: !ruby/object:Gem::Requirement
109
109
  requirements:
110
110
  - - "~>"
111
111
  - !ruby/object:Gem::Version
112
- version: '3.7'
112
+ version: '13.0'
113
113
  - !ruby/object:Gem::Dependency
114
- name: rubocop
114
+ name: rspec
115
115
  requirement: !ruby/object:Gem::Requirement
116
116
  requirements:
117
117
  - - "~>"
118
118
  - !ruby/object:Gem::Version
119
- version: 0.54.0
119
+ version: '3.9'
120
120
  type: :development
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - "~>"
125
125
  - !ruby/object:Gem::Version
126
- version: 0.54.0
126
+ version: '3.9'
127
127
  description: openstudio base gem for creating generic extensions with encapsulated
128
128
  data and measures.
129
129
  email:
@@ -168,7 +168,6 @@ files:
168
168
  - lib/measures/openstudio_extension_test_measure/measure.rb
169
169
  - lib/measures/openstudio_extension_test_measure/measure.xml
170
170
  - lib/measures/openstudio_extension_test_measure/resources/os_lib_helper_methods.rb
171
- - lib/measures/openstudio_extension_test_measure/tests/openstudio_extension_test_measure_test.rb
172
171
  - lib/openstudio-extension.rb
173
172
  - lib/openstudio/extension.rb
174
173
  - lib/openstudio/extension/core/CreateResults.rb
@@ -198,7 +197,6 @@ files:
198
197
  - lib/openstudio/extension/core/check_weather_files.rb
199
198
  - lib/openstudio/extension/core/deer_vintages.rb
200
199
  - lib/openstudio/extension/core/os_lib_aedg_measures.rb
201
- - lib/openstudio/extension/core/os_lib_cofee.rb
202
200
  - lib/openstudio/extension/core/os_lib_constructions.rb
203
201
  - lib/openstudio/extension/core/os_lib_geometry.rb
204
202
  - lib/openstudio/extension/core/os_lib_helper_methods.rb
@@ -220,7 +218,7 @@ licenses: []
220
218
  metadata:
221
219
  bug_tracker_uri: https://github.com/NREL/openstudio-extension-gem/issues
222
220
  changelog_uri: https://github.com/NREL/openstudio-extension-gem/blob/develop/CHANGELOG.md
223
- source_code_uri: https://github.com/NREL/openstudio-extension-gem/tree/v0.2.0
221
+ source_code_uri: https://github.com/NREL/openstudio-extension-gem/tree/v0.2.5
224
222
  post_install_message:
225
223
  rdoc_options: []
226
224
  require_paths:
@@ -236,8 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
236
234
  - !ruby/object:Gem::Version
237
235
  version: '0'
238
236
  requirements: []
239
- rubyforge_project:
240
- rubygems_version: 2.7.6
237
+ rubygems_version: 3.1.4
241
238
  signing_key:
242
239
  specification_version: 4
243
240
  summary: openstudio base gem for creating generic extensions with encapsulated data
@@ -1,74 +0,0 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
- # All rights reserved.
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are met:
6
- #
7
- # (1) Redistributions of source code must retain the above copyright notice,
8
- # this list of conditions and the following disclaimer.
9
- #
10
- # (2) Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- #
14
- # (3) Neither the name of the copyright holder nor the names of any contributors
15
- # may be used to endorse or promote products derived from this software without
16
- # specific prior written permission from the respective party.
17
- #
18
- # (4) Other than as required in clauses (1) and (2), distributions in any form
19
- # of modifications or other derivative works may not use the "OpenStudio"
20
- # trademark, "OS", "os", or any other confusingly similar designation without
21
- # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
- #
23
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
24
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
27
- # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
28
- # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
- # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32
- # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- require 'openstudio'
37
- require 'openstudio/measure/ShowRunnerOutput'
38
-
39
- require_relative '../measure.rb'
40
- require 'minitest/autorun'
41
-
42
- class OpenStudioExtensionTestMeasureTest < Minitest::Test
43
- # def setup
44
- # end
45
-
46
- # def teardown
47
- # end
48
-
49
- def test_OpenStudioExtensionTestMeasure
50
- # create an instance of the measure
51
- measure = OpenStudioExtensionTestMeasure.new
52
-
53
- # create an instance of a runner
54
- runner = OpenStudio::Measure::OSRunner.new(OpenStudio::WorkflowJSON.new)
55
-
56
- # make an empty model
57
- model = OpenStudio::Model::Model.new
58
-
59
- # get arguments and test that they are what we are expecting
60
- arguments = measure.arguments(model)
61
- assert_equal(0, arguments.size)
62
-
63
- # set argument values to good values and run the measure on model with spaces
64
- arguments = measure.arguments(model)
65
- argument_map = OpenStudio::Measure.convertOSArgumentVectorToMap(arguments)
66
-
67
- measure.run(model, runner, argument_map)
68
- result = runner.result
69
- # show_output(result)
70
- assert(result.value.valueName == 'Success')
71
- assert(result.warnings.empty?)
72
- assert(result.info.empty?)
73
- end
74
- end
@@ -1,259 +0,0 @@
1
- # *******************************************************************************
2
- # OpenStudio(R), Copyright (c) 2008-2020, Alliance for Sustainable Energy, LLC.
3
- # All rights reserved.
4
- # Redistribution and use in source and binary forms, with or without
5
- # modification, are permitted provided that the following conditions are met:
6
- #
7
- # (1) Redistributions of source code must retain the above copyright notice,
8
- # this list of conditions and the following disclaimer.
9
- #
10
- # (2) Redistributions in binary form must reproduce the above copyright notice,
11
- # this list of conditions and the following disclaimer in the documentation
12
- # and/or other materials provided with the distribution.
13
- #
14
- # (3) Neither the name of the copyright holder nor the names of any contributors
15
- # may be used to endorse or promote products derived from this software without
16
- # specific prior written permission from the respective party.
17
- #
18
- # (4) Other than as required in clauses (1) and (2), distributions in any form
19
- # of modifications or other derivative works may not use the "OpenStudio"
20
- # trademark, "OS", "os", or any other confusingly similar designation without
21
- # specific prior written permission from Alliance for Sustainable Energy, LLC.
22
- #
23
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) AND ANY CONTRIBUTORS
24
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
25
- # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26
- # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S), ANY CONTRIBUTORS, THE
27
- # UNITED STATES GOVERNMENT, OR THE UNITED STATES DEPARTMENT OF ENERGY, NOR ANY OF
28
- # THEIR EMPLOYEES, BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29
- # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
30
- # OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31
- # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32
- # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
- # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
- # *******************************************************************************
35
-
36
- module OsLib_Cofee
37
-
38
- # create def to use later to make bar
39
- def OsLib_Cofee.createBar(model, spaceTypeHash,lengthXTarget,lengthYTarget,totalFloorArea,numStories,midFloorMultiplier,xmin,ymin,lengthX,lengthY,zmin,zmax,endZones)
40
-
41
- # floor to floor height
42
- floor_to_floor_height = (zmax-zmin)/numStories
43
-
44
- # perimeter depth
45
- perimeterDepth = OpenStudio::convert(12,"ft","m").get
46
- perimeterBufferFactor = 1.5 # this is a margin below which I won't bother splitting the two largest spaces
47
-
48
- # create an array to control sort order of spaces in bar
49
- customSpaceTypeBar = []
50
- counter = 0
51
- spaceTypeHash.sort_by {|key, value| value}.reverse.each do |k,v|
52
- next if v == 0 # this line adds support for fractional values of 0
53
- if counter == 1
54
- if lengthXTarget*(v/totalFloorArea) > perimeterDepth * perimeterBufferFactor and endZones
55
- customSpaceTypeBar << [k,totalFloorArea * (perimeterDepth/lengthXTarget)]
56
- customSpaceTypeBar << [k,v - (totalFloorArea * (perimeterDepth/lengthXTarget))]
57
- else
58
- customSpaceTypeBar << [k,v]
59
- end
60
- elsif counter > 1
61
- customSpaceTypeBar << [k,v]
62
- end
63
- counter += 1
64
- end
65
-
66
- # add the largest space type to the end
67
- counter = 0
68
- spaceTypeHash.sort_by {|key, value| value}.reverse.each do |k,v|
69
- if counter == 0
70
- # if width is greater than 1.5x perimeter depth then split in half
71
- if lengthXTarget*(v/totalFloorArea) > perimeterDepth * perimeterBufferFactor and endZones
72
- customSpaceTypeBar << [k,v - (totalFloorArea * (perimeterDepth/lengthXTarget))]
73
- customSpaceTypeBar << [k,totalFloorArea * (perimeterDepth/lengthXTarget)]
74
- else
75
- customSpaceTypeBar << [k,v]
76
- end
77
- end
78
- break
79
- end
80
-
81
- # starting z level
82
- z = zmin
83
- storyCounter = 0
84
- barSpaceArray = []
85
-
86
- # create new stories and then add spaces
87
- [numStories,3].min.times do # no more than tree loops through this
88
- story = OpenStudio::Model::BuildingStory.new(model)
89
- story.setNominalFloortoFloorHeight(floor_to_floor_height)
90
- story.setNominalZCoordinate(z)
91
-
92
- # starting position for first space
93
- x = (lengthX - lengthXTarget)*0.5 + xmin
94
- y = (lengthY - lengthYTarget)*0.5 + ymin
95
-
96
- # temp array of spaces (this is to change floor boundary when there is mid floor multiplier)
97
- tempSpaceArray = []
98
-
99
- # loop through space types making diagram and spaces.
100
- #spaceTypeHash.sort_by {|key, value| value}.reverse.each do |k,v|
101
- customSpaceTypeBar.each do |object|
102
-
103
- # get values from what was hash
104
- k = object[0]
105
- v = object[1]
106
-
107
- # get proper zone multiplier value
108
- if storyCounter == 1 and midFloorMultiplier > 1
109
- thermalZoneMultiplier = midFloorMultiplier
110
- else
111
- thermalZoneMultiplier = 1
112
- end
113
-
114
- options = {
115
- "name" => nil,
116
- "spaceType" => k,
117
- "story" => story,
118
- "makeThermalZone" => true,
119
- "thermalZone" => nil,
120
- "thermalZoneMultiplier" => thermalZoneMultiplier,
121
- "floor_to_floor_height" => floor_to_floor_height,
122
- }
123
-
124
- # three paths for spaces depending upon building depth (3, 2 or one cross slices)
125
- if lengthYTarget > perimeterDepth * 3 # slice into core and perimeter
126
-
127
- # perimeter polygon a
128
- perim_polygon_a = OpenStudio::Point3dVector.new
129
- perim_origin_a = OpenStudio::Point3d.new(x,y,z)
130
- perim_polygon_a << perim_origin_a
131
- perim_polygon_a << OpenStudio::Point3d.new(x,y + perimeterDepth,z)
132
- perim_polygon_a << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + perimeterDepth,z)
133
- perim_polygon_a << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y,z)
134
-
135
- # create core polygon
136
- core_polygon = OpenStudio::Point3dVector.new
137
- core_origin = OpenStudio::Point3d.new(x,y + perimeterDepth,z)
138
- core_polygon << core_origin
139
- core_polygon << OpenStudio::Point3d.new(x,y + lengthYTarget - perimeterDepth,z)
140
- core_polygon << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget - perimeterDepth,z)
141
- core_polygon << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + perimeterDepth,z)
142
-
143
- # perimeter polygon b w
144
- perim_polygon_b = OpenStudio::Point3dVector.new
145
- perim_origin_b = OpenStudio::Point3d.new(x,y + lengthYTarget - perimeterDepth,z)
146
- perim_polygon_b << perim_origin_b
147
- perim_polygon_b << OpenStudio::Point3d.new(x,y + lengthYTarget,z)
148
- perim_polygon_b << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget,z)
149
- perim_polygon_b << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget - perimeterDepth,z)
150
-
151
- # run method to make spaces
152
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,perim_origin_a,perim_polygon_a,options) # model, origin, polygon, options
153
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,core_origin,core_polygon,options) # model, origin, polygon, options
154
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,perim_origin_b,perim_polygon_b,options) # model, origin, polygon, options
155
-
156
- elsif lengthYTarget > perimeterDepth * 2 # slice into two peremeter zones but no core
157
-
158
- # perimeter polygon a
159
- perim_polygon_a = OpenStudio::Point3dVector.new
160
- perim_origin_a = OpenStudio::Point3d.new(x,y,z)
161
- perim_polygon_a << perim_origin_a
162
- perim_polygon_a << OpenStudio::Point3d.new(x,y + lengthYTarget/2,z)
163
- perim_polygon_a << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget/2,z)
164
- perim_polygon_a << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y,z)
165
-
166
- # perimeter polygon b
167
- perim_polygon_b = OpenStudio::Point3dVector.new
168
- perim_origin_b = OpenStudio::Point3d.new(x,y + lengthYTarget/2,z)
169
- perim_polygon_b << perim_origin_b
170
- perim_polygon_b << OpenStudio::Point3d.new(x,y + lengthYTarget,z)
171
- perim_polygon_b << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget,z)
172
- perim_polygon_b << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget/2,z)
173
-
174
- # run method to make spaces
175
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,perim_origin_a,perim_polygon_a,options) # model, origin, polygon, options
176
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,perim_origin_b,perim_polygon_b,options) # model, origin, polygon, options
177
-
178
- else # don't slice into core and perimeter
179
-
180
- # create polygon
181
- core_polygon = OpenStudio::Point3dVector.new
182
- core_origin = OpenStudio::Point3d.new(x,y,z)
183
- core_polygon << core_origin
184
- core_polygon << OpenStudio::Point3d.new(x,y + lengthYTarget,z)
185
- core_polygon << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y + lengthYTarget,z)
186
- core_polygon << OpenStudio::Point3d.new(x + lengthXTarget*(v/totalFloorArea),y,z)
187
-
188
- # run method to make space
189
- tempSpaceArray << OsLib_Geometry.makeSpaceFromPolygon(model,core_origin,core_polygon,options) # model, origin, polygon, options
190
-
191
- end
192
-
193
- # update points for next run
194
- x += lengthXTarget*(v/totalFloorArea)
195
-
196
- end
197
-
198
- # set flags for adiabatic surfaces
199
- floorAdiabatic = false
200
- ceilingAdiabatic = false
201
-
202
- # update z
203
- if midFloorMultiplier == 1
204
- z += floor_to_floor_height
205
- else
206
- z += floor_to_floor_height * midFloorMultiplier - floor_to_floor_height
207
-
208
- if storyCounter == 0
209
- ceilingAdiabatic = true
210
- elsif storyCounter == 1
211
- floorAdiabatic = true
212
- ceilingAdiabatic = true
213
- else
214
- floorAdiabatic = true
215
- end
216
-
217
- # alter surfaces boundary conditions and constructions as described above
218
- tempSpaceArray.each do |space|
219
- space.surfaces.each do |surface|
220
- if surface.surfaceType == "RoofCeiling" and ceilingAdiabatic
221
- construction = surface.construction # todo - this isn't really the construction I want since it wasn't an interior one, but will work for now
222
- surface.setOutsideBoundaryCondition("Adiabatic")
223
- if not construction.empty?
224
- surface.setConstruction(construction.get)
225
- end
226
- end
227
- if surface.surfaceType == "Floor" and floorAdiabatic
228
- construction = surface.construction # todo - this isn't really the construction I want since it wasn't an interior one, but will work for now
229
- surface.setOutsideBoundaryCondition("Adiabatic")
230
- if not construction.empty?
231
- surface.setConstruction(construction.get)
232
- end
233
- end
234
- end
235
- end
236
-
237
- # populate bar space array from temp array
238
- barSpaceArray << tempSpaceArray
239
-
240
- end
241
-
242
- # update storyCounter
243
- storyCounter += 1
244
-
245
- end
246
-
247
- # surface matching (seems more complex than necessary)
248
- spaces = OpenStudio::Model::SpaceVector.new
249
- model.getSpaces.each do |space|
250
- spaces << space
251
- end
252
- OpenStudio::Model.matchSurfaces(spaces)
253
-
254
- result = barSpaceArray
255
- return result
256
-
257
- end
258
-
259
- end