# ------------------------------------------------------------------------------
# Frequency response of the exact solution, evaluated at the Head of the channel
# ------------------------------------------------------------------------------
G_head_grid = Gn_grid[0] + 1.
for n in np.arange(1, n_modes):
G_head_grid += (Gn_grid[n]*(-1)**n)
fig1 = make_subplots(rows=2, cols=1, horizontal_spacing=0.1,
subplot_titles=("Gain at the head of the bay (amplitude / open-sea amplitude)",
"Spatial structure |\zeta(x)| / Z"))
fig1.add_trace(go.Scatter(x=T_grid, y=bay_gain_head(T_grid, BAY_L, BAY_H, BAY_R), mode="lines",
name="analytic", line=dict(width=3)), row=1, col=1)
fig1.add_trace(go.Scatter(x=T_grid, y=np.abs(G_head_grid), mode="lines",
name=f"modal n_modes: {n_modes}", line=dict(width=3, dash="dot", color="black")), row=1, col=1)
fig1.add_trace(go.Scatter(x=T_sim, y=gain_sim, mode="markers", name="time-domain simulation",
marker=dict(size=10, symbol="diamond", color="crimson")), row=1, col=1)
for lab, Tv, col in (("M2 12.42 h", 12.42, "green"), ("K1 23.93 h", 23.93, "purple"),
("natural period T0 = %.1f h" % T0_h, T0_h, "orange"), ("6 h", 6.0, "darkcyan"),
("4.25 h", 4.25, "magenta")):
fig1.add_vline(x=Tv, line=dict(color=col, dash="dot"), row=1, col=1)
fig1.add_annotation(x=np.log10(Tv), y=1.0, yref="y domain", xref="x", text=lab, textangle=-90,
showarrow=False, xanchor="right", yanchor="top", font=dict(color=col, size=11))
xk = np.linspace(0, BAY_L, 300)
for lab, Tv, color in (("M2", 12.42, "green"), ("K1", 23.93, "purple"), ("T0", T0_h, "orange"),
("6 h", 6.0, "darkcyan"), ("4.25 h", 4.25, "magenta")):
fig1.add_trace(go.Scatter(x=xk/1e3, y=bay_profile(xk, Tv, BAY_L, BAY_H, BAY_R), mode="lines", line=dict(color=color),
name="T = %s" % lab), row=2, col=1)
fig1.update_xaxes(title_text="forcing period [h]", type="log", row=1, col=1)
fig1.update_yaxes(title_text="gain", row=1, col=1)
fig1.update_xaxes(title_text="distance from the mouth [km]", row=2, col=1)
fig1.update_yaxes(title_text="amplitude ratio", row=2, col=1)
fig1.update_layout(height=900, width=600, template="plotly_white", # width=1200,
title="Level 1: resonance of a quarter-wave bay (L = %.0f km, h = %.0f m, r = %.0e 1/s)"
% (BAY_L/1e3, BAY_H, BAY_R))
fig1.show()