Alpine3D  Alpine3D-3.2.0
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 #include <alpine3d/MeteoObj.h>
25 
27 class SnowDriftA3D;
28 class Runoff; // forward declaration, cyclic header include
29 
31 #include <alpine3d/runoff/Runoff.h>
34 #include <alpine3d/Glaciers.h>
35 #include <alpine3d/TechSnowA3D.h>
36 
128  {
129  public:
130  // Methods for accessing Snopack Interface Manager
131  SnowpackInterface(const mio::Config &io_cfg, const size_t& nbworkers,
132  const mio::DEMObject& dem_in,
133  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);
136 
138 
139  double getTiming() const;
140  void writeOutput(const mio::Date& julian);
141  void writeOutputSNO(const mio::Date& julian);
142 
143  // Methods to set other modules
144  void setSnowDrift(SnowDriftA3D& drift);
145  void setEnergyBalance(EnergyBalance& myeb);
146  void setDataAssimilation(DataAssimilation& init_da);
147  void setRunoff(Runoff& init_runoff);
148 
149  // Methods to communicate with other modules
150  void assimilate(const mio::Grid2DObject& daData, const mio::Date& timestamp);
151  void setSnowMassChange(const mio::Grid2DObject& new_mns, const mio::Date& timestamp);
152  void setMeteo(const mio::Grid2DObject& new_psum,
153  const mio::Grid2DObject& new_psum_ph,
154  const mio::Grid2DObject& new_vw,
155  const mio::Grid2DObject& new_dw,
156  const mio::Grid2DObject& new_rh,
157  const mio::Grid2DObject& new_ta,
158  const mio::Date& timestamp);
159  void setRadiationComponents(const mio::Array2D<double>& shortw,
160  const mio::Array2D<double>& longwave,
161  const mio::Array2D<double>& diff,
162  const double& solarElevation,
163  const mio::Date& timestamp);
164 
165  mio::Grid2DObject getGrid(const SnGrids::Parameters& param) const;
166 
167  private:
168  std::string getGridsRequirements() const;
169  mio::Config readAndTweakConfig(const mio::Config& io_cfg,const bool have_pts);
170  bool do_grid_output(const mio::Date &date) const;
171  void calcNextStep();
172  void setInitGlacierHeight();
173  SN_SNOWSOIL_DATA getIcePixel(const double glacier_height, const std::stringstream& GRID_sno, const bool seaIce);
174  void readInitalSnowCover(std::vector<SnowStation*>& snow_stations,
175  std::vector<std::pair<size_t,size_t> >& snow_stations_coord);
176  void readSnowCover(const std::string& GRID_sno, const std::string& LUS_sno, const bool& is_special_point,
177  SN_SNOWSOIL_DATA &sno, ZwischenData &zwischenData, const bool& read_seaice);
178  void writeSnowCover(const mio::Date& date, const std::vector<SnowStation*>& snow_station);
179 
180  void write_SMET_header(const mio::StationData& meta, const double& landuse_code) const;
181  void write_SMET(const CurrentMeteo& met, const mio::StationData& meta, const SurfaceFluxes& surf) const;
182  void writeOutputSpecialPoints(const mio::Date& date, const std::vector<SnowStation*>& snow_pixel, const std::vector<CurrentMeteo*>& meteo_pixel,
183  const std::vector<SurfaceFluxes*>& surface_flux);
184  void write_special_points();
185  void calcLateralFlow();
186 
187  RunInfo run_info;
188 
189  // MeteoIO, used to output grids
190  mio::IOManager io;
191 
192  std::vector< std::pair<size_t,size_t> > pts; //special points
193 
194  const mio::DEMObject dem;
195 
196  // Config dependent information
197  bool is_restart, useCanopy, enable_lateral_flow, a3d_view;
198  bool do_io_locally; // if false all I/O will only be done on the master process
199  std::string station_name; // value for the key OUTPUT::EXPERIMENT
200  bool glacier_katabatic_flow, snow_production, snow_grooming;
201  // Output
202  std::vector<std::string> Tsoil_idx; //TSOIL names in order to build the "field" header of the smet output
203  double grids_start, grids_days_between; //gridded outputs
204  double ts_start, ts_days_between; //time series outputs
205  double prof_start, prof_days_between; //profiles outputs
206  bool grids_write, ts_write, prof_write, snow_write, snow_poi_written, glacier_from_grid;
207  std::string meteo_outpath;
208  std::string outpath;
209  bool mask_glaciers; //mask glaciers in outputs?
210  bool mask_dynamic; //mask glaciers in outputs changes over time?
211  mio::Grid2DObject maskGlacier; // save the mask
212  double tz_out;
213 
214  SnowpackConfig sn_cfg;
215  // SnowpackIO, used to output non grids data
216  SnowpackIO snowpackIO;
217 
218  size_t dimx, dimy;
219  size_t mpi_offset, mpi_nx;
220  mio::Grid2DObject landuse;
221  // meteo forcing variables
222  mio::Grid2DObject mns, shortwave, longwave, diffuse;
223  mio::Grid2DObject psum, psum_ph, psum_tech, grooming, vw, dw, rh, ta, init_glaciers_height;
224  double solarElevation;
225 
226  std::vector<std::string> output_grids; //which grids should be written out
227  std::vector<SnowpackInterfaceWorker*> workers;
228  std::vector<size_t> worker_startx; // stores offset for each workers slice
229  std::vector<size_t> worker_deltax; // stores size for each workers slize
230  std::vector<std::vector<std::pair<size_t,size_t> > > worker_stations_coord; // ttores te grid coordiante of each worker
231  // time relevant
232  mio::Timer timer; // used to mesure calc time of one step
233  mio::Date nextStepTimestamp;
234  double timeStep; // size of timestep
235 
236  bool dataMeteo2D, dataDa, dataSnowDrift, dataRadiation; // say, if data are present for the actuall step
237 
238  // ==== other Modules ====
239  SnowDriftA3D *drift;
240  EnergyBalance *eb;
241  DataAssimilation *da;
242  Runoff *runoff;
243 
244  Glaciers *glaciers;
245  TechSnowA3D *techSnow;
246 };
247 
248 #endif
void setRunoff(Runoff &init_runoff)
Definition: SnowpackInterface.cc:546
void writeOutput(const mio::Date &julian)
Internal in Snowpack Interface Master used method to write standard results in output files...
Definition: SnowpackInterface.cc:392
void setSnowMassChange(const mio::Grid2DObject &new_mns, const mio::Date &timestamp)
Interface that SnowDrift can push the data to the SnowpackInterface.
Definition: SnowpackInterface.cc:600
void setSnowDrift(SnowDriftA3D &drift)
Set reference to SnowDrift module, to comunicate with it.
Definition: SnowpackInterface.cc:502
~SnowpackInterface()
Destructor of SnowpackInterface Master. Handels special cases with POP-C++ and also free correctly ru...
Definition: SnowpackInterface.cc:366
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:677
void setEnergyBalance(EnergyBalance &myeb)
Set reference to EnergyBalance module, to comunicate with it.
Definition: SnowpackInterface.cc:523
mio::Grid2DObject getGrid(const SnGrids::Parameters &param) const
Request specific grid by parameter type.
Definition: SnowpackInterface.cc:701
void setDataAssimilation(DataAssimilation &init_da)
Set reference to DataAssimilation module, to comunicate with it.
Definition: SnowpackInterface.cc:541
Definition: SnowDrift.h:78
Definition: SnowpackInterfaceWorker.h:26
SnowpackInterface & operator=(const SnowpackInterface &)
Assignement operator, required because of pointer member.
Definition: SnowpackInterface.cc:237
Definition: EnergyBalance.h:68
Definition: SnowpackInterface.h:127
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:557
Definition: TechSnowA3D.h:70
Parameters
Definition: MeteoObj.h:32
Definition: Runoff.h:82
Definition: Glaciers.h:47
void setMeteo(const mio::Grid2DObject &new_psum, const mio::Grid2DObject &new_psum_ph, const mio::Grid2DObject &new_vw, const mio::Grid2DObject &new_dw, 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:632
void writeOutputSNO(const mio::Date &julian)
commands worker to write .sno files. Is triggered by Alpine Control
Definition: SnowpackInterface.cc:456
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:378
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:76
Definition: DataAssimilation.h:30