Skip to content

Commit b788f64

Browse files
James CraigJames Craig
authored andcommitted
v528 - !A[] commands; :StartDate QC
support !A[-n] reservoir stage history in management expressions (DemandExpressionHandling.cpp; DemandOptimization.cpp/.h) -new CDemandOptimizer member _aAhist bug fix: -moved QA/QC for missing :StartDate to after read of runinfo file (Parse
1 parent e137c47 commit b788f64

File tree

5 files changed

+16
-5
lines changed

5 files changed

+16
-5
lines changed

src/DemandExpressionHandling.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,7 @@ double CDemandOptimizer::EvaluateTerm(expressionTerm **pTerms,const int k, const
15851585

15861586
if (tmp=='Q'){return _aQhist[_aSBIndices[p]][nshift]; }
15871587
else if (tmp=='h'){return _ahhist[_aSBIndices[p]][nshift]; }
1588+
else if (tmp=='A'){return _aAhist[_aSBIndices[p]][nshift]; }
15881589
else if (tmp=='D'){return _aDhist[_aSBIndices[p]][nshift]; }
15891590
else if (tmp=='I'){return _aIhist[_aSBIndices[p]][nshift]; }
15901591
else if (tmp=='B'){return _pModel->GetSubBasin(p)->GetSpecifiedInflow(t+pT->timeshift*1.0); } //ASSUMES DAILY TIMESTEP! \todo[funct] should be Options.timestep

src/DemandOptimization.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ CDemandOptimizer::CDemandOptimizer(CModel *pMod)
6868
_aDhist=NULL;
6969
_aIhist=NULL;
7070
_ahhist=NULL;
71+
_aAhist=NULL;
7172

7273
_nGoals=0;
7374
_pGoals=NULL;
@@ -113,10 +114,12 @@ CDemandOptimizer::~CDemandOptimizer()
113114
delete [] _aDhist[p];
114115
delete [] _aIhist[p];
115116
delete [] _ahhist[p];
117+
delete [] _aAhist[p];
116118
}
117119
}
118120
delete [] _aQhist;
119121
delete [] _ahhist;
122+
delete [] _aAhist;
120123
delete [] _aDhist;
121124
delete [] _aIhist;
122125
delete [] _aUserConstants;
@@ -768,19 +771,22 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op
768771
_ahhist = new double *[_nEnabledSubBasins];
769772
_aDhist = new double *[_nEnabledSubBasins];
770773
_aIhist = new double *[_nEnabledSubBasins];
771-
ExitGracefullyIf(_aDhist==NULL,"CDemandOptimizer::InitializePostRVMRead",OUT_OF_MEMORY);
774+
_aAhist = new double *[_nEnabledSubBasins];
775+
ExitGracefullyIf(_aAhist==NULL,"CDemandOptimizer::InitializePostRVMRead",OUT_OF_MEMORY);
772776
for (int pp=0;pp<_nEnabledSubBasins;pp++){
773777
_aDhist[pp]=NULL;
774778
_aQhist[pp] = new double[_nHistoryItems];
775779
_ahhist[pp] = new double[_nHistoryItems];
776780
_aDhist[pp] = new double[_nHistoryItems];
777781
_aIhist[pp] = new double[_nHistoryItems];
778-
ExitGracefullyIf(_aDhist[pp]==NULL,"CDemandOptimizer::InitializePostRVMRead (2)",OUT_OF_MEMORY);
782+
_aAhist[pp] = new double[_nHistoryItems];
783+
ExitGracefullyIf(_aAhist[pp]==NULL,"CDemandOptimizer::InitializePostRVMRead (2)",OUT_OF_MEMORY);
779784
for (int i = 0; i < _nHistoryItems; i++) {
780785
_aQhist[pp][i]=0.0;
781786
_ahhist[pp][i]=0.0;
782787
_aDhist[pp][i]=0.0;
783788
_aIhist[pp][i]=0.0;
789+
_aAhist[pp][i]=0.0;
784790
}
785791
}
786792

@@ -1290,17 +1296,20 @@ void CDemandOptimizer::UpdateHistoryArrays()
12901296
_aDhist[pp][i]=_aDhist[pp][i-1];
12911297
_aIhist[pp][i]=_aIhist[pp][i-1];
12921298
_ahhist[pp][i]=_ahhist[pp][i-1];
1299+
_aAhist[pp][i]=_aAhist[pp][i-1];
12931300
}
12941301
_aQhist[pp][0]=pSB->GetOutflowRate();
12951302
_aDhist[pp][0]=0.0;
12961303
_aIhist[pp][0]=0.0;
12971304
_ahhist[pp][0]=0.0;
1305+
_aAhist[pp][0]=0.0;
12981306
for (int ii=0;ii<pSB->GetNumWaterDemands();ii++){
12991307
_aDhist[pp][0]+=pSB->GetDemandDelivery(ii);
13001308
}
13011309
if (pSB->GetReservoir()!=NULL){
13021310
_aIhist[pp][0]=pSB->GetChannelOutflowRate();
13031311
_ahhist[pp][0]=pSB->GetReservoir()->GetResStage();
1312+
_aAhist[pp][0]=pSB->GetReservoir()->GetSurfaceArea();
13041313
}
13051314
}
13061315
}

src/DemandOptimization.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ class CDemandOptimizer
261261
double **_aDhist; //< history of actual delivery [size: _nEnabledSBs * _nHistoryItems]
262262
double **_aIhist; //< history of reservoir inflows [size: _nEnabledSBs * _nHistoryItems]
263263
double **_ahhist; //< history of actual reservoir stages (or 0 for non-reservoir basins) [size: _nEnabledSBs * _nHistoryItems]
264+
double **_aAhist; //< history of actual reservoir areas [size: _nEnabledSBs * _nHistoryItems]
264265

265266
int _nSolverResiduals; //< number of residuals of solution (equal to lp_lib::nRows)
266267
double *_aSolverResiduals; //< vector of residuals of solution [size: _nSolverResiduals]

src/ParseInput.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ bool ParseInputFiles (CModel *&pModel,
113113
ExitGracefully("Cannot find or read NetCDF runinfo file", BAD_DATA); return false;
114114
}
115115
}
116+
ExitGracefullyIf(Options.julian_start_year==1666,
117+
"ParseMainInputFile:: no :StartDate supplied in .rvi or runinfo.nc file.",BAD_DATA_WARN);
116118

117119
// Class Property file (.rvp)
118120
//--------------------------------------------------------------------------------
@@ -3640,8 +3642,6 @@ bool ParseMainInputFile (CModel *&pModel,
36403642
"ParseMainInputFile::Must have a postitive time step",BAD_DATA);
36413643
ExitGracefullyIf(Options.duration<0,
36423644
"ParseMainInputFile::Model duration less than zero. Make sure :EndDate is after :StartDate.",BAD_DATA_WARN);
3643-
ExitGracefullyIf(Options.julian_start_year==1666,
3644-
"ParseMainInputFile:: no :StartDate supplied in .rvi or runinfo.nc file.",BAD_DATA_WARN);
36453645

36463646
if((Options.nNetCDFattribs>0) && (Options.output_format!=OUTPUT_NETCDF)){
36473647
WriteAdvisory("ParseMainInputFile: NetCDF attributes were specified but output format is not NetCDF.",Options.noisy);

src/Solvers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ void MassEnergyBalance( CModel *pModel,
548548
pBasin->UpdateSubBasin(tt,Options);
549549
}
550550

551-
// Management optimization - determines optimal demand delivery/reservoir outflows
551+
// Management optimization - determines optimal demand delivery/reservoir outflows/return flows
552552
// ----------------------------------------------------------------------------------------
553553
if (Options.management_optimization)
554554
{

0 commit comments

Comments
 (0)