Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ repos:
# - id: include-what-you-use

- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.30.0
rev: 0.32.1
hooks:
- id: check-github-workflows
- repo: meta
Expand Down
14 changes: 7 additions & 7 deletions src/Assimilate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void CModel::InitializeDataAssimilation(const optStruct &Options)

}
/////////////////////////////////////////////////////////////////
/// \brief Overrides flows with observations at gauges and propagates adjustments upstream of gauges
/// \brief Overrides flows with observations at gauges and propagates adjustments upstream of gauges
/// \param p [in] global subbasin index
/// \param Options [in] current model options structure
/// \param tt [in] current model time structure
Expand Down Expand Up @@ -118,7 +118,7 @@ void CModel::AssimilationOverride(const int p,const optStruct& Options,const tim
mass_added=_pSubBasins[p]->AdjustAllFlows(_aDAQadjust[p],_aDAoverride[p],Options.timestep,tt.model_time);
}

//
//
if(mass_added>0.0){_CumulInput +=mass_added/(_WatershedArea*M2_PER_KM2)*MM_PER_METER;}
else {_CumulOutput-=mass_added/(_WatershedArea*M2_PER_KM2)*MM_PER_METER;}

Expand Down Expand Up @@ -179,7 +179,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAoverride [p]=true;
_aDAobsQ [p]=Qobs;
_aDADrainSum [p]=0.0; //??? maybe doesnt matter
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum [pdown]+=_pSubBasins[p]->GetDrainageArea(); //DOES THIS HANDLE NESTING RIGHT?
}
}
Expand All @@ -191,17 +191,17 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAlength [p]=0.0;
_aDAoverride [p]=false;
_aDAobsQ [p]=0.0;
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum[pdown] += _aDADrainSum[p];
}
}
ObsExists=true;
break; //avoids duplicate observations
}
}
}
}
else {
if (pdown != DOESNT_EXIST) {
if (pdown != DOESNT_EXIST) {
_aDADrainSum[pdown] += _aDADrainSum[p];
}
}
Expand Down Expand Up @@ -264,4 +264,4 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAQadjust[p] = _aDAQadjust[p]*ECCCwt;
}
}
}
}
2 changes: 1 addition & 1 deletion src/CustomOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,4 +1213,4 @@ CCustomOutput *CCustomOutput::ParseCustomOutputCommand(char *s[MAXINPUTITEMS], c
}

return pCustom;
}
}
20 changes: 10 additions & 10 deletions src/DemandExpressionHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ int CDemandOptimizer::GetUserDVIndex(const string s) const
//////////////////////////////////////////////////////////////////
/// \brief index of non-linear variable given guess string
/// \params s [in] - string (in format ?Q130, ?Q.RavenRiver, ?UserDV)
/// \returns index of non-linear variable in _aNonLinNames[] array
/// \returns index of non-linear variable in _aNonLinNames[] array
//
int CDemandOptimizer::GetNLIndexFromGuessString(const string& s) const
int CDemandOptimizer::GetNLIndexFromGuessString(const string& s) const
{
for (int i = 0; i < _nNonLinVars; i++) {
if (_pNonLinVars[i]->name==s){return i;}
Expand Down Expand Up @@ -1028,13 +1028,13 @@ expressionStruct *CDemandOptimizer::ParseExpression(const char **s,
return tmp;
}
//////////////////////////////////////////////////////////////////
/// \brief Parses :Condition within management goal or workflow variable definition
/// \brief Parses :Condition within management goal or workflow variable definition
/// \param s [in] - array of strings of [size: Len]
/// \param Len [in] - length of string array
/// \param lineno [in] - line number of original expression in input file filename, referenced in errors
/// \param filename [in] - name of input file, referenced in errors
/// \returns exp_condition: a pointer to an expression condition variable
///
///
/// \todo[funct]: Would it be better to support @date(), @between, @day_of_year() in general expression??
/// :Condition !Q32[0] < 300 + @ts(myTs,0)
/// :Condition DATE IS_BETWEEN 1975-01-02 2010-01-02
Expand All @@ -1048,13 +1048,13 @@ expressionStruct *CDemandOptimizer::ParseExpression(const char **s,
/// :Condition DAY_OF_YEAR IS_BETWEEN Apr-1 Aug-1 //\todo [NOT YET SUPPORTED]
/// :Condition @is_between(DAY_OF_YEAR,300,20) = 1 // \todo [NOT YET SUPPORTED]
//
exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, const int lineno, const string filename) const
exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, const int lineno, const string filename) const
{
bool badcond=false;
exp_condition *pCond = new exp_condition();
pCond->dv_name=s[1];
const optStruct *Options=_pModel->GetOptStruct();

bool is_exp=false;
for (int i = 2; i < Len; i++) {
if ((s[i][0]=='+') || (s[i][0]=='-') || (s[i][0]=='*') || (s[i][0]=='/') || (s[i][0]=='=') || (s[i][0]=='<') || (s[i][0]=='>')){
Expand Down Expand Up @@ -1091,7 +1091,7 @@ exp_condition* CDemandOptimizer::ParseCondition(const char** s, const int Len, c
char tmp =pCond->dv_name[1];
string tmp2=pCond->dv_name.substr(2);
char code=pCond->dv_name[1];
if ((code=='Q') || (code=='h') || (code=='I')) //subbasin state decision variable
if ((code=='Q') || (code=='h') || (code=='I')) //subbasin state decision variable
{
long long SBID=s_to_ll(tmp2.c_str());
if (_pModel->GetSubBasinByID(SBID) == NULL) {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ bool CDemandOptimizer::CheckOpRegimeConditions(const op_regime *pOperRegime, con
}
else {//handle user specified DVs and workflow variables
int i=GetUserDVIndex(pCond->dv_name);
if (i != DOESNT_EXIST) //decision variable
if (i != DOESNT_EXIST) //decision variable
{
dv_value =_pDecisionVars[i]->value;
}
Expand Down Expand Up @@ -1399,7 +1399,7 @@ void CDemandOptimizer::AddConstraintToLP(const int ii, const int kk, lp_lib::lpr
ExitGracefullyIf(retval==0,"AddConstraintToLP::Error updating user-specified constraint/goal",RUNTIME_ERR);
retval = lp_lib::set_rh(pLinProg,lpgoalrow,RHS);
}

}
#endif

Expand Down Expand Up @@ -1535,7 +1535,7 @@ double CDemandOptimizer::EvaluateTerm(expressionTerm **pTerms,const int k, const
}
else if (pT->type == TERM_ITER)
{
return _pNonLinVars[pT->DV_ind]->guess_val;//treated as if constant
return _pNonLinVars[pT->DV_ind]->guess_val;//treated as if constant
}
else if (pT->type == TERM_WORKFLOW)
{
Expand Down
32 changes: 16 additions & 16 deletions src/DemandOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CDemandOptimizer::CDemandOptimizer(CModel *pMod)

_nNonLinVars=0;
_pNonLinVars=NULL;
_maxIterations=5;
_maxIterations=5;
_iterTolerance=0.01;
_relaxCoeff=1.0;
}
Expand Down Expand Up @@ -230,7 +230,7 @@ void CDemandOptimizer::SetMaxIterations (const int Nmax )

//////////////////////////////////////////////////////////////////
/// \brief sets nonlinear solver tolerance
/// \params tol [in] - tolerance, as ratio dX/X
/// \params tol [in] - tolerance, as ratio dX/X
//
void CDemandOptimizer::SetSolverTolerance (const double tol )
{
Expand Down Expand Up @@ -354,7 +354,7 @@ void CDemandOptimizer::AddUserDecisionVar(const decision_var* pDV)
//////////////////////////////////////////////////////////////////
/// \brief disables stage discharge curve handling for reservoir in subbasin p
//
void CDemandOptimizer::OverrideSDCurve(const int p)
void CDemandOptimizer::OverrideSDCurve(const int p)
{
_aDisableSDCurve[p]=true;
}
Expand Down Expand Up @@ -401,7 +401,7 @@ void CDemandOptimizer::AddUserConstant(const string name, const double& val)
//////////////////////////////////////////////////////////////////
/// \brief adds nonlinearvariable
//
void CDemandOptimizer::AddNonLinVariable(const string name, const string targetDV)
void CDemandOptimizer::AddNonLinVariable(const string name, const string targetDV)
{
if (name[0]!='?'){
ExitGracefully("CDemandOptimizer::AddNonLinVariable: non-linear variable must start with ? character",BAD_DATA_WARN);
Expand Down Expand Up @@ -472,7 +472,7 @@ bool CDemandOptimizer::VariableNameExists(const string &name) const
for (int i = 0; i < _nUserConstants; i++) {
if (_aUserConstNames[i]==name){return true;}
}

if (GetUnitConversion(name)!=RAV_BLANK_DATA){return true;}

return false;
Expand Down Expand Up @@ -878,7 +878,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op
//------------------------------------------------------------------
for (int i = 0; i < _nNonLinVars; i++) {
expressionTerm* term=new expressionTerm();
if (ConvertToExpressionTerm(_pNonLinVars[i]->target, term, 0, "internal")) {
if (ConvertToExpressionTerm(_pNonLinVars[i]->target, term, 0, "internal")) {
_pNonLinVars[i]->DV_index=term->DV_ind-1; //using 0 indexing for dv rateher than lp 1 indexing
//cout<<" NONLINEAR TARGET FOUND : "<<term->DV_ind-1<<" "<<term->origexp<<" "<<expTypeToString(term->type)<<endl;
}
Expand Down Expand Up @@ -959,7 +959,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op
cout<<" "<<i<<" [WORKFLOWVAR]: "<<_pWorkflowVars[i]->name<<endl;
for (int k=0; k<_pWorkflowVars[i]->nOperRegimes; k++)
{

cout<<" +oper regime: "<<_pWorkflowVars[i]->pOperRegimes[k]->reg_name<<endl;
cout<<" +expression: "<<_pWorkflowVars[i]->pOperRegimes[k]->pExpression->origexp<<endl;
comparison ctype=_pWorkflowVars[i]->pOperRegimes[k]->pExpression->compare;
Expand Down Expand Up @@ -1368,12 +1368,12 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O

int *col_ind=new int [_nDecisionVars]; //index of column to insert value in current row (1:nDV, not zero-indexed)
double *row_val=new double [_nDecisionVars]; //values of row[col_ind]
double *dDV =new double [_nDecisionVars]; //change in decision variables between iterations
double *dDV =new double [_nDecisionVars]; //change in decision variables between iterations
double *h_iter =new double [_pModel->GetNumSubBasins()]; //value of stage from previous iteration for all reservoirs
double *Q_iter =new double [_pModel->GetNumSubBasins()]; //value of reservoir outflows from previous iteration for all reservoirs
double *Q_iter =new double [_pModel->GetNumSubBasins()]; //value of reservoir outflows from previous iteration for all reservoirs
int *lprow =new int [_pModel->GetNumSubBasins()]; //index of goal equation for non-linear reservoir stage discharge curve in subbasin p
int *lpsbrow=new int [_pModel->GetNumSubBasins()]; //index of constraint equation for subbasin reaches
int *lpgoalrow=new int [_nGoals]; //index of goal equation for all user-specified goals
int *lpgoalrow=new int [_nGoals]; //index of goal equation for all user-specified goals

// instantiate linear programming solver
// ----------------------------------------------------------------
Expand Down Expand Up @@ -1715,7 +1715,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
retval = lp_lib::add_constraintex(pLinProg,i,row_val,col_ind,ROWTYPE_EQ,RHS);
ExitGracefullyIf(retval==0,"SolveManagementProblem::Error adding mass balance constraint",RUNTIME_ERR);
IncrementAndSetRowName(pLinProg,rowcount,"reach_MB_"+to_string(pSB->GetID()));

lpsbrow[p]=lp_lib::get_Nrows(pLinProg);
}
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
int nInfeasibleIters=0;
int iter=0;
double norm;
do
do
{
if (_do_debug_level==2)//EXTREME OUTPUT!!
{
Expand Down Expand Up @@ -2092,8 +2092,8 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
if (fabs(_aSolverResiduals[j])>REAL_SMALL)
cout<<" -"<<_aSolverRowNames[j] << " " << _aSolverResiduals[j] << endl;
}
//lp_lib::print_debugdump(pLinProg, dumpfile.c_str());

//lp_lib::print_debugdump(pLinProg, dumpfile.c_str());
WriteLPSubMatrix(pLinProg,"overconstrained_lp_matrix.csv",Options);
ExitGracefully("SolveManagementProblem: non-optimal solution found. Problem is over-constrained. Remove or adjust management constraints.",RUNTIME_ERR);
}
Expand All @@ -2120,7 +2120,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
double val;
for (int i=0;i<_nDecisionVars;i++)
{
if ((typ == DV_STAGE) || (typ == DV_QOUT)) {
if ((typ == DV_STAGE) || (typ == DV_QOUT)) {
val=_pDecisionVars[i]->value;
if (val==0){val=1.0;}
norm+=dDV[i]*dDV[i]/val/val; N++;
Expand All @@ -2130,7 +2130,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
int i=_pNonLinVars[j]->DV_index;
val=_pDecisionVars[i]->value;
if (val==0){val=1.0;}
norm+=dDV[i]*dDV[i]/val/val; N++;
norm+=dDV[i]*dDV[i]/val/val; N++;
}
norm=sqrt(norm)/N;

Expand Down
16 changes: 8 additions & 8 deletions src/DemandOptimization.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ struct decision_var
struct nonlin_var
{
string name; //< name of nonlinear variable !Qxxx or !UserVar
string target; //< decision variable name Qxxx or UserVar
double guess_val; //< current guess of value
int DV_index; //index of linear decision variable (0:_nDecisionVars-1) corresponding to nonlinear variable
string target; //< decision variable name Qxxx or UserVar
double guess_val; //< current guess of value
int DV_index; //index of linear decision variable (0:_nDecisionVars-1) corresponding to nonlinear variable

nonlin_var(string nam, string targ) {
name=nam; target=targ; DV_index=DOESNT_EXIST; guess_val=0.0;
Expand Down Expand Up @@ -142,7 +142,7 @@ struct managementGoal
string name; //< goal or constraint name

bool is_goal; //< true if constraint is soft (goal rather than constraint)
bool is_nonlinear; //< current expression has non-linear terms
bool is_nonlinear; //< current expression has non-linear terms
int priority; //< priority (default==1, for goals only)
double penalty_under; //< DEFAULT penalty if under specified value (for goals only)
double penalty_over; //< DEFAULT penalty if over value (for goals only)
Expand Down Expand Up @@ -204,9 +204,9 @@ class CDemandOptimizer
int _nWorkflowVars; //< total number of workflow variables considered
workflowVar **_pWorkflowVars; //< array of pointers to workflow variables [size: _nWorkflowVars]

int _nNonLinVars; //> total number of non-linear variables (e.g., ?Q130)
nonlin_var **_pNonLinVars; //> array of pointers to non-linear variable pairs
int _maxIterations; //> maximum iterations in iterative scheme (default:5)
int _nNonLinVars; //> total number of non-linear variables (e.g., ?Q130)
nonlin_var **_pNonLinVars; //> array of pointers to non-linear variable pairs
int _maxIterations; //> maximum iterations in iterative scheme (default:5)
double _iterTolerance; //> iterative solve tolerance (%)
double _relaxCoeff; //> iterative solve relaxation coefficient (default:1.0=no relaxation)

Expand Down Expand Up @@ -323,7 +323,7 @@ class CDemandOptimizer
void SetRelaxationCoeff (const double relax);

void AddGoalOrConstraint (const managementGoal *pGoal);

void AddUserDecisionVar (const decision_var *pDV);
void SetUserDecisionVarBounds(const string name, const double &min, const double &max);
void AddUserConstant (const string name, const double &val);
Expand Down
2 changes: 1 addition & 1 deletion src/IsotopeTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CIsotopeModel routines related to isotope transport
Raven transports is in terms of mass concentration, mg/L or mg/mm/m2 (as is is for all species)
this is assumed to be equivalent to mass concentrations e.g., mg18O/(mgO); units conversions are IMPLICIT
and is internally converted to composition for advection corrections used to represent enrichment
Raven reports these concentrations as compositions in the standard output
Raven reports these concentrations as compositions in the standard output
----------------------------------------------------------------*/
#include "RavenInclude.h"
#include "IsotopeTransport.h"
Expand Down
2 changes: 1 addition & 1 deletion src/ParseInput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ bool ParseMainInputFile (CModel *&pModel,
Options.assimilate_flow =false;
Options.assimilate_stage =false;
Options.assim_method =DA_RAVEN_DEFAULT;
Options.assimilation_start =-1.0; //start before simulation
Options.assimilation_start =-1.0; //start before simulation
Options.time_zone =0;
Options.rvl_read_frequency =0.0; //do not read at all
Options.custom_interval =1.0; //daily
Expand Down
8 changes: 4 additions & 4 deletions src/ParseManagementFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)

else if(!strcmp(s[0],":UserTimeSeries")) { code=70; }

else if(!strcmp(s[0],":NonlinearVariable")) { code=80; }
else if(!strcmp(s[0],":NonlinearVariable")) { code=80; }
else if(!strcmp(s[0],":MaxNLSolverIterations")) { code=81; }
else if(!strcmp(s[0],":NLSolverTolerance")) { code=82; }
else if(!strcmp(s[0],":NLRelaxationCoeff")) { code=83; }
Expand Down Expand Up @@ -1312,13 +1312,13 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
if(Options.noisy) { cout <<"Non-linear solver tolerance"<<endl; }
pModel->GetManagementOptimizer()->SetSolverTolerance(s_to_d(s[1]));
break;
}
}
case (83): //---------------------------------------------
{/*:NLRelaxationCoeff [#]*/
if(Options.noisy) { cout <<"Non-linear solver relaxation coefficient"<<endl; }
pModel->GetManagementOptimizer()->SetRelaxationCoeff(s_to_d(s[1]));
break;
}
}
default://------------------------------------------------
{
/*cout << "UNREC LINE: (Len=" << Len << ")";
Expand Down Expand Up @@ -1407,4 +1407,4 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options)
pp=NULL;

return true;
}
}
4 changes: 2 additions & 2 deletions src/Reservoir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ double CReservoir::ScaleFlow(const double& scale,const bool overriding, const do

return va;
}
double CReservoir::AdjustFlow(const double& Qadjust, const bool overriding, const double& tstep, const double& t)
double CReservoir::AdjustFlow(const double& Qadjust, const bool overriding, const double& tstep, const double& t)
{
double scale=(_Qout+Qadjust)/_Qout;
if (_Qout=0){scale=1.0;}
Expand All @@ -1202,7 +1202,7 @@ double CReservoir::AdjustFlow(const double& Qadjust, const bool overriding, cons
//Estimate volume added through scaling
va+=0.5*(_Qout_last+_Qout)*sf*tstep*SEC_PER_DAY;

return va;
return va;
}
/////////////////////////////////////////////////////////////////
/// \brief update demand magnitudes, called in solver at start of every time step
Expand Down
4 changes: 2 additions & 2 deletions src/SoilClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,8 @@ void CSoilClass::AutoCalculateSoilProps(const soil_struct &Stmp,
warn="The required parameter FIELD_CAPACITY for soil class "+_tag+" was autogenerated with value "+to_string(_Soil.field_capacity);
if (chatty){WriteAdvisory(warn,false);}
}
if (_Soil.field_capacity == 0) {
WriteWarning("Soil Parameter FIELD_CAPACITY should be greater than zero. This can lead to issues with some model configurations", false);
if (_Soil.field_capacity == 0) {
WriteWarning("Soil Parameter FIELD_CAPACITY should be greater than zero. This can lead to issues with some model configurations", false);
}


Expand Down
Loading