0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ナビエ–ストークス方程式の拡散項のみを用いた2D流体シミュレーション

Posted at

✅ Pythonコード(拡散項のみの簡易モデル)

# Program Name: fluid_diffusion_sim.py
# Creation Date: 20250813
# Overview: 2D fluid simulation showing velocity field at t = 0.5 using diffusion only
# Usage: Run to visualize u, v fields with matplotlib quiver plot

import numpy as np
import matplotlib.pyplot as plt

# --- シミュレーションパラメータ(Simulation parameters)---
N = 64              # グリッド分割数(Number of grid points)
L = 1.0             # 領域サイズ(Length of domain)
dx = L / N          # 格子間隔(Grid spacing)
nu = 0.01           # 動粘性係数 ν(Kinematic viscosity)
dt = 0.001          # 時間ステップ(Time step size)
t_final = 0.5       # 最終時刻(Final time)
steps = int(t_final / dt)

# --- グリッド(Grid) ---
x = np.linspace(0, L, N)
y = np.linspace(0, L, N)
X, Y = np.meshgrid(x, y)

# --- 初期条件(Initial condition):小さな渦 ---
u = -np.cos(np.pi * X) * np.sin(np.pi * Y)
v = np.sin(np.pi * X) * np.cos(np.pi * Y)

# --- ラプラシアン関数(離散的) ---
def laplacian(f):
    return (np.roll(f, -1, axis=0) + np.roll(f, 1, axis=0) +
            np.roll(f, -1, axis=1) + np.roll(f, 1, axis=1) -
            4 * f) / dx**2

# --- メインループ(時間発展) ---
for step in range(steps):
    u_new = u + dt * nu * laplacian(u)
    v_new = v + dt * nu * laplacian(v)
    u, v = u_new, v_new

# --- 可視化(Quiver plot)---
plt.figure(figsize=(6, 6))
plt.quiver(X, Y, u, v, scale=10, color='blue')
plt.title('Velocity Field at t = 0.5')
plt.xlabel('x')
plt.ylabel('y')
plt.axis('equal')
plt.grid(True)
plt.tight_layout()
plt.show()

🔍 出力結果の解説

  • 初期条件として与えた小渦が、粘性により時間とともに拡散し、速度場が弱くなっていきます。
  • plt.quiver により、格子点上のベクトルを矢印として描画します。
    derへのインポートに利用可能 |
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?