22 #include "pism/icemodel/IceModel.hh"
23 #include "pism/basalstrength/ConstantYieldStress.hh"
24 #include "pism/basalstrength/MohrCoulombYieldStress.hh"
25 #include "pism/basalstrength/OptTillphiYieldStress.hh"
26 #include "pism/frontretreat/util/IcebergRemover.hh"
27 #include "pism/frontretreat/util/IcebergRemoverFEM.hh"
28 #include "pism/frontretreat/calving/CalvingAtThickness.hh"
29 #include "pism/frontretreat/calving/EigenCalving.hh"
30 #include "pism/frontretreat/calving/FloatKill.hh"
31 #include "pism/frontretreat/calving/HayhurstCalving.hh"
32 #include "pism/frontretreat/calving/vonMisesCalving.hh"
33 #include "pism/energy/BedThermalUnit.hh"
34 #include "pism/hydrology/NullTransport.hh"
35 #include "pism/hydrology/Routing.hh"
36 #include "pism/hydrology/SteadyState.hh"
37 #include "pism/hydrology/Distributed.hh"
38 #include "pism/stressbalance/StressBalance.hh"
39 #include "pism/util/ConfigInterface.hh"
40 #include "pism/util/Time.hh"
41 #include "pism/util/error_handling.hh"
42 #include "pism/util/io/File.hh"
43 #include "pism/coupler/OceanModel.hh"
44 #include "pism/coupler/SurfaceModel.hh"
45 #include "pism/coupler/atmosphere/Factory.hh"
46 #include "pism/coupler/ocean/Factory.hh"
47 #include "pism/coupler/ocean/Initialization.hh"
48 #include "pism/coupler/ocean/sea_level/Factory.hh"
49 #include "pism/coupler/ocean/sea_level/Initialization.hh"
50 #include "pism/coupler/surface/Factory.hh"
51 #include "pism/coupler/surface/Initialization.hh"
52 #include "pism/earth/LingleClark.hh"
53 #include "pism/earth/BedDef.hh"
54 #include "pism/earth/Given.hh"
55 #include "pism/util/Vars.hh"
56 #include "pism/util/projection.hh"
57 #include "pism/util/pism_utilities.hh"
58 #include "pism/age/AgeModel.hh"
59 #include "pism/age/Isochrones.hh"
60 #include "pism/energy/EnthalpyModel.hh"
61 #include "pism/energy/TemperatureModel.hh"
62 #include "pism/fracturedensity/FractureDensity.hh"
63 #include "pism/frontretreat/FrontRetreat.hh"
64 #include "pism/frontretreat/PrescribedRetreat.hh"
65 #include "pism/coupler/frontalmelt/Factory.hh"
66 #include "pism/coupler/util/options.hh"
67 #include "pism/util/ScalarForcing.hh"
68 #include "pism/stressbalance/ShallowStressBalance.hh"
69 #include "pism/util/array/Forcing.hh"
77 bool use_calendar =
m_config->get_flag(
"output.runtime.time_use_calendar");
81 "* Run time: [%s, %s] (%s years, using the '%s' calendar)\n",
84 m_time->run_length().c_str(),
85 m_time->calendar().c_str());
87 std::string time_units =
m_config->get_string(
"output.runtime.time_unit_name");
90 start =
m_time->convert_time_interval(
m_time->start(), time_units),
91 end =
m_time->convert_time_interval(
m_time->end(), time_units),
95 "* Run time: [%f %s, %f %s] (%f %s)\n",
96 start, time_units.c_str(),
97 end, time_units.c_str(),
98 length, time_units.c_str());
130 std::unique_ptr<File> input_file;
132 if (use_input_file) {
138 switch (input.
type) {
156 if (use_input_file) {
157 std::string mapping_name =
m_grid->get_mapping_info().mapping.get_name();
159 m_ctx->unit_system());
161 if (not info.
proj.empty()) {
162 m_log->message(2,
"* Got projection parameters \"%s\" from \"%s\".\n",
167 m_grid->set_mapping_info(info);
169 std::string history = input_file->read_text_attribute(
"PISM_GLOBAL",
"history");
207 switch (input.
type) {
222 W_till.
set(
m_config->get_number(
"bootstrapping.defaults.tillwat"));
223 W.set(
m_config->get_number(
"bootstrapping.defaults.bwat"));
224 P.set(
m_config->get_number(
"bootstrapping.defaults.bwp"));
237 switch (input.
type) {
271 if (
m_btu !=
nullptr) {
290 switch (input.
type) {
303 m_btu->flux_through_top_surface());
315 m_btu->flux_through_top_surface());
332 for (
auto p =
m_grid->points(); p; p.next()) {
333 const int i = p.i(), j = p.j();
345 auto startstr =
pism::printf(
"PISM (%s) started on %d procs.",
346 pism::revision, (
int)
m_grid->size());
357 std::string filename = input_file.
filename();
359 m_log->message(2,
"initializing 2D fields from NetCDF file '%s'...\n", filename.c_str());
362 variable->read(input_file, last_record);
368 m_log->message(2,
"bootstrapping from file '%s'...\n", input_file.
filename().c_str());
370 auto usurf = input_file.
find_variable(
"usurf",
"surface_altitude");
378 m_log->message(2,
" WARNING: 'mask' found; IGNORING IT!\n");
382 m_log->message(2,
" WARNING: surface elevation 'usurf' found; IGNORING IT!\n");
385 m_log->message(2,
" reading 2D model state variables by regridding ...\n");
393 if (not lon.exists) {
404 if (not lat.exists) {
412 if (
m_config->get_flag(
"geometry.part_grid.enabled")) {
424 if (
m_config->get_flag(
"stress_balance.ssa.dirichlet_bc")) {
440 if (max_thickness >
m_grid->Lz()) {
442 "exceeds the height of the computational domain (%3.3f m).",
443 max_thickness,
m_grid->Lz());
456 auto filename =
m_config->get_string(
"input.regrid.file");
460 if (filename.empty()) {
464 m_log->message(2,
"regridding from file %s ...\n", filename.c_str());
469 if (regrid_vars.find(v->get_name()) != regrid_vars.end()) {
480 if (max_thickness >= Lz + 1e-6) {
482 "exceeds the height of the computational domain (%f meters).",
496 m_log->message(2,
"# Allocating a stress balance model...\n");
510 m_log->message(2,
"# Allocating the geometry evolution model...\n");
525 "# Allocating an iceberg remover (part of a calving model)...\n");
527 if (
m_config->get_flag(
"geometry.remove_icebergs")) {
529 auto model =
m_config->get_string(
"stress_balance.model");
530 auto ssa_method =
m_config->get_string(
"stress_balance.ssa.method");
532 if ((
member(model, {
"ssa",
"ssa+sia"}) and ssa_method ==
"fem") or
533 model ==
"blatter") {
549 if (
m_config->get_flag(
"age.enabled")) {
550 m_log->message(2,
"# Allocating an ice age model...\n");
554 "Cannot allocate an age model: m_stress_balance == nullptr.");
570 m_log->message(2,
"# Allocating isochrone tracking...\n");
575 "Cannot allocate the isochrone tracking model: m_stress_balance == nullptr.");
590 m_log->message(2,
"# Allocating an energy balance model...\n");
592 if (
m_config->get_flag(
"energy.enabled")) {
593 if (
m_config->get_flag(
"energy.temperature_based")) {
609 if (
m_btu !=
nullptr) {
613 m_log->message(2,
"# Allocating a bedrock thermal layer model...\n");
625 std::string hydrology_model =
m_config->get_string(
"hydrology.model");
631 m_log->message(2,
"# Allocating a subglacial hydrology model...\n");
633 if (hydrology_model ==
"null") {
635 }
else if (hydrology_model ==
"routing") {
637 }
else if (hydrology_model ==
"steady") {
639 }
else if (hydrology_model ==
"distributed") {
643 "unknown 'hydrology.model': %s", hydrology_model.c_str());
657 "# Allocating a basal yield stress model...\n");
659 std::string model =
m_config->get_string(
"stress_balance.model");
662 if (
member(model, {
"ssa",
"ssa+sia",
"blatter"})) {
663 std::string yield_stress_model =
m_config->get_string(
"basal_yield_stress.model");
665 if (yield_stress_model ==
"constant") {
667 }
else if (yield_stress_model ==
"mohr_coulomb") {
669 }
else if (yield_stress_model ==
"tillphi_opt") {
673 yield_stress_model.c_str());
711 if (
m_config->get_flag(
"fracture_density.enabled")) {
723 m_log->message(2,
"# Allocating a surface process model or coupler...\n");
733 m_log->message(2,
"# Allocating sea level forcing...\n");
735 using namespace ocean::sea_level;
743 m_log->message(2,
"# Allocating an ocean model or coupler...\n");
745 using namespace ocean;
756 m_log->message(3,
"Finishing initialization...\n");
767 if (source.empty()) {
769 "PISM WARNING: file '%s' does not have the 'source' global attribute.\n"
770 " If '%s' is a PISM output file, please run the following to get rid of this warning:\n"
771 " ncatted -a source,global,c,c,PISM %s\n",
773 }
else if (source.find(
"PISM") == std::string::npos) {
777 "PISM WARNING: '%s' does not seem to be a PISM output file.\n"
778 " If it is, please make sure that the 'source' global attribute contains the string \"PISM\".\n",
789 const long int two_to_thirty_two = 4294967296L;
794 std::string output_format =
m_config->get_string(
"output.format");
795 if (Mx * My * Mz *
sizeof(
double) > two_to_thirty_two - 4 and
798 "The computational grid is too big to fit in a NetCDF-3 file.\n"
799 "Each 3D variable requires %lu Mb.\n"
800 "Please use '-o_format pnetcdf or -o_format netcdf4_parallel to proceed.",
801 Mx * My * Mz *
sizeof(
double) / (1024 * 1024));
807 #if (Pism_USE_PROJ==1)
809 std::string proj_string =
m_grid->get_mapping_info().proj;
810 if (not proj_string.empty()) {
828 std::vector<std::string> pik_methods;
829 if (
m_config->get_flag(
"geometry.part_grid.enabled")) {
830 pik_methods.push_back(
"part_grid");
832 if (
m_config->get_flag(
"geometry.remove_icebergs")) {
833 pik_methods.push_back(
"kill_icebergs");
836 if (not pik_methods.empty()) {
838 "* PISM-PIK mass/geometry methods are in use: %s\n",
839 join(pik_methods,
", ").c_str());
855 d.second->init(file, opts.
record);
887 if (not
m_config->get_flag(
"geometry.part_grid.enabled")) {
889 "ERROR: frontal melt models require geometry.part_grid.enabled");
905 auto front_retreat_file =
m_config->get_string(
"geometry.front_retreat.prescribed.file");
907 if (not front_retreat_file.empty()) {
919 std::set<std::string> methods =
set_split(
m_config->get_string(
"calving.methods"),
',');
920 bool allocate_front_retreat =
false;
922 if (
member(
"thickness_calving", methods)) {
929 methods.erase(
"thickness_calving");
935 if (
member(
"eigen_calving", methods)) {
936 allocate_front_retreat =
true;
943 methods.erase(
"eigen_calving");
948 if (
member(
"vonmises_calving", methods)) {
949 allocate_front_retreat =
true;
957 methods.erase(
"vonmises_calving");
962 if (
member(
"hayhurst_calving", methods)) {
963 allocate_front_retreat =
true;
970 methods.erase(
"hayhurst_calving");
975 if (
member(
"float_kill", methods)) {
981 methods.erase(
"float_kill");
986 if (not methods.empty()) {
988 "PISM ERROR: calving method(s) [%s] are not supported.\n",
998 auto filename =
m_config->get_string(
"calving.rate_scaling.file");
999 if (not filename.empty()) {
1001 "calving.rate_scaling",
1002 "frac_calving_rate",
1005 "calving rate scaling factor"));
1016 "# Allocating a bed deformation model...\n");
1018 std::string model =
m_config->get_string(
"bed_deformation.model");
1020 if (model ==
"none") {
1023 else if (model ==
"iso") {
1026 else if (model ==
"lc") {
1029 else if (model ==
"given") {
1041 "Processing physics-related command-line options...\n");
1053 if (
m_config->get_number(
"time_stepping.maximum_time_step") <= 0) {
1057 if (not
m_config->get_flag(
"geometry.update.enabled") &&
1058 m_config->get_flag(
"time_stepping.skip.enabled")) {
1060 "PISM WARNING: Both -skip and -no_mass are set.\n"
1061 " -skip only makes sense in runs updating ice geometry.\n");
1064 if (
m_config->get_string(
"calving.methods").find(
"thickness_calving") != std::string::npos &&
1065 not
m_config->get_flag(
"geometry.part_grid.enabled")) {
1067 "PISM WARNING: Calving at certain terminal ice thickness (-calving thickness_calving)\n"
1068 " without application of partially filled grid cell scheme (-part_grid)\n"
1069 " may lead to (incorrect) non-moving ice shelf front.\n");
1076 std::string variables;
1078 if (keyword ==
"none" or
1079 keyword ==
"small") {
1081 }
else if (keyword ==
"medium") {
1082 variables =
m_config->get_string(
"output.sizes.medium");
1083 }
else if (keyword ==
"big_2d") {
1084 variables = (
m_config->get_string(
"output.sizes.medium") +
"," +
1085 m_config->get_string(
"output.sizes.big_2d"));
1086 }
else if (keyword ==
"big") {
1087 variables = (
m_config->get_string(
"output.sizes.medium") +
"," +
1088 m_config->get_string(
"output.sizes.big_2d") +
"," +
1089 m_config->get_string(
"output.sizes.big"));
1097 std::string projection =
m_grid->get_mapping_info().proj;
1099 if (
m_config->get_flag(
"grid.recompute_longitude_and_latitude") and
1100 not projection.empty()) {
1102 "* Computing longitude and latitude using projection parameters...\n");
VariableLookupData find_variable(const std::string &short_name, const std::string &std_name) const
Find a variable using its standard name and/or short name.
std::string filename() const
std::string read_text_attribute(const std::string &var_name, const std::string &att_name) const
Get a text attribute.
High-level PISM I/O class.
array::Scalar1 ice_area_specific_volume
array::Scalar2 ice_thickness
std::map< std::string, const Component * > m_submodels
the list of sub-models, for writing model states and obtaining diagnostics
void enforce_consistency_of_geometry(ConsistencyFlag flag)
Update the surface elevation and the flow-type mask when the geometry has changed.
virtual void allocate_bed_deformation()
virtual void model_state_setup()
Sets the starting values of model state variables.
void init_checkpoints()
Initialize checkpointing (snapshot-on-wallclock-time) mechanism.
std::shared_ptr< stressbalance::StressBalance > m_stress_balance
std::shared_ptr< Isochrones > m_isochrones
virtual void init_calving()
Initialize calving mechanisms.
std::shared_ptr< ocean::OceanModel > m_ocean
std::shared_ptr< surface::SurfaceModel > m_surface
const Config::Ptr m_config
Configuration flags and parameters.
virtual void compute_lat_lon()
std::shared_ptr< FractureDensity > m_fracture
virtual void bootstrap_2d(const File &input_file)
const Time::Ptr m_time
Time manager.
std::shared_ptr< YieldStress > m_basal_yield_stress_model
std::shared_ptr< calving::IcebergRemover > m_iceberg_remover
virtual void initialize_2d()
std::shared_ptr< frontalmelt::FrontalMelt > m_frontal_melt
void init_extras()
Initialize the code saving spatially-variable diagnostic quantities.
array::Scalar m_basal_melt_rate
rate of production of basal meltwater (ice-equivalent); no ghosts
const std::shared_ptr< Context > m_ctx
Execution context.
virtual void misc_setup()
Miscellaneous initialization tasks plus tasks that need the fields that can come from regridding.
const Logger::Ptr m_log
Logger.
std::shared_ptr< array::Forcing > m_surface_input_for_hydrology
virtual void allocate_stressbalance()
Decide which stress balance model to use.
std::shared_ptr< calving::EigenCalving > m_eigen_calving
std::unique_ptr< ScalarForcing > m_calving_rate_factor
VariableMetadata m_output_global_attributes
stores global attributes saved in a PISM output file
const array::Scalar & frontal_melt() const
virtual void allocate_iceberg_remover()
std::vector< std::shared_ptr< array::Scalar2 > > m_work2d
virtual void process_options()
std::shared_ptr< calving::CalvingAtThickness > m_thickness_threshold_calving
std::shared_ptr< calving::FloatKill > m_float_kill_calving
virtual void allocate_subglacial_hydrology()
Decide which subglacial hydrology model to use.
std::shared_ptr< PrescribedRetreat > m_prescribed_retreat
array::Scalar2 m_velocity_bc_mask
mask to determine Dirichlet boundary locations for the sliding velocity
virtual void prepend_history(const std::string &string)
Get time and user/host name and add it to the given string.
std::shared_ptr< calving::HayhurstCalving > m_hayhurst_calving
virtual void allocate_basal_yield_stress()
Decide which basal yield stress model to use.
std::unique_ptr< GeometryEvolution > m_geometry_evolution
virtual void allocate_energy_model()
virtual void restart_2d(const File &input_file, unsigned int record)
Initialize 2D model state fields managed by IceModel from a file (for re-starting).
virtual void time_setup()
Initialize time from an input file or command-line options.
std::shared_ptr< energy::BedThermalUnit > m_btu
std::set< array::Array * > m_model_state
array::Scalar1 m_ice_thickness_bc_mask
Mask prescribing locations where ice thickness is held constant.
std::shared_ptr< AgeModel > m_age_model
virtual void init_front_retreat()
virtual void allocate_bedrock_thermal_unit()
Decide which bedrock thermal unit to use.
virtual std::set< std::string > output_variables(const std::string &keyword)
Assembles a list of diagnostics corresponding to an output file size.
virtual void regrid()
Manage regridding based on user options.
const units::System::Ptr m_sys
Unit system.
array::Vector2 m_velocity_bc_values
Dirichlet boundary velocities.
virtual void allocate_geometry_evolution()
std::map< std::string, Diagnostic::Ptr > m_diagnostics
Requested spatially-variable diagnostics.
void init_snapshots()
Initializes the snapshot-saving mechanism.
std::shared_ptr< ocean::sea_level::SeaLevel > m_sea_level
virtual void allocate_age_model()
virtual YieldStressInputs yield_stress_inputs()
virtual void init_diagnostics()
virtual void allocate_couplers()
std::unique_ptr< hydrology::Hydrology > m_subglacial_hydrology
std::shared_ptr< calving::vonMisesCalving > m_vonmises_calving
void init_timeseries()
Initializes the code writing scalar time-series.
std::set< std::string > m_output_vars
virtual void allocate_isochrones()
virtual void init_frontal_melt()
std::shared_ptr< energy::EnergyModel > m_energy_model
const std::shared_ptr< Grid > m_grid
Computational grid.
std::shared_ptr< bed::BedDef > m_beddef
virtual void allocate_submodels()
Allocate PISM's sub-models implementing some physical processes.
std::shared_ptr< FrontRetreat > m_front_retreat
array::Scalar2 m_basal_yield_stress
ghosted
virtual std::shared_ptr< Model > create()
Creates a boundary model. Processes command-line options.
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void copy_from(const Array2D< T > &source)
void set(double c)
Result: v[j] <- c for all j.
void regrid(const std::string &filename, io::Default default_value)
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
int as_int(int i, int j) const
static std::shared_ptr< BedThermalUnit > FromOptions(std::shared_ptr< const Grid > g, std::shared_ptr< const Context > ctx)
The PISM subglacial hydrology model for a distributed linked-cavity system.
A subglacial hydrology model which assumes water pressure equals overburden pressure.
#define PISM_ERROR_LOCATION
double max(const array::Scalar &input)
Finds maximum over all the values in an array::Scalar object. Ignores ghosts.
static std::vector< double > deposition_times(const File &input_file)
Sub-glacial hydrology models and related diagnostics.
@ PISM_READONLY
open an existing file for reading only
bool ocean(int M)
An ocean cell (floating ice or ice-free).
std::shared_ptr< StressBalance > create(const std::string &model, std::shared_ptr< const Grid > grid, bool regional)
InputOptions process_input_options(MPI_Comm com, Config::ConstPtr config)
void compute_latitude(const std::string &projection, array::Scalar &result)
std::string set_join(const std::set< std::string > &input, const std::string &separator)
std::string printf(const char *format,...)
void compute_longitude(const std::string &projection, array::Scalar &result)
std::set< std::string > set_split(const std::string &input, char separator)
Transform a separator-separated list (a string) into a set of strings.
bool member(const std::string &string, const std::set< std::string > &set)
void set_config_from_options(units::System::Ptr unit_system, Config &config)
Set configuration parameters using command-line options.
std::string args_string()
Uses argc and argv to create the string with current PISM command-line arguments.
MappingInfo get_projection_info(const File &input_file, const std::string &mapping_name, units::System::Ptr unit_system)
Get projection info from a file.
std::string join(const std::vector< std::string > &strings, const std::string &separator)
Concatenate strings, inserting separator between elements.