22 #include <gsl/gsl_interp.h>
26 #include "pism/util/Time.hh"
27 #include "pism/util/Profiling.hh"
28 #include "pism/util/Context.hh"
54 "* Initializing the \"steady state\" subglacial hydrology model ...\n");
68 if (
m_config->get_flag(
"hydrology.add_water_input_to_till_storage")) {
70 "'steady' hydrology requires hydrology.add_water_input_to_till_storage == false");
73 if (
m_config->get_string(
"hydrology.surface_input.file").empty()) {
75 "'steady' hydrology requires hydrology.surface_input.file");
84 if (t >= t_next or std::abs(t_next - t) <
m_t_eps or
87 m_log->message(3,
" Updating the steady-state subglacial water flux...\n");
89 m_grid->ctx()->profiling().begin(
"steady_emptying");
95 m_grid->ctx()->profiling().end(
"steady_emptying");
112 double dt_forcing = 0.0;
122 }
else if (t >= t_last) {
128 size_t k = gsl_interp_bsearch(
m_time.data(), t, 0,
m_time.size());
135 if (std::abs(t_next - t) <
m_t_eps) {
148 dt_forcing = t_next - t;
150 assert(dt_forcing > 0.0);
156 double dt_interval = 0.0;
160 "time %f is less than the previous time %f",
171 dt_interval = t_next - t;
178 double dt =
std::min(dt_forcing, dt_interval);
181 if (dt_null.finite()) {
195 "time of the last update of the steady state subglacial water flux");
284 std::string variable_name =
"water_input_rate";
289 file, variable_name);
291 if (time_name.empty()) {
298 if (bounds_name.empty()) {
301 "Variable '%s' does not have the time_bounds attribute.\n"
302 "Cannot use time-dependent water input rate without time bounds.",
308 tb[
"units"] =
m_grid->ctx()->time()->units_string();
315 for (
unsigned int k = 0;
k <
m_time.size(); ++
k) {
321 "time bounds in %s are invalid", input_file.c_str());
IceGrid::ConstPtr grid() const
const Config::ConstPtr m_config
configuration database used by this component
const Logger::ConstPtr m_log
logger (for easy access)
@ REGRID_WITHOUT_REGRID_VARS
virtual void regrid(const std::string &module_name, IceModelVec &variable, RegriddingFlag flag=NO_REGRID_WITHOUT_REGRID_VARS)
const IceGrid::ConstPtr m_grid
grid used by this component
MaxTimestep max_timestep(double t) const
Reports the maximum time-step the model can take at time t.
void read_variable(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, double *ip) const
void define_variable(const std::string &name, IO_Type nctype, const std::vector< std::string > &dims) const
Define a variable.
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.
void write_variable(const std::string &variable_name, const std::vector< unsigned int > &start, const std::vector< unsigned int > &count, const double *op) const
void write_attribute(const std::string &var_name, const std::string &att_name, IO_Type nctype, const std::vector< double > &values) const
Write a multiple-valued double attribute.
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.
std::shared_ptr< const IceGrid > ConstPtr
void copy_from(const IceModelVec2< T > &source)
SpatialVariableMetadata & metadata(unsigned int N=0)
Returns a reference to the SpatialVariableMetadata object containing metadata for the compoment N.
void regrid(const std::string &filename, RegriddingFlag flag, double default_value=0.0)
void set(double c)
Result: v[j] <- c for all j.
void read(const std::string &filename, unsigned int time)
void define(const File &file, IO_Type default_type=PISM_DOUBLE) const
Define variables corresponding to an IceModelVec in a file opened using file.
void write(const std::string &filename) const
int state_counter() const
Get the object state counter.
double value() const
Get the value of the maximum time step.
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
IceModelVec2S m_surface_input_rate
virtual void define_model_state_impl(const File &output) const
The default (empty implementation).
virtual std::map< std::string, Diagnostic::Ptr > diagnostics_impl() const
virtual void write_model_state_impl(const File &output) const
The default (empty implementation).
virtual void restart_impl(const File &input_file, int record)
virtual void init_impl(const IceModelVec2S &W_till, const IceModelVec2S &W, const IceModelVec2S &P)
virtual void bootstrap_impl(const File &input_file, const IceModelVec2S &ice_thickness)
virtual void update_impl(double t, double dt, const Inputs &inputs)
Solves an implicit step of a highly-simplified ODE.
virtual MaxTimestep max_timestep_impl(double t) const
double m_update_interval
Update interval in seconds.
void init_time(const std::string &input_file)
void write_model_state_impl(const File &output) const
The default (empty implementation).
double m_t_last
time of the last water flux update
void update_impl(double t, double dt, const Inputs &inputs)
Solves an implicit step of a highly-simplified ODE.
SteadyState(IceGrid::ConstPtr g)
std::vector< double > m_time_bounds
Time bounds corresponding to records in the input file.
MaxTimestep max_timestep_impl(double t) const
std::string m_time_name
Name of the variable used to store the last update time.
void restart_impl(const File &input_file, int record)
bool m_bootstrap
Set to true in bootstrap_impl() if update_impl() has to bootstrap m_Q.
std::map< std::string, Diagnostic::Ptr > diagnostics_impl() const
std::shared_ptr< EmptyingProblem > m_emptying_problem
void bootstrap_impl(const File &input_file, const IceModelVec2S &ice_thickness)
void define_model_state_impl(const File &output) const
The default (empty implementation).
std::vector< double > m_time
Times corresponding to records in the input file.
void initialization_message() const
void init_impl(const IceModelVec2S &W_till, const IceModelVec2S &W, const IceModelVec2S &P)
double m_t_eps
Temporal resolution to use when checking whether it's time to update.
#define PISM_ERROR_LOCATION
void read_time_bounds(const File &file, const VariableMetadata &metadata, const Logger &log, std::vector< double > &data)
std::string time_dimension(units::System::Ptr unit_system, const File &file, const std::string &variable_name)
bool is_increasing(const std::vector< double > &a)
Checks if a vector of doubles is strictly increasing.
double min(const IceModelVec2S &input)
Finds minimum over all the values in an IceModelVec2S object. Ignores ghosts.
@ PISM_READONLY
open an existing file for reading only
T combine(const T &a, const T &b)