Skip to content

Commit

Permalink
access to HBV-EC lapse params; EnKF NetCDF custom writing bug [NOT BE…
Browse files Browse the repository at this point in the history
…NCHMARKED]

enabled access to HBV-EC lapse params (GlobalParams.cpp; modelParamCheck.cpp, OrographicCorrections.cpp, Properties.h, RavenInclude.h)

fixed bug in ensemble writing of NetCDF custom output - required reset of _time_index (found by Arnejan @ Deltares) (CustomOutput.cpp)

git-svn-id: https://chyms.nrc.gc.ca/svn/raven/trunk@415 9a3899ca-7adb-4d27-9b38-7f4ebb3123b0
  • Loading branch information
James.Craig authored and James.Craig committed May 12, 2023
1 parent 6db90fb commit ea618a3
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/CustomOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,10 @@ void CCustomOutput::WriteCustomOutput(const time_struct &tt,
else if ((_timeAgg==WATER_YEARLY) && (dday==1) && (dmon==Options.wateryr_mo))
{reset=true;}//Oct 1 - print preceding year

if (reset)
bool skip=false;
if ((pModel->GetEnsemble() != NULL) && (pModel->GetEnsemble()->DontWriteOutput())) { skip=true;}

if ((reset) && (!skip))
{
if(Options.output_format==OUTPUT_STANDARD)//=================================================================
{
Expand Down Expand Up @@ -1017,6 +1020,7 @@ void CCustomOutput::WriteCustomOutput(const time_struct &tt,
{
#ifdef _RVNETCDF_
// Write to NetCDF (done entire vector of data at once)

if (num_data > 0)
{
int retval,data_id;
Expand Down Expand Up @@ -1048,6 +1052,7 @@ void CCustomOutput::CloseFiles(const optStruct& Options)
#endif
}
_filename=_filename_user; //so works in ensemble mode
_time_index=0;
}

int ParseSVTypeIndex(string s,CModel *&pModel);
Expand Down
3 changes: 1 addition & 2 deletions src/EnergyTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ double CEnthalpyModel::CalculateReportingConcentration(const double &M,const dou
}
//////////////////////////////////////////////////////////////////
/// \brief Converts basic energy units [deg C] to [mJ/mm/m2]
/// \param C [in] composition, in o/oo
/// \param T [in] temperature in deg C
/// \returns concentration, in mJ/mm/m2
//
double CEnthalpyModel::ConvertConcentration(const double &T) const
Expand Down Expand Up @@ -104,7 +104,6 @@ double CEnthalpyModel::GetOutflowIceFraction(const int p) const
if(flow<=0) { return 0.0; }

return ConvertVolumetricEnthalpyToIceContent(hv);

}
else {
return ConvertVolumetricEnthalpyToIceContent(_aMres[p]/pRes->GetStorage()); //[C]
Expand Down
26 changes: 26 additions & 0 deletions src/GlobalParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,21 @@ void CGlobalParams::AutoCalculateGlobalParams(const global_struct &Gtmp, const g
{
G.reservoir_demand_mult=1.0; //default
}
autocalc=SetCalculableValue(G.HBVEC_lapse_rate,Gtmp.HBVEC_lapse_rate,Gtemplate.HBVEC_lapse_rate);
if (autocalc)
{
G.HBVEC_lapse_rate=0.08; //Default [mm/d/km]
}
autocalc = SetCalculableValue(G.HBVEC_lapse_upper, Gtmp.HBVEC_lapse_upper, Gtemplate.HBVEC_lapse_upper);
if (autocalc)
{
G.HBVEC_lapse_upper=0.0;//Default [mm/d/km]
}
autocalc=SetCalculableValue(G.HBVEC_lapse_elev,Gtmp.HBVEC_lapse_elev,Gtemplate.HBVEC_lapse_elev);
if (autocalc)
{
G.HBVEC_lapse_upper=5000.0;//Default [m]
}


//Model-specific global parameters - cannot be autocomputed, must be specified by user
Expand Down Expand Up @@ -338,6 +353,7 @@ void CGlobalParams::AutoCalculateGlobalParams(const global_struct &Gtmp, const g
SetSpecifiedValue(G.init_stream_temp,Gtmp.init_stream_temp,Gtemplate.init_stream_temp,false,"INIT_STREAM_TEMP");
SetSpecifiedValue(G.windvel_icept,Gtmp.windvel_icept,Gtemplate.windvel_icept,false,"WINDVEL_ICEPT");
SetSpecifiedValue(G.windvel_scale,Gtmp.windvel_scale,Gtemplate.windvel_scale,false,"WINDVEL_SCALE");

}

//////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -386,6 +402,10 @@ void CGlobalParams::InitializeGlobalParameters(global_struct &g, bool is_templat
g.bare_ground_albedo =DefaultParameterValue(is_template,true);
g.snowfall_albthresh =DefaultParameterValue(is_template,true);

g.HBVEC_lapse_rate =DefaultParameterValue(is_template,true);
g.HBVEC_lapse_upper =DefaultParameterValue(is_template,true);
g.HBVEC_lapse_elev =DefaultParameterValue(is_template,true);

g.max_SWE_surface =DefaultParameterValue(is_template,true);
g.TOC_multiplier =DefaultParameterValue(is_template,true);
g.TIME_TO_PEAK_multiplier =DefaultParameterValue(is_template,true);
Expand Down Expand Up @@ -534,6 +554,9 @@ void CGlobalParams::SetGlobalProperty (global_struct &G,
else if (!name.compare("RESERVOIR_DEMAND_MULT")){G.reservoir_demand_mult=value; }
else if (!name.compare("WINDVEL_ICEPT" )){G.windvel_icept=value; }
else if (!name.compare("WINDVEL_SCALE" )){G.windvel_scale=value; }
else if (!name.compare("HBVEC_LAPSE_RATE" )){G.HBVEC_lapse_rate=value; }
else if (!name.compare("HBVEC_LAPSE_UPPER" )){G.HBVEC_lapse_upper=value; }
else if (!name.compare("HBVEC_LAPSE_ELEV" )){G.HBVEC_lapse_elev=value; }
else{
WriteWarning("CGlobalParams::SetGlobalProperty: Unrecognized/invalid global parameter name ("+name+") in .rvp file",false);

Expand Down Expand Up @@ -652,6 +675,9 @@ double CGlobalParams::GetGlobalProperty(const global_struct &G, string param_na
else if (!name.compare("RESERVOIR_DEMAND_MULT")){return G.reservoir_demand_mult; }
else if (!name.compare("WINDVEL_ICEPT" )){return G.windvel_icept; }
else if (!name.compare("WINDVEL_SCALE" )){return G.windvel_scale; }
else if (!name.compare("HBVEC_LAPSE_RATE" )){return G.HBVEC_lapse_rate; }
else if (!name.compare("HBVEC_LAPSE_UPPER" )){return G.HBVEC_lapse_upper; }
else if (!name.compare("HBVEC_LAPSE_ELEV" )){return G.HBVEC_lapse_elev; }
else{
if (strict){
string msg="CGlobalParams::GetParameter: Unrecognized/invalid global parameter name in .rvp file: "+name;
Expand Down
6 changes: 3 additions & 3 deletions src/ModelParamCheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ void CModel::GetParticipatingParamList(string *aP,class_type *aPC,int &nP,const
//----------------------------------------------------------------------
if(Options.orocorr_precip==OROCORR_HBV)
{
// Parameters are located in the RVT file, and there's no checking routine for that file yet.
//aP[nP]=":RainCorrection"; aPC[nP]=CLASS_; nP++;
//aP[nP]=":SnowCorrection"; aPC[nP]=CLASS_; nP++;
aP[nP]="HBVEC_LAPSE_ELEV"; aPC[nP]=CLASS_GLOBAL; nP++;
aP[nP]="HBVEC_LAPSE_RATE"; aPC[nP]=CLASS_GLOBAL; nP++;
aP[nP]="HBVEC_LAPSE_UPPER"; aPC[nP]=CLASS_GLOBAL; nP++;
}
else if((Options.orocorr_precip==OROCORR_UBCWM) || (Options.orocorr_precip==OROCORR_UBCWM2))
{
Expand Down
8 changes: 5 additions & 3 deletions src/OrographicCorrections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,12 @@ void CModel::CorrectPrecip(const optStruct &Options,
//---------------------------------------------------------------------------
else if (Options.orocorr_precip==OROCORR_HBV)
{
double corr=HBV_PRECIP_CORR;
double corr_upper=CGlobalParams::GetParams()->HBVEC_lapse_upper/M_PER_KM;
double corr =CGlobalParams::GetParams()->HBVEC_lapse_rate/M_PER_KM;
double lapse_elev=CGlobalParams::GetParams()->HBVEC_lapse_elev;
double add=0.0;
if (elev>HBV_PRECIP_CORR_ELEV){
add=(HBV_PRECIP_CORR_UP-HBV_PRECIP_CORR)*(elev-HBV_PRECIP_CORR_ELEV);
if (elev>lapse_elev){
add=(corr_upper-corr)*(elev-lapse_elev);
}
F.precip *=max(1.0+corr*(elev-ref_elev)+add,0.0);
F.precip_5day *=max(1.0+corr*(elev-ref_elev)+add,0.0);
Expand Down
4 changes: 4 additions & 0 deletions src/Properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ struct global_struct
double UBC_LW_forest_fact; ///< UBC mulitplier of temperature to estimate LW radiation in forests (P0BLUE*P0LWVF) [mm/d/K]
double UBC_flash_ponding; ///< UBC ponding threshold for flash factor (V0FLAS) [mm]

double HBVEC_lapse_rate; ///< HBV-EC precipitation lapse rate below HBVEC_lapse_elev [mm/d/km] (PCALT*1000 in HBV, PGRADL*1000 in HBV-EC)
double HBVEC_lapse_upper; ///< HBV-EC precipitation lapse rate above HBVEC_lapse_elev [mm/d/km] (PCALTUP*1000 in HBV, PGRADH*1000 in HBV-EC)
double HBVEC_lapse_elev; ///< HBV-EC precipitation lapse rate shift elevation [m] (PCALTL/EMID in HBV-EC)

double airsnow_coeff; ///< [1/d] air/snow heat transfer coefficient

double MOHYSE_PET_coeff; ///< [mm/d] MOHYSE PET constant (PET @ equinox when temperature is 10 degC)
Expand Down
3 changes: 0 additions & 3 deletions src/RavenInclude.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,6 @@ const double WIND_EXTINCT =2.5;
const double LEAF_PROJ_RAT =2.2; ///< [m2/m2] ratio of total leaf area to projected area.

const double HBV_REFERENCE_ELEV =1000; ///< [masl] (zref in HBV)
const double HBV_PRECIP_CORR =0.00008; ///< [1/m] precipitation lapse rate for low elevations (PCALT in HBV, PGRADL in HBV-EC)
const double HBV_PRECIP_CORR_UP =0.0; ///< [1/m] precipitation lapse rate for high elevations(PCALTUP in HBV, PGRADH in HBV-EC)
const double HBV_PRECIP_CORR_ELEV =5000; ///< [masl] reference correction elevation (PCALTL/EMID in HBV-EC)
const double HBV_PET_ELEV_CORR =0.0005; ///< [mm/m-d] PET lapse rate (ECALT in HBV-EC)
const double HBV_PET_TEMP_CORR =0.5; ///< [-] (ETF in HBV-EC)
const double GLOBAL_PET_CORR =1.0; ///< [-] (ECORR in HBV-EC)
Expand Down

0 comments on commit ea618a3

Please sign in to comment.