URI:
       tWeatherStation.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
       ---
       tWeatherStation.cc (4683B)
       ---
            1 /* Copyright (C) 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 "WeatherStation.hh"
           21 #include "pism/util/ConfigInterface.hh"
           22 #include "pism/util/pism_utilities.hh"
           23 #include "pism/util/iceModelVec.hh"
           24 #include "pism/util/Time.hh"
           25 #include "pism/util/IceGrid.hh"
           26 #include "pism/util/io/File.hh"
           27 #include "pism/util/error_handling.hh"
           28 #include "pism/util/io/io_helpers.hh"
           29 #include "pism/util/MaxTimestep.hh"
           30 
           31 namespace pism {
           32 namespace atmosphere {
           33 
           34 WeatherStation::WeatherStation(IceGrid::ConstPtr grid)
           35   : AtmosphereModel(grid),
           36     m_precipitation_timeseries(*grid, "precipitation", m_config->get_string("time.dimension_name")),
           37     m_air_temp_timeseries(*grid, "air_temp", m_config->get_string("time.dimension_name"))
           38 {
           39   m_precipitation_timeseries.dimension().set_string("units", grid->ctx()->time()->units_string());
           40   m_precipitation_timeseries.variable().set_string("units", "kg m-2 second-1");
           41   m_precipitation_timeseries.variable().set_string("long_name",
           42                                                    "ice-equivalent precipitation rate");
           43 
           44   m_air_temp_timeseries.dimension().set_string("units", grid->ctx()->time()->units_string());
           45   m_air_temp_timeseries.variable().set_string("units", "Kelvin");
           46   m_air_temp_timeseries.variable().set_string("long_name",
           47                                               "near-surface air temperature");
           48 
           49   m_precipitation = allocate_precipitation(grid);
           50   m_temperature   = allocate_temperature(grid);
           51 }
           52 
           53 WeatherStation::~WeatherStation() {
           54   // empty
           55 }
           56 
           57 void WeatherStation::init_impl(const Geometry &geometry) {
           58   (void) geometry;
           59 
           60   m_log->message(2,
           61                  "* Initializing the constant-in-space atmosphere model\n"
           62                  "  for use with scalar data from one weather station\n"
           63                  "  combined with lapse rate corrections...\n");
           64 
           65   auto filename = m_config->get_string("atmosphere.one_station.file");
           66 
           67   if (filename.empty()) {
           68     throw RuntimeError(PISM_ERROR_LOCATION,
           69                        "atmosphere.one_station.file cannot be empty");
           70   }
           71 
           72   m_log->message(2,
           73                  "  - Reading air temperature and precipitation from '%s'...\n",
           74                  filename.c_str());
           75 
           76   File file(m_grid->com, filename, PISM_NETCDF3, PISM_READONLY);
           77   {
           78     m_precipitation_timeseries.read(file, *m_grid->ctx()->time(), *m_grid->ctx()->log());
           79     m_air_temp_timeseries.read(file, *m_grid->ctx()->time(), *m_grid->ctx()->log());
           80   }
           81 }
           82 
           83 MaxTimestep WeatherStation::max_timestep_impl(double t) const {
           84   (void) t;
           85   return MaxTimestep("atmosphere weather_station");
           86 }
           87 
           88 void WeatherStation::update_impl(const Geometry &geometry, double t, double dt) {
           89   (void) geometry;
           90 
           91   double one_week = 7 * 24 * 60 * 60;
           92   unsigned int N = (unsigned int)(ceil(dt / one_week)); // one point per week
           93 
           94   m_precipitation->set(m_precipitation_timeseries.average(t, dt, N));
           95 
           96   m_temperature->set(m_air_temp_timeseries.average(t, dt, N));
           97 }
           98 
           99 const IceModelVec2S& WeatherStation::mean_precipitation_impl() const {
          100   return *m_precipitation;
          101 }
          102 
          103 const IceModelVec2S& WeatherStation::mean_annual_temp_impl() const {
          104   return *m_temperature;
          105 }
          106 
          107 void WeatherStation::begin_pointwise_access_impl() const {
          108   // empty
          109 }
          110 
          111 void WeatherStation::end_pointwise_access_impl() const {
          112   // empty
          113 }
          114 
          115 void WeatherStation::init_timeseries_impl(const std::vector<double> &ts) const {
          116   size_t N = ts.size();
          117 
          118   m_precip_values.resize(N);
          119   m_air_temp_values.resize(N);
          120 
          121   for (unsigned int k = 0; k < N; ++k) {
          122     m_precip_values[k]   = m_precipitation_timeseries(ts[k]);
          123     m_air_temp_values[k] = m_air_temp_timeseries(ts[k]);
          124   }
          125 }
          126 
          127 void WeatherStation::precip_time_series_impl(int i, int j, std::vector<double> &result) const {
          128   (void)i;
          129   (void)j;
          130 
          131   result = m_precip_values;
          132 }
          133 
          134 void WeatherStation::temp_time_series_impl(int i, int j, std::vector<double> &result) const {
          135   (void)i;
          136   (void)j;
          137 
          138   result = m_air_temp_values;
          139 }
          140 
          141 } // end of namespace atmosphere
          142 } // end of namespace pism