Loading [MathJax]/extensions/tex2jax.js
PISM, A Parallel Ice Sheet Model 2.2.2-d6b3a29ca committed by Constantine Khrulev on 2025-03-28
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Forcing.hh
Go to the documentation of this file.
1// Copyright (C) 2009--2024 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/Interpolation1D.hh" // InterpolationType
25
26namespace pism {
27namespace 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*/
41class Forcing : public array::Scalar {
42public:
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() const;
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
74private:
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:55
Combines the max. time step with the flag indicating if a restriction is active. Makes is possible to...
std::shared_ptr< const Grid > grid() const
Definition Array.cc:131
MaxTimestep max_timestep(double t) const
Given the time t determines the maximum possible time-step this Forcing allows.
Definition Forcing.cc:586
void begin_access() const
Checks if an Array is allocated and calls DAVecGetArray.
Definition Forcing.cc:217
void average(double t, double dt)
Definition Forcing.cc:660
void discard(int N)
Discard the first N records, shifting the rest of them towards the "beginning".
Definition Forcing.cc:551
void init_periodic_data(const File &file)
Definition Forcing.cc:316
void interp(double t)
Definition Forcing.cc:629
void set_record(int n)
Sets the record number n to the contents of the (internal) Vec v.
Definition Forcing.cc:572
void init(const std::string &filename, bool periodic)
Definition Forcing.cc:238
double *** array3()
Definition Forcing.cc:213
void allocate(unsigned int buffer_size, InterpolationType interpolation_type)
Definition Forcing.cc:179
void end_access() const
Checks if an Array is allocated and calls DAVecRestoreArray.
Definition Forcing.cc:227
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:761
static std::shared_ptr< Forcing > Constant(std::shared_ptr< const Grid > grid, const std::string &short_name, double value)
Definition Forcing.cc:148
void update(double t, double dt)
Read some data to make sure that the interval (t, t + dt) is covered.
Definition Forcing.cc:424
unsigned int buffer_size() const
Definition Forcing.cc:209
2D time-dependent inputs (for climate forcing, etc)
Definition Forcing.hh:41
#define n
Definition exactTestM.c:37
@ PIECEWISE_CONSTANT