// Code for reading in the fetch and depth data created by pre_proc.cpp OR avg_modify.cpp // and computing wave heights for each of the 4 formulations (WEMO,SPM,TMA,and TMA). These are calculated // on the wind forcing provided (ADCIRC .22 file) in addition to the physical processes of friction, breaking, // and shoaling as computed from each formulation's period. // The final results are 5 global elevation files (ADCIRC .63 files), one for each parametric formulation, and // one for the ensemble average. // // By: Samuel Carter Boyd // Date: 04/13/2020 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define pi 3.14159265 using namespace std; //********************************************************************************** //Here the manning's n values which correspond to optimal model performance from //previous tests are used. WEMO does not have any additional physical formulations double mannings_n_SPM=0.01; double mannings_n_TMA=0.01; double mannings_n_CEM=0.02; //********************************************************************************** char content[10],temp[10]; int x,i,n,di_low,di_high,node_tot,Angres,dir,dir_tot,c,node; double g=9.7918; //gravity at meanlat (28.1091 deg) int NDSETSE,NP,DTDP,NSPOOLGE,IRTYPE,TIME,IT; bool check; string s; double Hw,Hwabove,Hwbelow,u,di_temp,di_input,y3,PRN, HWEMO,HSPM,HCEM,HTMA,WSPM,TSPM,TCEM,TTMA,Tw; double HwaboveWEMO,HwbelowWEMO,HwaboveSPM,HwbelowSPM,HwaboveTMA,HwbelowTMA,HwaboveCEM,HwbelowCEM; double TaboveSPM,TbelowSPM,TaboveTMA,TbelowTMA,TaboveCEM,TbelowCEM; double WEMO_shoal,WEMO_fric,WEMO_cum,H_break; double kSPM,LSPM,ksSPM,kfSPM,SPM_shoal,SPM_fric,SPM_cum; double kCEM,LCEM,ksCEM,kfCEM,CEM_shoal,CEM_fric,CEM_cum; double kTMA,LTMA,ksTMA,kfTMA,TMA_shoal,TMA_fric,TMA_cum; double ENS_cum,H_break_SPM; double sigma; double tol; double eps; double knew,kold,k0; double k; double L; double ks,kf,Tm,fm; int line; int Ftop,Ftop2,Favg,v=0; double Dtop,Davg,dconst=0; //*****************TMA formulation (EQ 19 from TMA paper) double WaveTMA(double g, double f, double d, double u){ double alpha; alpha = 0.076*pow( ((g*f)/(u*u)),-0.22); double fm; fm = 3.5*(g/u)*pow( (g*f/(u*u)),-0.33); double ET; ET = alpha*g*d/(16*pi*pi*0.9*0.9)*1/(fm*fm); double WTMA; WTMA = 4*pow(ET,0.5); return WTMA; } double PeriodTMA(double g, double f, double d, double u){ double fm = 3.5*(g/u)*pow(((g*f)/(u*u)),-0.33); TTMA = 1/fm; return TTMA; } //***************CEM formulation (Eq II-2-36 in CEM) double WaveCEM(double g, double f, double u){ double Cd; Cd = 0.001*(0.009042*u + (-4.44*pow(10,-8)*f*f + 3.56*pow(10,-4)*f + 1.10949)); //Colvin //Cd = 0.001*(1.1+0.035*u); double Ustsq; Ustsq = Cd*u*u; double WCEM; WCEM = (Ustsq/g)*0.0413*pow((g*f/Ustsq),0.5); return WCEM; } double PeriodCEM(double g, double f, double u){ double Cd; Cd = 0.001*(0.009042*u + (-4.44*pow(10,-8)*f*f + 3.56*pow(10,-4)*f + 1.10949)); //Colvin //Cd = 0.001*(1.1+0.035*u); double Ustsq; Ustsq = u*u*Cd; double TCEM; TCEM = (pow(Ustsq,0.5)/g)*0.651*pow((g*f/Ustsq),0.3333333); //if(node==34283){ //cout<<" Cd: "<> content){ //reading headers x=x+1; //content counter; if(x==1){ node_tot=atoi(content); } if(x==2){ Angres=atoi(content); dir_tot=360/Angres; break; } } cout<<"Node total: "<> content){ x=x+1; if(x%(dir_tot+1)==0){ n=n+1; //node counter increment i=-1; //direction counter reset at new node } i=i+1; //direction counter increment F[n][i]=atof(content); //fetch values //if(n<15){ // cout<<"F["<> content){ x=x+1; //content counter; if(x%(dir_tot+1)==0){ n=n+1; //node counter increment i=-1; //direction counter reset at new node //dir index (i) = 0 corresponds to node number } i=i+1; //direction counter increment d[n][i]=atof(content); //depth values if(n==126765 || n==126769 || n==126770 || n==126771 || n==126772){ //for nan values d[n][i]=0; //cout<> content){ //counting NDSETSE number of time steps x=x+1; if(x<=node_tot*4){ } else{ x=1; NDSETSE=NDSETSE+1; } } infile3.close(); cout<<"NDSETSE: "<> content){ x=x+1; if(x%(dir_tot+1)==0){ n=n+1; //node counter increment i=-1; //direction counter reset at new node } i=i+1; //direction counter increment slope[n][i]=atof(content); //fetch values //if(n<15){ //cout<<"slope["<> content){ //if(infile3.is_open()){ x=0; c=0; node=0; line=1; IT=1; int Q=0; int y=0; HWEMO=-99999; HSPM= -99999; HCEM= -99999; HTMA= -99999; while(getline(infile3,s)){ //outfile3<>content; y=0; //if(node<15 && IT==1){ //cout<>temp; //read each value if(y==1){ WVX[node]=atof(temp); } if(y==2){ WVY[node]=atof(temp); } if(y==3){ PRN=atof(temp); WVEL[node] = sqrt(WVX[node]*WVX[node] + WVY[node]*WVY[node]); if(WVX[node] <= 0 && WVY[node] < 0){ //Q1 [0,90) WDIR[node] = atan(WVX[node]/WVY[node]) * 180/pi; //WDIR[node] = 180+atan(WVX[node]/WVY[node]) * 180/pi; } if(WVX[node] < 0 && WVY[node] >= 0){ //Q4 [90,180) WDIR[node] = 90+atan(abs(WVY[node]/WVX[node]))*180/pi; //WDIR[node] = 270+atan(abs(WVY[node]/WVX[node]))*180/pi; } if(WVX[node] >= 0 && WVY[node] > 0){ //Q3 [180,270) WDIR[node] = 180+atan(WVX[node]/WVY[node]) * 180/pi; //WDIR[node] = atan(WVX[node]/WVY[node]) * 180/pi; } if(WVX[node] > 0 && WVY[node] <= 0){ //Q2 [270,360) WDIR[node] = 270+atan(abs(WVY[node]/WVX[node]))*180/pi; //WDIR[node] = 90+atan(abs(WVY[node]/WVX[node]))*180/pi; } u = WVEL[node]; di_input=WDIR[node]/Angres;//di_input is interpolation direction index di_low=floor(di_input); //rounds down to the direction index below di_high=ceil(di_input); //rounds up to the direction index above //casting the double to int for the evenly divisible case dir = int(di_input); //if converged (evenly divisible case) no interpolation if(node==1){ //cout<<"BEFORE, WDIR: "<360-Angres){ di_high=1; } if(node==1){ cout<<" Interpolation between "<360-Angres){ di_high=360/Angres; } HWEMO = Interp(di_low,di_high,di_input,HwbelowWEMO,HwaboveWEMO); HSPM = Interp(di_low,di_high,di_input,HwbelowSPM,HwaboveSPM); HTMA = Interp(di_low,di_high,di_input,HwbelowTMA,HwaboveTMA); HCEM = Interp(di_low,di_high,di_input,HwbelowCEM,HwaboveCEM); TSPM = Interp(di_low,di_high,di_input,TbelowSPM,TaboveSPM); TTMA = Interp(di_low,di_high,di_input,TbelowTMA,TaboveTMA); TCEM = Interp(di_low,di_high,di_input,TbelowSPM,TaboveCEM); if(F[node][dir]==0 || d[node][dir]==0 || HWEMO < 0.0001){ HWEMO=-99999; HSPM =-99999; HTMA =-99999; HCEM =-99999; } //outfile3<0.0001){ knew=sigma*sigma/(g*tanh(kold*d[node][dir])); eps=abs(knew-kold); kold=knew; b=b+1; if(b>1000000){ //statement for no convergence //cout<<"SPM NOT CONVERGED at "<0.0001){ knew=sigma*sigma/(g*tanh(kold*d[node][dir])); eps=abs(knew-kold); kold=knew; b=b+1; if(b>1000000){ //cout<<"CEM NOT CONVERGED at "<0.0001){ knew=sigma*sigma/(g*tanh(kold*d[node][dir])); eps=abs(knew-kold); kold=knew; b=b+1; if(b>1000000){ //cout<<"TMA NOT CONVERGED at "<1 && IT==1){ //cout<<"SPM positive shoal effect at node: "<