URI: 
       tpisms.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
  HTML git clone git://src.adamsgaard.dk/pism
   DIR Log
   DIR Files
   DIR Refs
   DIR LICENSE
       ---
       tpisms.cc (4676B)
       ---
            1 // Copyright (C) 2004-2019 Jed Brown, Ed Bueler and Constantine Khroulev
            2 //
            3 // This file is part of Pism.
            4 //
            5 // Pism is free software; you can redistribute it and/or modify it under the
            6 // terms of the GNU General Public License as published by the Free Software
            7 // Foundation; either version 3 of the License, or (at your option) any later
            8 // version.
            9 //
           10 // Pism is distributed in the hope that it will be useful, but WITHOUT ANY
           11 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
           12 // FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
           13 // details.
           14 //
           15 // You should have received a copy of the GNU General Public License
           16 // along with Pism; if not, write to the Free Software
           17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
           18 
           19 static char help[] =
           20   "Ice sheet driver for EISMINT II, and other constant climate, simplified geometry\n"
           21   "intercomparison simulations.\n";
           22 
           23 #include <petscsys.h>
           24 
           25 #include "pism/icemodel/IceModel.hh"
           26 #include "pism/util/IceGrid.hh"
           27 #include "pism/util/Config.hh"
           28 #include "pism/util/error_handling.hh"
           29 #include "pism/util/petscwrappers/PetscInitializer.hh"
           30 #include "pism/util/pism_options.hh"
           31 #include "pism/icemodel/IceEISModel.hh"
           32 #include "pism/util/Context.hh"
           33 #include "pism/util/Logger.hh"
           34 #include "pism/util/Time.hh"
           35 #include "pism/util/EnthalpyConverter.hh"
           36 #include "pism/util/io/File.hh"
           37 
           38 using namespace pism;
           39 
           40 Context::Ptr pisms_context(MPI_Comm com) {
           41   // unit system
           42   units::System::Ptr sys(new units::System);
           43 
           44   // logger
           45   Logger::Ptr logger = logger_from_options(com);
           46 
           47   // configuration parameters
           48   Config::Ptr config = config_from_options(com, *logger, sys);
           49 
           50   config->set_string("time.calendar", "none");
           51   config->set_number("grid.Lx", 750e3);
           52   config->set_number("grid.Ly", 750e3);
           53   config->set_string("grid.periodicity", "none");
           54   config->set_string("grid.registration", "corner");
           55   config->set_string("stress_balance.sia.flow_law", "pb");
           56 
           57   set_config_from_options(*config);
           58 
           59   print_config(*logger, 3, *config);
           60 
           61   Time::Ptr time = time_from_options(com, config, sys);
           62 
           63   EnthalpyConverter::Ptr EC(new EnthalpyConverter(*config));
           64 
           65   return Context::Ptr(new Context(com, sys, config, EC, time, logger, "pisms"));
           66 }
           67 
           68 IceGrid::Ptr pisms_grid(Context::Ptr ctx) {
           69   auto config = ctx->config();
           70 
           71   auto input_file = config->get_string("input.file");
           72 
           73   if (config->get_flag("input.bootstrap")) {
           74     throw RuntimeError(PISM_ERROR_LOCATION, "pisms does not support bootstrapping");
           75   }
           76 
           77   if (not input_file.empty()) {
           78     GridRegistration r = string_to_registration(ctx->config()->get_string("grid.registration"));
           79 
           80     // get grid from a PISM input file
           81     return IceGrid::FromFile(ctx, input_file, {"enthalpy", "temp"}, r);
           82   } else {
           83     // use defaults from the configuration database
           84     GridParameters P(ctx->config());
           85     P.horizontal_size_from_options();
           86     P.horizontal_extent_from_options();
           87     P.vertical_grid_from_options(ctx->config());
           88     P.ownership_ranges_from_options(ctx->size());
           89 
           90     return IceGrid::Ptr(new IceGrid(ctx, P));
           91   }
           92 }
           93 
           94 
           95 int main(int argc, char *argv[]) {
           96 
           97   MPI_Comm com = MPI_COMM_WORLD;
           98   petsc::Initializer petsc(argc, argv, help);
           99 
          100   com = PETSC_COMM_WORLD;
          101 
          102   try {
          103     Context::Ptr ctx = pisms_context(com);
          104     Logger::Ptr log = ctx->log();
          105 
          106     std::string usage =
          107       "  pisms [-eisII x] [OTHER PISM & PETSc OPTIONS]\n"
          108       "where major option chooses type of simplified experiment:\n"
          109       "  -eisII x    choose EISMINT II experiment (x = A|B|C|D|E|F|G|H|I|J|K|L)\n";
          110 
          111     bool done = show_usage_check_req_opts(*log, "PISMS (simplified geometry mode)",
          112                                           std::vector<std::string>(), // no required options
          113                                           usage);
          114     if (done) {
          115       return 0;
          116     }
          117 
          118     std::string experiment = options::Keyword("-eisII", "EISMINT II experiment name",
          119                                               "A,B,C,D,E,F,G,H,I,J,K,L", "A");
          120 
          121     // Stop if -eisII G or -eisII H was given.
          122     if (experiment == "G" or experiment == "H") {
          123       throw RuntimeError::formatted(PISM_ERROR_LOCATION, "EISMINT II experiment %s is not supported.",
          124                                     experiment.c_str());
          125     }
          126 
          127     Config::Ptr config = ctx->config();
          128 
          129     IceGrid::Ptr g = pisms_grid(ctx);
          130     IceEISModel m(g, ctx, experiment[0]);
          131 
          132     m.init();
          133 
          134     m.run();
          135 
          136     log->message(2, "... done with run \n");
          137 
          138     // provide a default output file name if no -o option is given.
          139     m.save_results();
          140 
          141     print_unused_parameters(*log, 3, *config);
          142   }
          143   catch (...) {
          144     handle_fatal_errors(com);
          145     return 1;
          146   }
          147 
          148   return 0;
          149 }