PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/pismv.cc

Go to the documentation of this file.
00001 // Copyright (C) 2004-2011 Jed Brown, Ed Bueler and Constantine Khroulev
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 "Ice sheet driver for PISM (SIA and SSA) verification.  Uses exact solutions\n"
00021 "  to various coupled subsystems.  Computes difference between exact solution\n"
00022 "  and numerical solution.  Can also just compute exact solution (-eo).\n"
00023 "  Currently implements tests A, B, C, D, E, F, G, H, I, J, K, L\n\n";
00024 
00025 #include <cctype>               // toupper
00026 #include <string>
00027 #include <algorithm>            // std::transform()
00028 #include <petscda.h>
00029 #include "grid.hh"
00030 #include "verif/iceCompModel.hh"
00031 
00032 #include "coupler/PISMSurface.hh"
00033 #include "coupler/PISMOcean.hh"
00034 
00035 // a wrapper that seems to be necessary to make std::transform below work
00036 static inline char pism_toupper(char c)
00037 {
00038     return (char)std::toupper(c);
00039 }
00040 
00041 int main(int argc, char *argv[]) {
00042   PetscErrorCode  ierr;
00043   MPI_Comm        com;
00044   PetscMPIInt     rank, size;
00045 
00046   PetscInitialize(&argc, &argv, PETSC_NULL, help);
00047 
00048   com = PETSC_COMM_WORLD;
00049   ierr = MPI_Comm_rank(com, &rank); CHKERRQ(ierr);
00050   ierr = MPI_Comm_size(com, &size); CHKERRQ(ierr);
00051       
00052   /* This explicit scoping forces destructors to be called before PetscFinalize() */
00053   {
00054     ierr = verbosityLevelFromOptions(); CHKERRQ(ierr);
00055 
00056     ierr = verbPrintf(2, com, "PISMV %s (verification mode)\n",
00057                       PISM_Revision); CHKERRQ(ierr);
00058     ierr = stop_on_version_option(); CHKERRQ(ierr);
00059 
00060     vector<string> required;
00061     required.push_back("-test");
00062     ierr = show_usage_check_req_opts(com, "pismv", required,
00063                                      "  pismv -test x [-no_report] [-eo] [OTHER PISM & PETSc OPTIONS]\n"
00064                                      "where:\n"
00065                                      "  -test x     verification test (x = A|B|...|L)\n"
00066                                      "  -no_report  do not give error report at end of run\n"
00067                                      "  -eo         do not do numerical run; exact solution only\n"
00068                                      ); CHKERRQ(ierr);
00069 
00070     NCConfigVariable config, overrides;
00071     ierr = init_config(com, rank, config, overrides); CHKERRQ(ierr);
00072 
00073     config.set_flag("use_eta_transformation", false);
00074     config.set_flag("verification_mode",      true);
00075 
00076     IceGrid      g(com, rank, size, config);
00077 
00078     // Initialize boundary models:
00079     PISMSurfaceModel *surface = new PSDummy(g, config);
00080     PISMOceanModel     *ocean = new POConstant(g, config);
00081 
00082     // determine test (and whether to report error)
00083     string testname = "A";
00084     bool   dontReport, test_chosen;
00085     ierr = PetscOptionsBegin(g.com, "", "Options specific to PISMV", ""); CHKERRQ(ierr);
00086     {
00087       ierr = PISMOptionsString("-test", "Specifies PISM verification test",
00088                                testname, test_chosen); CHKERRQ(ierr);
00089       ierr = PISMOptionsIsSet("-no_report", "Don't report numerical errors",
00090                               dontReport); CHKERRQ(ierr);
00091     }
00092     ierr = PetscOptionsEnd(); CHKERRQ(ierr);
00093 
00094     // transform to uppercase:
00095     transform(testname.begin(), testname.end(), testname.begin(), pism_toupper);
00096 
00097     // actually construct and run one of the derived classes of IceModel
00098     // run derived class for compensatory source SIA solutions
00099     // (i.e. compensatory accumulation or compensatory heating)
00100     IceCompModel mComp(g, config, overrides, testname[0]);
00101     ierr = mComp.setExecName("pismv"); CHKERRQ(ierr);
00102     mComp.attach_surface_model(surface);
00103     mComp.attach_ocean_model(ocean);
00104 
00105     ierr = mComp.init(); CHKERRQ(ierr);
00106 
00107     ierr = mComp.run(); CHKERRQ(ierr);
00108     ierr = verbPrintf(2,com, "done with run\n"); CHKERRQ(ierr);
00109 
00110     ThermoGlenArrIce* tgaice = dynamic_cast<ThermoGlenArrIce*>(mComp.getIceFlowLaw());
00111     if (dontReport == PETSC_FALSE) {
00112 
00113       if (testname != "V" && !IceFlowLawIsPatersonBuddCold(tgaice, config) &&
00114           ((testname == "F") || (testname == "G"))) {
00115         ierr = verbPrintf(1,com, 
00116                           "pismv WARNING: flow law must be cold part of Paterson-Budd ('-ice_type arr')\n"
00117                           "   for reported errors in test %c to be meaningful!\n",
00118                           testname.c_str()); CHKERRQ(ierr);
00119       }
00120       ierr = mComp.reportErrors();  CHKERRQ(ierr);
00121     }
00122     ierr = mComp.writeFiles("verify.nc"); CHKERRQ(ierr);
00123     
00124   }
00125 
00126   ierr = PetscFinalize(); CHKERRQ(ierr);
00127 
00128   return 0;
00129 }
00130 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines