Skip to content

Commit 30faea4

Browse files
committed
Merge pull request #31 from danielru/add/images_boussinesq
Add/images boussinesq
2 parents 8c9c3c3 + eeda0f2 commit 30faea4

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

examples/boussinesq_2d_imex/HookClass.py

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def __init__(self):
2020

2121
# add figure object for further use
2222
# self.fig = plt.figure(figsize=(18,6))
23-
self.fig = plt.figure(figsize=(9,9))
24-
23+
self.fig = plt.figure(figsize=(15,5))
24+
self.counter = 0
2525

2626
def dump_step(self,status):
2727
"""
@@ -40,23 +40,34 @@ def dump_step(self,status):
4040
#plt.ylim([-1.1, 1.1])
4141
#plt.show(block=False)
4242
#plt.pause(0.00001)
43-
44-
if True:
43+
44+
fs = 18
45+
46+
if False:
4547
yplot = self.level.uend.values
4648
xx = self.level.prob.xx
4749
zz = self.level.prob.zz
48-
self.fig.clear()
50+
#self.fig.clear()
4951
levels = [-5e-3, -4e-3, -3e-3, -2e-3, -1e3, 1e-3, 2e-3, 3e-3, 4e-3, 5e-3]
5052
CS = plt.contourf(xx, zz, yplot[2,:,:], rstride=1, cstride=1, cmap=cm.coolwarm, linewidth=0, antialiased=False)
5153
# CS = plt.contour(xx, zz, yplot[2,:,:], rstride=1, cstride=1, linewidth=0, antialiased=False)
52-
cbar = plt.colorbar(CS)
54+
# cbar = plt.colorbar(CS)
5355
plt.axes().set_xlim(xmin = self.level.prob.x_bounds[0], xmax = self.level.prob.x_bounds[1])
5456
plt.axes().set_ylim(ymin = self.level.prob.z_bounds[0], ymax = self.level.prob.z_bounds[1])
55-
#plt.axes().set_aspect('equal')
56-
plt.xlabel('x')
57-
plt.ylabel('z')
57+
plt.axes().set_aspect('auto')
58+
plt.xlabel('x in km', fontsize=fs)
59+
plt.ylabel('z in km', fontsize=fs)
60+
plt.tick_params(axis='both', which='major', labelsize=fs)
5861
#plt.tight_layout()
59-
plt.show(block=False)
60-
plt.pause(0.00001)
61-
62+
#plt.show(block=False)
63+
#plt.show()
64+
plt.draw()
65+
plt.gcf().savefig('images/boussinesq-'+"%04d" % self.counter +'.png', bbox_inches='tight')
66+
self.counter = self.counter + 1
67+
plt.pause(0.001)
68+
69+
# NOTE: Can use ffmpeg to collate images into movie.
70+
# HELPFUL WEBSITE: http://hamelot.co.uk/visualization/using-ffmpeg-to-convert-a-set-of-images-into-a-video/
71+
# USEFUL COMMAND: ffmpeg -r 25 -i boussinesq-%04d.jpeg -vcodec libx264 -crf 25 test1800.avi
72+
# WEBSITE TO CONVERT TO MP4: http://video.online-convert.com/convert-to-mp4
6273
return None

examples/boussinesq_2d_imex/playground.py

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,34 +28,36 @@
2828

2929
# This comes as read-in for the level class
3030
lparams = {}
31-
lparams['restol'] = 1E-12
31+
lparams['restol'] = 1E-14
3232

3333
swparams = {}
3434
swparams['collocation_class'] = collclass.CollGaussLobatto
3535
swparams['num_nodes'] = 3
3636
swparams['do_LU'] = True
3737

3838
sparams = {}
39-
sparams['maxiter'] = 15
39+
sparams['maxiter'] = 4
4040

4141
# setup parameters "in time"
4242
t0 = 0
43-
Tend = 3
44-
Nsteps = 1
43+
Tend = 3000
44+
Nsteps = 500
45+
Tend = 30
46+
Nsteps = 5
4547
dt = Tend/float(Nsteps)
4648

4749
# This comes as read-in for the problem class
4850
pparams = {}
49-
pparams['nvars'] = [(4,300,10)]
51+
pparams['nvars'] = [(4,450,30)]
5052
pparams['u_adv'] = 0.02
5153
pparams['c_s'] = 0.3
5254
pparams['Nfreq'] = 0.01
5355
pparams['x_bounds'] = [(-150.0, 150.0)]
5456
pparams['z_bounds'] = [( 0.0, 10.0)]
55-
pparams['order'] = [0, 0] # [fine_level, coarse_level]
56-
pparams['gmres_maxiter'] = [50, 5]
57+
pparams['order'] = [0] # [fine_level, coarse_level]
58+
pparams['gmres_maxiter'] = [50]
5759
pparams['gmres_restart'] = 20
58-
pparams['gmres_tol'] = 1e-14
60+
pparams['gmres_tol'] = 1e-6
5961

6062
# This comes as read-in for the transfer operations
6163
tparams = {}
@@ -71,15 +73,22 @@
7173
description['sweeper_class'] = imex_1st_order
7274
description['level_params'] = lparams
7375
description['hook_class'] = plot_solution
74-
description['transfer_class'] = mesh_to_mesh_2d
75-
description['transfer_params'] = tparams
76+
#description['transfer_class'] = mesh_to_mesh_2d
77+
#description['transfer_params'] = tparams
7678

7779
# quickly generate block of steps
7880
MS = mp.generate_steps(num_procs,sparams,description)
7981

8082
# get initial values on finest level
8183
P = MS[0].levels[0].prob
8284
uinit = P.u_exact(t0)
85+
86+
cfl_advection = pparams['u_adv']*dt/P.h[0]
87+
cfl_acoustic_hor = pparams['c_s']*dt/P.h[0]
88+
cfl_acoustic_ver = pparams['c_s']*dt/P.h[1]
89+
print ("CFL number of advection: %4.2f" % cfl_advection)
90+
print ("CFL number of acoustics (horizontal): %4.2f" % cfl_acoustic_hor)
91+
print ("CFL number of acoustics (vertical): %4.2f" % cfl_acoustic_ver)
8392

8493
# call main function to get things done...
8594
uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend)
@@ -92,8 +101,8 @@
92101

93102
P.report_log()
94103

95-
plt.show()
104+
#plt.show()
96105

97-
# extract_stats = grep_stats(stats,iter=-1,type='residual')
98-
# sortedlist_stats = sort_stats(extract_stats,sortby='step')
99-
# print(extract_stats,sortedlist_stats)
106+
#extract_stats = grep_stats(stats,iter=-1,type='residual')
107+
#sortedlist_stats = sort_stats(extract_stats,sortby='step')
108+
#print(extract_stats,sortedlist_stats)

0 commit comments

Comments
 (0)