//Font settings
mathcolor="Black";
mathfontsize="1.1em";
mathfontfamily = "Arial";  
mathfontweight = "bold";  

//General
define("!<=","\u2270");
define("!>=","\u2271");
define("undefined","O/");
define("dgr","\u00BA");
define("tns","(t ons)");
define("tick","\u2713");
define("cross","\u2717");

//Mathematics
define("DDX","d/(dx)");
define("DDY","d/(dy)");
define("DDZ","d/(dz)");
define("DDX2","d^2/(dx^2)");
define("DDY2","d^2/(dy^2)");
define("DDZ2","d^2/(dz^2)");
define("ddx","del/(delx)");
define("ddy","del/(dely)");
define("ddz","del/(delz)");
define("ddx2","del^2/(delx^2)");
define("ddy2","del^2/(dely^2)");
define("ddz2","del^2/(delz^2)");


//Dredging general
define("concentration","(rho_m-rho_w)/(rho_q-rho_w)");
define("Cv","(rho_m-rho_w)/(rho_q-rho_w)");


//Dredging cutting
//General cutting equations
define("FG","G=rho_s*g*h_i*w*sin(alpha+beta)/sin(beta)*((h_b+h_i*sin(alpha))/sin(alpha)+(h_i*cos(alpha+beta))/(2*sin(beta)))");
define("FI","I=rho_s*v_c^2*sin(alpha)/sin(alpha+beta)*h_i*w");
define("FC","C=(tau_c*h_i*w)/sin(beta)");
define("FA","A=(tau_a*h_b*w)/sin(alpha)");
define("S1N1","S_1=N_1*tan(phi)")
define("S2N2","S_2=N_2*tan(delta)");
define("ESP","E_sp=(F_h*v_c)/(h_i*w*v_c)=F_h/(h_i*w)");
define("W1ncav","W_1=(Deltap_1*rho_w*g*v_c*e*h_i^2*w)/((0.5*k_i+0.5*k_max)*sin(beta))");
define("W2ncav","W_2=(Deltap_2*rho_w*g*v_c*e*h_i*h_b*w)/((0.5*k_i+0.5*k_max)*sin(alpha))");
define("W1cav","W_1=(rho_w*g*(z+10)*h_i*w)/sin(beta)");
define("W2cav","W_2=(rho_w*g*(z+10)*h_b*w)/sin(alpha)");
//Horizontal and vertical equilibrium
define("HEQ","K_1*sin(beta+phi)-W_1*sin(beta)+C*cos(beta)+I*cos(beta)-A*cos(alpha)+W_2*sin(alpha)-K_2*sin(alpha+delta)=0");
define("VEQ","-K_1*cos(beta+phi)+W_1*cos(beta)+C*sin(beta)+I*sin(beta)+A*sin(alpha)+W_2*cos(alpha)-K_2*cos(alpha+delta)+G=0");
//The unknown grain forces
define("K1general","K_1=(W_1*sin(alpha+beta+delta)+W_2*sin(delta)+G*sin(alpha+delta)-I*cos(alpha+beta+delta)-C*cos(alpha+beta+delta)+A*cos(delta))/sin(alpha+beta+phi+delta)");
define("K2general","K_2=(W_1*sin(phi)+W_2*sin(alpha+beta+phi)+G*sin(beta+phi)+I*cos(phi)+C*cos(phi)-A*cos(alpha+beta+phi))/sin(alpha+beta+phi+delta)");
//The normal forces
define("N1general","N_1=(W_1*sin(alpha+beta+delta)+W_2*sin(delta)+G*sin(alpha+delta)-I*cos(alpha+beta+delta)-C*cos(alpha+beta+delta)+A*cos(delta))/sin(alpha+beta+phi+delta)*cos(phi)");
define("N2general","N_2=(W_1*sin(phi)+W_2*sin(alpha+beta+phi)+G*sin(beta+phi)+I*cos(phi)+C*cos(phi)-A*cos(alpha+beta+phi))/sin(alpha+beta+phi+delta)*cos(delta)");
//The forces on the cutting blade
define("Fhgeneral","F_h=-W_2*sin(alpha)+K_2*sin(alpha+delta)+A*cos(alpha)");
define("Fvgeneral","F_v=-W_2*cos(alpha)+K_2*cos(alpha+delta)-A*sin(alpha)");

//Cutting equations dry sand
//Horizontal and vertical equilibrium
define("HEQdrysand","K_1*sin(beta+phi)+I*cos(beta)-K_2*sin(alpha+delta)=0");
define("VEQdrysand","-K_1*cos(beta+phi)+I*sin(beta)-K_2*cos(alpha+delta)+G=0");
//The unknown grain forces
define("K1drysand","K_1=(G*sin(alpha+delta)-I*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)");
define("K2drysand","K_2=(G*sin(beta+phi)+I*cos(phi))/sin(alpha+beta+phi+delta)");
//The normal forces
define("N1drysand","N_1=(G*sin(alpha+delta)-I*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)*cos(phi)");
define("N2drysand","N_2=(G*sin(beta+phi)+I*cos(phi))/sin(alpha+beta+phi+delta)*cos(delta)");
//The forces on the cutting blade
define("Fhdrysand","F_h=K_2*sin(alpha+delta)");
define("Fvdrysand","F_v=K_2*cos(alpha+delta)");

//Cutting equations wet sand
//Horizontal and vertical equilibrium
define("HEQwetsand","K_1*sin(beta+phi)-W_1*sin(beta)+W_2*sin(alpha)-K_2*sin(alpha+delta)=0");
define("VEQwetsand","-K_1*cos(beta+phi)+W_1*cos(beta)+W_2*cos(alpha)-K_2*cos(alpha+delta)=0");
//The unknown grain forces
define("K1wetsand","K_1=(W_1*sin(alpha+beta+delta)+W_2*sin(delta))/sin(alpha+beta+phi+delta)");
define("K2wetsand","K_2=(W_1*sin(phi)+W_2*sin(alpha+beta+phi))/sin(alpha+beta+phi+delta)");
//The normal forces
define("N1wetsand","N_1=(W_1*sin(alpha+beta+delta)+W_2*sin(delta))/sin(alpha+beta+phi+delta)*cos(phi)");
define("N2wetsand","N_2=(W_1*sin(phi)+W_2*sin(alpha+beta+phi))/sin(alpha+beta+phi+delta)*cos(delta)");
//The forces on the cutting blade
define("Fhwetsand","F_h=-W_2*sin(alpha)+K_2*sin(alpha+delta)");
define("Fvwetsand","F_v=-W_2*cos(alpha)+K_2*cos(alpha+delta)");
//Horizontal and vertical cutting forces no cavitation
define("Fhnc","F_hnc=(c_1*rho_w*g*h_i^2*v_c*w*e)/k_m");
define("Fvnc","F_vnc=(c_2*rho_w*g*h_i^2*v_c*w*e)/k_m");
//Horizontal and vertical cutting forces cavitation
define("Fhc","F_hc=d_1*rho_w*g*(z+10)*h_i*w");
define("Fvc","F_vc=d_2*rho_w*g*(z+10)*h_i*w");

//Cutting equations in clay
//Horizontal and vertical equilibrium
define("HEQclay","K_1*sin(beta)+C*cos(beta)-A*cos(alpha)-K_2*sin(alpha)=0");
define("VEQclay","-K_1*cos(beta)+C*sin(beta)+A*sin(alpha)-K_2*cos(alpha)=0");
//The unknown grain forces
define("K1clay","K_1=(-C*cos(alpha+beta)+A)/sin(alpha+beta)");
define("K2clay","K_2=(C-A*cos(alpha+beta))/sin(alpha+beta)");
//The normal forces
define("N1clay","N_1=(-C*cos(alpha+beta)+A)/sin(alpha+beta)");
define("N2clay","N_2=(C-A*cos(alpha+beta))/sin(alpha+beta)");
//The forces on the cutting blade
define("Fhclay","F_h=K_2*sin(alpha+delta)+A*cos(alpha)");
define("Fvclay","F_v=K_2*cos(alpha+delta)-A*sin(alpha)");
//Conditions
define("ClayCurlingType","(C-A*cos(alpha+beta))/sin(alpha+beta)-A<=0");
define("ClayTearType","(A-C*cos(alpha+Beta))/sin(alpha+beta)-C<=T");

//Cutting equations in rock
define("HEQrock","K_1*sin(beta+phi)+C*cos(beta)-K_2*sin(alpha+delta)=0");
define("VEQrock","-K_1*cos(beta+phi)+C*sin(beta)-K_2*cos(alpha+delta)=0");
//The unknown grain forces
define("K1rock","K_1=(-C*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)");
define("K2rock","K_2=(C*cos(phi))/sin(alpha+beta+phi+delta)");
//The normal forces
define("N1rock","N_1=(-C*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)*cos(phi)");
define("N2rock","N_2=(C*cos(phi))/sin(alpha+beta+phi+delta)*cos(delta)");
//The forces on the cutting blade
define("Fhrock","F_h=K_2*sin(alpha+delta)");
define("Fvrock","F_v=K_2*cos(alpha+delta)");
//Conditions
define("RockTearType1","(-C*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)*cos(phi)-C<=T");
define("RockTearType2","(-C*cos(alpha+beta+delta))/sin(alpha+beta+phi+delta)*cos(phi)-C+F_hydr<=T");

//TSHD sedimentation
//Turbulence efficiency
define("TSE1","eta_t=eta_g^0*(1-.184*eta_g^(+.885-.20*eta_g)*(1-tanh(eta_g^(-.13-.80*eta_g)*(log(v_s/s_o)-.2614-.5*log(lambda)+eta_g^(-.33-.94*eta_g)))))");
define("TSE2","eta_t=eta_g^(-1)*(1-.184*eta_g^(-.69-.38*eta_g)*(1-tanh(eta_g^(+.77-.08*eta_g)*(log(v_s/s_o)-.2614-.5*log(lambda)+eta_g^(+1.01-.18*eta_g)))))");
//Hopper Load Parameter
define("HLP","v_o=(Q/(L*W))");
//Flow velocity in the hopper
define("FlowV","s_o=((Q)/(W*H)");
//Terminal settling velocity
define("tsv","v_s=sqrt((4*g*(rho_q-rho_w)*d*psi)/(3*rho_w*C_d))");
//Cd value for particle
define("cdp","C_d=24/Re_p*(1+0.173*Re_p^0.657)+0.413/(1+16300*Re_p^-1.09)");
//Stokes, Budryck and Rittinger equations
define("Stokes","v_s=424*R_d*d^2");
define("Budryck","v_s=8.925*((sqrt(1+95*R_d*d^3)-1)/(d))");
define("Rittinger","v_s=87*sqrt(R_d*d)");
//Grain settling efficiency
define("GrainE","eta_g=(v_s/v_o)");
//Moody diagram equations
define("SwameeJain","lambda=0.25/(log(d/(3.7*D_h)+5.75/Re^0.9))^2");
define("Reynolds","Re=(v*D_h)/nu");
//Hydraulic diameter and radius civil engineering
define("Dhr","D_h=(4*A)/O=(4*H*W)/(2*H+W)~~4*H"); 
define("Rhr","R_h=(A)/O=(H*W)/(2*H+W)~~H"); 
//Hydraulic diameter and radius mechanical engineering
define("Dhp","D_h=(4*A)/O=(4*(pi/4*D^2))/(pi*D)=D"); 
define("Rhp","R_h=(2*A)/O=(2*(pi/4*D^2))/(pi*D)=R"); 

//Density of water
var rho_w = 1.025;
//Density of quarts
var rho_q = 2.650;
//Relative density
var Rd = (rho_q-rho_w)/rho_w; 
//Viscosity of water
var nu_w = 1.26*pow(10,-6);
//Gravity constant
var gravity = 9.81;


//Turbulence Settling Efficiency
function TSE(vsvo,vsso,labda) {
  var etat;
  if (vsvo<=1) {
    etat = (1-0.184*pow(vsvo,0.885-0.20*vsvo)*(1-tanh(pow(vsvo,-0.13-0.88*vsvo)*(log(vsso)-0.2614-0.5*log(labda)+pow(vsvo,-0.33-0.94*vsvo)))))*vsvo;
  } else {
    etat = (1-0.184*pow(vsvo,-0.690-0.38*vsvo)*(1-tanh(pow(vsvo,+0.77-0.08*vsvo)*(log(vsso)-0.2614-0.5*log(labda)+pow(vsvo,+1.01-0.18*vsvo)))));
  }
  return etat;
}
//Settling velocity according to Stokes
function Stokes(d) {
  return 424*Rd*pow(d,2);
}
//Settling velocity according to Budryck
function Budryck(d) {
  return 8.925*(sqrt(1+95*Rd*pow(d,3))-1)/d;
}
//Settling velocity according to Rittinger
function Rittinger(d) {
  return 87*sqrt(Rd*d);
}
//Swamee Jain equation for the Moody diagram, alert(SwameeJain(0.000001,1,10,0.000001));
function SwameeJain(d_r,D_h,Re) {
  return 0.25/sq(log(d_r/(3.7*D_h)+5.75/pow(Re,0.9)));
}
//Reynolds as a function of the grain diameter d in mm
function Rep(d) {
  return Budryck(d)*d/nu_w/pow(10,6);
}
//Cd value according to Turton & Levenspiel
function Cdp(Rep) {
  return 24/Rep*(1+0.173*pow(Rep,0.657))+0.413/(1+16300*pow(Rep,-1.09));
}
//Settling velocity theoretical, d in mm
function TSV(d) {
  return sqrt((4*gravity*(rho_q-rho_w)*d*0.7)/(3000*rho_w*Cdp(Rep(d))))*1000;
}

//Cutting of dry sand
function FHdrysand(alphad,hi,hb,w,vc,phid,deltad,ni) {
  var beta = rad(75-alphad/3-phid/2-deltad/4);
  var alpha = rad(alphad);
  var phi = rad(phid);
  var delta = rad(deltad);
  var rho_s = (1-ni/100)*rho_q;
  var G = rho_s*gravity*hi*w*sin(alpha+beta)/sin(beta)*((hb+hi*sin(alpha))/sin(alpha)+hi*cos(alpha+beta)/2/sin(beta));
  var I = rho_s*vc*vc*sin(alpha)/sin(alpha+beta)*hi*w;
  var K2 = (G*sin(beta+phi)+I*cos(phi))/sin(alpha+beta+phi+delta);
  var Fh = K2*sin(alpha+delta);
  return Fh;
}
function FVdrysand(alphad,hi,hb,w,vc,phid,deltad,ni) {
  var beta = rad(75-alphad/3-phid/2-deltad/4);
  var alpha = rad(alphad);
  var phi = rad(phid);
  var delta = rad(deltad);
  var rho_s = (1-ni/100)*rho_q;
  var G = rho_s*gravity*hi*w*sin(alpha+beta)/sin(beta)*((hb+hi*sin(alpha))/sin(alpha)+hi*cos(alpha+beta)/2/sin(beta));
  var I = rho_s*vc*vc*sin(alpha)/sin(alpha+beta)*hi*w;
  var K2 = (G*sin(beta+phi)+I*cos(phi))/sin(alpha+beta+phi+delta);
  var Fv = K2*cos(alpha+delta);
  return Fv;
}
function ESPdrysand(alphad,hi,hb,w,vc,phid,deltad,ni) {
  var beta = rad(75-alphad/3-phid/2-deltad/4);
  var alpha = rad(alphad);
  var phi = rad(phid);
  var delta = rad(deltad);
  var rho_s = (1-ni/100)*rho_q;
  var G = rho_s*gravity*hi*w*sin(alpha+beta)/sin(beta)*((hb+hi*sin(alpha))/sin(alpha)+hi*cos(alpha+beta)/2/sin(beta));
  var I = rho_s*vc*vc*sin(alpha)/sin(alpha+beta)*hi*w;
  var K2 = (G*sin(beta+phi)+I*cos(phi))/sin(alpha+beta+phi+delta);
  var ESP = K2*sin(alpha+delta)/hi/w;
  return ESP;
}
