PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/verif/tests/exactV.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 # Computes and plots exact solution for "test V", in preparation for
00004 # implementing C version for PISM verification.
00005 
00006 from pylab import *
00007 from os import system
00008 
00009 try:
00010     from netCDF4 import Dataset as NC
00011 except:
00012     from netCDF3 import Dataset as NC
00013 
00014 def permute(variable, output_order = ('t', 'z', 'zb', 'y', 'x')):
00015     """Permute dimensions of a NetCDF variable to match the output storage order."""
00016     input_dimensions = variable.dimensions
00017 
00018     # filter out irrelevant dimensions
00019     dimensions = filter(lambda(x): x in input_dimensions,
00020                         output_order)
00021 
00022     # create the mapping
00023     mapping = map(lambda(x): dimensions.index(x),
00024                   input_dimensions)
00025 
00026     if mapping:
00027         return np.transpose(variable[:], mapping)
00028     else:
00029         return variable[:]              # so that it does not break processing "mapping"
00030 
00031 ### Setup
00032 
00033 secpera = 3.15569259747e7               # seconds per year
00034 rho_sw = 1028.0                         # sea water density
00035 rho_ice = 910.0                         # ice density
00036 standard_gravity = 9.81                 # g
00037 B0 = 1.9e8                              # ice hardness
00038 
00039 # "typical constant ice parameter" as defined in the paper and in Van der
00040 # Veen's "Fundamentals of Glacier Dynamics", 1999
00041 C = (rho_ice * standard_gravity * (1.0 - rho_ice/rho_sw) / (4 * B0))**3
00042 
00043 # upstream ice thickness
00044 H0 = 600.0                              # meters
00045 # upstream ice velocity
00046 v0 = 300.0/secpera                      # 300 meters/year
00047 # upstream ice flux
00048 Q0 = H0 * v0;
00049 
00050 Mx = 201
00051 x = linspace(0, 400e3, Mx)
00052 
00053 def H(x):
00054     """Ice thickness."""    
00055     return (4 * C / Q0 * x + 1 / H0**4)**(-0.25)
00056 
00057 def v(x):
00058     """Ice velocity."""    
00059     return Q0 / H(x)
00060 
00061 def x_c(t):
00062     """Location of the calving front."""
00063     return Q0 / (4*C) * ((3*C*t + 1/H0**3)**(4.0/3.0) - 1/H0**4)
00064 
00065 def plot_xc(t_years):
00066     """Plot the location of the calving front."""
00067     x = x_c(t_years * secpera)/1000.0   # convert to km
00068     a = axis()
00069     y_min = a[2]
00070     y_max = a[3]
00071 
00072     hold(True)
00073     plot([x, x], [y_min, y_max], '--g')
00074 
00075 def run_pismv(Mx, run_length, options, output):
00076     system("pismv -test V -y %f -Mx %d %s -o %s" % (run_length, Mx, options, output))
00077 
00078 def plot_pism_results(figure_number, filename, figure_title, color):
00079     nc = NC(filename)
00080 
00081     time = nc.variables['t'][0]
00082 
00083     thk = permute(nc.variables['thk'])[0,1,2:]
00084     ubar_ssa = permute(nc.variables['cbar'])[0,1,2:]
00085     x = nc.variables['x'][:]
00086     dx = x[1] - x[0]
00087     Lx = (x[-1] - x[0]) / 2.0
00088     x_nc = (x[2:] + Lx - 2*dx) / 1000.0
00089 
00090     hold(True)
00091 
00092     figure(figure_number)
00093 
00094     subplot(211)
00095     title(figure_title)
00096     plot(x_nc, H(x_nc*1000.0), color='black', linestyle='dashed')
00097     plot(x_nc, thk, color=color)
00098     plot_xc(time)
00099     ylabel("Ice thickness, m")
00100     axis(xmin=0, xmax=400, ymax=600)
00101     grid(True)
00102 
00103     subplot(212)
00104     plot(x_nc, v(x_nc*1000.0) * secpera, color='black', linestyle='dashed')
00105     plot(x_nc, ubar_ssa, color=color)
00106     plot_xc(time)
00107     axis(xmin=0, xmax=400, ymax=1000)
00108     xlabel("km")
00109     ylabel("ice velocity, m/year")
00110     grid(True)
00111 
00112     nc.close()
00113 
00114 options = "-ssa_method fd -cfbc -part_grid -Lx 250"
00115 
00116 run_pismv(101, 300, options, "out.nc")
00117 plot_pism_results(1, "out.nc", "Figure 6 (b)", 'blue')
00118 
00119 run_pismv(101, 300, options + " -max_dt 1", "out.nc")
00120 plot_pism_results(1, "out.nc", "Figure 6 (b)", 'green')
00121 
00122 run_pismv(101, 300, options + " -part_redist", "out.nc")
00123 plot_pism_results(2, "out.nc", "Figure 6 (c)", 'blue')
00124 
00125 run_pismv(101, 300, options + " -part_redist -max_dt 1", "out.nc")
00126 plot_pism_results(2, "out.nc", "Figure 6 (c)", 'green')
00127 
00128 show()
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines