Class: StructuraidCore::Elements::Reinforcement::StraightLongitudinalLayer

Inherits:
Base
  • Object
show all
Defined in:
lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb

Constant Summary collapse

VALID_DIRECTIONS =
%i[length_1 length_2 length_3].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(start_location:, end_location:, amount_of_rebars:, rebar:, distribution_direction:) ⇒ StraightLongitudinalLayer

Returns a new instance of StraightLongitudinalLayer.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 11

def initialize(
  start_location:,
  end_location:,
  amount_of_rebars:,
  rebar:,
  distribution_direction:
)
  if VALID_DIRECTIONS.none?(distribution_direction)
    raise Elements::Reinforcement::InvalidDistributionDirection.new(distribution_direction, VALID_DIRECTIONS)
  end

  @start_location = start_location
  @end_location = end_location
  @amount_of_rebars = amount_of_rebars
  @rebar = rebar
  @distribution_direction = distribution_direction
end

Instance Attribute Details

#amount_of_rebarsObject (readonly)

Returns the value of attribute amount_of_rebars.



7
8
9
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 7

def amount_of_rebars
  @amount_of_rebars
end

#rebarObject (readonly)

Returns the value of attribute rebar.



7
8
9
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 7

def rebar
  @rebar
end

Instance Method Details

#areaObject



59
60
61
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 59

def area
  @amount_of_rebars * @rebar.area
end

#centroid_heightObject



67
68
69
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 67

def centroid_height
  @start_location.value_3
end

#diameterObject



71
72
73
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 71

def diameter
  @rebar.diameter
end

#inertiaObject



63
64
65
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 63

def inertia
  area * centroid_height
end

#lengthObject



75
76
77
78
79
80
81
82
83
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 75

def length
  vector = length_vector

  vector[0] = 0 if @distribution_direction == :length_1
  vector[1] = 0 if @distribution_direction == :length_2
  vector[2] = 0 if @distribution_direction == :length_3

  vector.magnitude
end

#modify_rebar_configuration(amount_of_new_rebars:, new_rebar:, above_middle:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 29

def modify_rebar_configuration(
  amount_of_new_rebars:,
  new_rebar:,
  above_middle:
)

  offset = (diameter - new_rebar.diameter) / 2
  offset *= -1 unless above_middle

  @amount_of_rebars = amount_of_new_rebars
  @rebar = new_rebar

  reposition(above_middle:, offset:)
  @rebar
end

#reposition(above_middle:, offset: nil) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/structuraid_core/elements/reinforcement/straight_longitudinal_layer.rb', line 45

def reposition(above_middle:, offset: nil)
  offset ||= 0.5 * diameter

  [@start_location, @end_location].each do |location|
    location.update_from_vector(
      Vector[
        location.value_1,
        location.value_2,
        above_middle ? location.value_3 - offset : location.value_3 + offset
      ]
    )
  end
end