class CalcCurrent

This is proof of concept code. It can be extended to allow for a great deal more realistic take on estuary currents. CPD - 12-May-2018

Constants

Depth
Estuary_Length
Estuary_Width
Gamma
Meters_Knots
Shaft_Radius
SixMin_Secs

Attributes

depth_delta[R]

Public Class Methods

new() click to toggle source
# File lib/calc_current.rb, line 33
def initialize
        return if self.class.static.size != 0         
        @@tanh_fac = tanh_normalization_factor
        static_bootstrap
end
static() click to toggle source
# File lib/calc_current.rb, line 25
def self.static
        @@static_data
end
tanh_fac() click to toggle source
# File lib/calc_current.rb, line 29
def self.tanh_fac
        @@tanh_fac
end

Public Instance Methods

calc_surface_current(location, depth_delta = nil) click to toggle source
# File lib/calc_current.rb, line 39
def calc_surface_current(location, depth_delta = nil)
        @depth_delta = depth_delta / SixMin_Secs if !!depth_delta
        
        return "Missisng Depth Delta information."  if !!!self.depth_delta
        
        depth = depth_from_loc(location) # this maps location to a depth from radial tdc in the river channel.

        stat = self.class.static
        rdh = stat.select { |e| e.depth == depth.to_i }[0]

        surf_current = self.depth_delta * rdh.normalized_tanh * Estuary_Length
        
        rdu = RiverData_Surf.new
        rdu.tdc_radius = Shaft_Radius
        rdu.c_velocity_ms = surf_current
        rdu.c_velocity_kts = surf_current * Meters_Knots      
        rdu.surf_loc = location
        rdu.surf_radius = rdh.depth_radius

        rdu
end

Private Instance Methods

depth_from_loc(loc) click to toggle source
# File lib/calc_current.rb, line 81
def depth_from_loc(loc)
        r_tdc = Shaft_Radius - Depth
        
        r_tdc2 = r_tdc ** 2
        l2 = loc ** 2
        r_loc = sqrt(r_tdc2 + l2)
        depth = (r_loc - r_tdc).floor
        depth
end
static_bootstrap() click to toggle source
# File lib/calc_current.rb, line 70
def static_bootstrap
        (0..Depth).each do |i|
                rdh = RiverData_Shaft.new
                rdh.depth = Depth - i
                rdh.height = i
                rdh.depth_radius = Shaft_Radius - i
                rdh.normalized_tanh = tanh(Gamma * i) / self.class.tanh_fac
                self.class.static << rdh
        end
end
tanh_normalization_factor() click to toggle source
# File lib/calc_current.rb, line 62
def tanh_normalization_factor
        tnf = 0
        (0..Depth).each do |i|
                tnf += tanh(Gamma * i)
        end 
        tnf
end