Commit c073a383 authored by Turner, Sean's avatar Turner, Sean
Browse files

directed flows

parent d29a6853
Loading
Loading
Loading
Loading
+169 −0
Original line number Diff line number Diff line
datetime,catchment_inflow,target_release
2007-07-01T00:00:00Z,8.416219997951998,5.308050825937269
2007-07-01T01:00:00Z,8.416219997951998,5.101331614130994
2007-07-01T02:00:00Z,8.416219997951998,6.406875581125612
2007-07-01T03:00:00Z,8.416219997951998,4.69492170871826
2007-07-01T04:00:00Z,8.416219997951998,7.706239199319716
2007-07-01T05:00:00Z,8.416219997951998,7.990713481248751
2007-07-01T06:00:00Z,8.416219997951998,6.5661771721100175
2007-07-01T07:00:00Z,8.416219997951998,9.935104640736169
2007-07-01T08:00:00Z,8.416219997951998,5.639826578089164
2007-07-01T09:00:00Z,8.416219997951998,12.563627525443023
2007-07-01T10:00:00Z,8.416219997951998,11.584503491140607
2007-07-01T11:00:00Z,8.416219997951998,6.077601571866892
2007-07-01T12:00:00Z,8.416219997951998,11.737633073185977
2007-07-01T13:00:00Z,8.416219997951998,8.38507969393619
2007-07-01T14:00:00Z,8.416219997951998,7.619851998289994
2007-07-01T15:00:00Z,8.416219997951998,12.434177345803144
2007-07-01T16:00:00Z,8.416219997951998,11.008058928101974
2007-07-01T17:00:00Z,8.416219997951998,8.357046750588287
2007-07-01T18:00:00Z,8.416219997951998,7.405026674311733
2007-07-01T19:00:00Z,8.416219997951998,5.387243195547386
2007-07-01T20:00:00Z,8.416219997951998,6.852892272530108
2007-07-01T21:00:00Z,8.416219997951998,10.553381927405157
2007-07-01T22:00:00Z,8.416219997951998,10.02883979860741
2007-07-01T23:00:00Z,8.416219997951998,6.868997854030686
2007-07-02T00:00:00Z,11.401042206527999,14.054787807022644
2007-07-02T01:00:00Z,11.401042206527999,5.902827103261581
2007-07-02T02:00:00Z,11.401042206527999,14.003312776612573
2007-07-02T03:00:00Z,11.401042206527999,10.94137548175276
2007-07-02T04:00:00Z,11.401042206527999,12.895656096416177
2007-07-02T05:00:00Z,11.401042206527999,9.136423608521048
2007-07-02T06:00:00Z,11.401042206527999,10.739237591999839
2007-07-02T07:00:00Z,11.401042206527999,10.797371343642494
2007-07-02T08:00:00Z,11.401042206527999,9.862119505029126
2007-07-02T09:00:00Z,11.401042206527999,13.723634491758803
2007-07-02T10:00:00Z,11.401042206527999,16.945001527530458
2007-07-02T11:00:00Z,11.401042206527999,5.875427320699803
2007-07-02T12:00:00Z,11.401042206527999,10.132310890516774
2007-07-02T13:00:00Z,11.401042206527999,8.177132004921228
2007-07-02T14:00:00Z,11.401042206527999,9.34136653171742
2007-07-02T15:00:00Z,11.401042206527999,7.5673836474405975
2007-07-02T16:00:00Z,11.401042206527999,12.813150635716573
2007-07-02T17:00:00Z,11.401042206527999,15.340632217692422
2007-07-02T18:00:00Z,11.401042206527999,12.016126802056146
2007-07-02T19:00:00Z,11.401042206527999,14.55522651409827
2007-07-02T20:00:00Z,11.401042206527999,9.968457206276415
2007-07-02T21:00:00Z,11.401042206527999,14.453030369193442
2007-07-02T22:00:00Z,11.401042206527999,7.330188586663013
2007-07-02T23:00:00Z,11.401042206527999,11.309488390425475
2007-07-03T00:00:00Z,11.547836741375999,7.422719276247288
2007-07-03T01:00:00Z,11.547836741375999,8.234758831802045
2007-07-03T02:00:00Z,11.547836741375999,12.632208893855806
2007-07-03T03:00:00Z,11.547836741375999,7.983690914077474
2007-07-03T04:00:00Z,11.547836741375999,6.33869304796781
2007-07-03T05:00:00Z,11.547836741375999,9.034371699225565
2007-07-03T06:00:00Z,11.547836741375999,7.993384938418182
2007-07-03T07:00:00Z,11.547836741375999,15.559806979147687
2007-07-03T08:00:00Z,11.547836741375999,11.781531205701594
2007-07-03T09:00:00Z,11.547836741375999,5.999557392622285
2007-07-03T10:00:00Z,11.547836741375999,8.832920936111671
2007-07-03T11:00:00Z,11.547836741375999,9.6497887529109
2007-07-03T12:00:00Z,11.547836741375999,8.251524928891824
2007-07-03T13:00:00Z,11.547836741375999,17.156341060796755
2007-07-03T14:00:00Z,11.547836741375999,8.05256349503374
2007-07-03T15:00:00Z,11.547836741375999,15.889597594082352
2007-07-03T16:00:00Z,11.547836741375999,17.281486396368674
2007-07-03T17:00:00Z,11.547836741375999,8.85589766303425
2007-07-03T18:00:00Z,11.547836741375999,8.517858232415993
2007-07-03T19:00:00Z,11.547836741375999,9.513993864743691
2007-07-03T20:00:00Z,11.547836741375999,13.633153020177176
2007-07-03T21:00:00Z,11.547836741375999,13.603812617794745
2007-07-03T22:00:00Z,11.547836741375999,11.323390188525575
2007-07-03T23:00:00Z,11.547836741375999,10.34184746292146
2007-07-04T00:00:00Z,7.046137672703999,10.239888389463848
2007-07-04T01:00:00Z,7.046137672703999,5.8784575587597905
2007-07-04T02:00:00Z,7.046137672703999,6.699313828046055
2007-07-04T03:00:00Z,7.046137672703999,3.8763640212433454
2007-07-04T04:00:00Z,7.046137672703999,10.270730097154722
2007-07-04T05:00:00Z,7.046137672703999,6.884325747504043
2007-07-04T06:00:00Z,7.046137672703999,8.024286796074879
2007-07-04T07:00:00Z,7.046137672703999,4.246655323410585
2007-07-04T08:00:00Z,7.046137672703999,5.3747206751583025
2007-07-04T09:00:00Z,7.046137672703999,4.638618646274563
2007-07-04T10:00:00Z,7.046137672703999,5.599888592896644
2007-07-04T11:00:00Z,7.046137672703999,6.305863373281562
2007-07-04T12:00:00Z,7.046137672703999,6.752502973655714
2007-07-04T13:00:00Z,7.046137672703999,9.998363613800459
2007-07-04T14:00:00Z,7.046137672703999,4.381925489429517
2007-07-04T15:00:00Z,7.046137672703999,5.151558428301431
2007-07-04T16:00:00Z,7.046137672703999,6.694808550732034
2007-07-04T17:00:00Z,7.046137672703999,6.296073846207062
2007-07-04T18:00:00Z,7.046137672703999,5.722975234610012
2007-07-04T19:00:00Z,7.046137672703999,8.050572370832432
2007-07-04T20:00:00Z,7.046137672703999,4.807977690404024
2007-07-04T21:00:00Z,7.046137672703999,4.420120502313691
2007-07-04T22:00:00Z,7.046137672703999,9.777711686211843
2007-07-04T23:00:00Z,7.046137672703999,4.889619945545822
2007-07-05T00:00:00Z,3.4007400573119995,1.8042197759638163
2007-07-05T01:00:00Z,3.4007400573119995,1.8729954761869594
2007-07-05T02:00:00Z,3.4007400573119995,4.683962726142156
2007-07-05T03:00:00Z,3.4007400573119995,2.3090915499655638
2007-07-05T04:00:00Z,3.4007400573119995,3.664052614057873
2007-07-05T05:00:00Z,3.4007400573119995,4.7638146023022205
2007-07-05T06:00:00Z,3.4007400573119995,3.7189444350938747
2007-07-05T07:00:00Z,3.4007400573119995,4.425378938807732
2007-07-05T08:00:00Z,3.4007400573119995,2.29067517900868
2007-07-05T09:00:00Z,3.4007400573119995,2.2316398758216387
2007-07-05T10:00:00Z,3.4007400573119995,1.7564834911278588
2007-07-05T11:00:00Z,3.4007400573119995,4.895290940962358
2007-07-05T12:00:00Z,3.4007400573119995,1.8450568093307163
2007-07-05T13:00:00Z,3.4007400573119995,4.60778050527373
2007-07-05T14:00:00Z,3.4007400573119995,4.172667259981488
2007-07-05T15:00:00Z,3.4007400573119995,2.923381973983738
2007-07-05T16:00:00Z,3.4007400573119995,4.953433195092381
2007-07-05T17:00:00Z,3.4007400573119995,2.789986372082994
2007-07-05T18:00:00Z,3.4007400573119995,3.6987611773813462
2007-07-05T19:00:00Z,3.4007400573119995,2.233252789038789
2007-07-05T20:00:00Z,3.4007400573119995,5.063621725470027
2007-07-05T21:00:00Z,3.4007400573119995,3.4400249866408794
2007-07-05T22:00:00Z,3.4007400573119995,4.311490701294223
2007-07-05T23:00:00Z,3.4007400573119995,3.293195344937536
2007-07-06T00:00:00Z,2.3976440691839995,1.223197735488137
2007-07-06T01:00:00Z,2.3976440691839995,3.329055776361745
2007-07-06T02:00:00Z,2.3976440691839995,2.0571508386883943
2007-07-06T03:00:00Z,2.3976440691839995,3.4169549252081364
2007-07-06T04:00:00Z,2.3976440691839995,3.1156904699136327
2007-07-06T05:00:00Z,2.3976440691839995,1.9960102249601634
2007-07-06T06:00:00Z,2.3976440691839995,3.011091877064751
2007-07-06T07:00:00Z,2.3976440691839995,2.325782490073682
2007-07-06T08:00:00Z,2.3976440691839995,1.5331152592156267
2007-07-06T09:00:00Z,2.3976440691839995,3.2747248585864432
2007-07-06T10:00:00Z,2.3976440691839995,1.3373158058680792
2007-07-06T11:00:00Z,2.3976440691839995,3.3380054331123583
2007-07-06T12:00:00Z,2.3976440691839995,2.217973057253805
2007-07-06T13:00:00Z,2.3976440691839995,2.796016510394889
2007-07-06T14:00:00Z,2.3976440691839995,2.693261548493505
2007-07-06T15:00:00Z,2.3976440691839995,1.974522532619386
2007-07-06T16:00:00Z,2.3976440691839995,3.0257938818958254
2007-07-06T17:00:00Z,2.3976440691839995,3.1182110695144227
2007-07-06T18:00:00Z,2.3976440691839995,1.8129309932536324
2007-07-06T19:00:00Z,2.3976440691839995,3.2347684417158304
2007-07-06T20:00:00Z,2.3976440691839995,2.5260321358859166
2007-07-06T21:00:00Z,2.3976440691839995,3.2102582043300747
2007-07-06T22:00:00Z,2.3976440691839995,3.3220542562578332
2007-07-06T23:00:00Z,2.3976440691839995,2.7016829854402014
2007-07-07T00:00:00Z,1.9572604646400003,1.3679207225444083
2007-07-07T01:00:00Z,1.9572604646400003,1.7825000996164175
2007-07-07T02:00:00Z,1.9572604646400003,1.4507102542160224
2007-07-07T03:00:00Z,1.9572604646400003,2.21589206380837
2007-07-07T04:00:00Z,1.9572604646400003,1.5733548376999111
2007-07-07T05:00:00Z,1.9572604646400003,1.4081392447218022
2007-07-07T06:00:00Z,1.9572604646400003,2.6673300964136697
2007-07-07T07:00:00Z,1.9572604646400003,2.708883822174827
2007-07-07T08:00:00Z,1.9572604646400003,2.4303522434156126
2007-07-07T09:00:00Z,1.9572604646400003,1.5086885229908662
2007-07-07T10:00:00Z,1.9572604646400003,2.8095854616853457
2007-07-07T11:00:00Z,1.9572604646400003,1.0948007280936083
2007-07-07T12:00:00Z,1.9572604646400003,1.0324641803572616
2007-07-07T13:00:00Z,1.9572604646400003,1.1169703696699251
2007-07-07T14:00:00Z,1.9572604646400003,2.9055189118084868
2007-07-07T15:00:00Z,1.9572604646400003,1.1909804977900813
2007-07-07T16:00:00Z,1.9572604646400003,2.2305085045466684
2007-07-07T17:00:00Z,1.9572604646400003,2.0787625662123737
2007-07-07T18:00:00Z,1.9572604646400003,2.503711672491426
2007-07-07T19:00:00Z,1.9572604646400003,2.533236773585508
2007-07-07T20:00:00Z,1.9572604646400003,2.4168857623377273
2007-07-07T21:00:00Z,1.9572604646400003,2.4045215973288245
2007-07-07T22:00:00Z,1.9572604646400003,2.8805597467947033
2007-07-07T23:00:00Z,1.9572604646400003,2.501509904036444
+24 −1
Original line number Diff line number Diff line
# Cumberland River Basin Reservoir Cascade

# ~~~~~~ Reservoirs ~~~~~~~~
#===========================
# Wolf Creek reservoir
Wolf_Creek:
  object_type: reservoir
  capacity: 100.0
  initial_storage: 50.0
  max_release: 10.0
  min_release: 3.0
  downstream_object: Cordell_Hull

# Cordell Hull reservoir
Cordell_Hull:
  object_type: reservoir
  capacity: 80.0
  initial_storage: 40.0
  max_release: 8
  min_release: 2.0
  downstream_object: Old_Hickory

# Center Hill reservoir
Center_Hill:
  object_type: reservoir
  capacity: 50
  initial_storage: 30
  max_release: 8
  min_release: 2.0
  downstream_object: Old_Hickory

# Old Hickory reservoir
Old_Hickory:
  object_type: reservoir
  capacity: 200.0
  initial_storage: 40.0
  max_release: 8
  min_release: 2.0
  
 No newline at end of file
  downstream_object: NA
 No newline at end of file
+4 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ from pathlib import Path

@dataclass
class ReservoirData:
    object_type: str
    capacity: float
    initial_storage: float
    max_release: float
@@ -35,6 +36,7 @@ class ReservoirData:
    catchment_inflow: list[float]
    target_release: list[float]
    simulation_order: int
    downstream_object: str

@dataclass
class CascadeData:
@@ -48,7 +50,8 @@ with open('reservoirs/reservoir_config.yaml', 'r') as file:
simulation_orders = {
    "Wolf_Creek": 1,
    "Cordell_Hull": 2,
    "Old_Hickory": 3
    "Center_Hill": 3,
    "Old_Hickory": 4
}

cascade_data = CascadeData(reservoirs={
+19 −15
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ use std::collections::HashMap;

#[derive(FromPyObject)]
struct ReservoirData {
    object_type: String,
    capacity: f64,
    initial_storage: f64,
    max_release: f64,
@@ -12,6 +13,7 @@ struct ReservoirData {
    catchment_inflow: Vec<f64>,
    target_release: Vec<f64>,
    simulation_order: i32,
    downstream_object: String,
}

#[derive(FromPyObject)]
@@ -99,26 +101,28 @@ fn simulate_cascade(

    // simulation loop
    for t in 0..n {
        for (i, (name, reservoir_data)) in ordered_reservoirs.iter().enumerate() {
            
            // Calculate inflow: use input inflow for first reservoir,
            // otherwise use outflow from previous reservoir
            let current_inflow = if i == 0 {
                reservoir_data.catchment_inflow[t]
            } else {
                let prev_name = &ordered_reservoirs[i-1].0;
                let prev_results = &results[*prev_name];
                reservoir_data.catchment_inflow[t] + prev_results.release[t] + prev_results.spill[t]
            };
        for (name, reservoir_data) in &ordered_reservoirs {

            // Get previous storage for this reservoir
            let current_results = results.get_mut(*name).unwrap();  // Changed to use ReservoirResults
            let upstream_inflow = ordered_reservoirs.iter()
            .filter(|(upstream_name, upstream_data)| 
                upstream_data.downstream_object == **name)
            .map(|(upstream_name, _)| {
                let upstream_results = &results[*upstream_name];
                upstream_results.release[t] + upstream_results.spill[t]
            })
            .sum::<f64>();

            // Combine catchment inflow wiht upstream inflow
            let current_inflow = reservoir_data.catchment_inflow[t] + upstream_inflow;
            let current_results = results.get_mut(*name).unwrap();
            let previous_storage = if t == 0 { 
                reservoir_data.initial_storage 
            } else { 
                current_results.storage[t-1] 
            };



            // Simulate this timestep
            let state = simulate_timestep(
                reservoir_data,