PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
pismr.cc
Go to the documentation of this file.
1 // Copyright (C) 2004--2023 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 PISM ice sheet simulations, initialized from data.\n"
21  "The basic PISM executable for evolution runs.\n";
22 
23 #include <memory>
24 #include <petscsys.h> // PETSC_COMM_WORLD
25 
26 #include "pism/icemodel/IceModel.hh"
27 #include "pism/icemodel/IceEISModel.hh"
28 #include "pism/util/Config.hh"
29 #include "pism/util/Grid.hh"
30 
31 #include "pism/util/Context.hh"
32 #include "pism/util/Profiling.hh"
33 #include "pism/util/error_handling.hh"
34 #include "pism/util/petscwrappers/PetscInitializer.hh"
35 #include "pism/util/pism_options.hh"
36 
37 #include "pism/regional/Grid_Regional.hh"
38 #include "pism/regional/IceRegionalModel.hh"
39 
40 using namespace pism;
41 
42 static void set_eismint2_config_defaults(Config &config) {
43  config.set_number("grid.Lx", 750e3);
44  config.set_number("grid.Ly", 750e3);
45  config.set_string("grid.periodicity", "none");
46  config.set_string("grid.registration", "corner");
47  config.set_string("stress_balance.sia.flow_law", "pb");
48 
49  config.set_flag("energy.temperature_based", true);
50 
51  // Set sea level elevation to -1e4 meters to remove ocean interaction
52  config.set_number("sea_level.constant.value", -1e4);
53 
54  // purely SIA, and E=1
55  config.set_number("stress_balance.sia.enhancement_factor", 1.0);
56 
57  // none use bed smoothing & bed roughness parameterization
58  config.set_number("stress_balance.sia.bed_smoother.range", 0.0);
59 
60  // basal melt does not change computation of mass continuity or vertical velocity:
61  config.set_flag("geometry.update.use_basal_melt_rate", false);
62 
63  // Make bedrock thermal material properties into ice properties. Note that
64  // zero thickness bedrock layer is the default, but we want the ice/rock
65  // interface segment to have geothermal flux applied directly to ice without
66  // jump in material properties at base.
67  config.set_number("energy.bedrock_thermal.density",
68  config.get_number("constants.ice.density"));
69  config.set_number("energy.bedrock_thermal.conductivity",
70  config.get_number("constants.ice.thermal_conductivity"));
71  config.set_number("energy.bedrock_thermal.specific_heat_capacity",
72  config.get_number("constants.ice.specific_heat_capacity"));
73 
74  // no sliding + SIA
75  config.set_string("stress_balance.model", "sia");
76 }
77 
78 int main(int argc, char *argv[]) {
79 
80  MPI_Comm com = MPI_COMM_WORLD;
81  petsc::Initializer petsc(argc, argv, help);
82 
83  com = PETSC_COMM_WORLD;
84 
85  int exit_code = 0;
86  try {
87  // Note: EISMINT II experiments G and H are not supported.
88  auto eisII = options::Keyword("-eisII",
89  "EISMINT II experiment name",
90  "A,B,C,D,E,F,I,J,K,L", "A");
91 
92  std::shared_ptr<Context> ctx = context_from_options(com, "pismr", false);
93 
94  Logger::Ptr log = ctx->log();
95  Config::Ptr config = ctx->config();
96 
97  std::vector<std::string> required_options{};
98  if (eisII.is_set()) {
99  // set defaults:
101 
102  // process -config_override
103  DefaultConfig::Ptr overrides(new DefaultConfig(com,
104  "pism_overrides",
105  "-config_override",
106  ctx->unit_system()));
107  overrides->init(*ctx->log());
108  config->import_from(*overrides);
109  // process command-line options
110  set_config_from_options(ctx->unit_system(), *config);
111  config->resolve_filenames();
112  } else {
113  required_options.emplace_back("-i");
114  }
115 
116  print_config(*ctx->log(), 3, *config);
117 
118  std::string usage =
119  " pismr -i IN.nc [-bootstrap] [-regional] [OTHER PISM & PETSc OPTIONS]\n"
120  "where:\n"
121  " -i IN.nc is input file in NetCDF format: contains PISM-written model state\n"
122  " -bootstrap enable heuristics to produce an initial state from an incomplete input\n"
123  " -regional enable \"regional mode\"\n"
124  " -eisII [experiment] enable EISMINT II mode\n"
125  "notes:\n"
126  " * option -i is required\n"
127  " * if -bootstrap is used then also '-Mx A -My B -Mz C -Lz D' are required\n";
128  {
129  bool done = show_usage_check_req_opts(*log, "PISMR (basic evolution run mode)" ,
130  required_options, usage);
131  if (done) {
132  return 0;
133  }
134  }
135 
136  options::String profiling_log = options::String("-profile",
137  "Save detailed profiling data to a file.");
138 
139  if (profiling_log.is_set()) {
140  ctx->profiling().start();
141  }
142 
143  std::shared_ptr<Grid> grid;
144  std::unique_ptr<IceModel> model;
145 
146  if (options::Bool("-regional", "enable regional (outlet glacier) mode")) {
147  grid = regional_grid_from_options(ctx);
148  model.reset(new IceRegionalModel(grid, ctx));
149  } else {
150  grid = Grid::FromOptions(ctx);
151 
152  if (eisII.is_set()) {
153  char experiment = eisII.value()[0];
154  model.reset(new IceEISModel(grid, ctx, experiment));
155  } else {
156  model.reset(new IceModel(grid, ctx));
157  }
158  }
159 
160  model->init();
161 
162  auto list_type = options::Keyword("-list_diagnostics",
163  "List available diagnostic quantities and stop.",
164  "all,spatial,scalar,json",
165  "all");
166 
167  if (list_type.is_set()) {
168  model->list_diagnostics(list_type);
169  } else {
170  auto termination_reason = model->run();
171 
172  switch (termination_reason) {
173  case PISM_CHEKPOINT:
174  {
175  exit_code = static_cast<int>(config->get_number("output.checkpoint.exit_code"));
176  log->message(2, "... stopping (exit_code=%d) after saving the checkpoint file\n",
177  exit_code);
178  break;
179  }
180  case PISM_SIGNAL:
181  {
182  exit_code = 0;
183  break;
184  }
185  case PISM_DONE:
186  {
187  log->message(2, "... done with the run\n");
188  model->save_results();
189  exit_code = 0;
190  break;
191  }
192  }
193  }
194  print_unused_parameters(*log, 3, *config);
195 
196  if (profiling_log.is_set()) {
197  ctx->profiling().report(profiling_log);
198  }
199  }
200  catch (...) {
201  handle_fatal_errors(com);
202  exit_code = 1;
203  }
204 
205  return exit_code;
206 }
std::shared_ptr< Config > Ptr
void set_string(const std::string &name, const std::string &value, ConfigSettingFlag flag=CONFIG_FORCE)
double get_number(const std::string &name, UseFlag flag=REMEMBER_THIS_USE) const
void set_flag(const std::string &name, bool value, ConfigSettingFlag flag=CONFIG_FORCE)
void set_number(const std::string &name, double value, ConfigSettingFlag flag=CONFIG_FORCE)
A class for storing and accessing PISM configuration flags and parameters.
std::shared_ptr< DefaultConfig > Ptr
Definition: Config.hh:80
Default PISM configuration database: uses NetCDF files; can be initialized from a file specified usin...
Definition: Config.hh:72
static std::shared_ptr< Grid > FromOptions(std::shared_ptr< const Context > ctx)
Create a grid using command-line options and (possibly) an input file.
Definition: Grid.cc:1263
Derived class for doing EISMINT II simplified geometry experiments.
Definition: IceEISModel.hh:31
A version of the PISM core class (IceModel) which knows about the no_model_mask and its semantics.
std::shared_ptr< Logger > Ptr
Definition: Logger.hh:45
bool is_set() const
Definition: options.hh:35
bool Bool(const std::string &option, const std::string &description)
Definition: options.cc:240
std::shared_ptr< Grid > regional_grid_from_options(std::shared_ptr< Context > ctx)
Create a grid using command-line options and (possibly) an input file.
std::shared_ptr< Context > context_from_options(MPI_Comm com, const std::string &prefix, bool print)
Create a default context using options.
Definition: Context.cc:170
@ PISM_SIGNAL
Definition: IceModel.hh:114
@ PISM_DONE
Definition: IceModel.hh:114
@ PISM_CHEKPOINT
Definition: IceModel.hh:114
void handle_fatal_errors(MPI_Comm com)
void set_config_from_options(units::System::Ptr unit_system, Config &config)
Set configuration parameters using command-line options.
bool show_usage_check_req_opts(const Logger &log, const std::string &execname, const std::vector< std::string > &required_options, const std::string &usage)
In a single call a driver program can provide a usage string to the user and check if required option...
Definition: pism_options.cc:51
void print_unused_parameters(const Logger &log, int verbosity_threshhold, const Config &config)
Report unused configuration parameters to stdout.
void print_config(const Logger &log, int verbosity_threshhold, const Config &config)
Report configuration parameters to stdout.
int main(int argc, char *argv[])
Definition: pismr.cc:78
static char help[]
Definition: pismr.cc:19
static void set_eismint2_config_defaults(Config &config)
Definition: pismr.cc:42