tCache.cc - pism - [fork] customized build of PISM, the parallel ice sheet model (tillflux branch)
HTML git clone git://src.adamsgaard.dk/pism
DIR Log
DIR Files
DIR Refs
DIR LICENSE
---
tCache.cc (4121B)
---
1 /* Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018 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 "Cache.hh"
25 #include "pism/util/Time.hh"
26 #include "pism/util/IceGrid.hh"
27
28 #include "pism/util/error_handling.hh"
29 #include "pism/util/pism_utilities.hh"
30 #include "pism/util/MaxTimestep.hh"
31
32 namespace pism {
33 namespace ocean {
34
35 Cache::Cache(IceGrid::ConstPtr g, std::shared_ptr<OceanModel> in)
36 : OceanModel(g, in) {
37
38 m_next_update_time = m_grid->ctx()->time()->current();
39 m_update_interval_years = m_config->get_number("ocean.cache.update_interval");
40
41 if (m_update_interval_years < 1) {
42 throw RuntimeError::formatted(PISM_ERROR_LOCATION,
43 "ocean.cache.update_interval has to be strictly positive (got %d)",
44 m_update_interval_years);
45 }
46
47 {
48 m_shelf_base_temperature = allocate_shelf_base_temperature(g);
49 m_shelf_base_mass_flux = allocate_shelf_base_mass_flux(g);
50 m_melange_back_pressure_fraction = allocate_melange_back_pressure(g);
51 }
52 }
53
54 Cache::~Cache() {
55 // empty
56 }
57
58 void Cache::init_impl(const Geometry &geometry) {
59 m_input_model->init(geometry);
60
61 m_log->message(2,
62 "* Initializing the 'caching' ocean model modifier...\n");
63
64 m_next_update_time = m_grid->ctx()->time()->current();
65 }
66
67 void Cache::update_impl(const Geometry &geometry, double t, double dt) {
68 // ignore dt and always use 1 year long time-steps when updating
69 // an input model
70 (void) dt;
71
72 if (t >= m_next_update_time or
73 fabs(t - m_next_update_time) < 1.0) {
74
75 double
76 one_year_from_now = m_grid->ctx()->time()->increment_date(t, 1.0),
77 update_dt = one_year_from_now - t;
78
79 assert(update_dt > 0.0);
80
81 m_input_model->update(geometry, t, update_dt);
82
83 m_next_update_time = m_grid->ctx()->time()->increment_date(m_next_update_time,
84 m_update_interval_years);
85
86 m_melange_back_pressure_fraction->copy_from(m_input_model->melange_back_pressure_fraction());
87
88 m_shelf_base_temperature->copy_from(m_input_model->shelf_base_temperature());
89
90 m_shelf_base_mass_flux->copy_from(m_input_model->shelf_base_mass_flux());
91 }
92 }
93
94 MaxTimestep Cache::max_timestep_impl(double t) const {
95 double dt = m_next_update_time - t;
96
97 // if we got very close to the next update time, set time step
98 // length to the interval between updates
99 if (dt < 1.0) {
100 double update_time_after_next = m_grid->ctx()->time()->increment_date(m_next_update_time,
101 m_update_interval_years);
102
103 dt = update_time_after_next - m_next_update_time;
104 assert(dt > 0.0);
105 }
106
107 MaxTimestep cache_dt(dt, "ocean cache");
108
109 MaxTimestep input_max_timestep = m_input_model->max_timestep(t);
110 if (input_max_timestep.finite()) {
111 return std::min(input_max_timestep, cache_dt);
112 } else {
113 return cache_dt;
114 }
115 }
116
117 const IceModelVec2S& Cache::shelf_base_temperature_impl() const {
118 return *m_shelf_base_temperature;
119 }
120
121 const IceModelVec2S& Cache::shelf_base_mass_flux_impl() const {
122 return *m_shelf_base_mass_flux;
123 }
124
125 const IceModelVec2S& Cache::melange_back_pressure_fraction_impl() const {
126 return *m_melange_back_pressure_fraction;
127 }
128
129
130 } // end of namespace ocean
131 } // end of namespace pism