Skip to content

Commit 83b78ee

Browse files
James CraigJames Craig
authored andcommitted
v515 - Lateral flush/diversion with several recipient HRUs
Updated CmvLatFlush::Initialize() to handle more than one recipient HRUS (LatFlush.cpp) cleaned up CustomOutput.cpp/.h to conform to code specs for member vars cosmetic changes to other files
1 parent b768a9b commit 83b78ee

File tree

9 files changed

+141
-144
lines changed

9 files changed

+141
-144
lines changed

src/CustomOutput.cpp

Lines changed: 93 additions & 91 deletions
Large diffs are not rendered by default.

src/CustomOutput.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,15 @@ class CCustomOutput
9090
string _statStr; ///< statistic type string
9191
string _spaceAggStr;///< spatial aggregation type string
9292

93-
double **data; ///< stores accumulated data for each HRU,Basin, or WShed (size:[num_store][num_data])
94-
int num_data; ///< number of data points
95-
int num_store; ///< number of data items needed for each HRU, Basin or WShed
93+
double **_aData; ///< stores accumulated data for each HRU,Basin, or WShed (size:[_nDataItems][_nData])
94+
int _nData; ///< number of data points
95+
int _nDataItems; ///< number of data items needed for each HRU, Basin or WShed
9696
//(e.g., =2 if max and min are both tracked)
97-
int _time_index; ///< index tracking current output line (e.g., 3=3 years/months/days passed, dependent upon _timeAgg
97+
int _time_index; ///< index tracking current output line (e.g., 3=3 years/months/days passed, dependent upon _timeAgg
9898

9999
int _count; ///< counts accumulated data (# of timesteps since last output dump)
100100

101-
int kk_only; ///< index of HRUGroup for which output is generated when spaceAgg==BY_SELECT_HRUS
101+
int _kk_only; ///< index of HRUGroup for which output is generated when spaceAgg==BY_SELECT_HRUS
102102

103103
const CModel *pModel; ///< Reference to model
104104

src/DemandOptimization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ void CDemandOptimizer::SolveManagementProblem(CModel *pModel, const optStruct &O
22542254
else if (retval==ACCURACYERROR){code="ACCURACYERROR "; }
22552255

22562256
cout<<"=========================================="<<endl;
2257-
cout<<"LP SOLVE CANNOT SOLVE OPTIMZIATION PROBLEM"<<endl;
2257+
cout<<"LP SOLVE CANNOT SOLVE OPTIMIZATION PROBLEM"<<endl;
22582258
cout<<"=========================================="<<endl;
22592259
cout<<"Diagnostics:"<<endl;
22602260
cout<<" lp_lib::solve error code: "<<retval<<" ("<<code<<")"<<endl;

src/Diagnostics.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,6 +1454,7 @@ CDiagPeriod::CDiagPeriod(string name,string startdate,string enddate,comparison
14541454

14551455
tt=DateStringToTimeStruct(enddate ,"00:00:00",Options.calendar);
14561456
_t_end = TimeDifference(Options.julian_start_day,Options.julian_start_year,tt.julian_day,tt.year,Options.calendar);
1457+
14571458
if (_t_end<=_t_start){
14581459
string warn;
14591460
warn="CDiagPeriod: :EvaluationPeriod "+_name+": startdate after enddate. ("+to_string(_t_start)+">="+to_string(_t_end);

src/ForcingGrid.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ class CForcingGrid //: public CForcingGridABC
5858

5959
double **_aVal; ///< Array of magnitudes of pulses (variable units)
6060
/// ///< [size _ChunkSize, _nNonZeroWeightedGridCells]
61-
/// ///< time steps are in model resolution (means original input data are
62-
/// ///< already aggregated to match model resolution)
61+
/// ///< time steps are in model resolution (means original input data are already aggregated to match model resolution)
6362

6463
double **_GridWeight; ///< Sparse array of weights for each HRU for a list of cells
6564
// ///< Dimensions : [_nHydroUnits][_nWeights[k]] (variable)

src/LatFlush.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void CmvLatFlush::Initialize()
6262
if(_constrain_to_SBs)
6363
{
6464
//sift through all HRUs
65-
for(int p=0;p<_pModel->GetNumSubBasins();p++)
65+
/*for (int p = 0; p<_pModel->GetNumSubBasins(); p++)
6666
{
6767
//find 'to' HRU (only one allowed per SB)
6868
int kToSB=DOESNT_EXIST;
@@ -88,12 +88,45 @@ void CmvLatFlush::Initialize()
8888
q++;
8989
}
9090
}
91+
}*/
92+
//Alternate approach: multiple recipient stores
93+
bool source_sink_issue=false;
94+
int k1,k2;
95+
for(int p=0;p<_pModel->GetNumSubBasins();p++)
96+
{
97+
for(int ks=0; ks<_pModel->GetSubBasin(p)->GetNumHRUs(); ks++)
98+
{
99+
k1=_pModel->GetSubBasin(p)->GetHRU(ks)->GetGlobalIndex();
100+
for(int ks2=0; ks2<_pModel->GetSubBasin(p)->GetNumHRUs(); ks2++)
101+
{
102+
k2=_pModel->GetSubBasin(p)->GetHRU(ks2)->GetGlobalIndex();
103+
104+
if ((_pModel->IsInHRUGroup(k1,toHRUGrp)) && (_pModel->IsInHRUGroup(k2,fromHRUGrp)))
105+
{
106+
if (k1!=k2){
107+
kTo [q]=k1;
108+
kFrom[q]=k2;
109+
q++;
110+
ExitGracefullyIf(q>=MAX_LAT_CONNECTIONS,"Number of HRU connections in LateralFlush or LateralDivert exceeds MAX_LAT_CONNECTIONS limit.",BAD_DATA);
111+
}
112+
else {
113+
//may want to throw warning if source is also sink
114+
source_sink_issue=true;
115+
}
116+
}
117+
}
118+
}
91119
}
120+
92121
nConn=q;
93122
if(nConn==0) {
94123
string warning="CmvLatFlush::Initialize: no connections found between from and to HRU groups in any of the basins. if INTERBASIN flag not used, only transfer within basins is supported. ";
95124
WriteWarning(warning,true);
96125
}
126+
if (source_sink_issue) {
127+
string warning="CmvLatFlush::Initialize: one or more HRUs belongs to both source and recipient HRU groups in LateralFlush or LateralDivert process. This may have unintentended consequences. ";
128+
WriteWarning(warning,true);
129+
}
97130
}
98131
else //!constrain_to_SBs
99132
{
@@ -102,7 +135,7 @@ void CmvLatFlush::Initialize()
102135
for(k=0;k<_pModel->GetNumHRUs();k++) {
103136
if(_pModel->IsInHRUGroup(k,toHRUGrp)) {
104137
ExitGracefullyIf(kToSB!=DOESNT_EXIST,
105-
"LatFlush::Initialize - only one HRU in the model can recieve flush output. More than one recipient HRU found.",BAD_DATA_WARN);
138+
"LatFlush::Initialize - only one HRU in the model can recieve flush output if INTERBASIN is used. More than one recipient HRU found.",BAD_DATA_WARN);
106139
kToSB=k;
107140
}
108141
}
@@ -128,9 +161,6 @@ void CmvLatFlush::Initialize()
128161
_kTo [q] =kTo[q];
129162
_iFromLat[q] =_iFlushFrom;
130163
_iToLat [q] =_iFlushTo;
131-
/*cout << "latflush connections: " << _pModel->GetHydroUnit(_kFrom[q])->GetID() << " " << _pModel->GetHydroUnit(_kTo[q])->GetID() << " ";
132-
cout<<_pModel->GetStateVarInfo()->SVTypeToString(_pModel->GetStateVarType(_iFromLat[q]),-1)<<" ";
133-
cout<<_pModel->GetStateVarInfo()->SVTypeToString(_pModel->GetStateVarType(_iToLat[q]),-1)<<endl;*/
134164
}
135165
delete [] kFrom;
136166
delete [] kTo;

src/MFUSGpp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ namespace MFUSG
3838
// Routines to work with MFUSG data
3939
void mask_iunit (int *export_iunit); // See Extern.f90 in MFUSGLib for iunit/package table (CUNIT)
4040
void add_to_flow_eq (int *node, double *AMAT_change, double *RHS_change);
41-
void add_to_flow_budget (int *nnodes, int *rvn_nodes, double *rates, char *pckg_name);
41+
void add_to_flow_budget (int *nnodes, int *rvn_nodes, double *rates, char *pckg_name);
4242
void first_active_below (int *node);
4343
void set_irvncb (int *unit_no);
4444
void set_nrchop (int *new_NRCHOP);
@@ -58,4 +58,4 @@ namespace MFUSG
5858

5959
}
6060
#endif
61-
#endif
61+
#endif

src/Model.cpp

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -249,84 +249,70 @@ CModel::~CModel()
249249

250250
//////////////////////////////////////////////////////////////////
251251
/// \brief Returns pointer to global parameters object
252-
///
253252
/// \return Pointer to global parameters object
254253
//
255-
CGlobalParams* CModel::GetGlobalParams() const {
256-
return _pGlobalParams;
257-
}
254+
CGlobalParams* CModel::GetGlobalParams() const { return _pGlobalParams;}
258255

259256
//////////////////////////////////////////////////////////////////
260257
/// \brief Returns number of sub basins in model
261-
///
262258
/// \return Integer number of sub basins
263259
//
264260
int CModel::GetNumSubBasins () const{return _nSubBasins;}
265261

266262
//////////////////////////////////////////////////////////////////
267263
/// \brief Returns number of SB groups
268-
///
269264
/// \return Integer number of SB groups
270265
//
271266
int CModel::GetNumSubBasinGroups() const { return _nSBGroups; }
272267

273268
//////////////////////////////////////////////////////////////////
274269
/// \brief Returns number of HRUs in model
275-
///
276270
/// \return Integer number of HRUs
277271
//
278272
int CModel::GetNumHRUs () const{return _nHydroUnits;}
279273

280274
//////////////////////////////////////////////////////////////////
281275
/// \brief Returns number of HRU groups
282-
///
283276
/// \return Integer number of HRU groups
284277
//
285278
int CModel::GetNumHRUGroups () const{return _nHRUGroups;}
286279

287280
//////////////////////////////////////////////////////////////////
288281
/// \brief Returns number of gauges in model
289-
///
290282
/// \return Integer number of gauges in model
291283
//
292284
int CModel::GetNumGauges () const{return _nGauges;}
293285

294286
//////////////////////////////////////////////////////////////////
295287
/// \brief Returns number of gridded forcings in model
296-
///
297288
/// \return Integer number of gridded forcings in model
298289
//
299290
int CModel::GetNumForcingGrids () const{return _nForcingGrids;}
300291

301292
//////////////////////////////////////////////////////////////////
302293
/// \brief Returns number of state variables per HRU in model
303-
///
304294
/// \return Integer number of state variables per HRU in model
305295
//
306296
int CModel::GetNumStateVars () const{return _nStateVars;}
307297

308298
//////////////////////////////////////////////////////////////////
309299
/// \brief Returns number of soil layers
310-
///
311300
/// \return Integer number of soil layers
312301
//
313302
int CModel::GetNumSoilLayers () const{return _nSoilVars;}
314303

315304
//////////////////////////////////////////////////////////////////
316305
/// \brief Returns number of hydrologic processes simulated by model
317-
///
318306
/// \return Integer number of hydrologic processes simulated by model
319307
//
320308
int CModel::GetNumProcesses () const{return _nProcesses;}
321309

322310
//////////////////////////////////////////////////////////////////
323311
/// \brief Returns total modeled watershed area
324-
///
325312
/// \return total modeled watershed area [km2]
326313
//
327314
double CModel::GetWatershedArea () const{return _WatershedArea;}
328315

329-
330316
//////////////////////////////////////////////////////////////////
331317
/// \brief Returns number of observation time series
332318
/// \return number of observation time series
@@ -371,13 +357,11 @@ const CTimeSeriesABC* CModel::GetSimulatedTS(const int i) const {
371357

372358
//////////////////////////////////////////////////////////////////
373359
/// \brief Returns specific hydrologic process denoted by parameter
374-
///
375360
/// \param j [in] Process index
376361
/// \return pointer to hydrologic process corresponding to passed index j
377362
//
378363
CHydroProcessABC *CModel::GetProcess(const int j) const
379364
{
380-
381365
#ifdef _STRICTCHECK_
382366
ExitGracefullyIf((j<0) || (j>=_nProcesses),"CModel GetProcess::improper index",BAD_DATA);
383367
#endif
@@ -386,7 +370,6 @@ CHydroProcessABC *CModel::GetProcess(const int j) const
386370

387371
//////////////////////////////////////////////////////////////////
388372
/// \brief Returns specific gauge denoted by index
389-
///
390373
/// \param g [in] Gauge index
391374
/// \return pointer to gauge corresponding to passed index g
392375
//
@@ -400,7 +383,6 @@ CGauge *CModel::GetGauge(const int g) const
400383

401384
//////////////////////////////////////////////////////////////////
402385
/// \brief Returns specific forcing grid denoted by index
403-
///
404386
/// \param f [in] Forcing Grid index
405387
/// \return pointer to gauge corresponding to passed index g
406388
//
@@ -417,7 +399,6 @@ CForcingGrid *CModel::GetForcingGrid(const forcing_type &ftyp) const
417399

418400
//////////////////////////////////////////////////////////////////
419401
/// \brief Returns specific HRU denoted by index k
420-
///
421402
/// \param k [in] HRU index
422403
/// \return pointer to HRU corresponding to passed index k
423404
//
@@ -431,7 +412,6 @@ CHydroUnit *CModel::GetHydroUnit(const int k) const
431412

432413
//////////////////////////////////////////////////////////////////
433414
/// \brief Returns specific HRU with HRU identifier HRUID
434-
///
435415
/// \param HRUID [in] HRU identifier
436416
/// \return pointer to HRU corresponding to passed ID HRUID, NULL if no such HRU exists
437417
//
@@ -449,7 +429,6 @@ CHydroUnit *CModel::GetHRUByID(const long long int HRUID) const
449429

450430
//////////////////////////////////////////////////////////////////
451431
/// \brief Returns specific HRU group denoted by parameter kk
452-
///
453432
/// \param kk [in] HRU group index
454433
/// \return pointer to HRU group corresponding to passed index kk
455434
//
@@ -463,7 +442,6 @@ CHRUGroup *CModel::GetHRUGroup(const int kk) const
463442

464443
//////////////////////////////////////////////////////////////////
465444
/// \brief Returns specific HRU group denoted by string parameter
466-
///
467445
/// \param name [in] String name of HRU group
468446
/// \return pointer to HRU group corresponding to passed name, or NULL if this group doesn't exist
469447
//
@@ -513,7 +491,6 @@ CSubBasin *CModel::GetSubBasin(const int p) const
513491

514492
//////////////////////////////////////////////////////////////////
515493
/// \brief Returns index of subbasin downstream from subbasin referred to by index
516-
///
517494
/// \param p [in] List index for accessing subbasin
518495
/// \return downstream subbasin index, if input index is valid; -1 if there is no downstream basin
519496
//
@@ -527,7 +504,6 @@ int CModel::GetDownstreamBasin(const int p) const
527504

528505
//////////////////////////////////////////////////////////////////
529506
/// \brief Returns subbasin object corresponding to passed subbasin ID
530-
///
531507
/// \param SBID [in] long long integer sub basin ID
532508
/// \return pointer to Sub basin object corresponding to passed ID, if ID is valid
533509
//
@@ -546,7 +522,6 @@ CSubBasin *CModel::GetSubBasinByID(const long long SBID) const
546522

547523
//////////////////////////////////////////////////////////////////
548524
/// \brief Returns sub basin index corresponding to passed subbasin ID
549-
///
550525
/// \param SBID [in] Integer subbasin ID
551526
/// \return SubBasin index corresponding to passed ID, if ID is valid
552527
//
@@ -564,7 +539,6 @@ int CModel::GetSubBasinIndex(const long long SBID) const
564539
}
565540
//////////////////////////////////////////////////////////////////
566541
/// \brief Returns array of pointers to subbasins upstream of subbasin SBID, including that subbasin
567-
///
568542
/// \param SBID [in] long long int subbasin ID
569543
/// \param nUpstream [out] size of array of pointers of subbasins
570544
/// \return array of pointers to subbasins upstream of subbasin SBID, including that subbasin
@@ -774,7 +748,6 @@ int CModel::GetStateVarLayer(const int ii) const
774748

775749
//////////////////////////////////////////////////////////////////
776750
/// \brief Checks if state variable passed exists in model
777-
///
778751
/// \param typ [in] State variable type
779752
/// \return Boolean indicating whether state variable exists in model
780753
//
@@ -785,14 +758,12 @@ bool CModel::StateVarExists(sv_type typ) const
785758

786759
//////////////////////////////////////////////////////////////////
787760
/// \brief Returns lake storage variable index
788-
///
789761
/// \return Integer index of lake storage variable
790762
//
791763
int CModel::GetLakeStorageIndex() const{return _lake_sv;}
792764

793765
//////////////////////////////////////////////////////////////////
794766
/// \brief Returns gauge index of gauge with specified name
795-
///
796767
/// \return Integer index of gauge
797768
/// \param name [in] specified name
798769
//
@@ -806,7 +777,6 @@ int CModel::GetGaugeIndexFromName (const string name) const
806777

807778
//////////////////////////////////////////////////////////////////
808779
/// \brief Returns forcing grid index of forcing grid with specified type
809-
///
810780
/// \return Integer index of forcing grid
811781
/// \param name [in] specified type
812782
//
@@ -821,7 +791,6 @@ int CModel::GetForcingGridIndexFromType (const forcing_type &typ) const
821791
//////////////////////////////////////////////////////////////////
822792
/// \brief Returns current mass/energy flux (mm/d, MJ/m2/d, mg/m2/d) between two storage compartments iFrom and iTo
823793
/// \details required for advective transport processes
824-
///
825794
/// \param k [in] HRU index
826795
/// \param js [in] index of process connection (i.e., j*)
827796
/// \param &Options [in] Global model options information
@@ -836,7 +805,6 @@ double CModel::GetFlux(const int k, const int js, const optStruct &Options) cons
836805
}
837806
//////////////////////////////////////////////////////////////////
838807
/// \brief returns concentration or temperature within hru k with storage index i
839-
///
840808
/// \param k [in] HRU index
841809
/// \param i [in] mass/energy state variable index
842810
//
@@ -848,7 +816,6 @@ double CModel::GetConcentration(const int k, const int i) const
848816
//////////////////////////////////////////////////////////////////
849817
/// \brief Returns current mass/energy flow (mm-m2/d, MJ/d, mg/d) between two storage compartments iFrom and iTo
850818
/// \details required for advective transport processes
851-
///
852819
/// \param k [in] HRU index
853820
/// \param qs [in] global index of process connection (i.e., q*)
854821
/// \param &Options [in] Global model options information
@@ -862,7 +829,6 @@ double CModel::GetLatFlow(const int qs,const optStruct &Options) const
862829
}
863830
//////////////////////////////////////////////////////////////////
864831
/// \brief Returns cumulative flux to/from storage unit i
865-
///
866832
/// \param k [in] index of HRU
867833
/// \param i [in] index of storage compartment
868834
/// \param to [in] true if evaluating cumulative flux to storage compartment, false for 'from'
@@ -903,7 +869,6 @@ double CModel::GetCumulativeFlux(const int k, const int i, const bool to) const
903869
}
904870
//////////////////////////////////////////////////////////////////
905871
/// \brief Returns cumulative gross flux between unit iFrom and iTo in HRU k
906-
///
907872
/// \param k [in] index of HRU
908873
/// \param iFrom [in] index of storage compartment
909874
/// \param iTo [in] index of storage compartment

0 commit comments

Comments
 (0)