Alpine3D 20241222.625fd38
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/MeteoObj.h> //for the SnGrids
23#include <snowpack/libsnowpack.h> //for TechSnow
24
26{
27 public:
28 SnowpackInterfaceWorker(const mio::Config& io_cfg,
29 const mio::DEMObject& dem_in,
30 const mio::Grid2DObject& landuse_in,
31 const std::vector< std::pair<size_t,size_t> >& pts_in,
32 const std::vector<SnowStation*>& snow_stations,
33 const std::vector<std::pair<size_t,size_t> >& snow_stations_coord,
34 const size_t offset_in,
35 const std::vector<std::string>& grids_not_computed_in_worker);
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
48 void runModel(const mio::Date& julian,
49 const mio::Grid2DObject &psum,
50 const mio::Grid2DObject &psum_ph,
51 const mio::Grid2DObject &psum_tech,
52 const mio::Grid2DObject &rh,
53 const mio::Grid2DObject &ta,
54 const mio::Grid2DObject &vw,
55 const mio::Grid2DObject &dw,
56 const mio::Grid2DObject &mns,
57 const mio::Grid2DObject &shortwave,
58 const mio::Grid2DObject &diffuse,
59 const mio::Grid2DObject &longwave,
60 const double solarElevation);
61
62 void grooming(const mio::Date &current_date, const mio::Grid2DObject &grooming_map);
63
64 static int round_landuse(const double& landuse_dbl);
65 static bool skipThisCell(const double& landuse_val, const double& dem_val);
66 static bool is_special(const std::vector< std::pair<size_t,size_t> >& pts_in, const size_t& ix, const size_t& iy);
67 static void uniqueOutputGrids(std::vector<std::string>& output_grids);
68 void getLateralFlow(std::vector<SnowStation*>& snow_station);
69 void setLateralFlow(const std::vector<SnowStation*>& snow_station);
70
71 private:
72 void initGrids(std::vector<std::string> params, const std::vector<std::string>& grids_not_computed_in_worker);
73 void gatherSpecialPoints(const CurrentMeteo& meteoPixel, const SnowStation& snowPixel, const SurfaceFluxes& surfaceFlux);
74 void fillGrids(const size_t& ii, const size_t& jj, const CurrentMeteo& meteoPixel, const SnowStation& snowPixel, const SurfaceFluxes& surfaceFlux);
75 double& getGridPoint(const SnGrids::Parameters& param, const size_t& ii, const size_t& jj);
76
77 public:
78 std::vector<std::pair<size_t,size_t> > SnowStationsCoord;
79
80 private:
81 SnowpackConfig sn_cfg; // created on element
82 Snowpack sn;
83 Meteo meteo;
84 Stability stability;
85 TechSnow sn_techsnow;
86
87 const mio::DEMObject& dem;
88 const size_t dimx, dimy, offset;
89 std::vector<SnowStation*> SnowStations; // Save different Pixel values
90 std::vector<bool> isSpecialPoint;
91
92 const mio::Grid2DObject& landuse;
93 mio::Grid2DObject store;
94 std::map< SnGrids::Parameters, mio::Grid2DObject > grids;
95
96 // cache special point data for output on master process:
97 std::vector<SnowStation> snow_pixel;
98 std::vector<CurrentMeteo> meteo_pixel;
99 std::vector<SurfaceFluxes> surface_flux;
100 std::vector<double> soil_temp_depths, soil_runoff_depths;
101
102 double calculation_step_length;
103 double height_of_wind_value;
104 double snow_temp_depth, snow_avg_temp_depth, snow_avg_rho_depth;
105 bool useDrift, useEBalance, useCanopy;
106};
107
108#endif
Parameters
this enum provides names for possible Snowpack grids
Definition: MeteoObj.h:33
Definition: SnowpackInterfaceWorker.h:26
void getOutputSpecialPoints(std::vector< SnowStation * > &ptr_snow_pixel, std::vector< CurrentMeteo * > &ptr_meteo_pixel, std::vector< SurfaceFluxes * > &ptr_surface_flux)
Definition: SnowpackInterfaceWorker.cc:279
static int round_landuse(const double &landuse_dbl)
optimised way to round landuse
Definition: SnowpackInterfaceWorker.cc:707
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:757
void setUseEBalance(const bool useEBalance_in)
Definition: SnowpackInterfaceWorker.h:40
static void uniqueOutputGrids(std::vector< std::string > &output_grids)
Make sure all requested grids only appear once.
Definition: SnowpackInterfaceWorker.cc:245
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, const std::vector< std::string > &grids_not_computed_in_worker)
Constructs and initialise Snowpack Interface Worker. Create one worker and init values for slice whic...
Definition: SnowpackInterfaceWorker.cc:157
void grooming(const mio::Date &current_date, const mio::Grid2DObject &grooming_map)
Definition: SnowpackInterfaceWorker.cc:682
std::vector< std::pair< size_t, size_t > > SnowStationsCoord
Definition: SnowpackInterfaceWorker.h:78
static bool skipThisCell(const double &landuse_val, const double &dem_val)
check if a cell should be simulated or skipped
Definition: SnowpackInterfaceWorker.cc:717
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:732
~SnowpackInterfaceWorker()
Definition: SnowpackInterfaceWorker.cc:231
void clearSpecialPointsData()
Definition: SnowpackInterfaceWorker.cc:290
void getOutputSNO(std::vector< SnowStation * > &snow_station) const
method that returns SnowCover files for specific date.
Definition: SnowpackInterfaceWorker.cc:301
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:745
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:323
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:470