Skip to content

Commit 4c90354

Browse files
author
Daniel Ruprecht
committed
changed run routines to legendre nodes; automatically cropping generated pdfs
1 parent c0c0434 commit 4c90354

File tree

3 files changed

+35
-50
lines changed

3 files changed

+35
-50
lines changed

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/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

0 commit comments

Comments
 (0)