Skip to content

Commit 324d1c6

Browse files
committed
Merge pull request #61 from danielru/fix/change_plots_to_legendre
Fix/change plots to legendre
2 parents b38180b + 4c90354 commit 324d1c6

File tree

7 files changed

+62
-66
lines changed

7 files changed

+62
-66
lines changed

examples/acoustic_1d_imex/plotconvdata.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from matplotlib import pyplot as plt
33
from pylab import rcParams
44
from matplotlib.ticker import ScalarFormatter
5+
from subprocess import call
56

67
fs = 8
78
order = np.array([])
@@ -54,5 +55,8 @@
5455
plt.gca().get_xaxis().get_major_formatter().labelOnlyBase = False
5556
plt.gca().get_xaxis().set_major_formatter(ScalarFormatter())
5657
plt.show()
57-
fig.savefig('sdc_fwsw_convergence.pdf',bbox_inches='tight')
58+
filename = 'sdc_fwsw_convergence.pdf'
59+
fig.savefig(filename,bbox_inches='tight')
60+
call(["pdfcrop", filename, filename])
61+
5862

examples/acoustic_1d_imex/runconvergence.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131

3232
# This comes as read-in for the problem class
3333
pparams = {}
34-
pparams['nvars'] = [(2,250)]
34+
pparams['nvars'] = [(2,400)]
3535
pparams['cadv'] = 0.05
3636
pparams['cs'] = 1.00
3737
pparams['order_adv'] = 5
38-
pparams['waveno'] = 1
38+
pparams['waveno'] = 2
3939

4040
# This comes as read-in for the transfer operations
4141
tparams = {}
@@ -47,12 +47,11 @@
4747
description['problem_params'] = pparams
4848
description['dtype_u'] = mesh
4949
description['dtype_f'] = rhs_imex_mesh
50-
description['collocation_class'] = collclass.CollGaussLobatto
50+
description['collocation_class'] = collclass.CollGaussLegendre
5151
description['sweeper_class'] = imex_1st_order
52+
description['do_coll_update'] = True
5253
description['level_params'] = lparams
5354
description['hook_class'] = plot_solution
54-
#description['transfer_class'] = mesh_to_mesh_1d
55-
#description['transfer_params'] = tparams
5655

5756
Nsteps = [15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80]
5857

examples/acoustic_1d_imex/runitererror.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from matplotlib import pyplot as plt
1818
from pylab import rcParams
19-
19+
from subprocess import call
2020

2121
if __name__ == "__main__":
2222

@@ -62,7 +62,7 @@
6262
description['problem_params'] = pparams
6363
description['dtype_u'] = mesh
6464
description['dtype_f'] = rhs_imex_mesh
65-
description['collocation_class'] = collclass.CollGaussLobatto
65+
description['collocation_class'] = collclass.CollGaussLegendre
6666
description['sweeper_class'] = imex_1st_order
6767
description['level_params'] = lparams
6868
description['hook_class'] = plot_solution
@@ -127,6 +127,8 @@
127127
plt.yticks(fontsize=fs)
128128
plt.xticks(fontsize=fs)
129129
plt.show()
130-
fig.savefig('sdc_fwsw_iteration.pdf',bbox_inches='tight')
130+
filename = 'sdc_fwsw_iteration.pdf'
131+
fig.savefig(filename,bbox_inches='tight')
132+
call(["pdfcrop", filename, filename])
131133

132134

examples/acoustic_1d_imex/runmultiscale.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from matplotlib import pyplot as plt
1818
from pylab import rcParams
19+
from subprocess import call
1920

2021
fs = 8
2122

@@ -56,11 +57,9 @@
5657
description['problem_params'] = pparams
5758
description['dtype_u'] = mesh
5859
description['dtype_f'] = rhs_imex_mesh
59-
description['collocation_class'] = collclass.CollGaussRadau_Right
60-
if sparams['maxiter']==2:
61-
description['num_nodes'] = 2
62-
else:
63-
description['num_nodes'] = 3
60+
description['collocation_class'] = collclass.CollGaussLegendre
61+
# Number of nodes
62+
description['num_nodes'] = 3
6463
description['sweeper_class'] = imex_1st_order
6564
description['level_params'] = lparams
6665
description['hook_class'] = plot_solution
@@ -137,4 +136,7 @@
137136
plt.legend(loc='upper left', fontsize=fs, prop={'size':fs})
138137
fig.gca().grid()
139138
#plt.show()
140-
plt.gcf().savefig('fwsw-sdc-K'+str(sparams['maxiter'])+'-M'+str(description['num_nodes'])+'.pdf', bbox_inches='tight')
139+
filename = 'sdc-fwsw-multiscale-K'+str(sparams['maxiter'])+'-M'+str(description['num_nodes'])+'.pdf'
140+
plt.gcf().savefig(filename, bbox_inches='tight')
141+
call(["pdfcrop", filename, filename])
142+

examples/boussinesq_2d_imex/plotgmrescounter.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,34 @@
44
from matplotlib import cm
55
from matplotlib.ticker import LinearLocator, FormatStrFormatter
66
from pylab import rcParams
7+
from subprocess import call
78

89
from unflatten import unflatten
910

1011
if __name__ == "__main__":
1112
xx = np.load('xaxis.npy')
1213
uend = np.load('sdc.npy')
13-
udirk2 = np.load('dirk2.npy')
14-
udirk4 = np.load('dirk4.npy')
15-
utrap = np.load('trap.npy')
14+
udirk = np.load('dirk.npy')
15+
uref = np.load('uref.npy')
16+
17+
print "Estimated discretisation error of DIRK: %5.3e" % ( np.linalg.norm(udirk.flatten() - uref.flatten(), np.inf)/np.linalg.norm(uref.flatten(),np.inf) )
18+
print "Estimated discretisation error of SDC: %5.3e" % ( np.linalg.norm(uend.flatten() - uref.flatten(), np.inf)/np.linalg.norm(uref.flatten(),np.inf) )
1619

1720
fs = 8
1821
rcParams['figure.figsize'] = 5.0, 2.5
1922
fig = plt.figure()
2023

24+
plt.plot(xx[:,5], udirk[2,:,5], '--', color='r', markersize=fs-2, label='DIRK', dashes=(3,3))
2125
plt.plot(xx[:,5], uend[2,:,5], '-', color='b', label='SDC')
22-
plt.plot(xx[:,5], udirk4[2,:,5], '--', color='g', markersize=fs-2, label='DIRK(4)', dashes=(3,3))
23-
plt.plot(xx[:,5], udirk2[2,:,5], '--', color='r', markersize=fs-2, label='DIRK(2)', dashes=(3,3))
26+
#plt.plot(xx[:,5], udirk2[2,:,5], '--', color='r', markersize=fs-2, label='DIRK(2)', dashes=(3,3))
2427
#plt.plot(xx[:,5], utrap[2,:,5], '--', color='k', markersize=fs-2, label='Trap', dashes=(3,3))
2528
plt.legend(loc='lower left', fontsize=fs, prop={'size':fs})
2629
plt.yticks(fontsize=fs)
2730
plt.xticks(fontsize=fs)
2831
plt.xlabel('x [km]', fontsize=fs, labelpad=0)
2932
plt.ylabel('Bouyancy', fontsize=fs, labelpad=1)
3033
#plt.show()
31-
plt.savefig('boussinesq.pdf', bbox_inches='tight')
34+
filename = 'sdc-fwsw-boussinesq.pdf'
35+
plt.savefig(filename, bbox_inches='tight')
36+
call(["pdfcrop", filename, filename])
3237

examples/boussinesq_2d_imex/rungmrescounter.py

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
lparams['restol'] = 1E-15
3636

3737
swparams = {}
38-
swparams['collocation_class'] = collclass.CollGaussLobatto
38+
swparams['collocation_class'] = collclass.CollGaussLegendre
3939
swparams['num_nodes'] = 3
4040
swparams['do_LU'] = False
4141

@@ -96,54 +96,32 @@
9696
print ("CFL number of acoustics (horizontal): %4.2f" % cfl_acoustic_hor)
9797
print ("CFL number of acoustics (vertical): %4.2f" % cfl_acoustic_ver)
9898

99-
dirk4 = dirk(P, 4)
100-
dirk2 = dirk(P, 2)
101-
trap = trapezoidal(P)
102-
bdf = bdf2(P)
99+
dirkp = dirk(P, dirk_order)
103100
u0 = uinit.values.flatten()
104-
udirk4 = u0
105-
udirk2 = u0
106-
ubdf = u0
107-
utrap = u0
101+
udirk = u0
108102
for i in range(0,Nsteps):
109-
udirk4 = dirk4.timestep(udirk4, dt)
110-
udirk2 = dirk2.timestep(udirk2, dt)
111-
utrap = trap.timestep(utrap, dt)
112-
#if i==0:
113-
# ubdf_new = bdf.firsttimestep(ubdf, dt)
114-
# ubdf_m1 = ubdf
115-
#else:
116-
# ubdf_new = bdf.timestep(ubdf, ubdf_m1, dt)
117-
#ubdf_m1 = ubdf
118-
#ubdf = ubdf_new
103+
udirk = dirkp.timestep(udirk, dt)
104+
105+
dirkref = dirk(P, 4)
106+
uref = u0
107+
dt_ref = dt/10.0
108+
for i in range(0,10*Nsteps):
109+
uref = dirkref.timestep(uref, dt_ref)
119110

120111
# call main function to get things done...
121112
uend,stats = mp.run_pfasst(MS,u0=uinit,t0=t0,dt=dt,Tend=Tend)
122-
udirk4 = unflatten(udirk4, 4, P.N[0], P.N[1])
123-
udirk2 = unflatten(udirk2, 4, P.N[0], P.N[1])
124-
print "Norm of final solution by trapezoidal rule: %5.3f" % np.linalg.norm( utrap, np.inf )
125-
utrap = unflatten(utrap, 4, P.N[0], P.N[1])
126-
113+
udirk = unflatten(udirk, 4, P.N[0], P.N[1])
114+
uref = unflatten(uref, 4, P.N[0], P.N[1])
115+
127116
np.save('xaxis', P.xx)
128117
np.save('sdc', uend.values)
129-
np.save('dirk2', udirk2)
130-
np.save('dirk4', udirk4)
131-
np.save('trap', utrap)
118+
np.save('dirk', udirk)
119+
np.save('uref', uref)
132120

133-
print " #### Logging report for DIRK-4 #### "
134-
print "Number of calls to implicit solver: %5i" % dirk4.logger.solver_calls
135-
print "Total number of GMRES iterations: %5i" % dirk4.logger.iterations
136-
print "Average number of iterations per call: %6.3f" % (float(dirk4.logger.iterations)/float(dirk4.logger.solver_calls))
137-
138-
print " #### Logging report for DIRK-2 #### "
139-
print "Number of calls to implicit solver: %5i" % dirk2.logger.solver_calls
140-
print "Total number of GMRES iterations: %5i" % dirk2.logger.iterations
141-
print "Average number of iterations per call: %6.3f" % (float(dirk2.logger.iterations)/float(dirk2.logger.solver_calls))
142-
143-
#print " #### Logging report for BDF2 #### "
144-
#print "Number of calls to implicit solver: %5i" % bdf.logger.solver_calls
145-
#print "Total number of GMRES iterations: %5i" % bdf.logger.iterations
146-
#print "Average number of iterations per call: %6.3f" % (float(bdf.logger.iterations)/float(bdf.logger.solver_calls))
121+
print " #### Logging report for DIRK-%1i #### " % dirk_order
122+
print "Number of calls to implicit solver: %5i" % dirkp.logger.solver_calls
123+
print "Total number of GMRES iterations: %5i" % dirkp.logger.iterations
124+
print "Average number of iterations per call: %6.3f" % (float(dirkp.logger.iterations)/float(dirkp.logger.solver_calls))
147125

148126
print " #### Logging report for SDC-(%1i,%1i) #### " % (swparams['num_nodes'], sparams['maxiter'])
149127
print "Number of calls to implicit solver: %5i" % P.logger.solver_calls

examples/fwsw/plot_stifflimit_specrad.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
from matplotlib import pyplot as plt
1212
from pylab import rcParams
13+
from subprocess import call
1314

1415
if __name__ == "__main__":
1516

@@ -20,7 +21,7 @@
2021
pparams['lambda_f'] = np.array([50.0*1j], dtype='complex')
2122
pparams['u0'] = 1.0
2223
swparams = {}
23-
swparams['collocation_class'] = collclass.CollGaussLobatto
24+
swparams['collocation_class'] = collclass.CollGaussLegendre
2425

2526
nodes_v = np.arange(2,10)
2627
specrad = np.zeros((2,np.size(nodes_v)))
@@ -53,8 +54,10 @@
5354
# For Lobatto nodes, first column and row are all zeros, since q_1 = q_0; hence remove them
5455
QI = QI[1:,1:]
5556
Q = Q[1:,1:]
56-
# Eigenvalue of error propagation matrix in stiff limit: E = I - inv(QI)*Q
57-
evals, evecs = np.linalg.eig( np.eye(nnodes-1) - np.linalg.inv(QI).dot(Q) )
57+
# Eigenvalue of error propagation matrix in stiff limit: E = I - inv(QI)*Q
58+
evals, evecs = np.linalg.eig( np.eye(nnodes-1) - np.linalg.inv(QI).dot(Q) )
59+
else:
60+
evals, evecs = np.linalg.eig( np.eye(nnodes) - np.linalg.inv(QI).dot(Q) )
5861
specrad[0,i] = np.linalg.norm( evals, np.inf )
5962

6063
### Plot result
@@ -71,5 +74,8 @@
7174
plt.yticks(fontsize=fs)
7275
plt.xticks(fontsize=fs)
7376
#plt.show()
74-
fig.savefig('sdc_fwsw_stifflimit_specrad.pdf',bbox_inches='tight')
77+
filename = 'sdc_fwsw_stifflimit_specrad.pdf'
78+
fig.savefig(filename,bbox_inches='tight')
79+
call(["pdfcrop", filename, filename])
80+
7581

0 commit comments

Comments
 (0)