%% BOS R2018A Tether and Winch Specification
% In order to understand the txradeoffs, this worksheet aims to help constrain the solution space through some basic assumptions.

clear; close all;
LastRun = datetime

%% Load Estimates
% Air weight of the BOS, a depressor weight, and any tether/strength member weights.

% Dry Weights
dwBOS = 350; %lbf for R2017A design.
dwDepressor = 50; %lbf %N
dwAddedMass = 2.204; % 1 liter of sampled water/ no mud

%Specific Gravities
sgSeaWater = 1.027;
sgLead     = 11.35;

% Wet Weights
wwBOS = 140; %lbs for R2017A design
wwDepressor = dwDepressor*(1-sgSeaWater/sgLead);
wwCable = 23*2.205*.3; %kMacArtney Fibre Cable 3409/B
wwAddedMass = 0; %no mud pickup

%

F_deployed = (wwBOS+wwDepressor+wwCable+wwAddedMass) % Fully deployed
F_overboard= (dwBOS+dwAddedMass) %hanging on launch/recovery
%SWL is double the static heaviest load (in air on deck)

% Ok now let's look at the space of possible weights and determine SWL

MaxLoad_Est = max(F_deployed,F_overboard);

Gear_SWL = 1.5*MaxLoad_Est; %From 46 CFR 189.35-9
disp(['Minimum SWL required for all gear and winches must exceed ' num2str(ceil(Gear_SWL)) 'lbf.']);

%
%% Tether Load Rating
% Given the tow dynamics for the estimated payout following the standard guideline of a 5x safety factor makes sense:

NBL_Tether = ceil(5*(Gear_SWL));
disp(['Minimum NBL of the tether should be above ' num2str(NBL_Tether) ' lbf']);

%
%% Towing
% Upon review of the varied data obtained during the channel islands experiments, vehicle pitch did not exceed 10 degrees (nose down) at speeds above 2 knots. More testing would be required to determine pitch for a lighter unit and higher tow speeds. Within this context, we can assume the drag force is dominated by flows around the cylindricial shape of the towbody, the BOS, and the tether.

rhoSw  = 1027; %kg/m^3 seawater density @ 10C
muSw   = 0.001397; %Ns/m^2 
vSw    = muSw/rhoSw; %kinematic viscosity
diamTb = 12*.0254; %m (12 in)
lenTb  = 1; %m
diamWi = 0.394*.0254; %m (1/4")
lenWi  = 270; %m 
nblWi  = 2800; %lbs Wire NBL
uTow   = (0:.1:5)*0.514; %m/s
ReTb   = uTow*diamTb/vSw;
ReWi   = uTow*diamWi/vSw;

CdBreak = 3e5;


semilogy(uTow/0.514,ReTb,uTow/0.514, ReWi,uTow/0.514,CdBreak*ones(size(ReTb))); 
xlabel('Tow Velocity (knots)');
ylabel('Reynolds number');
legend('Tow Body','Tether','Turbulent Regime');
title('Reynolds Numbers for BOS Items')

% Let's determine the force of the drag under different regimes, and at 100<\mathrm{Re}<3{\mathrm{x10}}^5 ,C_D \approx 1. As shown here:
%
% That corresponds to towing under 2.5 knots. Below 10^6 the Cd is less than one. The force per unit length equation equals
% f_D =\frac{1}{2}\rho u^2 d\text{ }C_D

Cd = 1;
figure();
fdCyl = 0.5*rhoSw*uTow.^2*diamTb*lenTb*Cd;% Newton per meter, the cylinder is 1 meter
fdWire = 0.5*rhoSw*uTow.^2*diamWi*lenWi*Cd;% Newton per meter, the cylinder is 1 meter
fdTots = fdCyl+fdWire+F_deployed/0.2248;

plot(uTow/0.514, fdCyl*0.2248,':',...
    uTow/0.514, fdWire*0.2248,':',...
    uTow/0.514, fdTots*0.2248,'',...
    uTow/0.514, F_overboard*ones(size(uTow)),'-.',...
    uTow/0.514, Gear_SWL*ones(size(uTow)),...
    uTow/0.514, nblWi*ones(size(uTow)));

xlabel('Tow Velocity (knots)');
ylabel('Force (lbs)');
title(['Forces for ' num2str(lenWi) ' Meter Deployment']);
legend('Tow Body Drag','FM021814-2 Tether Drag', 'Total Drag + Wet Weight',...
    'Current System In-Air Weight','SWL','FM021814-2 Upgraded NBL','Location','northwest');

% Clearly, the tow characteristics of the system are getting near the lifting loading condition. This means that we shouldn't attempt to use the winch when the vessel is moving if it is sized to the SWL of the overboard load. However, this provides a static brake requirement for winch specification.
%
%% Lifting Power Requirements

HaulRate = 0:.1:40; % m/min
PowerkW  = (Gear_SWL*4.45)*HaulRate/60/1000; %kN * m/s = kilowatts
PowerHP  = PowerkW*1000/745.7; % horsepower
Load220VAC = PowerkW*1000/220 * 1.25; % kW to A with a 75% efficiency

figure();
subplot(211);
plot(HaulRate,PowerHP); ylabel('Power (HP)');
title(['Power Requirements for SWL ' num2str(ceil(Gear_SWL)) ' LBF'])
subplot(212);
plot(HaulRate,Load220VAC); ylabel('220V Load (A)');
xlabel('Haul Rate (m/min)');

%
% At the end of these calculations, we have definition of the maximum estimated load, the safe working load, the winch haul requirements, the winch brake requirements, potential loading from towing, and tether strength ratings.
%