numpy を np として
インポート matplotlib.pyplot を plt としてインポート
# モデルパラメータを定義
L = 100 # 領域の長さ
W = 100 # 領域の幅
dx = 1 # グリッド間隔
dt = 0.1 # タイムステップ
T = 10 # 合計シミュレーション時間
g = 9.8 # 重力加速度
# 水深と速度フィールドを初期化
h = np.ones((W, L)) # 初期水深
u = np.zeros((W, L)) # 初期 x 方向速度
v = np.zeros((W, L)) # y 方向の初期流速
# np.arange(0, T, dt) の t のタイムステップをシミュレートします:
# 水深と速度の変化を計算します
dh_dt = -np.gradient(u, axis=1) - np.gradient(v, axis=0)
du_dt = -g * np.gradient(h, axis=1)
dv_dt = -g * np.gradient(h, axis=0)
# 水深と速度を更新
h += dt * dh_dt
u += dt * du_dt
v + = dt * dv_dt
# 可視化結果
plt.imshow(h, cmap='Blues')
plt.colorbar()
plt.title('水深')
plt.show()