20 #include "pism/hydrology/SteadyState.hh"
22 #include <gsl/gsl_interp.h>
24 #include "pism/hydrology/EmptyingProblem.hh"
26 #include "pism/util/Time.hh"
27 #include "pism/util/Profiling.hh"
28 #include "pism/util/Context.hh"
29 #include "pism/util/MaxTimestep.hh"
55 "* Initializing the \"steady state\" subglacial hydrology model ...\n");
69 if (
m_config->get_flag(
"hydrology.add_water_input_to_till_storage")) {
71 "'steady' hydrology requires hydrology.add_water_input_to_till_storage == false");
74 if (
m_config->get_string(
"hydrology.surface_input.file").empty()) {
76 "'steady' hydrology requires hydrology.surface_input.file");
85 if (t >= t_next or std::abs(t_next - t) <
m_t_eps or
88 m_log->message(3,
" Updating the steady-state subglacial water flux...\n");
113 double dt_forcing = 0.0;
123 }
else if (t >= t_last) {
129 size_t k = gsl_interp_bsearch(
m_time.data(), t, 0,
m_time.size());
136 if (std::abs(t_next - t) <
m_t_eps) {
149 dt_forcing = t_next - t;
151 assert(dt_forcing > 0.0);
157 double dt_interval = 0.0;
161 "time %f is less than the previous time %f",
172 dt_interval = t_next - t;
179 double dt =
std::min(dt_forcing, dt_interval);
182 if (dt_null.finite()) {
196 "time of the last update of the steady state subglacial water flux");
285 std::string variable_name =
"water_input_rate";
290 file, variable_name);
292 if (time_name.empty()) {
299 if (bounds_name.empty()) {
302 "Variable '%s' does not have the time_bounds attribute.\n"
303 "Cannot use time-dependent water input rate without time bounds.",
316 for (
unsigned int k = 0;
k <
m_time.size(); ++
k) {
322 "time bounds in %s are invalid", input_file.c_str());
const Time & time() const
std::shared_ptr< const Grid > 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
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)
const Profiling & profiling() const
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
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 define_variable(const std::string &name, io::Type nctype, const std::vector< std::string > &dims) const
Define a variable.
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.
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...
void begin(const char *name) const
void end(const char *name) const
static RuntimeError formatted(const ErrorLocation &location, const char format[],...) __attribute__((format(printf
build a RuntimeError with a formatted message
std::string units_string() const
Internal time units as a string.
double current() const
Current time, in seconds.
void copy_from(const Array2D< T > &source)
void read(const std::string &filename, unsigned int time)
void define(const File &file, io::Type default_type) const
Define variables corresponding to an Array in a file opened using file.
void write(const std::string &filename) const
int state_counter() const
Get the object state counter.
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.
array::Scalar 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 array::Scalar &W_till, const array::Scalar &W, const array::Scalar &P)
virtual void bootstrap_impl(const File &input_file, const array::Scalar &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.
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 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
SteadyState(std::shared_ptr< const Grid > g)
void bootstrap_impl(const File &input_file, const array::Scalar &ice_thickness)
void init_impl(const array::Scalar &W_till, const array::Scalar &W, const array::Scalar &P)
double m_t_eps
Temporal resolution to use when checking whether it's time to update.
#define PISM_ERROR_LOCATION
double min(const array::Scalar &input)
Finds minimum over all the values in an array::Scalar object. Ignores ghosts.
@ PISM_READONLY
open an existing file for reading only
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.
static std::string calendar(const File *input_file, const Config &config, const Logger &log)
T combine(const T &a, const T &b)