lib/tbd/psi.rb in tbd-3.0.2 vs lib/tbd/psi.rb in tbd-3.0.3
- old
+ new
@@ -842,22 +842,22 @@
return invalid("'#{id}' massless layer?", mth, 0) if m.empty?
m = m.get
up = ""
up = "uprated " if m.nameString.include?(" uprated")
m = m.clone(model).to_MasslessOpaqueMaterial.get
- m.setName("'#{id}' #{up}m tbd")
+ m.setName("#{id} #{up}m tbd")
de_r = 0.001 unless de_r > 0.001
loss = (de_u - 1 / de_r) * s[:net] unless de_r > 0.001
m.setThermalResistance(de_r)
else
m = lc.getLayer(index).to_StandardOpaqueMaterial
return invalid("'#{id}' standard layer?", mth, 0) if m.empty?
m = m.get
up = ""
up = "uprated " if m.nameString.include?(" uprated")
m = m.clone(model).to_StandardOpaqueMaterial.get
- m.setName("'#{id}' #{up}m tbd")
+ m.setName("#{id} #{up}m tbd")
k = m.thermalConductivity
if de_r > 0.001
d = de_r * k
@@ -1103,10 +1103,14 @@
dy = (origin.y - terminal.y).abs
dz = (origin.z - terminal.z).abs
horizontal = dz.abs < TOL
vertical = dx < TOL && dy < TOL
edge_V = terminal - origin
+
+ invalid("1x edge length < TOL", mth, 0, ERROR) if edge_V.magnitude < TOL
+ next if edge_V.magnitude < TOL
+
edge_plane = Topolys::Plane3D.new(origin, edge_V)
if vertical
reference_V = north.dup
elsif horizontal
@@ -1118,75 +1122,81 @@
edge[:surfaces].each do |id, surface|
# Loop through each linked wire and determine farthest point from
# edge while ensuring candidate point is not aligned with edge.
t_model.wires.each do |wire|
- if surface[:wire] == wire.id # there should be a unique match
- normal = tbd[:surfaces][id][:n] if tbd[:surfaces].key?(id)
- normal = holes[id].attributes[:n] if holes.key?(id)
- normal = shades[id][:n] if shades.key?(id)
- farthest = Topolys::Point3D.new(origin.x, origin.y, origin.z)
- farthest_V = farthest - origin # zero magnitude, initially
- inverted = false
- i_origin = wire.points.index(origin)
- i_terminal = wire.points.index(terminal)
- i_last = wire.points.size - 1
+ next unless surface[:wire] == wire.id # should be a unique match
+ normal = tbd[:surfaces][id][:n] if tbd[:surfaces].key?(id)
+ normal = holes[id].attributes[:n] if holes.key?(id)
+ normal = shades[id][:n] if shades.key?(id)
+ farthest = Topolys::Point3D.new(origin.x, origin.y, origin.z)
+ farthest_V = farthest - origin # zero magnitude, initially
+ inverted = false
+ i_origin = wire.points.index(origin)
+ i_terminal = wire.points.index(terminal)
+ i_last = wire.points.size - 1
- if i_terminal == 0
- inverted = true unless i_origin == i_last
- elsif i_origin == i_last
- inverted = true unless i_terminal == 0
+ if i_terminal == 0
+ inverted = true unless i_origin == i_last
+ elsif i_origin == i_last
+ inverted = true unless i_terminal == 0
+ else
+ inverted = true unless i_terminal - i_origin == 1
+ end
+
+ wire.points.each do |point|
+ next if point == origin
+ next if point == terminal
+
+ point_on_plane = edge_plane.project(point)
+ origin_point_V = point_on_plane - origin
+ point_V_magnitude = origin_point_V.magnitude
+ next unless point_V_magnitude > TOL
+
+ # Generate a plane between origin, terminal & point. Only consider
+ # planes that share the same normal as wire.
+ if inverted
+ plane = Topolys::Plane3D.from_points(terminal, origin, point)
else
- inverted = true unless i_terminal - i_origin == 1
+ plane = Topolys::Plane3D.from_points(origin, terminal, point)
end
- wire.points.each do |point|
- next if point == origin
- next if point == terminal
- point_on_plane = edge_plane.project(point)
- origin_point_V = point_on_plane - origin
- point_V_magnitude = origin_point_V.magnitude
- next unless point_V_magnitude > TOL
+ next unless (normal.x - plane.normal.x).abs < TOL &&
+ (normal.y - plane.normal.y).abs < TOL &&
+ (normal.z - plane.normal.z).abs < TOL
- # Generate a plane between origin, terminal & point. Only consider
- # planes that share the same normal as wire.
- if inverted
- plane = Topolys::Plane3D.from_points(terminal, origin, point)
- else
- plane = Topolys::Plane3D.from_points(origin, terminal, point)
- end
+ farther = point_V_magnitude > farthest_V.magnitude
+ farthest = point if farther
+ farthest_V = origin_point_V if farther
+ end
- next unless (normal.x - plane.normal.x).abs < TOL &&
- (normal.y - plane.normal.y).abs < TOL &&
- (normal.z - plane.normal.z).abs < TOL
+ puts "ADDITION!!" if id == "ADDITION"
+ puts "#{reference_V} vs #{farthest_V}" if id == "ADDITION"
- farther = point_V_magnitude > farthest_V.magnitude
- farthest = point if farther
- farthest_V = origin_point_V if farther
- end
+ angle = reference_V.angle(farthest_V)
+ invalid("#{id} polar angle", mth, 0, ERROR, 0) if angle.nil?
+ angle = 0 if angle.nil?
- angle = reference_V.angle(farthest_V)
- adjust = false # adjust angle [180°, 360°] if necessary
+ adjust = false # adjust angle [180°, 360°] if necessary
- if vertical
+ if vertical
+ adjust = true if east.dot(farthest_V) < -TOL
+ else
+ if north.dot(farthest_V).abs < TOL ||
+ (north.dot(farthest_V).abs - 1).abs < TOL
adjust = true if east.dot(farthest_V) < -TOL
else
- if north.dot(farthest_V).abs < TOL ||
- (north.dot(farthest_V).abs - 1).abs < TOL
- adjust = true if east.dot(farthest_V) < -TOL
- else
- adjust = true if north.dot(farthest_V) < -TOL
- end
+ adjust = true if north.dot(farthest_V) < -TOL
end
-
- angle = 2 * Math::PI - angle if adjust
- angle -= 2 * Math::PI if (angle - 2 * Math::PI).abs < TOL
- surface[:angle] = angle
- farthest_V.normalize!
- surface[:polar] = farthest_V
- surface[:normal] = normal
end
+
+ angle = 2 * Math::PI - angle if adjust
+ angle -= 2 * Math::PI if (angle - 2 * Math::PI).abs < TOL
+ surface[:angle ] = angle
+ farthest_V.normalize!
+ surface[:polar ] = farthest_V
+ surface[:normal] = normal
end # end of edge-linked, surface-to-wire loop
end # end of edge-linked surface loop
edge[:horizontal] = horizontal
edge[:vertical ] = vertical
@@ -1991,11 +2001,9 @@
# @param runner [Runner] OpenStudio Measure runner
# @param argh [Hash] TBD arguments
#
# @return [Bool] true if TBD Measure is successful
def exit(runner = nil, argh = {})
- mth = "TBD::#{__callee__}"
-
# Generated files target a design context ( >= WARN ) ... change TBD log
# level for debugging purposes. By default, log status is set < DBG
# while log level is set @INF.
state = msg(status)
state = msg(INF) if status.zero?