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.32.1
rev: 0.33.2
hooks:
- id: check-github-workflows
- repo: meta
Expand Down
16 changes: 8 additions & 8 deletions src/Assimilate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,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 @@ -102,7 +102,7 @@ void CModel::AssimilationOverride(const int p,const optStruct& Options,const tim
}
}

//
//
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 @@ -151,7 +151,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
break; //avoids duplicate observations
}
}
}
}

pdown=GetDownstreamBasin(p);

Expand Down Expand Up @@ -184,7 +184,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDAscale [p]= _aDAscale [pdown];
_aDAlength [p]+=_pSubBasins [pdown]->GetReachLength();
_aDAtimesince [p]= _aDAtimesince[pdown];
_aDAoverride [p]=false;
_aDAoverride [p]=false;
}
else{ //Nothing downstream or reservoir present in this basin, no assimilation
_aDAscale [p]=1.0;
Expand All @@ -194,7 +194,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
}
}
}// end downstream to upstream

//Calculate _aDADrainSum, sum of assimilated drainage areas upstream of a subbasin outlet
// and _aDADownSum, drainage of nearest assimilated flow observation
// dynamic because data can disappear mid simulation
Expand All @@ -221,7 +221,7 @@ void CModel::PrepareAssimilation(const optStruct &Options,const time_struct &tt)
_aDADrainSum[pdown]+=_aDADrainSum[p];
}
}
for(int pp=_nSubBasins-1;pp>=0; pp--)// downstream to upstream
for(int pp=_nSubBasins-1;pp>=0; pp--)// downstream to upstream
{
p=GetOrderedSubBasinIndex(pp);
pdown=GetDownstreamBasin(p);
Expand Down Expand Up @@ -266,7 +266,7 @@ void CModel::AssimilationBackPropagate(const optStruct &Options,const time_struc
if (_pSubBasins[p]->GetDownstreamID()!=DOESNT_EXIST){
pdown = GetSubBasinByID(_pSubBasins[p]->GetDownstreamID())->GetGlobalIndex();
}

// no observations in this basin, get scaling from downstream
//----------------------------------------------------------------
pdown=GetDownstreamBasin(p);
Expand Down Expand Up @@ -302,7 +302,7 @@ void CModel::AssimilationBackPropagate(const optStruct &Options,const time_struc
}
}

// Actually update flows
// Actually update flows
//----------------------------------------------------------------
for(p=0; p<_nSubBasins; p++)
{
Expand Down
10 changes: 5 additions & 5 deletions src/CommonFunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ double GetSaturatedVaporPressure(const double &T)//[C]
const double A3=237.3;
const double A4=21.87456;
const double A5=265.5;

//0.61115*exp(22.452*T/(T+ZERO_CELSIUS)); //MESH

//0.611*exp(17.27*Ta/(Ta+237.3)); //Common simplification of Dingman for T>0
Expand Down Expand Up @@ -1749,11 +1749,11 @@ double ADRCumDist(const double &t, const double &L, const double &v, const doubl
/// \param &L reach length [m]
/// \param &v celerity [m/d]
/// \param &D diffusivity [m2/d]
/// \return Returns integral
/// \return Returns integral
//
//int_0^time L/2/t^(1/2)/sqrt(pi*D)*exp(-(v*t-L)^2/(4*D*t)) dt
// extreme case (D->0): =1 for v*t<L, 0 otherwise
double G_integral(const double& t, const double& L, const double& v, const double& D)
double G_integral(const double& t, const double& L, const double& v, const double& D)
{
double G=0;
if (t<=0){return 0.0;}
Expand All @@ -1771,12 +1771,12 @@ double G_integral(const double& t, const double& L, const double& v, const doubl
/// \param &L reach length [m]
/// \param &v celerity [m/d]
/// \param &D diffusivity [m2/d]
/// \return Returns Unit hydrograph - sums to one
/// \return Returns Unit hydrograph - sums to one
//
double DiffusiveWaveUH(const int n, const double& L, const double& v, const double& D, const double& dt)
{
if (n == 0) {
return 1.0/dt*(G_integral(0.0,L,v,D)-G_integral(dt,L,v,D))+ADRCumDist(dt,L,v,D)-ADRCumDist(0.0,L,v,D);
return 1.0/dt*(G_integral(0.0,L,v,D)-G_integral(dt,L,v,D))+ADRCumDist(dt,L,v,D)-ADRCumDist(0.0,L,v,D);
}
else {
double UH=1.0/dt*(2*G_integral(n*dt,L,v,D)- G_integral((n-1)*dt,L,v,D)- G_integral((n+1)*dt,L,v,D));
Expand Down
2 changes: 1 addition & 1 deletion src/CustomOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,4 +1215,4 @@ CCustomOutput *CCustomOutput::ParseCustomOutputCommand(char *s[MAXINPUTITEMS], c
}

return pCustom;
}
}
4 changes: 2 additions & 2 deletions src/DemandExpressionHandling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1331,7 +1331,7 @@ void CDemandOptimizer::AddConstraintToLP(const int ii, const int kk, lp_lib::lpr
retval = lp_lib::set_rowex(pLinProg,lpgoalrow,1,row_val,col_ind);
ExitGracefullyIf(retval==0,"AddConstraintToLP::Error updating user-specified constraint/goal",RUNTIME_ERR);
retval = lp_lib::set_rh(pLinProg,lpgoalrow,RHS);
return;
return;
}

//bool is_stage;
Expand Down Expand Up @@ -1369,7 +1369,7 @@ void CDemandOptimizer::AddConstraintToLP(const int ii, const int kk, lp_lib::lpr
else {
coeff *= (pE->pTerms[j][k]->mult) * term;
}

}
}

Expand Down
40 changes: 20 additions & 20 deletions src/DemandOptimization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void CDemandOptimizer::Initialize(CModel* pModel, const optStruct& Options)
}
}
}
// add reservoir delta stage DVs
// add reservoir delta stage DVs
res_count=0;
for (int pp=0;pp<pModel->GetNumSubBasins();pp++)
{
Expand Down Expand Up @@ -1325,7 +1325,7 @@ void CDemandOptimizer::IncrementAndSetRowName(lp_lib::lprec *pLinProg,int &rowco
//
int CDemandOptimizer::GetDVColumnInd(const dv_type typ, const int counter) const
{
int N=5;
int N=5;

if (typ==DV_QOUT ){return counter+1;}
else if (typ==DV_QOUTRES ){return _nEnabledSubBasins+counter+1;}
Expand Down Expand Up @@ -1474,7 +1474,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
r++;
}
}

// Set lower bounds of stages to min stage -2m
// ----------------------------------------------------------------
int res_count=0;
Expand Down Expand Up @@ -1710,7 +1710,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
// Mass balance equation at reach outlet:
// Q_p = (Qin +Qin2 )*U0 + sum(Ui*Qn-i) + Runoff - Div_out(Q) + Div_in - Delivered + Qadded + U_0*Qadded2 +Qreturn
// Q_p-U_0*Qin-U_0*Qin2... +Delivered -Qreturn= sum(Ui*Qn-i) + Runoff - Div_out(Q) + Div_in + Qadded + U_0*Qadded2
//
//
// or, if assimilating flows, use direct insertion:
// Q_p = Q*_p
//------------------------------------------------------------------------
Expand All @@ -1721,7 +1721,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O

i=0;
Qobs=_pModel->GetObservedFlow(p,nn);
assimilating = ((Options.assimilate_flow) && (pSB->UseInFlowAssimilation()) && (Qobs!=RAV_BLANK_DATA) && (pSB->GetReservoir()==NULL));
assimilating = ((Options.assimilate_flow) && (pSB->UseInFlowAssimilation()) && (Qobs!=RAV_BLANK_DATA) && (pSB->GetReservoir()==NULL));

// outflow term =============================
col_ind[i]=GetDVColumnInd(DV_QOUT,_aSBIndices[p]);
Expand Down Expand Up @@ -1811,7 +1811,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
double Adt,ET,precip,seepage(0);
double h_old,dQdh,Qout_last,Qin_last,h_obs,h_dry;
bool assim_stage(false);

for (int pp = 0; pp<pModel->GetNumSubBasins(); pp++)
{
p =pModel->GetOrderedSubBasinIndex(pp);
Expand All @@ -1822,7 +1822,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
{
Qobs=_pModel->GetObservedFlow(p,nn);
assimilating = ((Options.assimilate_flow) && (pSB->UseInFlowAssimilation()) && (Qobs!=RAV_BLANK_DATA));

h_obs = pRes->GetObsStage(nn);
assim_stage = ((Options.assimilate_stage) && (pRes->UseInStageAssimilation()) && (h_obs!=RAV_BLANK_DATA));

Expand Down Expand Up @@ -1867,11 +1867,11 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
row_val[i]=+0.5;
i++;

col_ind[i]=GetDVColumnInd(DV_DSTAGE ,_aResIndices[p]);
col_ind[i]=GetDVColumnInd(DV_DSTAGE ,_aResIndices[p]);
row_val[i]=Adt;
i++;
col_ind[i]=GetDVColumnInd(DV_DSTAGE2 ,_aResIndices[p]);

col_ind[i]=GetDVColumnInd(DV_DSTAGE2 ,_aResIndices[p]);
row_val[i]=-Adt;
i++;

Expand All @@ -1882,7 +1882,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
row_val[i]=+1.0;
i++;
}

RHS=(precip-ET)-seepage-0.5*Qout_last+0.5*Qin_last;

retval = lp_lib::add_constraintex(pLinProg,i,row_val,col_ind,ROWTYPE_EQ,RHS);
Expand All @@ -1894,8 +1894,8 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
else //(assim_stage==true)
{
// lake assimilation equation - solves for dh
// dh+-dh- = h_obs-h_old
// dh+-dh- = h_obs-h_old

col_ind[0]=GetDVColumnInd(DV_DSTAGE ,_aResIndices[p]); row_val[0]=1.0;
col_ind[1]=GetDVColumnInd(DV_DSTAGE2 ,_aResIndices[p]); row_val[1]=-1.0;
RHS=h_obs-h_old;
Expand All @@ -1905,7 +1905,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
IncrementAndSetRowName(pLinProg,rowcount,"reser_MB_"+to_string(pSB->GetID()));
}

// Equation: Definition of delta h
// Equation: Definition of delta h
//-------------------------------------------------------
col_ind[0]=GetDVColumnInd(DV_STAGE,_aResIndices[p]); row_val[0]= 1.0;
col_ind[1]=GetDVColumnInd(DV_DSTAGE,_aResIndices[p]); row_val[1]=-1.0;
Expand Down Expand Up @@ -1948,10 +1948,10 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O

lprow[p]=lp_lib::get_Nrows(pLinProg);
}
else if (assimilating)
else if (assimilating)
{
//------------------------------------------------------------------------
// Assimilating
// Assimilating
// Q^n+1 == Qobs
//------------------------------------------------------------------------

Expand Down Expand Up @@ -2107,7 +2107,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
//lp_lib::set_epslevel(pLinProg, EPS_MEDIUM);

retval = lp_lib::solve(pLinProg);

if (retval!=OPTIMAL)
{
if (_do_debug_level>0){ cout<<"LP instability found."<<endl; }
Expand Down Expand Up @@ -2184,7 +2184,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
cout << " >h " << SBID << ": "; for (int i = 0; i <= iter; i++) { cout << setprecision(10)<<ahiterHist[p][i] << " "; }cout << endl;
cout << " >B " << SBID << ": "; for (int i = 0; i <= iter; i++) { cout << aBinHist[p][i] << " "; }cout << endl;
cout << " >Sill ht "<< SBID<<": "<< sill_ht<< " diff: "<< h_iter[p]-sill_ht<<endl;

if (fabs(h_iter[p] - sill_ht) < 0.001) {
cout << " > VERY CLOSE TO SILL: PROBLEM LAKE IS "<<SBID<<endl;
}
Expand Down Expand Up @@ -2263,7 +2263,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
{
p =pModel->GetOrderedSubBasinIndex(pp);
pSB =pModel->GetSubBasin(p);

long long SBID=pSB->GetID();
if ((pSB->IsEnabled()) && (pSB->GetReservoir() != NULL))
{
Expand Down Expand Up @@ -2427,7 +2427,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
else if (typ == DV_QOUTRES)
{
if (_aDisableSDCurve[p]){ // no need to report if this is handled properly by Raven default solver
pModel->GetSubBasin(p)->GetReservoir()->SetOptimizedOutflow(value);
pModel->GetSubBasin(p)->GetReservoir()->SetOptimizedOutflow(value);
}
}
else if (typ == DV_DELIVERY)
Expand Down
2 changes: 1 addition & 1 deletion src/EnergyTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ void CEnthalpyModel::Initialize(const optStruct& Options)
for(int p=0;p<_pModel->GetNumSubBasins();p++)
{
pBasin=_pModel->GetSubBasin(p);

for(int i=0; i<pBasin->GetNumSegments(); i++)
{
_aMout[p][i]=pBasin->GetOutflowArray()[_pModel->GetSubBasin(p)->GetNumSegments()-1] * SEC_PER_DAY * hv; //not really - requires outflow rate from all segments in general case. Don't have access to this. assumes nSegs=1
Expand Down
2 changes: 1 addition & 1 deletion src/ForcingGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1003,7 +1003,7 @@ bool CForcingGrid::ReadData(const optStruct &Options,
}
}
}
// Deaccumulate
// Deaccumulate
// -------------------------------
Deaccumulate();

Expand Down
2 changes: 1 addition & 1 deletion src/ForcingGrid.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ class CForcingGrid //: public CForcingGridABC
void SetAsPeriodEnding (); ///< set _period_ending
void SetIs3D( const bool is3D); ///< set _is3D of class
void SetIdxNonZeroGridCells( const int nHydroUnits,
const int nGridCells,
const int nGridCells,
const bool *disabledHRUs,
const optStruct &Options);
///< set _IdxNonZeroGridCells of class
Expand Down
16 changes: 8 additions & 8 deletions src/IsotopeTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ void CIsotopeModel::UpdateInitialConditions(const optStruct& Options)
pBasin=_pModel->GetSubBasin(p);

int nSegments=pBasin->GetNumSegments();

for(int i=0; i<pBasin->GetNumSegments(); i++)
{
_aMout[p][i]=pBasin->GetOutflowArray()[nSegments-1] * SEC_PER_DAY * Cinit; // assumes nSegs=1
}
_aMout_last[p]=_aMout[p][0];

const double *aQin=_pModel->GetSubBasin(p)->GetInflowHistory();
for(int i=0; i<_nMinHist[p]; i++) {
for(int i=0; i<_nMinHist[p]; i++) {
_aMinHist [p][i]=aQin[i]*SEC_PER_DAY*Cinit;
}
const double *aQlat=_pModel->GetSubBasin(p)->GetLatHistory();
Expand All @@ -73,7 +73,7 @@ void CIsotopeModel::UpdateInitialConditions(const optStruct& Options)
_aMlat_last[p]=_aMlatHist[p][0];
_aMlocal [p]=_aMlat_last[p];
_aMlocLast [p]=_aMlat_last[p];

//_channel_storage[p]=0.0;
//_rivulet_storage[p]=0.0;

Expand All @@ -93,7 +93,7 @@ void CIsotopeModel::UpdateInitialConditions(const optStruct& Options)
//////////////////////////////////////////////////////////////////
/// \brief set initial surface water concentration
//
void CIsotopeModel::SetSurfaceWaterConc(const double& delta)
void CIsotopeModel::SetSurfaceWaterConc(const double& delta)
{
_initSWconc=delta;
}
Expand Down Expand Up @@ -137,7 +137,7 @@ double CIsotopeModel::ConvertConcentration(const double &delta) const
/// \param iToWater [in] index of "to" water storage state variable
/// \param mass [in] source mass prior to advection [mg]
/// \param vol [in] source volume prior to advection [mm] or [mm-m2]
/// \param Q [in] flow between source and recipient [mm/d] or [mm-m2]
/// \param Q [in] flow between source and recipient [mm/d] or [mm-m2]
///
double CIsotopeModel::GetAdvectionCorrection(const CHydroUnit* pHRU,const int iFromWater,const int iToWater,const double& mass, const double &vol, const double &Q) const
{
Expand Down Expand Up @@ -186,7 +186,7 @@ double CIsotopeModel::GetAdvectionCorrection(const CHydroUnit* pHRU,const int iF
CK0=25.0/TO_PER_MILLE;
}
ep_star =alpha_star-1.0; //[-]

if (fromType==DEPRESSION ) {eta=0.6;}
else if (fromType==SOIL ) {eta=1.0;}
else if (fromType==SURFACE_WATER) {eta=0.5;}
Expand All @@ -200,7 +200,7 @@ double CIsotopeModel::GetAdvectionCorrection(const CHydroUnit* pHRU,const int iF
dStar=(h*dA/TO_PER_MILLE+ekin+ep_star/alpha_star)/(h - ekin - ep_star/alpha_star)*TO_PER_MILLE; //[o/oo]

dE =((dL/TO_PER_MILLE-ep_star)/alpha_star - h*dA/TO_PER_MILLE - ekin) / (1.0-h+ekin)*TO_PER_MILLE; //[o/oo]

if (dE>dL){dE=dL;}

double C_E =CompositionToConc(dE);
Expand All @@ -225,7 +225,7 @@ double CIsotopeModel::GetAdvectionCorrection(const CHydroUnit* pHRU,const int iF
}
else if ( ((fromType==SNOW_LIQ) || (toType==SNOW)) ) //refreeze - dilutes snow
{
// \todo[funct]
// \todo[funct]
}

return 1.0;
Expand Down
Loading
Loading