Created
May 29, 2018 20:03
-
-
Save Kohei-Toyoda/9062cc9c11c9d249047984c27f7d3d02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
# グリッド分割数 | |
DIVISION_COUNT = 256 | |
# 境界条件 | |
BOUNDARY_CONDITION = { | |
0 : 0.0, | |
int(DIVISION_COUNT-1) : 0.0 | |
} | |
def generate_initial_grid(division_count): | |
""" | |
初期状態のグリッドを作成 | |
""" | |
grid = [] | |
for i in range(int(DIVISION_COUNT/2)): | |
grid.append(i/DIVISION_COUNT*2) | |
for i in range(int(DIVISION_COUNT/2)): | |
grid.append(-i/DIVISION_COUNT*2+1) | |
return grid | |
def calcurate_step(grid): | |
""" | |
Δtステップの計算を行う | |
""" | |
next_grid = [0]*DIVISION_COUNT | |
for x in range(DIVISION_COUNT): | |
if x in BOUNDARY_CONDITION: | |
next_grid[x] = BOUNDARY_CONDITION[x] | |
else: | |
next_grid[x]=grid[x]+(grid[x+1]-2*grid[x]+grid[x-1])/DIVISION_COUNT | |
return next_grid | |
def main(): | |
grid = generate_initial_grid(DIVISION_COUNT) | |
plt.plot(grid) | |
for i in range(8): | |
for j in range(2000*2**i): | |
grid = calcurate_step(grid) | |
plt.plot(grid) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment