10 const double PI_ = M_PI;
20 inline void fastcosh(
double * hype,
double k,
double Z,
bool fast )
24 double Kd2 = Kd * Kd *0.5;
25 double Kd3 = Kd2 * Kd * 3.3333333333E-01;
26 double Kd4 = Kd3 * Kd* 2.5000000000E-01;
27 double Kd5 = Kd4 * Kd *2.0000000000E-01;
28 double Kd6 = Kd5 * Kd*1.6666666667E-01;
29 double Kd7 = Kd6 * Kd*1.4285714286E-01;
30 double Kd8 = Kd7 * Kd*1.2500000000E-01;
31 double Kd9 = Kd8 * Kd*1.1111111111E-01;
32 double Kd10 =Kd9 * Kd*0.1;
35 hype[0] = 1. + Kd2 + Kd4 + Kd6 + Kd8 + Kd10;
36 hype[1] = Kd + Kd3 + Kd5 + Kd7 + Kd9;
54 if(phiphi<0.){phiphi +=
Pi2_;}
58 if(phiphi >
Pi17_){ phiphi = phiphi -
Pi2_; }
60 if(phiphi >
Pi07_ ){ phiphi = phiphi -
PI_; signcos = -1;}
67 double phi2 = phiphi * phiphi *0.5;
68 double phi4 = phi2*phi2*0.16666666666666666667;
69 double fastc = 1. - phi2 + phi4;
76 double phi3 = phi1 * phi1 *phi1 * 0.166666666666667;
77 double fastc1 = - phi1 + phi3;
95 double phase = x[0]*kDir[0]+x[1]*kDir[1]+x[2]*kDir[2] - omega*t +
phi;
96 double eta = amplitude*
fastcos(phase,fast);
136 inline void __cpp_vel_mode_p(
double*
U,
double x[
nDim],
double t,
double kDir[
nDim],
double kAbs,
double omega,
double phi,
double amplitude,
double mwl,
double depth,
double waveDir[
nDim],
double vDir[
nDim],
double tanhkd,
double gAbs,
bool fast)
138 double phase = x[0]*kDir[0]+x[1]*kDir[1]+x[2]*kDir[2] - omega*t +
phi;
139 double Z = (vDir[0]*x[0] + vDir[1]*x[1]+ vDir[2]*x[2]) - mwl;
142 double hype[2] = {0};
150 Uhype = hype[0] / tanhkd + hype[1];
151 Vhype = hype[1]/ tanhkd + hype[0];
157 Uhype = hype[0] / tanhkd + hype[1];
158 Vhype = hype[1]/ tanhkd + hype[0];
161 double fcos =
fastcos(phase,fast);
164 double C = omega / kAbs;
165 double Udrift = 0.5*gAbs*amplitude*amplitude/(C*depth);
166 double UH=amplitude*omega*Uhype*fcos;
167 double UV=amplitude*omega*Vhype*fsin;
169 for(
int ii=0; ii<
nDim ; ii++)
171 U[ii] += (UH-Udrift)*waveDir[ii] + UV*vDir[ii];
185 double phi0,
double amplitude,
int Nf,
double* Ycoeff,
bool fast)
193 double kw[3] = {0.,0.,0.};
196 for (
int nn=0; nn<Nf; nn++)
209 inline void __cpp_uFenton(
double*
U,
double x[
nDim],
double t,
double kDir[
nDim],
double kAbs,
double omega,
double phi0,
double amplitude,
210 double mwl,
double depth,
double gAbs,
int Nf,
double* Bcoeff ,
double mV[
nDim],
double waveDir[
nDim],
double vDir[
nDim],
double* tanhF,
bool fast)
217 double kw[
nDim] = {0.,0.,0.};
222 double sqrtAbs(sqrt(gAbs/kAbs));
226 for (
int nn=0; nn<Nf; nn++)
235 amp = tanhF[nn]*sqrtAbs*Bcoeff[nn]/omega;
236 __cpp_vel_mode_p(
U,x, t ,kw, kmode, om,
phi, amp, mwl, depth, waveDir, vDir, tanhF[nn],gAbs, fast);
240 for (
int kk = 0; kk<3; kk++)
242 U[kk] =
U[kk]+mV[kk];
256 inline double __cpp_etaRandom(
double x[
nDim],
double t,
double* kDir,
double* omega,
double*
phi,
double* amplitude,
int N,
bool fast)
262 double kw[
nDim] = {0.,0.,0.};
265 for (
int nn=0; nn<N; nn++)
276 inline void __cpp_uRandom(
double *
U,
double x[
nDim],
double t,
double* kDir,
double* kAbs,
double* omega,
double*
phi,
double* amplitude,
double mwl,
double depth,
int N,
double waveDir[
nDim],
double vDir[
nDim],
double* tanhF,
double gAbs,
bool fast )
281 double kw[
nDim] = {0.,0.,0.};
286 for (
int nn=0; nn<N; nn++)
292 __cpp_vel_mode_p(
U,x, t ,kw, kAbs[nn], omega[nn],
phi[nn], amplitude[nn], mwl, depth, waveDir, vDir, tanhF[nn], gAbs, fast);
303 inline void __cpp_uDir(
double *
U,
double x[
nDim],
double t,
double* kDir,
double* kAbs,
double* omega,
double*
phi,
double* amplitude,
double mwl,
double depth,
int N,
double* waveDir,
double vDir[
nDim],
double* tanhF ,
double gAbs,
bool fast)
308 double kw[
nDim] = {0.,0.,0.};
309 double wd[
nDim] = {0.,0.,0.};
313 for (
int nn=0; nn<N; nn++)
320 wd[1] = waveDir[ii+1];
321 wd[2] = waveDir[ii+2];
322 __cpp_vel_mode_p(
U,x, t ,kw, kAbs[nn], omega[nn],
phi[nn], amplitude[nn], mwl, depth, wd, vDir, tanhF[nn], gAbs, fast);
332 inline int __cpp_findWindow(
double t,
double handover,
double t0,
double Twindow,
int Nwindows,
double* windows_handover)
334 double term = 1. - handover;
336 if (t-t0 >= term*Twindow)
338 Nw =
std::min(
int((t-t0 - term*Twindow)/(Twindow - 2. * handover * Twindow)) + 1, Nwindows-1);
339 if (t-t0 < windows_handover[Nw-1] - t0)
348 inline double __cpp_etaDirect(
double x[
nDim],
double x0[
nDim],
double t,
double* kDir,
double* omega,
double*
phi,
double* amplitude,
int N,
bool fast)
353 xx[0] = x[0] - x0[0];
354 xx[1] = x[1] - x0[1];
355 xx[2] = x[2] - x0[2];
365 inline void __cpp_uDirect(
double *
U,
double x[
nDim],
double x0[
nDim],
double t,
double* kDir,
double* kAbs,
double* omega,
double*
phi,
double* amplitude,
double mwl,
double depth,
int N,
double* waveDir,
double vDir[
nDim],
double* tanhKd,
double gAbs,
bool fast )
371 xx[0] = x[0] - x0[0];
372 xx[1] = x[1] - x0[1];
373 xx[2] = x[2] - x0[2];
375 __cpp_uRandom(
U, xx, t, kDir, kAbs, omega,
phi, amplitude, mwl, depth, N, waveDir, vDir, tanhKd, gAbs, fast );
380 inline double __cpp_etaWindow(
double x[
nDim],
double x0[
nDim],
double t,
double* t0,
double* kDir,
double* omega,
double*
phi,
double* amplitude,
int N,
int Nw,
bool fast)
386 xx[0] = x[0] - x0[0];
387 xx[1] = x[1] - x0[1];
388 xx[2] = x[2] - x0[2];
391 double kw[
nDim] = {0.,0.,0.};
394 for (
int nn=Is; nn<Is+N; nn++)
409 inline void __cpp_uWindow(
double*
U,
double x[
nDim],
double x0[
nDim],
double t,
double* t0,
double* kDir,
double* kAbs,
double* omega,
double*
phi,
double* amplitude,
double mwl,
double depth,
int N,
int Nw,
double* waveDir,
double* vDir,
double* tanhF,
double gAbs ,
bool fast)
415 xx[0] = x[0] - x0[0];
416 xx[1] = x[1] - x0[1];
417 xx[2] = x[2] - x0[2];
420 double kw[
nDim] = {0.,0.,0.};
425 for (
int nn=Is; nn<Is+N; nn++)
431 __cpp_vel_mode_p(
U, xx, t ,kw, kAbs[nn], omega[nn],
phi[nn], amplitude[nn], mwl, depth, waveDir, vDir, tanhF[nn], gAbs, fast);
439 inline double __cpp_eta2nd(
double x[
nDim],
double t,
double* kDir,
double* ki,
double* omega,
double*
phi,
double* amplitude,
int N,
double* sinhKd,
double* tanhKd,
bool fast)
447 double kw[
nDim] = {0.,0.,0.};
452 for (
int nn=0; nn<N; nn++)
456 kw[1] =2.* kDir[ii+1];
457 kw[2] =2.* kDir[ii+2];
458 ai_2nd = (amplitude[nn]*amplitude[nn] * ki[nn]*(2+3./(sinhKd[nn]*sinhKd[nn]) )/(4.*tanhKd[nn] ));
464 inline double __cpp_eta_short(
double x[
nDim],
double t,
double* kDir,
double* ki,
double* omega,
double*
phi,
double* amplitude,
int N,
double* sinhKd,
double* tanhKd,
double gAbs,
bool fast)
472 double kw[
nDim] = {0.,0.,0.};
473 double kw2[
nDim] = {0.,0.,0.};
480 for (
int i=0; i<N-1; i++)
487 for (
int j=i+1; j<N; j++)
490 kw2[0] = kDir[jj]+kw[0];
491 kw2[1] = kDir[jj+1]+kw[1];
492 kw2[2] = kDir[jj+2]+kw[2];
494 tanhSum = (tanhKd[i]+tanhKd[j])/(1.+tanhKd[i]*tanhKd[j]);
496 Dp = pow(omega[i]+omega[j],2) - gAbs*(ki[i]+ki[j])*tanhSum;
497 Bp = (pow(omega[i],2)+pow(omega[j],2))/(2*gAbs);
498 Bp = Bp -((omega[i]*omega[j])/(2*gAbs))*(1-1./(tanhKd[i]*tanhKd[j]) )*((pow(omega[i]+omega[j],2) + gAbs*(ki[i]+ki[j])*tanhSum)/Dp);
499 Bp = Bp + ((omega[i]+omega[j])/(2*gAbs*Dp))*((pow(omega[i],3)/pow(sinhKd[i],2)) + (pow(omega[j],3)/pow(sinhKd[j],2)));
501 ai = amplitude[i]*amplitude[j]*Bp;
508 inline double __cpp_eta_long(
double x[
nDim],
double t,
double* kDir,
double* ki,
double* omega,
double*
phi,
double* amplitude,
int N,
double* sinhKd,
double* tanhKd,
double gAbs,
bool fast)
516 double kw[
nDim] = {0.,0.,0.};
517 double kw2[
nDim] = {0.,0.,0.};
524 for (
int i=0; i<N-1; i++)
531 for (
int j=i+1; j<N; j++)
534 kw2[0] = -kDir[jj]+kw[0];
535 kw2[1] = -kDir[jj+1]+kw[1];
536 kw2[2] = -kDir[jj+2]+kw[2];
538 tanhSum = (tanhKd[i]-tanhKd[j])/(1.-tanhKd[i]*tanhKd[j]);
540 Dp = pow(omega[i]-omega[j],2) - gAbs*(ki[i]-ki[j])*tanhSum;
541 Bp = (pow(omega[i],2)+pow(omega[j],2))/(2*gAbs);
542 Bp = Bp + ((omega[i]*omega[j])/(2*gAbs))*(1+1./(tanhKd[i]*tanhKd[j]) )*((pow(omega[i]-omega[j],2) + gAbs*(ki[i]-ki[j])*tanhSum)/Dp);
543 Bp = Bp + ((omega[i]-omega[j])/(2*gAbs*Dp))*((pow(omega[i],3)/pow(sinhKd[i],2)) - (pow(omega[j],3)/pow(sinhKd[j],2)));
545 ai = amplitude[i]*amplitude[j]*Bp;