PISM, A Parallel Ice Sheet Model 2.3.0-79cae578d committed by Constantine Khrulev on 2026-03-22
Loading...
Searching...
No Matches
Cache.cc
Go to the documentation of this file.
1/* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2020, 2021, 2023, 2025 PISM Authors
2 *
3 * This file is part of PISM.
4 *
5 * PISM is free software; you can redistribute it and/or modify it under the
6 * terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 3 of the License, or (at your option) any later
8 * version.
9 *
10 * PISM is distributed in the hope that it will be useful, but WITHOUT ANY
11 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with PISM; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <algorithm> // std::min
21#include <cassert>
22#include <cmath>
23
24#include "pism/coupler/ocean/Cache.hh"
25#include "pism/util/Grid.hh"
26#include "pism/util/MaxTimestep.hh"
27#include "pism/util/Time.hh"
28#include "pism/util/error_handling.hh"
29#include "pism/util/Logger.hh"
30
31namespace pism {
32namespace ocean {
33
34Cache::Cache(std::shared_ptr<const Grid> g, std::shared_ptr<OceanModel> in)
35 : OceanModel(g, in) {
36
38 m_update_interval_years = m_config->get_number("ocean.cache.update_interval", "seconds");
39
40 // use the current year length (according to the selected calendar) to convert update
41 // interval length into years
43
44 if (m_update_interval_years <= 0.0) {
46 "ocean.cache.update_interval has to be strictly positive (got %f)",
48 }
49
50 {
54 }
55}
56
57void Cache::init_impl(const Geometry &geometry) {
58 m_input_model->init(geometry);
59
60 m_log->message(2,
61 "* Initializing the 'caching' ocean model modifier...\n");
62
64}
65
66void Cache::update_impl(const Inputs &inputs, double t, double dt) {
67 // ignore dt and always use 1 year long time-steps when updating
68 // an input model
69 (void) dt;
70
71 double time_resolution = m_config->get_number("time_stepping.resolution", "seconds");
72
73 if (t >= m_next_update_time or
74 fabs(t - m_next_update_time) < time_resolution) {
75
76 double
77 one_year_from_now = time().increment_date(t, 1.0),
78 update_dt = one_year_from_now - t;
79
80 assert(update_dt > 0.0);
81
82 m_input_model->update(inputs, t, update_dt);
83
86
87 m_water_column_pressure->copy_from(m_input_model->average_water_column_pressure());
88
89 m_shelf_base_temperature->copy_from(m_input_model->shelf_base_temperature());
90
91 m_shelf_base_mass_flux->copy_from(m_input_model->shelf_base_mass_flux());
92 }
93}
94
96 double dt = m_next_update_time - t;
97
98 double time_resolution = m_config->get_number("time_stepping.resolution", "seconds");
99
100 // if we got very close to the next update time, set time step
101 // length to the interval between updates
102 if (dt < time_resolution) {
103 double update_time_after_next = time().increment_date(m_next_update_time,
105
106 dt = update_time_after_next - m_next_update_time;
107 assert(dt > 0.0);
108 }
109
110 MaxTimestep cache_dt(dt, "ocean cache");
111
112 MaxTimestep input_max_timestep = m_input_model->max_timestep(t);
113 if (input_max_timestep.finite()) {
114 return std::min(input_max_timestep, cache_dt);
115 } else {
116 return cache_dt;
117 }
118}
119
123
127
131
132
133} // end of namespace ocean
134} // end of namespace pism
const Time & time() const
Definition Component.cc:111
std::shared_ptr< const Config > m_config
configuration database used by this component
Definition Component.hh:160
std::shared_ptr< const Logger > m_log
logger (for easy access)
Definition Component.hh:164
bool finite() const
Convert to bool to check if a time step restriction is "active".
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
double increment_date(double T, double years) const
Definition Time.cc:867
double convert_time_interval(double T, const std::string &units) const
Convert time interval from seconds to given units. Handle 'years' using the year length corresponding...
Definition Time.cc:694
double current() const
Current time, in seconds.
Definition Time.cc:461
double m_update_interval_years
Definition Cache.hh:44
const array::Scalar & shelf_base_temperature_impl() const
Definition Cache.cc:120
MaxTimestep max_timestep_impl(double t) const
Definition Cache.cc:95
void update_impl(const Inputs &inputs, double my_t, double my_dt)
Definition Cache.cc:66
std::shared_ptr< array::Scalar > m_shelf_base_mass_flux
Definition Cache.hh:48
void init_impl(const Geometry &geometry)
Definition Cache.cc:57
const array::Scalar & shelf_base_mass_flux_impl() const
Definition Cache.cc:124
double m_next_update_time
Definition Cache.hh:43
std::shared_ptr< array::Scalar > m_shelf_base_temperature
Definition Cache.hh:47
Cache(std::shared_ptr< const Grid > g, std::shared_ptr< OceanModel > in)
Definition Cache.cc:34
const array::Scalar & average_water_column_pressure_impl() const
Definition Cache.cc:128
std::shared_ptr< OceanModel > m_input_model
Definition OceanModel.hh:77
std::shared_ptr< array::Scalar > m_water_column_pressure
Definition OceanModel.hh:78
static std::shared_ptr< array::Scalar > allocate_shelf_base_temperature(std::shared_ptr< const Grid > g)
Definition OceanModel.cc:31
static std::shared_ptr< array::Scalar > allocate_shelf_base_mass_flux(std::shared_ptr< const Grid > g)
Definition OceanModel.cc:39
static std::shared_ptr< array::Scalar > allocate_water_column_pressure(std::shared_ptr< const Grid > g)
Definition OceanModel.cc:49
A very rudimentary PISM ocean model.
Definition OceanModel.hh:38
#define PISM_ERROR_LOCATION
bool ocean(int M)
An ocean cell (floating ice or ice-free).
Definition Mask.hh:40
static const double g
Definition exactTestP.cc:36