Skip to content

Commit 17553f1

Browse files
James CraigJames Craig
authored andcommitted
fixed memory bug; AnnualPattern INTERPOLATE bug.
memory bug introduced with wetland freezing (PartitionPrecip.cpp) fixed interpolation bug in AnnualPattern when Dec 31 is included (TimeSeries.cpp) updated .dat files
1 parent 776f204 commit 17553f1

File tree

4 files changed

+18
-19
lines changed

4 files changed

+18
-19
lines changed

src/PartitionPrecip.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ void CmvPrecipitation::Initialize()
3232

3333
int N=13;
3434

35-
if (pModel->StateVarExists(ICE_THICKNESS)){N+=3;}
36-
35+
if (pModel->StateVarExists(ICE_THICKNESS)){
36+
N+=3;
37+
if (pModel->StateVarExists(DEPRESSION)){N+=3;}
38+
}
3739
CHydroProcessABC::DynamicSpecifyConnections(N);
3840

3941
iFrom[0]=iAtmos; iTo[0]=pModel->GetStateVarIndex(PONDED_WATER);
@@ -62,9 +64,11 @@ void CmvPrecipitation::Initialize()
6264
iFrom[13]=pModel->GetStateVarIndex(SNOW); iTo[13]=pModel->GetLakeStorageIndex();
6365
iFrom[14]=pModel->GetStateVarIndex(SNOW_LIQ); iTo[14]=pModel->GetLakeStorageIndex();
6466
iFrom[15]=pModel->GetStateVarIndex(PONDED_WATER); iTo[15]=pModel->GetLakeStorageIndex();
65-
iFrom[16]=pModel->GetStateVarIndex(SNOW); iTo[16]=pModel->GetStateVarIndex(DEPRESSION);
66-
iFrom[17]=pModel->GetStateVarIndex(SNOW_LIQ); iTo[17]=pModel->GetStateVarIndex(DEPRESSION);
67-
iFrom[18]=pModel->GetStateVarIndex(PONDED_WATER); iTo[18]=pModel->GetStateVarIndex(DEPRESSION);
67+
if (pModel->StateVarExists(DEPRESSION)){
68+
iFrom[16]=pModel->GetStateVarIndex(SNOW); iTo[16]=pModel->GetStateVarIndex(DEPRESSION);
69+
iFrom[17]=pModel->GetStateVarIndex(SNOW_LIQ); iTo[17]=pModel->GetStateVarIndex(DEPRESSION);
70+
iFrom[18]=pModel->GetStateVarIndex(PONDED_WATER); iTo[18]=pModel->GetStateVarIndex(DEPRESSION);
71+
}
6872
}
6973
}
7074
//////////////////////////////////////////////////////////////////
@@ -347,14 +351,11 @@ void CmvPrecipitation::GetRatesOfChange(const double *state_vars,
347351
}
348352
}
349353
//////////////////////////////////////////////////////////////////
350-
/// \brief Applies constraints to baseflow
351-
/// \details For all methods, ensures that rate of flow cannot drain "from" compartment over timestep.
352-
///
353354
/// \param *state_vars [in] array of state variable values for this HRU (of size CModel::_nStateVars)
354355
/// \param *pHRU [in] Pointer to HRU object
355356
/// \param &Options [in] Global model options information
356357
/// \param &tt [in] Current input time structure
357-
/// \param *rates [out] Rates of change of state variables (of size MAX_CONNECTIONS)
358+
/// \param *rates [out] Rates of change of state variables
358359
//
359360
void CmvPrecipitation::ApplyConstraints(const double *state_vars,
360361
const CHydroUnit *pHRU,

src/RavenParameters.dat

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ SNOWFALL_ALBTHRESH GLOBAL [mm/d] False 10 5 20
9898
AVG_ANNUAL_SNOW GLOBAL [mm] False -9999 0.0 10000
9999
AVG_ANNUAL_RUNOFF GLOBAL [mm] False -9999 0.0 10000
100100
MAX_REACH_SEGLENGTH GLOBAL [km] False 100 0.0 1000000
101-
MAX_SWE_SURFACE GLOBAL [mm] False 300 1.0 100000
102101
UBC_S_CORR GLOBAL [0..1][12] True 1.0 0.25 2.0
103102
UBC_N_CORR GLOBAL [0..1][12] True 1.0 0.25 2.0
104103
UBC_GW_SPLIT GLOBAL [0..1] True 0.6 0.0 1.0

src/RavenProcessConnections.dat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ SNOBAL_TWO_LAYER SnowBalance CUM_SNOWMELT CUM_SNOWMELT
143143
SNOBAL_CEMA_NEIGE SnowBalance SNOW_COVER PONDED_WATER
144144
SNOBAL_CEMA_NEIGE SnowBalance SNOW_COVER SNOW_COVER
145145
SNOBAL_GAWSER SnowBalance SNOW SNOW_LIQ
146-
SNOBAL_GAWSER SnowBalance POMDED_WATER SNOW_LIQ
146+
SNOBAL_GAWSER SnowBalance PONDED_WATER SNOW_LIQ
147147
SNOBAL_GAWSER SnowBalance SNOW_LIQ SNOW
148148
SNOBAL_GAWSER SnowBalance SNOW_DEPTH SNOW_DEPTH
149149
SNOBAL_GAWSER SnowBalance SNOW ATMOSPHERE
@@ -218,4 +218,4 @@ DFLOW_THRESHPOW DepressionOverflow DEPRESSION SURFACE_WATER
218218
DFLOW_LINEAR DepressionOverflow DEPRESSION SURFACE_WATER
219219
DFLOW_WEIR DepressionOverflow DEPRESSION SURFACE_WATER
220220
SEEP_LINEAR Seepage DEPRESSION SOIL
221-
LAKEREL_LINEAR LakeRelease LAKE SURFACE_WATER
221+
LAKEREL_LINEAR LakeRelease LAKE SURFACE_WATER

src/TimeSeries.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ CTimeSeries *CTimeSeries::Parse(CParser *p, bool is_pulse, string name, long loc
882882
if(!strcmp(s[1],"STEP" )){step=true;}
883883
}
884884

885-
int *days=new int [(int)(DAYS_PER_YEAR)+1]; //sized for max # of events
886-
double *vals=new double [(int)(DAYS_PER_YEAR)+1];
885+
int *days=new int [366]; //sized for max # of events
886+
double *vals=new double [366];
887887
int nEvents=0;
888888

889889
p->Tokenize(s,Len);
@@ -896,7 +896,7 @@ CTimeSeries *CTimeSeries::Parse(CParser *p, bool is_pulse, string name, long loc
896896
days[nEvents]=GetJulianDayFromMonthYear(date_str,Options.calendar);
897897
vals[nEvents]=s_to_d(s[1]);
898898
nEvents++;
899-
ExitGracefullyIf(nEvents>(int)(DAYS_PER_YEAR),"CTimeSeries::Parse: exceeded maximum number of items in :AnnualPattern command",BAD_DATA);
899+
ExitGracefullyIf(nEvents>365,"CTimeSeries::Parse: exceeded maximum number of items in :AnnualPattern command",BAD_DATA);
900900
}
901901
else { p->ImproperFormat(s); break; }
902902
bool eof=p->Tokenize(s,Len);
@@ -919,7 +919,7 @@ CTimeSeries *CTimeSeries::Parse(CParser *p, bool is_pulse, string name, long loc
919919
}
920920
}
921921
else { //interpolate with wraparound
922-
double lastday=days[nEvents-1]-(int)(DAYS_PER_YEAR);
922+
double lastday=days[nEvents-1]-365;
923923
double nextday=days[0];
924924
double lastval=vals[nEvents-1];
925925
double nextval=vals[0];
@@ -929,13 +929,12 @@ CTimeSeries *CTimeSeries::Parse(CParser *p, bool is_pulse, string name, long loc
929929
nextval=vals[i+1];nextday=days[i+1];
930930
}
931931
}
932-
if (tt.julian_day > days[nEvents - 1]) {
932+
if (tt.julian_day >= days[nEvents - 1]) {
933933
lastval=vals[nEvents - 1]; lastday=days[nEvents - 1];
934-
nextval=vals[0]; nextday=days[0]+(int)(DAYS_PER_YEAR);
934+
nextval=vals[0]; nextday=days[0]+365;
935935
}
936936
if ((nextday-lastday)==0){aVal[n]=lastval; }
937937
else{
938-
939938
aVal[n]=(tt.julian_day-lastday)/(nextday-lastday)*(nextval-lastval)+lastval;
940939
}
941940
}

0 commit comments

Comments
 (0)