/
driver.py
47 lines (38 loc) · 1.39 KB
/
driver.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# -*- coding: utf-8 -*-
"""
Driver runs 3 steps together: function generation, time stepping, plotting
This script will call the time_stepping and plotting script when you enter the
initial conditions (function) below
A little clunky right now:
* Need to run plot and animate steps one by one
* Close the figure window before the next plot or animate can appear
@author: cepuuher
"""
#TODO figure out how to not require closing window before next plot can appear
import numpy
# Not standard modules: ensure these files are in the current directory
import timestep as ts
import simple_plot as sp
import simple_animate as sa
from matplotlib import pyplot
# Sample initial condition and code for testing
#dx = 0.025
xmax = 2.0
nx = 41
dx = xmax/(nx-1)
nt = 50
test_ic = numpy.zeros((1, nx)) # put at assert to accept 1-by-nx ICs
test_ic[0, 0.5/dx: 1/dx + 1] = 2
test_solution = ts.timestep(test_ic, 'fd')
sp.plot_at(0, test_solution)
sp.plot_at(30, test_solution)
sa.animate_it(test_solution)
# try a different IC - Double hat
test_ic_2 = test_ic.copy()
test_ic_2[0, 0.7/dx: 0.9/dx] = 0
test_solution_2 = ts.timestep(test_ic_2, 'fd')
sp.plot_at(0, test_solution_2) # see initial condition
sp.plot_at(24, test_solution_2) # see intermediate step
sp.plot_at(49, test_solution_2) # see final state #BUG: clipped
sa.animate_it(test_solution_2)
pyplot.show() # to make it show after all the previous non-blocking figures