一次元の浅水方程式のWrangle

// パラメータ
float g = 9.81; // 重力加速度
float dt = 0.01; // 時間ステップ
float nu = 0.001; // 数値的粘性(拡散)係数

// 水の高さ(h)と流速(u)の現在値
float h = point(0, "h", @ptnum);
float u = point(0, "u", @ptnum);

// 隣接ポイントの水の高さと流速
float h_next = point(0, "h", @ptnum + 1);
float u_next = point(0, "u", @ptnum + 1);
float h_prev = point(0, "h", @ptnum - 1);
float u_prev = point(0, "u", @ptnum - 1);

// 一次元浅水方程式の計算
float h_new = h - dt * ( (u_next * h_next - u_prev * h_prev) / (2 * 1));
float u_new = u - dt * (u * (u_next - u_prev) / (2 * 1) + g * (h_next - h_prev) / (2 * 1));

    // 数値的拡散の追加
    h_new += nu * (h_next - 2 * h + h_prev);
    u_new += nu * (u_next - 2 * u + u_prev);

if(h_new<0) h_new =0;

if (@ptnum == 0 || @ptnum == npoints(0) - 1) {
    // 流速の符号を反転
    h_new = 0.0;
    u_new = 0;
}


// 更新
setpointattrib(0, "h", @ptnum, h_new, "set");
setpointattrib(0, "u", @ptnum, u_new, "set");

@P.y = @h;