Skip to content

Commit

Permalink
IceGrid::FromOptions can create grids using config. defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
ckhroulev committed Jun 25, 2021
1 parent c11e459 commit 040b08a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 34 deletions.
6 changes: 6 additions & 0 deletions src/icemodel/IceEISModel.cc
Expand Up @@ -169,4 +169,10 @@ void IceEISModel::initialize_2d() {
m_geometry.sea_level_elevation);
}

void IceEISModel::bootstrap_2d(const File &input_file) {
throw RuntimeError::formatted(PISM_ERROR_LOCATION,
"EISMINT II mode does not support bootstrapping");
}


} // end of namespace pism
3 changes: 2 additions & 1 deletion src/icemodel/IceEISModel.hh
@@ -1,4 +1,4 @@
// Copyright (C) 2004-2017 Jed Brown, Ed Bueler and Constantine Khroulev
// Copyright (C) 2004-2017, 2021 Jed Brown, Ed Bueler and Constantine Khroulev
//
// This file is part of PISM.
//
Expand Down Expand Up @@ -34,6 +34,7 @@ public:

protected:
virtual void initialize_2d();
virtual void bootstrap_2d(const File &input_file);

virtual void allocate_couplers();

Expand Down
29 changes: 1 addition & 28 deletions src/pisms.cc
Expand Up @@ -64,33 +64,6 @@ std::shared_ptr<Context> pisms_context(MPI_Comm com) {
return std::shared_ptr<Context>(new Context(com, sys, config, EC, time, logger, "pisms"));
}

IceGrid::Ptr pisms_grid(std::shared_ptr<Context> ctx) {
auto config = ctx->config();

auto input_file = config->get_string("input.file");

if (config->get_flag("input.bootstrap")) {
throw RuntimeError(PISM_ERROR_LOCATION, "pisms does not support bootstrapping");
}

if (not input_file.empty()) {
GridRegistration r = string_to_registration(ctx->config()->get_string("grid.registration"));

// get grid from a PISM input file
return IceGrid::FromFile(ctx, input_file, {"enthalpy", "temp"}, r);
} else {
// use defaults from the configuration database
GridParameters P(ctx->config());
P.horizontal_size_from_options();
P.horizontal_extent_from_options(ctx->unit_system());
P.vertical_grid_from_options(ctx->config());
P.ownership_ranges_from_options(ctx->size());

return IceGrid::Ptr(new IceGrid(ctx, P));
}
}


int main(int argc, char *argv[]) {

MPI_Comm com = MPI_COMM_WORLD;
Expand Down Expand Up @@ -120,7 +93,7 @@ int main(int argc, char *argv[]) {

Config::Ptr config = ctx->config();

IceGrid::Ptr g = pisms_grid(ctx);
IceGrid::Ptr g = IceGrid::FromOptions(ctx);
IceEISModel m(g, ctx, experiment[0]);

m.init();
Expand Down
18 changes: 13 additions & 5 deletions src/util/IceGrid.cc
Expand Up @@ -1395,7 +1395,8 @@ IceGrid::Ptr IceGrid::FromOptions(std::shared_ptr<const Context> ctx) {
input_file.c_str());
}

// process all possible options controlling grid parameters, overriding values read from a file
// process all possible options controlling grid parameters, overriding values read
// from a file
input_grid.horizontal_size_from_options();
input_grid.horizontal_extent_from_options(ctx->unit_system());
input_grid.vertical_grid_from_options(config);
Expand All @@ -1419,10 +1420,17 @@ IceGrid::Ptr IceGrid::FromOptions(std::shared_ptr<const Context> ctx) {

return result;
} else {
// This covers the two remaining cases "-i is not set, -bootstrap is set" and "-i is not set,
// -bootstrap is not set either".
throw RuntimeError(PISM_ERROR_LOCATION,
"Please set the input file using the \"-i\" command-line option.");
// This covers the two remaining cases "-i is not set, -bootstrap is set" and "-i is
// not set, -bootstrap is not set either".

// Use defaults from the configuration database
GridParameters P(ctx->config());
P.horizontal_size_from_options();
P.horizontal_extent_from_options(ctx->unit_system());
P.vertical_grid_from_options(ctx->config());
P.ownership_ranges_from_options(ctx->size());

return IceGrid::Ptr(new IceGrid(ctx, P));
}
}

Expand Down

0 comments on commit 040b08a

Please sign in to comment.