PISM, A Parallel Ice Sheet Model  stable v2.1.1 committed by Constantine Khrulev on 2024-12-04 13:36:58 -0900
init_step.hh
Go to the documentation of this file.
1 /* Copyright (C) 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 "pism/util/Time.hh"
21 #include "pism/util/MaxTimestep.hh"
22 
23 namespace pism {
24 
25 /*!
26  * Update a `model` by asking it to perform time-stepping from the current time to one year in the
27  * future (or as far as the time step restriction allows).
28  *
29  * This is sometimes necessary during initialization, but should be avoided if possible.
30  */
31 template<class M>
32 void init_step(M *model, const Geometry &geometry, const Time& time) {
33  const double
34  now = time.current(),
35  one_year_from_now = time.increment_date(now, 1.0);
36 
37  // Take a one year long step if we can.
38  MaxTimestep max_dt(one_year_from_now - now);
39 
40  max_dt = std::min(max_dt, model->max_timestep(now));
41 
42  // Do not take time-steps shorter than 1 second
43  if (max_dt.value() < 1.0) {
44  max_dt = MaxTimestep(1.0);
45  }
46 
47  assert(max_dt.finite());
48 
49  model->update(geometry, now, max_dt.value());
50 }
51 
52 } // end of namespace pism
bool finite() const
Convert to bool to check if a time step restriction is "active".
Definition: MaxTimestep.cc:47
double value() const
Get the value of the maximum time step.
Definition: MaxTimestep.cc:55
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
double increment_date(double T, double years) const
Definition: Time.cc:852
double current() const
Current time, in seconds.
Definition: Time.cc:465
Time management class.
Definition: Time.hh:55
double min(const array::Scalar &input)
Finds minimum over all the values in an array::Scalar object. Ignores ghosts.
Definition: Scalar.cc:193
void init_step(M *model, const Geometry &geometry, const Time &time)
Definition: init_step.hh:32