PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/software_tests/bedrough_test.cc

Go to the documentation of this file.
00001 // Copyright (C) 2010, 2011 Ed Bueler
00002 //
00003 // This file is part of PISM.
00004 //
00005 // PISM is free software; you can redistribute it and/or modify it under the
00006 // terms of the GNU General Public License as published by the Free Software
00007 // Foundation; either version 2 of the License, or (at your option) any later
00008 // version.
00009 //
00010 // PISM is distributed in the hope that it will be useful, but WITHOUT ANY
00011 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00012 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
00013 // details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with PISM; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 static char help[] =
00020   "\nBEDROUGH_TEST\n"
00021   "  Simple testing program for Schoof (2003)-type bed smoothing and roughness-\n"
00022   "  parameterization schemes.  Allows comparison of computed theta to result\n"
00023   "  from Matlab/Octave code exampletheta.m in src/base/bedroughplay.  Also\n"
00024   "  used in PISM software (regression) test.\n\n";
00025 
00026 #include <cmath>
00027 #include <cstdio>
00028 #include <petscvec.h>
00029 #include <petscda.h>
00030 #include "pism_const.hh"
00031 #include "grid.hh"
00032 #include "iceModelVec.hh"
00033 #include "NCVariable.hh"
00034 #include "PISMBedSmoother.hh"
00035 
00036 int main(int argc, char *argv[]) {
00037   PetscErrorCode  ierr;
00038 
00039   MPI_Comm    com;  // won't be used except for rank,size
00040   PetscMPIInt rank, size;
00041 
00042   ierr = PetscInitialize(&argc, &argv, PETSC_NULL, help); CHKERRQ(ierr);
00043 
00044   com = PETSC_COMM_WORLD;
00045   ierr = MPI_Comm_rank(com, &rank); CHKERRQ(ierr);
00046   ierr = MPI_Comm_size(com, &size); CHKERRQ(ierr);
00047   
00048   /* This explicit scoping forces destructors to be called before PetscFinalize() */
00049   {  
00050     NCConfigVariable config, overrides;
00051     ierr = init_config(com, rank, config, overrides); CHKERRQ(ierr);
00052 
00053     IceGrid grid(com, rank, size, config);
00054     grid.Mx = 81;
00055     grid.My = 81;
00056     grid.Lx = 1200e3;
00057     grid.Ly = grid.Lx;
00058     grid.compute_nprocs();
00059     grid.compute_ownership_ranges();
00060     ierr = grid.compute_horizontal_spacing(); CHKERRQ(ierr);
00061     ierr = grid.createDA(); CHKERRQ(ierr);
00062 
00063     PetscPrintf(grid.com,"PISMBedSmoother TEST\n");
00064 
00065     bool show;
00066     ierr = PISMOptionsIsSet("-show", show); CHKERRQ(ierr);
00067 
00068     IceModelVec2S topg, usurf, theta;
00069     ierr = topg.create(grid, "topg", true, 1); CHKERRQ(ierr);
00070     ierr = topg.set_attrs(
00071       "trybedrough_tool", "original topography",
00072       "m", "bedrock_altitude"); CHKERRQ(ierr);
00073     ierr = usurf.create(grid, "usurf", true, 1); CHKERRQ(ierr);
00074     ierr = usurf.set_attrs(
00075       "trybedrough_tool", "ice surface elevation",
00076       "m", "surface_altitude"); CHKERRQ(ierr);
00077     ierr = theta.create(grid, "theta", true, 1); CHKERRQ(ierr);
00078     ierr = theta.set_attrs(
00079       "trybedrough_tool",
00080       "coefficient theta in Schoof (2003) bed roughness parameterization",
00081       "", ""); CHKERRQ(ierr);
00082 
00083     // put in bed elevations, a la this Matlab:
00084     //    topg0 = 400 * sin(2 * pi * xx / 600e3) + ...
00085     //            100 * sin(2 * pi * (xx + 1.5 * yy) / 40e3);
00086     ierr = topg.begin_access(); CHKERRQ(ierr);
00087     for (PetscInt i=grid.xs; i<grid.xs+grid.xm; ++i) {
00088       for (PetscInt j=grid.ys; j<grid.ys+grid.ym; ++j) {
00089         topg(i,j) = 400.0 * sin(2.0 * pi * grid.x[i] / 600.0e3) +
00090                     100.0 * sin(2.0 * pi * (grid.x[i] + 1.5 * grid.y[j]) / 40.0e3);
00091       }
00092     }
00093     ierr = topg.end_access(); CHKERRQ(ierr);
00094 
00095     ierr = usurf.set(1000.0); CHKERRQ(ierr);  // compute theta for this constant thk
00096 
00097     // actually use the smoother/bed-roughness-parameterizer
00098     PISMBedSmoother smoother(grid, config, 1);
00099     const PetscReal n = 3.0, 
00100                     lambda = 50.0e3;
00101     ierr = smoother.preprocess_bed(topg, n, lambda); CHKERRQ(ierr);
00102     PetscInt Nx,Ny;
00103     ierr = smoother.get_smoothing_domain(Nx,Ny); CHKERRQ(ierr);
00104     PetscPrintf(grid.com,"  smoothing domain:  Nx = %d, Ny = %d\n",Nx,Ny);
00105     ierr = smoother.get_theta(usurf, n, 1, &theta); CHKERRQ(ierr);
00106 
00107     if (show) {
00108       const PetscInt  window = 400;
00109       ierr = topg.view(window);  CHKERRQ(ierr);
00110       ierr = smoother.topgsmooth.view(window);  CHKERRQ(ierr);
00111       ierr = theta.view(window);  CHKERRQ(ierr);
00112       printf("[showing topg, smoother.topgsmooth, theta in X windows for 10 seconds ...]\n");
00113       ierr = PetscSleep(10); CHKERRQ(ierr);
00114     }
00115 
00116     PetscReal topg_min, topg_max, topgs_min, topgs_max, theta_min, theta_max;
00117     ierr = topg.min(topg_min); CHKERRQ(ierr);
00118     ierr = topg.max(topg_max); CHKERRQ(ierr);
00119     ierr = smoother.topgsmooth.min(topgs_min); CHKERRQ(ierr);
00120     ierr = smoother.topgsmooth.max(topgs_max); CHKERRQ(ierr);
00121     ierr = theta.min(theta_min); CHKERRQ(ierr);
00122     ierr = theta.max(theta_max); CHKERRQ(ierr);
00123     PetscPrintf(grid.com,
00124            "  original bed    :  min elev = %12.6f m,  max elev = %12.6f m\n",
00125            topg_min, topg_max);
00126     PetscPrintf(grid.com,
00127            "  smoothed bed    :  min elev = %12.6f m,  max elev = %12.6f m\n",
00128            topgs_min, topgs_max);
00129     PetscPrintf(grid.com,
00130            "  Schoof's theta  :  min      = %12.9f,    max      = %12.9f\n",
00131            theta_min, theta_max);
00132 
00133   }
00134   ierr = PetscFinalize(); CHKERRQ(ierr);
00135   return 0;
00136 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines