Skip to content

Commit 64a802e

Browse files
James CraigJames Craig
authored andcommitted
v526 - Support for :Flush BY_SUBBASIN, minor assimilation change
Support for :Flush BY_SUBBASIN -full model pointer in CmvFlush (HydroProcessABC.h;Flush.cpp) -parsing support (ParseInput.cpp) -new global constant BY_SUBBASIN_FLAG (RavenInclude.h) -new SubBasin member _flush_fract (SubBasin.cpp/.h) adjustment to AdjustAllFlows to properly correct inflows in long basin minor edit to StandardOutput.cpp to support reset of output times in ensemble simulation
1 parent 472bfe7 commit 64a802e

File tree

8 files changed

+58
-23
lines changed

8 files changed

+58
-23
lines changed

src/Flush.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*----------------------------------------------------------------
22
Raven Library Source Code
3-
Copyright (c) 2008-2022 the Raven Development Team
3+
Copyright (c) 2008-2025 the Raven Development Team
44
------------------------------------------------------------------
55
Flush (abstract move of all water from one compartment to another)
66
Split (move water to two compartments)
@@ -24,9 +24,11 @@
2424
CmvFlush::CmvFlush(int In_index, //soil water storage
2525
int Out_index,
2626
const double &pct,
27-
CModelABC *pModel)
27+
CModelABC *pModel,
28+
CModel *pModel_full)
2829
:CHydroProcessABC(FLUSH, In_index, Out_index, pModel)
2930
{
31+
_pModel_full=pModel_full;
3032
_percentage=pct;
3133
ExitGracefullyIf(In_index==DOESNT_EXIST,
3234
"CmvFlush Constructor: invalid 'from' compartment specified",BAD_DATA);
@@ -75,8 +77,13 @@ void CmvFlush::GetRatesOfChange( const double *storage,
7577
const optStruct &Options,
7678
const time_struct &tt,
7779
double *rates) const
78-
{
79-
rates[0]=_percentage*storage[iFrom[0]]/Options.timestep;
80+
{
81+
double mult=_percentage;
82+
if (_percentage==BY_SUBBASIN_FLAG){
83+
int p=pHRU->GetSubBasinIndex();
84+
mult=_pModel_full->GetSubBasin(p)->GetFlushFract();
85+
}
86+
rates[0]=mult*storage[iFrom[0]]/Options.timestep;
8087
}
8188

8289
//////////////////////////////////////////////////////////////////

src/HydroProcessABC.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*----------------------------------------------------------------
22
Raven Library Source Code
3-
Copyright (c) 2008-2019 the Raven Development Team
3+
Copyright (c) 2008-2025 the Raven Development Team
44
----------------------------------------------------------------*/
55

66
#ifndef HYDROPROCESS_H
@@ -117,14 +117,16 @@ class CHydroProcessABC
117117
class CmvFlush: public CHydroProcessABC
118118
{
119119
private:/*------------------------------------------------------*/
120-
double _percentage;
120+
double _percentage;
121+
CModel *_pModel_full;
121122

122123
public:/*-------------------------------------------------------*/
123124
//Constructors/destructors:
124125
CmvFlush(int from_index,
125126
int to_index,
126127
const double &pct,
127-
CModelABC *pM);
128+
CModelABC *pM,
129+
CModel *pM_full);
128130
~CmvFlush();
129131

130132
//inherited functions

src/ModelInitialize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ void CModel::InitializeParameterOverrides()
775775
{
776776
double *address = this->_pGlobalParams->GetAddress(name);
777777
if (address==NULL){
778-
ExitGracefully("CModel::InitializeParameterOverrides() : Invalid or unsupported global parameter name in :LocalParameterOverride command",BAD_DATA);
778+
ExitGracefully("CModel::InitializeParameterOverrides() : Invalid or unsupported global parameter name in :GlobalParameterOverride command",BAD_DATA);
779779
}
780780
_pParamOverrides[i]->pxAddress=address;
781781

src/ParseInput.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,18 +2528,25 @@ bool ParseMainInputFile (CModel *&pModel,
25282528
}
25292529
case(215): //----------------------------------------------
25302530
{/*Flush
2531-
:Flush RAVEN_DEFAULT [state_var from] [state_var to] {Optional percentage}*/
2531+
:Flush RAVEN_DEFAULT [state_var from] [state_var to] {Optional percentage or 'FRACT_BY_SUBBASIN'}*/
25322532
if (Options.noisy){cout <<"Flushing Process"<<endl;}
25332533
double pct=1.0;
25342534
if (Len<4){ImproperFormatWarning(":Flush",p,Options.noisy); break;}
25352535
tmpS[0] = pStateVar->StringToSVType(s[2],tmpLev[0],true);
25362536
tmpS[1] = pStateVar->StringToSVType(s[3],tmpLev[1],true);
25372537
pModel->AddStateVariables(tmpS,tmpLev,2);
2538-
if ((Len>=5) && (s[4][0]!='#')){pct=max(min(s_to_d(s[4]),1.0),0.0);}
2538+
if (Len>=5){
2539+
if (to_string(s[4])=="FRACT_BY_SUBBASIN"){
2540+
pct=BY_SUBBASIN_FLAG;
2541+
}
2542+
else{
2543+
pct=max(min(s_to_d(s[4]),1.0),0.0);
2544+
}
2545+
}
25392546

25402547
pMover = new CmvFlush(ParseSVTypeIndex(s[2], pModel, pStateVar),
25412548
ParseSVTypeIndex(s[3], pModel, pStateVar),
2542-
pct, pModel);
2549+
pct, pModel,pModel);
25432550
AddProcess(pModel,pMover,pProcGroup);
25442551
break;
25452552
}

src/RavenInclude.h

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ const double NETCDF_BLANK_VALUE =-9999.0;
254254
const double RAV_BLANK_DATA =-1.2345; ///< double corresponding to blank/void data item (also used in input files)
255255
const double DIRICHLET_TEMP =-9999.0; ///< dirichlet concentration flag corresponding to air temperature
256256
const int FROM_STATION_VAR =-55; ///< special flag indicating that NetCDF indices should be looked up from station attribute table
257+
const double BY_SUBBASIN_FLAG =64; ///< special flag indicating flush percentage should be retrieved from subbasin parameter
257258

258259
//Decision constants
259260
const double HUGE_RESIST =1e20; ///< [d/mm] essentially infinite resistance
@@ -865,7 +866,7 @@ enum assimtype
865866
//
866867
enum sv_type
867868
{
868-
//Water Storage
869+
// Water Storage Compartments
869870
SURFACE_WATER, ///< [mm] Streams & rivers: see surface_struct (REQUIRED)
870871
ATMOSPHERE, ///< [mm] atmosphere : recieves water only!! (REQUIRED)
871872
ATMOS_PRECIP, ///< [mm] atmosphere : provides water only!! (REQUIRED)
@@ -877,11 +878,11 @@ enum sv_type
877878
TRUNK, ///< [mm] water stored in trunks of trees
878879
ROOT, ///< [mm] water stored in roots
879880
GROUNDWATER, ///< [mm] Deep groundwater
880-
DEPRESSION, ///< [mm] depression/surface storage
881+
DEPRESSION, ///< [mm] depression/surface/wetland storage
881882
SNOW, ///< [mm] frozen snow depth (mm SWE : snow water equivalent)
882883
NEW_SNOW, ///< [mm] new snowfall waiting to be handled by snow balance (as SWE)
883884
SNOW_LIQ, ///< [mm] liquid water content of snowpack
884-
TOTAL_SWE, ///< [mm] equivalent to SNOW[0]+SNOW[1]+...+SNOW_LIQ[0]..
885+
TOTAL_SWE, ///< [mm] equivalent to SNOW[0]+SNOW[1]+...+SNOW_LIQ[0].. (diagnostic variable)
885886
WETLAND, ///< [mm] deep wetland depression storage
886887
GLACIER, ///< [mm] Glacier melt/reservoir storage
887888
GLACIER_ICE, ///< [mm] Glacier ice - typically assumed to be infinite reservoir.
@@ -893,14 +894,14 @@ enum sv_type
893894
// Distribution tracking variables
894895
MIN_DEP_DEFICIT, ///< [mm or -1..0] Minimum depression deficit (describes deficit distribution), =-percent full if negative
895896

896-
// Memory variables
897+
// Memory/diagnostic variables
897898
CUM_INFIL, ///< [mm] Cumulative infiltration to topsoil
898899
GA_MOISTURE_INIT, ///< [mm] Initial topsoil moisture content for Green Ampt infiltration
899900
CUM_SNOWMELT, ///< [mm] Cumulative snowmelt as SWE
900901
AET, ///< [mm] PET used up in given time step (diagnostic variable)
901902
RUNOFF, ///< [mm] net release of water to surface water in given times step (diagnostic variable)
902903

903-
//Temperature/Energy storage [C] or [MJ/m^2]
904+
// Temperature/Energy storage [C] or [MJ/m^2]
904905
ENERGY_LOSSES, ///< [MJ/m2] general energy losses
905906

906907
SURFACE_WATER_TEMP, ///< [C] Temperature of surface water
@@ -909,7 +910,7 @@ enum sv_type
909910
SOIL_TEMP, ///< [C] Temperature of soil
910911
CANOPY_TEMP, ///< [C] Temperature fo canopy
911912

912-
//Snow/Glacier variables
913+
// Snow/Glacier variables
913914
SNOW_DEPTH, ///< [mm] Snow depth - surrogate for density
914915
PERMAFROST_DEPTH, ///< [mm] depth of permafrost
915916
THAW_DEPTH, ///< [mm] depth of thaw
@@ -924,22 +925,22 @@ enum sv_type
924925

925926
SNOW_ALBEDO, ///< [-] Snow Surface albedo
926927

927-
//Crop variables
928+
// Crop variables
928929
CROP_HEAT_UNITS, ///< [-] cumulative crop heat units
929930

930-
//Transport variables
931+
// Transport variables
931932
CONSTITUENT, ///< chemical species [mg/m2], enthalpy [MJ/m2], or tracer [-]
932933
CONSTITUENT_SRC, ///< chemical species [mg/m2], enthalpy [MJ/m2], or tracer [-] cumulative source
933934
CONSTITUENT_SW, ///< chemical species [mg/m2], enthalpy [MJ/m2], or tracer [-] dumped to surface water
934935
CONSTITUENT_SINK, ///< chemical species [mg/m2], enthalpy [MJ/m2], or tracer [-] cumulative sink (e.g., decay)
935936

936-
//Energy variables
937+
// Energy variables
937938
LATENT_HEAT, ///< [MJ/m2] cumulative energy lost to evaporative phase change
938939

939-
//Lateral exchange
940+
// Lateral exchange
940941
LATERAL_EXCHANGE, ///< [mm] water storage in transit from HRU awaiting lateral transfer to other HRUs
941942

942-
//Special - internal flags
943+
// Special - internal flags
943944
STREAMFLOW, ///< only used for referencing in data assimilation
944945
RESERVOIR_STAGE, ///< only used for referencing in data assimilation
945946
UNRECOGNIZED_SVTYPE, ///< Unrecognized type of state variable

src/StandardOutput.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,9 @@ void CModel::WriteMinorOutput(const optStruct &Options,const time_struct &tt)
13431343

13441344
// Write major output, if necessary
13451345
//--------------------------------------------------------------
1346+
if (tt.model_time == 0.0) {//for ensembles
1347+
_currOutputTimeInd=0;
1348+
}
13461349
if ((_nOutputTimes>0) && (_currOutputTimeInd<_nOutputTimes) && (tt.model_time>_aOutputTimes[_currOutputTimeInd]-0.5*Options.timestep))
13471350
{
13481351
string thishour=DecDaysToHours(tt.julian_day);

src/SubBasin.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ CSubBasin::CSubBasin( const long long Identifier,
7272
_temperature_corr = 0.0;
7373
_unusable_flow_pct =0.0;
7474
_divert_fract =1.0;
75+
_flush_fract =1.0;
7576

7677
_res_disabled =false;
7778
_assimilate =false;
@@ -1085,6 +1086,12 @@ double CSubBasin::GetUnusableFlowPercentage() const {
10851086
double CSubBasin::GetDivertFract () const{
10861087
return _divert_fract;
10871088
}
1089+
//////////////////////////////////////////////////////////////////
1090+
/// \brief gets flush fraction (percentage of flush applied in basin)
1091+
//
1092+
double CSubBasin::GetFlushFract () const{
1093+
return _flush_fract;
1094+
}
10881095
/*****************************************************************
10891096
Manipulators
10901097
*****************************************************************/
@@ -1137,6 +1144,7 @@ bool CSubBasin::SetBasinProperties(const string label,
11371144
else if (!label_n.compare("GAMMA_SHAPE" )) {_gamma_shape=value;}
11381145
else if (!label_n.compare("GAMMA_SCALE" )) {_gamma_scale=value;}
11391146
else if (!label_n.compare("DIVERT_FRACT" )) {_divert_fract=value;}
1147+
else if (!label_n.compare("FLUSH_FRACT" )) {_flush_fract=value;}
11401148

11411149
else if (!label_n.compare("Q_REFERENCE" )) {_Q_ref=value;}
11421150
else if (!label_n.compare("MANNINGS_N" )) {_mannings_n=value;}
@@ -1224,6 +1232,7 @@ double CSubBasin::GetBasinProperties(const basin_props prop)
12241232
case BP_GAMMA_SHAPE: return _gamma_shape;
12251233
case BP_GAMMA_SCALE: return _gamma_scale;
12261234
case BP_DIVERT_FRACT : return _divert_fract;
1235+
case BP_FLUSH_FRACT : return _flush_fract;
12271236
12281237
case BP_Q_REFERENCE : return _Q_ref;
12291238
case BP_MANNINGS_N : return _mannings_n;
@@ -1271,6 +1280,7 @@ double CSubBasin::GetBasinProperties(const string label) const
12711280
else if (!label_n.compare("GAMMA_SHAPE" )) { return _gamma_shape;}
12721281
else if (!label_n.compare("GAMMA_SCALE" )) { return _gamma_scale;}
12731282
else if (!label_n.compare("DIVERT_FRACT" )) { return _divert_fract;}
1283+
else if (!label_n.compare("FLUSH_FRACT" )) { return _divert_fract;}
12741284

12751285
else if (!label_n.compare("Q_REFERENCE" )) { return _Q_ref;}
12761286
else if (!label_n.compare("MANNINGS_N" )) { return _mannings_n;}
@@ -1543,8 +1553,11 @@ double CSubBasin::AdjustAllFlows(const double &adjust, const bool overriding, co
15431553

15441554
if(!overriding)
15451555
{
1556+
1557+
double distfact = _pModel->GetGlobalParams()->GetParams()->assim_upstream_decay/M_PER_KM; //[1/km]->[1/m]
1558+
double corr=exp(-distfact*_reach_length);
15461559
for(int n=0;n<_nQinHist; n++) {
1547-
_aQinHist[n]+=adjust*(_drainage_area-_basin_area)/_drainage_area;
1560+
_aQinHist[n]+=adjust*(_drainage_area-_basin_area)/_drainage_area*corr;
15481561
upperswap(_aQinHist[n],0.0);
15491562
va+=adjust*tstep*SEC_PER_DAY;
15501563
}

src/SubBasin.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ class CSubBasin
9797
double _recharge_corr; ///< correction factor for recharge [-]
9898
double _temperature_corr; ///< correction factor (additive) for temperature [-]
9999
double _divert_fract; ///< fraction of water flushed from source HRUs in basin [0..1] (:LateralDivert)
100+
double _flush_fract; ///< fraction of water flushed from source compartment in basin [0..1] (:Flush with BY_SUBBASIN)
100101

101102
int _nSegments; ///< Number of river segments used in routing( >=1)
102103

@@ -224,6 +225,7 @@ class CSubBasin
224225
int GetNumWaterDemands () const;
225226
double GetUnusableFlowPercentage() const;
226227
double GetDivertFract () const;
228+
double GetFlushFract () const;
227229

228230
const double *GetUnitHydrograph () const;
229231
const double *GetRoutingHydrograph () const;

0 commit comments

Comments
 (0)