Alpine3D  Alpine3D-3.2.0
SnowpackInterfaceWorker.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* This file is part of Alpine3D.
3  Alpine3D is free software: you can redistribute it and/or modify
4  it under the terms of the GNU Lesser General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Alpine3D is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU Lesser General Public License for more details.
12 
13  You should have received a copy of the GNU Lesser General Public License
14  along with Alpine3D. If not, see <http://www.gnu.org/licenses/>.
15 */
16 #ifndef SNOWPACKINTERFACEWORKER_H
17 #define SNOWPACKINTERFACEWORKER_H
18 
22 #include <alpine3d/runoff/Runoff.h>
23 #include <alpine3d/MeteoObj.h> //for the SnGrids
24 #include <snowpack/libsnowpack.h> //for TechSnow
25 
27 {
28  public:
29  SnowpackInterfaceWorker(const mio::Config& io_cfg,
30  const mio::DEMObject& dem_in,
31  const mio::Grid2DObject& landuse_in,
32  const std::vector< std::pair<size_t,size_t> >& pts_in,
33  const std::vector<SnowStation*>& snow_stations,
34  const std::vector<std::pair<size_t,size_t> >& snow_stations_coord,
35  const size_t offset_in);
36 
38 
39  void setUseDrift(const bool useDrift_in) {useDrift = useDrift_in;}
40  void setUseEBalance(const bool useEBalance_in) {useEBalance = useEBalance_in;}
41  void getOutputSNO(std::vector<SnowStation*>& snow_station) const;
42  void getOutputSpecialPoints(std::vector<SnowStation*>& ptr_snow_pixel, std::vector<CurrentMeteo*>& ptr_meteo_pixel,
43  std::vector<SurfaceFluxes*>& ptr_surface_flux);
45 
46  mio::Grid2DObject getGrid(const SnGrids::Parameters& param) const;
47  double& getGridPoint(const SnGrids::Parameters& param, const size_t& ii, const size_t& jj);
48 
49  void runModel(const mio::Date& julian,
50  const mio::Grid2DObject &psum,
51  const mio::Grid2DObject &psum_ph,
52  const mio::Grid2DObject &psum_tech,
53  const mio::Grid2DObject &rh,
54  const mio::Grid2DObject &ta,
55  const mio::Grid2DObject &vw,
56  const mio::Grid2DObject &dw,
57  const mio::Grid2DObject &mns,
58  const mio::Grid2DObject &shortwave,
59  const mio::Grid2DObject &diffuse,
60  const mio::Grid2DObject &longwave,
61  const double solarElevation);
62 
63  void grooming(const mio::Date &current_date, const mio::Grid2DObject &grooming_map);
64 
65  static int round_landuse(const double& landuse_dbl);
66  static bool skipThisCell(const double& landuse_val, const double& dem_val);
67  static bool is_special(const std::vector< std::pair<size_t,size_t> >& pts_in, const size_t& ix, const size_t& iy);
68  static void uniqueOutputGrids(std::vector<std::string>& output_grids);
69  void getLateralFlow(std::vector<SnowStation*>& snow_station);
70  void setLateralFlow(const std::vector<SnowStation*>& snow_station);
71 
72  private:
73  void initGrids(std::vector<std::string>& params);
74  void gatherSpecialPoints(const CurrentMeteo& meteoPixel, const SnowStation& snowPixel, const SurfaceFluxes& surfaceFlux);
75  void fillGrids(const size_t& ii, const size_t& jj, const CurrentMeteo& meteoPixel, const SnowStation& snowPixel, const SurfaceFluxes& surfaceFlux);
76 
77  private:
78  SnowpackConfig sn_cfg; // created on element
79  Snowpack sn;
80  Meteo meteo;
81  Stability stability;
82  TechSnow sn_techsnow;
83 
84  const mio::DEMObject dem;
85  const size_t dimx, dimy, offset;
86  std::vector<SnowStation*> SnowStations; // Save different Pixel values
87  std::vector<std::pair<size_t,size_t> > SnowStationsCoord;
88  std::vector<bool> isSpecialPoint;
89 
90  const mio::Grid2DObject landuse;
91  mio::Grid2DObject store;
92  std::map< SnGrids::Parameters, mio::Grid2DObject > grids;
93 
94  // cache special point data for output on master process:
95  std::vector<SnowStation> snow_pixel;
96  std::vector<CurrentMeteo> meteo_pixel;
97  std::vector<SurfaceFluxes> surface_flux;
98  std::vector<double> soil_temp_depths;
99 
100  double calculation_step_length;
101  double height_of_wind_value;
102  double snow_temp_depth, snow_avg_temp_depth, snow_avg_rho_depth;
103  bool useDrift, useEBalance, useCanopy;
104 };
105 
106 #endif
mio::Grid2DObject getGrid(const SnGrids::Parameters &param) const
Method that the Master can search the neded data (in grids) from Worker (Pull from client) ...
Definition: SnowpackInterfaceWorker.cc:276
void runModel(const mio::Date &julian, const mio::Grid2DObject &psum, const mio::Grid2DObject &psum_ph, const mio::Grid2DObject &psum_tech, const mio::Grid2DObject &rh, const mio::Grid2DObject &ta, const mio::Grid2DObject &vw, const mio::Grid2DObject &dw, const mio::Grid2DObject &mns, const mio::Grid2DObject &shortwave, const mio::Grid2DObject &diffuse, const mio::Grid2DObject &longwave, const double solarElevation)
method which prepares all data for simulation and then access correctly the Snowpack model interfaces...
Definition: SnowpackInterfaceWorker.cc:431
void setUseEBalance(const bool useEBalance_in)
Definition: SnowpackInterfaceWorker.h:40
void clearSpecialPointsData()
Definition: SnowpackInterfaceWorker.cc:243
void setLateralFlow(const std::vector< SnowStation *> &snow_station)
method called by SnowpackInterface to send back the source/sink term for treating lateral flow ...
Definition: SnowpackInterfaceWorker.cc:711
void getOutputSNO(std::vector< SnowStation *> &snow_station) const
method that returns SnowCover files for specific date.
Definition: SnowpackInterfaceWorker.cc:254
static void uniqueOutputGrids(std::vector< std::string > &output_grids)
Make sure all requested grids only appear once.
Definition: SnowpackInterfaceWorker.cc:202
Definition: SnowpackInterfaceWorker.h:26
void grooming(const mio::Date &current_date, const mio::Grid2DObject &grooming_map)
Definition: SnowpackInterfaceWorker.cc:636
static bool is_special(const std::vector< std::pair< size_t, size_t > > &pts_in, const size_t &ix, const size_t &iy)
Definition: SnowpackInterfaceWorker.cc:686
~SnowpackInterfaceWorker()
Definition: SnowpackInterfaceWorker.cc:188
Parameters
Definition: MeteoObj.h:32
void getOutputSpecialPoints(std::vector< SnowStation *> &ptr_snow_pixel, std::vector< CurrentMeteo *> &ptr_meteo_pixel, std::vector< SurfaceFluxes *> &ptr_surface_flux)
Definition: SnowpackInterfaceWorker.cc:232
double & getGridPoint(const SnGrids::Parameters &param, const size_t &ii, const size_t &jj)
Retrieve one point (ii,jj) from the specified grid.
Definition: SnowpackInterfaceWorker.cc:293
static bool skipThisCell(const double &landuse_val, const double &dem_val)
check if a cell should be simulated or skipped
Definition: SnowpackInterfaceWorker.cc:671
static int round_landuse(const double &landuse_dbl)
optimised way to round landuse
Definition: SnowpackInterfaceWorker.cc:661
void setUseDrift(const bool useDrift_in)
Definition: SnowpackInterfaceWorker.h:39
SnowpackInterfaceWorker(const mio::Config &io_cfg, const mio::DEMObject &dem_in, const mio::Grid2DObject &landuse_in, const std::vector< std::pair< size_t, size_t > > &pts_in, const std::vector< SnowStation *> &snow_stations, const std::vector< std::pair< size_t, size_t > > &snow_stations_coord, const size_t offset_in)
Constructs and initialise Snowpack Interface Worker. Create one worker and init values for slice whic...
Definition: SnowpackInterfaceWorker.cc:127
void getLateralFlow(std::vector< SnowStation *> &snow_station)
method called by SnowpackInterface to retrieve all snow_pixels, to read the lateral flow variable ...
Definition: SnowpackInterfaceWorker.cc:699