Alpine3D 20240428.cd14b8b
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
27class SnowDriftA3D;
28
32#include <alpine3d/Glaciers.h>
34
126 {
127 public:
128 // Methods for accessing Snowpack Interface Manager
129 SnowpackInterface(const mio::Config &io_cfg, const size_t& nbworkers,
130 const mio::DEMObject& dem_in,
131 const mio::Grid2DObject& landuse_in, const std::vector<mio::Coords>& vec_pts,
132 const mio::Date& startTime, const std::string& grids_requirements, const bool is_restart_in);
135
137
138 double getTiming() const;
139 void writeOutput(const mio::Date& julian);
140 void writeOutputSNO(const mio::Date& julian);
141
142 // Methods to set other modules
143 void setSnowDrift(SnowDriftA3D& drift);
146
147 // Methods to communicate with other modules
148 void setSnowDrift();
149 void setEnergyBalance();
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 mio::Array2D<double>& terrain_shortwave_in,
163 const mio::Array2D<double>& terrain_longwave_in,
164 const double& solarElevation,
165 const mio::Date& timestamp);
166
167 mio::Grid2DObject getGrid(const SnGrids::Parameters& param) const;
168 void calcNextStep();
169
170 private:
171 static const std::vector<std::string> grids_not_computed_in_worker;
172 std::string getGridsRequirements() const;
173 mio::Config readAndTweakConfig(const mio::Config& io_cfg,const bool have_pts);
174 bool do_grid_output(const mio::Date &date) const;
175 void setInitGlacierThickness();
176 SN_SNOWSOIL_DATA getIcePixel(const double glacier_thickness, const std::stringstream& GRID_sno, const bool seaIce);
177 void readInitalSnowCover(std::vector<SnowStation*>& snow_stations,
178 std::vector<std::pair<size_t,size_t> >& snow_stations_coord);
179 void readSnowCover(const std::string& GRID_sno, const std::string& LUS_sno, const bool& is_special_point,
180 SN_SNOWSOIL_DATA &sno, ZwischenData &zwischenData, const bool& read_seaice);
181 void writeSnowCover(const mio::Date& date, const std::vector<SnowStation*>& snow_station);
182
183 void write_SMET_header(const mio::StationData& meta, const double& landuse_code) const;
184 void write_SMET(const CurrentMeteo& met, const mio::StationData& meta, const SurfaceFluxes& surf) const;
185 void writeOutputSpecialPoints(const mio::Date& date, const std::vector<SnowStation*>& snow_pixel, const std::vector<CurrentMeteo*>& meteo_pixel,
186 const std::vector<SurfaceFluxes*>& surface_flux);
187 void write_special_points();
188 void calcLateralFlow();
189
190 RunInfo run_info;
191
192 // MeteoIO, used to output grids
193 mio::IOManager io;
194
195 std::vector< std::pair<size_t,size_t> > pts; //special points
196
197 const mio::DEMObject dem; // full DEM
198 mio::DEMObject omp_dem; // DEM shared by OMP workers (after MPI slicing)
199
200 // Config dependent information
201 bool is_restart, useCanopy, enable_lateral_flow, a3d_view;
202 bool do_io_locally; // if false all I/O will only be done on the master process
203 std::string station_name; // value for the key OUTPUT::EXPERIMENT
204 bool glacier_katabatic_flow, snow_production, snow_grooming;
205 // Output
206 std::vector<std::string> Tsoil_idx; //TSOIL names in order to build the "field" header of the smet output
207 std::vector<std::string> soil_runoff_idx; // Runoff depths names in order to build the "field" header of the smet output
208 double grids_start, grids_days_between; //gridded outputs
209 double ts_start, ts_days_between; //time series outputs
210 double prof_start, prof_days_between; //profiles outputs
211 bool grids_write, ts_write, prof_write, snow_write, write_poi_meteo, snow_poi_written, glacier_from_grid;
212 std::string meteo_outpath;
213 std::string outpath;
214 bool mask_glaciers; //mask glaciers in outputs?
215 bool mask_dynamic; //mask glaciers in outputs changes over time?
216 mio::Grid2DObject maskGlacier; // save the mask
217 double tz_out;
218
219 SnowpackConfig sn_cfg;
220 // SnowpackIO, used to output non grids data
221 SnowpackIO snowpackIO;
222
223 size_t dimx, dimy;
224 size_t mpi_offset, mpi_nx;
225 mio::Grid2DObject landuse, omp_landuse; // full land use map, and land use map shared by OMP workers (after MPI slicing)
226 // meteo forcing variables
227 mio::Grid2DObject mns, shortwave, longwave, diffuse, terrain_shortwave, terrain_longwave;
228 mio::Grid2DObject psum, psum_ph, psum_tech, grooming, vw, dw, rh, ta, init_glaciers_thickness;
229 double solarElevation;
230
231 std::vector<std::string> output_grids; //which grids should be written out
232 std::vector<SnowpackInterfaceWorker*> workers;
233 std::vector<size_t> worker_startx; // stores offset for each workers slice
234 std::vector<size_t> worker_deltax; // stores size for each workers slize
235 std::vector<std::vector<std::pair<size_t,size_t> > > worker_stations_coord; // stores the grid coordinates of each worker
236 // time relevant
237 mio::Timer timer; // used to measure calc time of one step
238 mio::Date nextStepTimestamp;
239 double timeStep; // size of timestep
240
241 bool dataMeteo2D, dataDa, dataSnowDrift, dataRadiation; // say, if data are present for the actual step
242
243 // ==== other Modules ====
244 SnowDriftA3D *drift;
245 EnergyBalance *eb;
247
248 Glaciers *glaciers;
249 TechSnowA3D *techSnow;
250};
251
252#endif
Definition: DataAssimilation.h:30
Definition: EnergyBalance.h:70
Definition: Glaciers.h:48
Parameters
this enum provides names for possible Snowpack grids
Definition: MeteoObj.h:33
Definition: SnowDrift.h:78
Definition: SnowpackInterfaceWorker.h:26
Definition: SnowpackInterface.h:126
void setSnowMassChange(const mio::Grid2DObject &new_mns, const mio::Date &timestamp)
Interface that SnowDrift can push the data to the SnowpackInterface.
Definition: SnowpackInterface.cc:667
SnowpackInterface & operator=(const SnowpackInterface &)
Assignment operator, required because of pointer member.
Definition: SnowpackInterface.cc:292
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:625
void setRadiationComponents(const mio::Array2D< double > &shortw, const mio::Array2D< double > &longwave, const mio::Array2D< double > &diff, const mio::Array2D< double > &terrain_shortwave_in, const mio::Array2D< double > &terrain_longwave_in, const double &solarElevation, const mio::Date &timestamp)
get values from Energy Balance
Definition: SnowpackInterface.cc:742
mio::Grid2DObject getGrid(const SnGrids::Parameters &param) const
Request specific grid by parameter type.
Definition: SnowpackInterface.cc:772
void setSnowDrift()
Send required fields to SnowDrift module.
Definition: SnowpackInterface.cc:570
void writeOutput(const mio::Date &julian)
Internal in Snowpack Interface Master used method to write standard results in output files....
Definition: SnowpackInterface.cc:450
void writeOutputSNO(const mio::Date &julian)
commands worker to write .sno files. Is triggered by Alpine Control
Definition: SnowpackInterface.cc:511
void setDataAssimilation(DataAssimilation &init_da)
Set reference to DataAssimilation module, to comunicate with it.
Definition: SnowpackInterface.cc:613
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:92
void setEnergyBalance()
Send required fields to EnergyBalance module.
Definition: SnowpackInterface.cc:600
void calcNextStep()
Get data from other modules and run one simulation step. Once the simulation step has been performed,...
Definition: SnowpackInterface.cc:840
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:698
~SnowpackInterface()
Destructor of SnowpackInterface Master. Handels special cases with POP-C++ and also free correctly wo...
Definition: SnowpackInterface.cc:425
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:436
SnowpackInterface(const SnowpackInterface &)
Definition: TechSnowA3D.h:71