21 "Ice sheet driver for PISM ice sheet simulations, initialized from data.\n"
22 "The basic PISM executable for evolution runs.\n";
27#include "pism/icemodel/IceModel.hh"
28#include "pism/icemodel/IceEISModel.hh"
29#include "pism/verification/iceCompModel.hh"
30#include "pism/util/NetCDFConfig.hh"
31#include "pism/util/Grid.hh"
33#include "pism/util/Context.hh"
34#include "pism/util/Profiling.hh"
35#include "pism/util/error_handling.hh"
36#include "pism/util/petscwrappers/PetscInitializer.hh"
37#include "pism/util/pism_options.hh"
38#include "pism/util/EnthalpyConverter.hh"
40#include "pism/regional/IceRegionalModel.hh"
50 config.
set_string(
"grid.registration",
"corner");
51 config.
set_string(
"stress_balance.sia.flow_law",
"pb");
56 config.
set_number(
"sea_level.constant.value", -1e4);
59 config.
set_number(
"stress_balance.sia.enhancement_factor", 1.0);
62 config.
set_number(
"stress_balance.sia.bed_smoother.range", 0.0);
65 config.
set_flag(
"geometry.update.use_basal_melt_rate",
false);
71 config.
set_number(
"energy.bedrock_thermal.density",
73 config.
set_number(
"energy.bedrock_thermal.conductivity",
74 config.
get_number(
"constants.ice.thermal_conductivity"));
75 config.
set_number(
"energy.bedrock_thermal.specific_heat_capacity",
76 config.
get_number(
"constants.ice.specific_heat_capacity"));
79 config.
set_string(
"stress_balance.model",
"sia");
94 config.
set_string(
"grid.registration",
"corner");
100 config.
set_string(
"grid.ice_vertical_spacing",
"quadratic");
147std::shared_ptr<Context>
context(MPI_Comm com,
const std::string &prefix,
150 auto sys = std::make_shared<units::System>();
153 auto logger = std::make_shared<Logger>(com, 1);
160 config->resolve_filenames();
162 logger->set_threshold(
static_cast<int>(config->get_number(
"output.runtime.verbosity")));
166 auto time = std::make_shared<Time>(com, config, *logger, sys);
168 auto EC = std::make_shared<ColdEnthalpyConverter>(*config);
170 return std::make_shared<Context>(com, sys, config, EC, time, logger, prefix);
173std::shared_ptr<Grid>
grid(std::shared_ptr<Context> ctx) {
174 auto config = ctx->config();
176 auto input_file_name = config->get_string(
"input.file");
178 if (config->get_flag(
"input.bootstrap")) {
182 if (not input_file_name.empty()) {
188 return Grid::FromFile(ctx, input_file, {
"enthalpy",
"temp" }, r);
195int main(
int argc,
char *argv[]) {
197 MPI_Comm com = MPI_COMM_WORLD;
200 com = PETSC_COMM_WORLD;
206 "EISMINT II experiment name",
207 "A,B,C,D,E,F,I,J,K,L",
"A");
209 auto verification_test =
210 options::Keyword(
"-test",
"Specifies PISM verification test",
"A,B,C,D,F,G,H,K,L,V",
"A");
212 if (eisII.is_set() and verification_test.is_set()) {
216 std::shared_ptr<Context> ctx;
217 if (verification_test.is_set()) {
218 char test = verification_test.value()[0];
224 auto log = ctx->log();
225 auto config = ctx->config();
227 if (eisII.is_set()) {
232 auto overrides = std::make_shared<NetCDFConfig>(
"pism_overrides", ctx->unit_system());
234 options::String override_filename(
"-config_override",
"Config override file name");
236 if (override_filename.
is_set()) {
237 overrides->read(com, override_filename);
238 config->import_from(*overrides);
243 config->resolve_filenames();
246 if (
options::Bool(
"-version",
"print PISM version and stop")) {
251 if (not(verification_test.is_set() or eisII.is_set()) and
252 config->get_string(
"input.file").empty()) {
254 "Configuration parameter 'input.file' cannot be empty");
260 " pism -i IN.nc [-bootstrap] [-regional] [OTHER PISM & PETSc OPTIONS]\n"
262 " -i IN.nc is input file in NetCDF format: contains PISM-written model state\n"
263 " -bootstrap enable heuristics to produce an initial state from an incomplete input\n"
264 " -regional enable \"regional mode\"\n"
265 " -eisII [experiment] enable EISMINT II mode\n"
266 " -test [verification_test] enable verification mode\n"
268 " * option -i is required\n"
269 " * if -bootstrap is used then also '-Mx A -My B -Mz C -Lz D' are required\n";
271 bool done =
maybe_show_usage(*log,
"PISM (basic evolution run mode)", usage);
278 "Save detailed profiling data to a file.");
280 if (profiling_log.
is_set()) {
281 ctx->profiling().start();
284 std::shared_ptr<Grid> grid;
285 std::shared_ptr<IceModel> model;
286 std::shared_ptr<IceCompModel> verification_model;
288 if (verification_test.is_set()) {
289 char test = verification_test.value()[0];
292 verification_model = std::make_shared<IceCompModel>(grid, ctx, test);
293 model = verification_model;
297 if (
options::Bool(
"-regional",
"enable regional (outlet glacier) mode")) {
298 model = std::make_shared<IceRegionalModel>(grid, ctx);
299 }
else if (eisII.is_set()) {
300 char experiment = eisII.value()[0];
302 model = std::make_shared<IceEISModel>(grid, ctx, experiment);
304 model = std::make_shared<IceModel>(grid, ctx);
309 "List available diagnostic quantities and stop.",
310 "all,spatial,scalar,json",
313 if (list_type.is_set()) {
315 auto value = list_type.value();
316 if (value ==
"spatial") {
318 }
else if (value ==
"scalar") {
320 }
else if (value ==
"json") {
330 auto termination_reason = model->run();
332 switch (termination_reason) {
335 exit_code =
static_cast<int>(config->get_number(
"output.checkpoint.exit_code"));
336 log->message(2,
"... stopping (exit_code=%d) after saving the checkpoint file\n",
343 log->message(2,
"... done with the run\n");
344 model->write_final_output();
347 if (verification_model and
348 not
options::Bool(
"-no_report",
"do not print the error report")) {
349 verification_model->reportErrors();
357 if (profiling_log.
is_set()) {
358 ctx->profiling().report(profiling_log);
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.
High-level PISM I/O class.
static std::shared_ptr< Grid > FromFile(std::shared_ptr< const Context > ctx, const File &file, const std::vector< std::string > &var_names, grid::Registration r)
Create a grid using one of variables in var_names in file.
static std::shared_ptr< Grid > FromOptions(std::shared_ptr< const Context > ctx)
Create a grid using command-line options and (possibly) an input file.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
#define PISM_ERROR_LOCATION
static void set_config_defaults(Config &config)
Registration string_to_registration(const std::string &keyword)
@ PISM_READONLY
open an existing file for reading only
bool Bool(const std::string &option, const std::string &description)
void set_config_from_options(Config &config)
Set configuration parameters using command-line options.
void handle_fatal_errors(MPI_Comm com)
std::shared_ptr< Context > context_from_options(MPI_Comm com, const std::string &prefix)
Create a default context using options.
bool maybe_show_usage(const Logger &log, const std::string &execname, const std::string &usage)
In a single call a driver program can provide a usage string to the user and check if required option...
std::shared_ptr< Config > config_from_options(MPI_Comm com, units::System::Ptr unit_system)
Create a configuration database using command-line options.
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.
std::shared_ptr< Context > context(MPI_Comm com, const std::string &prefix, char testname)
Allocate the verification mode context. Uses ColdEnthalpyConverter.
std::shared_ptr< Grid > grid(std::shared_ptr< Context > ctx)
void set_config_defaults(Config &config, char testname)
int main(int argc, char *argv[])