Skip to content

Commit 2e43f41

Browse files
James CraigJames Craig
authored andcommitted
v494b - fix to user variable handling introduced in v494
1 parent 6ceaa70 commit 2e43f41

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/DemandExpressionHandling.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,11 +217,8 @@ workflowVar* CDemandOptimizer::GetWorkflowVarStruct(string s) {
217217
int CDemandOptimizer::GetUserDVIndex(const string s) const
218218
{
219219
int ct=0;
220-
for (int i = 0; i < _nDecisionVars; i++) {
221-
if (_pDecisionVars[i]->dvar_type==DV_USER){
222-
if (_pDecisionVars[i]->name==s){return ct;}
223-
ct++;
224-
}
220+
for (int i = 0; i < _nUserDecisionVars; i++) {
221+
if (_pUserDecisionVars[i]->name==s){return i;}
225222
}
226223
return DOESNT_EXIST;
227224
}
@@ -233,7 +230,7 @@ int CDemandOptimizer::GetUserDVIndex(const string s) const
233230
/// index is subbasin index p for subbasin-based DVs, or demand index ii for demand-linked DVs
234231
/// supports !Qxxx, !Q.name, !hxxx, !Ixxx, !Dxxx, !Cxxx, $Bxxx, $Exxx, !dxxx, !Rxxx
235232
//
236-
int CDemandOptimizer::GetIndexFromDVString(string s) const //String in format !Qxxx or !Q.name but not !Qxx[n]
233+
int CDemandOptimizer::GetIndexFromDVString(string s) const //String in format !Qxxx or !Q.name or $dxxx but not !Qxx[n]
237234
{
238235
if ((s[1] == 'Q') || (s[1] == 'h') || (s[1]=='I') || (s[1]=='B') || (s[1]=='E')) //Subbasin-indexed \todo[funct] - support q = dQ/dt
239236
{
@@ -504,6 +501,17 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t
504501
term->p_index=p;
505502
return true;
506503
}
504+
else if (s[1] == 'd') {
505+
int d=GetIndexFromDVString(s);
506+
if (d == DOESNT_EXIST) {
507+
warn="ConvertToExpressionTerm: invalid demand ID or demand from disabled subbasin used in expression " +warnstring +": goal/constraint will be ignored";
508+
WriteWarning(warn.c_str(),true);
509+
return false;
510+
}
511+
term->type=TERM_CONST;
512+
term->value=_pDemands[d]->GetDemand();
513+
return true;
514+
}
507515
}
508516
//----------------------------------------------------------------------
509517
else if (s.substr(0, 4) == "@ts(")//time series (e.g., @ts(my_time_series,n)
@@ -763,7 +771,6 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t
763771
//----------------------------------------------------------------------
764772
else if (GetWorkflowVariable(s,index) != RAV_BLANK_DATA) // workflow variable
765773
{
766-
767774
term->type=TERM_WORKFLOW;
768775
term->value=GetWorkflowVariable(s,index);// initially zero
769776
term->DV_ind=index;

src/ParseInitialConditionFile.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,9 @@ bool ParseInitialConditionsFile(CModel *&pModel, const optStruct &Options)
795795
pConstit->SetMoutArray(p,nsegs,aMout,aMout[nsegs]);
796796
delete[] aMout;
797797
}
798+
else {
799+
WriteWarning("ParseInitialConditionsFile: incorrect number of terms in :Mout initial conditions item",Options.noisy);
800+
}
798801
}
799802
}
800803
else if(!strcmp(s[0],":Mlat"))
@@ -809,6 +812,9 @@ bool ParseInitialConditionsFile(CModel *&pModel, const optStruct &Options)
809812
pConstit->SetMlatHist(p,histsize,aMlat,aMlat[histsize]);
810813
delete[] aMlat;
811814
}
815+
else {
816+
WriteWarning("ParseInitialConditionsFile: incorrect number of terms in :Mlat initial conditions item",Options.noisy);
817+
}
812818
}
813819
}
814820
else if(!strcmp(s[0],":Min"))
@@ -823,6 +829,9 @@ bool ParseInitialConditionsFile(CModel *&pModel, const optStruct &Options)
823829
pConstit->SetMinHist(p,histsize,aMin);
824830
delete[] aMin;
825831
}
832+
else {
833+
WriteWarning("ParseInitialConditionsFile: incorrect number of terms in :Min initial conditions item",Options.noisy);
834+
}
826835
}
827836
}
828837
else if(!strcmp(s[0],":ResMass"))

0 commit comments

Comments
 (0)