diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e1685b60..7ca113f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,7 +3,7 @@ default_language_version: repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-json - id: pretty-format-json @@ -26,7 +26,7 @@ repos: # - id: include-what-you-use - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.28.6 + rev: 0.29.3 hooks: - id: check-github-workflows - repo: meta diff --git a/src/CommonFunctions.cpp b/src/CommonFunctions.cpp index 2da17762..ba86464d 100644 --- a/src/CommonFunctions.cpp +++ b/src/CommonFunctions.cpp @@ -1834,7 +1834,7 @@ void quickSort(double arr[], int left, int right) } ////////////////////////////////////////////////////////////////// /// \brief adds value v to end of integer array a[] of original size n, expands a[] to size n+1 -// +// void pushIntoIntArray(int*&a, const int &v, int &n) { int *tmp=new int [n+1]; diff --git a/src/DemandExpressionHandling.cpp b/src/DemandExpressionHandling.cpp index 575e7f29..0aa30176 100644 --- a/src/DemandExpressionHandling.cpp +++ b/src/DemandExpressionHandling.cpp @@ -302,7 +302,7 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t return true; } - } + } else { warn="ConvertToExpression:: Unparseable term in history expression starting with !/$ - only !Q, !I, !D, !h, $B, or $E currently supported. "+warnstring; ExitGracefully(warn.c_str(), BAD_DATA_WARN); @@ -393,7 +393,7 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t return true; } //---------------------------------------------------------------------- - else if (s[0] == '$') + else if (s[0] == '$') { if ((s[1] == 'B') || (s[1] == 'E')) //Subbasin-indexed { @@ -1115,7 +1115,7 @@ void CDemandOptimizer::AddConstraintToLP(const int ii, const int kk, lp_lib::lpr pE= pC->pOperRegimes[0]->pExpression; //inactive expression } - if ((kk==DOESNT_EXIST) || (!constraint_valid)) // INACTIVE/INVALID GOAL/CONSTRAINT + if ((kk==DOESNT_EXIST) || (!constraint_valid)) // INACTIVE/INVALID GOAL/CONSTRAINT { if (!pC->is_goal) { col_ind[i]=1; @@ -1150,7 +1150,7 @@ void CDemandOptimizer::AddConstraintToLP(const int ii, const int kk, lp_lib::lpr #endif ////////////////////////////////////////////////////////////////// -/// evaluates difference between right hand side and left hand side of expression, or value of RHS if RHS_only==true and statement only has one term left of (in)equality +/// evaluates difference between right hand side and left hand side of expression, or value of RHS if RHS_only==true and statement only has one term left of (in)equality /// does not support active decision variables in expression (only to be used for conditionals and demand/return expressions) /// \params pE [in] - conditional expression /// \param t [in] - current model time @@ -1192,7 +1192,7 @@ double CDemandOptimizer::EvaluateExpression(const expressionStruct* pE,const dou } } } - + RHS-=coeff; //term group goes on right hand side } } @@ -1207,7 +1207,7 @@ double CDemandOptimizer::EvaluateExpression(const expressionStruct* pE,const dou // bool CDemandOptimizer::EvaluateConditionExp(const expressionStruct* pE,const double &t) const { - + double RHSminusLHS=EvaluateExpression(pE,t,false); if (fabs(RHSminusLHS-RAV_BLANK_DATA)GetName() == name) { @@ -165,14 +165,14 @@ CDemandGroup* CDemandOptimizer::GetDemandGroupFromName(const string name) return NULL; } ////////////////////////////////////////////////////////////////// -/// \brief gets demand group from index +/// \brief gets demand group from index // -int CDemandOptimizer::GetNumDemandGroups() const +int CDemandOptimizer::GetNumDemandGroups() const { return _nDemandGroups; } ////////////////////////////////////////////////////////////////// -/// \brief returns true if demands have been initialized +/// \brief returns true if demands have been initialized // bool CDemandOptimizer::DemandsAreInitialized() const { @@ -220,7 +220,7 @@ void CDemandOptimizer::SetDebugLevel(const int val) /// \brief assigns a demand 'unrestricted' status, meaning it wont be considered when applying environmental min flow constraints /// \params dname [in] - name of demand // -void CDemandOptimizer::SetDemandAsUnrestricted(const string dname) +void CDemandOptimizer::SetDemandAsUnrestricted(const string dname) { int d = GetDemandIndexFromName(dname); if (d!=DOESNT_EXIST){ @@ -228,7 +228,7 @@ void CDemandOptimizer::SetDemandAsUnrestricted(const string dname) } else{ string warn = "CDemandOptimizer::SetDemandAsUnrestricted: invalid or disabled demand name " + dname +" provided in : DemandIsUnrestricted command. This will be ignored "; - WriteWarning(warn,true); + WriteWarning(warn,true); } } ////////////////////////////////////////////////////////////////// @@ -243,7 +243,7 @@ void CDemandOptimizer::SetDemandPenalty(const string dname, const double& pen) } else { string warn = "CDemandOptimizer::SetDemandPenalty: invalid or disabled demand name " + dname +" provided in : DemandPenalty command. This will be ignored "; - WriteWarning(warn,true); + WriteWarning(warn,true); } } ////////////////////////////////////////////////////////////////// @@ -267,7 +267,7 @@ void CDemandOptimizer::SetCumulativeDate(const int julian_date, const string dem /// \brief adds demand group to array of demand groups /// \params groupname [in] - user-specified demand group name // -void CDemandOptimizer::AddDemandGroup(const string groupname) +void CDemandOptimizer::AddDemandGroup(const string groupname) { CDemandGroup *pDG=new CDemandGroup(groupname,_nDemandGroups); @@ -279,7 +279,7 @@ void CDemandOptimizer::AddDemandGroup(const string groupname) /// \brief adds demand ONLY if subbasin associated with demand is enabled, otherwise tosses out. /// \params pDem [in] - pointer to demand object // -void CDemandOptimizer::AddWaterDemand(CDemand* pDem) +void CDemandOptimizer::AddWaterDemand(CDemand* pDem) { long SBID=pDem->GetSubBasinID(); if (_pModel->GetSubBasinByID(SBID)->IsEnabled()) @@ -594,7 +594,7 @@ void CDemandOptimizer::InitializeDemands(CModel* pModel, const optStruct& Option if (Options.noisy){cout<<"CDemandOptimizer: Demand initialization..."<GetSubBasinByID(_pDemands[d]->GetSubBasinID())->GetGlobalIndex(); pDV=new decision_var(_pDemands[d]->GetName(), p, DV_DELIVERY, d); @@ -623,10 +623,10 @@ void CDemandOptimizer::InitializeDemands(CModel* pModel, const optStruct& Option AddDecisionVar(pDV); } - // add return flow decision vars + // add return flow decision vars //------------------------------------------------------------------ int r=0; - for (int d = 0; d < _nDemands; d++) + for (int d = 0; d < _nDemands; d++) { if (_pDemands[d]->HasReturnFlow()) { @@ -636,7 +636,7 @@ void CDemandOptimizer::InitializeDemands(CModel* pModel, const optStruct& Option else { p=DOESNT_EXIST; } - + //pDV=new decision_var(_pDemands[d]->GetName()+"[return]", p, DV_RETURN, r); pDV=new decision_var(_pDemands[d]->GetName()+"[return]", p, DV_RETURN, d); //loc_index is d so that demand can be accessed (not r) pDV->dem_index=_pDemands[d]->GetLocalIndex(); //ii @@ -649,7 +649,7 @@ void CDemandOptimizer::InitializeDemands(CModel* pModel, const optStruct& Option _demands_initialized=true; } -string ComparisonToString(comparison C) +string ComparisonToString(comparison C) { if (C==COMPARE_IS_EQUAL){return "="; } if (C==COMPARE_GREATERTHAN){return ">"; } @@ -696,7 +696,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op _aIhist[pp][i]=0.0; } } - + int p; _nSlackVars = 0; CSubBasin *pSB; @@ -704,7 +704,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op // create 2 slack variables for reservoir outflow by stage-discharge //------------------------------------------------------------------ - //remove if _stage_discharge_as_goal option REMOVED + //remove if _stage_discharge_as_goal option REMOVED for (int pp=0;ppGetNumSubBasins();pp++) { p=pModel->GetOrderedSubBasinIndex(pp); @@ -740,11 +740,11 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op //------------------------------------------------------------------ AddReservoirConstraints(); - // Calculate penalty units correction for reservoirs + // Calculate penalty units correction for reservoirs //------------------------------------------------------------------ for (int j = 0; j < _nGoals; j++) { - if ((_pGoals[j]->is_goal) && (_pGoals[j]->use_stage_units)) + if ((_pGoals[j]->is_goal) && (_pGoals[j]->use_stage_units)) { pSB =_pModel->GetSubBasin(_pGoals[j]->reservoir_index); @@ -766,7 +766,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op for (int j = 0; j < _nGoals; j++) { for (int k=0;k<_pGoals[j]->nOperRegimes;k++){ - if (_pGoals[j]->pOperRegimes[k]->penalty_over ==RAV_BLANK_DATA){_pGoals[j]->pOperRegimes[k]->penalty_over =_pGoals[j]->penalty_over; } + if (_pGoals[j]->pOperRegimes[k]->penalty_over ==RAV_BLANK_DATA){_pGoals[j]->pOperRegimes[k]->penalty_over =_pGoals[j]->penalty_over; } if (_pGoals[j]->pOperRegimes[k]->penalty_under==RAV_BLANK_DATA){_pGoals[j]->pOperRegimes[k]->penalty_under=_pGoals[j]->penalty_under;} } } @@ -951,7 +951,7 @@ void CDemandOptimizer::AddReservoirConstraints() pGoal->use_stage_units=true; pGoal->reservoir_index=p; pGoal->penalty_over=6.0; - + AddGoalOrConstraint(pGoal); advice="A :ReservoirMaxStage time series for subbasin "+SBIDs+" has been added to the management optimization formulation"; WriteAdvisory(advice,false); @@ -973,7 +973,7 @@ void CDemandOptimizer::AddReservoirConstraints() TokenizeString(expString, s, Len); exp = ParseExpression((const char**)(s), Len, 0, "internal"); - + pGoal=new managementGoal(); pGoal->name=TSname; pGoal->is_goal=true; @@ -1273,7 +1273,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // Set upper bounds of delivery (D) to demand (D*) (preferred to adding constraint) // ---------------------------------------------------------------- - for (int d = 0; d < _nDemands; d++) + for (int d = 0; d < _nDemands; d++) { retval=lp_lib::set_upbo(pLinProg,GetDVColumnInd(DV_DELIVERY,d), _pDemands[d]->GetDemand()); ExitGracefullyIf(retval!=1,"SolveDemandProblem::Error adding demand upper bound",RUNTIME_ERR); @@ -1282,7 +1282,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // Set upper bounds of return (R) to max return (R*) (preferred to adding constraint) // ---------------------------------------------------------------- int r=0; - for (int d = 0; d < _nDemands; d++) + for (int d = 0; d < _nDemands; d++) { if (_pDemands[d]->HasReturnFlow()){ retval=lp_lib::set_upbo(pLinProg,GetDVColumnInd(DV_RETURN,r), _pDemands[d]->GetReturnFlowTarget()); @@ -1393,7 +1393,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // penalties for unmet demand // ---------------------------------------------------------------- - for (int d = 0; d < _nDemands; d++) + for (int d = 0; d < _nDemands; d++) { demand_penalty_sum+=(_pDemands[d]->GetPenalty()*_pDemands[d]->GetDemand()); @@ -1409,7 +1409,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio for (int d = 0; d < _nDemands; d++) { if (_pDemands[d]->HasReturnFlow()) { - col_ind[i]=GetDVColumnInd(DV_RETURN,r); + col_ind[i]=GetDVColumnInd(DV_RETURN,r); row_val[i]=-1.0; i++; r++; @@ -1462,7 +1462,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio { _pGoals[j]->conditions_satisfied=false; _pGoals[j]->active_regime=DOESNT_EXIST; - + // ASSUMES ALL OP REGIME EXPRESSIONS IN GOAL/CONSTRAINT ARE EITHER == or >/<, NEVER MIXED. // TODO - really need to also determine wheter constraint is even valid (e.g., due to BLANK_DATA in @ts). right now this is withheld until AddConstraintToLP called for (int k=0;k<_pGoals[j]->nOperRegimes;k++) @@ -1575,12 +1575,12 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio d=pSB->GetWaterDemandObj(ii)->GetGlobalIndex(); col_ind[i]=GetDVColumnInd(DV_DELIVERY,d); row_val[i]=1.0; - i++; + i++; } - + // return flow terms ============================= int r=0; - for (int d = 0; d < _nDemands; d++) + for (int d = 0; d < _nDemands; d++) { if (_pDemands[d]->HasReturnFlow()){ if ((_pDemands[d]->GetTargetSBID()==SBID)) { @@ -1616,7 +1616,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio //AddLakeMBEquations(pLinProg,s); //AddLakeOutflowEquations(pLinProg,s); - + // Determine which lakes/reservoirs should have their stage/discharge curve constraints disabled // depends upon whether overriding goals are active //------------------------------------------------------------------ @@ -1627,9 +1627,9 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio } for (int j = 0; j < _nGoals; j++) { - if ((_pGoals[j]->reservoir_index != DOESNT_EXIST) && - (_pGoals[j]->active_regime != DOESNT_EXIST) && - (_pGoals[j]->overrides_SDcurve)) + if ((_pGoals[j]->reservoir_index != DOESNT_EXIST) && + (_pGoals[j]->active_regime != DOESNT_EXIST) && + (_pGoals[j]->overrides_SDcurve)) { p=_pGoals[j]->reservoir_index; aDisableSDCurve[p]=true; @@ -1689,11 +1689,11 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio i++; for (int ii = 0; iiGetReservoir()->GetNumWaterDemands();ii++) - { + { d=pRes->GetWaterDemandObj(ii)->GetGlobalIndex(); col_ind[i]=GetDVColumnInd(DV_DELIVERY ,d); row_val[i]=+1.0; - i++; + i++; } RHS=(precip-ET)-seepage-0.5*Qout_last+0.5*Qin_last;//+Adt*h_old; //TMP DEBUG : DSTAGE testing @@ -1714,7 +1714,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio i++; RHS=h_old; - + retval = lp_lib::add_constraintex(pLinProg,i,row_val,col_ind,ROWTYPE_EQ,RHS); ExitGracefullyIf(retval==0,"SolveDemandProblem::Error adding delta stage definition",RUNTIME_ERR); @@ -1770,20 +1770,20 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio lprow[p]=lp_lib::get_Nrows(pLinProg); } - else + else { // Stage discharge relation AS IF-ELSE CONSTRAINT : (Formulation from B. Tolson) // ------------------------------------------------------------------------ // linearized storage -discharge curve // Qout = Qout_guess + dQ/dh * (h-h_guess) if h>h_sill // Qout = 0 if h= h_sill // M must be >> |h-h_sill| //------------------------------------------------------------------------ @@ -1806,7 +1806,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio //------------------------------------------------------------------------ // Eqns 3 & 4 : Q^n+1 >= -M(1-b) // Q^n+1 <= M(1-b) - // M must be >> Q + // M must be >> Q //------------------------------------------------------------------------ col_ind[0]=GetDVColumnInd(DV_QOUTRES,_aResIndices[p]); row_val[0]=1.0; @@ -1830,7 +1830,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // Q^n+1 <= Qout_guess + dQ/dh * (h^n+1-h_guess) + M(b) // Q^n+1 - dQdh* h^n+1 + Mb >= [Qout_guess - dQ/dh * h_guess] // Q^n+1 - dQdh* h^n+1 - Mb <= [Qout_guess - dQ/dh * h_guess] - // dQ << M + // dQ << M //------------------------------------------------------------------------ col_ind[0]=GetDVColumnInd(DV_QOUTRES,_aResIndices[p]); row_val[0]=1.0; @@ -1844,7 +1844,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio lprow[p]=lp_lib::get_Nrows(pLinProg); IncrementAndSetRowName(pLinProg,rowcount,"reserv_Q_E"+to_string(pSB->GetID())); - + col_ind[0]=GetDVColumnInd(DV_QOUTRES,_aResIndices[p]); row_val[0]=1.0; col_ind[1]=GetDVColumnInd(DV_STAGE ,_aResIndices[p]); row_val[1]=-dQdh; col_ind[2]=GetDVColumnInd(DV_BINRES ,_aResIndices[p]); row_val[2]=-LARGE_NUMBER2; @@ -1855,7 +1855,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio IncrementAndSetRowName(pLinProg,rowcount,"reserv_Q_F"+to_string(pSB->GetID())); } } - else /* if (aDisableSDCurve[p])*/ //keep same rows - make inert equations + else /* if (aDisableSDCurve[p])*/ //keep same rows - make inert equations { if (_stage_discharge_as_goal) { @@ -1914,7 +1914,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio //------------------------------------------------------------------------ // 10^6 * e+ >= (sum of upstream D) - if e+ is zero, min flow is violated, therefore shutting down upstream delivery // if e+ > zero, min flow is not violated, so upstream demand is allowed - //------------------------------------------------------------------------ + //------------------------------------------------------------------------ col_ind[0]=GetDVColumnInd(DV_SLACK,s); row_val[0]=ENV_FLOW_PENALTY; i=1; @@ -1935,7 +1935,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio } } - // Return flow constraints + // Return flow constraints // ---------------------------------------------------------------- r=0; for (int d = 0; d < _nDemands; d++) { @@ -1968,22 +1968,22 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // ---------------------------------------------------------------- // ITERATIVELY SOLVE OPTIMIZATION PROBLEM WITH LP_SOLVE - // ---------------------------------------------------------------- + // ---------------------------------------------------------------- const int NUM_ITERATIONS=7; int ctyp; int nrows =lp_lib::get_Nrows(pLinProg); double *soln =new double [_nDecisionVars]; double *constr =new double [nrows]; - if (_aSolverResiduals==NULL){ //TODO: problem: this needs to be max nrows + if (_aSolverResiduals==NULL){ //TODO: problem: this needs to be max nrows _aSolverResiduals=new double [nrows]; _nSolverResiduals=nrows; - _aSolverRowNames =new string [nrows]; + _aSolverRowNames =new string [nrows]; } string dumpfile =Options.output_dir+"/lp_solve_dump.txt"; lp_lib::set_add_rowmode(pLinProg, FALSE); //must be turned off once model goals/constraints and obj function are added - lp_lib::set_minim (pLinProg); //ensures this is treated as a minimization probleme + lp_lib::set_minim (pLinProg); //ensures this is treated as a minimization probleme lp_lib::set_verbose (pLinProg,IMPORTANT); for (int iter=0; iter=2) { cout<<"Objective value: "<GetCumulDeliveryDate()){ - _aCumDelivery[d]=0.0; + _aCumDelivery[d]=0.0; } //_pDemands[d]->SetDeliveredDemand(ii); @@ -2179,16 +2179,16 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio pModel->GetSubBasin(p)->GetReservoir()->AddToDeliveredDemand(ii, value); } } - else if (typ == DV_RETURN) + else if (typ == DV_RETURN) { ii=_pDecisionVars[i]->dem_index; d =_pDecisionVars[i]->loc_index; //d is stored in loc_index, instead of r - - if (p!=DOESNT_EXIST){// here, p is index of *recipient* subbasin + + if (p!=DOESNT_EXIST){// here, p is index of *recipient* subbasin pModel->GetSubBasin(p)->AddToReturnFlow(value); } else { - //todo: add irrigation support + //todo: add irrigation support //pModel->AddIrrigation(value,_pDemands[d]->GetIrrigationHRUGroup()); } //pDemands[d]->RecordReturnFlow(value); @@ -2201,12 +2201,12 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio demand_penalty_sum+=value; } else if (typ == DV_SLACK) - { + { s = _pDecisionVars[i]->loc_index; _aSlackValues[s]=value; } } - + #endif } @@ -2299,27 +2299,27 @@ void CDemandOptimizer::WriteMinorOutput(const optStruct &Options,const time_stru bool include_pen=false; double pen; double mult=1.0; - + _GOALSAT<is_goal) + if (_pGoals[i]->is_goal) { if (include_pen){mult=_pGoals[i]->penalty_over*_pGoals[i]->units_correction;} if (_pGoals[i]->pOperRegimes[0]->pExpression->compare != COMPARE_LESSTHAN){mult*=-1.0; } pen = mult*_aSlackValues[s]; s++; - if (_pGoals[i]->pOperRegimes[0]->pExpression->compare == COMPARE_IS_EQUAL) + if (_pGoals[i]->pOperRegimes[0]->pExpression->compare == COMPARE_IS_EQUAL) { mult=1.0; if (include_pen){mult=_pGoals[i]->penalty_under*_pGoals[i]->units_correction;} @@ -2344,7 +2344,7 @@ void CDemandOptimizer::WriteMinorOutput(const optStruct &Options,const time_stru // OptimizationResidual.csv //-------------------------------------------------------- - if (_do_debug_level > 0) + if (_do_debug_level > 0) { //Header must be written during simulation because row names don't exist until lp solver build if (fabs(tt.model_time - Options.timestep)InitializePostRVM(Options); diff --git a/src/ParseLib.cpp b/src/ParseLib.cpp index 65b8827a..99de21c5 100644 --- a/src/ParseLib.cpp +++ b/src/ParseLib.cpp @@ -138,7 +138,7 @@ bool CParser::Tokenize(char **out, int &numwords){ if (_parsing_math_exp) { string line; - line=AddSpacesBeforeOps(wholeline); + line=AddSpacesBeforeOps(wholeline); strcpy(wholeline,line.c_str()); _parsing_math_exp=false; } diff --git a/src/ParseManagementFile.cpp b/src/ParseManagementFile.cpp index 2decec01..07bce962 100644 --- a/src/ParseManagementFile.cpp +++ b/src/ParseManagementFile.cpp @@ -56,7 +56,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) CDemand *pDemand=NULL; int demand_ind=0; - long demandSBID; + long demandSBID; int demand_ID; string demand_name; @@ -190,7 +190,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) for(i=1;iis_goal) { @@ -607,17 +607,17 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) } } //---------------------------------------------- - else if (!strcmp(s[0], ":Priority")) + else if (!strcmp(s[0], ":Priority")) { if (Options.noisy){cout<<" Priority "<priority = s_to_i(s[1]); //for later } //---------------------------------------------- - else if (!strcmp(s[0], ":UseStageUnitsCorrection")) + else if (!strcmp(s[0], ":UseStageUnitsCorrection")) { if (Options.noisy){cout<<" Use Stage Units Correction "<GetSubBasinByID(s_to_l(s[1])); - + ExitGracefullyIf(pSB->GetGlobalIndex()==DOESNT_EXIST,"ParseManagementFile: subbasin ID in :UseStageUnitsCorrection is invalid",BAD_DATA_WARN); if (pSB->GetReservoir()==NULL){ @@ -640,7 +640,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) else if (!strcmp(s[0], ":OverrideStageDischargeCurve")) { if (Options.noisy){cout<<"Override Stage Discharge Curve"<GetSubBasinByID(s_to_l(s[1])); - + ExitGracefullyIf(pSB->GetGlobalIndex()==DOESNT_EXIST,"ParseManagementFile: subbasin ID in :OverrideStageDischargeCurve is invalid",BAD_DATA_WARN); if (pSB->GetReservoir()==NULL){ @@ -677,7 +677,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) if (!badgoal) { pDO->AddGoalOrConstraint(pGoal); } - + break; } case(24): //---------------------------------------------- @@ -760,7 +760,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) loopStartLine=pp->GetLineNumber(); if (!strcmp(s[1],"SB_GROUP" )) - { + { pLoopSBGroup=pModel->GetSubBasinGroup(s[2]); if (pLoopSBGroup == NULL) { ExitGracefully("ParseManagementFile: bad subbasin group name in :LoopThrough command",BAD_DATA_WARN); @@ -769,7 +769,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) loopCount=0; aLoopVector[0]=new string [pLoopSBGroup->GetNumSubbasins()]; aLoopVector[1]=new string [pLoopSBGroup->GetNumSubbasins()]; - for (int p = 0; p < pLoopSBGroup->GetNumSubbasins(); p++) + for (int p = 0; p < pLoopSBGroup->GetNumSubbasins(); p++) { long SBID = pLoopSBGroup->GetSubBasin(p)->GetID(); string SBName = pLoopSBGroup->GetSubBasin(p)->GetName(); @@ -787,15 +787,15 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) pLoopDemandGroup=pDO->GetDemandGroupFromName(s[2]); if (pLoopDemandGroup == NULL) { ExitGracefully("ParseManagementFile: bad demand group name in :LoopThrough command",BAD_DATA_WARN); - } + } else { loopCount=0; aLoopVector[0]=new string [pLoopDemandGroup->GetNumDemands()]; aLoopVector[1]=new string [pLoopDemandGroup->GetNumDemands()]; - for (int p = 0; p < pLoopDemandGroup->GetNumDemands(); p++) + for (int p = 0; p < pLoopDemandGroup->GetNumDemands(); p++) { long ID = pLoopDemandGroup->GetDemand(loopCount)->GetID(); - string DName = pLoopDemandGroup->GetDemand(loopCount)->GetName(); + string DName = pLoopDemandGroup->GetDemand(loopCount)->GetName(); aLoopVector[0][p]=to_string(ID); aLoopVector[1][p]=DName; } @@ -805,7 +805,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) nWildcards=2; } } - else if (!strcmp(s[1], "LIST")) + else if (!strcmp(s[1], "LIST")) { loopListSize=s_to_i(s[2]); loopCount=0; @@ -818,18 +818,18 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) } case(41): //---------------------------------------------- { /*:EndLoopThrough */ - if(Options.noisy) { cout <<"End Loop"<GetNumSubbasins()))//iterating subbasin loop + if ((pLoopSBGroup!=NULL) && (loopCount == pLoopSBGroup->GetNumSubbasins()))//iterating subbasin loop { pLoopSBGroup=NULL; loopDone=true; } else if ((pLoopDemandGroup != NULL) && (loopCount == pLoopDemandGroup->GetNumDemands())) - { + { pLoopDemandGroup=NULL; loopDone=true; } @@ -848,14 +848,14 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) loopListSize =0; pLoopSBGroup =NULL; pLoopDemandGroup=NULL; - } - else //not finished yet - update all wildcards and jump back to start of loop + } + else //not finished yet - update all wildcards and jump back to start of loop { for (int j = 0; j < nWildcards; j++) { aWildcards[j][1]=aLoopVector[j][loopCount]; } - // jump back to start of loop + // jump back to start of loop pp->SetPosition(loopStartPos); pp->SetLineCounter(loopStartLine); } @@ -890,7 +890,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) } case (50): //-------------------------------------------- { /* - :WaterDemand [SBID] [ID] [Name] + :WaterDemand [SBID] [ID] [Name] ... :EndWaterDemand */ @@ -899,7 +899,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) ExitGracefully("Incorrect number of terms in :WaterDemand command header.",BAD_DATA_WARN); } else{ - demandSBID =s_to_l(s[1]); + demandSBID =s_to_l(s[1]); demand_ID =s_to_i(s[2]); demand_name=s[3]; CSubBasin *pSB=pModel->GetSubBasinByID(demandSBID); @@ -981,7 +981,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) } else { pDemand->SetIrrigationGroup(pGrp->GetGlobalIndex()); - } + } } break; } @@ -1076,7 +1076,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) string warn ="Invalid expression in :DemandExpression command at line " + pp->GetLineNumber(); WriteWarning(warn.c_str(),Options.noisy); } - + } break; } @@ -1168,4 +1168,4 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) pp=NULL; return true; -} \ No newline at end of file +} diff --git a/src/ParseTimeSeriesFile.cpp b/src/ParseTimeSeriesFile.cpp index e564a656..c51b1356 100644 --- a/src/ParseTimeSeriesFile.cpp +++ b/src/ParseTimeSeriesFile.cpp @@ -632,7 +632,7 @@ bool ParseTimeSeriesFile(CModel *&pModel, const optStruct &Options) if ((pSB!=NULL) && (pSB->GetReservoir()!=NULL)) { has_irrig=true; - + pTimeSer=CTimeSeries::Parse(p,true,demand_name,SBID,"none",Options); pTimeSer->SetIDTag(demand_ID); diff --git a/src/Raven.vcxproj b/src/Raven.vcxproj index 2911aa1c..47a0d57e 100644 --- a/src/Raven.vcxproj +++ b/src/Raven.vcxproj @@ -1040,4 +1040,4 @@ - \ No newline at end of file + diff --git a/src/Raven.vcxproj.filters b/src/Raven.vcxproj.filters index a224e635..234411ea 100644 --- a/src/Raven.vcxproj.filters +++ b/src/Raven.vcxproj.filters @@ -718,4 +718,4 @@ Resource Files - \ No newline at end of file + diff --git a/src/Reservoir.cpp b/src/Reservoir.cpp index e33ca816..34c336b8 100644 --- a/src/Reservoir.cpp +++ b/src/Reservoir.cpp @@ -278,7 +278,7 @@ CReservoir::CReservoir(const string Name, const long SubID, _aQunder[i]=0.0;if(a_Qund!=NULL){ _aQunder[i]=a_Qund[i]; } _aArea [i]=a_A[i]; _aVolume[i]=a_V[i]; - if (_aQ[i]==0){_crest_ht=_aStage[i]; } + if (_aQ[i]==0){_crest_ht=_aStage[i]; } for (int v = 0; v < _nDates; v++){ _aQ_back[v][i] = a_QQ[v][i]; if ((i > 0) && ((_aQ_back[v][i] - _aQ_back[v][i-1]) < -REAL_SMALL)){ @@ -435,9 +435,9 @@ double CReservoir::GetMaxStage (const int nn) const { } ////////////////////////////////////////////////////////////////// /// \returns sill elevation [m] -/// supports time-variable discharge curves and weir height adjustments +/// supports time-variable discharge curves and weir height adjustments // -double CReservoir::GetSillElevation(const int nn) const +double CReservoir::GetSillElevation(const int nn) const { double weir_adj=0.0; if (_pWeirHeightTS!=NULL){ @@ -641,12 +641,12 @@ int CReservoir::GetNumWaterDemands() const { /// \brief returns water/irrigation demand object /// \return water/irrigation demand object // -CDemand* CReservoir::GetWaterDemandObj(const int ii) const +CDemand* CReservoir::GetWaterDemandObj(const int ii) const { #ifdef _STRICTCHECK_ ExitGracefullyIf(ii < 0 || ii >= _nWaterDemands, "CReservoir::GetWaterDemandObj: invalid index",RUNTIME_ERR); #endif - return _pWaterDemands[ii]; + return _pWaterDemands[ii]; } ////////////////////////////////////////////////////////////////// /// \brief Returns specified irrigation/water use demand from reservoir at time t @@ -754,7 +754,7 @@ void CReservoir::Initialize(const optStruct &Options) /// \brief Initializes SB demand members AFTER RVM FILE READ /// \param &Options [in] Global model options information // -void CReservoir::InitializePostRVM(const optStruct& Options) +void CReservoir::InitializePostRVM(const optStruct& Options) { _aQdelivered = new double [_nWaterDemands]; _aQreturned = new double [_nWaterDemands]; @@ -1024,21 +1024,21 @@ void CReservoir::SetVolumeStageCurve(const double *a_ht,const double *a_V,const } _min_stage =a_ht[0]; - _max_stage =a_ht[nPoints-1]; + _max_stage =a_ht[nPoints-1]; //_Np=102; //SAME AS LAKE TYPE CONSTRUCTOR, BY NECESSITY! //cout<<_name<<" CREST HEIGHT : "<<_crest_ht<UpdateDemand(Options,tt); @@ -1278,7 +1278,7 @@ void CReservoir::AddToDeliveredDemand(const int ii, const double &Qdel) { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CReservoir::AddToDeliveredDemand: invalid demand index",RUNTIME_ERR); -#endif +#endif _aQdelivered[ii]=Qdel; } ////////////////////////////////////////////////////////////////// @@ -1290,7 +1290,7 @@ void CReservoir::RecordReturnFlow(const int ii, const double &Qret) { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CReservoir::RecordReturnFlow: invalid demand index",RUNTIME_ERR); -#endif +#endif _aQreturned[ii]=Qret; } ////////////////////////////////////////////////////////////////// diff --git a/src/Reservoir.h b/src/Reservoir.h index 8bb6a909..f3d9c367 100644 --- a/src/Reservoir.h +++ b/src/Reservoir.h @@ -114,7 +114,7 @@ class CReservoir double *_aQstruct; ///< array of flows from control structures at end of time step [m3/s] double *_aQstruct_last; ///< array of flows from control structures at start of time step [m3/s] double *_aQdelivered; ///< amount of water demand delivered for each demand [m3/s] (for management optimization) - double *_aQreturned; ///< amount of water returned for each demand [m3/s] + double *_aQreturned; ///< amount of water returned for each demand [m3/s] res_constraint _constraint; ///< current constraint type @@ -270,7 +270,7 @@ class CReservoir //Called during initialization: void Initialize (const optStruct &Options); - void InitializePostRVM (const optStruct &Options); + void InitializePostRVM (const optStruct &Options); //Called during simulation: diff --git a/src/Solvers.cpp b/src/Solvers.cpp index c791c8d7..05b54f07 100644 --- a/src/Solvers.cpp +++ b/src/Solvers.cpp @@ -558,19 +558,19 @@ void MassEnergyBalance( CModel *pModel, { pBasin->UpdateInflow(aQinnew[p]); // from upstream, diversions, and specified flows - pBasin->UpdateLateralInflow(aRouted[p]/(tstep*SEC_PER_DAY));//[m3/d]->[m3/s] + pBasin->UpdateLateralInflow(aRouted[p]/(tstep*SEC_PER_DAY));//[m3/d]->[m3/s] pBasin->RouteWater (aQoutnew,Options,tt); irr_Q=pBasin->ApplyIrrigationDemand(t+tstep,aQoutnew[pBasin->GetNumSegments()-1],Options.management_optimization); - div_Q_total=0; + div_Q_total=0; for(int i=0; iGetNumDiversions();i++) { //upstream of reservoir! div_Q=pBasin->GetDiversionFlow(i,pBasin->GetChannelOutflowRate(),Options,tt,pDivert); //diversions based upon flows at start of timestep (without diversions) div_Q_total+=div_Q; } - down_Q=pBasin->GetDownstreamInflow(t)+pBasin->GetTotalReturnFlow(); + down_Q=pBasin->GetDownstreamInflow(t)+pBasin->GetTotalReturnFlow(); aQoutnew[pBasin->GetNumSegments()-1]+=down_Q; //add return flows and Basin inflow hydrographs (type2) diff --git a/src/StandardOutput.cpp b/src/StandardOutput.cpp index 31879229..ff91a2c0 100644 --- a/src/StandardOutput.cpp +++ b/src/StandardOutput.cpp @@ -1032,7 +1032,7 @@ void CModel::WriteMinorOutput(const optStruct &Options,const time_struct &tt) for (int ii=0;iiGetReservoir()->GetNumWaterDemands(); ii++){ demsum =pSB->GetReservoir()->GetWaterDemand(ii); delsum =pSB->GetReservoir()->GetDemandDelivery(ii); - retsum =pSB->GetReservoir()->GetReturnFlow(ii); + retsum =pSB->GetReservoir()->GetReturnFlow(ii); } } _DEMANDS<<","<GetReservoir()->GetNumWaterDemands(); ii++){ irr =pSB->GetReservoir()->GetWaterDemand(ii); Qd =pSB->GetReservoir()->GetDemandDelivery(ii); - Qr =pSB->GetReservoir()->GetReturnFlow(ii); + Qr =pSB->GetReservoir()->GetReturnFlow(ii); //double unmet=max(irr-Qd,0.0); _DEMANDS<<","<GetReservoir()->GetWaterDemandObj(ii)->HasReturnFlow()){ diff --git a/src/SubBasin.cpp b/src/SubBasin.cpp index b5dec115..c057c4c1 100644 --- a/src/SubBasin.cpp +++ b/src/SubBasin.cpp @@ -488,7 +488,7 @@ double CSubBasin::GetTotalWaterDemand() const ////////////////////////////////////////////////////////////////// /// \brief Returns specified irrigation/water use demand from subbasin /// \param &t [in] Model time at which the demand from SB is to be determined -/// \return specified demand from subbasin at current time +/// \return specified demand from subbasin at current time // double CSubBasin::GetWaterDemand(const int ii) const { @@ -527,7 +527,7 @@ double CSubBasin::GetDemandDelivery(const int ii) const { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CSubBasin::GetDemandDelivery: invalid demand index",RUNTIME_ERR); -#endif +#endif return _aQdelivered[ii]; } ////////////////////////////////////////////////////////////////// @@ -538,7 +538,7 @@ double CSubBasin::GetReturnFlow(const int ii) const { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CSubBasin::GetDemandDelivery: invalid demand index",RUNTIME_ERR); -#endif +#endif return _aQreturned[ii]; } ////////////////////////////////////////////////////////////////// @@ -814,7 +814,7 @@ CDemand *CSubBasin::GetWaterDemandObj (const int ii) const #ifdef _STRICTCHECK_ ExitGracefullyIf(ii < 0 || ii >= _nWaterDemands, "CSubBasin::GetWaterDemandObj: invalid index",RUNTIME_ERR); #endif - return _pWaterDemands[ii]; + return _pWaterDemands[ii]; } ////////////////////////////////////////////////////////////////// @@ -1224,8 +1224,8 @@ void CSubBasin::AddDownstreamInflow (CTimeSeries *pInflow) _pInflowHydro2=pInflow; } ////////////////////////////////////////////////////////////////// -/// \brief Adds water demand -/// \param *pDemand pointer to demand object to be added +/// \brief Adds water demand +/// \param *pDemand pointer to demand object to be added // void CSubBasin::AddWaterDemand(CDemand *pDemand) { @@ -1435,7 +1435,7 @@ void CSubBasin::AddToDeliveredDemand(const int ii, const double &Qdel) { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CSubBasin::AddToDeliveredDemand: invalid demand index",RUNTIME_ERR); -#endif +#endif _aQdelivered[ii]=Qdel; _Qdelivered+=Qdel; } @@ -1444,13 +1444,13 @@ void CSubBasin::AddToDeliveredDemand(const int ii, const double &Qdel) /// \param &Options [in] Global model options information /// \param &tt [in] time structure at start of current time step // -void CSubBasin::UpdateDemands(const optStruct& Options, const time_struct& tt) +void CSubBasin::UpdateDemands(const optStruct& Options, const time_struct& tt) { for (int ii = 0; ii < _nWaterDemands; ii++) { _pWaterDemands[ii]->UpdateDemand(Options,tt); } if (_pReservoir != NULL) { - _pReservoir->UpdateDemands(Options,tt); + _pReservoir->UpdateDemands(Options,tt); } } @@ -1464,11 +1464,11 @@ void CSubBasin::AddToReturnFlow(const double &Qret) { _Qreturn+=Qret; } -void CSubBasin::RecordReturnFlow(const int ii, const double& Qret) +void CSubBasin::RecordReturnFlow(const int ii, const double& Qret) { #ifdef _STRICTCHECK_ ExitGracefullyIf((ii<0) || (ii>=_nWaterDemands),"CSubBasin::RecordReturnFlow: invalid demand index",RUNTIME_ERR); -#endif +#endif _aQreturned[ii]=Qret; } ///////////////////////////////////////////////////////////////// @@ -1657,9 +1657,9 @@ void CSubBasin::Initialize(const double &Qin_avg, //[m3/s] from upst if(_pEnviroMinFlow != NULL) { _pEnviroMinFlow->Initialize(Options.julian_start_day,Options.julian_start_year,Options.duration,Options.timestep,false,Options.calendar); } - //must be initialized AFTER RVM FILE READ + //must be initialized AFTER RVM FILE READ + - //QA/QC check of Muskingum parameters, if necessary //------------------------------------------------------------------------ @@ -1691,7 +1691,7 @@ void CSubBasin::Initialize(const double &Qin_avg, //[m3/s] from upst /// \brief Initializes SB demand members AFTER RVM FILE READ /// \param &Options [in] Global model options information // -void CSubBasin::InitializePostRVM(const optStruct &Options) +void CSubBasin::InitializePostRVM(const optStruct &Options) { if (_nWaterDemands>0){ _aQdelivered=new double [_nWaterDemands]; diff --git a/src/SubBasin.h b/src/SubBasin.h index 89af1f83..36698f33 100644 --- a/src/SubBasin.h +++ b/src/SubBasin.h @@ -141,7 +141,7 @@ class CSubBasin CTimeSeries *_pInflowHydro2; ///< pointer to time series of inflows/extractions ; at downstream end of basin reach CTimeSeries *_pEnviroMinFlow; ///< pointer to time series of environmental minimum flow targets that force reduced irrigation demand (=0 by default) - int _nWaterDemands; ///< number of water demand objects + int _nWaterDemands; ///< number of water demand objects CDemand **_pWaterDemands; ///< pointer to array of demand objects; demand applied at downstream end of basin reach [size: _nIrrigDemand] int _nDiversions; ///< number of flow diversions from basin @@ -259,7 +259,7 @@ class CSubBasin int GetDiversionTargetIndex (const int i) const; // returns subbasin index p of diversion i CReservoir *GetReservoir () const; - CDemand *GetWaterDemandObj (const int ii) const; //returns pointer to ith water demand + CDemand *GetWaterDemandObj (const int ii) const; //returns pointer to ith water demand double GetBasinProperties (const string label) const; @@ -275,7 +275,7 @@ class CSubBasin const double &Qlat_avg, //[m3/s] const double &total_drain_area, //[km2] const optStruct &Options); - void InitializePostRVM (const optStruct &Options); + void InitializePostRVM (const optStruct &Options); void InitializeFlowStates (const double& Qin_avg,const double& Qlat_avg,const optStruct &Options); void AddInflowHydrograph (CTimeSeries *pInflow); void AddDownstreamInflow (CTimeSeries *pInflow); @@ -307,7 +307,7 @@ class CSubBasin void UpdateDemands (const optStruct &Options,const time_struct &tt); void AddToDeliveredDemand (const int ii, const double &Qdel); void RecordReturnFlow (const int ii, const double& Qret); - void AddToReturnFlow (const double &Qret); + void AddToReturnFlow (const double &Qret); void UpdateInflow (const double &Qin );//[m3/s] void UpdateLateralInflow (const double &Qlat);//[m3/s] void UpdateSubBasin (const time_struct &tt, const optStruct &Options); diff --git a/src/UpdateForcings.cpp b/src/UpdateForcings.cpp index 83113bec..99eac885 100644 --- a/src/UpdateForcings.cpp +++ b/src/UpdateForcings.cpp @@ -598,13 +598,13 @@ void CModel::UpdateHRUForcingFunctions(const optStruct &Options, //------------------------------------------------------------------- // Irrigation //------------------------------------------------------------------- - F.irrigation=0.0; //FOR NOW + F.irrigation=0.0; //FOR NOW //F.irrigation=GetDemandOptimizer()->EstimateIrrigation(F,_pHydroUnits[k],Options,tt); //------------------------------------------------------------------- - // Direct evaporation of rainfall / irrigation + // Direct evaporation of rainfall / irrigation //------------------------------------------------------------------- - if(Options.direct_evap) + if(Options.direct_evap) { double rainfall=F.precip*(1.0-F.snow_frac); double reduce =min(F.PET,rainfall+F.irrigation); diff --git a/src/WaterDemands.cpp b/src/WaterDemands.cpp index a8928bb3..ad6824d3 100644 --- a/src/WaterDemands.cpp +++ b/src/WaterDemands.cpp @@ -8,7 +8,7 @@ /// \brief Implementation of the water demand constructor /// \details Creates empty instance of the water demand class // -CDemand::CDemand(int ID, string name, long SBID, bool is_res) +CDemand::CDemand(int ID, string name, long SBID, bool is_res) { _ID=ID; _name=name; @@ -22,10 +22,10 @@ CDemand::CDemand(int ID, string name, long SBID, bool is_res) _global_index=DOESNT_EXIST; _unrestricted=0; _cumDelivDate=0; //Jan-1 - + _penalty=1.0; _multiplier=1.0; - _demandFract=0.0;//default + _demandFract=0.0;//default _pDemandTS=NULL; _pReturnTS=NULL; @@ -33,31 +33,31 @@ CDemand::CDemand(int ID, string name, long SBID, bool is_res) _pReturnExp=NULL; _targetSBID=_SBID; //default return is to same location _irrigHRUGroup=DOESNT_EXIST; - _returnPct=0.0; //default is no return + _returnPct=0.0; //default is no return _currentDemand=0; _currentRetTarget=0; } -CDemand::CDemand(int ID, string name, long SBID, bool is_res, CTimeSeries* pTS):CDemand(ID,name,SBID,is_res) +CDemand::CDemand(int ID, string name, long SBID, bool is_res, CTimeSeries* pTS):CDemand(ID,name,SBID,is_res) { _pDemandTS=pTS; _demType=DEMAND_TIME_SERIES; } -CDemand::~CDemand() +CDemand::~CDemand() { delete _pDemandTS; - delete _pReturnTS; + delete _pReturnTS; delete _pDemandExp; delete _pReturnExp; } ////////////////////////////////////////////////////////////////// /// \brief Water demand accessors // -int CDemand::GetID() const +int CDemand::GetID() const { return _ID; } -string CDemand::GetName() const +string CDemand::GetName() const { return _name; } @@ -71,7 +71,7 @@ int CDemand::GetLocalIndex() const ExitGracefullyIf(_loc_index==DOESNT_EXIST,"CDemand::GetLocalIndex(): didnt set local index",RUNTIME_ERR); return _loc_index; } -long CDemand::GetSubBasinID() const +long CDemand::GetSubBasinID() const { return _SBID; } @@ -79,11 +79,11 @@ double CDemand::GetPenalty() const { return _penalty; } -bool CDemand::IsUnrestricted() const +bool CDemand::IsUnrestricted() const { return _unrestricted; } -int CDemand::GetCumulDeliveryDate() const +int CDemand::GetCumulDeliveryDate() const { return _cumDelivDate; } @@ -91,20 +91,20 @@ bool CDemand::IsReservoirDemand() const { return _is_reservoir; } -double CDemand::GetDemand() const +double CDemand::GetDemand() const { return _currentDemand; } -double CDemand::GetReturnFlowTarget() const +double CDemand::GetReturnFlowTarget() const { return _currentRetTarget; -} -double CDemand::GetReturnFlowFraction() const +} +double CDemand::GetReturnFlowFraction() const { return _returnPct; } -// returns true if this demand has a return flow -bool CDemand::HasReturnFlow() const +// returns true if this demand has a return flow +bool CDemand::HasReturnFlow() const { return (_returnPct*_multiplier>0.0); } @@ -114,23 +114,23 @@ long CDemand::GetTargetSBID() const { ////////////////////////////////////////////////////////////////// /// \brief Water demand manipulators // -void CDemand::SetLocalIndex(const int ii) +void CDemand::SetLocalIndex(const int ii) { _loc_index=ii; } -void CDemand::SetGlobalIndex(const int d) +void CDemand::SetGlobalIndex(const int d) { _global_index=d; } -void CDemand::SetDemandPenalty(const double& P) +void CDemand::SetDemandPenalty(const double& P) { _penalty=P; } -void CDemand::SetCumulDeliveryDate(const int date) +void CDemand::SetCumulDeliveryDate(const int date) { _cumDelivDate=date; } -void CDemand::SetAsUnrestricted() +void CDemand::SetAsUnrestricted() { _unrestricted=true; } @@ -149,24 +149,24 @@ void CDemand::SetReturnTimeSeries(CTimeSeries* pTS) { _retType=RETURN_TIME_SERIES; _pReturnTS=pTS; } -void CDemand::SetReturnFraction(const double &val) +void CDemand::SetReturnFraction(const double &val) { ExitGracefullyIf((val>1.0) || (val<0.0),"CDemand::SetReturnFraction: demand must be set between 0 and 1",BAD_DATA_WARN); _returnPct=val; } -void CDemand::SetDemandFraction(const double &val) +void CDemand::SetDemandFraction(const double &val) { ExitGracefullyIf((val>1.0) || (val<0.0),"CDemand::SetDemandFraction: demand must be set between 0 and 1",BAD_DATA_WARN); _demType=DEMAND_PCT; _demandFract=val; } -void CDemand::SetDemandExpression(expressionStruct* pExp) +void CDemand::SetDemandExpression(expressionStruct* pExp) { //TODO: check for valid LHS ? _demType=DEMAND_EXPRESSION; _pDemandExp=pExp; } -void CDemand::SetReturnExpression(expressionStruct* pExp) +void CDemand::SetReturnExpression(expressionStruct* pExp) { //TODO: check for valid LHS ? _retType=RETURN_EXPRESSION; @@ -185,7 +185,7 @@ void CDemand::SetIrrigationGroup(const int kk) /// \brief initialized demand and return time series prior to simulation /// \param &Options [in] Global model options information // -void CDemand::Initialize(const optStruct &Options) +void CDemand::Initialize(const optStruct &Options) { if (_pDemandTS != NULL) { _pDemandTS->Initialize(Options.julian_start_day,Options.julian_start_year,Options.duration,Options.timestep,false,Options.calendar); @@ -199,29 +199,29 @@ void CDemand::Initialize(const optStruct &Options) /// \param &Options [in] Global model options information /// \param &tt [in] Current model time structure // -void CDemand::UpdateDemand(const optStruct &Options,const time_struct& tt) +void CDemand::UpdateDemand(const optStruct &Options,const time_struct& tt) { - // Calculate Delivery Targets + // Calculate Delivery Targets //------------------------------------------------------------------- if (_demType==DEMAND_TIME_SERIES) { //int nn=tt.nn; int nn=(int)((tt.model_time+TIME_CORRECTION)/Options.timestep);//current timestep index - + double Qirr=_pDemandTS->GetSampledValue(nn); if (Qirr==RAV_BLANK_DATA){Qirr=0.0;} _currentDemand=_multiplier*Qirr; //cout<<"UPDATE DEMAND : "<<_currentDemand<<" "<<_multiplier<<" "<GetSubBasin(p)->GetInflow(); // outflow from last time step + //pct of inflow from end of previous time step + //double Q=pModel->GetSubBasin(p)->GetInflow(); // outflow from last time step //_currentDemand=demPct * Q; ExitGracefully("UpdateDEmand::DEMAND_PCT",STUB); } - else if (_demType == DEMAND_EXPRESSION) + else if (_demType == DEMAND_EXPRESSION) { //double val=pModel->GetDO->EvaluateExpression(pExp,tt.model_time); //if (fabs(val-RAV_BLANK_DATA)GetSampledValue(nn); if (Qret==RAV_BLANK_DATA){Qret=0.0;} @@ -251,11 +251,10 @@ void CDemand::UpdateDemand(const optStruct &Options,const time_struct& tt) else if (_retType == RETURN_MAX) { _currentRetTarget = 1e8; } - else if (_retType == RETURN_EXPRESSION) + else if (_retType == RETURN_EXPRESSION) { - + } _currentRetTarget=min(_currentRetTarget,_currentDemand); //this is likely unnecessary } } -