PISM, A Parallel Ice Sheet Model
ScalarForcing.hh
Go to the documentation of this file.
1 // Copyright (C) 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2021 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 #ifndef PISM_SCALARFORCING_H
20 #define PISM_SCALARFORCING_H
21 
22 #include <memory> // std::unique_ptr
23 #include <vector> // std::vector
24 
25 #include <gsl/gsl_spline.h>
26 
27 namespace pism {
28 
29 class Context;
30 class File;
31 class Logger;
32 
33 /*!
34  * This class helps with loading and using scalar forcings such as scalar temperature
35  * offsets.
36  *
37  * It processes command-line options, reads data from a file, and gets data corresponding
38  * to a time interval [t, t+dt].
39  */
41 public:
42  ScalarForcing(const Context &ctx,
43  const std::string &option_prefix,
44  const std::string &variable_name,
45  const std::string &units,
46  const std::string &glaciological_units,
47  const std::string &long_name);
48 
49  ScalarForcing(const Context &ctx,
50  const std::string &filename,
51  const std::string &variable_name,
52  const std::string &units,
53  const std::string &glaciological_units,
54  const std::string &long_name,
55  bool periodic);
56 
58 
59  double value(double t) const;
60 
61  double average(double t, double dt) const;
62 
63 private:
64  // disable copy constructor and the assignment operator:
67 
68  void initialize(const Context &ctx,
69  const std::string &filename,
70  const std::string &variable_name,
71  const std::string &units,
72  const std::string &glaciological_units,
73  const std::string &long_name,
74  bool periodic);
75 
76  double integral(double a, double b) const;
77 
78  // period, in seconds (zero if not periodic)
79  double m_period;
80 
81  // start of the period, in seconds (not used if not periodic)
83 
84  // Times associated with corresponding values (used for linear interpolation)
85  std::vector<double> m_times;
86 
87  // Forcing values
88  std::vector<double> m_values;
89 
90  gsl_interp_accel* m_acc;
91  gsl_spline* m_spline;
92 };
93 
94 } // end of namespace pism
95 
96 #endif /* PISM_SCALARFORCING_H */
gsl_spline * m_spline
ScalarForcing & operator=(const ScalarForcing &)
ScalarForcing(const ScalarForcing &other)
double average(double t, double dt) const
double value(double t) const
std::vector< double > m_times
std::vector< double > m_values
ScalarForcing(const Context &ctx, const std::string &option_prefix, const std::string &variable_name, const std::string &units, const std::string &glaciological_units, const std::string &long_name)
void initialize(const Context &ctx, const std::string &filename, const std::string &variable_name, const std::string &units, const std::string &glaciological_units, const std::string &long_name, bool periodic)
gsl_interp_accel * m_acc
double integral(double a, double b) const