close all
clear all

e_AST = [0.294182703 0.441274054 0.518690555 0.588365406 0.650298607 0.727715107 0.797389958 0.828356558];

Tmin_AST = [349.5145631 611.6504854 699.0291262 830.0970874 873.7864078 1266.990291 2927.184466 3582.524272];
Tmean_AST = [393.2038835 786.407767 917.4757282 1048.543689 1266.990291 2097.087379 3713.592233 4412.621359];
Tmax_AST = [567.961165 917.4757282 1135.92233 1485.436893 2053.398058 3145.631068 4106.796117 5242.718447];

e_TMT_Linear = [0 1.436170213];
T_TMT_Linear = [0 1318.918919];

e_TMT_Calculated = [1.053191489 1.095744681 1.138297872 1.20212766 1.255319149 1.29787234 1.372340426];
T_TMT_Calculated = [970 1037.837838 1145.945946 1362.162162 1556.756757 1751.351351 2097.297297];

e_TMT_100Cycles = [0.680851064 0.670212766 0.70212766 0.755319149 0.861702128 0.914893617 0.978723404 1.053191489 1.117021277];
T_TMT_100Cycles = [324.3243243 410.8108108 497.2972973 605.4054054 864.8648649 1059.459459 1275.675676 1578.378378 1902.702703];

e_TMT_127000Cycles = [0.989361702 0.978723404 0.989361702 1.010638298 1.074468085 1.127659574 1.191489362 1.265957447 1.308510638];
T_TMT_127000Cycles = [281.0810811 389.1891892 475.6756757 562.1621622 778.3783784 972.972973 1254.054054 1643.243243 1924.324324];





n = 10;
e_AST_smoothed = e_AST(1):.01:e_AST(end);
tmp = interp1(e_AST,Tmin_AST,e_AST_smoothed,'PCHIP');
Tmin_AST_smoothed = filtfilt(ones(n,1)/n,1,tmp);
tmp = interp1(e_AST,Tmean_AST,e_AST_smoothed,'PCHIP');
Tmean_AST_smoothed = filtfilt(ones(n,1)/n,1,tmp);
tmp = interp1(e_AST,Tmax_AST,e_AST_smoothed,'PCHIP');
Tmax_AST_smoothed = filtfilt(ones(n,1)/n,1,tmp);

e = 0:.01:1.35;
T0 = 11675*e.^2-25086*e.^3+19235*e.^4;
L0 = 100*12*.0254;
L = (1+e)*12*100*.0254;  
a = 1.95;
e2 = e/(1-1.2*4*a/(3*L0));  %1.2 factor correction is to approximate empirical results better than direct application of quadratic strain over length a=1.95m at each end

figure('Position',[ 1000         589        1366         909],'PaperPositionMode','manual','PaperOrientation','landscape','PaperType','usletter','PaperPosition',[0 0 11 8.5]);
plot(e2,T0/4.45,'k--','LineWidth',2);
hold all
plot(e_AST_smoothed,Tmean_AST_smoothed,'Color',[0 0.5 0]);
e = .19:.01:.85;
plot(e,95*2*15*(e-.19),'LineWidth',2,'Color',[0 0.5 0]);  %Looks like marks linear strains are linearized about a point twice the original length.
e = .3:.01:1.2;
plot(e,65*2*15*(e-.3),'LineWidth',2,'Color',[0 0.5 0],'LineStyle','--');

plot(e_TMT_Linear, T_TMT_Linear,'LineWidth',2,'Color','b')

plot(e_TMT_100Cycles,T_TMT_100Cycles,'LineWidth',1,'Color','r','LineStyle','--');
plot(e_TMT_127000Cycles,T_TMT_127000Cycles,'LineWidth',1,'Color','r','LineStyle','-.');

tmp = axis; tmp(4) = 5500; axis(tmp);
legend('Strain estimated from datasheet stress-elongation for 100'' hose',...
       'From Grosenbaugh estimates for 15m AST hose (days 1-2, dotted lines show envelope)',...
       '190lbs/m stretch for 15 m hose with 19% permanent stretch (days 1-2)',...
       '130lbs/m stretch for 15 m hose with 30% permanent stretch  (days 5-35)',...
       'Calculated Strain for TMT test hose (Walter 2000)',...
       'Experiment Results for cycle number 100 of TMT test hose (Walter 2000)',...
       'Experiment Results for cycle number 127000 of TMT test hose (Walter 2000)',...
       'Location','NorthWest');


plot(e_AST_smoothed,Tmax_AST_smoothed,'Color',[0 0.5 0],'LineStyle','--');
plot(e_AST_smoothed,Tmin_AST_smoothed,'Color',[0 0.5 0],'LineStyle','--');
plot(e_TMT_Calculated,T_TMT_Calculated,'LineWidth',2,'Color','b');



load('AnalysisOfWHOITests/CompliantSectionStrainFromTMTTests.mat');

ColorString = {'-kx','-rx','-bx','-gx'};
for i = 1:4;
  plot(Strain{i},Tension{i},ColorString{i})
  leg_str{3*i-2} = ['2011 TMT Tests - 4X6 - Compliant Section - Cycle ' num2str(i) ' - Point 1'];
  leg_str{3*i-1} = ['2011 TMT Tests - 4X6 - Compliant Section - Cycle ' num2str(i) ' - Point 2'];
  leg_str{3*i} = ['2011 TMT Tests - 4X6 - Compliant Section - Cycle ' num2str(i) ' - Point 3'];
end
xlim([0 2.2])
set(gca,'Xtick',0:.1:2.2)




leg_str = ['Strain estimated from datasheet stress-elongation for 100'' hose',...
       'From Grosenbaugh estimates for 15m AST hose (days 1-2, dotted lines show envelope)',...
       '190lbs/m stretch for 15 m hose with 19% permanent stretch (days 1-2)',...
       '130lbs/m stretch for 15 m hose with 30% permanent stretch  (days 5-35)',...
       'Calculated Strain for TMT test hose (Walter 2000)',...
       'Experiment Results for cycle number 100 of TMT test hose (Walter 2000)',...
       'Experiment Results for cycle number 127000 of TMT test hose (Walter 2000)',...
       'Low limit of Grosenbaugh estimate',...
       'High limit of Grosenbaugh estimate',...
       'Linear Estimate of Rubber Stretch (Walter 2000)',...
       leg_str];

   
   
   e = 0:.01:2;
   
   e_min = [0 .3 1.45  1.9]; 
   T_min = [0 60  1400 5300]'; 

   clear A;
   for i = 1:length(e_min)
       A(i,:) = [e_min(i)^2 e_min(i)^3 e_min(i)^4]
   end
   x_min = A\T_min;
   TbestMinStiffness = x_min(1)*e.^2+x_min(2)*e.^3+x_min(3)*e.^4;
   for i = 1:length(x_min)
     if(sign(x_min(i)) == 1) s_min{i} = '+'; else s_min{i} = '-'; end
   end
   if(s_min{1} == '+') s_min{1} = ''; end
   
   e_nom = [0 .3  1.1  1.6]; 
   T_nom = [0 60 950 5300]'; 
   clear A;
   for i = 1:length(e_nom)
       A(i,:) = [e_nom(i)^2 e_nom(i)^3 e_nom(i)^4]
   end
   x_nom = A\T_nom;
   TbestNomStiffness = x_nom(1)*e.^2+x_nom(2)*e.^3+x_nom(3)*e.^4;
   for i = 1:length(x_nom)
     if(sign(x_nom(i)) == 1) s_nom{i} = '+'; else s_nom{i} = '-'; end
   end
    if(s_nom{1} == '+') s_nom{1} = ''; end
      
   e_max = [0 .3  .8  1.3]; 
   T_max = [0 60 950 5300]';
   clear A;
   for i = 1:length(e_max)
       A(i,:) = [e_max(i)^2 e_max(i)^3 e_max(i)^4]
   end
   x_max= A\T_max;
   TbestMaxStiffness = x_max(1)*e.^2+x_max(2)*e.^3+x_max(3)*e.^4;
   for i = 1:length(x_max)
      if(sign(x_max(i)) == 1) s_max{i} = '+'; else s_max{i} = '-'; end
   end
   if(s_max{1} == '+') s_max{1} = ''; end
   
   
   plot(e,TbestMinStiffness,'g-','LineWidth',3); 
   plot(e,TbestNomStiffness,'k-','LineWidth',3); 
   plot(e,TbestMaxStiffness,'r-','LineWidth',3); 

   leg_str = [leg_str ,...
              ['Best Estimate:  Minimum stiffness:  T(e) = ' s_min{1} ' '  num2str(abs(x_min(1)),'%4.0f') 'e^2 ' s_min{2} ' ' num2str(abs(x_min(2)),'%4.0f') 'e^3 '  s_min{3} ' ' num2str(abs(x_min(3)),'%4.0f') 'e^4   (lbs)'],...
              ['Best Estimate:  Nominal stiffness:  T(e) = ' s_nom{1} ' '  num2str(abs(x_nom(1)),'%4.0f') 'e^2 ' s_nom{2} ' ' num2str(abs(x_nom(2)),'%4.0f') 'e^3 '  s_nom{3} ' ' num2str(abs(x_nom(3)),'%4.0f') 'e^4   (lbs)'],...
              ['Best Estimate:  Maximum stiffness:  T(e) = ' s_max{1} ' '  num2str(abs(x_max(1)),'%4.0f') 'e^2 ' s_max{2} ' ' num2str(abs(x_max(2)),'%4.0f') 'e^3 '  s_max{3} ' ' num2str(abs(x_max(3)),'%4.0f') 'e^4   (lbs)']];

   
   %plot(e_min,T_min,'k*');
   %plot(e_nom,T_nom,'k*');
   %plot(e_max,T_max,'k*');
   
   
legend(leg_str,...
       'FontSize',10,'Location','NorthWest');

set(gcf,'PaperType','tabloid');
set(gcf,'PaperPosition',[0 0 17 11]);

xlabel('Strain of Compliant Section','FontSize',14);
ylabel('Tension (lbs)','FontSize',14);
set(gca,'Xtick',0:.1:2.2)
title('Stress-Strain of Compliant section, estimated from various tests','FontSize',14)

print('-dpdf','LargeHoseStressStrainEstimates');


