Skip to content

Commit 68ab732

Browse files
committed
v512 - fixed demand optimization issues with lake at sill
Micromanaging managment support for at-sill lakes - A DEVIOUS BUG! -Add CReservoir::GetSurfaceAreaFromStage() (Reservoir.h/cpp) -Properly handle stage-discharge derivatives for h-h_sill<0.001 (Reservoir.cpp) -(temporarily?) introduce DV_RSLACK for debugging (DemandOptimization.h; DemandExpressionHandling.cpp;DemandOptimization.cpp) -track history of binary values through iterations (DemandOptimization.cpp) -enable relaxation after first infeasible solution (DemandOptimization.cpp) -fix bug in handling DSTAGE2 in iteration (DemandOptimization.cpp) [THIS DID THE TRICK] -properly support changing lake area during iteration (DemandOptimization.cpp) -don't update reservoir outflow unless managed at close of LP solve (DemandOptimization.cpp) [THE OTHER KEY TRICK] minor: Handle disabled SBs in CSubBasin::InitializePostRVM() (SubBasin.cpp)
1 parent eaf0a28 commit 68ab732

File tree

8 files changed

+213
-187
lines changed

8 files changed

+213
-187
lines changed

src/CommonFunctions.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1949,7 +1949,6 @@ double InterpolateCurve(const double x,const double *xx,const double *y,int N,bo
19491949
{
19501950
//int i=0; while ((x>xx[i+1]) && (i<(N-2))){i++;}//Dumb Search
19511951
int i=SmartIntervalSearch(x,xx,N,ilast);
1952-
if(i==DOESNT_EXIST) { return 0.0; }
19531952
ExitGracefullyIf(i==DOESNT_EXIST,"InterpolateCurve::mis-ordered list or infinite x",RUNTIME_ERR);
19541953
ilast=i;
19551954
if (fabs(xx[i+1]-xx[i]) < REAL_SMALL) { return (y[i]+y[i+1])/2; } // x locations too close to each other

src/DemandExpressionHandling.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,8 @@ string DVTypeToString(dv_type t)
288288
if (t==DV_QOUTRES ){return "DV_QOUTRES"; }
289289
if (t==DV_STAGE ){return "DV_STAGE"; }
290290
if (t==DV_DSTAGE ){return "DV_DSTAGE"; }
291-
if (t==DV_DSTAGE2 ){return "DV_DSTAGE2"; }
291+
if (t==DV_DSTAGE2 ){return "DV_DSTAGE2"; }
292+
if (t==DV_RSLACK ){return "DV_RSLACK"; }
292293
if (t==DV_BINRES ){return "DV_BINRES"; }
293294
if (t==DV_DELIVERY){return "DV_DELIVERY"; }
294295
if (t==DV_RETURN ){return "DV_RETURN"; }

src/DemandOptimization.cpp

Lines changed: 191 additions & 176 deletions
Large diffs are not rendered by default.

src/DemandOptimization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ enum dv_type
4444
DV_STAGE, //< reservoir stage
4545
DV_DSTAGE, //< positive change in reservoir stage over time step
4646
DV_DSTAGE2, //< negative change in reservoir stage over time step
47+
DV_RSLACK, //< slack variable for res outflow adjustment
4748
DV_BINRES, //< binary integer value for above/beneath stage-discharge sill
4849
DV_DELIVERY,//< delivery of water demand
4950
DV_RETURN, //< return flows to reach

src/ParseInput.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,7 @@ bool ParseMainInputFile (CModel *&pModel,
17821782
break;
17831783
}
17841784
case(94): //--------------------------------------------
1785-
{/*:AssimilatReservoirStage*/
1785+
{/*:AssimilateReservoirStage*/
17861786
if(Options.noisy) { cout << "Assimilate lake stage on" << endl; }
17871787
Options.assimilate_stage=true;
17881788
break;

src/Reservoir.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,11 @@ bool CReservoir::UseInStageAssimilation() const
483483
//
484484
double CReservoir::GetSurfaceArea () const { return GetArea(_stage); }
485485

486+
//////////////////////////////////////////////////////////////////
487+
/// \returns surface area given stage [m2]
488+
//
489+
double CReservoir::GetSurfaceAreaFromStage (const double h) const {return GetArea(h);}
490+
486491
//////////////////////////////////////////////////////////////////
487492
/// \returns start-of-timestep surface area [m2]
488493
//
@@ -648,6 +653,8 @@ double CReservoir::GetStageDischargeDerivative(const double &stage, const int nn
648653
if(_pWeirHeightTS!=NULL) {
649654
weir_adj=_pWeirHeightTS->GetSampledValue(nn);
650655
}
656+
double h_sill=GetSillElevation(nn);
657+
if (stage <=h_sill){return 0.0;}
651658

652659
return (GetWeirOutflow(stage+dh,weir_adj)-GetWeirOutflow(stage,weir_adj))/dh;
653660
}

src/Reservoir.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ class CReservoir
193193
double GetOldStage () const; //[m]
194194
double GetSurfaceArea () const; //[m2]
195195
double GetOldSurfaceArea () const; //[m2]
196+
double GetSurfaceAreaFromStage (const double h) const;//[m2]
196197
double GetLakebedThickness () const; //[m]
197198
double GetLakebedConductivity () const; //[MJ/m/K/d]
198199
double GetLakeConvectionCoeff () const; //[MJ/m2/d/K]

src/SubBasin.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,16 +1757,18 @@ void CSubBasin::Initialize(const double &Qin_avg, //[m3/s] from upst
17571757
//
17581758
void CSubBasin::InitializePostRVM(const optStruct &Options)
17591759
{
1760-
if (_nWaterDemands>0){
1761-
_aQdelivered=new double [_nWaterDemands];
1762-
_aQreturned =new double [_nWaterDemands];
1763-
for (int ii=0;ii<_nWaterDemands;ii++){
1764-
_pWaterDemands[ii]->Initialize(Options);
1765-
_aQdelivered [ii]=0.0;
1766-
_aQreturned [ii]=0.0;
1760+
if (!_disabled) {
1761+
if (_nWaterDemands>0){
1762+
_aQdelivered=new double [_nWaterDemands];
1763+
_aQreturned =new double [_nWaterDemands];
1764+
for (int ii=0;ii<_nWaterDemands;ii++){
1765+
_pWaterDemands[ii]->Initialize(Options);
1766+
_aQdelivered [ii]=0.0;
1767+
_aQreturned [ii]=0.0;
1768+
}
17671769
}
1770+
if (_pReservoir!=NULL){_pReservoir->InitializePostRVM(Options); }
17681771
}
1769-
if (_pReservoir!=NULL){_pReservoir->InitializePostRVM(Options); }
17701772
}
17711773
//////////////////////////////////////////////////////////////////
17721774
/// \brief Initializes channel flows, channel storage, rivulet storage from estimated mean inflows

0 commit comments

Comments
 (0)