Skip to content

Commit 215ed80

Browse files
James CraigJames Craig
authored andcommitted
v509 - :LateralDivert
support for lateral flow partial diversion (as opposed to full diversion in :LateralFlush) -new LU parameter divert_fract (LandUseClass.cpp,Properties.h) -new member variable _divert in CmvLatFlush() (LateralExchangeABC.h/LatFlush.cpp) -new command :LateralDivert (ParseInput.cpp)
1 parent 73b4735 commit 215ed80

File tree

5 files changed

+56
-9
lines changed

5 files changed

+56
-9
lines changed

src/LandUseClass.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*----------------------------------------------------------------
22
Raven Library Source Code
3-
Copyright (c) 2008-2021 the Raven Development Team
3+
Copyright (c) 2008-2025 the Raven Development Team
44
----------------------------------------------------------------*/
55
#include "Properties.h"
66
#include "SoilAndLandClasses.h"
@@ -256,6 +256,10 @@ void CLandUseClass::AutoCalculateLandUseProps(surface_struct &Stmp,
256256
if(autocalc) {
257257
S.wind_vel_corr = 1.0;
258258
}
259+
autocalc = SetCalculableValue(S.divert_fract,Stmp.divert_fract,Sdefault.divert_fract);
260+
if(autocalc) {
261+
S.divert_fract = 0.0;
262+
}
259263

260264
/*for(i=0;i<N_LU_PARAMETERS;i++) {
261265
if (!S.params[i].iscomputable){
@@ -290,6 +294,7 @@ void CLandUseClass::AutoCalculateLandUseProps(surface_struct &Stmp,
290294
SetSpecifiedValue(S.AWBM_areafrac1,Stmp.AWBM_areafrac1,Sdefault.AWBM_areafrac1,needed,"AWBM_AREAFRAC1");
291295
SetSpecifiedValue(S.AWBM_areafrac2,Stmp.AWBM_areafrac2,Sdefault.AWBM_areafrac2,needed,"AWBM_AREAFRAC2");
292296
SetSpecifiedValue(S.AWBM_bflow_index,Stmp.AWBM_bflow_index,Sdefault.AWBM_bflow_index,needed,"AWBM_BFLOW_INDEX");
297+
293298
SetSpecifiedValue(S.lake_rel_coeff,Stmp.lake_rel_coeff,Sdefault.lake_rel_coeff,needed,"LAKE_REL_COEFF");
294299
SetSpecifiedValue(S.abst_percent,Stmp.abst_percent,Sdefault.abst_percent,needed,"ABST_PERCENT");
295300
SetSpecifiedValue(S.HBV_glacier_Kmin,Stmp.HBV_glacier_Kmin,Sdefault.HBV_glacier_Kmin,needed,"HBV_GLACIER_KMIN");
@@ -373,6 +378,7 @@ void CLandUseClass::InitializeSurfaceProperties(string name, surface_struct &S,
373378
S.stream_fraction =DefaultParameterValue(is_template,true);//0
374379
S.relhum_corr =DefaultParameterValue(is_template,true);//1.0
375380
S.wind_vel_corr =DefaultParameterValue(is_template,true);//1.0
381+
S.divert_fract =DefaultParameterValue(is_template,true);//0.0
376382

377383
//User-specified parameters
378384
S.partition_coeff =DefaultParameterValue(is_template,false);//0.4;//needs reasonable defaults
@@ -496,6 +502,7 @@ void CLandUseClass::SetSurfaceProperty(surface_struct &S,
496502
else if (!name.compare("AWBM_AREAFRAC1" )){S.AWBM_areafrac1 =value; }
497503
else if (!name.compare("AWBM_AREAFRAC2" )){S.AWBM_areafrac2 =value; }
498504
else if (!name.compare("AWBM_BFLOW_INDEX" )){S.AWBM_bflow_index =value; }
505+
else if (!name.compare("DIVERT_FRACT" )){S.divert_fract =value; }
499506
else if (!name.compare("LAKE_REL_COEFF" )){S.lake_rel_coeff =value;}
500507
else if (!name.compare("DEP_K" )){S.dep_k =value;}
501508
else if (!name.compare("DEP_SEEP_K" )){S.dep_seep_k =value;}
@@ -604,6 +611,7 @@ double CLandUseClass::GetSurfaceProperty(const surface_struct &S, string param_n
604611
else if (!name.compare("AWBM_AREAFRAC1" )){return S.AWBM_areafrac1; }
605612
else if (!name.compare("AWBM_AREAFRAC2" )){return S.AWBM_areafrac2; }
606613
else if (!name.compare("AWBM_BFLOW_INDEX" )){return S.AWBM_bflow_index; }
614+
else if (!name.compare("DIVERT_FRACT" )){return S.divert_fract; }
607615
else if (!name.compare("LAKE_REL_COEFF" )){return S.lake_rel_coeff;}
608616
else if (!name.compare("ABST_PERCENT" )){return S.abst_percent;}
609617
else if (!name.compare("OW_PET_CORR" )){return S.ow_PET_corr;}

src/LatFlush.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ CmvLatFlush::CmvLatFlush(int from_sv_ind,
1717
int from_HRU_grp,
1818
int to_HRU_grp,
1919
bool constrain_to_SBs,
20+
bool divert,
2021
CModel *pModel)
2122
:CLateralExchangeProcessABC(LAT_FLUSH, pModel)
2223
{
@@ -25,19 +26,20 @@ CmvLatFlush::CmvLatFlush(int from_sv_ind,
2526
_kk_from =from_HRU_grp;
2627
_kk_to =to_HRU_grp;
2728
_constrain_to_SBs=constrain_to_SBs;
29+
_divert =divert;
2830

2931
DynamicSpecifyConnections(0); //purely lateral flow, no vertical
3032

3133
//check for valid SVs, HRU group indices
3234
bool badHRU;
3335
badHRU=(to_HRU_grp<0) || (to_HRU_grp>_pModel->GetNumHRUGroups()-1);
34-
ExitGracefullyIf(badHRU,"CmvLatFlush::unrecognized 'to' HRU group specified in :LateralFlush command",BAD_DATA_WARN);
36+
ExitGracefullyIf(badHRU,"CmvLatFlush::unrecognized 'to' HRU group specified in :LateralFlush/:LateralDivert command",BAD_DATA_WARN);
3537

3638
badHRU=(from_HRU_grp<0) || (from_HRU_grp>_pModel->GetNumHRUGroups()-1);
37-
ExitGracefullyIf(badHRU,"CmvLatFlush::unrecognized 'from' HRU group specified in :LateralFlush command",BAD_DATA_WARN);
39+
ExitGracefullyIf(badHRU,"CmvLatFlush::unrecognized 'from' HRU group specified in :LateralFlush/:LateralDivert command",BAD_DATA_WARN);
3840

39-
ExitGracefullyIf(from_sv_ind==DOESNT_EXIST,"CmvLatFlush::unrecognized 'from' state variable specified in :LateralFlush command",BAD_DATA_WARN);
40-
ExitGracefullyIf(to_sv_ind ==DOESNT_EXIST,"CmvLatFlush::unrecognized 'to' state variable specified in :LateralFlush command",BAD_DATA_WARN);
41+
ExitGracefullyIf(from_sv_ind==DOESNT_EXIST,"CmvLatFlush::unrecognized 'from' state variable specified in :LateralFlush/:LateralDivert command",BAD_DATA_WARN);
42+
ExitGracefullyIf(to_sv_ind ==DOESNT_EXIST,"CmvLatFlush::unrecognized 'to' state variable specified in :LateralFlush/:LateralDivert command",BAD_DATA_WARN);
4143
}
4244
//////////////////////////////////////////////////////////////////
4345
/// \brief Implementation of the default destructor
@@ -152,6 +154,9 @@ void CmvLatFlush::GetParticipatingStateVarList(sv_type *aSV,int *aLev,int &nSV)
152154
void CmvLatFlush::GetParticipatingParamList(string *aP,class_type *aPC,int &nP) const
153155
{
154156
nP=0;
157+
if (_divert) {
158+
aP[0]="DIVERT_FRACTION"; aPC[0]=CLASS_LANDUSE; nP++;
159+
}
155160
}
156161
//////////////////////////////////////////////////////////////////
157162
/// \brief returns lateral exchange rates (mm/d) between from and to HRU/SV combinations
@@ -169,6 +174,7 @@ void CmvLatFlush::GetLateralExchange( const double * const *state_vars, //ar
169174
{
170175
double stor,Afrom,Ato;
171176
double to_stor,max_to_stor,max_rate;
177+
double mult=1.0; //default: flush 100%
172178

173179
for(int q=0; q<_nLatConnections; q++)
174180
{
@@ -179,7 +185,11 @@ void CmvLatFlush::GetLateralExchange( const double * const *state_vars, //ar
179185
max_to_stor=pHRUs[_kTo [q]]->GetStateVarMax(_iToLat[q],state_vars[_kTo[q]],Options);
180186
max_rate =max(max_to_stor-to_stor,0.0)/Options.timestep*Ato;
181187

182-
exchange_rates[q]=max(stor,0.0)/Options.timestep*Afrom; //[mm-m2/d]
188+
if (_divert) {
189+
mult=pHRUs[_kFrom[q]]->GetSurfaceProps()->divert_fract;
190+
}
191+
192+
exchange_rates[q]=max(mult*stor,0.0)/Options.timestep*Afrom; //[mm-m2/d]
183193
exchange_rates[q]=min(exchange_rates[q],max_rate); //constrains so that it does not overfill receiving compartment
184194
}
185195
}

src/LateralExchangeABC.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*----------------------------------------------------------------
22
Raven Library Source Code
3-
Copyright (c) 2008-2017 the Raven Development Team
3+
Copyright (c) 2008-2025 the Raven Development Team
44
----------------------------------------------------------------*/
55
#ifndef LATERALEXCHANGE_H
66
#define LATERALEXCHANGE_H
@@ -84,6 +84,8 @@ class CmvLatFlush: public CLateralExchangeProcessABC
8484
int _kk_from; //< HRU group index of source HRUs
8585
int _kk_to; //< HRU group index of target HRUs
8686

87+
bool _divert; //< true if this is simulation partial flushing using HRU land use property DIVERT_FRACTION
88+
8789
bool _constrain_to_SBs; // all transfer is within one sub-basin; otherwise, requires only one recipient HRU in model
8890

8991

@@ -94,6 +96,7 @@ class CmvLatFlush: public CLateralExchangeProcessABC
9496
int from_HRU_grp,
9597
int to_HRU_grp,
9698
bool constrain_to_SBs,
99+
bool divert,
97100
CModel *pModel);
98101
~CmvLatFlush();
99102

src/ParseInput.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ bool ParseMainInputFile (CModel *&pModel,
575575
else if (!strcmp(s[0],":SoilBalance" )){code=237;}
576576
else if (!strcmp(s[0],":LateralEquilibrate" )){code=238;}
577577
else if (!strcmp(s[0],":LakeFreeze" )){code=239;}
578+
else if (!strcmp(s[0],":LateralDivert" )){code=240;}
578579
//...
579580
else if (!strcmp(s[0],":-->RedirectFlow" )){code=294;}
580581
else if (!strcmp(s[0],":ProcessGroup" )){code=295;}
@@ -2886,7 +2887,7 @@ bool ParseMainInputFile (CModel *&pModel,
28862887
pModel->GetStateVarIndex(tmpS[1],tmpLev[1]),//to SV index
28872888
pModel->GetHRUGroup(s[2])->GetGlobalIndex(),
28882889
pModel->GetHRUGroup(s[5])->GetGlobalIndex(),
2889-
!interbasin, pModel);
2890+
!interbasin, false, pModel);
28902891
AddProcess(pModel,pMover,pProcGroup);
28912892
}
28922893
break;
@@ -3059,6 +3060,30 @@ bool ParseMainInputFile (CModel *&pModel,
30593060
AddProcess(pModel, pMover, pProcGroup);
30603061
break;
30613062
}
3063+
case(240): //----------------------------------------------
3064+
{/*Lateral Diversion
3065+
:LateralDivert RAVEN_DEFAULT [FROM_HRUGroup] [FROM_SV] To [TO_HRUGROUP] [TO_SV] */
3066+
if(Options.noisy){ cout <<"Lateral Divert Process"<<endl; }
3067+
bool interbasin=false;
3068+
if(Len<7){ ImproperFormatWarning(":LateralDivert",p,Options.noisy); break; }
3069+
3070+
tmpS[0] = pModel->GetStateVarInfo()->StringToSVType(s[3],tmpLev[0],true);
3071+
tmpS[1] = pModel->GetStateVarInfo()->StringToSVType(s[6],tmpLev[1],true);
3072+
pModel->AddStateVariables(tmpS,tmpLev,2);
3073+
3074+
if((pModel->GetHRUGroup(s[2])==NULL) || (pModel->GetHRUGroup(s[5])==NULL)){
3075+
ExitGracefully("ParseInput: Lateral Flush - invalid 'to' or 'from' HRU Group used. Must define using :DefineHRUGroups command.",BAD_DATA_WARN);
3076+
}
3077+
else{
3078+
pMover=new CmvLatFlush( pModel->GetStateVarIndex(tmpS[0],tmpLev[0]),//from SV index
3079+
pModel->GetStateVarIndex(tmpS[1],tmpLev[1]),//to SV index
3080+
pModel->GetHRUGroup(s[2])->GetGlobalIndex(),
3081+
pModel->GetHRUGroup(s[5])->GetGlobalIndex(),
3082+
true, true, pModel);
3083+
AddProcess(pModel,pMover,pProcGroup);
3084+
}
3085+
break;
3086+
}
30623087
case(294): //----------------------------------------------
30633088
{/*:-->RedirectFlow
30643089
:-->RedirectFlow [old 'To' SV] [new 'To' SV]*/

src/Properties.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*----------------------------------------------------------------
22
Raven Library Source Code
3-
Copyright (c) 2008-2023 the Raven Development Team
3+
Copyright (c) 2008-2025 the Raven Development Team
44
----------------------------------------------------------------
55
Properties.h
66
------------------------------------------------------------------
@@ -295,6 +295,7 @@ struct surface_struct
295295
double AWBM_areafrac1; ///< [0..1] fraction of infiltration to smallest landscape store in AWBM model (nonzero)
296296
double AWBM_areafrac2; ///< [0..1] fraction of infiltration to medium landscape store in AWBM model (nonzero)
297297
double AWBM_bflow_index; ///< [0..1] fraction of excess going to groundwater in AWBM model
298+
double divert_fract; ///< [0..1] fraction of available water diverted in :LateralDivert run (default=0.0)
298299

299300
double ow_PET_corr; ///< [-] fraction of PET to apply to open water evaporation
300301
double lake_PET_corr; ///< [-] fraction of PET to apply to lake evaporation

0 commit comments

Comments
 (0)