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/Config.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"
71#include "pism/util/io/IO_Flags.hh"
98 const bool use_input_file =
101 std::unique_ptr<File> input_file;
103 if (use_input_file) {
111 if (use_input_file) {
112 std::string old_history = input_file->read_text_attribute(
"PISM_GLOBAL",
"history");
118 switch (input_options.
type) {
161 switch (input_options.
type) {
171 W_till.
set(
m_config->get_number(
"bootstrapping.defaults.tillwat"));
172 W.set(
m_config->get_number(
"bootstrapping.defaults.bwat"));
173 P.set(
m_config->get_number(
"bootstrapping.defaults.bwp"));
186 switch (input_options.
type) {
220 if (
m_btu !=
nullptr) {
221 m_btu->init(input_options);
239 switch (input_options.
type) {
256 m_btu->flux_through_top_surface());
272 for (
auto p :
m_grid->points()) {
273 const int i = p.i(), j = p.j();
308 std::string filename = input_file.
name();
310 m_log->message(2,
"initializing 2D fields from NetCDF file '%s'...\n", filename.c_str());
313 variable->read(input_file, last_record);
319 m_log->message(2,
"bootstrapping from file '%s'...\n", input_file.
name().c_str());
321 auto usurf = input_file.
find_variable(
"usurf",
"surface_altitude");
329 m_log->message(2,
" WARNING: 'mask' found; IGNORING IT!\n");
333 m_log->message(2,
" WARNING: surface elevation 'usurf' found; IGNORING IT!\n");
336 m_log->message(2,
" reading 2D model state variables by regridding ...\n");
355 if (
m_config->get_flag(
"geometry.part_grid.enabled")) {
367 if (
m_config->get_flag(
"stress_balance.ssa.dirichlet_bc")) {
383 if (max_thickness >
m_grid->Lz()) {
385 "Max. ice thickness (%3.3f m)\n"
386 "exceeds the height of the computational domain (%3.3f m).",
387 max_thickness,
m_grid->Lz());
400 auto filename =
m_config->get_string(
"input.regrid.file");
404 if (filename.empty()) {
408 m_log->message(2,
"regridding from file %s ...\n", filename.c_str());
413 if (regrid_vars.find(v->get_name()) != regrid_vars.end()) {
422 if (max_thickness >= Lz + 1e-6) {
424 "Maximum ice thickness (%f meters)\n"
425 "exceeds the height of the computational domain (%f meters).",
439 m_log->message(2,
"# Allocating a stress balance model...\n");
453 m_log->message(2,
"# Allocating the geometry evolution model...\n");
467 m_log->message(2,
"# Allocating an iceberg remover (part of a calving model)...\n");
469 if (
m_config->get_flag(
"geometry.remove_icebergs")) {
471 auto model =
m_config->get_string(
"stress_balance.model");
472 auto ssa_method =
m_config->get_string(
"stress_balance.ssa.method");
474 if ((
set_member(model, {
"ssa",
"ssa+sia" }) and ssa_method ==
"fem") or model ==
"blatter") {
490 if (
m_config->get_flag(
"age.enabled")) {
491 m_log->message(2,
"# Allocating an ice age model...\n");
495 "Cannot allocate an age model: m_stress_balance == nullptr.");
509 auto deposition_times =
m_config->get_string(
"isochrones.deposition_times");
510 if (not deposition_times.empty()) {
511 m_log->message(2,
"# Allocating isochrone tracking...\n");
516 "Cannot allocate the isochrone tracking model: m_stress_balance == nullptr.");
531 m_log->message(2,
"# Allocating an energy balance model...\n");
533 auto energy_model =
m_config->get_string(
"energy.model");
534 if (energy_model ==
"enthalpy") {
536 }
else if (energy_model ==
"cold") {
549 if (
m_btu !=
nullptr) {
553 m_log->message(2,
"# Allocating a bedrock thermal layer model...\n");
565 std::string hydrology_model =
m_config->get_string(
"hydrology.model");
571 m_log->message(2,
"# Allocating a subglacial hydrology model...\n");
573 if (hydrology_model ==
"null") {
575 }
else if (hydrology_model ==
"routing") {
577 }
else if (hydrology_model ==
"steady") {
579 }
else if (hydrology_model ==
"distributed") {
583 hydrology_model.c_str());
596 m_log->message(2,
"# Allocating a basal yield stress model...\n");
598 std::string model =
m_config->get_string(
"stress_balance.model");
601 if (
set_member(model, {
"ssa",
"ssa+sia",
"blatter" })) {
602 std::string yield_stress_model =
m_config->get_string(
"basal_yield_stress.model");
604 if (yield_stress_model ==
"constant") {
606 }
else if (yield_stress_model ==
"mohr_coulomb") {
608 }
else if (yield_stress_model ==
"tillphi_opt") {
612 "yield stress model '%s' is not supported.",
613 yield_stress_model.c_str());
651 if (
m_config->get_flag(
"fracture_density.enabled")) {
663 m_log->message(2,
"# Allocating a surface process model or coupler...\n");
673 m_log->message(2,
"# Allocating sea level forcing...\n");
675 using namespace ocean::sea_level;
683 m_log->message(2,
"# Allocating an ocean model or coupler...\n");
685 using namespace ocean;
696 m_log->message(3,
"Finishing initialization...\n");
706 if (source.empty()) {
709 "PISM WARNING: file '%s' does not have the 'source' global attribute.\n"
710 " If '%s' is a PISM output file, please run the following to get rid of this warning:\n"
711 " ncatted -a source,global,c,c,PISM %s\n",
714 }
else if (source.find(
"PISM") == std::string::npos) {
719 "PISM WARNING: '%s' does not seem to be a PISM output file.\n"
720 " If it is, please make sure that the 'source' global attribute contains the string \"PISM\".\n",
731 const long int two_to_thirty_two = 4294967296L;
733 std::string output_format =
m_config->get_string(
"output.format");
734 if (Mx * My * Mz *
sizeof(
double) > two_to_thirty_two - 4 and
738 "The computational grid is too big to fit in a NetCDF-3 file.\n"
739 "Each 3D variable requires %lu Mb.\n"
740 "Please use '-o_format pnetcdf or -o_format netcdf4_parallel to proceed.",
741 Mx * My * Mz *
sizeof(
double) / (1024 * 1024));
754 std::vector<std::string> pik_methods;
755 if (
m_config->get_flag(
"geometry.part_grid.enabled")) {
756 pik_methods.push_back(
"part_grid");
758 if (
m_config->get_flag(
"geometry.remove_icebergs")) {
759 pik_methods.push_back(
"kill_icebergs");
762 if (not pik_methods.empty()) {
763 m_log->message(2,
"* PISM-PIK mass/geometry methods are in use: %s\n",
764 join(pik_methods,
", ").c_str());
794 if (not
m_config->get_flag(
"geometry.part_grid.enabled")) {
812 auto front_retreat_file =
m_config->get_string(
"geometry.front_retreat.prescribed.file");
814 if (not front_retreat_file.empty()) {
826 std::set<std::string> methods =
set_split(
m_config->get_string(
"calving.methods"),
',');
827 bool allocate_front_retreat =
false;
829 if (
set_member(
"thickness_calving", methods)) {
836 methods.erase(
"thickness_calving");
843 allocate_front_retreat =
true;
850 methods.erase(
"eigen_calving");
855 if (
set_member(
"vonmises_calving", methods)) {
856 allocate_front_retreat =
true;
864 methods.erase(
"vonmises_calving");
869 if (
set_member(
"hayhurst_calving", methods)) {
870 allocate_front_retreat =
true;
877 methods.erase(
"hayhurst_calving");
888 methods.erase(
"float_kill");
893 if (not methods.empty()) {
895 "PISM ERROR: calving method(s) [%s] are not supported.\n",
905 auto filename =
m_config->get_string(
"calving.rate_scaling.file");
906 if (not filename.empty()) {
908 "frac_calving_rate",
"1",
"1",
909 "calving rate scaling factor"));
919 m_log->message(2,
"# Allocating a bed deformation model...\n");
921 std::string model =
m_config->get_string(
"bed_deformation.model");
923 if (model ==
"none") {
925 }
else if (model ==
"iso") {
927 }
else if (model ==
"lc") {
929 }
else if (model ==
"given") {
939 std::string variables;
941 if (keyword ==
"none" or
942 keyword ==
"small") {
944 }
else if (keyword ==
"medium") {
945 variables =
m_config->get_string(
"output.sizes.medium");
946 }
else if (keyword ==
"big_2d") {
947 variables = (
m_config->get_string(
"output.sizes.medium") +
"," +
948 m_config->get_string(
"output.sizes.big_2d"));
949 }
else if (keyword ==
"big") {
950 variables = (
m_config->get_string(
"output.sizes.medium") +
"," +
951 m_config->get_string(
"output.sizes.big_2d") +
"," +
952 m_config->get_string(
"output.sizes.big"));
960 std::string projection =
m_grid->get_mapping_info()[
"proj_params"];
965 m_log->message(2,
"* Computing longitude and latitude using projection parameters...\n");
967#if (Pism_USE_PROJ==1)
972 "Cannot compute longitude and latitude.\n"
973 "Please rebuild PISM with PROJ\n"
974 "or set '%s' to 'false'.",
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.
bool variable_exists(const std::string &short_name) const
Checks if a variable exists.
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()
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
virtual void compute_lat_lon()
std::shared_ptr< FractureDensity > m_fracture
std::shared_ptr< Config > m_config
Configuration flags and parameters.
virtual void bootstrap_2d(const File &input_file)
std::shared_ptr< YieldStress > m_basal_yield_stress_model
std::shared_ptr< calving::IcebergRemover > m_iceberg_remover
virtual void initialize_2d()
std::shared_ptr< Context > m_ctx
Execution context.
std::shared_ptr< frontalmelt::FrontalMelt > m_frontal_melt
std::shared_ptr< Logger > m_log
Logger.
array::Scalar m_basal_melt_rate
rate of production of basal meltwater (ice-equivalent); no ghosts
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
void init_outputs(InputOptions options, DiagnosticReport report_type)
const array::Scalar & frontal_melt() const
virtual void allocate_iceberg_remover()
std::vector< std::shared_ptr< array::Scalar2 > > m_work2d
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
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).
std::shared_ptr< energy::BedThermalUnit > m_btu
virtual void model_state_setup(InputOptions input_options)
Sets the starting values of model state variables.
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.
array::Vector2 m_velocity_bc_values
Dirichlet boundary velocities.
virtual void allocate_geometry_evolution()
std::shared_ptr< ocean::sea_level::SeaLevel > m_sea_level
virtual void allocate_age_model()
std::string m_output_history
virtual YieldStressInputs yield_stress_inputs()
virtual void misc_setup(InputOptions input_options, DiagnosticReport report_type)
Miscellaneous initialization tasks plus tasks that need the fields that can come from regridding.
virtual void allocate_couplers()
virtual void append_history(const std::string &string)
Get time and user/host name and add it to the given string.
std::unique_ptr< hydrology::Hydrology > m_subglacial_hydrology
std::shared_ptr< calving::vonMisesCalving > m_vonmises_calving
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)
VariableMetadata & metadata(unsigned int N=0)
Returns a reference to the VariableMetadata 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.
Sub-glacial hydrology models and related diagnostics.
@ PISM_READONLY
open an existing file for reading only
std::shared_ptr< StressBalance > create(const std::string &model, std::shared_ptr< const Grid > grid, bool regional)
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.
std::string args_string()
Uses argc and argv to create the string with current PISM command-line arguments.
static void compute_lon_lat(const std::string &projection, LonLat which, array::Scalar &result)
std::string join(const std::vector< std::string > &strings, const std::string &separator)
Concatenate strings, inserting separator between elements.
bool set_member(const std::string &string, const std::set< std::string > &set)