PISM, A Parallel Ice Sheet Model  stable v2.1-1-g6902d5502 committed by Ed Bueler on 2023-12-20 08:38:27 -0800
Forcing.hh
Go to the documentation of this file.
1 // Copyright (C) 2009--2023 Constantine Khrulev
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 #ifndef PISM_ARRAY_FORCING
20 #define PISM_ARRAY_FORCING
21 
22 #include "pism/util/array/Scalar.hh"
23 #include "pism/util/MaxTimestep.hh"
24 #include "pism/util/interpolation.hh" // InterpolationType
25 
26 namespace pism {
27 namespace array {
28 
29 //! @brief 2D time-dependent inputs (for climate forcing, etc)
30 /*! This class was created to read time-dependent and spatially-varying climate
31  forcing data, in particular snow temperatures and precipitation.
32 
33  If requests (calls to update()) go in sequence, every record should be read only once.
34 
35  Note that this class is optimized for use with a PDD scheme -- it stores
36  records so that data corresponding to a grid point are stored in adjacent
37  memory locations.
38 
39  `Forcing` has no ghosts.
40 */
41 class Forcing : public array::Scalar {
42 public:
43 
44  Forcing(std::shared_ptr<const Grid> grid,
45  const File &file,
46  const std::string &short_name,
47  const std::string &standard_name,
48  unsigned int max_buffer_size,
49  bool periodic,
50  InterpolationType interpolation_type = PIECEWISE_CONSTANT);
51 
52  virtual ~Forcing();
53 
54  static std::shared_ptr<Forcing>
55  Constant(std::shared_ptr<const Grid> grid, const std::string &short_name, double value);
56 
57  unsigned int buffer_size();
58 
59  void init(const std::string &filename, bool periodic);
60 
61  void update(double t, double dt);
62  MaxTimestep max_timestep(double t) const;
63 
64  void interp(double t);
65 
66  void interp(int i, int j, std::vector<double> &results);
67 
68  void average(double t, double dt);
69 
70  void begin_access() const;
71  void end_access() const;
72  void init_interpolation(const std::vector<double> &ts);
73 
74 private:
75  struct Data;
76 
78 
79  Forcing(std::shared_ptr<const Grid> grid,
80  const std::string &short_name,
81  unsigned int buffer_size,
82  InterpolationType interpolation_type);
83  void allocate(unsigned int buffer_size, InterpolationType interpolation_type);
84 
85  double*** array3();
86  void update(unsigned int start);
87  void discard(int N);
88  void set_record(int n);
89  void init_periodic_data(const File &file);
90 };
91 
92 } // end of namespace array
93 } // end of namespace pism
94 
95 #endif // PISM_ARRAY_FORCING
High-level PISM I/O class.
Definition: File.hh:56
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
Definition: MaxTimestep.hh:31
std::shared_ptr< const Grid > grid() const
Definition: Array.cc:132
MaxTimestep max_timestep(double t) const
Given the time t determines the maximum possible time-step this Forcing allows.
Definition: Forcing.cc:599
void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition: Forcing.cc:213
void average(double t, double dt)
Definition: Forcing.cc:673
void discard(int N)
Discard the first N records, shifting the rest of them towards the "beginning".
Definition: Forcing.cc:564
void init_periodic_data(const File &file)
Definition: Forcing.cc:314
void interp(double t)
Definition: Forcing.cc:642
void set_record(int n)
Sets the record number n to the contents of the (internal) Vec v.
Definition: Forcing.cc:585
void init(const std::string &filename, bool periodic)
Definition: Forcing.cc:234
double *** array3()
Definition: Forcing.cc:209
void allocate(unsigned int buffer_size, InterpolationType interpolation_type)
Definition: Forcing.cc:178
void end_access() const
Checks if an Array is allocated and calls DAVecRestoreArray.
Definition: Forcing.cc:223
Forcing(std::shared_ptr< const Grid > grid, const File &file, const std::string &short_name, const std::string &standard_name, unsigned int max_buffer_size, bool periodic, InterpolationType interpolation_type=PIECEWISE_CONSTANT)
Definition: Forcing.cc:112
void init_interpolation(const std::vector< double > &ts)
Compute weights for the piecewise-constant interpolation. This is used both for time-series and "snap...
Definition: Forcing.cc:774
static std::shared_ptr< Forcing > Constant(std::shared_ptr< const Grid > grid, const std::string &short_name, double value)
Definition: Forcing.cc:147
unsigned int buffer_size()
Definition: Forcing.cc:205
virtual ~Forcing()
Definition: Forcing.cc:201
void update(double t, double dt)
Read some data to make sure that the interval (t, t + dt) is covered.
Definition: Forcing.cc:429
2D time-dependent inputs (for climate forcing, etc)
Definition: Forcing.hh:41
#define n
Definition: exactTestM.c:37
InterpolationType
@ PIECEWISE_CONSTANT