Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/snowpack-model/snowpack i…
Browse files Browse the repository at this point in the history
…nto snowpack_core
  • Loading branch information
nwever committed Jan 31, 2023
2 parents 910bd89 + ed2ee29 commit 252bfec
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 7 deletions.
8 changes: 5 additions & 3 deletions Source/snowpack/applications/snowpack/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -423,11 +423,13 @@ inline void copyMeteoData(const mio::MeteoData& md, CurrentMeteo& Mdata,
Mdata.iswr = md(MeteoData::ISWR);
Mdata.rswr = md(MeteoData::RSWR);

Mdata.ea = md("EA");
if (md.param_exists("NET_LW"))
if (md.param_exists("NET_LW")) {
Mdata.ea = 1.;
Mdata.lw_net = md("NET_LW");
else
} else {
Mdata.ea = md("EA");
Mdata.lw_net = IOUtils::nodata;
}
Mdata.tss = md(MeteoData::TSS);
if (md.param_exists("TSS_A12H") && (md("TSS_A12H") != mio::IOUtils::nodata))
Mdata.tss_a12h = md("TSS_A12H");
Expand Down
7 changes: 5 additions & 2 deletions Source/snowpack/snowpack/DataClasses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1985,7 +1985,7 @@ SnowStation::SnowStation(const bool i_useCanopyModel, const bool i_useSoilLayers
#ifndef SNOWPACK_CORE
rime_hn(0.),
#endif
hn_redeposit(0.), rho_hn_redeposit(0.), ErosionLevel(0), ErosionMass(0.), ErosionLength(0.),
hn_redeposit(0.), rho_hn_redeposit(0.), ErosionLevel(0), ErosionMass(0.), ErosionLength(0.), ErosionAge(Constants::undefined),
#ifndef SNOWPACK_CORE
S_class1(0), S_class2(0), S_d(0.), z_S_d(0.), S_n(0.), z_S_n(0.),
S_s(0.), z_S_s(0.), S_4(0.), z_S_4(0.), S_5(0.), z_S_5(0.),
Expand Down Expand Up @@ -2015,7 +2015,7 @@ SnowStation::SnowStation(const SnowStation& c) :
#ifndef SNOWPACK_CORE
rime_hn(c.rime_hn),
#endif
hn_redeposit(c.hn_redeposit), rho_hn_redeposit(c.rho_hn_redeposit), ErosionLevel(c.ErosionLevel), ErosionMass(c.ErosionMass), ErosionLength(c.ErosionLength),
hn_redeposit(c.hn_redeposit), rho_hn_redeposit(c.rho_hn_redeposit), ErosionLevel(c.ErosionLevel), ErosionMass(c.ErosionMass), ErosionLength(c.ErosionLength), ErosionAge(c.ErosionAge),
#ifndef SNOWPACK_CORE
S_class1(c.S_class1), S_class2(c.S_class2), S_d(c.S_d), z_S_d(c.z_S_d), S_n(c.S_n), z_S_n(c.z_S_n),
S_s(c.S_s), z_S_s(c.z_S_s), S_4(c.S_4), z_S_4(c.z_S_4), S_5(c.S_5), z_S_5(c.z_S_5),
Expand Down Expand Up @@ -2076,6 +2076,7 @@ SnowStation& SnowStation::operator=(const SnowStation& source) {
ErosionLevel = source.ErosionLevel;
ErosionMass = source.ErosionMass;
ErosionLength = source.ErosionLength;
ErosionAge = source.ErosionAge;
#ifndef SNOWPACK_CORE
S_class1 = source.S_class1;
S_class2 = source.S_class2;
Expand Down Expand Up @@ -3035,6 +3036,7 @@ std::ostream& operator<<(std::ostream& os, const SnowStation& data)
os.write(reinterpret_cast<const char*>(&data.ErosionLevel), sizeof(data.ErosionLevel));
os.write(reinterpret_cast<const char*>(&data.ErosionMass), sizeof(data.ErosionMass));
os.write(reinterpret_cast<const char*>(&data.ErosionLength), sizeof(data.ErosionLength));
os.write(reinterpret_cast<const char*>(&data.ErosionAge), sizeof(data.ErosionAge));
#ifndef SNOWPACK_CORE
os.write(reinterpret_cast<const char*>(&data.S_class1), sizeof(data.S_class1));
os.write(reinterpret_cast<const char*>(&data.S_class2), sizeof(data.S_class2));
Expand Down Expand Up @@ -3129,6 +3131,7 @@ std::istream& operator>>(std::istream& is, SnowStation& data)
is.read(reinterpret_cast<char*>(&data.ErosionLevel), sizeof(data.ErosionLevel));
is.read(reinterpret_cast<char*>(&data.ErosionMass), sizeof(data.ErosionMass));
is.read(reinterpret_cast<char*>(&data.ErosionLength), sizeof(data.ErosionLength));
is.read(reinterpret_cast<char*>(&data.ErosionAge), sizeof(data.ErosionAge));
#ifndef SNOWPACK_CORE
is.read(reinterpret_cast<char*>(&data.S_class1), sizeof(data.S_class1));
is.read(reinterpret_cast<char*>(&data.S_class2), sizeof(data.S_class2));
Expand Down
1 change: 1 addition & 0 deletions Source/snowpack/snowpack/DataClasses.h
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,7 @@ class SnowStation {
size_t ErosionLevel; ///< Element where snow erosion stopped previously for the drift index
double ErosionMass; ///< Eroded mass either real or virtually (storage if less than one element)
double ErosionLength; ///< Snow height change dueo to eroded mass (only real erosion)
double ErosionAge; ///< Layer age of eroded snow layers
#ifndef SNOWPACK_CORE
char S_class1; ///< Stability class based on hand hardness, grain class ...
char S_class2; ///< Stability class based on hand hardness, grain class ...
Expand Down
2 changes: 1 addition & 1 deletion Source/snowpack/snowpack/Laws_sn.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ double SnLaws::newSnowDensityEvent(const std::string& variant, const SnLaws::Eve
const double vw_avg_ref = Meteo::windspeedProfile(Mdata, z_ref_vw, Mdata.vw_avg);
if ((vw_avg_ref >= event_wind_lowlim) && (vw_avg_ref <= event_wind_highlim)) {
static const double rho_0=361., rho_1=33.;
return (vw_avg_ref == 0.) ? (rho_1) : (std::max(rho_1, rho_0*log10(vw_avg_ref)) + rho_1);
return (vw_avg_ref == 0.) ? (rho_1) : (std::max(rho_1, rho_0*log10(vw_avg_ref) + rho_1));
} else
return Constants::undefined;
}
Expand Down
8 changes: 8 additions & 0 deletions Source/snowpack/snowpack/SnowDrift.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ void SnowDrift::compSnowDrift(const CurrentMeteo& Mdata, SnowStation& Xdata, Sur
const bool no_wind_data = (Mdata.vw_drift == mio::IOUtils::nodata);
Xdata.ErosionMass = 0.;
Xdata.ErosionLength = 0.;
Xdata.ErosionAge = 0.;
if (no_snow || no_wind_data) {
if (no_snow) {
Xdata.ErosionLevel = Xdata.SoilNode;
Expand Down Expand Up @@ -286,6 +287,7 @@ void SnowDrift::compSnowDrift(const CurrentMeteo& Mdata, SnowStation& Xdata, Sur
Xdata.ErosionMass += EMS[e].M;
Xdata.ErosionLength -= EMS[e].L;
Xdata.ErosionLevel = std::min(e, Xdata.ErosionLevel);
Xdata.ErosionAge += EMS[e].depositionDate.getJulian() * EMS[e].L;
nErode++;
massErode -= EMS[e].M;
forced_massErode = -massErode;
Expand All @@ -308,6 +310,7 @@ void SnowDrift::compSnowDrift(const CurrentMeteo& Mdata, SnowStation& Xdata, Sur
assert(EMS[e].M>=0.); //mass must be positive
Xdata.ErosionMass += massErode;
Xdata.ErosionLength += dL;
Xdata.ErosionAge += EMS[e].depositionDate.getJulian() * -dL;
massErode = 0.;
forced_massErode = 0.;
break;
Expand Down Expand Up @@ -358,5 +361,10 @@ void SnowDrift::compSnowDrift(const CurrentMeteo& Mdata, SnowStation& Xdata, Sur
Xdata.ErosionMass = 0.;
}
Sdata.mass[SurfaceFluxes::MS_EROSION_DHS] += Xdata.ErosionLength;
if (Xdata.ErosionLength < 0.) {
Xdata.ErosionAge /= -Xdata.ErosionLength;
} else {
Xdata.ErosionAge = Constants::undefined;
}
return;
}
1 change: 1 addition & 0 deletions Source/snowpack/snowpack/SnowpackConfig.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ bool SnowpackConfig::initStaticData()
advancedConfig["PERP_TO_SLOPE"] = "false";
advancedConfig["PLASTIC"] = "false";
advancedConfig["PREVAILING_WIND_DIR"] = "0.";
advancedConfig["REDEPOSIT_KEEP_AGE"] = "false";
advancedConfig["RESEARCH"] = "true";
advancedConfig["SNOW_ALBEDO"] = "PARAMETERIZED";
advancedConfig["SNOW_EROSION"] = "false";
Expand Down
9 changes: 8 additions & 1 deletion Source/snowpack/snowpack/snowpackCore/Snowpack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ Snowpack::Snowpack(const SnowpackConfig& i_cfg)
allow_adaptive_timestepping(false), research_mode(false), useCanopyModel(false), enforce_measured_snow_heights(false), detect_grass(false),
soil_flux(false), useSoilLayers(false), coupled_phase_changes(false), combine_elements(false), reduce_n_elements(0), force_add_snowfall(false), max_simulated_hs(-1.),
change_bc(false), meas_tss(false), vw_dendricity(false),
enhanced_wind_slab(false), snow_erosion("NONE"), alpine3d(false), ageAlbedo(true), soot_ppmv(0.), adjust_height_of_meteo_values(true),
enhanced_wind_slab(false), snow_erosion("NONE"), redeposit_keep_age(false), alpine3d(false), ageAlbedo(true), soot_ppmv(0.), adjust_height_of_meteo_values(true),
adjust_height_of_wind_value(false), advective_heat(false), heat_begin(0.), heat_end(0.),
temp_index_degree_day(0.), temp_index_swr_factor(0.), forestfloor_alb(false), rime_index(false), newsnow_lwc(false), read_dsm(false), soil_evaporation(), soil_thermal_conductivity()
{
Expand Down Expand Up @@ -397,6 +397,7 @@ Snowpack::Snowpack(const SnowpackConfig& i_cfg)

cfg.getValue("SNOW_EROSION", "SnowpackAdvanced", snow_erosion);
std::transform(snow_erosion.begin(), snow_erosion.end(), snow_erosion.begin(), ::toupper); // Force upper case
cfg.getValue("REDEPOSIT_KEEP_AGE", "SnowpackAdvanced", redeposit_keep_age);

cfg.getValue("NEW_SNOW_GRAIN_SIZE", "SnowpackAdvanced", new_snow_grain_size);
new_snow_bond_size = 0.25 * new_snow_grain_size;
Expand Down Expand Up @@ -2092,6 +2093,7 @@ void Snowpack::RedepositSnow(CurrentMeteo Mdata, SnowStation& Xdata, SurfaceFlux
const bool tmp_enforce_measured_snow_heights = enforce_measured_snow_heights;
const double tmp_Xdata_hn = Xdata.hn;
const double tmp_Xdata_rho_hn = Xdata.rho_hn;
const mio::Date tmp_MdataDate = Mdata.date;
// Deposition mode settings:
double tmp_psum = redeposit_mass;
force_add_snowfall = true;
Expand All @@ -2102,13 +2104,18 @@ void Snowpack::RedepositSnow(CurrentMeteo Mdata, SnowStation& Xdata, SurfaceFlux
if (Mdata.vw_avg == mio::IOUtils::nodata) Mdata.vw_avg = Mdata.vw;
if (Mdata.rh_avg == mio::IOUtils::nodata) Mdata.rh_avg = Mdata.rh;
Xdata.hn = 0.;
if (Xdata.ErosionAge != Constants::undefined && redeposit_keep_age) {
mio::Date EnforcedDepositionDate(Xdata.ErosionAge, Mdata.date.getTimeZone());
Mdata.date = EnforcedDepositionDate;
}
// Add eroded snow:
compSnowFall(Mdata, Xdata, tmp_psum, Sdata);
// Set back original settings:
force_add_snowfall = tmp_force_add_snowfall;
hn_density = tmp_hn_density;
variant = tmp_variant;
enforce_measured_snow_heights = tmp_enforce_measured_snow_heights;
Mdata.date = tmp_MdataDate;
// Calculate new snow density (weighted average) and total snowfall (snowfall + redeposited snow)
Xdata.hn_redeposit = Xdata.hn;
Xdata.rho_hn_redeposit = Xdata.rho_hn;
Expand Down
1 change: 1 addition & 0 deletions Source/snowpack/snowpack/snowpackCore/Snowpack.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class Snowpack {
bool vw_dendricity;
bool enhanced_wind_slab; ///< to use an even stronger wind slab densification than implemented by default
std::string snow_erosion;
bool redeposit_keep_age;
bool alpine3d; ///< triggers various tricks for Alpine3D (including reducing the number of warnings)
bool ageAlbedo; ///< use the age of snow in the albedo parametrizations? default: true
double soot_ppmv; ///< Impurity content in ppmv for albedo calculatoins
Expand Down

0 comments on commit 252bfec

Please sign in to comment.