Alpine3D

Alpine3D Svn Source Tree

Root/trunk/alpine3d/SnowpackInterface.h

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
26class SnowpackInterfaceWorker;
27class SnowDriftA3D;
28class Runoff; // forward declaration, cyclic header include
29
30#include <alpine3d/DataAssimilation.h>
31#include <alpine3d/runoff/Runoff.h>
32#include <alpine3d/snowdrift/SnowDrift.h>
33#include <alpine3d/SnowpackInterfaceWorker.h>
34#include <alpine3d/Glaciers.h>
35#include <alpine3d/TechSnowA3D.h>
36
37/**
38 * @page snowpack Snowpack
39 * This module call the Snowpack energy balance model on each relevant cell of the domain (see \ref principles_snowpack). The cells that are excluded
40 * are the following:
41 * - cells those altitude is nodata (in the dem);
42 * - cells those land cover is undefined/nodata (in the lus);
43 * - cells marked as "water body".
44 *
45 * During a parallel simulation, it is often more efficient (but not always possible) to let each node perform its I/O on its local disk instead
46 * of requesting the data from another single node. This is enabled with the LOCAL_IO key in the [General] section (default: true).
47 *
48 * Several corrections are applied on glaciated pixels: the albedo of such pixels is reset to a fixed glacier albedo when no snow is present
49 * and when the air temperature is higher than 5°C the atmospheric stability is forced to MONIN_OBUKHOV. It is also possible to apply an air
50 * temperature correction simulating the effect of katabatic flows by setting GLACIER_KATABATIC_FLOW to true in the [ALPINE3D] section (this is
51 * still an experimental feature).
52 *
53 * Several types of outputs are supported: gridded outputs and full snowpack stratigraphy.
54 *
55 * @section gridded_outputs Gridded outputs
56 * The gridded outputs are written out for all requested the parameters every GRIDS_DAYS_BETWEEN (in days), starting at GRIDS_START
57 * (in days, <i>0</i> being noon). The available parameters are provided in SnGrids::Parameters and should be written as a space delimited
58 * list of parameters as GRIDS_PARAMETERS key (in the [Output] section).
59 *
60 * It is possible to mask the glaciated areas (in order to keep a relevant scaling
61 * on snow water equivalent or similar parameters) either statically (performed once and for all at the begining of the run) or dynamically
62 * (performed at every time step). The criteria to decide if a pixel is glaciated is defined in Snowpack, in SnowStation::isGlacier(). This is
63 * currently defined as more than 2 meters of pure ice in the whole snowpack. The keys to enable glaciers masking and dynamic masking are
64 * MASK_GLACIERS and MASK_DYNAMIC in the [Output] section.
65 *
66 * Finally, the soil temperature at multiple given depths can be written out simply by setting the SOIL_TEMPERATURE_DEPTHS key in the [Output] section
67 * to the chosen depths (in meters). In this case, there is no need to declare a TSOILx parameter for the GRIDS_PARAMETERS key (it is currently limited
68 * to at most 5 different depths but could be increased in the future). It is possible to do the same in the snow at a given depth by setting
69 * the SNOW_TEMPERATURE_DEPTH key, or the average snow temperature from the surface until a given depth (SNOW_AVG_TEMPERATURE_DEPTH key) or the snow density from
70 * the surface until a given depth (SNOW_AVG_DENSITY_DEPTH key). When averaging either temperature or density, if the snow height is less
71 * than the requested depth, the average is performed on the whole snow pack.
72 *
73 * @code
74 * [Output]
75 * GRID2D = ARC
76 * A3D_VIEW = TRUE ;naming scheme compatible with the viewer of Alpine3D
77 * GRID2DPATH = ../output
78 * MASK_GLACIERS = TRUE
79 * MASK_DYNAMIC = FALSE
80 * SOIL_TEMPERATURE_DEPTHS = 0.1 0.5 1.5 ;output soil temperatures at 0.1m, 0.5m and 1.5m - leave this key out to skip this output
81 *
82 * GRIDS_WRITE = TRUE ;default
83 * GRIDS_START = 0.
84 * GRIDS_DAYS_BETWEEN = 1.
85 * GRIDS_PARAMETERS = HS SWE ISWR ILWR
86 * @endcode
87 *
88 * @subsection output_new_grids Writing new grids out
89 * If the parameters you want to write out do not already exist in SnGrids::Parameters, then you have a few extra steps to perform:
90 * -# add the parameter in SnGrids::Parameters as well as its string representation in SnGrids::initStaticData()
91 * -# add the proper code (similarly as for the already existing parameters) in SnowpackInterfaceWorker::fillGrids() (in some rare cases, this must be done in SnowpackInterface::getGrid() ie for parameters that only exist in SnowpackInterface);
92 * -# after recompiling, it will be possible to specify the newly created grid as explained in \ref gridded_outputs.
93 *
94 * Several Snowpack objects are available for the current point (and documented in Snowpack itself in the Dataclasses.h file):
95 * - meteoPixel is an object of type CurrentMeteo;
96 * - snowPixel is an object of type SnowStation (this also contains CanopyData, NodeData and ElementData);
97 * - surfaceFlux is an object of type SurfaceFluxes;
98 *
99 *
100 * @section poi_outputs Snow stratigraphy
101 * Full snowpack stratigraphy outputs are provided at specific Points Of Interest, as defined with the POI key in the [Input] section. These outputs
102 * contain time series of snow profiles and fluxes as well as meteorological forcing at these points, allowing to re-run these points manually in the
103 * Snowpack model. These outputs are written in the path pointed to by METEOPATH in the [Ouput] section. The time resolution is controlled similarly to
104 * standard Snowpack runs with the TS_WRITE and PROF_WRITE groups of keys (see Snowpack documentation).
105 *
106 * @code
107 * [Input]
108 * POI = A3D
109 * POIFILE = ../input/surface-grids/poi.pts
110 *
111 * [Output]
112 * PROF_WRITE = TRUE
113 * PROFILE_FORMAT = PRO
114 * PROF_START = 0.0
115 * PROF_DAYS_BETWEEN = 1.
116 *
117 * TS_WRITE = TRUE
118 * TS_START = 0.0
119 * TS_DAYS_BETWEEN = 1.
120 *
121 * METEO = SMET
122 * METEOPATH = ../output
123 * @endcode
124 *
125 *
126 */
127 class SnowpackInterface
128 {
129public:
130// Methods for accessing Snopack Interface Manager
131SnowpackInterface(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);
134SnowpackInterface(const SnowpackInterface&);
135~SnowpackInterface();
136
137SnowpackInterface& operator=(const SnowpackInterface&); ///<Assignement operator, required because of pointer member
138
139double getTiming() const;
140void writeOutput(const mio::Date& julian);
141void writeOutputSNO(const mio::Date& julian);
142
143// Methods to set other modules
144void setSnowDrift(SnowDriftA3D& drift);
145void setEnergyBalance(EnergyBalance& myeb);
146void setDataAssimilation(DataAssimilation& init_da);
147void setRunoff(Runoff& init_runoff);
148
149// Methods to communicate with other modules
150void assimilate(const mio::Grid2DObject& daData, const mio::Date& timestamp);
151void setSnowMassChange(const mio::Grid2DObject& new_mns, const mio::Date& timestamp);
152void 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);
159void 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
165mio::Grid2DObject getGrid(const SnGrids::Parameters& param) const;
166
167private:
168std::string getGridsRequirements() const;
169mio::Config readAndTweakConfig(const mio::Config& io_cfg,const bool have_pts);
170bool do_grid_output(const mio::Date &date) const;
171void calcNextStep();
172void setInitGlacierHeight();
173SN_SNOWSOIL_DATA getIcePixel(const double glacier_height, const std::stringstream& GRID_sno, const bool seaIce);
174void readInitalSnowCover(std::vector<SnowStation*>& snow_stations,
175 std::vector<std::pair<size_t,size_t> >& snow_stations_coord);
176void 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);
178void writeSnowCover(const mio::Date& date, const std::vector<SnowStation*>& snow_station);
179
180void write_SMET_header(const mio::StationData& meta, const double& landuse_code) const;
181void write_SMET(const CurrentMeteo& met, const mio::StationData& meta, const SurfaceFluxes& surf) const;
182void writeOutputSpecialPoints(const mio::Date& date, const std::vector<SnowStation*>& snow_pixel, const std::vector<CurrentMeteo*>& meteo_pixel,
183 const std::vector<SurfaceFluxes*>& surface_flux);
184void write_special_points();
185void calcLateralFlow();
186
187RunInfo run_info;
188
189// MeteoIO, used to output grids
190mio::IOManager io;
191
192std::vector< std::pair<size_t,size_t> > pts; //special points
193
194const mio::DEMObject dem;
195
196// Config dependent information
197bool is_restart, useCanopy, enable_lateral_flow, a3d_view;
198bool do_io_locally; // if false all I/O will only be done on the master process
199std::string station_name; // value for the key OUTPUT::EXPERIMENT
200bool glacier_katabatic_flow, snow_production, snow_grooming;
201// Output
202std::vector<std::string> Tsoil_idx; //TSOIL names in order to build the "field" header of the smet output
203double grids_start, grids_days_between; //gridded outputs
204double ts_start, ts_days_between; //time series outputs
205double prof_start, prof_days_between; //profiles outputs
206bool grids_write, ts_write, prof_write, snow_write, snow_poi_written, glacier_from_grid;
207std::string meteo_outpath;
208std::string outpath;
209bool mask_glaciers; //mask glaciers in outputs?
210bool mask_dynamic; //mask glaciers in outputs changes over time?
211mio::Grid2DObject maskGlacier; // save the mask
212double tz_out;
213
214SnowpackConfig sn_cfg;
215// SnowpackIO, used to output non grids data
216SnowpackIO snowpackIO;
217
218size_t dimx, dimy;
219size_t mpi_offset, mpi_nx;
220mio::Grid2DObject landuse;
221// meteo forcing variables
222mio::Grid2DObject mns, shortwave, longwave, diffuse;
223mio::Grid2DObject psum, psum_ph, psum_tech, grooming, vw, dw, rh, ta, init_glaciers_height;
224double solarElevation;
225
226std::vector<std::string> output_grids; //which grids should be written out
227std::vector<SnowpackInterfaceWorker*> workers;
228std::vector<size_t> worker_startx; // stores offset for each workers slice
229std::vector<size_t> worker_deltax; // stores size for each workers slize
230std::vector<std::vector<std::pair<size_t,size_t> > > worker_stations_coord; // ttores te grid coordiante of each worker
231// time relevant
232mio::Timer timer; // used to mesure calc time of one step
233mio::Date nextStepTimestamp;
234double timeStep; // size of timestep
235
236bool dataMeteo2D, dataDa, dataSnowDrift, dataRadiation; // say, if data are present for the actuall step
237
238// ==== other Modules ====
239SnowDriftA3D *drift;
240EnergyBalance *eb;
241DataAssimilation *da;
242Runoff *runoff;
243
244Glaciers *glaciers;
245TechSnowA3D *techSnow;
246};
247
248#endif

Archive Download this file

Revision: HEAD