diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ca113f..6bfdcf3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -26,7 +26,7 @@ repos: # - id: include-what-you-use - repo: https://github.com/python-jsonschema/check-jsonschema - rev: 0.29.3 + rev: 0.30.0 hooks: - id: check-github-workflows - repo: meta diff --git a/src/DemandExpressionHandling.cpp b/src/DemandExpressionHandling.cpp index 71d4473..f7095b3 100644 --- a/src/DemandExpressionHandling.cpp +++ b/src/DemandExpressionHandling.cpp @@ -336,7 +336,7 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t //---------------------------------------------------------------------- else if (s[0]=='!') //decision variable e.g., !Q234, !I32, or !D.Matts_Brewery { - if ((s[1] == 'Q') || (s[1] == 'h') || (s[1]=='I')) //Subbasin-indexed + if ((s[1] == 'Q') || (s[1] == 'h') || (s[1]=='I')) //Subbasin-indexed { int p=GetIndexFromDVString(s); if (p == DOESNT_EXIST) { @@ -707,7 +707,7 @@ bool CDemandOptimizer::ConvertToExpressionTerm(const string s, expressionTerm* t //---------------------------------------------------------------------- else if (GetControlVariable(s,index) != RAV_BLANK_DATA) // control variable { - + term->type=TERM_CONTROL; term->value=GetControlVariable(s,index);// initially zero term->DV_ind=index; @@ -760,7 +760,7 @@ expressionStruct *CDemandOptimizer::ParseExpression(const char **s, { strlen=to_string(s[i]).length(); type[i]=EXP; - if ((s[i][0]=='+') || ((strlen==1) && (s[i][0]=='-')) || (s[i][0]=='*') || (s[i][0]=='/') || (s[i][0]=='=') || (s[i][0]=='<') || (s[i][0]=='>')){ + if ((s[i][0]=='+') || ((strlen==1) && (s[i][0]=='-')) || (s[i][0]=='*') || (s[i][0]=='/') || (s[i][0]=='=') || (s[i][0]=='<') || (s[i][0]=='>')){ type[i] = EXP_OP; if ((i > 1) && (type[i - 1] == EXP_OP)) { ExitGracefully("ParseExpression: cannot have consecutive math operators in an expression.",BAD_DATA_WARN); @@ -1277,7 +1277,7 @@ double CDemandOptimizer::EvaluateTerm(expressionTerm **pTerms,const int k, const int p=pT->p_index; return _pModel->GetSubBasin(p)->GetAvgStateVar(i); } - else if (pT->type == TERM_CONST) + else if (pT->type == TERM_CONST) { return pT->value; } diff --git a/src/DemandOptimization.cpp b/src/DemandOptimization.cpp index 23fff3a..103cf76 100644 --- a/src/DemandOptimization.cpp +++ b/src/DemandOptimization.cpp @@ -135,14 +135,14 @@ int CDemandOptimizer::GetDemandIndexFromName(const string demand_tag) const ////////////////////////////////////////////////////////////////// /// \brief gets demand from index // -CDemand* CDemandOptimizer::GetWaterDemand(const int d) +CDemand* CDemandOptimizer::GetWaterDemand(const int d) { return _pDemands[d]; } ////////////////////////////////////////////////////////////////// /// \brief gets number of enabled water demands // -int CDemandOptimizer::GetNumWaterDemands() const +int CDemandOptimizer::GetNumWaterDemands() const { return _nDemands; } @@ -420,7 +420,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; @@ -771,7 +771,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op { // ASSUMES ALL EXPRESSIONS IN GOAL/CONSTRAINT ARE EITHER == or >/<, NEVER MIXED. if (_pGoals[j]->is_goal) { - if (_pGoals[j]->pOperRegimes[0]->pExpression->compare == COMPARE_IS_EQUAL) + if (_pGoals[j]->pOperRegimes[0]->pExpression->compare == COMPARE_IS_EQUAL) { _pGoals[j]->slack_ind1=_nSlackVars; pDV = new decision_var("SL+" + to_string(j), p, DV_SLACK,_nSlackVars); @@ -790,7 +790,7 @@ void CDemandOptimizer::InitializePostRVMRead(CModel* pModel, const optStruct& Op AddDecisionVar(pDV); _nSlackVars++; } - else + else { _pGoals[j]->slack_ind1=_nSlackVars; pDV = new decision_var("SL+"+ to_string(j), p, DV_SLACK,_nSlackVars); @@ -1782,7 +1782,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio retval = lp_lib::add_constraintex(pLinProg,3,row_val,col_ind,ROWTYPE_LE,RHS); ExitGracefullyIf(retval==0,"SolveDemandProblem::Error adding stage discharge constraint F",RUNTIME_ERR); IncrementAndSetRowName(pLinProg,rowcount,"reserv_Q_F"+to_string(pSB->GetID())); - + } else /* if (aDisableSDCurve[p])*/ //keep same rows - make inert equations { @@ -1798,7 +1798,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio IncrementAndSetRowName(pLinProg,rowcount,"reserv_Q_E"+to_string(pSB->GetID())); retval = lp_lib::add_constraintex(pLinProg,1,row_val,col_ind,ROWTYPE_LE,RHS); IncrementAndSetRowName(pLinProg,rowcount,"reserv_Q_F"+to_string(pSB->GetID())); - + s+=2; //to ensure EnvMin counter is working } res_count++; @@ -1887,7 +1887,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio // ---------------------------------------------------------------- // ITERATIVELY SOLVE OPTIMIZATION PROBLEM WITH LP_SOLVE - // ---------------------------------------------------------------- + // ---------------------------------------------------------------- const int NUM_ITERATIONS=5; int ctyp; @@ -1953,7 +1953,7 @@ void CDemandOptimizer::SolveDemandProblem(CModel *pModel, const optStruct &Optio { _aSolverRowNames [j]=to_string(lp_lib::get_row_name(pLinProg,j+1)); _aSolverResiduals[j]=constr[j]-lp_lib::get_rh(pLinProg,j+1); // LHS-RHS for each goal/constraint - + ctyp=lp_lib::get_constr_type(pLinProg,j+1); if (ctyp==LE){upperswap(_aSolverResiduals[j],0.0); } if (ctyp==GE){lowerswap(_aSolverResiduals[j],0.0); _aSolverResiduals[j]*=-1; } @@ -2211,8 +2211,8 @@ void CDemandOptimizer::WriteMinorOutput(const optStruct &Options,const time_stru _GOALSAT<GetSubBasin(p)->GetReferenceXSectArea(); tr=L*A/Q/SEC_PER_DAY; if (tr<0.33*Options.timestep){_aMinResTime [p]=tr;} - else {_aMinResTime [p]=0.333*Options.timestep; } + else {_aMinResTime [p]=0.333*Options.timestep; } } // initialize stream temperatures if init_stream_temp is given @@ -834,7 +834,7 @@ double CEnthalpyModel::GetEnergyLossesFromReach(const int p,double &Q_sens,doubl Q_sens +=dA*hstar *(temp_air-Tbar_km); //[m2]*[MJ/m2/d/K]*[K]=[MJ/d] Q_cond +=dA*kbed *(temp_bed-Tbar_km); Q_lw_out +=dA*klin *(0.75*temp_lin-(Tbar_km+ZERO_CELSIUS)); //linearized - works except at T~0 - Q_lateral+=dA*qlat *dbar/Ax*HCP_WATER*(temp_lat-Tbar_km); + Q_lateral+=dA*qlat *dbar/Ax*HCP_WATER*(temp_lat-Tbar_km); temp_average+=dA/As*Tbar_km; if (As == 0.0) {temp_average=0.0;} diff --git a/src/EnergyTransport.h b/src/EnergyTransport.h index fa5f2c1..c3399c1 100644 --- a/src/EnergyTransport.h +++ b/src/EnergyTransport.h @@ -73,7 +73,7 @@ class CEnthalpyModel :public CConstituentModel //Manipulators (inherited from CConstitModel) void Initialize (const optStruct& Options); - + void PrepareForInCatchmentRouting(const int p); void PrepareForRouting (const int p); double ApplyInCatchmentRouting (const int p, diff --git a/src/FrozenLake.cpp b/src/FrozenLake.cpp index 682bbf7..7422d4c 100644 --- a/src/FrozenLake.cpp +++ b/src/FrozenLake.cpp @@ -66,7 +66,7 @@ void CmvFrozenLake::GetParticipatingParamList(string *aP , class_type *aPC , in } else if (_type == LFREEZE_THERMAL) { - + } else { @@ -105,7 +105,7 @@ void CmvFrozenLake::GetRatesOfChange( const double *state_vars, const time_struct &tt, double *rates) const { - if ((pHRU->GetHRUType()!=HRU_LAKE) && + if ((pHRU->GetHRUType()!=HRU_LAKE) && (pHRU->GetHRUType()!=HRU_WETLAND)){return;}//Lakes and wetlands only (includes reservoirs) double ice_thick=state_vars[iFrom[0]]; diff --git a/src/MassRouting.cpp b/src/MassRouting.cpp index e5eab4d..9b2c295 100644 --- a/src/MassRouting.cpp +++ b/src/MassRouting.cpp @@ -221,14 +221,14 @@ void CConstituentModel::PrepareForRouting(const int p) { void CConstituentModel::PrepareForInCatchmentRouting(const int p) { //does nothing - interesting in child classes } -void CConstituentModel::InCatchmentRoute(const int p, double &Mlat_new, const optStruct &Options) +void CConstituentModel::InCatchmentRoute(const int p, double &Mlat_new, const optStruct &Options) { PrepareForInCatchmentRouting(p); const double * aUnitHydro =_pModel->GetSubBasin(p)->GetUnitHydrograph(); const double * aQlatHist =_pModel->GetSubBasin(p)->GetLatHistory(); Mlat_new=ApplyInCatchmentRouting(p,aUnitHydro,aQlatHist,_aMlatHist[p],_nMlatHist[p], Options.timestep); - + _aMlocLast[p] = _aMlocal[p]; _aMlocal [p] = Mlat_new; } @@ -266,7 +266,7 @@ void CConstituentModel::RouteMass(const int p, // SB index //============================================================== const double * aRouteHydro=_pModel->GetSubBasin(p)->GetRoutingHydrograph(); const double * aQinHist =_pModel->GetSubBasin(p)->GetInflowHistory(); - + int nSegments =_pModel->GetSubBasin(p)->GetNumSegments(); double seg_fraction=1.0/(double)(nSegments); @@ -284,7 +284,7 @@ void CConstituentModel::RouteMass(const int p, // SB index else { ExitGracefully("Unrecognized or unsupported constiuent routing method (:Routing command must be ROUTE_NONE, ROUTE_PLUG_FLOW, or ROUTE_DIFFUSIVE_WAVE to support transport)",STUB); } - + //all fluxes from catchment are routed directly to basin outlet (unless handled in convolution routing as source term) if ((!_lateral_via_convol) || (_pModel->GetSubBasin(p)->IsHeadwater())){ aMout_new[nSegments-1]+=Mlat_new; @@ -436,7 +436,7 @@ void CConstituentModel::UpdateMassOutflows( const int p, if (!_lateral_via_convol){//elsewise, in get net reach losses dM+=0.5*(Mlat_new+_aMlat_last[p])*dt; } - + _channel_storage[p]+=dM;//[mg] or [MJ] //Update rivulet storage diff --git a/src/ParseInput.cpp b/src/ParseInput.cpp index e8ef553..2221157 100644 --- a/src/ParseInput.cpp +++ b/src/ParseInput.cpp @@ -108,7 +108,7 @@ bool ParseInputFiles (CModel *&pModel, } ExitGracefully("Cannot find or read .rvi file",BAD_DATA);return false; } - if (!Options.create_rvp_template) {//otherwise, jump right to parse rvp, where template is created + if (!Options.create_rvp_template) {//otherwise, jump right to parse rvp, where template is created if (!ParseNetCDFRunInfoFile(pModel, Options, runname_overridden,runmode_overridden)){ ExitGracefully("Cannot find or read NetCDF runinfo file", BAD_DATA); return false; } @@ -3533,12 +3533,12 @@ bool ParseMainInputFile (CModel *&pModel, } //end while (!end_of_file) INPUT.close(); - // Add TOTAL_SWE state variable if any snow is simulated + // Add TOTAL_SWE state variable if any snow is simulated if (pModel->GetStateVarIndex(SNOW) != -1) { tmpS[0] = TOTAL_SWE; tmpLev[0]=0; tmpN=1; pModel->AddStateVariables(tmpS,tmpLev,tmpN); } - + //=============================================================================================== //Check input quality diff --git a/src/ParseManagementFile.cpp b/src/ParseManagementFile.cpp index d326994..77f277e 100644 --- a/src/ParseManagementFile.cpp +++ b/src/ParseManagementFile.cpp @@ -56,14 +56,14 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) CDemand *pDemand=NULL; int demand_ind=0; - long demandSBID; + long demandSBID; int demand_ID; string demand_name; ifstream INPUT2; //For Secondary input CParser *pMainParser=NULL; //for storage of main parser while reading secondary files - //ifstream INPUT3; //For tertiary input - //CParser *pSecondaryParser=NULL; //for storage of secondary parser while reading tertiary files + //ifstream INPUT3; //For tertiary input + //CParser *pSecondaryParser=NULL; //for storage of secondary parser while reading tertiary files ifstream RVM; RVM.open(Options.rvm_filename.c_str(),ios::binary); @@ -176,8 +176,8 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) else if(!strcmp(s[0],":DemandExpression")) { code=62; } //else if(!strcmp(s[0],":AnnualLicense")) { code=63; } else if(!strcmp(s[0],":ReservoirWaterDemand")) { code=64; } - else if(!strcmp(s[0],":EndReservoirWaterDemand")) { code=65; } - else if(!strcmp(s[0],":IsUnrestricted")) { code=66; } + else if(!strcmp(s[0],":EndReservoirWaterDemand")) { code=65; } + else if(!strcmp(s[0],":IsUnrestricted")) { code=66; } else if(!strcmp(s[0],":UserTimeSeries")) { code=70; } @@ -209,14 +209,14 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) //if ((pMainParser != NULL) && (pSecondaryParser != NULL)){ // ExitGracefully("ParseEnsembleFile::nested :RedirectToFile commands are not allowed to be nested more than two levels (e.g., rvm file to rvm file to rvm file to rvm file)",BAD_DATA); //} - //if (pMainParser != NULL) { + //if (pMainParser != NULL) { // pSecondaryParser=pp // pp=new CParser(INPUT3,filename,line);//open new parser - //} //from already redirected .rvm file - //else { - // pMainParser=pp; + //} //from already redirected .rvm file + //else { + // pMainParser=pp; // pp=new CParser(INPUT2,filename,line);//open new parser - //} //from base .rvm file + //} //from base .rvm file // if (pMainParser != NULL) { @@ -1077,7 +1077,7 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) break; } case (61): //-------------------------------------------- - {/*:DemandLookupTable + {/*:DemandLookupTable N {Q_i D_i} x N :EndDemandLookupTable @@ -1266,4 +1266,4 @@ bool ParseManagementFile(CModel *&pModel,const optStruct &Options) pp=NULL; return true; -} \ No newline at end of file +} diff --git a/src/PartitionPrecip.cpp b/src/PartitionPrecip.cpp index 7318cef..9490133 100644 --- a/src/PartitionPrecip.cpp +++ b/src/PartitionPrecip.cpp @@ -280,7 +280,7 @@ void CmvPrecipitation::GetRatesOfChange(const double *state_vars, rates[qSnLiqToDep]+=state_vars[iSnLiq]/Options.timestep; } } - else if (pHRU->GetHRUType() == HRU_WATER) + else if (pHRU->GetHRUType() == HRU_WATER) { rates[qSW] =snowthru + rainthru; //all water goes to surface water } diff --git a/src/RavenProcessConnections.dat b/src/RavenProcessConnections.dat index 2a39f24..3aef72e 100644 --- a/src/RavenProcessConnections.dat +++ b/src/RavenProcessConnections.dat @@ -218,4 +218,4 @@ DFLOW_THRESHPOW DepressionOverflow DEPRESSION SURFACE_WATER DFLOW_LINEAR DepressionOverflow DEPRESSION SURFACE_WATER DFLOW_WEIR DepressionOverflow DEPRESSION SURFACE_WATER SEEP_LINEAR Seepage DEPRESSION SOIL -LAKEREL_LINEAR LakeRelease LAKE SURFACE_WATER \ No newline at end of file +LAKEREL_LINEAR LakeRelease LAKE SURFACE_WATER diff --git a/src/SnowBalance.cpp b/src/SnowBalance.cpp index b03ebba..f1ad3c4 100644 --- a/src/SnowBalance.cpp +++ b/src/SnowBalance.cpp @@ -52,7 +52,7 @@ CmvSnowBalance::CmvSnowBalance(snowbal_type bal_type, CModelABC *pModel) iSoil =pModel->GetStateVarIndex(SOIL,0); iPond =pModel->GetStateVarIndex(PONDED_WATER); - CHydroProcessABC::DynamicSpecifyConnections(5); + CHydroProcessABC::DynamicSpecifyConnections(5); iFrom[0]=iSnow; iTo[0]=iSnowLiq; //rates[0]: SNOW->SNOW_LIQ iFrom[1]=iSnow; iTo[1]=iSoil; //rates[1]: SNOW->SOIL diff --git a/src/Solvers.cpp b/src/Solvers.cpp index cec0e72..e396f41 100644 --- a/src/Solvers.cpp +++ b/src/Solvers.cpp @@ -604,7 +604,7 @@ void MassEnergyBalance( CModel *pModel, }//end for pp... delete [] res_Qstruct; - + //----------------------------------------------------------------- @@ -658,7 +658,7 @@ void MassEnergyBalance( CModel *pModel, pConstitModel->SetMassInflows (p,aMinnew[p]); pConstitModel->SetLateralInfluxes(p,aRoutedMass[p]); - + pConstitModel->InCatchmentRoute (p,Mlat_new,Options);//prepares, calculates, and updates Mlat_new pConstitModel->PrepareForRouting (p); pConstitModel->RouteMass (p,aMoutnew,Mlat_new,ResMass,ResSedMass,Options,tt); //Where everything happens! @@ -676,13 +676,13 @@ void MassEnergyBalance( CModel *pModel, //update state variable values===================================== for (k=0;kGetHydroUnit(k); - + if(pHRU->IsEnabled()) { //update total SWE variable if (iTotalSWE != DOESNT_EXIST) { aPhinew[k][iTotalSWE] =0.0; - for (int i = 0; i < NS; i++) + for (int i = 0; i < NS; i++) { sv_type typ=pModel->GetStateVarType(i); if ((typ == SNOW) || (typ == SNOW_LIQ)) { @@ -690,7 +690,7 @@ void MassEnergyBalance( CModel *pModel, } } } - + for(i=0;iSetStateVarValue(i,aPhinew[k][i]); } diff --git a/src/StateVariables.cpp b/src/StateVariables.cpp index 6e13b14..f39576c 100644 --- a/src/StateVariables.cpp +++ b/src/StateVariables.cpp @@ -138,7 +138,7 @@ string CStateVariable::GetStateVarLongName(const sv_type typ, const int layerind case(SNOW): {name="Snow"; break;} case(NEW_SNOW): {name="New Snow"; break;} case(SNOW_LIQ): {name="Snow Melt (Liquid)"; break;} - case(TOTAL_SWE): {name="Total SWE"; break;} + case(TOTAL_SWE): {name="Total SWE"; break;} case(WETLAND): {name="Wetlands"; break;} case(CUM_INFIL): {name="Cumulative infiltration"; break;} case(GA_MOISTURE_INIT): {name="Green Ampt initial soil Water"; break;} @@ -594,7 +594,7 @@ bool CStateVariable::IsWaterStorage (sv_type typ, bool conv_coverup) case(GLACIER): {return true;} case(GLACIER_ICE): {return true;} case(CONVOLUTION): {return conv_coverup;} - case(CONV_STOR): {return !conv_coverup;} + case(CONV_STOR): {return !conv_coverup;} case(NEW_SNOW): {return true;} case(LATERAL_EXCHANGE):{return true;} case(SNOW_DRIFT): {return true;}