21#include "pism/earth/BedDef.hh"
22#include "pism/util/Config.hh"
23#include "pism/util/Context.hh"
24#include "pism/util/Grid.hh"
25#include "pism/util/MaxTimestep.hh"
26#include "pism/util/Time.hh"
27#include "pism/util/Logger.hh"
28#include "pism/util/io/IO_Flags.hh"
29#include "pism/util/io/io_helpers.hh"
35BedDef::BedDef(std::shared_ptr<const Grid> grid,
const std::string &model_name)
37 m_topg(m_grid,
"topg"),
38 m_topg_last(m_grid,
"topg"),
39 m_load(grid,
"bed_def_load"),
40 m_load_accumulator(grid,
"bed_def_load_accumulator"),
41 m_uplift(m_grid,
"dbdt"),
42 m_t_last(time().current()),
43 m_time_name(time().variable_name() +
"_bed_deformation"),
44 m_model_name(model_name)
55 .
long_name(
"bedrock surface elevation after the previous update (used to compute uplift)")
60 .
long_name(
"load on the bed expressed as ice-equivalent thickness")
65 .
long_name(
"accumulated load on the bed expressed as the time integral of ice-equivalent thickness")
86 T.long_name(
"time of the last update of the bed deformation model")
87 .units(
time().units())
88 .set_time_dependent(
true);
102 auto t_start = t_length > 0 ? t_length - 1 : 0;
119 m_log->message(2,
"* Initializing the %s bed deformation model...\n",
128 auto t_last = t_length > 0 ? t_length - 1 : 0;
140 m_log->message(2,
" reading bed topography and uplift from %s ... \n",
167 auto uplift_file =
m_config->get_string(
"bed_deformation.bed_uplift_file");
168 if (not uplift_file.empty()) {
169 m_log->message(2,
" reading bed uplift from %s ... \n", uplift_file.c_str());
173 auto correction_file =
m_config->get_string(
"bed_deformation.bed_topography_delta_file");
174 if (not correction_file.empty()) {
175 m_log->message(2,
" Adding a bed topography correction read in from '%s'...\n",
176 correction_file.c_str());
181 this->
init_impl(opts, ice_thickness, sea_level_elevation);
197 this->
bootstrap_impl(bed_elevation, bed_uplift, ice_thickness, sea_level_elevation);
208 double t,
double dt) {
210 double t_final = t + dt;
219 if (std::abs(t_next - t_final) <
m_t_eps) {
221 double dt_beddef = t_final -
m_t_last;
251 "time %f is less than the previous time %f",
289 bed_topography.
add(1.0, topg_delta);
293 double ice_density,
double ocean_density) {
296 ice_load = ice_thickness,
297 ocean_depth = std::max(sea_level - bed, 0.0),
298 ocean_load = (ocean_density / ice_density) * ocean_depth;
301 return ice_load > ocean_load ? ice_load : 0.0;
313 auto config = result.
grid()->ctx()->config();
315 const double ice_density = config->get_number(
"constants.ice.density"),
316 ocean_density = config->get_number(
"constants.sea_water.density");
318 array::AccessScope list{ &bed_elevation, &ice_thickness, &sea_level_elevation, &result };
320 for (
auto p : result.
grid()->points()) {
321 const int i = p.i(), j = p.j();
323 result(i, j) += C *
compute_load(bed_elevation(i, j), ice_thickness(i, j), sea_level_elevation(i, j),
324 ice_density, ocean_density);
const units::System::Ptr m_sys
unit system used by this component
const Time & time() const
std::shared_ptr< const Grid > grid() const
std::shared_ptr< const Config > m_config
configuration database used by this component
@ REGRID_WITHOUT_REGRID_VARS
const std::shared_ptr< const Grid > m_grid
grid used by this component
void regrid(const std::string &module_name, array::Array &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
std::shared_ptr< const Logger > m_log
logger (for easy access)
A class defining a common interface for most PISM sub-models.
static Ptr wrap(const T &input)
unsigned int nrecords() const
Get the number of records. Uses the length of an unlimited dimension.
bool variable_exists(const std::string &short_name) const
Checks if a variable exists.
High-level PISM I/O class.
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
unsigned int time_dimension_length() const
void write_timeseries(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, const std::vector< double > &input) const
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
double current() const
Current time, in seconds.
std::string calendar() const
Returns the calendar string.
Makes sure that we call begin_access() and end_access() for all accessed array::Arrays.
void copy_from(const Array2D< T > &source)
void add(double alpha, const Array2D< T > &x)
void read(const std::string &filename, unsigned int time)
void write(const OutputFile &file) const
void scale(double alpha)
Result: v <- v * alpha. Calls VecScale.
std::shared_ptr< const Grid > grid() const
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.
virtual DiagnosticList spatial_diagnostics_impl() const
std::string m_time_name
Name of the variable used to store the last update time.
array::Scalar m_load_accumulator
virtual void write_state_impl(const OutputFile &output) const
The default (empty implementation).
array::Scalar m_topg_last
bed elevation at the time of the last update
virtual void update_impl(const array::Scalar &load, double t, double dt)=0
void init(const InputOptions &opts, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
virtual MaxTimestep max_timestep_impl(double t) const
void update(const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation, double t, double dt)
double m_update_interval
Update interval in seconds.
void bootstrap(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)
Initialize using provided bed elevation and uplift.
array::Scalar2 m_topg
current bed elevation
virtual void bootstrap_impl(const array::Scalar &bed_elevation, const array::Scalar &bed_uplift, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)=0
BedDef(std::shared_ptr< const Grid > g, const std::string &model_name)
array::Scalar m_uplift
bed uplift rate
const array::Scalar & uplift() const
const array::Scalar & bed_elevation() const
virtual void init_impl(const InputOptions &opts, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation)=0
double m_t_last
time of the last bed deformation update
static void apply_topg_offset(const std::string &filename, array::Scalar &bed_topography)
virtual std::set< VariableMetadata > state_impl() const
double m_t_eps
Temporal resolution to use when checking whether it's time to update.
#define PISM_ERROR_LOCATION
std::set< VariableMetadata > metadata(std::initializer_list< const Array * > vecs)
void accumulate_load(const array::Scalar &bed_elevation, const array::Scalar &ice_thickness, const array::Scalar &sea_level_elevation, double C, array::Scalar &result)
double compute_load(double bed, double ice_thickness, double sea_level, double ice_density, double ocean_density)
std::vector< double > read_timeseries_variable(const File &file, const std::string &variable_name, const std::string &units, std::shared_ptr< units::System > unit_system, size_t start, size_t count)
@ PISM_READONLY
open an existing file for reading only
std::map< std::string, Diagnostic::Ptr > DiagnosticList