PISM, A Parallel Ice Sheet Model stable 0.4.1779

src/pismr.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 ice sheet simulations, initialized from data.\n"
00021   "The basic PISM executable for evolution runs.\n";
00022 
00023 #include <petsc.h>
00024 #include "grid.hh"
00025 #include "iceModel.hh"
00026 
00027 #include "coupler/PCFactory.hh"
00028 #include "coupler/PISMAtmosphere.hh"
00029 #include "coupler/PISMSurface.hh"
00030 #include "coupler/PISMOcean.hh"
00031 
00032 int main(int argc, char *argv[]) {
00033   PetscErrorCode  ierr;
00034 
00035   MPI_Comm    com;
00036   PetscMPIInt rank, size;
00037 
00038   ierr = PetscInitialize(&argc, &argv, PETSC_NULL, help); CHKERRQ(ierr);
00039 
00040   com = PETSC_COMM_WORLD;
00041   ierr = MPI_Comm_rank(com, &rank); CHKERRQ(ierr);
00042   ierr = MPI_Comm_size(com, &size); CHKERRQ(ierr);
00043 
00044   /* This explicit scoping forces destructors to be called before PetscFinalize() */
00045   {
00046     ierr = verbosityLevelFromOptions(); CHKERRQ(ierr);
00047 
00048     ierr = verbPrintf(2,com, "PISMR %s (basic evolution run mode)\n",
00049                       PISM_Revision); CHKERRQ(ierr);
00050     ierr = stop_on_version_option(); CHKERRQ(ierr);
00051 
00052     ierr = check_old_option_and_stop(com, "-boot_from", "-boot_file"); CHKERRQ(ierr); 
00053 
00054     bool iset, bfset;
00055     ierr = PISMOptionsIsSet("-i", iset); CHKERRQ(ierr);
00056     ierr = PISMOptionsIsSet("-boot_file", bfset); CHKERRQ(ierr);
00057     string usage =
00058       "  pismr {-i IN.nc|-boot_file IN.nc} [OTHER PISM & PETSc OPTIONS]\n"
00059       "where:\n"
00060       "  -i          IN.nc is input file in NetCDF format: contains PISM-written model state\n"
00061       "  -boot_file  IN.nc is input file in NetCDF format: contains a few fields, from which\n"
00062       "              heuristics will build initial model state\n"
00063       "notes:\n"
00064       "  * one of -i or -boot_file is required\n"
00065       "  * if -boot_file is used then also '-Mx A -My B -Mz C -Lz D' are required\n";
00066     if ((iset == PETSC_FALSE) && (bfset == PETSC_FALSE)) {
00067       ierr = PetscPrintf(com,
00068          "\nPISM ERROR: one of options -i,-boot_file is required\n\n"); CHKERRQ(ierr);
00069       ierr = show_usage_and_quit(com, "pismr", usage.c_str()); CHKERRQ(ierr);
00070     } else {
00071       vector<string> required;  required.clear();
00072       ierr = show_usage_check_req_opts(com, "pismr", required, usage.c_str()); CHKERRQ(ierr);
00073     }
00074 
00075     NCConfigVariable config, overrides;
00076     ierr = init_config(com, rank, config, overrides); CHKERRQ(ierr);
00077 
00078     IceGrid g(com, rank, size, config);
00079     IceModel m(g, config, overrides);
00080 
00081     // Initialize boundary models:
00082     PAFactory pa(g, config);
00083     PISMAtmosphereModel *atmosphere;
00084 
00085     PSFactory ps(g, config);
00086     PISMSurfaceModel *surface;
00087 
00088     POFactory po(g, config);
00089     PISMOceanModel *ocean;
00090 
00091     ierr = PetscOptionsBegin(com, "", "Options choosing PISM boundary models", ""); CHKERRQ(ierr);
00092     pa.create(atmosphere);
00093     ps.create(surface);
00094     po.create(ocean);
00095     ierr = PetscOptionsEnd(); CHKERRQ(ierr);
00096 
00097     surface->attach_atmosphere_model(atmosphere);
00098 
00099     m.attach_ocean_model(ocean);
00100     m.attach_surface_model(surface);
00101     ierr = m.setExecName("pismr"); CHKERRQ(ierr);
00102 
00103     ierr = m.init(); CHKERRQ(ierr);
00104 
00105     ierr = m.run(); CHKERRQ(ierr);
00106 
00107     ierr = verbPrintf(2,com, "... done with run\n"); CHKERRQ(ierr);
00108     // provide a default output file name if no -o option is given.
00109     ierr = m.writeFiles("unnamed.nc"); CHKERRQ(ierr);
00110   }
00111 
00112   ierr = PetscFinalize(); CHKERRQ(ierr);
00113   return 0;
00114 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines