tbd 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/.gitattributes +3 -0
  3. data/.github/workflows/pull_request.yml +72 -0
  4. data/.gitignore +23 -0
  5. data/.rspec +3 -0
  6. data/Gemfile +3 -0
  7. data/LICENSE.md +21 -0
  8. data/README.md +154 -0
  9. data/Rakefile +60 -0
  10. data/json/midrise.json +64 -0
  11. data/json/tbd_5ZoneNoHVAC.json +19 -0
  12. data/json/tbd_5ZoneNoHVAC_btap.json +91 -0
  13. data/json/tbd_seb_n2.json +41 -0
  14. data/json/tbd_seb_n4.json +57 -0
  15. data/json/tbd_warehouse10.json +24 -0
  16. data/json/tbd_warehouse5.json +37 -0
  17. data/lib/measures/tbd/LICENSE.md +21 -0
  18. data/lib/measures/tbd/README.md +136 -0
  19. data/lib/measures/tbd/README.md.erb +42 -0
  20. data/lib/measures/tbd/docs/.gitkeep +1 -0
  21. data/lib/measures/tbd/measure.rb +327 -0
  22. data/lib/measures/tbd/measure.xml +460 -0
  23. data/lib/measures/tbd/resources/geo.rb +714 -0
  24. data/lib/measures/tbd/resources/geometry.rb +351 -0
  25. data/lib/measures/tbd/resources/model.rb +1431 -0
  26. data/lib/measures/tbd/resources/oslog.rb +381 -0
  27. data/lib/measures/tbd/resources/psi.rb +2229 -0
  28. data/lib/measures/tbd/resources/tbd.rb +55 -0
  29. data/lib/measures/tbd/resources/transformation.rb +121 -0
  30. data/lib/measures/tbd/resources/ua.rb +986 -0
  31. data/lib/measures/tbd/resources/utils.rb +1636 -0
  32. data/lib/measures/tbd/resources/version.rb +3 -0
  33. data/lib/measures/tbd/tests/tbd_full_PSI.json +17 -0
  34. data/lib/measures/tbd/tests/tbd_tests.rb +222 -0
  35. data/lib/tbd/geo.rb +714 -0
  36. data/lib/tbd/psi.rb +2229 -0
  37. data/lib/tbd/ua.rb +986 -0
  38. data/lib/tbd/version.rb +25 -0
  39. data/lib/tbd.rb +93 -0
  40. data/sponsors/canada.png +0 -0
  41. data/sponsors/quebec.png +0 -0
  42. data/tbd.gemspec +43 -0
  43. data/tbd.schema.json +571 -0
  44. data/v291_MacOS.md +110 -0
  45. metadata +191 -0
@@ -0,0 +1,55 @@
1
+ # MIT License
2
+ #
3
+ # Copyright (c) 2020-2022 Denis Bourgeois & Dan Macumber
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in all
13
+ # copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ # SOFTWARE.
22
+
23
+ require "openstudio"
24
+
25
+ # Topolys gem files.
26
+ require_relative "model"
27
+ require_relative "geometry"
28
+ require_relative "transformation"
29
+ require_relative "version"
30
+
31
+ # OSlg gem file.
32
+ require_relative "oslog"
33
+
34
+ # OSut gem file.
35
+ require_relative "utils"
36
+
37
+ # TBD gem files.
38
+ require_relative "psi"
39
+ require_relative "geo"
40
+ require_relative "ua"
41
+
42
+ module TBD
43
+ extend OSut # OpenStudio utilities
44
+
45
+ TOL = OSut::TOL
46
+ TOL2 = OSut::TOL2
47
+ DBG = OSut::DEBUG # mainly to flag invalid arguments for devs (buggy code)
48
+ INF = OSut::INFO # informs TBD user of measure success or failure
49
+ WRN = OSut::WARN # e.g. WARN users of 'iffy' .osm inputs (yet not critical)
50
+ ERR = OSut::ERR # e.g. flag invalid .osm inputs
51
+ FTL = OSut::FATAL # e.g. invalid TBD JSON format/entries
52
+ NS = "nameString" # OpenStudio IdfObject nameString method
53
+
54
+ extend TBD
55
+ end
@@ -0,0 +1,121 @@
1
+ require 'matrix'
2
+
3
+ class Matrix
4
+ def []=(i, j, x)
5
+ @rows[i][j] = x
6
+ end
7
+ end
8
+
9
+ module Topolys
10
+
11
+ # Transformations can be applied to Geometry. Ported from OpenStudio Transformation library.
12
+
13
+ class Transformation
14
+
15
+ # @return [Matrix] internal 4x4 matrix
16
+ attr_reader :matrix
17
+
18
+ ##
19
+ # Initializes an Transformation object
20
+ #
21
+ # @param [Matrix] matrix A 4x4 matrix, defaults to identity
22
+ def initialize(matrix=Matrix.identity(4))
23
+ raise "Incorrect argument for Transformation, expected Matrix but got #{matrix.class}" unless matrix.is_a?(Matrix)
24
+ @matrix = matrix
25
+ end
26
+
27
+ # translation along vector
28
+ def Transformation.translation(translation)
29
+ return nil if !translation.is_a?(Vector3D)
30
+
31
+ matrix = Matrix.identity(4)
32
+ matrix[0,3] = translation.x
33
+ matrix[1,3] = translation.y
34
+ matrix[2,3] = translation.z
35
+
36
+ return Transformation.new(matrix)
37
+ end
38
+
39
+ ##
40
+ # Initializes a rotation about origin defined by axis and angle (radians)
41
+ #
42
+ def Transformation.rotation(axis, radians)
43
+ return nil if !axis.is_a?(Vector3D)
44
+ return nil if !radians.is_a?(Numeric)
45
+ return nil if (axis.magnitude < Float::EPSILON)
46
+ normal = axis
47
+ normal.normalize!
48
+
49
+ # Rodrigues' rotation formula / Rotation matrix from Euler axis/angle
50
+ # I*cos(radians) + I*(1-cos(radians))*axis*axis^T + Q*sin(radians)
51
+ # Q = [0, -axis[2], axis[1]; axis[2], 0, -axis[0]; -axis[1], axis[0], 0]
52
+ p = normal.outer_product(normal)
53
+ i = Matrix.identity(3)
54
+ q = Matrix.zero(3)
55
+ q[0,1] = -normal.z
56
+ q[0,2] = normal.y
57
+ q[1,0] = normal.z
58
+ q[1,2] = -normal.x
59
+ q[2,0] = -normal.y
60
+ q[2,1] = normal.x
61
+
62
+ # rotation matrix
63
+ r = i*Math.cos(radians) + (1-Math.cos(radians))*p + q*Math.sin(radians)
64
+
65
+ matrix = Matrix.identity(4)
66
+ matrix[0,0] = r[0,0]
67
+ matrix[0,1] = r[0,1]
68
+ matrix[0,2] = r[0,2]
69
+ matrix[1,0] = r[1,0]
70
+ matrix[1,1] = r[1,1]
71
+ matrix[1,2] = r[1,2]
72
+ matrix[2,0] = r[2,0]
73
+ matrix[2,1] = r[2,1]
74
+ matrix[2,2] = r[2,2]
75
+
76
+ return Transformation.new(matrix)
77
+ end
78
+
79
+ ##
80
+ # Multiplies a Transformation by geometry class
81
+ #
82
+ # @param [Obj] obj A geometry object
83
+ #
84
+ # @return [Obj] Returns a new, transformed object - nil if not a geometry object
85
+ def *(obj)
86
+ if obj.is_a?(Point3D)
87
+ return mult_point(obj)
88
+ elsif obj.is_a?(Vector3D)
89
+ return mult_vector(obj)
90
+ elsif obj.is_a?(Array)
91
+ return mult_array(obj)
92
+ elsif obj.is_a?(Transformation)
93
+ return mult_transformation(obj)
94
+ end
95
+ return nil
96
+ end
97
+
98
+ private
99
+
100
+ def mult_point(point)
101
+ temp = Matrix.column_vector([point.x, point.y, point.z, 1])
102
+ temp = @matrix*temp
103
+ return Point3D.new(temp[0,0],temp[1,0],temp[2,0])
104
+ end
105
+
106
+ def mult_vector(vector)
107
+ temp = Matrix.column_vector([vector.x, vector.y, vector.z, 1])
108
+ temp = @matrix*temp
109
+ return Vector3D.new(temp[0,0],temp[1,0],temp[2,0])
110
+ end
111
+
112
+ def mult_array(array)
113
+ array.map {|obj| self*obj}
114
+ end
115
+
116
+ def mult_transformation(obj)
117
+ Transformation.new(@matrix * obj.matrix)
118
+ end
119
+
120
+ end
121
+ end