|
| 1 | +import numpy as np |
| 2 | +from scipy import interpolate |
| 3 | + |
| 4 | +# custom 2D profiles for SWASH numerical model cases |
| 5 | + |
| 6 | + |
| 7 | +def reef(dx, h0, Slope1, Slope2, Wreef, Wfore, bCrest, emsl): |
| 8 | + """ |
| 9 | + Reef morphologic profile (Pearson et al. 2017) |
| 10 | +
|
| 11 | + dx: bathymetry mesh resolution at x axes (m) |
| 12 | + h0: offshore depth (m) |
| 13 | + Slope1: fore shore slope |
| 14 | + Slope2: inner shore slope |
| 15 | + Wreef: reef bed width (m) |
| 16 | + Wfore: flume length before fore toe (m) |
| 17 | + bCrest: beach heigh (m) |
| 18 | + emsl: mean sea level (m) |
| 19 | +
|
| 20 | + return depth data values |
| 21 | + """ |
| 22 | + |
| 23 | + # flume length |
| 24 | + W_inner = bCrest / Slope2 |
| 25 | + W1 = int(abs(h0 - emsl) / Slope1) |
| 26 | + |
| 27 | + # sections length |
| 28 | + x1 = np.arange(0, Wfore, dx) |
| 29 | + x2 = np.arange(0, W1, dx) |
| 30 | + x3 = np.arange(0, Wreef, dx) |
| 31 | + x4 = np.arange(0, W_inner, dx) |
| 32 | + |
| 33 | + # curve equation |
| 34 | + y_fore = np.zeros(len(x1)) + [h0] |
| 35 | + y1 = -Slope1 * x2 + h0 |
| 36 | + y2 = np.zeros(len(x3)) + emsl |
| 37 | + y_inner = -Slope2 * x4 + emsl |
| 38 | + |
| 39 | + # overtopping cases: an inshore plane beach to dissipate overtopped flux |
| 40 | + plane = 0.005 * np.arange(0, 150, 1) + y_inner[-1] |
| 41 | + |
| 42 | + # concatenate depth |
| 43 | + depth = np.concatenate([y_fore, y1, y2, y_inner, plane]) |
| 44 | + |
| 45 | + return depth |
| 46 | + |
| 47 | + |
| 48 | +def linear(dx, h0, bCrest, m, Wfore): |
| 49 | + """ |
| 50 | + simple linear profile (y = m * x + n) |
| 51 | +
|
| 52 | + dx: bathymetry mesh resolution at x axes (m) |
| 53 | + h0: offshore depth (m) |
| 54 | + bCrest: beach heigh (m) |
| 55 | + m: profile slope |
| 56 | + Wfore: flume length before slope toe (m) |
| 57 | +
|
| 58 | + return depth data values |
| 59 | + """ |
| 60 | + |
| 61 | + # Flume length |
| 62 | + W1 = int(h0 / m) |
| 63 | + W2 = int(bCrest / m) |
| 64 | + |
| 65 | + # Sections length |
| 66 | + x1 = np.arange(0, Wfore, dx) |
| 67 | + x2 = np.arange(0, W1, dx) |
| 68 | + x3 = np.arange(0, W2, dx) |
| 69 | + |
| 70 | + # Curve equation |
| 71 | + y_fore = np.zeros(len(x1)) + [h0] |
| 72 | + y1 = -m * x2 + h0 |
| 73 | + y2 = -m * x3 |
| 74 | + |
| 75 | + # Overtopping cases: an inshore plane beach to dissipate overtopped flux |
| 76 | + plane = 0.005 * np.arange(0, len(y2), 1) + y2[-1] # Length bed = 2 L |
| 77 | + |
| 78 | + # concatenate depth |
| 79 | + depth = np.concatenate([y_fore, y1, y2, plane]) |
| 80 | + |
| 81 | + return depth |
| 82 | + |
| 83 | + |
| 84 | +def parabolic(dx, h0, A, xBeach, bCrest): |
| 85 | + """ |
| 86 | + Parabolic profile (y = A * x^(2/3)) |
| 87 | +
|
| 88 | + dx: bathymetry mesh resolution at x axes (m) |
| 89 | + h0: offshore depth (m) |
| 90 | + A: parabola coefficient |
| 91 | + xBeach: beach length(m) |
| 92 | + bCrest: beach heigh (m) |
| 93 | + """ |
| 94 | + |
| 95 | + lx = np.arange(1, xBeach, dx) |
| 96 | + y = -(bCrest / xBeach) * lx |
| 97 | + |
| 98 | + depth, xl = [], [] |
| 99 | + x, z = 0, 0 |
| 100 | + |
| 101 | + while z <= h0: |
| 102 | + z = A * x ** (2 / 3) |
| 103 | + depth.append(z) |
| 104 | + xl.append(x) |
| 105 | + x += dx |
| 106 | + |
| 107 | + f = interpolate.interp1d(xl, depth) |
| 108 | + xnew = np.arange(0, int(np.round(len(depth) * dx)), 1) |
| 109 | + ynew = f(xnew) |
| 110 | + |
| 111 | + # concatenate depth |
| 112 | + depth = np.concatenate([ynew[::-1], y]) |
| 113 | + |
| 114 | + return depth |
| 115 | + |
| 116 | + |
| 117 | +def biparabolic(h0, hsig, omega_surf_list, TR): |
| 118 | + """ |
| 119 | + Biparabolic profile (Bernabeu et al. 2013) |
| 120 | +
|
| 121 | + h0: offshore water level (m) |
| 122 | + hsig: significant wave height (m) |
| 123 | + omega_surf: intertidal dimensionless fall velocity (1 <= omega_surf <= 5) |
| 124 | + TR: tidal range (m) |
| 125 | + """ |
| 126 | + |
| 127 | + # Discontinuity point |
| 128 | + hr = 1.1 * hsig + TR |
| 129 | + |
| 130 | + # Legal point |
| 131 | + ha = 3 * hsig + TR |
| 132 | + |
| 133 | + # Empirical adjusted parameters |
| 134 | + A = 0.21 - 0.02 * omega_surf_list |
| 135 | + B = 0.89 * np.exp(-1.24 * omega_surf_list) |
| 136 | + C = 0.06 + 0.04 * omega_surf_list |
| 137 | + D = 0.22 * np.exp(-0.83 * omega_surf_list) |
| 138 | + |
| 139 | + # Different values for the height |
| 140 | + h = np.linspace(0, h0, 150) |
| 141 | + h_cont = [] |
| 142 | + |
| 143 | + # Important points for the profile |
| 144 | + xr = (hr / A) ** (3 / 2) + (B / (A ** (3 / 2))) * hr**3 |
| 145 | + |
| 146 | + # Lines for the profile |
| 147 | + x, Xx, X, xX = [], [], [], [] |
| 148 | + |
| 149 | + for hs in h: # For each vertical point |
| 150 | + if hs < hr: |
| 151 | + x_max = 0 |
| 152 | + xapp = (hs / A) ** (3 / 2) + (B / (A ** (3 / 2))) * hs**3 |
| 153 | + x.append(xapp) |
| 154 | + x_max = max(xapp, x_max) |
| 155 | + if hs > (hr - 1.5): |
| 156 | + Xxapp = (hs / C) ** (3 / 2) + (D / (C ** (3 / 2))) * hs**3 |
| 157 | + Xx.append(Xxapp) |
| 158 | + h_cont.append(hs) |
| 159 | + else: |
| 160 | + Xapp = (hs / C) ** (3 / 2) + (D / (C ** (3 / 2))) * hs**3 |
| 161 | + if (hs - hr) < 0.1: |
| 162 | + x_diff = x_max - Xapp |
| 163 | + X.append(Xapp) |
| 164 | + if hs < (hr + 1.5): |
| 165 | + xXapp = (hs / A) ** (3 / 2) + (B / (A ** (3 / 2))) * hs**3 |
| 166 | + xX.append(xXapp) |
| 167 | + h_cont.append(hs) |
| 168 | + |
| 169 | + h_cont = np.array(h_cont) |
| 170 | + x_tot = np.concatenate((np.array(x), np.array(X) + x_diff)) |
| 171 | + # x_cont = np.concatenate((np.array(Xx)+x_diff, np.array(xX))) |
| 172 | + |
| 173 | + # Centering the y-axis in the mean tide |
| 174 | + xnew = np.arange(0, x_tot[-1], 1) |
| 175 | + # xnew_border = np.arange(x_tot[-1]-x_cont[0], x_cont[-1]-x_cont[-1], 1) |
| 176 | + depth = h - TR / 2 |
| 177 | + # border = (-h_cont+TR/2) |
| 178 | + |
| 179 | + f = interpolate.interp1d(x_tot, depth) |
| 180 | + # f1 = interpolate.interp1d(x_cont, border) |
| 181 | + ynew = f(xnew)[::-1] |
| 182 | + # ynew_border = f1(xnew_border)[::-1] |
| 183 | + |
| 184 | + depth = (h - TR / 2)[::-1] |
| 185 | + # border = (-h_cont+TR/2)[::-1] |
| 186 | + |
| 187 | + # plot |
| 188 | + # TODO: move plot to plots.py |
| 189 | + # fig, ax = plt.subplots(1, figsize = (12, 4)) |
| 190 | + # ax.plot(xnew, -ynew, color='k', zorder=3) |
| 191 | + # ax.fill_between(xnew, np.zeros((len(xnew)))+(-ynew[0]), |
| 192 | + # -ynew,facecolor="wheat", alpha=1, zorder=2) |
| 193 | + # ax.scatter(x_tot[-1]-xr, -hr+TR/2, s=30, c='red', label='Discontinuity point', zorder=5) |
| 194 | + # ax.fill_between(xnew, -ynew, np.zeros(len(xnew)), facecolor="deepskyblue", alpha=0.5, zorder=1) |
| 195 | + # ax.axhline(-ha+TR/2, color='grey', ls='-.', label='Available region') |
| 196 | + # ax.axhline(TR/2, color='silver', ls='--', label='HT') |
| 197 | + # ax.axhline(0, color='lightgrey', ls='--', label='MSL') |
| 198 | + # ax.axhline(-TR/2, color='silver', ls='--', label='LT') |
| 199 | + # ax.scatter(xnew_border, -ynew_border, c='k', s=1, marker='_', zorder=4) |
| 200 | + |
| 201 | + # attrbs |
| 202 | + # ax.set_ylim(-ynew[0], -ynew[-1]+1) |
| 203 | + # ax.set_xlim(0, x_tot[-1]) |
| 204 | + # set_title = '$\Omega_{sf}$ = ' + str(omega_surf_list) |
| 205 | + # set_title += ', TR = ' + str(TR) |
| 206 | + # ax.set_title(set_title) |
| 207 | + # ax.legend(loc='upper left') |
| 208 | + # ax.set_ylabel('$Depth$ $[m]$', fontweight='bold') |
| 209 | + # ax.set_xlabel('$X$ $[m]$', fontweight='bold') |
| 210 | + |
| 211 | + # TODO: deph or ynew ? |
| 212 | + return ynew |
| 213 | + |
| 214 | + |
| 215 | +def custom_profile(dx, emsl, xs, ys): |
| 216 | + """ |
| 217 | + custom N points profile |
| 218 | +
|
| 219 | + dx: bathymetry mesh resolution at x axes (m) |
| 220 | + xs: x values array |
| 221 | + ys: y values array |
| 222 | + emsl: mean sea level (m) |
| 223 | + """ |
| 224 | + |
| 225 | + # flume length |
| 226 | + xnew = np.arange(xs[0], xs[-1], dx) |
| 227 | + f = interpolate.interp1d(xs, ys) |
| 228 | + ynew = f(xnew) |
| 229 | + |
| 230 | + depth = -ynew |
| 231 | + |
| 232 | + return depth |
0 commit comments