Alpine3D  Alpine3D-3.1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
SnowpackInterface.h
Go to the documentation of this file.
1 /***********************************************************************************/
2 /* Copyright 2009-2015 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
3 /***********************************************************************************/
4 /* This file is part of Alpine3D.
5  Alpine3D is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Alpine3D is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with Alpine3D. If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef SNOWPACKINTERFACE_H
19 #define SNOWPACKINTERFACE_H
20 
21 #include <iostream>
22 #include <meteoio/MeteoIO.h>
23 #include <snowpack/libsnowpack.h>
24 
26 class SnowDriftA3D;
27 class Runoff; // forward declaration, cyclic header include
28 
30 #include <alpine3d/runoff/Runoff.h>
33 #include <alpine3d/Glaciers.h>
34 
122  {
123  public:
124  // Methods for accessing Snopack Interface Manager
125  SnowpackInterface(const mio::Config &io_cfg, const size_t& nbworkers,
126  const mio::DEMObject& dem_in,
127  const mio::Grid2DObject& landuse_in, const std::vector<mio::Coords>& vec_pts, const mio::Date& startTime, const std::string& grids_requirements, const bool is_restart_in);
130 
132 
133  double getTiming() const;
134  void writeOutput(const mio::Date& julian);
135  void writeOutputSNO(const mio::Date& julian);
136 
137  // Methods to set other modules
138  void setSnowDrift(SnowDriftA3D& drift);
139  void setEnergyBalance(EnergyBalance& myeb);
140  void setDataAssimilation(DataAssimilation& init_da);
141  void setRunoff(Runoff& init_runoff);
142 
143  // Methods to communicate with other modules
144  void assimilate(const mio::Grid2DObject& daData, const mio::Date& timestamp);
145  void setSnowMassChange(const mio::Grid2DObject& new_mns, const mio::Date& timestamp);
146  void setMeteo(const mio::Grid2DObject& new_psum,
147  const mio::Grid2DObject& new_psum_ph,
148  const mio::Grid2DObject& new_vw,
149  const mio::Grid2DObject& new_rh,
150  const mio::Grid2DObject& new_ta,
151  const mio::Date& timestamp);
152  void setRadiationComponents(const mio::Array2D<double>& shortw,
153  const mio::Array2D<double>& longwave,
154  const mio::Array2D<double>& diff,
155  const double& solarElevation,
156  const mio::Date& timestamp);
157 
158  void getGrid(const SnGrids::Parameters& param, mio::Grid2DObject& o_grid2D);
159 
160  private:
161  std::string getGridsRequirements() const;
162  void readAndTweakConfig(const mio::Config& io_cfg);
163  static void uniqueOutputGrids(std::vector<std::string>& output_grids);
164  bool do_grid_output(const mio::Date &date) const;
165  void calcNextStep();
166 
167  void readInitalSnowCover(std::vector<SnowStation*>& snow_stations);
168  void readSnowCover(const std::string& GRID_sno, const std::string& LUS_sno, const std::string& sno_type,
169  const bool& is_special_point, SN_SNOWSOIL_DATA &sno, ZwischenData &zwischenData);
170  void writeSnowCover(const mio::Date& date, const std::vector<SnowStation*>& snow_station);
171 
172  void write_SMET_header(const mio::StationData& meta, const double& landuse_code) const;
173  void write_SMET(const CurrentMeteo& met, const mio::StationData& meta, const SurfaceFluxes& surf) const;
174  void writeOutputSpecialPoints(const mio::Date& date, const std::vector<SnowStation*>& snow_pixel, const std::vector<CurrentMeteo*>& meteo_pixel,
175  const std::vector<SurfaceFluxes*>& surface_flux);
176  void write_special_points();
177 
178  // simulation dependent information
179  RunInfo run_info;
180  AsciiIO asciiIO;
181  SmetIO smetIO;
182  size_t dimx, dimy;
183 
184  mio::Grid2DObject landuse;
185 
186  // meteo forcing variables
187  mio::Grid2DObject mns, shortwave, longwave, diffuse;
188  mio::Grid2DObject psum, psum_ph, vw, rh, ta;
189  double solarElevation;
190 
191  std::vector<std::string> output_grids; //which grids should be written out
192  std::vector<SnowpackInterfaceWorker*> workers;
193  std::vector<size_t> worker_startx; // stores offset for each workers slice
194  std::vector<size_t> worker_deltax; // stores size for each workers slize
195 
196  // time relevant
197  mio::Timer timer; // used to mesure calc time of one step
198  mio::Date nextStepTimestamp;
199  double timeStep; // size of timestep
200 
201  // ==== other Modules ====
202  SnowDriftA3D *drift;
203  EnergyBalance *eb;
204  DataAssimilation *da;
205  Runoff *runoff;
206  bool dataMeteo2D, dataDa, dataSnowDrift, dataRadiation; // say, if data are present vor the actuall step
207 
208  // MeteoIO
209  mio::IOManager io;
210 
211  // Output
212  std::string outpath;
213  bool mask_glaciers; //mask glaciers in outputs?
214  bool mask_dynamic; //mask glaciers in outputs changes over time?
215  mio::Grid2DObject maskGlacier; // save the mask
216 
217  bool glacier_katabatic_flow;
218  Glaciers *glaciers;
219 
220  SnowpackConfig sn_cfg;
221  const mio::DEMObject dem;
222  bool is_restart, useCanopy;
223  bool do_io_locally; // if false all I/O will only be done on the master process
224  std::string station_name; // value for the key OUTPUT::EXPERIMENT
225 
226  double soil_temp_depth; //if set, output the soil temperatures at this depth.
227  double grids_start, grids_days_between; //gridded outputs
228  double ts_start, ts_days_between; //time series outputs
229  double prof_start, prof_days_between; //profiles outputs
230  bool grids_write, ts_write, prof_write, snow_write, snow_poi_written;
231  std::string meteo_outpath;
232  double tz_out;
233  std::vector< std::pair<size_t,size_t> > pts; //special points
234 };
235 
236 #endif
void setRunoff(Runoff &init_runoff)
Definition: SnowpackInterface.cc:474
void writeOutput(const mio::Date &julian)
Internal in Snowpack Interface Master used method to write standard results in output files...
Definition: SnowpackInterface.cc:336
void setSnowMassChange(const mio::Grid2DObject &new_mns, const mio::Date &timestamp)
Interface that SnowDrift can push the data to the SnowpackInterface.
Definition: SnowpackInterface.cc:528
void setMeteo(const mio::Grid2DObject &new_psum, const mio::Grid2DObject &new_psum_ph, const mio::Grid2DObject &new_vw, const mio::Grid2DObject &new_rh, const mio::Grid2DObject &new_ta, const mio::Date &timestamp)
get Meteo changes from AlpineControl or SnowDrift module
Definition: SnowpackInterface.cc:559
void setSnowDrift(SnowDriftA3D &drift)
Set reference to SnowDrift module, to comunicate with it.
Definition: SnowpackInterface.cc:429
~SnowpackInterface()
Destructor of SnowpackInterface Master. Handels special cases with POP-C++ and also free correctly ru...
Definition: SnowpackInterface.cc:310
void setRadiationComponents(const mio::Array2D< double > &shortw, const mio::Array2D< double > &longwave, const mio::Array2D< double > &diff, const double &solarElevation, const mio::Date &timestamp)
get values from Energy Balance
Definition: SnowpackInterface.cc:597
void setEnergyBalance(EnergyBalance &myeb)
Set reference to EnergyBalance module, to comunicate with it.
Definition: SnowpackInterface.cc:451
void setDataAssimilation(DataAssimilation &init_da)
Set reference to DataAssimilation module, to comunicate with it.
Definition: SnowpackInterface.cc:469
Definition: SnowDrift.h:71
Definition: SnowpackInterfaceWorker.h:75
SnowpackInterface & operator=(const SnowpackInterface &)
Assignement operator, required because of pointer member.
Definition: SnowpackInterface.cc:171
Definition: EnergyBalance.h:69
Definition: SnowpackInterface.h:121
void assimilate(const mio::Grid2DObject &daData, const mio::Date &timestamp)
Interface that DataAssimilation can push the data to the SnowpackInterface This is currently never us...
Definition: SnowpackInterface.cc:485
Parameters
Definition: SnowpackInterfaceWorker.h:28
Definition: Runoff.h:82
double getTiming() const
get time who was used to exchange Data with Workers and run on each Pixel the Snowpack Model throught...
Definition: SnowpackInterface.cc:322
Definition: Glaciers.h:47
void writeOutputSNO(const mio::Date &julian)
commands worker to write .sno files. Is triggered by Alpine Control
Definition: SnowpackInterface.cc:383
void getGrid(const SnGrids::Parameters &param, mio::Grid2DObject &o_grid2D)
Request specific grid by parameter type.
Definition: SnowpackInterface.cc:621
SnowpackInterface(const mio::Config &io_cfg, const size_t &nbworkers, const mio::DEMObject &dem_in, const mio::Grid2DObject &landuse_in, const std::vector< mio::Coords > &vec_pts, const mio::Date &startTime, const std::string &grids_requirements, const bool is_restart_in)
Constructs and initialise Snowpack Interface Master. He creates the Worker and Distributes the Data f...
Definition: SnowpackInterface.cc:74
Definition: DataAssimilation.h:30