# RiverWare_Ruleset 6.1.5 Patch # Created 18:33 April 10, 2012 # RULESET AGENDA_ORDER DESCENDING; DESCRIPTION "Baseline CRSS ruleset
$Id: CRSS.rls,v 1.18 2009/02/11 19:04:11 jprairie Exp $"; PRECISION 2; BEGIN POLICY_GROUP "Computation Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Compute Compact Annual Volume"; DESCRIPTION "This rule fires once a year and computes both Powell's water year release and the Compact Point volume. The Compact Point volume is a sum of the gains from the Paria River and Powell's release over the water year."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 December 31, Current Year"; BEGIN $ "PowellOperation.Compact Point Volume" [] := "SumFlowsToVolume"( $ "CoRivPowellToVirgin:PariaGains.Outflow", @"24:00:00 October 31, Previous Year", @"24:00:00 September 30, Current Year" ); $ "PowellOperation.PowellWYRelease" [] := "SumFlowsToVolume"( $ "Powell.Outflow", @"24:00:00 October 31, Previous Year", @"24:00:00 September 30, Current Year" ); END; RULE "Compute Compact 10 Year Volume"; DESCRIPTION "This rule fires once a year and computes both Powell's water year release and the Compact Point volume over a ten-year period (the current year and the previous 9 years). This rule uses the single-year values for both Powell's water year release and the Compact Point volume set in the previous rule."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 December 31, Current Year"; BEGIN $ "PowellOperation.10 Year Compact Volume" [] := "SumSlot"( $ "PowellOperation.Compact Point Volume", @"24:00:00 December 31, Current Year - 9 Year", @"24:00:00 December 31, Current Year" ); $ "PowellOperation.Powell10YearWYRelease" [] := "SumSlot"( $ "PowellOperation.PowellWYRelease", @"24:00:00 December 31, Current Year - 9 Year", @"24:00:00 December 31, Current Year" ); END; END; POLICY_GROUP "Fontenelle Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Fontenelle Rule Curve"; DESCRIPTION "This rule fires monthly and sets the storage for Fontenelle. It computes the storage based on the whichever release demand is greater - the release to meet downstream demands or the release to meet the storage rule curve."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN "Fontenelle.Storage" []; BEGIN "Fontenelle.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Fontenelle", "Max"( "ComputeOutflowAtRuleCurveStorage"( % "Fontenelle" ), "ComputeDemandsBelow"( % "Fontenelle" ) ) ); END; END; POLICY_GROUP "Starvation Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Starvation Rule Curve"; DESCRIPTION "This rule fires monthly and sets the storage for Starvation. Starvation is a virtual reservoir and represents a composite of 8 small reservoirs that are part of the Central Utah Project, located primarily on the Duschene. It computes the storage based on the whichever release demand is greater - the release to meet downstream demands or the release to meet the storage rule curve."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN "Starvation.Storage" []; BEGIN "Starvation.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Starvation", "Max"( "ComputeOutflowAtRuleCurveStorage"( % "Starvation" ), "ComputeDemandsBelow"( % "Starvation" ) ) ); END; END; POLICY_GROUP "Flaming Gorge Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Flaming Gorge Rule Curve"; DESCRIPTION "This rule fires monthly and sets the storage for Flaming Gorge. It computes the storage based on the whichever release demand is greater - the release to meet downstream demands or the release to meet the target space for the month. A target space is used for Flaming Gorge (and also used for Navajo and Blue Mesa) rather than the rule curve storage (used for the other Upper Basin reservoirs above Powell) and is modified during the simulation to simulate operations based on imperfect inflow forecasts."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "FlamingGorge.Storage" []; BEGIN "FlamingGorge.Storage" [] := "ComputeStorageAtGivenOutflow"( % "FlamingGorge", "Max"( "ComputeTargetSpaceOutflow"( % "FlamingGorge" ), "ComputeDemandsBelow"( % "FlamingGorge" ) ) ); END; END; POLICY_GROUP "Taylor Park and Aspinall Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Compute Demands Below Crystal"; DESCRIPTION "This rule fires monthly and sets a data object slot with the total monthly demand below the Crystal reservoir. The value is then used to compute the monthly storage for Morrow Point in the rule Fulfill Crystal Demand. It"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "ComputedDemandsBelow.Crystal" []; BEGIN $ "ComputedDemandsBelow.Crystal" [] := "ComputeDemandsBelow"( % "Crystal" ); END; RULE "Fulfilll Crystal Demand"; DESCRIPTION "This rule fires monthly if the Crystal release required to meet the rule curve is not enough to meet the downstream demands. This rule re-sets the storage for Morrow Point, Taylor Park and Blue Mesa that was set in the lower priority rules. "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "Aspinall Operations.BlueMesaforDemandsFlag" [] AND ( $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] > 1.00000000 "acre-feet/month" ) COMMENTED_BY "Execute if demands are greater than outflow required to meet rule curve."; BEGIN $ "MorrowPoint.Storage" [] := IF ( "ComputeStorageAtGivenOutflow"( % "BlueMesa", $ "BlueMesa.Outflow" [] + ( $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [] ) == "InactiveCapacity"( % "BlueMesa" ) AND "ComputeStorageAtGivenOutflow"( % "TaylorPark", ( $ "TaylorPark.Outflow" [] + $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] - "VolumeToFlow"( ( $ "BlueMesa.Storage" [] ) - "InactiveCapacity"( % "BlueMesa" ), @"t" ) ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [] + $ "TaylorAboveBlueMesa:GainsAboveBlueMesa.Local Inflow Adjust" [] ) == "InactiveCapacity"( % "TaylorPark" ) ) THEN "ComputeStorageAtGivenInOut"( % "MorrowPoint", ( $ "MorrowPoint.Outflow" [] + $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [], $ "MorrowPoint.Inflow" [] + "VolumeToFlow"( ( $ "BlueMesa.Storage" [] ) - "InactiveCapacity"( % "BlueMesa" ), @"t" ) + "VolumeToFlow"( ( $ "TaylorPark.Storage" [] ) - "InactiveCapacity"( % "TaylorPark" ), @"t" ) ) ENDIF; $ "TaylorPark.Storage" [] := IF ( "ComputeStorageAtGivenOutflow"( % "BlueMesa", $ "BlueMesa.Outflow" [] + ( $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [] ) == "InactiveCapacity"( % "BlueMesa" ) ) THEN "Min"( "LiveCapacity"( % "TaylorPark" ), "ComputeStorageAtGivenOutflow"( % "TaylorPark", ( $ "TaylorPark.Outflow" [] + $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] - "VolumeToFlow"( ( $ "BlueMesa.Storage" [] ) - "InactiveCapacity"( % "BlueMesa" ), @"t" ) ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [] + $ "TaylorAboveBlueMesa:GainsAboveBlueMesa.Local Inflow Adjust" [] ) ) ENDIF; $ "BlueMesa.Storage" [] := "ComputeStorageAtGivenOutflow"( % "BlueMesa", $ "BlueMesa.Outflow" [] + ( $ "ComputedDemandsBelow.Crystal" [] - $ "Crystal.Outflow" [] ) + $ "GunnisonRiverAboveCrystal:GainsAboveCrystal.Local Inflow Adjust" [] ); $ "Aspinall Operations.BlueMesaforDemandsFlag" [] := 1.00000000; END; RULE "Taylor Park Rule Curve"; DESCRIPTION "This rule fires monthly and sets the storage for Taylor Park. It computes the storage based on the whichever release demand is greater - the release to meet downstream demands (between Taylor Park and Blue Mesa) or the release to meet the storage rule curve.
"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN "TaylorPark.Storage" []; BEGIN "TaylorPark.Storage" [] := "ComputeStorageAtGivenOutflow"( % "TaylorPark", "Max"( "ComputeOutflowAtRuleCurveStorage"( % "TaylorPark" ), "ComputeDemandsBelow"( % "TaylorPark" ) ) ); END; RULE "Blue Mesa Rule Curve"; DESCRIPTION "This rule fires monthly and sets the storage for Blue Mesa. It computes the storage based on the release to meet the target space for the month. A target space is used for Blue Mesa, (and also used for Navajo and Flaming Gorge) rather than the rule curve storage (used for the other Upper Basin reservoirs above Powell) and is modified during the simulation to simulate operations based on imperfect inflow forecasts.

An important thing to note here is that in the CRSS kludge in the ComputeTargetSpaceOutflow->TargetSpace->MaxAllowableStorage->CurrentInflowAbove function brings in the inflows and local inflows, therefore if they are negative, they will also be predicting negative flows as well. Likely this is a bad thing."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "BlueMesa.Storage" []; BEGIN $ "BlueMesa.Storage" [] := "ComputeStorageAtGivenOutflow"( % "BlueMesa", "ComputeTargetSpaceOutflow"( % "BlueMesa" ) ); END; RULE "Morrow Point Rule Curve"; DESCRIPTION "This rule fires monthly and sets the Morrow Point storage (only if Blue Mesa is already set). If the outflow required to get to the live capacity is greater than the maximum controlled release, then the storage is set assuming the maximum release. If the outflow required to get to the live capacity is less than the minimum release (and the storage resulting from the minimum release isn't less than inactive capacity), then the storage is set assuming the minimum release. If neither of these two extremes apply, then the storage is set to the rule curve storage, which is live capacity in this case.

In other words: make the reservoir full if you can within the physical constraints of release and capacity.


"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN "MorrowPoint.Storage" [] AND NOT IsNaN $ "BlueMesa.Storage" []; BEGIN "MorrowPoint.Storage" [] := "ComputeStorageAtGivenOutflow"( % "MorrowPoint", "ComputeOutflowAtGivenStorage"( % "MorrowPoint", "LiveCapacity"( % "MorrowPoint" ) ) ); END; RULE "Crystal Rule Curve"; DESCRIPTION "This rule fires monthly and sets the Crystal storage (only after Morrow Point and hence Blue Mesa are already set). If the outflow required to get to the live capacity is greater than the maximum controlled release, then the storage is set assuming the maximum release. If the outflow required to get to the live capacity is less than the minimum release (and the storage resulting from the minimum release isn't less than inactive capacity), then the storage is set assuming the minimum release. If neither of these two extremes apply, then the storage is set to the rule curve storage, which is live capacity in this case. This rule is similiar as the rule Morrow Point Rule Curve."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT NOT IsNaN "MorrowPoint.Storage" [] AND IsNaN "Crystal.Storage" []; BEGIN $ "Crystal.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Crystal", "ComputeOutflowAtGivenStorage"( % "Crystal", "LiveCapacity"( % "Crystal" ) ) ); END; END; POLICY_GROUP "Navajo Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Set NIIP Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "NavajoIndianIrrigationProjectNIIP.Total Diversion Requested" [] OR IsNaN $ "NavajoIndianIrrigationProjectNIIP.Total Depletion Requested" []; BEGIN $ "NavajoIndianIrrigationProjectNIIP.Total Diversion Requested" [] := IF ( "ComputeStorageAtZeroRelease"( % "Navajo" ) < "NIIPMinDiversionStorage"( ) ) THEN "ShortNIIPDiversion"( ) ELSE $ "NIIPSchedule.Diversion Schedule" [] ENDIF; $ "NavajoIndianIrrigationProjectNIIP.Total Depletion Requested" [] := IF ( "ComputeStorageAtZeroRelease"( % "Navajo" ) < "NIIPMinDiversionStorage"( ) ) THEN "ShortNIIPDiversion"( ) * "NIIPDiversionRatio"( ) ELSE $ "NIIPSchedule.Depletion Schedule" [] ENDIF; END; RULE "Minimum Navajo Release"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT NOT IsNaN $ "Navajo.Storage" []; BEGIN $ "Navajo.Storage" [] := IF ( $ "Navajo.Outflow" [] < 10.00000000 "acre-feet/month" ) THEN "ComputeMinNavajoStorage"( ) ENDIF; END; RULE "Navajo Rule Curve"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "Navajo.Storage" []; BEGIN $ "Navajo.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Navajo", "Max"( "ComputeTargetSpaceOutflow"( % "Navajo" ), "ComputeDemandsBelow"( % "Navajo" ) ) ); END; END; POLICY_GROUP "Powell Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Compute 602a Storage"; DESCRIPTION "This rule fires once a year and sets the 602a storage. Although this solves for each year in the run duration, the value is only used while the Guidelines are in effect, through 2026."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND IsNaN $ "EqualizationData.value602a" [@"24:00:00 December 31, Current Year"]; BEGIN $ "EqualizationData.value602a" [@"24:00:00 December 31, Current Year"] := "602aStorage"( ); END; RULE "Compute 70R Assurance Level Surplus Volume"; DESCRIPTION "This rule fires at the beginning of the year and sets the 70R surplus volume. This is the estimated end-of-year volume of water in excess of the system space requirement assuming a 70th percentile runoff, a 7.5 maf Lower Basin delivery, the Upper Basin scheduled use and the current Powell and Mead volumes. If this volume is greater than 0, a 70R or Quantified Surplus is declared in the Surplus Rules: 70R Assurance Level Surplus and 7 State Plan Level 1. "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND IsNaN $ "Surplus.SurplusRelease" []; BEGIN $ "Surplus.SurplusRelease" [] := ( ( $ "Powell.Storage" [@"t - 1"] + $ "Mead.Storage" [@"t - 1"] - "SurplusMaxStorage"( ) ) - "SumPreviousYearICSCredits"( ) COMMENTED_BY "Beginning total ICS balance is not included in 70R determination." ) * ( 1.00000000 + ( $ "Mead.Bank Storage Coefficient" [0.00000000, 0.00000000] + $ "Powell.Bank Storage Coefficient" [0.00000000, 0.00000000] ) / 2.00000000 ) + "ComputeInflowAtProbability"( ) - "SumUBDemands"( ) - "SumLBDemands"( ); END; RULE "Powell Forecast Error"; DESCRIPTION "Brad Vickers, Wave Engineering Inc.
January, 1999

This rule checks to see if the PowellForecastError slot on the MeadFloodControlData object has been set, if it has not and the month is not June (because June has some special limits) then
the forecast error for Powell is computed with the ComputeForecastError function. The first part of the IF statement in the rule limits June's computed forecast error to one half of
May's forecast error. This check was performed in the originall CRSS. Ideally I believe there should be limits on every month to ensure that the forecast error is within the range of historical
forecast error. This becomes a problem with the random component of how the forecast error is derived. See the comments on the ComputeForecastError function for further information on
how the forecast error is computed.

NOTE the print statement in this rule. this calls the resetRanDev function which rewinds the file of random numbers to the hydrology start date that is input
by the user on the MeadFloodControlData.HydrologyStartYear table slot. This function is only called at the first of the model run. It is used with a print statement because it has to be in a rule
rather than a function and there are no slots set with it.
"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "MeadFloodControlData.PowellForecastError" []; BEGIN $ "MeadFloodControlData.PowellForecastError" [] := "ComputePowellForecastError"( ); $ "PowellForecastData.forecastError" [] := "ComputePowellForecastError"( ) * 1000000.00000000 "acre-feet"; $ "PowellForecastData.random" [] := "SetRandomDeviation"( ); END; RULE "Powell Runoff Forecast"; DESCRIPTION "This rule was added to compute and store the forecasts for inflows into Lake Powell. These computations
are done for Mead's inflow forecast, so we should clean that up eventually.

It assumes that the forecast error has been computed previously by the Powell Forecast Error rule
and stored on the data/slot MeadFloodControlData.PowellForecastError"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 July Max DayOfMonth, Current Year" AND @"t" >= @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN $ "PowellForecastData.Natural Inflow with Error" [] := $ "Qsum.Powell" [] - $ "MeadFloodControlData.PowellForecastError" [] * 1000000.00000000 "acre-feet"; $ "PowellForecastData.Unreg Inflow with Error" [] := $ "Qsum.Powell" [] - $ "MeadFloodControlData.PowellForecastError" [] * 1000000.00000000 "acre-feet" - "UBDepletionsRange"( @"t", @"24:00:00 July Max DayOfMonth, Current Year" ); $ "PowellForecastData.Reg Inflow with Error" [] := $ "Qsum.Powell" [] - $ "MeadFloodControlData.PowellForecastError" [] * 1000000.00000000 "acre-feet" - "UBDepletionsRange"( @"t", @"24:00:00 July Max DayOfMonth, Current Year" ) - "UBEffectiveStorage"( ); END; RULE "EOWYStorageForecasts"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "EqualizationData.ForecastEOWYSPowell" []; BEGIN $ "EqualizationData.ForecastEOWYSPowell" [] := IF ( @"t" >= @"October" ) THEN 0.00000000 "acre-ft" ELSE "EOWYStorage"( % "Powell", "ForecastPowellRelease"( ), "ForecastMeadRelease"( ) ) ENDIF; $ "EqualizationData.ForecastEOWYSMead" [] := IF ( @"t" >= @"October" ) THEN 0.00000000 "acre-ft" ELSE "EOWYStorage"( % "Mead", "ForecastPowellRelease"( ), "ForecastMeadRelease"( ) ) ENDIF; END; RULE "Estimate Upper Basin Storage"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "EqualizationData.AvailableWater" [] AND @"t" <= @"24:00:00 September 30, Current Year"; BEGIN $ "EqualizationData.AvailableWater" [] := "SumUpperBasinStorage"( ); END; RULE "Sum Powell Inflow Spring"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 July 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"24:00:00 January 31, Current Year" TO @"24:00:00 July 31, Current Year") DO $ "PowellForecastData.Powell Inflow Volume" [date] := "SumFlowsToVolume"( $ "Powell.Inflow", date, @"24:00:00 July 31, Current Year" ); ENDFOREACH; END; RULE "Sum Powell Inflow Fall"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 December 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"24:00:00 August 31, Current Year" TO @"24:00:00 December 31, Current Year") DO $ "PowellForecastData.Powell Inflow Volume" [date] := "SumFlowsToVolume"( $ "Powell.Inflow", date, @"24:00:00 December 31, Current Year" ); ENDFOREACH; END; RULE "Powell Spike Flow Rule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 July 31, Current Year" AND IsNaN $ "Powell Spike Flow Data.Spike Flow Flag" [] AND NOT IsNaN "Powell.Storage" [] AND NOT "SpikeAlreadyMade"( ); BEGIN $ "Powell.Bypass" [] := IF ( "CheckSpikeFlowCriteria"( ) ) THEN "VolumeToFlow"( $ "Powell Spike Flow Data.Additional Bypass Volume" [0.00000000, 0.00000000], @"t" ) ENDIF; $ "Powell.Storage" [] := IF ( "CheckSpikeFlowCriteria"( ) ) THEN IF ( $ "Powell.Spill" [] > 0.00000000 "acre-feet/month" ) THEN $ "Powell.Storage" [] ELSE "PowellComputeStorageAtGivenOutflow"( "PowellMinSpikeFlowOutflow"( ) + "VolumeToFlow"( $ "Powell Spike Flow Data.Additional Bypass Volume" [0.00000000, 0.00000000], @"t" ) ) ENDIF ENDIF; $ "Powell Spike Flow Data.Spike Flow Flag" [] := IF ( "CheckSpikeFlowCriteria"( ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Equalization Post Guidelines"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 September 30, Current Year" AND @"t" > @"24:00:00 December 31, 2026" AND IsNaN $ "EqualizationData.EqualFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN "Powell.Storage" [] := IF ( "WaterAvailableInUpperBasin"( ) >= "602aStorageValue"( ) ) THEN IF ( $ "EqualizationData.ForecastEOWYSPowell" [] >= $ "EqualizationData.ForecastEOWYSMead" [] ) THEN "PowellComputeStorageAtGivenOutflow"( "ComputePowellRelease"( "CheckEqualizationRelease602a"( "ConvertPowellRelease"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ) ) ) ) ENDIF ENDIF; $ "EqualizationData.EqualFlag" [] := IF ( "WaterAvailableInUpperBasin"( ) >= "602aStorageValue"( ) AND $ "EqualizationData.ForecastEOWYSPowell" [] >= $ "EqualizationData.ForecastEOWYSMead" [] ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Equalization Tier"; DESCRIPTION "This rule fires monthly January through September and computes the Equalization (EQ) release from Powell, given that the conditions for EQ are met. Note that Powell's previous EOCY storage is compared to the EQ Line. This has the effect of not allowing Powell to bounce in and out of EQ. The new EQ conditions in the Guidelines (release to keep Mead above 1105 so as Powell doesn't go more than 20' below the EQ Line) are performed in the function CheckEqualizationRelease_Mead1105. "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 September 30, Current Year" AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "EqualizationData.EqualBasinStatesFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN "Powell.Storage" [] := IF ( "StartYearInEqualization"( ) COMMENTED_BY "By comparing to Powell's actual storage at beginning of year, EQ is an annual decision" ) THEN "PowellComputeStorageAtGivenOutflow"( "ComputePowellRelease"( "CheckEqualizationRelease_Mead1105"( "ConvertPowellRelease"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ) ) ) ) ENDIF; $ "EqualizationData.EqualBasinStatesFlag" [] := IF ( "StartYearInEqualization"( ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Upper Elevation Balancing Tier Jan thru March"; DESCRIPTION "This rule fires in January through March and determines if Powell is in the Upper Elevation Balancing Tier (based on previous EOCY storage). If Powell is in this tier and Mead (again, previous EOCY storage) is below the minimum balancing elevation of 1075, Powell makes balancing releases within the min and max of 700 and 900 kaf. If Mead is above 1075, Powell releases 823 maf set in the rule Meet Powell Min Objective Release, which is lower priority and required to fire before this rule."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 March 31, Current Year" AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "Coordinated Operation.UpperLevelBalancingFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN $ "Powell.Storage" [] := IF ( "InUpperElevationBalancingTier"( ) ) THEN IF ( $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "Use actual Jan 1 elevation" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) ) THEN "PowellComputeStorageAtGivenOutflow"( "ComputePowellReleaseUpperBalancing"( "ConvertPowellReleaseBalancing"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ), "700" COMMENTED_BY "min release", "900" COMMENTED_BY "max release" ) ) COMMENTED_BY "Release for Upper Level Balancing if 1) Powell is in the correct elevation tier 2) EQ conditions are not met 3) EQ has not yet trumped 4) Mead is less than 1075 trigger" ENDIF ENDIF; $ "Coordinated Operation.UpperLevelBalancingFlag" [] := IF ( "InUpperElevationBalancingTier"( ) AND $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "Used actual Jan 1 elevation" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Upper Elevation Balancing Tier April thru Sept"; DESCRIPTION "This rule fires in April through September and makes any required adjustments to Powell's release if Powell began the year in the Upper Elevation Balancing Tier. The decision to switch to the EQ Tier or to increase the release for balancing is based on the April EOWY forecasts. Meaning, the decision made in April stays for the rest of the water year."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT ( @"t" <= @"24:00:00 September 30, Current Year" AND @"t" >= @"24:00:00 April 30, Current Year" ) AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "Coordinated Operation.UpperLevelBalancingFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN $ "Powell.Storage" [] := IF ( "InUpperElevationBalancingTier"( ) ) THEN IF ( ( NOT "EqualizationConditionsMet"( ) AND IsNaN $ "Coordinated Operation.EQTrumpUpperLevelBalancingFlag" [@"t - 1"] ) COMMENTED_BY "If EQ Trumps in April, release for EQ for the rest of the water year - go to ELSE" ) THEN IF ( $ "EqualizationData.ForecastEOWYSMead" [@"24:00:00 April 30, Current Year"] COMMENTED_BY "If EQ doesn't trump, check April EOWY forecasts for Mead & Powell to see if switch from 823 kaf to Balancing" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) AND $ "EqualizationData.ForecastEOWYSPowell" [@"24:00:00 April 30, Current Year"] > "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] ) OR $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "Use actual Jan 1 elevation" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) ) THEN IF ( $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "Use actual Jan 1 elevation" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) ) THEN "PowellComputeStorageAtGivenOutflow"( "ComputePowellReleaseUpperBalancing"( "ConvertPowellReleaseBalancing"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ), "700" COMMENTED_BY "min release", "900" COMMENTED_BY "max release" ) ) COMMENTED_BY "If Mead began the year less than 1075, release with 700 kaf minimum" ELSE "PowellComputeStorageAtGivenOutflow"( "ComputePowellReleaseUpperBalancing"( "ConvertPowellReleaseBalancing"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ), "823" COMMENTED_BY "min release", "900" COMMENTED_BY "max release" ) ) COMMENTED_BY "If Mead is above 1075 at beginning of year but below at April EOWY forecast, release with 823 kaf minimum." ENDIF COMMENTED_BY "Release for Balancing if 1) Powell is in the correct elevation tier 2) EQ conditions are not met 3) EQ has not yet trumped 4) Mead is less than 1075 trigger" ENDIF ELSE "PowellComputeStorageAtGivenOutflow"( "ComputePowellRelease"( "CheckEqualizationRelease_Mead1105"( "ConvertPowellRelease"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ) ) COMMENTED_BY "Constrain EQ Release to bring Mead to 1105 or Powell 20 ft below the EQ Line." ) ) COMMENTED_BY "If Mead below 1105 then EQ release must 1) bring Mead to 1105 2) take Powell 20 ft below the EQ Line or 3) equalize. Whatever occurs first. " COMMENTED_BY "EQ trumps Upper Elevation Balancing if EQ conditions are met OR EQ trumped last month" ENDIF ENDIF; $ "Coordinated Operation.UpperLevelBalancingFlag" [] := IF ( "InUpperElevationBalancingTier"( ) AND NOT "EqualizationConditionsMet"( ) AND IsNaN $ "Coordinated Operation.EQTrumpUpperLevelBalancingFlag" [@"t - 1"] AND ( $ "EqualizationData.ForecastEOWYSMead" [@"24:00:00 April 30, Current Year"] COMMENTED_BY "Use April EOWY forecast for Mead & Powell" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) AND $ "EqualizationData.ForecastEOWYSPowell" [@"24:00:00 April 30, Current Year"] > "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] ) OR $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "Use actual Jan 1 elevation" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_MeadMinBalancingElevation" [] ) ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; $ "Coordinated Operation.EQTrumpUpperLevelBalancingFlag" [] := IF ( "InUpperElevationBalancingTier"( ) AND ( "EqualizationConditionsMet"( ) OR NOT IsNaN $ "Coordinated Operation.EQTrumpUpperLevelBalancingFlag" [@"t - 1"] ) ) THEN 1.00000000 ENDIF; $ "Coordinated Operation.EQTrumpUpperLevelBalancing1105GovFlag" [] := IF ( "InUpperElevationBalancingTier"( ) AND ( "EqualizationConditionsMet"( ) OR NOT IsNaN $ "Coordinated Operation.EQTrumpUpperLevelBalancingFlag" [@"t - 1"] ) AND $ "EqualizationData.ForecastEOWYSMead" [@"t"] COMMENTED_BY "Use moving EOWY forecast here for Mead" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.MeadProtectionElevation" [] ) ) THEN 1.00000000 ENDIF; END; RULE "Mid Elevation Release Tier"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "Coordinated Operation.ReducedReleaseFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN $ "Powell.Storage" [] := IF ( @"t" <= @"September" ) THEN IF ( "InMidElevationReleaseTier"( ) AND $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] >= "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_Mead823Trigger" [] ) ) THEN "PowellComputeStorageAtGivenOutflow"( "PowellReducedRelforCurrentMonth"( "748" ) ) ENDIF COMMENTED_BY "Compare Powell and Mead previous EOCYS instead of forecasted EOWYS" ELSE IF ( $ "Powell.Pool Elevation" [@"24:00:00 September 30, Current Year"] < $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] AND $ "Powell.Pool Elevation" [@"24:00:00 September 30, Current Year"] >= $ "Coordinated Operation.Hybrid_PowellLowerTierElevation" [] AND $ "Mead.Pool Elevation" [@"24:00:00 September 30, Current Year"] >= $ "Coordinated Operation.Hybrid_Mead823Trigger" [] ) THEN "PowellComputeStorageAtGivenOutflow"( "PowellReducedRelforCurrentMonth"( "748" ) ) ENDIF ENDIF; $ "Coordinated Operation.ReducedReleaseFlag" [] := IF ( @"t" <= @"September" ) THEN IF ( "InMidElevationReleaseTier"( ) AND $ "Mead.Storage" [@"24:00:00 December 31, Previous Year"] >= "ElevationToStorage"( % "Mead", $ "Coordinated Operation.Hybrid_Mead823Trigger" [] ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF ELSE IF ( $ "Powell.Pool Elevation" [@"24:00:00 September 30, Current Year"] < $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] AND $ "Powell.Pool Elevation" [@"24:00:00 September 30, Current Year"] >= $ "Coordinated Operation.Hybrid_PowellLowerTierElevation" [] AND $ "Mead.Pool Elevation" [@"24:00:00 September 30, Current Year"] >= $ "Coordinated Operation.Hybrid_Mead823Trigger" [] ) THEN 1.00000000 ELSE 0.00000000 ENDIF ENDIF; END; RULE "Check Bypass Capacity"; DESCRIPTION "If the reservoir is below the power pool, check if the set outflow is greater than the capacity of the bypass tubes.
If it is, reset it to the bypass capacity.

If the reservoir is above the power pool, then the power plant capacity is in play. This is roughly 25,000 cfs, or the maximum ROD release anyway, and the limitations of the bypass tubes do not matter."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT NOT IsNaN $ "EqualizationData.MinObjRelFlag" []; BEGIN $ "Powell.Storage" [] := IF ( $ "Powell.Storage" [] < "InactiveCapacity"( % "Powell" ) AND $ "Powell.Outflow" [] > "BypassCapacity"( $ "Powell.Pool Elevation" [] ) ) THEN "PowellComputeStorageAtGivenOutflow"( "IterateBypassCapacity"( $ "Powell.Pool Elevation" [] ) ) ENDIF; $ "EqualizationData.BypassCapFlag" [] := IF ( IsNaN $ "EqualizationData.BypassCapFlag" [] ) THEN IF ( $ "Powell.Storage" [] < "InactiveCapacity"( % "Powell" ) AND $ "Powell.Outflow" [] > "BypassCapacity"( $ "Powell.Pool Elevation" [] ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF ENDIF; END; RULE "Lower Elevation Balancing Tier"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" <= @"24:00:00 September 30, Current Year" AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "Coordinated Operation.LowerLevelBalancingFlag" [] AND ( NOT IsNaN "Powell.Storage" [] AND NOT IsNaN $ "EqualizationData.MinObjRelFlag" [] ); BEGIN $ "Powell.Storage" [] := IF ( "InLowerElevationBalancingTier"( ) ) THEN "PowellComputeStorageAtGivenOutflow"( "ComputePowellReleaseLowerBalancing"( "ConvertPowellReleaseBalancing"( "ComputeEqualizationReleaseList"( $ "EqualizationData.ForecastEOWYSPowell" [], $ "EqualizationData.ForecastEOWYSMead" [] ) ) COMMENTED_BY "No additional check required because balancing releases made until dead pool", "700" COMMENTED_BY "min release", "950" COMMENTED_BY "max release" ) ) ENDIF COMMENTED_BY "Compare Powell and Mead previous EOCYS instead of forecasted EOWYS"; $ "Coordinated Operation.LowerLevelBalancingFlag" [] := IF ( "InLowerElevationBalancingTier"( ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Powell Limit Outflow Rule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" >= @"24:00:00 July Max DayOfMonth, Current Year"; BEGIN $ "Powell.Storage" [] := IF ( "PowellComputeStorageAtGivenOutflow"( 25000.00000000 "cfs" ) < 23822000.00000000 "acre-feet" AND $ "Powell.Outflow" [] > 25000.00000000 "cfs" ) THEN "PowellComputeStorageAtGivenOutflow"( 25000.00000000 "cfs" ) ENDIF; END; RULE "Powell Smooth July Operation Rule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 July Max DayOfMonth, Current Year"; BEGIN $ "Powell.Storage" [] := IF ( $ "Powell.Storage" [] > 23000000.00000000 "acre-feet" AND $ "Powell.Outflow" [] < 1000000.00000000 "acre-feet/month" ) THEN "PowellComputeStorageAtGivenOutflow"( 1000000.00000000 "acre-feet/month" ) ENDIF; END; RULE "Meet Powell Min Objective Release"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "EqualizationData.MinObjRelFlag" [] AND NOT IsNaN $ "Powell.Outflow" []; BEGIN "Powell.Storage" [] := IF ( $ "Powell.Outflow" [] < "PowellMinObjRelforCurrentMonth"( ) ) THEN "PowellComputeStorageAtGivenOutflow"( "PowellMinObjRelforCurrentMonth"( ) ) ENDIF; $ "EqualizationData.MinObjRelFlag" [] := IF ( $ "Powell.Outflow" [] < "PowellMinObjRelforCurrentMonth"( ) ) THEN 1.00000000 ELSE 0.00000000 ENDIF; END; RULE "Powell Operations Rule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "Powell.Storage" [] := IF ( @"t" <= @"24:00:00 July Max DayOfMonth, Current Year" AND @"t" >= @"24:00:00 January Max DayOfMonth, Current Year" ) THEN "PowellRunoffSeasonStorage"( ) ELSE "PowellFallSeasonStorage"( ) ENDIF; END; END; POLICY_GROUP "Mead Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Set Mead Outflow During Extreme Low Stochastic"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT "ComputeMeadStoragePlusInflowBeforeRelease"( ) <= "FlowToVolume"( "CurrentDemandBelowMead"( ), @"t" ); BEGIN PRINT $ "Mead.Inflow" []; PRINT $ "SNWPDiversion.Total Depletion Requested" []; PRINT $ "Mead.Storage" [@"t - 1"]; PRINT "CurrentDemandBelowMead"( ); $ "Mead.Outflow" [] := "Min"( $ "Mead.Inflow" [], "ComputeOutflowAtGivenStorage_Critical"( % "Mead", 0.00000000 "acre-feet" ) - 1.00000000 "acre-feet/month" ); END; RULE "Mead Flood Control"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "Mead.Outflow" [] := IF ( @"t" <= @"24:00:00 July 31, Current Year" AND $ "Mead.Outflow" [] < "RunoffSeasonRelease"( ) ) THEN "ComputeMeadSpringReleaseConstrained"( ) ELSE IF ( @"t" > @"24:00:00 July 31, Current Year" AND $ "Mead.Outflow" [] < "ComputeOutflowAtGivenStorage"( % "Mead", "ComputeTargetStorage"( ) ) ) THEN "ComputeMeadFallReleaseConstrained"( ) ENDIF ENDIF; $ "MeadFloodControlData.MeadFloodControlFlag" [] := IF ( "MeadInFloodControl"( ) ) THEN 1.00000000 ENDIF; FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Surplus.SurplusFlag" [date] := IF ( "MeadInFloodControl"( ) ) THEN 1.00000000 ENDIF; ENDFOREACH; FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Surplus.Flood Control Surplus Flag" [date] := IF ( "MeadInFloodControl"( ) ) THEN 1.00000000 ENDIF COMMENTED_BY "Need to set this flag for banking"; $ "Shortage.ShortageFlag" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 ENDIF; $ "Nevada ICS.NonSystemExchangesActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Nevada ICS.NonSystemExchangesActualMonthlyPut" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Nevada ICS.GroundwaterActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Nevada ICS.GroundwaterActualMonthlyPut" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Nevada ICS.Drop2ActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Nevada ICS.TributaryConsActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "NevadaDesalination.Inflow" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft/month" ENDIF; $ "Arizona ICS.ActualMonthlyPut" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "Arizona ICS.ActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Diversion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "ArizonaPriority1Schedules.Diversion_YumaCountyWUA" [date] ENDIF; $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Depletion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "ArizonaPriority1Schedules.Depletion_YumaCountyWUA" [date] ENDIF; $ "California ICS.ActualMonthlyPut" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "California ICS.ActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; $ "California ICS.Drop2ActualMonthlyTake" [date] := IF ( "MeadInFloodControl"( ) ) THEN 0.00000000 "acre-ft" ENDIF; ENDFOREACH; FOREACH (STRING diversion IN { "MWD" , "CAP" , "SNWP" , "IID" , "Coachella" , "Mexico" }) DO FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN IF ( diversion == "CAP" ) THEN "ComputeSurplusDiversion"( diversion, date ) - $ "CAPMinDiversion.Total Diversion Requested" [date] ELSE IF ( diversion == "Mexico" ) THEN ( "ComputeSurplusDiversion"( diversion, date ) - $ "OverDeliveryToMexico.Total Diversion Requested" [date] ) COMMENTED_BY "Adjust Mexico for OverDelivery object (already set), but during FC, over-delivery counts as Mexico depletion" ELSE "ComputeSurplusDiversion"( diversion, date ) ENDIF ENDIF COMMENTED_BY "CAP minus min diversion b/c min diversion in different object" ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN IF ( diversion == "CAP" ) THEN "ComputeSurplusDepletion"( diversion, date ) - $ "CAPMinDiversion.Total Depletion Requested" [date] ELSE IF ( diversion == "Mexico" ) THEN ( "ComputeSurplusDepletion"( diversion, date ) - $ "OverDeliveryToMexico.Total Depletion Requested" [date] ) COMMENTED_BY "Adjust Mexico for OverDelivery object (already set), but during FC, over-delivery counts as Mexico depletion" ELSE "ComputeSurplusDepletion"( diversion, date ) ENDIF ENDIF COMMENTED_BY "CAP minus min diversion b/c min diversion in different object" ENDIF; diversion CONCAT "Schedule.FCSurplusFlag" [date] := IF ( "MeadInFloodControl"( ) ) THEN 1.00000000 ENDIF; ENDFOREACH; ENDFOREACH; FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "MWDSchedule.Diversion Schedule" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "MWDSchedule.Input Diversion Schedule" [date] + "RemainingMonthlyFallow"( "MWD", date ) ENDIF COMMENTED_BY "Reset MWD and PVID fallowing to surplus minimum, adjusting for amount of fallowing credits already created by PVID"; $ "MWDSchedule.Depletion Schedule" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "MWDSchedule.Input Depletion Schedule" [date] + "RemainingMonthlyFallow"( "MWD", date ) ENDIF; $ "PVIDDiversion.Total Diversion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "PVIDSchedule.Input Diversion Schedule" [date] - "RemainingMonthlyFallow"( "PVID", date ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ) ENDIF; $ "PVIDSchedule.Diversion Schedule" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "PVIDSchedule.Input Diversion Schedule" [date] - "RemainingMonthlyFallow"( "PVID", date ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ) ENDIF; $ "PVIDDiversion.Total Depletion Requested" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "PVIDSchedule.Input Depletion Schedule" [date] - "RemainingMonthlyFallow"( "PVID", date ) ENDIF; $ "PVIDSchedule.Depletion Schedule" [date] := IF ( "MeadInFloodControl"( ) ) THEN $ "PVIDSchedule.Input Depletion Schedule" [date] - "RemainingMonthlyFallow"( "PVID", date ) ENDIF; ENDFOREACH; END; RULE "Set Mead Outflow For Demands"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "Mead.Outflow" [] := "ComputeOutflowAtGivenStorageMeadClimateChange"( % "Mead", "ComputeStorageAtGivenOutflow"( % "Mead", "CurrentDemandBelowMead"( ) ) ); END; END; POLICY_GROUP "ICS and Other Project Water Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Set Normal Year Flag"; DESCRIPTION "This rule sets a flag to 1 if the year is determined to be Normal, i.e. not a Shortage or Surplus. This flag is used to determine whether or not proposed ICS activity may occur."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND "NotSurplusOrShortageYear"( ); BEGIN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] := 1.00000000; END; RULE "Adjust User for California ICS Put"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND ( NOT IsNaN $ "Surplus.SurplusFlag" [] OR NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) AND @"t" <= @"24:00:00 December 31, 2026"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "IIDDiversion.Total Diversion Requested" [date] := $ "IIDDiversion.Total Diversion Requested" [date] - "VolumeToFlow"( "MWDExchangeWithIID"( date ), date ); $ "IIDDiversion.Total Depletion Requested" [date] := $ "IIDDiversion.Total Depletion Requested" [date] - "VolumeToFlow"( "MWDExchangeWithIID"( date ), date ); ENDFOREACH; END; RULE "Adjust User for Arizona ICS Put"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND ( NOT IsNaN $ "Surplus.SurplusFlag" [] OR NOT IsNaN $ "Shortage.ShortageFlag" [] OR NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) AND @"t" <= @"24:00:00 December 31, 2026"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Diversion Requested" [date] := $ "ArizonaPriority1Schedules.Diversion_YumaCountyWUA" [date] - "VolumeToFlow"( "CAPExchangeWithYumaCountyWUA"( date ), date ); $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Depletion Requested" [date] := $ "ArizonaPriority1Schedules.Depletion_YumaCountyWUA" [date] - "VolumeToFlow"( "CAPExchangeWithYumaCountyWUA"( date ), date ); ENDFOREACH; END; RULE "Adjust Gains for Nevada ICS Put and Other"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND IsNaN $ "NevadaTributaryConservation.Inflow" [@"24:00:00 January 31, Current Year"]; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "NevadaTributaryConservation.Inflow" [date] := "VolumeToFlow"( ( $ "Nevada ICS.TributaryConsAnnualPut" [@"24:00:00 December 31, Current Year"] / 12.00000000 ) COMMENTED_BY "Put always occurs regardless of bank balance. Use schedule and not ActualMonthly", date ); $ "NevadaGroundwater.Inflow" [date] := "VolumeToFlow"( ( $ "Nevada ICS.GroundwaterActualMonthlyPut" [date] / "SystemTaxAdjustment"( ) ) COMMENTED_BY "Need to add system tax back in for real water", date ); $ "NevadaDesalination.Inflow" [date] := "VolumeToFlow"( ( $ "Nevada ICS.NonSystemExchangesActualMonthlyPut" [date] / "SystemTaxAdjustment"( ) ) COMMENTED_BY "Need to add system tax back in for real water", date ); ENDFOREACH; END; RULE "Adjust CAP for Arizona ICS Take"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"]; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "CAPDiversion.Total Diversion Requested" [date] := $ "CAPDiversion.Total Diversion Requested" [date] + "VolumeToFlow"( $ "Arizona ICS.ActualMonthlyTake" [date] + $ "Arizona ICS.Drop2ActualMonthlyTake" [date], date ); $ "CAPDiversion.Total Depletion Requested" [date] := $ "CAPDiversion.Total Depletion Requested" [date] + "VolumeToFlow"( $ "Arizona ICS.ActualMonthlyTake" [date] + $ "Arizona ICS.Drop2ActualMonthlyTake" [date], date ); ENDFOREACH; END; RULE "Compute Arizona Available ICS Water "; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Arizona ICS.ActualMonthlyPut" [date] := ( "DetermineArizonaAnnualPut"( ) / 12.00000000 ) COMMENTED_BY "Put is from GilaGravityMainCanalPriority1.YumaCountyWUA"; $ "Arizona ICS.ActualMonthlyTake" [date] := ( "DetermineArizonaAnnualTake"( ) / 12.00000000 ) COMMENTED_BY "Take is by CAP"; $ "Arizona ICS.Drop2ActualMonthlyTake" [date] := ( "DetermineAZDrop2Take"( ) / 12.00000000 ) COMMENTED_BY "System Efficiency ICS - No Drop 2 put. Put always occurs through capturing of over-deliveries to Mexico. Take is by MWD"; ENDFOREACH; END; RULE "Adjust MWD for California ICS Take"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"]; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MWDDiversion.Total Diversion Requested" [date] := $ "MWDSchedule.Diversion Schedule" [date] + "VolumeToFlow"( $ "California ICS.ActualMonthlyTake" [date] + $ "California ICS.Drop2ActualMonthlyTake" [date], date ); $ "MWDDiversion.Total Depletion Requested" [date] := $ "MWDSchedule.Depletion Schedule" [date] + "VolumeToFlow"( $ "California ICS.ActualMonthlyTake" [date] + $ "California ICS.Drop2ActualMonthlyTake" [date], date ); ENDFOREACH; END; RULE "Adjust MWD for California Drop2 Repay in Shortage"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND $ "California ICS.Drop2ActualMonthlyRepayInShortage" [] > 0.00000000 "acre-ft"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MWDDiversion.Total Diversion Requested" [date] := IF ( NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) THEN $ "MWDSchedule.Diversion Schedule" [date] ELSE $ "MWDDiversion.Total Diversion Requested" [date] ENDIF - "VolumeToFlow"( $ "California ICS.Drop2ActualMonthlyRepayInShortage" [date], date ); $ "MWDDiversion.Total Depletion Requested" [date] := IF ( NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) THEN $ "MWDSchedule.Depletion Schedule" [date] ELSE $ "MWDDiversion.Total Depletion Requested" [date] ENDIF - "VolumeToFlow"( $ "California ICS.Drop2ActualMonthlyRepayInShortage" [date], date ); $ "MWDSchedule.Drop2RepayInShortageFlag" [date] := 1.00000000; ENDFOREACH; END; RULE "Compute California Available ICS Water"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December Max DayOfMonth, Current Year") DO $ "California ICS.ActualMonthlyPut" [date] := ( "DetermineCaliforniaAnnualPut"( ) / 12.00000000 ) COMMENTED_BY "Put is from IID"; $ "California ICS.ActualMonthlyTake" [date] := ( "DetermineCaliforniaAnnualTake"( ) / 12.00000000 ) COMMENTED_BY "Take is by MWD"; $ "California ICS.Drop2ActualMonthlyTake" [date] := ( "DetermineCADrop2Take"( ) / 12.00000000 ) COMMENTED_BY "System Efficiency ICS - No Drop 2 put. Put always occurs through capturing of over-deliveries to Mexico. Take is by MWD"; $ "California ICS.Drop2ActualMonthlyRepayInShortage" [date] := ( "DetermineCADrop2RepayInShortage"( ) / 12.00000000 ) COMMENTED_BY "MWD to repay Drop2 ICS if a shortage occurs in 2011 or 2012"; ENDFOREACH; END; RULE "Adjust SNWP for Nevada ICS Take and Other"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND ( "NotShortageYear"( ) OR NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ); BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "SNWPDiversion.Total Diversion Requested" [date] := IF ( NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) THEN $ "SNWPSchedule.Diversion Schedule" [date] ELSE $ "SNWPDiversion.Total Diversion Requested" [date] ENDIF + ( "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [date] / $ "SNWPSchedule.Depletion Schedule" [date] ) ); $ "SNWPDiversion.Total Depletion Requested" [date] := IF ( NOT IsNaN $ "Mead Bank.Normal Year" [@"24:00:00 December 31, Current Year"] ) THEN $ "SNWPSchedule.Depletion Schedule" [date] ELSE $ "SNWPDiversion.Total Depletion Requested" [date] ENDIF + "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ); ENDFOREACH; END; RULE "Compute Nevada Available ICS and Other Project Water"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND IsNaN $ "Nevada ICS.GroundwaterActualMonthlyPut" [@"24:00:00 January 31, Current Year"] AND IsNaN $ "Nevada ICS.TributaryConsActualMonthlyPut" [@"24:00:00 January 31, Current Year"]; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Nevada ICS.NonSystemExchangesActualMonthlyTake" [date] := ( "DetermineNVDesalTake"( ) / 12.00000000 ) COMMENTED_BY "Imported ICS - Take is by SNWP"; $ "Nevada ICS.NonSystemExchangesActualMonthlyPut" [date] := ( "DetermineNVDesalPut"( ) / 12.00000000 ) COMMENTED_BY "Imported ICS - Put is from NevadaDesalinization.Inflow"; $ "Nevada ICS.GroundwaterActualMonthlyTake" [date] := ( "DetermineNVGroundwaterTake"( ) / 12.00000000 ) COMMENTED_BY "Imported ICS - Take is by SNWP"; $ "Nevada ICS.GroundwaterActualMonthlyPut" [date] := ( "DetermineNVGroundwaterPut"( ) / 12.00000000 ) COMMENTED_BY "Imported ICS - Put is from NevadaGroundwater.Inflow"; $ "Nevada ICS.Drop2ActualMonthlyTake" [date] := ( "DetermineNVDrop2Take"( ) / 12.00000000 ) COMMENTED_BY "System Efficiency ICS - No Drop 2 put. Put always occurs through capturing of over-deliveries to Mexico. Take is by SNWP"; $ "Nevada ICS.TributaryConsActualMonthlyTake" [date] := ( "DetermineNevadaAnnualTake"( ) / 12.00000000 ) COMMENTED_BY "Tributary Conservation ICS - Take is by SNWP"; $ "Nevada ICS.TributaryConsActualMonthlyPut" [date] := ( "DetermineNevadaAnnualPut"( ) / 12.00000000 ) COMMENTED_BY "Tributary Conservation ICS - Put is from NevadaTributaryConservation.Inflow"; ENDFOREACH; END; END; POLICY_GROUP "Shortage Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "SNWP Elevation Check"; DESCRIPTION ""; ACTIVE FALSE; RULE_EXEC_CONSTRAINT $ "Mead.Pool Elevation" [@"t - 1"] < $ "MeadProrationScheme.SNWPMinPumpingElevation" [0.00000000, 0.00000000] AND NOT IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN $ "SNWPDiversion.Total Diversion Requested" [] := 0.00000000 "acre-ft/month"; $ "SNWPDiversion.Total Depletion Requested" [] := 0.00000000 "acre-ft/month"; $ "MeadProrationScheme.SNWPZeroFlag" [] := 1.00000000; END; RULE "Monthly Absolute Protection (Level 2) Shortage for ICS"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT "ComputeWaterAvailableFromMeadAboveAnElevation"( ) < "CurrentDemandBelowMead"( ) AND ( @"t" >= @"October" OR NOT IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ) COMMENTED_BY "We should be able to ignore affects of level 2 critical period short, since we require it to have already fired." AND @"t" > @"24:00:00 December 31, 2026" AND IF ( $ "Shortage.MWDShortageCounter" [@"t"] == 1.00000000 ) THEN NOT IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ELSE TRUE ENDIF; BEGIN FOREACH (STRING diversion IN IF ( $ "Mead.Pool Elevation" [@"t - 1"] < $ "MeadProrationScheme.SNWPMinPumpingElevation" [0.00000000, 0.00000000] ) THEN { "CAP" , "Mexico" , "MWD" } ELSE { "CAP" , "SNWP" , "Mexico" , "MWD" } ENDIF) DO diversion CONCAT "Diversion.Total Diversion Requested" [] := IF ( diversion CONCAT "Diversion.Total Diversion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAbsoluteProtectionShortageDiversion"( diversion, % "Mead" COMMENTED_BY "Has no significance, just needed an existing object to pass" ) + IF ( diversion == "SNWP" AND $ "Shortage.MWDShortageCounter" [@"t"] == 1.00000000 AND IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( @"t" ), @"t" ) * ( $ "SNWPSchedule.Diversion Schedule" [] / $ "SNWPSchedule.Depletion Schedule" [] ) ELSE 0.00000000 "acre-ft/month" ENDIF ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [] := "ComputeAbsoluteProtectionShortageDepletion"( diversion, % "Mead" COMMENTED_BY "Has no significance, just needed an existing object to pass" ) + IF ( diversion == "SNWP" AND $ "Shortage.MWDShortageCounter" [@"t"] == 1.00000000 AND IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( @"t" ), @"t" ) ELSE 0.00000000 "acre-ft/month" ENDIF; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [] := IF ( diversion CONCAT ".Diversion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAbsoluteProtectionShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDIF; diversion CONCAT ".Depletion Requested" [] := IF ( diversion CONCAT ".Depletion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAbsoluteProtectionShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDIF; ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [] := IF ( diversion CONCAT ".Diversion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAbsoluteProtectionShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDIF; diversion CONCAT ".Depletion Requested" [] := IF ( diversion CONCAT ".Depletion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAbsoluteProtectionShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDIF; ENDFOREACH; diversion CONCAT "Schedule.ShortageScheduleFlag" [] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [@"t"] := 0.00000000; ENDFOREACH; $ "Surplus.SurplusFlag" [] := 0.00000000; $ "Shortage.ShortageFlag" [] := 1.00000000; $ "Shortage.Monthly Level 2 Shortage Flag" [] := 1.00000000; $ "Shortage.Stage2Shortage" [] := "AbsoluteProtectionLevelShortageToAllocateMONTH"( ); $ "Shortage.Stage2ShortageCHECK" [] := "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) + ( FOR ( STRING diversion IN { "CAP" , "SNWP" , "Mexico" , "MWD" } ) WITH NUMERIC result = 0.00000000 "acre-ft/month" DO result + diversion CONCAT "Diversion.Total Depletion Requested" [] - "ComputeAbsoluteProtectionShortageDepletion"( diversion, % "Mead" ) ENDFOR + ( FOR ( OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft/month" DO result + diversion CONCAT ".Depletion Requested" [] - "ComputeAbsoluteProtectionShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDFOR + FOR ( OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft/month" DO result + diversion CONCAT ".Depletion Requested" [] - "ComputeAbsoluteProtectionShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), diversion ) ENDFOR ) ); END; RULE "Jan-Sept Absolute Protection (Level 2) Shortage for ICS"; DESCRIPTION "This rule sets CAP and the other Priority 4 Arizona Users to zero for the current month if Mead is forecasted to go below 1000 ft in July."; ACTIVE TRUE; RULE_EXEC_CONSTRAINT ( @"t" < @"October" AND @"t" > @"24:00:00 December 31, 2026" AND ( $ "Shortage.ShortageFlag" [] == 1.00000000 ) COMMENTED_BY "We should be able to ignore effects of level 1 short, since we require it to have already fired." AND "CriticalPeriodVolumeCheck"( ) COMMENTED_BY "Checks now or May through (and including) September, water availability" AND IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ) OR ( ( $ "Shortage.MWDShortageCounter" [@"t"] == 1.00000000 AND @"t" > @"24:00:00 December 31, 2026" ) AND ( $ "Shortage.ShortageFlag" [] == 1.00000000 ) ) OR ( ( $ "EqualizationData.BypassCapFlag" [@"t"] == 1.00000000 AND @"t" > @"24:00:00 December 31, 2026" ) AND ( $ "Shortage.ShortageFlag" [] == 1.00000000 ) ); BEGIN FOREACH (STRING diversion IN IF ( $ "Mead.Pool Elevation" [@"t - 1"] < $ "MeadProrationScheme.SNWPMinPumpingElevation" [0.00000000, 0.00000000] ) THEN { "CAP" , "Mexico" } ELSE { "SNWP" , "CAP" , "Mexico" } ENDIF) DO diversion CONCAT "Diversion.Total Diversion Requested" [] := IF ( diversion CONCAT "Diversion.Total Diversion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAPCritPeriodShortageDiversion"( diversion ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( @"t" ), @"t" ) * ( $ "SNWPSchedule.Diversion Schedule" [] / $ "SNWPSchedule.Depletion Schedule" [] ) ELSE 0.00000000 "acre-ft/month" ENDIF ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [] := IF ( diversion CONCAT "Diversion.Total Depletion Requested" [] > 0.00000000 "acre-ft/month" ) THEN "ComputeAPCritPeriodShortageDepletion"( diversion ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( @"t" ), @"t" ) ELSE 0.00000000 "acre-ft/month" ENDIF ENDIF; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [] := "ComputeAPCritPeriodShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) ); diversion CONCAT ".Depletion Requested" [] := "ComputeAPCritPeriodShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) ); ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) []; diversion CONCAT ".Depletion Requested" [] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) []; ENDFOREACH; diversion CONCAT "Schedule.ShortageScheduleFlag" [] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [@"t"] := 0.00000000; ENDFOREACH; $ "Surplus.SurplusFlag" [] := 0.00000000; $ "Shortage.ShortageFlag" [] := 1.00000000; $ "Shortage.Stage1Shortage" [] := "TotalLBShortageArizonaPriority4Zero"( ); $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] := 1.00000000; END; RULE "Adjust Mexico for ICMA"; DESCRIPTION ""; ACTIVE FALSE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND @"t" <= @"24:00:00 December 31, 2036"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MexicoDiversion.Total Diversion Requested" [date] := $ "MexicoDiversion.Total Diversion Requested" [date] - "VolumeToFlow"( $ "ICMA.ActualMonthlyPut" [date] / "ICMASystemTaxAdjustment"( ) - $ "ICMA.ActualMonthlyTake" [date], date ); $ "MexicoDiversion.Total Depletion Requested" [date] := $ "MexicoDiversion.Total Depletion Requested" [date] - "VolumeToFlow"( $ "ICMA.ActualMonthlyPut" [date] / "ICMASystemTaxAdjustment"( ) - $ "ICMA.ActualMonthlyTake" [date], date ); ENDFOREACH; END; RULE "Compute Available ICMA"; DESCRIPTION ""; ACTIVE FALSE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND IsNaN $ "ICMA.ActualMonthlyPut" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "ICMA.ActualMonthlyPut" [date] := ( "DetermineICMAAnnualPut"( ) / 12.00000000 ); $ "ICMA.ActualMonthlyTake" [date] := ( ( GET @INDEX 0.00000000 FROM "DetermineICMAAnnualTake"( ) ) / 12.00000000 ); $ "ICMA.ActualMonthlyPulseFlow" [date] := "ComputeMonthlyPulseFlow"( date ); ENDFOREACH; END; RULE "Shortage (80P1050) for ICS"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND $ "Mead.Pool Elevation" [@"t - 1"] < $ "Shortage.Mead Trigger 80P1050" [@"t - 1"] AND @"t" > @"24:00:00 December 31, 2026" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO FOREACH (STRING diversion IN { "CAP" , "SNWP" , "Mexico" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeShortageDiversion"( diversion, date ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [date] / $ "SNWPSchedule.Depletion Schedule" [date] ) ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeShortageDepletion"( diversion, date ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 0.00000000; ENDFOREACH; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ComputeShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), date ); diversion CONCAT ".Depletion Requested" [date] := "ComputeShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), date ); ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; $ "Surplus.SurplusFlag" [date] := 0.00000000; $ "Shortage.ShortageFlag" [date] := 1.00000000; $ "Shortage.80P1050 Shortage Flag" [date] := 1.00000000; ENDFOREACH; $ "Shortage.Annual Level 1 Shortage" [] := "TotalLevel1LBShortage"( ); END; RULE "Step 3 Shortage for ICS"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year" AND $ "Mead.Pool Elevation" [@"t - 1"] < $ "Shortage.Step Shortage Mead Tier" [0.00000000, 0.00000000] AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December Max DayOfMonth, Current Year") DO FOREACH (STRING diversion IN { "CAP" , "SNWP" , "Mexico" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeStepShortageDiversion"( diversion, 3.00000000, date ) + IF ( diversion == "SNWP" ) THEN ( "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [date] / $ "SNWPSchedule.Depletion Schedule" [date] ) ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeStepShortageDepletion"( diversion, 3.00000000, date ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ComputeStepShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 3.00000000, date ); diversion CONCAT ".Depletion Requested" [date] := "ComputeStepShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 3.00000000, date ); ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 0.00000000; ENDFOREACH; $ "Surplus.SurplusFlag" [date] := 0.00000000; $ "Shortage.ShortageFlag" [date] := 1.00000000; $ "Shortage.Step 3 Shortage Flag" [date] := 1.00000000; ENDFOREACH; END; RULE "Step 2 Shortage for ICS"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year" AND ( $ "Mead.Pool Elevation" [@"t - 1"] < $ "Shortage.Step Shortage Mead Tier" [1.00000000, 0.00000000] AND $ "Mead.Pool Elevation" [@"t - 1"] >= $ "Shortage.Step Shortage Mead Tier" [0.00000000, 0.00000000] ) AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO FOREACH (STRING diversion IN { "CAP" , "SNWP" , "Mexico" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeStepShortageDiversion"( diversion, 2.00000000, date ) + IF ( diversion == "SNWP" ) THEN ( "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [date] / $ "SNWPSchedule.Depletion Schedule" [date] ) ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeStepShortageDepletion"( diversion, 2.00000000, date ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ComputeStepShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 2.00000000, date ); diversion CONCAT ".Depletion Requested" [date] := "ComputeStepShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 2.00000000, date ); ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 0.00000000; ENDFOREACH; $ "Surplus.SurplusFlag" [date] := 0.00000000; $ "Shortage.ShortageFlag" [date] := 1.00000000; $ "Shortage.Step 2 Shortage Flag" [date] := 1.00000000; ENDFOREACH; END; RULE "Step 1 Shortage for ICS"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND ( $ "Mead.Pool Elevation" [@"t - 1"] <= $ "Shortage.Step Shortage Mead Tier" [2.00000000, 0.00000000] AND $ "Mead.Pool Elevation" [@"t - 1"] >= $ "Shortage.Step Shortage Mead Tier" [1.00000000, 0.00000000] ) AND @"t" <= @"24:00:00 December 31, 2026" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO FOREACH (STRING diversion IN { "CAP" , "SNWP" , "Mexico" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeStepShortageDiversion"( diversion, 1.00000000, date ) + IF ( diversion == "SNWP" ) THEN ( "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [date] / $ "SNWPSchedule.Depletion Schedule" [date] ) ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeStepShortageDepletion"( diversion, 1.00000000, date ) + IF ( diversion == "SNWP" ) THEN "VolumeToFlow"( "DetermineSNWPAdditionalProjectWater"( date ), date ) COMMENTED_BY "Adjust for any takes that still occur in shortage." ELSE 0.00000000 "acre-ft/month" ENDIF; diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 1.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 0.00000000; FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ComputeStepShortageDiversion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 1.00000000, date ); diversion CONCAT ".Depletion Requested" [date] := "ComputeStepShortageDepletion"( "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ), 1.00000000, date ); ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; ENDFOREACH; $ "Surplus.SurplusFlag" [date] := 0.00000000; $ "Shortage.ShortageFlag" [date] := 1.00000000; $ "Shortage.Step 1 Shortage Flag" [date] := 1.00000000; ENDFOREACH; END; END; POLICY_GROUP "Surplus Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Quantified 7 State Plan Level 1 Surplus"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND $ "Surplus.SurplusRelease" [] > 0.00000000 "acre-feet" AND @"t" < @"24:00:00 January 31, 2027" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Surplus.SurplusFlag" [date] := 1.00000000; $ "Shortage.ShortageFlag" [date] := 0.00000000; $ "Surplus.Quantified Surplus Flag" [date] := 1.00000000; FOREACH (STRING diversion IN { "MWD" , "CAP" , "SNWP" , "IID" , "Coachella" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeSurplusDiv7StatePlanLevel1"( diversion, date ); diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeSurplusDepl7StatePlanLevel1"( diversion, date ); diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 0.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := IF ( "ComputeSurplusDepl7StatePlanLevel1"( diversion, date ) > diversion CONCAT "Schedule.Depletion Schedule" [] ) THEN 1.00000000 ELSE 0.00000000 ENDIF; diversion CONCAT "Schedule.SurplusLevel1Flag" [date] := IF ( "ComputeSurplusDepl7StatePlanLevel1"( diversion, date ) > diversion CONCAT "Schedule.Depletion Schedule" [] ) THEN 1.00000000 ELSE 0.00000000 ENDIF; ENDFOREACH; ENDFOREACH; END; RULE "Domestic 7 State Plan Level 2 Surplus"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND ( ( $ "Mead.Pool Elevation" [@"t - 1"] >= $ "Surplus Triggers.7 State Plan Level 2" [@"t - 1"] AND $ "Surplus.SurplusRelease" [] <= 0.00000000 "acre-feet" ) AND @"t" < @"24:00:00 January 31, 2027" ) AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Surplus.SurplusFlag" [date] := 1.00000000; $ "Shortage.ShortageFlag" [date] := 0.00000000; $ "Surplus.Full Domestic Surplus Flag" [date] := 1.00000000; FOREACH (STRING diversion IN { "MWD" , "SNWP" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeSurplusDiv7StatePlanLevel2"( diversion, date ); diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeSurplusDepl7StatePlanLevel2"( diversion, date ); diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 0.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 1.00000000; diversion CONCAT "Schedule.SurplusLevel2Flag" [date] := 1.00000000; ENDFOREACH; FOREACH (STRING diversion IN { "CAP" , "IID" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := diversion CONCAT "Schedule.Diversion Schedule" [date]; diversion CONCAT "Diversion.Total Depletion Requested" [date] := diversion CONCAT "Schedule.Depletion Schedule" [date]; ENDFOREACH; ENDFOREACH; END; RULE "70R Assurance Level Surplus"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND $ "Surplus.SurplusRelease" [] > 0.00000000 "acre-feet" AND @"t" >= @"24:00:00 January 31, 2027" AND IsNaN $ "SNWPDiversion.Total Depletion Requested" []; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "Surplus.SurplusFlag" [date] := 1.00000000; $ "Surplus.Normal 70R Surplus Flag" [date] := 1.00000000; $ "Shortage.ShortageFlag" [date] := 0.00000000; FOREACH (STRING diversion IN { "MWD" , "CAP" , "SNWP" , "Coachella" , "IID" }) DO diversion CONCAT "Diversion.Total Diversion Requested" [date] := "ComputeSurplusDiversion"( diversion, date ); diversion CONCAT "Diversion.Total Depletion Requested" [date] := "ComputeSurplusDepletion"( diversion, date ); diversion CONCAT "Schedule.ShortageScheduleFlag" [date] := 0.00000000; diversion CONCAT "Schedule.SurplusScheduleFlag" [date] := 1.00000000; ENDFOREACH; ENDFOREACH; END; END; POLICY_GROUP "Normal and Other Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Set PVID Fallow Amount"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN $ "California ICS.PVID Fallow Amount" [@"24:00:00 December 31, Current Year"] := IF ( @"t" == @"24:00:00 January 31, 2010" ) THEN 150000.00000000 "acre-ft" ELSE IF ( @"t" == @"24:00:00 January 31, 2011" ) THEN 110000.00000000 "acre-ft" ELSE IF ( @"t" >= @"24:00:00 January 31, 2012" AND @"t" <= @"24:00:00 January 31, 2039" ) THEN IF ( "IsEven"( "GetYear"( @"t" ), 1.00000000 ) ) THEN IF ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] > $ "California ICS.PVIDFallowing" [0.00000000, 0.00000000] ) THEN $ "California ICS.PVIDFallowing" [0.00000000, 1.00000000] ELSE IF ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] >= $ "California ICS.PVIDFallowing" [1.00000000, 0.00000000] AND $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] <= $ "California ICS.PVIDFallowing" [0.00000000, 0.00000000] ) THEN $ "California ICS.PVIDFallowing" [1.00000000, 1.00000000] ELSE IF ( @"t" < @"24:00:00 January 31, 2020" ) THEN $ "California ICS.PVIDFallowing" [2.00000000, 1.00000000] ELSE IF ( "SumSlot"( $ "California ICS.PVID Fallow Amount", @"24:00:00 December 31, Previous Year - 7 Year", @"24:00:00 December 31, Previous Year" ) - 8.00000000 * $ "California ICS.PVIDFallowing" [2.00000000, 1.00000000] <= 0.00000000 "acre-ft" AND "SumSlot"( $ "California ICS.PVID Fallow Amount", @"24:00:00 December 31, Previous Year - 7 Year", @"24:00:00 December 31, Previous Year" ) - 8.00000000 * $ "California ICS.PVIDFallowing" [2.00000000, 1.00000000] >= - 1.00000000 "acre-ft" ) THEN $ "California ICS.PVIDFallowing" [3.00000000, 1.00000000] ELSE $ "California ICS.PVIDFallowing" [2.00000000, 1.00000000] ENDIF COMMENTED_BY "check to see if PVID has been fallowing 110 kaf for 8 consecutive years by substracting the last 8yr fallowing amount from 880 kaf (110 kaf * 8). due to significant digits, the SumSlot function results in slightly less than 880 kaf, which is why the <=0 and >=-1 was necessary" ENDIF COMMENTED_BY "Mead is less than 1105 fallow 110 kaf unless 8 consecutive years of 110 kaf, then fallow 100 kaf" ENDIF COMMENTED_BY "if Mead is between 1105 and 1140 fallow 50 kaf" ENDIF COMMENTED_BY "if Mead is greater than 1140 fallow 26 kaf
" ELSE $ "California ICS.PVID Fallow Amount" [@"24:00:00 December 31, Previous Year"] COMMENTED_BY "it's an odd year so fallow same amount as last year" ENDIF COMMENTED_BY "if current year is even (fallowing amount is set for 2-yr period beginning 2012), determine fallowing amount based on Mead elevation" ELSE 0.00000000 "acre-ft" COMMENTED_BY "it's after 2039 so the fallowing program has ended" ENDIF COMMENTED_BY "last year of fallowing program is 2039
" ENDIF ENDIF; END; RULE "MWD and PVID Surplus Fallowing"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT ( NOT IsNaN $ "Surplus.SurplusRelease" [] AND ( ( ( NOT "NotSurplusYear"( ) ) AND @"t" == @"January" ) AND $ "California ICS.PVID Fallow Amount" [@"24:00:00 December 31, Current Year"] > 0.00000000 "acre-ft" ) ) COMMENTED_BY ">:-)"; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO $ "MWDSchedule.Diversion Schedule" [date] := $ "MWDSchedule.Input Diversion Normal Schedule" [date] + "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "MWD", date ), date ); $ "MWDSchedule.Depletion Schedule" [date] := $ "MWDSchedule.Input Depletion Normal Schedule" [date] + "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "MWD", date ), date ); $ "MWDSchedule.Input Diversion Schedule" [date] := $ "MWDSchedule.Input Diversion Normal Schedule" [date]; $ "MWDSchedule.Input Depletion Schedule" [date] := $ "MWDSchedule.Input Depletion Normal Schedule" [date]; $ "PVIDDiversion.Total Diversion Requested" [date] := $ "PVIDSchedule.Input Diversion Schedule" [date] - "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "PVID", date ), date ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ); $ "PVIDSchedule.Diversion Schedule" [date] := $ "PVIDSchedule.Input Diversion Schedule" [date] - "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "PVID", date ), date ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ); $ "PVIDDiversion.Total Depletion Requested" [date] := $ "PVIDSchedule.Input Depletion Schedule" [date] - "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "PVID", date ), date ); $ "PVIDSchedule.Depletion Schedule" [date] := $ "PVIDSchedule.Input Depletion Schedule" [date] - "VolumeToFlow"( $ "California ICS.Minimum PVID Fallow Amount" [] * "SurplusMonthlyPercent"( "PVID", date ), date ); ENDFOREACH; END; RULE "Set MWD Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MWDDiversion.Total Diversion Requested" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Diversion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Diversion Shortage Schedule" [date] ENDIF + "PVID Fallow Amount"( date, "MWD" ); $ "MWDSchedule.Diversion Schedule" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Diversion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Diversion Shortage Schedule" [date] ENDIF + "PVID Fallow Amount"( date, "MWD" ); $ "MWDDiversion.Total Depletion Requested" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Depletion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Depletion Shortage Schedule" [date] ENDIF + "PVID Fallow Amount"( date, "MWD" ); $ "MWDSchedule.Depletion Schedule" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Depletion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Depletion Shortage Schedule" [date] ENDIF + "PVID Fallow Amount"( date, "MWD" ); $ "MWDSchedule.Input Diversion Schedule" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Diversion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Diversion Shortage Schedule" [date] ENDIF; $ "MWDSchedule.Input Depletion Schedule" [date] := IF ( "NotShortageYear"( ) ) THEN $ "MWDSchedule.Input Depletion Normal Schedule" [date] ELSE $ "MWDSchedule.Input Depletion Shortage Schedule" [date] ENDIF; $ "MWDSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "MWDSchedule.ShortageScheduleFlag" [date] := 0.00000000; $ "MWDSchedule.UsingShortageScheduleFlag" [date] := IF ( "NotShortageYear"( ) ) THEN 0.00000000 ELSE 1.00000000 ENDIF; ENDFOREACH; END; RULE "Set PVID Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "PVIDDiversion.Total Diversion Requested" [date] := $ "PVIDSchedule.Input Diversion Schedule" [date] - "PVID Fallow Amount"( date, "PVID" ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ); $ "PVIDSchedule.Diversion Schedule" [date] := $ "PVIDSchedule.Input Diversion Schedule" [date] - "PVID Fallow Amount"( date, "PVID" ) * ( $ "PVIDSchedule.Input Diversion Schedule" [date] / $ "PVIDSchedule.Input Depletion Schedule" [date] ); $ "PVIDDiversion.Total Depletion Requested" [date] := $ "PVIDSchedule.Input Depletion Schedule" [date] - "PVID Fallow Amount"( date, "PVID" ); $ "PVIDSchedule.Depletion Schedule" [date] := $ "PVIDSchedule.Input Depletion Schedule" [date] - "PVID Fallow Amount"( date, "PVID" ); ENDFOREACH; END; RULE "Set CAP Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "CAPDiversion.Total Diversion Requested" [date] := $ "CAPSchedule.Diversion Schedule" [date]; $ "CAPDiversion.Total Depletion Requested" [date] := $ "CAPSchedule.Depletion Schedule" [date]; $ "CAPSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "CAPSchedule.ShortageScheduleFlag" [date] := 0.00000000; ENDFOREACH; END; RULE "Set Mexico Schedule for Upper Basin Shortage Only"; DESCRIPTION ""; ACTIVE FALSE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND $ "MexicoShortageSensitivity.AnnualUpperBasinShortage_Adj" [@"24:00:00 December 31, Current Year"] > 0.00000000 "acre-ft"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MexicoDiversion.Total Diversion Requested" [date] := "ComputeMexicoDiversionUBShortOnly"( date ); $ "MexicoDiversion.Total Depletion Requested" [date] := "ComputeMexicoDepletionUBShortOnly"( date ); $ "MexicoSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "MexicoSchedule.ShortageScheduleFlag" [date] := 0.00000000; ENDFOREACH; END; RULE "Set Mexico Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "MexicoDiversion.Total Diversion Requested" [date] := $ "MexicoSchedule.Diversion Schedule" [date]; $ "MexicoDiversion.Total Depletion Requested" [date] := $ "MexicoSchedule.Depletion Schedule" [date]; $ "MexicoSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "MexicoSchedule.ShortageScheduleFlag" [date] := 0.00000000; ENDFOREACH; END; RULE "Set Mexico Over Delivery Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND @"t" <= @"24:00:00 December 31, 2009"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "OverDeliveryToMexico.Total Diversion Requested" [date] := "VolumeToFlow"( $ "MexicoSchedule.OverDelivery" [], date ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"]; $ "OverDeliveryToMexico.Total Depletion Requested" [date] := "VolumeToFlow"( $ "MexicoSchedule.OverDelivery" [], date ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"]; ENDFOREACH; END; RULE "Set Mexico Over Delivery Schedule Drop 2"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year" AND @"t" >= @"24:00:00 January 31, 2010"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "OverDeliveryToMexico.Total Diversion Requested" [date] := "VolumeToFlow"( $ "MexicoSchedule.OverDelivery" [] - $ "MexicoSchedule.Drop2Recovery" [], date ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"]; $ "OverDeliveryToMexico.Total Depletion Requested" [date] := "VolumeToFlow"( $ "MexicoSchedule.OverDelivery" [] - $ "MexicoSchedule.Drop2Recovery" [], date ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"]; ENDFOREACH; END; RULE "Set Coachella Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "CoachellaDiversion.Total Diversion Requested" [date] := $ "CoachellaSchedule.Diversion Schedule" [date]; $ "CoachellaDiversion.Total Depletion Requested" [date] := $ "CoachellaSchedule.Depletion Schedule" [date]; $ "CoachellaSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "CoachellaSchedule.ShortageScheduleFlag" [date] := 0.00000000; ENDFOREACH; END; RULE "Set IID Normal Schedule"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January Max DayOfMonth, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "IIDDiversion.Total Diversion Requested" [date] := $ "IIDSchedule.Diversion Schedule" [date]; $ "IIDDiversion.Total Depletion Requested" [date] := $ "IIDSchedule.Depletion Schedule" [date]; $ "IIDSchedule.SurplusScheduleFlag" [date] := 0.00000000; $ "IIDSchedule.ShortageScheduleFlag" [date] := 0.00000000; ENDFOREACH; END; RULE "Set Yuma County WUA Normal Schedule"; DESCRIPTION "This rule fires once a year and sets the YumaCountyWUA water user to its Normal schedule. This schedule may be adjusted for ICS creation according to Arizona's ICS schedule. This adjustment is done in the higher priority rule: Adjust User for Arizona ICS Put"; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"t + 11") DO $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Diversion Requested" [date] := $ "ArizonaPriority1Schedules.Diversion_YumaCountyWUA" [date]; $ "GilaGravityMainCanalPriority1:YumaCountyWUA.Depletion Requested" [date] := $ "ArizonaPriority1Schedules.Depletion_YumaCountyWUA" [date]; ENDFOREACH; END; RULE "Set Arizona Priority 2, 3 and 4 Normal Schedules"; DESCRIPTION "This rule fires once a year and sets the Arizona 2nd, 3rd and 4th (excluding CAP) priority users to their Normal schedules. The Normal schedule for these users may be adjusted during a Shortage. View subbasins Other Arizona Priority 4 Users, Arizona Priority 2 and 3 Users to see specifically which users are included. "; ACTIVE TRUE; RULE_EXEC_CONSTRAINT @"t" == @"24:00:00 January 31, Current Year"; BEGIN FOREACH (DATETIME date IN @"t" TO @"24:00:00 December 31, Current Year") DO FOREACH (OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( )) DO diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority4Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority4Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; FOREACH (OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( )) DO diversion CONCAT ".Depletion Requested" [date] := "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; diversion CONCAT ".Diversion Requested" [date] := "ArizonaPriority2and3Schedules.Diversion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [date]; ENDFOREACH; ENDFOREACH; END; END; POLICY_GROUP "Mohave Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Mohave Rule Curve"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN "Mohave.Storage" []; BEGIN "Mohave.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Mohave", "ComputeOutflowAtRuleCurveStorage"( % "Mohave" ) ); END; RULE "Compute Davis Energy"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "Lower Basin Energy.Computed Davis Energy Using Input Eff" [] := $ "Lower Basin Energy.Davis Efficiency" [0.00000000, 0.00000000] * "FlowToVolume"( $ "Mohave.Turbine Release" [], @"t" ) * "Compute Head as a Function of Turbine Release"( $ "Mohave.Turbine Release" [] ) * ( 9789.00000000 "newton" / ( 1.00000000 "m" * 1.00000000 "m" * 1.00000000 "m" ) ); $ "Lower Basin Energy.Computed Davis Head using Turbine Release" [] := "Compute Head as a Function of Turbine Release"( $ "Mohave.Turbine Release" [] ); END; END; POLICY_GROUP "Havasu Rules"; DESCRIPTION ""; ACTIVE TRUE; BEGIN RULE "Havasu Rule Curve"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT IsNaN $ "Havasu.Storage" []; BEGIN $ "Havasu.Storage" [] := "ComputeStorageAtGivenOutflow"( % "Havasu", "ComputeOutflowAtRuleCurveStorage"( % "Havasu" ) ); END; RULE "Compute Parker Energy"; DESCRIPTION ""; ACTIVE TRUE; RULE_EXEC_CONSTRAINT TRUE; BEGIN $ "Lower Basin Energy.Computed Parker Head using Turbine Release" [] := "Compute Head as a Function of Turbine Release"( $ "Havasu.Turbine Release" [] ); $ "Lower Basin Energy.Computed Parker Energy Using Input Eff" [] := $ "Lower Basin Energy.Parker Efficiency" [0.00000000, 0.00000000] * "FlowToVolume"( $ "Havasu.Turbine Release" [], @"t" ) * $ "Havasu.Operating Head" [] * ( 9789.00000000 "newton" / ( 1.00000000 "m" * 1.00000000 "m" * 1.00000000 "m" ) ); END; END; UTILITY_GROUP "General Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "AnnualVolume" ( SLOT slot ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( slot, @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ); END; FUNCTION "AvailableSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( reservoir ) - reservoir & "Storage" [@"t - 1"]; END; FUNCTION "CurrentAvailableSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( reservoir ) - reservoir & "Storage" []; END; FUNCTION "EstimateBankStorage" ( OBJECT reservoir, NUMERIC startStorage, NUMERIC endStorage ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( endStorage - "EstimateEvaporation"( reservoir, startStorage, "Min"( endStorage, "LiveCapacity"( reservoir ) ), @"t", @"24:00:00 September 30, Current Year" ) - startStorage ) * reservoir & "Bank Storage Coefficient" [0.00000000, 0.00000000]; END; FUNCTION "EstimateEvaporation" ( OBJECT reservoir, NUMERIC startStorage, NUMERIC endStorage, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( ( STRINGIFY reservoir ) == "Starvation" OR ( STRINGIFY reservoir ) == "TaylorPark" ) THEN 0.00000000 "acre-ft" ELSE "FlowToVolume"( ( "StorageToArea"( reservoir, startStorage ) + "StorageToArea"( reservoir, endStorage ) ) / 2.00000000 * "SumEvapCoeff"( reservoir, "GetMonth"( startDate ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ), endDate ) ENDIF; END; FUNCTION "GetListElement" ( NUMERIC index, LIST list ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN GET @INDEX index FROM list; END; FUNCTION "SumGainsBelowVolume" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Below" CONCAT STRINGIFY reservoir, "Local Inflow", "SUM", "INPUT", TRUE, startDate, endDate ) + IF ( ( STRINGIFY reservoir ) == "Mead" ) THEN "SumFlowsToVolume"( $ "BelowImperialDamColoradoR.Total Local Inflow", startDate, endDate ) COMMENTED_BY "Need to add in Desal local inflow, which is not input." ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "SumDiversionsBelowVolume" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Below" CONCAT STRINGIFY reservoir, "Total Diversion Requested", "SUM", "ALL", TRUE, startDate, endDate ); END; FUNCTION "SumDepletionsBelowVolume" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Below" CONCAT STRINGIFY reservoir, "Total Depletion Requested", "SUM", "ALL", TRUE, startDate, endDate ); END; FUNCTION "SumDepletionsBelow" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Below" CONCAT STRINGIFY reservoir, "Total Depletion Requested", "SUM", "ALL", FALSE, startDate, endDate ); END; FUNCTION "SumEvapCoeff" ( OBJECT reservoir, NUMERIC startRow, NUMERIC endRow ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableColumn"( reservoir & "Evaporation Coefficients", 0.00000000, startRow, endRow ); END; FUNCTION "EstimateEvapForDownstreamDemands" ( OBJECT reservoir, NUMERIC startStorage, NUMERIC endStorage ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FlowToVolume"( ( "StorageToArea"( reservoir, startStorage ) + "StorageToArea"( reservoir, endStorage ) ) / 2.00000000 * "SumEvapCoeff"( reservoir, "GetMonth"( @"t" ) - 1.00000000, "GetMonth"( @"t" ) - 1.00000000 ) * ( 31.00000000 "day" / "GetDaysInMonth"( @"t" ) ), @"t" ); END; FUNCTION "ComputePowellForecastError" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Replaced Tcl function: ComputePowellForecastError (3/1/04)
-this function is called directly from the rule: Powell Forecast Error and limits
June's error to half of May's error. Otherwise, the value of ComputeInitialPowellForecastError()
is returned. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" == @"June" ) THEN IF ( "Abs"( "ComputeInitialPowellForecastError"( ) ) > "Abs"( $ "MeadFloodControlData.PowellForecastError" [@"t - 1"] / 2.00000000 ) ) THEN $ "MeadFloodControlData.PowellForecastError" [@"t - 1"] / 2.00000000 ELSE "ComputeInitialPowellForecastError"( ) ENDIF ELSE "ComputeInitialPowellForecastError"( ) ENDIF; END; FUNCTION "ComputeInitialPowellForecastError" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Computes the forecast error based on the previous forecast error, regression
coefficients, Powell's runoff and the random deviation. The forecast error is 0
Aug-December and is a quarter of the June's error during July. The value of this
function is returned to ComputePowellForecastError() which, during June, limits
the error to half of May's error. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" > @"July" ) THEN 0.00000000 ELSE IF ( @"Current Month" == @"July" ) THEN "GetPreviousForecastError"( ) / 4.00000000 ELSE "RegressionCoefficient"( % "Powell", "c1" ) * ( $ "Qsum.Powell" [] / 1000000.00000000 "acre-feet" ) + "RegressionCoefficient"( % "Powell", "c2" ) * "GetPreviousForecastError"( ) + "RegressionCoefficient"( % "Powell", "c3" ) + "RegressionCoefficient"( % "Powell", "sde" ) * "SetRandomDeviation"( ) ENDIF ENDIF; END; FUNCTION "SetRandomDeviation" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "This function calls the random number generator and returns the random
number if it is Jan - June. Otherwise, there is no random deviation. The value
returned by this function is stored in PowellForecastData.random. The 0.000
passed to RandomNormal() only specifies the units of the returned number, in this case,
NONE. To get a different set of random numbers, change the seed in
PowellForecastData.Random Seed.

The min and max constraints on this function are from the old generator, which had these limits. We have a slightly different result here, because the old generator would create a new number if the value exceeded these limits, we just return a number at the limit instead. Things will probably break if we get a random number even close to this large.
Since the generator has less than a 1 in 1e-21 chance of generating something outside these bands, it probably isn't useful to have those constraints anyway. :)
"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT - 10.00000000; MAX_CONSTRAINT 10.00000000; BEGIN IF ( @"Current Month" >= @"July" ) THEN 0.00000000 ELSE "RandomNormal"( "GetRandSeed"( ), $ "PowellForecastData.Random Index" [], 0.00000000 ) ENDIF; END; FUNCTION "GetRandSeed" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Returns a seed for use by the RandomNormal function.
The seed is incremented by the trace number, as stored in the first timestep of the
Hydrology Increment slot. The trace number could be available as a RPL function, but would not be enough to fulfill our requirements.

In the current setup, all MRM runs will have the same set of random numbers at the same trace, but all traces will have different sets, as controlled by the Hydrology Increment slot, which is rotated with the MRM runs.
This also allows single trace runs to have identical random numbers generated as well, which is not possible with a RPL function.

Probably should rename the Hydrology Increment slot to Trace Number.

With Random Seed = 1, is equivalent to just using the Trace Number as the seed for each trace."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( $ "PowellForecastData.Random Seed" [] + ( $ "MeadFloodControlData.hydrologyIncrement" [@"Start Timestep"] - 1.00000000 ) ); END; FUNCTION "GetPreviousForecastError" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Called by ComputeInitialPowellForecastError() and returns the previous month's
forecast error unless the current month is January. In that case, 0 is returned."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" == @"January" ) THEN 0.00000000 ELSE $ "MeadFloodControlData.PowellForecastError" [@"t - 1"] ENDIF; END; FUNCTION "MinReleaseVolume" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN "GetDates"( startDate, endDate, "1 MONTHS" ) ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "FlowToVolume"( "MinRelease"( reservoir ), date ) ENDFOR; END; FUNCTION "MaxReleaseVolume" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN "GetDates"( startDate, endDate, "1 MONTHS" ) ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "FlowToVolume"( "MaxRelease"( reservoir ), date ) ENDFOR; END; FUNCTION "Compute Head as a Function of Turbine Release" ( NUMERIC turbineRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( $ "Mohave.Pool Elevation" [] + $ "Mohave.Pool Elevation" [@"t - 1"] ) / 2.00000000 - "TableInterpolation"( $ "Mohave.Tailwater Table", 0.00000000, 1.00000000, turbineRelease, @"t" ); END; END; UTILITY_GROUP "Get Data Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "DeadCapacity" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "DeadStorage"]; END; FUNCTION "InactiveCapacity" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "inactiveCapacityStorage"]; END; FUNCTION "LiveCapacity" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "liveCapacityStorage"]; END; FUNCTION "MaxCreditableSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "MeadFloodControlData.CredSpace" ["Credit. Space", STRINGIFY reservoir]; END; FUNCTION "MaxRelease" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN reservoir & "Maximum Controlled Release" [0.00000000, 0.00000000]; END; FUNCTION "MinPowerElev" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "MinPowerElev"]; END; FUNCTION "MinPowerStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ElevationToStorage"( reservoir, "MinPowerElev"( reservoir ) ); END; FUNCTION "MinRelease" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "minRelease"]; END; FUNCTION "MininumSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "MeadFloodControlData.MinSpace" [STRINGIFY reservoir, "Min Space"]; END; FUNCTION "SurplusMonthlyPercent" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion]; END; FUNCTION "MonthlyWeightedInflow" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Returns inflow weights, during January though July only, for Flaming Gorge, Blue Mesa and Navajo. Used in the weighted average calculation of the forecast inflow into these reservoirs."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.wtInflow" ["Weighted Inflow", "GetMonthAsString"( @"t" )]; END; FUNCTION "PreviousElevation" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN reservoir & "Pool Elevation" [@"t - 1"]; END; FUNCTION "PreviousStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN reservoir & "Storage" [@"t - 1"]; END; FUNCTION "RatedPowerElev" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "ratedPowerElev"]; END; FUNCTION "RatedPowerStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ElevationToStorage"( reservoir, "RatedPowerElev"( reservoir ) ); END; FUNCTION "RegressionCoefficient" ( OBJECT reservoir, STRING col ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( "MeadFloodControlData." CONCAT STRINGIFY reservoir ) CONCAT "RegressionCoefficients" ["GetMonthAsString"( @"t" ), col]; END; FUNCTION "RuleCurveStorage" ( OBJECT reservoir, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the rule curve storage for a reservoir based on the month provided."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.BaseRuleCurves" [STRINGIFY reservoir, "GetMonthAsString"( date )]; END; FUNCTION "SystemSpace" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "MeadFloodControlData.Space" [0.00000000, "GetMonthAsString"( @"t" )]; END; FUNCTION "TurbineOverloadElev" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.TurbineOverloadElev" [STRINGIFY reservoir, "OverloadElev"]; END; FUNCTION "WaterAvailableInUpperBasin" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.AvailableWater" []; END; FUNCTION "602aStorageValue" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.value602a" [@"24:00:00 December Max DayOfMonth, Current Year"]; END; END; UTILITY_GROUP "Upper Basin Rule Curve Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeOutflowAtGivenStorage" ( OBJECT reservoir, NUMERIC storage ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "Returns a reservoir's release for a given storage. NOTE: the release is contrained by the reservoir's min and max release."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( reservoir ); MAX_CONSTRAINT "MaxRelease"( reservoir ); BEGIN "SolveOutflow"( reservoir, reservoir & "Inflow" [], storage, "PreviousStorage"( reservoir ), @"t" ); END; FUNCTION "ComputeOutflowAtGivenStorageMeadClimateChange" ( OBJECT reservoir, NUMERIC storage ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "Returns a reservoir's release for a given storage. NOTE: the release is contrained by the reservoir's min and max release."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( reservoir ); BEGIN "SolveOutflow"( reservoir, reservoir & "Inflow" [], storage, "PreviousStorage"( reservoir ), @"t" ) COMMENTED_BY "Max release constraint removed"; END; FUNCTION "ComputeOutflowAtRuleCurveStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "For the reservoir that is passed to this function, the release required to meet the reservoir's rule curve is computed. The release is constratined by the reservoir's min and max release. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( reservoir ); MAX_CONSTRAINT "MaxRelease"( reservoir ); BEGIN "SolveOutflow"( reservoir, reservoir & "Inflow" [], "RuleCurveStorage"( reservoir, @"t" ), reservoir & "Storage" [@"t - 1"], @"t" ); END; FUNCTION "ComputeStorageAtMaxRelease" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( reservoir ); MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN "SolveStorage"( reservoir, reservoir & "Inflow" [], "MaxRelease"( reservoir ), reservoir & "Storage" [@"t - 1"], @"t" ); END; FUNCTION "ComputeStorageAtMinRelease" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( reservoir ); MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN IF ( reservoir & "Storage" [@"t - 1"] + "FlowToVolume"( reservoir & "Inflow" [], @"t" ) - ( "FlowToVolume"( "MinRelease"( reservoir ), @"t" ) + "EstimateEvaporation"( reservoir, reservoir & "Storage" [@"t - 1"], reservoir & "Storage" [@"t - 1"], @"t", @"t" ) ) < 0.00000000 "acre-ft" ) THEN "InactiveCapacity"( reservoir ) ELSE "SolveStorage"( reservoir, reservoir & "Inflow" [], "MinRelease"( reservoir ), reservoir & "Storage" [@"t - 1"], @"t" ) ENDIF; END; FUNCTION "ComputeStorageAtGivenOutflow" ( OBJECT reservoir, NUMERIC outflow ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function returns the storage for a reservoir given its outflow. Before calling the pre-defined function SolveStorage, first check to see if outflow will result in a negative storage. We must do this first because a NaN will be returned if negative storage results inside the SolveStorage function. NOTE: the resulting storage is constrained by the reservoir's live capacity and inactive capacity. If the reservoir is Powell, the minimum constraint is PowellMinimumContent, which is set to 0 acre-feet."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT IF ( ( STRINGIFY reservoir ) == "Powell" ) THEN $ "PowellMinObjRelData.PowellMinimumContent" [] ELSE "InactiveCapacity"( reservoir ) ENDIF; MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN IF ( reservoir & "Storage" [@"t - 1"] + "FlowToVolume"( reservoir & "Inflow" [], @"t" ) - ( "FlowToVolume"( outflow, @"t" ) + "EstimateEvaporation"( reservoir, reservoir & "Storage" [@"t - 1"], reservoir & "Storage" [@"t - 1"], @"t", @"t" ) ) < 0.00000000 "acre-ft" ) THEN "InactiveCapacity"( reservoir ) ELSE "SolveStorage"( reservoir, reservoir & "Inflow" [], outflow, "PreviousStorage"( reservoir ), @"t" ) ENDIF; END; FUNCTION "ComputeStorageAtZeroRelease" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN "SolveStorage"( reservoir, reservoir & "Inflow" [], $ "NIIPSchedule.Diversion Schedule" [], reservoir & "Storage" [@"t - 1"], @"t" ); END; FUNCTION "ComputeTargetSpaceOutflow" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "This function computes the outflow required to meet a reservoir's monthly target space. January through July the target space is based on the inflow forecast through July.
"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ComputeOutflowAtGivenStorage"( reservoir, "LiveCapacity"( reservoir ) - "TargetSpace"( reservoir ) ); END; FUNCTION "DepletionAbove" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the depletion above a reservoir. Used specifically in operations rule for Navajo, Blue Mesa and Flaming Gorge. 0 is returned for Blue Mesa and Flaming Gorge because the depletions are accounted for in the inflow value that is part of the equation in the MaxAllowableStorage function, which calls this function. There is a diversion directly from Navajo and needs to be accounted for separately (not included in the inflow value), which is the purpose of this function."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( ( STRINGIFY reservoir ) == "Navajo" ) THEN "FlowToVolume"( $ "NavajoIndianIrrigationProjectNIIP.Total Diversion Requested" [], @"t" ) ELSE 0.00000000 "acre-feet" ENDIF; END; FUNCTION "CurrentInflowAbove" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the monthly inflow above a reservoir. Used specifically in operations rule for Navajo, Blue Mesa and Flaming Gorge."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( ( STRINGIFY reservoir ) == "Navajo" ) THEN "SumObjectsAggregatedOverTime"( "Above" CONCAT STRINGIFY reservoir, "Inflow", "SUM", "INPUT", TRUE, @"t", @"t" ) ELSE "SumObjectsAggregatedOverTime"( "Above" CONCAT STRINGIFY reservoir, "Inflow", "SUM", "INPUT", TRUE, @"t", @"t" ) + "SumObjectsAggregatedOverTime"( "Above" CONCAT STRINGIFY reservoir, "Local Inflow", "SUM", "INPUT", TRUE, @"t", @"t" ) ENDIF; END; FUNCTION "MaxAllowableStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the the maximum allowable storage (target storage during January through July) based on inflow forecast for current month through July for a given reservoir- Flaming Gorge, Blue Mesa or Navajo. Constrained by reservoir's live capacity and 0 acre-feet."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "LiveCapacity"( reservoir ); MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "PreviousStorage"( reservoir ) - "ReleaseNeeded"( reservoir ) + "CurrentInflowAbove"( reservoir ) - "DepletionAbove"( reservoir ); END; FUNCTION "PredictInflow" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns an inflow forecast during January through July. Forecast is the weighted average of the actual natural inflow through July and the long-term average natural inflow through July. This forecast is used only for Flaming Gorge, Blue Mesa and Navajo operations. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" > @"July" ) THEN 0.00000000 "acre-feet" ELSE "MonthlyWeightedInflow"( ) * "SumActualInflow"( reservoir ) + ( 1.00000000 - "MonthlyWeightedInflow"( ) ) * "SumAveVirginInflow"( reservoir ) ENDIF; END; FUNCTION "ReleaseNeeded" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Based on the inflow forecast computed in PredictInflow, returns the release needed for the current month that results in the reservoir reaching its live capacity storage by July. The release must be at least the reservoir's minimum release."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "Max"( ( reservoir & "Storage" [@"t - 1"] - "LiveCapacity"( reservoir ) + "PredictInflow"( reservoir ) ) / ( 8.00000000 - "GetMonth"( @"t" ) ), "FlowToVolume"( "MinRelease"( reservoir ), @"t" ) ); END; FUNCTION "SumActualInflow" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the sum of the natural flow above a given reservoir from the current month through July."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( % "Qsum" & STRINGIFY reservoir ) []; END; FUNCTION "SumAveVirginInflow" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "For a given reservoir (Flaming Gorge, Blue Mesa, or Navajo) returns the sum of the long-term average natural inflow above that reservoir, for the current month through July."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableRow"( $ "UBRuleCurveData.aveVirginInflow", "GetRowIndex"( $ "UBRuleCurveData.aveVirginInflow", STRINGIFY reservoir ), "GetMonth"( @"t" ) - 1.00000000, 6.00000000 ); END; FUNCTION "TargetSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns the target space for a given reservoir. If August through December, look up space from table. If January through July, determine space based on inflow forecast in MaxAllowableStorage function."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" >= @"24:00:00 August 31, Current Year" ) THEN $ "UBRuleCurveData.targetSpace" [STRINGIFY reservoir, "GetMonthAsString"( @"t" )] ELSE "LiveCapacity"( reservoir ) - "MaxAllowableStorage"( reservoir ) ENDIF; END; END; UTILITY_GROUP "Aspinall Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeCrystalRuleCurveStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( % "Crystal" ); END; FUNCTION "ComputeCrystalRuleCurveRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SolveOutflow"( % "Crystal", $ "Crystal.Inflow" [], "ComputeCrystalRuleCurveStorage"( ), "PreviousStorage"( % "Crystal" ), @"t" ); END; FUNCTION "ComputeMorrowRuleCurveRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SolveOutflow"( % "MorrowPoint", $ "MorrowPoint.Inflow" [], "ComputeMorrowRuleCurveStorage"( ), "PreviousStorage"( % "MorrowPoint" ), @"t" ); END; FUNCTION "ComputeMorrowRuleCurveStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( % "MorrowPoint" ); END; END; UTILITY_GROUP "Navajo Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeMinNavajoStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN "SolveStorage"( % "Navajo", $ "Navajo.Inflow" [], 10.00000000 "acre-feet/month", "PreviousStorage"( % "Navajo" ), @"t" ); END; FUNCTION "NIIPMinDiversionStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ElevationToStorage"( % "Navajo", $ "NIIPSchedule.MinDiversionElev" [0.00000000, 0.00000000] ); END; FUNCTION "NIIPDiversionRatio" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "NIIPSchedule.Diversion Schedule" [] == 0.00000000 "acre-feet/month" ) THEN 0.00000000 ELSE $ "NIIPSchedule.Depletion Schedule" [] / $ "NIIPSchedule.Diversion Schedule" [] ENDIF; END; FUNCTION "ShortNIIPDiversion" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "NIIPSchedule.Diversion Schedule" [] - "VolumeToFlow"( "NIIPMinDiversionStorage"( ) - "ComputeStorageAtZeroRelease"( % "Navajo" ), @"t" ); END; END; UTILITY_GROUP "EOWY Forecast Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "EOWYStorage" ( OBJECT reservoir, NUMERIC powellRelease, NUMERIC meadRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function estimates the End of Water Year (end of September) storage for Powell and Mead, with the given release from Powell and Mead. by subtracting
the estimated evaporation and bankstorage from the given release. This function is used in conjunction with equalization."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT IF ( ( STRINGIFY reservoir ) == "Powell" ) THEN $ "PowellMinObjRelData.PowellMinimumContent" [] ELSE "InactiveCapacity"( reservoir ) ENDIF; MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN IF ( ( STRINGIFY reservoir ) == "Powell" ) THEN "InitialEOWYStoragePowell"( powellRelease ) - "EstimateEvaporation"( reservoir, "PreviousStorage"( reservoir ), "Min"( "InitialEOWYStoragePowell"( powellRelease ), "LiveCapacity"( reservoir ) ), @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) - "EstimateBankStorage"( reservoir, "PreviousStorage"( reservoir ), "InitialEOWYStoragePowell"( powellRelease ) ) ELSE "InitialEOWYStorageMead"( powellRelease, meadRelease ) - "EstimateEvaporation"( reservoir, "PreviousStorage"( reservoir ), "Min"( "InitialEOWYStorageMead"( powellRelease, meadRelease ), "LiveCapacity"( reservoir ) ), @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) - "EstimateBankStorage"( reservoir, "PreviousStorage"( reservoir ), "InitialEOWYStorageMead"( powellRelease, meadRelease ) ) ENDIF; END; FUNCTION "InitialEOWYStorageMead" ( NUMERIC powellRelease, NUMERIC meadRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( @"t" == @"24:00:00 September Max DayOfMonth, Current Year" ) THEN "PreviousStorage"( % "Mead" ) + powellRelease - meadRelease - "SumFlowsToVolume"( $ "SNWPDiversion.Total Depletion Requested", @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) + $ "EqualizationData.GlenToHoover" [0.00000000, "GetMonthAsString"( @"t" )] ELSE "PreviousStorage"( % "Mead" ) + powellRelease - meadRelease - "SumFlowsToVolume"( $ "SNWPDiversion.Total Depletion Requested", @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) + ( $ "EqualizationData.GlenToHoover" [0.00000000, "GetMonthAsString"( @"t" )] + "SumTableRow"( $ "EqualizationData.GlenToHoover", 0.00000000, "Max"( "GetMonth"( @"t" ), 7.00000000 ), 8.00000000 ) ) ENDIF; END; FUNCTION "InitialEOWYStoragePowell" ( NUMERIC powellRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "PreviousStorage"( % "Powell" ) + "ForecastPowellInflow"( ) - powellRelease; END; FUNCTION "ForecastPowellInflow" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" <= @"July" ) THEN $ "PowellForecastData.Reg Inflow with Error" [] + "PowellRegulatedInflowVolume"( @"24:00:00 August Max DayOfMonth, Current Year", @"24:00:00 September Max DayOfMonth, Current Year" ) ELSE IF ( @"Current Month" == @"August" ) THEN "FlowToVolume"( $ "Powell.Inflow" [], @"t" ) + "PowellRegulatedInflowVolume"( @"24:00:00 September Max DayOfMonth, Current Year", @"24:00:00 September Max DayOfMonth, Current Year" ) ELSE "FlowToVolume"( $ "Powell.Inflow" [], @"t" ) ENDIF ENDIF; END; FUNCTION "PowellRegulatedInflowVolume" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the regulated inflow into Powell, from the startDate through the endDate.
No forecast error is used."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "PowellNaturalInflowVolume"( startDate, endDate ) - "UBDepletionsRange"( startDate, endDate ) - "UBRegulation"( startDate, endDate ); END; FUNCTION "PowellNaturalInflowVolume" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( $ "TotVal.Powell", startDate, endDate ); END; FUNCTION "UBDepletionsRange" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.UBDepletion" [@"24:00:00 December Max DayOfMonth, Current Year"] * "SumTableRow"( $ "MeadFloodControlData.UBDist", 0.00000000, "GetMonth"( startDate ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ); END; FUNCTION "UBRegulation" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( OBJECT reservoir IN "ListSubbasin"( "UBEffectiveStorageReservoirs" ) ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "UBDrawDown"( reservoir, startDate, endDate ) ENDFOR; END; FUNCTION "UBDrawDown" ( OBJECT reservoir, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "UBTargetStorage"( reservoir, endDate ) - "UBInitialStorage"( reservoir, startDate ); END; FUNCTION "UBTargetStorage" ( OBJECT reservoir, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the target storage from the live capacity and target space
for the Upper Basin reservoirs."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.ReservoirData" [STRINGIFY reservoir, "liveCapacityStorage"] - $ "UBRuleCurveData.targetSpace" [STRINGIFY reservoir, "GetMonth"( date ) - 1.00000000]; END; FUNCTION "UBInitialStorage" ( OBJECT reservoir, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( date > @"t" ) THEN "UBTargetStorage"( reservoir, "OffsetDate"( date, - 1.00000000, "1 Months" ) ) ELSE reservoir & "Storage" ["OffsetDate"( date, - 1.00000000, "1 Months" )] ENDIF; END; FUNCTION "ForecastMeadRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDemandsDownstreamofMead"( ) - "SumInflowBelowMead"( ) + "ComputeEqualizationEvaporation"( % "Mohave", @"t" TO @"24:00:00 September Max DayOfMonth, Current Year" ) + "ComputeEqualizationEvaporation"( % "Havasu", @"t" TO @"24:00:00 September Max DayOfMonth, Current Year" ) + "EqualizationRuleCurveStorage"( % "Havasu" ) + "EqualizationRuleCurveStorage"( % "Mohave" ); END; FUNCTION "ComputeEqualizationEvaporation" ( OBJECT reservoir, LIST dates ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN dates ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "EstimateEvaporation"( reservoir, "RuleCurveStorage"( reservoir, date - 1.00000000 "month" ), "RuleCurveStorage"( reservoir, date ), date, date ) ENDFOR; END; FUNCTION "EqualizationRuleCurveStorage" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "RuleCurveStorage"( reservoir, @"24:00:00 September Max DayOfMonth, Current Year" ) - "PreviousStorage"( reservoir ); END; FUNCTION "SumDemandsDownstreamofMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "I changed this function 2/26/2000 to add in Coachella and IID as they are now not included in the Below Mead sub-basin since they may be surplused.
Also, CRSS did some funky thing and only used the current timesteps MWD and CAP diversion schedule, and looked in the past year for the rest of the schedule.
It probably was because it didn't know whether they were surplused or not. Since we do, I changed this function to just sum what's on the slots."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDepletionsBelowVolume"( % "Mead", @"t", @"24:00:00 September 30, Current Year" ) + "SumFlowsToVolume"( $ "MWDDiversion.Total Depletion Requested", @"t", @"24:00:00 September 30, Current Year" ) + "SumFlowsToVolume"( $ "CAPDiversion.Total Depletion Requested", @"t", @"24:00:00 September 30, Current Year" ) + "SumFlowsToVolume"( $ "MexicoDiversion.Total Depletion Requested", @"t", @"24:00:00 September 30, Current Year" ) + "SumFlowsToVolume"( $ "CoachellaDiversion.Total Depletion Requested", @"t", @"24:00:00 September 30, Current Year" ) + "SumFlowsToVolume"( $ "IIDDiversion.Total Depletion Requested", @"t", @"24:00:00 September 30, Current Year" ) + "TotalOtherPriority4ActualUse"( @"t", @"24:00:00 September 30, Current Year" ) + "TotalPriority2and3ActualUse"( @"t", @"24:00:00 September 30, Current Year" ) COMMENTED_BY "Priority 1 Users included in Below Mead subbasin"; END; FUNCTION "ForecastPowellRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" <= @"July" ) THEN "PowellSpringOutflowVolConstrained"( ) + "ForecastPowellFallRangeOutflowVolume"( "ForecastPowellJulyStorage"( ), @"24:00:00 August 31, Current Year", @"24:00:00 September 30, Current Year" ) ELSE "ForecastPowellFallRangeOutflowVolume"( $ "Powell.Storage" [@"t - 1"], @"t", @"24:00:00 September 30, Current Year" ) ENDIF; END; FUNCTION "ForecastPowellFallRangeOutflowVolume" ( NUMERIC initialStorage, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Forecasts the Powell outflow volume for a range of months in the fall drawdown period.
The Min Constraint has been altered from just the 823 pattern to actually consider how much water is left
in the Minimum Objective release, and also considers the minimum flow constraint."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "Max"( "PowellMinObjRelVolumeFall"( startDate, endDate ), "MinReleaseVolume"( % "Powell", startDate, endDate ) ); MAX_CONSTRAINT "MaxReleaseVolume"( % "Powell", startDate, endDate ); BEGIN "PowellFallOutflowVolume"( initialStorage, startDate, @"24:00:00 December 31, Current Year" ) * ( "PowellSumReleaseWeights"( startDate, endDate ) / "PowellSumReleaseWeights"( startDate, @"24:00:00 December 31, Current Year" ) ); END; FUNCTION "ForecastPowellJulyStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "forecasts the Powell july storage at the current timestep by using the spring operation, execpt that the forecasted outflow volume
is contrainied by the min release volume, min objective release volume, and the max release volume."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( % "Powell" ); MAX_CONSTRAINT "LiveCapacity"( % "Powell" ); BEGIN $ "Powell.Storage" [@"t - 1"] + $ "PowellForecastData.Reg Inflow with Error" [] - "PowellSpringOutflowVolConstrained"( ) - "EstimateEvaporation"( % "Powell", $ "Powell.Storage" [@"t - 1"], "UBTargetStorage"( % "Powell", @"24:00:00 July Max DayOfMonth, Current Year" ), @"t", @"24:00:00 July Max DayOfMonth, Current Year" ) - "Estimate Bank Storage without Evap"( % "Powell", $ "Powell.Storage" [@"t - 1"], "UBTargetStorage"( % "Powell", @"24:00:00 July Max DayOfMonth, Current Year" ) ); END; FUNCTION "PowellSpringOutflowVolConstrained" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "Max"( "MinReleaseVolume"( % "Powell", @"t", @"24:00:00 July Max DayOfMonth, Current Year" ), "PowellMinObjRelVolumeSpring"( @"24:00:00 July Max DayOfMonth, Current Year" ) ); MAX_CONSTRAINT "MaxReleaseVolume"( % "Powell", @"t", @"24:00:00 July Max DayOfMonth, Current Year" ); BEGIN "PowellSpringOutflowVolume"( ); END; FUNCTION "ComputeScheduledMinObjRelRemainingThruSept" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, "GetMonth"( @"t" ) - 1.00000000, 8.00000000 ); END; FUNCTION "PowellMinObjRelVolumeFall" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS " acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "PowellMinObjRelVolRemaining"( ) * ( "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, "GetMonth"( startDate ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ) / "ComputeScheduledMinObjRelRemainingThruSept"( ) ); END; END; UTILITY_GROUP "602a Storage Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "602aStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( "ShortedUBDepletion"( ) + "AnnualMinObjectiveRelease"( ) - $ "EqualizationData.CPNaturalFlowLeesFerry" [0.00000000, 0.00000000] ) * $ "EqualizationData.CriticalPeriod" [0.00000000, 0.00000000] + $ "EqualizationData.MinPowerPoolUB" [0.00000000, 0.00000000]; END; FUNCTION "AnnualMinObjectiveRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, 0.00000000, 11.00000000 ); END; FUNCTION "ShortedUBDepletion" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( "CriticalPeriodUBDepletion"( ) / $ "EqualizationData.CriticalPeriod" [0.00000000, 0.00000000] + $ "EqualizationData.UBEvaporation" [0.00000000, 0.00000000] ) * ( 1.00000000 - $ "EqualizationData.PercentShortage" [0.00000000, 0.00000000] ); END; FUNCTION "CriticalPeriodUBDepletion" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Replaced Tcl function: CriticalPeriodUBDepletion (3/1/04)
From the current year to as many years into the future as the critical period, the
UB Depletions are summed. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumSlot"( $ "EqualizationData.UBDepletion", @"24:00:00 December Max DayOfMonth, Current Year", "OffsetDate"( @"24:00:00 December Max DayOfMonth, Previous Year", $ "EqualizationData.CriticalPeriod" [0.00000000, 0.00000000], "1 years" ) ); END; END; UTILITY_GROUP "Powell General Operation Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "PowellComputeStorageAtGivenOutflow" ( NUMERIC outflow ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Returns Powell's storage for a given outflow. First checks that there is enough storage in Powell for the given outflow. If there isn't enough, set Powell's storage to 0. This check is required for hydrologic sequences that take Powell this low. RiverWare's SolveStorage function will return a NaN if a negative storage is computed. NOTE: the final storage is constrained by Powell's minimum content, 0 and live capacity."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT $ "PowellMinObjRelData.PowellMinimumContent" []; MAX_CONSTRAINT "LiveCapacity"( % "Powell" ); BEGIN IF ( "SolveStorage"( % "Powell", % "Powell" & "Inflow" [], 0.00000000 "acre-ft/month", "PreviousStorage"( % "Powell" ), @"t" ) < "FlowToVolume"( outflow, @"t" ) ) THEN 0.00000000 "acre-ft" ELSE "SolveStorage"( % "Powell", % "Powell" & "Inflow" [], outflow, "PreviousStorage"( % "Powell" ), @"t" ) ENDIF; END; FUNCTION "PowellMinObjRelforCurrentMonth" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Powell" ); BEGIN "VolumeToFlow"( "PowellMinObjRelVolRemaining"( ) * ( $ "UBRuleCurveData.PowellMinObjectiveRelease" [0.00000000, "GetMonth"( @"t" ) - 1.00000000] / "ComputeMinObjReleaseRemaining"( ) ), @"t" ); END; FUNCTION "PowellMinObjRelVolRemaining" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "AnnualMinObjectiveRelease"( ) - "ReleaseMade"( ); END; FUNCTION "PowellRunoffSeasonStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function takes the computed runoff season release and computes the resulting storage given the inflow
at the current timestep. The ComputeStorage function also checks it to be sure that the resulting storage is between
inactive and live capacity."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( % "Powell" ); MAX_CONSTRAINT "LiveCapacity"( % "Powell" ); BEGIN "PowellComputeStorageAtGivenOutflow"( "PowellComputeRunoffSeasonRelease"( ) ); END; FUNCTION "PowellFallSeasonStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function takes the computed fall season release and computes the resulting storage given
the inflow for the current month. The ComputeStorage function also checks to be sure that the
resulting storage is between live and inactive capacity."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( % "Powell" ); MAX_CONSTRAINT "LiveCapacity"( % "Powell" ); BEGIN "PowellComputeStorageAtGivenOutflow"( "PowellComputeFallSeasonRelease"( ) ); END; FUNCTION "PowellComputeRunoffSeasonRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "cfs"; DESCRIPTION "This function computes the release for the month, from the spring outflow volume and the release
weights. It is constrained by the minimum and maximum release.
On March 4, 2000, TJF added the check to see if the outflow volume average (equally distributed over the remaining
months) exceeds a check (currently 1 maf). If so, we want to just equally weight the outflow for the remaining months.
This was added for high forecast years, where we really would want to start dumping the water quicker than what the
current weights would have us do."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Powell" ); MAX_CONSTRAINT "MaxRelease"( % "Powell" ); BEGIN IF ( "PowellSpringOutflowAverage"( ) > $ "UBRuleCurveData.Powell Outflow Check" [0.00000000, 0.00000000] ) THEN "PowellSpringOutflowAverage"( ) ELSE "VolumeToFlow"( "PowellSpringOutflowVolume"( ) * "PowellReleaseFraction"( @"t", @"24:00:00 July Max DayOfMonth, Current Year" ), @"t" ) ENDIF; END; FUNCTION "PowellSpringOutflowVolume" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Powell.Storage" [@"t - 1"] - "UBTargetStorage"( % "Powell", @"24:00:00 July 31, Current Year" ) + $ "PowellForecastData.Reg Inflow with Error" [] - "EstimateEvaporation"( % "Powell", $ "Powell.Storage" [@"t - 1"], "UBTargetStorage"( % "Powell", @"24:00:00 July 31, Current Year" ), @"t", @"24:00:00 July 31, Current Year" ) - "Estimate Bank Storage without Evap"( % "Powell", $ "Powell.Storage" [@"t - 1"], "UBTargetStorage"( % "Powell", @"24:00:00 July 31, Current Year" ) ); END; FUNCTION "PowellFallOutflowVolume" ( NUMERIC initialStorage, DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the outflow volume from Powell from the current month through December necessary to meet the December target.
It assums a perfect forecast."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN initialStorage - "UBTargetStorage"( % "Powell", endDate ) + "PowellRegulatedInflowVolume"( startDate, endDate ) - "EstimateEvaporation"( % "Powell", initialStorage, "UBTargetStorage"( % "Powell", endDate ), startDate, endDate ) - "Estimate Bank Storage without Evap"( % "Powell", initialStorage, "UBTargetStorage"( % "Powell", endDate ) ); END; FUNCTION "PowellReleaseFraction" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "This function computes the release fraction for the current month. Since the tables are indexed from zero,
we have to subtract 1 from the numeric month."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "UBRuleCurveData.Outflow Weights" [0.00000000, "GetMonth"( startDate ) - 1.00000000] / "SumTableRow"( $ "UBRuleCurveData.Outflow Weights", 0.00000000, "GetMonth"( startDate ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ); END; FUNCTION "PowellComputeFallSeasonRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "This function computes the release for the month, from the fall outflow volume and the
release weights. It is constrained by the miniumu and maximum releases."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Powell" ); MAX_CONSTRAINT "MaxRelease"( % "Powell" ); BEGIN "VolumeToFlow"( "PowellFallOutflowVolume"( $ "Powell.Storage" [@"t - 1"], @"t", @"24:00:00 December Max DayOfMonth, Current Year" ) * "PowellReleaseFraction"( @"t", @"24:00:00 December Max DayOfMonth, Current Year" ), @"t" ); END; FUNCTION "Estimate Bank Storage without Evap" ( OBJECT reservoir, NUMERIC startStorage, NUMERIC endStorage ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Function to estimate the change in bank storage, given a starting and ending storage.
This is different from the function Estimate Bank Storage. In that function, the evaporation
is also estimated and subtracted from the ending storage. why I don't know."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( endStorage - startStorage ) * reservoir & "Bank Storage Coefficient" [0.00000000, 0.00000000]; END; FUNCTION "BypassCapacity" ( NUMERIC elevation ) RETURN_TYPE NUMERIC; SCALE_UNITS "1 cfs"; DESCRIPTION "The Bypass Tube Capacity table is per tube, and there are 4 tubes at Powell. This assumes all tubes are always available."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TableInterpolation"( $ "PowellMinObjRelData.Bypass Tube Capacity", 0.00000000, 1.00000000, ( elevation + $ "Powell.Pool Elevation" [@"t - 1"] ) / 2.00000000, @"t" ) * 4.00000000; END; FUNCTION "IterateBypassCapacity" ( NUMERIC elevation ) RETURN_TYPE NUMERIC; SCALE_UNITS "1 cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN WHILE ( "Abs"( capacity - "BypassCapacity"( "StorageToElevation"( % "Powell", "SolveStorage"( % "Powell", $ "Powell.Inflow" [], capacity, $ "Powell.Storage" [@"t - 1"], @"t" ) ) ) ) > 50.00000000 "cfs" ) WITH NUMERIC capacity = "BypassCapacity"( elevation ) DO "BypassCapacity"( "StorageToElevation"( % "Powell", "SolveStorage"( % "Powell", $ "Powell.Inflow" [], capacity, $ "Powell.Storage" [@"t - 1"], @"t" ) ) ) ENDWHILE; END; END; UTILITY_GROUP "Powell Guidelines Operation Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "CheckEqualizationRelease_Mead1105" ( NUMERIC equalizationRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "This function checks the EQ release to ensure that it doesn't cause Powell to go below the EQ Line, unless Mead is less than 1105. If Mead is less than 1105, Powell releases more until the first of the following 3 occurs: 1) the reservoirs are equal 2) Mead is at 1105 3) Powell is 20' below the EQ Line. Then a final check is made that the release is at least what would bring Powell to the EQ Line. If Mead is above 1105, then Powell is constrainted to the EQ Line."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( $ "EqualizationData.ForecastEOWYSPowell" [@"t"] - equalizationRelease < $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"] ) THEN IF ( $ "EqualizationData.ForecastEOWYSMead" [@"t"] COMMENTED_BY "Use moving EOWY forecast here for Mead" < "ElevationToStorage"( % "Mead", $ "Coordinated Operation.MeadProtectionElevation" [] ) ) THEN "Max"( $ "EqualizationData.ForecastEOWYSPowell" [@"t"] - $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"], "Min"( "Min"( $ "EqualizationData.ForecastEOWYSPowell" [@"t"] - $ "EqualizationData.Shifted EQ Line" [@"24:00:00 December 31, Current Year"], "ElevationToStorage"( % "Mead", $ "Coordinated Operation.MeadProtectionElevation" [] ) - $ "EqualizationData.ForecastEOWYSMead" [] ), equalizationRelease ) COMMENTED_BY "Returns the minimum release for the following conditions: 1) the release required to Equalize 2) the release required to bring Mead to 1105 3) the release required to take Powell to 20' below the EQ Line." ) COMMENTED_BY "The release must be at least what would bring Powell to the EQ Line. This check is specifically for the condition when Mead is less than 1105 but close enough that Powell doesn't need to release to the EQ Line to get Mead to 1105." ELSE $ "EqualizationData.ForecastEOWYSPowell" [@"t"] - $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"] ENDIF ELSE equalizationRelease ENDIF; END; FUNCTION "ConvertPowellReleaseBalancing" ( LIST equalizationReleaseList ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( "GetListElement"( 0.00000000, equalizationReleaseList ) - "ForecastPowellRelease"( ) ); END; FUNCTION "ComputePowellReleaseUpperBalancing" ( NUMERIC equalizationRelease, STRING minRelease, STRING maxRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "Computes the monthly balancing release from Powell if in either the Upper or Lower Elevation Balancing Tiers. NOTE: the release is constrained by the specified min and max release for that tier. This specified release is the STRING argument minRelease and maxRelease."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "PowellReducedRelforCurrentMonth"( minRelease ); MAX_CONSTRAINT "PowellReducedRelforCurrentMonth"( maxRelease ); BEGIN ( $ "Powell.Outflow" [] + "VolumeToFlow"( equalizationRelease / "NumberMonthsRemaining"( ), @"t" ) ); END; FUNCTION "ComputePowellReleaseLowerBalancing" ( NUMERIC equalizationRelease, STRING minRelease, STRING maxRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "PowellReducedRelforCurrentMonth"( minRelease ); MAX_CONSTRAINT "PowellReducedRelforCurrentMonth"( maxRelease ); BEGIN ( $ "Powell.Outflow" [] + "VolumeToFlow"( equalizationRelease / "NumberMonthsRemaining"( ), @"t" ) ); END; FUNCTION "InUpperElevationBalancingTier" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION "Determines if Powell (based on previous EOCY storage) is in the Upper Elevation Balancing Tier. Returns TRUE if so."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] < $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"] AND $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] >= "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] ) ) THEN TRUE ELSE FALSE ENDIF; END; FUNCTION "InLowerElevationBalancingTier" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION "Determines if Powell (based on previous EOCY storage) is in the Lower Elevation Balancing Tier. Returns TRUE if so."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] < "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellLowerTierElevation" [] ) ) THEN TRUE ELSE FALSE ENDIF; END; FUNCTION "InMidElevationReleaseTier" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION "Determines if Powell (based on previous EOCY storage) is in the Mid Elevation ReleaseTier. Returns TRUE if so."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] < "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellUpperTierElevation" [] ) AND $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] >= "ElevationToStorage"( % "Powell", $ "Coordinated Operation.Hybrid_PowellLowerTierElevation" [] ) ) THEN TRUE ELSE FALSE ENDIF; END; FUNCTION "EqualizationConditionsMet" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "EqualizationData.ForecastEOWYSPowell" [@"24:00:00 April 30, Current Year"] >= $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"] AND $ "EqualizationData.ForecastEOWYSPowell" [] >= $ "EqualizationData.ForecastEOWYSMead" [] ) THEN TRUE ELSE FALSE ENDIF COMMENTED_BY "Checks that both Powell EOWYS forecast is above the EQ Line AND that Powell is greater than Mead."; END; FUNCTION "StartYearInEqualization" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Powell.Storage" [@"24:00:00 December 31, Previous Year"] >= $ "EqualizationData.Equalization Line" [@"24:00:00 December 31, Current Year"] AND $ "EqualizationData.ForecastEOWYSPowell" [] >= $ "EqualizationData.ForecastEOWYSMead" [] ) THEN TRUE ELSE FALSE ENDIF COMMENTED_BY "Checks that Powell EOCY (previous year) is above the EQ Line"; END; FUNCTION "PowellReducedRelforCurrentMonth" ( STRING releaseIndex ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Powell" ); BEGIN "VolumeToFlow"( "PowellReducedRelVolRemaining"( releaseIndex ) * ( $ "Coordinated Operation.Monthly Release Pattern" [releaseIndex, "GetMonth"( @"t" ) - 1.00000000] / "ComputeReducedReleaseRemaining"( releaseIndex ) ), @"t" ); END; FUNCTION "PowellReducedRelVolRemaining" ( STRING releaseIndex ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "AnnualReducedRelease"( releaseIndex ) - "ReleaseMade"( ); END; FUNCTION "ComputeReducedReleaseRemaining" ( STRING releaseIndex ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" < @"October" ) THEN "SumTableRow"( $ "Coordinated Operation.Monthly Release Pattern", "GetRowIndex"( $ "Coordinated Operation.Monthly Release Pattern", releaseIndex ), "GetMonth"( @"t" ) - 1.00000000, 8.00000000 ) ELSE IF ( @"t" == @"October" ) THEN "AnnualReducedRelease"( releaseIndex ) ELSE "AnnualReducedRelease"( releaseIndex ) - "SumTableRow"( $ "Coordinated Operation.Monthly Release Pattern", "GetRowIndex"( $ "Coordinated Operation.Monthly Release Pattern", releaseIndex ), 9.00000000, "GetMonth"( @"t" ) - 2.00000000 ) ENDIF ENDIF; END; FUNCTION "AnnualReducedRelease" ( STRING releaseIndex ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableRow"( $ "Coordinated Operation.Monthly Release Pattern", "GetRowIndex"( $ "Coordinated Operation.Monthly Release Pattern", releaseIndex ), 0.00000000, 11.00000000 ); END; END; UTILITY_GROUP "Powell Equalization Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeEqualizationReleaseList" ( NUMERIC EOWYSPowell, NUMERIC EOWYSMead ) RETURN_TYPE LIST; SCALE_UNITS ""; DESCRIPTION "This function returns a five element list, the order of the list is Equalization Release, Powell Release, EOWY storage for Powell, EOWY storage for Mead,
and a count. The list is initialized with the function InitializedEqualizationReleaseList. Which of course is a five element list in the same
order as above. PER TJF: FEB, 2000: I think this is a 4 element list ... the equalization release is not a part of it."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN WHILE ( "Abs"( "GetListElement"( 1.00000000, result ) - "GetListElement"( 2.00000000, result ) ) > $ "EqualizationData.EqualizationTolerance" [0.00000000, 0.00000000] AND "GetListElement"( 3.00000000, result ) < 30.00000000 ) WITH LIST result = "InitialEqualizationReleaseList"( EOWYSPowell, EOWYSMead ) DO INSERT "TotalPowellRelease"( result ) INTO INSERT "EOWYStorage"( % "Powell", "ComputeNewPowellRelease"( result ), "ForecastMeadRelease"( ) ) INTO INSERT "EOWYStorage"( % "Mead", "TotalPowellRelease"( result ), "ForecastMeadRelease"( ) ) INTO INSERT "GetListElement"( 3.00000000, result ) + 1.00000000 INTO result ENDWHILE; END; FUNCTION "EstimateEqualizationRelease" ( NUMERIC EOWYSPowell, NUMERIC EOWYSMead ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( EOWYSPowell - EOWYSMead ) * 0.50000000; END; FUNCTION "NumberMonthsRemaining" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" < @"October" ) THEN 10.00000000 - "GetMonth"( @"t" ) ELSE 22.00000000 - "GetMonth"( @"t" ) ENDIF; END; FUNCTION "PowellFallRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( $ "Powell.Outflow", @"24:00:00 October 31, Previous Year", @"24:00:00 December 31, Previous Year" ); END; FUNCTION "ReleaseMade" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"January" ) THEN "PowellFallRelease"( ) ELSE IF ( @"t" > @"January" AND @"t" < @"October" ) THEN "SumFlowsToVolume"( $ "Powell.Outflow", @"24:00:00 January 31, Current Year", @"t - 1" ) + "PowellFallRelease"( ) ELSE IF ( @"t" == @"October" ) THEN 0.00000000 "acre-feet" ELSE "SumFlowsToVolume"( $ "Powell.Outflow", @"24:00:00 October 31, Current Year", @"t - 1" ) ENDIF ENDIF ENDIF; END; FUNCTION "SumCurrentDemandsBelowMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "SumDepletionsBelowMead includes only those that are input by the user. we then add to those the ones that the rules set."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDepletionsBelow"( % "Mead", @"t", @"t" ) + $ "MWDDiversion.Total Depletion Requested" [] + $ "CAPDiversion.Total Depletion Requested" [] + $ "CoachellaDiversion.Total Depletion Requested" [] + $ "IIDDiversion.Total Depletion Requested" [] + $ "MexicoDiversion.Total Depletion Requested" [] + "VolumeToFlow"( "TotalOtherPriority4ActualUse"( @"t", @"t" ), @"t" ) + "VolumeToFlow"( "TotalPriority2and3ActualUse"( @"t", @"t" ), @"t" ) COMMENTED_BY "Priority 1 included in Below Mead subbasin"; END; FUNCTION "SumCurrentInflowBelowMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "BelowMead", "Local Inflow", "SUM", "INPUT", FALSE, @"t", @"t" ) + $ "NevadaDesalination.Inflow" [@"t"] COMMENTED_BY "Need to add in Desal local inflow, which is not input."; END; FUNCTION "SumInflowBelowMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( $ "TotVal.Mohave", @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) + "SumFlowsToVolume"( $ "TotVal.Havasu", @"t", @"24:00:00 September Max DayOfMonth, Current Year" ) + "SumFlowsToVolume"( $ "TotVal.Imperial", @"t", @"24:00:00 September Max DayOfMonth, Current Year" ); END; FUNCTION "CheckERMeadExclusiveFCS" ( NUMERIC EOWYSMead, NUMERIC equalizationRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function is used in conjuction with ComputeEqualizationRelease. It is called to check if the computed equalization release will cause Mead to
violate its exclusive flood control space. If the release will cause this violation, a new equalization release is computed as the live capacity of mead
minus the minimum flood control space minus the estimated end of water year storage for Mead. Otherwise no changes to the equalization release
are made. Also note that this function is contrained to have a minumum value of zero."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( EOWYSMead + equalizationRelease > "LiveCapacity"( % "Mead" ) - $ "MeadFloodControlData.MinSpace" [0.00000000, 0.00000000] ) THEN "LiveCapacity"( % "Mead" ) - $ "MeadFloodControlData.MinSpace" [0.00000000, 0.00000000] - EOWYSMead ELSE equalizationRelease ENDIF; END; FUNCTION "CheckEqualizationRelease" ( LIST results ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "CheckERMeadExclusiveFCS"( "GetListElement"( 2.00000000, results ), "EstimateEqualizationRelease"( "GetListElement"( 1.00000000, results ), "GetListElement"( 2.00000000, results ) ) ); END; FUNCTION "ComputeNewPowellRelease" ( LIST results ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalPowellRelease"( results ) + "CheckEqualizationRelease"( results ); END; FUNCTION "TotalPowellRelease" ( LIST results ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "GetListElement"( 0.00000000, results ) + "EstimateEqualizationRelease"( "GetListElement"( 1.00000000, results ), "GetListElement"( 2.00000000, results ) ); END; FUNCTION "CheckEqualizationRelease602a" ( NUMERIC equalizationRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "After the function ComputeEqualizationReleaseList has completed its while loop, which varies Powell's release until a balance between Powell's and Mead EOWY storages are within equalization tolerance. Equalization tolerance is a user input variable and is currently set at 2,000 acre-feet. This value is input on the equalizationTolerance slot in the EqualizationData data object. This function does a final check on the release from Lake Powell to insure that making this release will not violate the upper basin 602a storage. This check is computed by subtracting the value of Powell equalization release (which is represented by the function GetListElement(0,equalizationReleaseList) and the value of ForecastPowellRelease from the amount of storage in the Upper Basin which is computed by the function SumUpperBasinStorage. which is set with a rule and written out to a dataobject slot. this value is then compared to the value of 602a storage that has already been set with another rule. Also note that the results of this check are also constrained by a minimum value of zero. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( $ "EqualizationData.AvailableWater" [] - equalizationRelease < "602aStorageValue"( ) ) THEN $ "EqualizationData.AvailableWater" [] - "602aStorageValue"( ) ELSE equalizationRelease ENDIF; END; FUNCTION "ConvertPowellRelease" ( LIST equalizationReleaseList ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "GetListElement"( 0.00000000, equalizationReleaseList ) - "ForecastPowellRelease"( ); END; FUNCTION "InitialEqualizationReleaseList" ( NUMERIC EOWYSPowell, NUMERIC EOWYSMead ) RETURN_TYPE LIST; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN { "ForecastPowellRelease"( ) , EOWYSPowell , EOWYSMead , 0.00000000 }; END; FUNCTION "ComputeMinObjReleaseRemaining" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" < @"October" ) THEN "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, "GetMonth"( @"t" ) - 1.00000000, 8.00000000 ) ELSE IF ( @"t" == @"October" ) THEN "AnnualMinObjectiveRelease"( ) ELSE "AnnualMinObjectiveRelease"( ) - "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, 9.00000000, "GetMonth"( @"t" ) - 2.00000000 ) ENDIF ENDIF; END; FUNCTION "PowellMinObjRelVolumeSpring" ( DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Estimates the volume of minimum objective release remaining from the current timestep through the endDate
and scales it by the ratio of the amount remaining through EWOY to the annual value."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN "PowellMinObjRelVolRemaining"( ) * ( "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, "GetMonth"( @"t" ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ) / "ComputeScheduledMinObjRelRemainingThruSept"( ) ); END; FUNCTION "ComputePowellRelease" ( NUMERIC equalizationRelease ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Powell" ); MAX_CONSTRAINT $ "Coordinated Operation.Powell Max ROD Release" []; BEGIN $ "Powell.Outflow" [] + "VolumeToFlow"( equalizationRelease / "NumberMonthsRemaining"( ), @"t" ); END; FUNCTION "PowellSumReleaseWeights" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumTableRow"( $ "UBRuleCurveData.Outflow Weights", 0.00000000, "GetMonth"( startDate ) - 1.00000000, "GetMonth"( endDate ) - 1.00000000 ); END; FUNCTION "SumUpperBasinStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.ForecastEOWYSPowell" [] + FOR ( OBJECT reservoir IN { % "FlamingGorge" , % "BlueMesa" , % "Navajo" } ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "PreviousStorage"( reservoir ) ENDFOR; END; END; UTILITY_GROUP "Powell Spike Flow Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "SpikeAlreadyMade" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN "GetDates"( @"24:00:00 January Max DayOfMonth, Current Year", @"t - 1", "1 MONTHS" ) ) WITH BOOLEAN result = FALSE DO IF ( $ "Powell Spike Flow Data.Spike Flow Flag" [date] == 1.00000000 ) THEN TRUE ELSE FALSE ENDIF ENDFOR; END; FUNCTION "CheckSpikeFlowCriteria" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"Current Month" == @"January" AND $ "PowellForecastData.Unreg Inflow with Error" [] > $ "Powell Spike Flow Data.January Volume Trigger" [0.00000000, 0.00000000] ) THEN TRUE ELSE IF ( $ "Powell.Outflow" [] > $ "Powell Spike Flow Data.Outflow Trigger" [0.00000000, 0.00000000] ) THEN TRUE ELSE IF ( "PowellSpringOutflowAverage"( ) > $ "Powell Spike Flow Data.Outflow Trigger" [0.00000000, 0.00000000] ) THEN TRUE ELSE FALSE ENDIF ENDIF ENDIF; END; FUNCTION "PowellSpringOutflowAverage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "VolumeToFlow"( "PowellSpringOutflowVolume"( ) / ( ( "GetMonth"( @"24:00:00 July Max DayOfMonth, Current Year" ) - "GetMonth"( @"t" ) ) + 1.00000000 ), @"t" ); END; FUNCTION "PowellMinSpikeFlowOutflow" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT $ "Powell Spike Flow Data.Outflow Trigger" [0.00000000, 0.00000000]; BEGIN $ "Powell.Outflow" []; END; END; UTILITY_GROUP "Set Mead Outflow For Demands Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeDemandsBelow" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "For the reservoir that is passed to this function, the total demand (in flow) below that reservoir is computed. The NetSubBasinDiverionRequirement() pre-defined looks at reach objects in the SubBasin argument and returns the minimum inflow required to meet all the diversion requests and minimum flows on that that reach, i.e. return flows and local inflows are considered. The reservoir must be capable of releasing for the demand, so the value is constrained by the reservoir's max release. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "MaxRelease"( reservoir ); BEGIN "Max"( "NetSubBasinDiversionRequirement"( "ListSubbasin"( "Below" CONCAT STRINGIFY reservoir ), @"t" ), 0.00000000 "acre-feet/month" ); END; FUNCTION "CurrentDemandBelowMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "MinRelease"( % "Mead" ); MAX_CONSTRAINT "MaxRelease"( % "Mead" ); BEGIN "SumCurrentDemandsBelowMead"( ) + "VolumeToFlow"( ( "RuleCurveStorage"( % "Havasu", @"t" ) - "PreviousStorage"( % "Havasu" ) ), @"t" ) + "VolumeToFlow"( ( "RuleCurveStorage"( % "Mohave", @"t" ) - "PreviousStorage"( % "Mohave" ) ), @"t" ) + "VolumeToFlow"( "EstimateEvapForDownstreamDemands"( % "Havasu", "PreviousStorage"( % "Havasu" ), "RuleCurveStorage"( % "Havasu", @"t" ) ), @"t" ) + "VolumeToFlow"( "EstimateEvapForDownstreamDemands"( % "Mohave", "PreviousStorage"( % "Mohave" ), "RuleCurveStorage"( % "Mohave", @"t" ) ), @"t" ) - "SumCurrentInflowBelowMead"( ); END; END; UTILITY_GROUP "Mexico Shortage Functions"; DESCRIPTION ""; ACTIVE FALSE; BEGIN FUNCTION "ComputeMexicoDiversionUBShortOnly" ( DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "MexicoSchedule.Diversion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "MexicoShortageSensitivity.AnnualTreatyDelivery" [] * "ComputeMexicoShortagePercent"( 0.00000000 "acre-ft" ) ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"], date ); END; FUNCTION "ComputeMexicoDepletionUBShortOnly" ( DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "MexicoSchedule.Depletion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "MexicoShortageSensitivity.AnnualTreatyDelivery" [] * "ComputeMexicoShortagePercent"( 0.00000000 "acre-ft" ) ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "Mexico"], date ); END; FUNCTION "ComputeMexicoShortagePercent" ( NUMERIC LBShortageAmount ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG FALSE; POST_EXEC_DIAG FALSE; BEGIN ( LBShortageAmount + $ "MexicoShortageSensitivity.AnnualUpperBasinShortage_Adj" [@"24:00:00 December 31, Current Year"] ) / ( $ "MexicoShortageSensitivity.AnnualUSLowerBasinApportionment" [] + $ "EqualizationData.UBDepletion" [@"24:00:00 December 31, Current Year"] ); END; END; UTILITY_GROUP "70R Surplus Release Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "AnnualEvaporation" ( OBJECT reservoir, LIST dates ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN dates ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "EstimateEvaporation"( reservoir, "RuleCurveStorage"( reservoir, date ), "RuleCurveStorage"( reservoir, date ), date, date ) ENDFOR; END; FUNCTION "ComputeSurplusDepletion" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "VolumeToFlow"( "No Action Annual Surplus Schedules." CONCAT diversion CONCAT " Surplus Schedule" [@"24:00:00 December Max DayOfMonth, Current Year"] * "SurplusMonthlyPercent"( diversion, date ), date ); END; FUNCTION "ComputeSurplusDiversion" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "Function to compute the monthly diversion surplus amount. For SNWP, we assume that they will consume 100% of the extra
surplus volume. So we compute a surplus delta (surplus depletion - normal depletion) and add that to the normal diversion.

For the other diversions (MWD, CAP, Coachella, IID), they consume what they divert."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN $ "SNWPSchedule.Diversion Schedule" [date] + ( "ComputeSurplusDepletion"( diversion, date ) - $ "SNWPSchedule.Depletion Schedule" [date] ) ELSE "ComputeSurplusDepletion"( diversion, date ) ENDIF; END; FUNCTION "SumLBDemands" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDemandsDownstreamOfPowell"( ) + ( "AnnualEvaporation"( % "Havasu", @"24:00:00 January 31, Current Year" TO @"24:00:00 December 31, Current Year" ) + "AnnualEvaporation"( % "Mohave", @"24:00:00 January 31, Current Year" TO @"24:00:00 December 31, Current Year" ) ) + $ "Surplus.AverageMeadEvaporation" [0.00000000, 0.00000000] - $ "Surplus.AverageAnnualGainPowellToMead" [0.00000000, 0.00000000] - $ "Surplus.AverageAnnualGainBelowMead" [0.00000000, 0.00000000]; END; FUNCTION "SumUBDemands" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.UBDepletion" [@"24:00:00 December Max DayOfMonth, Current Year"] + $ "EqualizationData.UBEvaporation" [0.00000000, 0.00000000]; END; FUNCTION "SumDemandsDownstreamOfPowell" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "The original CRSS did not include CAP and MWD in this calculation, SumDepletionsBelowVolume with Mead includes every diversion below Mead with the exception of SNWP, CAP, MWD,
and Mexico. therefore the annual volume of SNWP and Mexico depletion schedules are added to match CRSS results. This seems to be a very bad calculation and I would recommend that
it be examined closely in conjuction with all of the functions that sum demands into the future such as SumDemandsDownstreamOfMead, and SumDemandsBelowMead and
SumCurrentDemandsBelowMead, to see if a common function could replace all of these. It is not possible now in order to match CRSS results.

The above comments was due to Brad Vickers, Wave Eng. On Feb 26, 2000, Terry Fulp changed this function to include MWD, CAP, and Coachella and IID, as they are now
beiing surplused."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDepletionsBelowVolume"( % "Mead", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) + "AnnualVolume"( $ "SNWPSchedule.Depletion Schedule" ) + "AnnualVolume"( $ "MexicoSchedule.Depletion Schedule" ) + "AnnualVolume"( $ "CAPSchedule.Depletion Schedule" ) + "AnnualVolume"( $ "CoachellaSchedule.Depletion Schedule" ) + "AnnualVolume"( $ "IIDSchedule.Depletion Schedule" ) + "AnnualVolume"( $ "MWDSchedule.Input Depletion Schedule" ) + "TotalOtherPriority4ScheduledUse"( @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) + "TotalPriority2and3ScheduledUse"( @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ); END; FUNCTION "SurplusMaxStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( % "Mead" ) + "LiveCapacity"( % "Powell" ) - 0.70000000 * $ "MeadFloodControlData.Space" [0.00000000, "GetMonthAsString"( @"24:00:00 December Max DayOfMonth, Current Year" )]; END; FUNCTION "ComputeInflowAtProbability" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "Replaced Tcl function: ComputeInflowAtProbability (3/1/04)
-Returns the inflow at a specified assurance probability"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Surplus.AssuranceProb" [0.00000000, 0.00000000] > 0.50000000 ) THEN $ "Surplus.AnnualAvgLeesFerryFlow" [0.00000000, 0.00000000] + ( "GetT"( ) - "GetNumerator"( ) / "GetDenominator"( ) ) * $ "Surplus.StdDevLeesFerryFlow" [0.00000000, 0.00000000] ELSE $ "Surplus.AnnualAvgLeesFerryFlow" [0.00000000, 0.00000000] - ( ( "GetT"( ) - "GetNumerator"( ) / "GetDenominator"( ) ) * $ "Surplus.StdDevLeesFerryFlow" [0.00000000, 0.00000000] ) ENDIF; END; FUNCTION "GetT" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Surplus.AssuranceProb" [0.00000000, 0.00000000] > 0.50000000 ) THEN "Exp"( - 2.00000000 * "Ln"( 1.00000000 - $ "Surplus.AssuranceProb" [0.00000000, 0.00000000], 0.00000000 ), 0.50000000 ) ELSE "Exp"( - 2.00000000 * "Ln"( $ "Surplus.AssuranceProb" [0.00000000, 0.00000000], 0.00000000 ), 0.50000000 ) ENDIF; END; FUNCTION "GetDenominator" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Surplus.probabilityCoeff2" [0.00000000, 0.00000000] + ( $ "Surplus.probabilityCoeff2" [0.00000000, 1.00000000] * "GetT"( ) + $ "Surplus.probabilityCoeff2" [0.00000000, 2.00000000] * "GetT"( ) ^ 2.00000000 ) + $ "Surplus.probabilityCoeff2" [0.00000000, 3.00000000] * "GetT"( ) ^ 3.00000000; END; FUNCTION "GetNumerator" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Surplus.probabilityCoeff1" [0.00000000, 0.00000000] + ( $ "Surplus.probabilityCoeff1" [0.00000000, 1.00000000] * "GetT"( ) + $ "Surplus.probabilityCoeff1" [0.00000000, 2.00000000] * "GetT"( ) ^ 2.00000000 ); END; END; UTILITY_GROUP "Mead Flood Control Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeMinMeadFloodRelease" ( NUMERIC level ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"24:00:00 July Max DayOfMonth, Current Year" ) THEN "MeadMinReleaseWithoutFloodControl"( ) ELSE "MeadMinReleaseWithoutFloodControl"( ) - "FloodControlLevelVolume"( @"t + 1" TO @"24:00:00 July Max DayOfMonth, Current Year", level ) ENDIF; END; FUNCTION "ComputeMinimumSpace" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "LiveCapacity"( reservoir ) - "MininumSpace"( reservoir ); END; FUNCTION "ComputeTargetStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ComputeOutflowAtGivenStorage"( % "Mead", "SpaceBuilding"( ) ) > $ "MeadFloodControlData.MaxRelease" [0.00000000, 0.00000000] ) THEN "ComputeStorageAtGivenOutflow"( % "Mead", $ "MeadFloodControlData.MaxRelease" [0.00000000, 0.00000000] ) ELSE "SpaceBuilding"( ) ENDIF; END; FUNCTION "DeltaBankStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Mead.Bank Storage Coefficient" [0.00000000, 0.00000000] * ( "AvailableSpace"( % "Mead" ) - $ "MeadFloodControlData.MinSpace" [0.00000000, 0.00000000] ) + $ "Powell.Bank Storage Coefficient" [0.00000000, 0.00000000] * "AvailableSpace"( % "Powell" ); END; FUNCTION "FirstMonthSouthernNevConsumed" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FlowToVolume"( $ "SNWPSchedule.Depletion Schedule" [], @"t" ) - "FlowToVolume"( ( $ "SNWPSchedule.Depletion Schedule" [] - $ "SNWPDiversion.Total Depletion Requested" [] ), @"t" ) * "SouthernNevRatio"( ); END; FUNCTION "FloodControlEvap" ( OBJECT reservoir ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FlowToVolume"( "StorageToArea"( reservoir, "LiveCapacity"( reservoir ) - "AvailableSpace"( reservoir ) / 2.00000000 ) * "SumEvapCoeff"( reservoir, "GetMonth"( @"t" ) - 1.00000000, 6.00000000 ), @"t" ); END; FUNCTION "ForecastRunoffSeason" ( ) RETURN_TYPE LIST; SCALE_UNITS "cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN WHILE ( "VolumeToFlow"( "ComputeMinMeadFloodRelease"( ( GET @INDEX 1.00000000 FROM results ) ), @"t" ) > $ "MeadFloodControlData.Levels" [0.00000000, ( GET @INDEX 1.00000000 FROM results )] AND ( GET @INDEX 1.00000000 FROM results ) <= 4.00000000 ) WITH LIST results = { "Max"( "VolumeToFlow"( "ComputeMinMeadFloodRelease"( 0.00000000 ), @"t" ), 0.00000000 "acre-feet/month" ) , 0.00000000 } DO IF ( "VolumeToFlow"( "ComputeMinMeadFloodRelease"( ( GET @INDEX 1.00000000 FROM results ) + 1.00000000 ), @"t" ) <= $ "MeadFloodControlData.Levels" [0.00000000, ( GET @INDEX 1.00000000 FROM results )] ) THEN INSERT $ "MeadFloodControlData.Levels" [0.00000000, ( GET @INDEX 1.00000000 FROM results )] INTO INSERT ( GET @INDEX 1.00000000 FROM results ) + 1.00000000 INTO results ELSE INSERT "Max"( "VolumeToFlow"( "ComputeMinMeadFloodRelease"( ( GET @INDEX 1.00000000 FROM results ) + 1.00000000 ), @"t" ), 0.00000000 "acre-feet/month" ) INTO INSERT ( GET @INDEX 1.00000000 FROM results ) + 1.00000000 INTO results ENDIF ENDWHILE; END; FUNCTION "MeadInflowForecast" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the inflow forcast for Mead in for the flood control release."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "PowellRunoffForecast"( ) + $ "EqualizationData.GlenToHoover" [0.00000000, "GetMonthAsString"( @"t" )] + $ "MeadFloodControlData.Forcmax" ["Forcmax", "GetMonthAsString"( @"t" )] - $ "MeadFloodControlData.Qavg" ["Qavg", "August"] - $ "MeadFloodControlData.Qavg" ["Qavg", "September"] + $ "EqualizationData.UBDepletion" [@"24:00:00 December Max DayOfMonth, Current Year"] * ( $ "MeadFloodControlData.UBDist" [0.00000000, "August"] + $ "MeadFloodControlData.UBDist" [0.00000000, "September"] ); END; FUNCTION "MeadMinReleaseWithoutFloodControl" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "MeadInflowForecast"( ) + $ "Qsum.Mead" [] - ( "AvailableSpace"( % "Mead" ) + "AvailableSpace"( % "Powell" ) ) + $ "MeadFloodControlData.MinSpace" [0.00000000, 0.00000000] - "DeltaBankStorage"( ) - "FloodControlEvap"( % "Mead" ) - "FloodControlEvap"( % "Powell" ) - "SouthernNevConsumed"( ); END; FUNCTION "PowellRunoffForecast" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the runoff forecast into Powell for the current month through September."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "Max"( $ "Qsum.Powell" [] - $ "MeadFloodControlData.PowellForecastError" [] * 1000000.00000000 "acre-feet" + $ "MeadFloodControlData.Qavg" ["Qavg", "August"] + $ "MeadFloodControlData.Qavg" ["Qavg", "September"] - "UBDepletion"( ) - "UBEffectiveStorage"( ), 0.00000000 "acre-feet" ); END; FUNCTION "SpaceBuilding" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "CurrentAvailableSpace"( % "Mead" ) + "UBCreditableSpace"( ) > "SystemSpace"( ) ) THEN "ComputeMinimumSpace"( % "Mead" ) ELSE "LiveCapacity"( % "Mead" ) - "SystemSpace"( ) + "UBCreditableSpace"( ) ENDIF; END; FUNCTION "SouthernNevConsumed" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"24:00:00 July Max DayOfMonth, Current Year" ) THEN "FirstMonthSouthernNevConsumed"( ) ELSE "SumFlowsToVolume"( $ "SNWPSchedule.Depletion Schedule", @"t + 1", @"24:00:00 July Max DayOfMonth, Current Year" ) + "FirstMonthSouthernNevConsumed"( ) ENDIF; END; FUNCTION "SouthernNevRatio" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "SNWPSchedule.Depletion Schedule" [] / $ "SNWPSchedule.Diversion Schedule" []; END; FUNCTION "FloodControlLevelVolume" ( LIST dateList, NUMERIC index ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME date IN dateList ) WITH NUMERIC result = 0.00000000 "acre-feet" DO result + "FlowToVolume"( $ "MeadFloodControlData.Levels" [0.00000000, index], date ) ENDFOR; END; FUNCTION "UBCreditableSpace" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function sums the flood control creditable space for Powell, Flaming Gorge, Navajo, and Blue Mesa These are the upper basin reservoir
with flood control functions."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( OBJECT reservoir IN "ListSubbasin"( "UBCreditableStorageReservoirs" ) ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "Min"( "CurrentAvailableSpace"( reservoir ), "MaxCreditableSpace"( reservoir ) ) ENDFOR; END; FUNCTION "UBDepletion" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "EqualizationData.UBDepletion" [@"24:00:00 December Max DayOfMonth, Current Year"] * "SumTableRow"( $ "MeadFloodControlData.UBDist", 0.00000000, "GetMonth"( @"t" ) - 1.00000000, 8.00000000 ); END; FUNCTION "UBEffectiveStorage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( OBJECT reservoir IN "ListSubbasin"( "UBEffectiveStorageReservoirs" ) ) WITH NUMERIC sum = 0.00000000 "acre-feet" DO sum + "AvailableSpace"( reservoir ) ENDFOR; END; FUNCTION "ComputeMeadSpringFCRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "2/27/2000: Terry Fulp : I added the check that if the computed Runoff Season Release is not great enough to meet surplus
demand downstream of Mead, then we should up that release. We saw this happen once in the NoAction Surplus EIS run."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "RunoffSeasonRelease"( ) < "ComputeFCSurplusDemandsBelowMead"( ) ) THEN "ComputeFCSurplusDemandsBelowMead"( ) ELSE "RunoffSeasonRelease"( ) ENDIF; END; FUNCTION "ComputeMeadFallFCRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "2/28/2000: Terry Fulp: I added the check that if the outflow resulting from the space building release is not enough to meet the surplus demand
below Mead, then we need to increase it so that it will. We saw this appox 10 times on the No Action Surplus EIS runs."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ComputeOutflowAtGivenStorage"( % "Mead", "ComputeTargetStorage"( ) ) < "ComputeFCSurplusDemandsBelowMead"( ) ) THEN "ComputeFCSurplusDemandsBelowMead"( ) ELSE "ComputeOutflowAtGivenStorage"( % "Mead", "ComputeTargetStorage"( ) ) ENDIF; END; FUNCTION "ComputeMeadFallReleaseConstrained" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ComputeTargetStorage"( ) > "RuleCurveStorage"( % "Mead", @"t" ) ) THEN IF ( "ComputeOutflowAtRuleCurveStorage"( % "Mead" ) < "ComputeFCSurplusDemandsBelowMead"( ) ) THEN "ComputeFCSurplusDemandsBelowMead"( ) ELSE "ComputeOutflowAtRuleCurveStorage"( % "Mead" ) ENDIF ELSE "ComputeMeadFallFCRelease"( ) ENDIF; END; FUNCTION "ComputeMeadSpringReleaseConstrained" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ComputeStorageAtGivenOutflow"( % "Mead", "ComputeMeadSpringFCRelease"( ) ) > "RuleCurveStorage"( % "Mead", @"t" ) ) THEN IF ( "ComputeOutflowAtRuleCurveStorage"( % "Mead" ) < "ComputeFCSurplusDemandsBelowMead"( ) ) THEN "ComputeFCSurplusDemandsBelowMead"( ) ELSE "ComputeOutflowAtRuleCurveStorage"( % "Mead" ) ENDIF ELSE "ComputeMeadSpringFCRelease"( ) ENDIF; END; FUNCTION "ComputeFCSurplusDemandsBelowMead" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDepletionsBelow"( % "Mead", @"t", @"t" ) + "ComputeSurplusDepletion"( "MWD", @"t" ) + "ComputeSurplusDepletion"( "CAP", @"t" ) COMMENTED_BY "Don't need to add CAP min diversion separately, will be included in CAP surplus schedule" + "ComputeSurplusDepletion"( "Mexico", @"t" ) + "ComputeSurplusDepletion"( "Coachella", @"t" ) + "ComputeSurplusDepletion"( "IID", @"t" ) + "VolumeToFlow"( "TotalOtherPriority4ActualUse"( @"t", @"t" ), @"t" ) + "VolumeToFlow"( ( "RuleCurveStorage"( % "Havasu", @"t" ) - "PreviousStorage"( % "Havasu" ) ), @"t" ) + "VolumeToFlow"( ( "RuleCurveStorage"( % "Mohave", @"t" ) - "PreviousStorage"( % "Mohave" ) ), @"t" ) + "VolumeToFlow"( "EstimateEvaporation"( % "Havasu", "PreviousStorage"( % "Havasu" ), "RuleCurveStorage"( % "Havasu", @"t" ), @"t", @"t" ), @"t" ) + "VolumeToFlow"( "EstimateEvaporation"( % "Mohave", "PreviousStorage"( % "Mohave" ), "RuleCurveStorage"( % "Mohave", @"t" ), @"t", @"t" ), @"t" ) - "SumCurrentInflowBelowMead"( ); END; FUNCTION "MeadInFloodControl" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 July Max DayOfMonth, Current Year" AND $ "Mead.Outflow" [] < "RunoffSeasonRelease"( ) ) THEN TRUE ELSE IF ( @"t" > @"24:00:00 July Max DayOfMonth, Current Year" AND $ "Mead.Outflow" [] < "ComputeOutflowAtGivenStorage"( % "Mead", "ComputeTargetStorage"( ) ) ) THEN TRUE ELSE FALSE ENDIF ENDIF; END; FUNCTION "RunoffSeasonRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "cfs"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( ( GET @INDEX 1.00000000 FROM "ForecastRunoffSeason"( ) ) > 1.00000000 AND ( GET @INDEX 0.00000000 FROM "ForecastRunoffSeason"( ) ) < $ "MeadFloodControlData.Levels" [0.00000000, ( GET @INDEX 1.00000000 FROM "ForecastRunoffSeason"( ) ) - 1.00000000] ) THEN $ "MeadFloodControlData.Levels" [0.00000000, ( GET @INDEX 1.00000000 FROM "ForecastRunoffSeason"( ) ) - 1.00000000] ELSE ( GET @INDEX 0.00000000 FROM "ForecastRunoffSeason"( ) ) ENDIF; END; END; UTILITY_GROUP "7 State Plan Surplus Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeSurplusDiv7StatePlanLevel2" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN $ "SNWPSchedule.Diversion Schedule" [date] + ( "ComputeSurplusDepl7StatePlanLevel2"( diversion, date ) - $ "SNWPSchedule.Depletion Schedule" [date] ) ELSE "ComputeSurplusDepl7StatePlanLevel2"( diversion, date ) ENDIF; END; FUNCTION "ComputeSurplusDepl7StatePlanLevel2" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "VolumeToFlow"( "7 State Plan Surplus Schedules." CONCAT diversion CONCAT " Level 2" [@"24:00:00 December Max DayOfMonth, Current Year"] * "SurplusMonthlyPercent"( diversion, date ), date ); END; FUNCTION "ComputeSurplusDepl7StatePlanLevel1" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION "MWD and SNWP are guaranteed to get at least their Level 2 amounts (Full Domestic Surplus)"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "MWD" OR diversion == "SNWP" ) THEN diversion CONCAT "Schedule.Depletion Schedule" [date] + "VolumeToFlow"( "Max"( "ComputeLevel2RequestedAboveNormal"( diversion ), "ComputeQuantifiedLevel1Volume"( diversion ) ) * "SurplusMonthlyPercent"( diversion, date ), date ) ELSE diversion CONCAT "Schedule.Depletion Schedule" [date] + "VolumeToFlow"( "ComputeQuantifiedLevel1Volume"( diversion ) * "SurplusMonthlyPercent"( diversion, date ), date ) ENDIF; END; FUNCTION "ComputeSurplusDiv7StatePlanLevel1" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN $ "SNWPSchedule.Diversion Schedule" [date] + ( "ComputeSurplusDepl7StatePlanLevel1"( diversion, date ) - $ "SNWPSchedule.Depletion Schedule" [date] ) ELSE "ComputeSurplusDepl7StatePlanLevel1"( diversion, date ) ENDIF; END; FUNCTION "ComputeQuantifiedSurplusVolumeByState" ( STRING state ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Surplus.SurplusRelease" [] * $ "7 State Plan Data.Share of Surplus by State" ["Fraction", state]; END; FUNCTION "ComputeUnusedSurplusApportionment" ( STRING state ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "As of 10/26/2000, we are assuming that only Arizona will have unused surplus apportionment.

Also, this function must be constrained to be >= 0 for the calling function to work (ComputeLevel1VolumeAvailable)"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( state == "Arizona" ) THEN "ComputeQuantifiedSurplusVolumeByState"( "Arizona" ) - "ComputeLevel1RequestedAboveNormal"( "CAP" ) ELSE 0.00000000 "acre-feet" ENDIF; END; FUNCTION "ComputeLevel1RequestedAboveNormal" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "CAP" ) THEN ( "7 State Plan Surplus Schedules." CONCAT diversion CONCAT " Level 1" [@"24:00:00 December Max DayOfMonth, Current Year"] - "AnnualVolume"( "GetObject"( diversion CONCAT "Schedule" ) & "Total Depletion Schedule" ) ) COMMENTED_BY "Have to use a different schedule that includes the CAP 75 kaf min diversion" ELSE "7 State Plan Surplus Schedules." CONCAT diversion CONCAT " Level 1" [@"24:00:00 December Max DayOfMonth, Current Year"] - "AnnualVolume"( "GetObject"( diversion CONCAT "Schedule" ) & "Depletion Schedule" ) ENDIF; END; FUNCTION "ComputeLevel2RequestedAboveNormal" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "7 State Plan Surplus Schedules." CONCAT diversion CONCAT " Level 2" [@"24:00:00 December Max DayOfMonth, Current Year"] - "AnnualVolume"( "GetObject"( diversion CONCAT "Schedule" ) & "Depletion Schedule" ); END; FUNCTION "ComputeLevel1VolumeAvailable" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function computes the amount of water available for each diversion under the quantified Level 1 surplus of the 7 State Plan
and is constrained to be >= 0. The calling function takes care of the case if it's a really large number

The total amount of surplus water is divided between the states and then is divided up within the states.
I have assumed that only Arizona will have unused water and gave 50% each to California and Nevada.
Once MWD gets it's full ditch, any remaining water is given to Coachella and IID by percentages used in computting
the Level 1 scheduels for them. Those were 128533/300000 = 0.4284 for Coachella and 171467/300000 = 0.5716
All of these percentages are on the 7 State Plan Data object."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-feet"; BEGIN IF ( diversion == "MWD" ) THEN "ComputeQuantifiedSurplusVolumeByState"( "California" ) + "ComputeUnusedSurplusApportionment"( "Arizona" ) * $ "7 State Plan Data.Share of AZ Unused Surplus" ["Fraction", "California"] ELSE IF ( diversion == "Coachella" ) THEN ( "ComputeLevel1VolumeAvailable"( "MWD" ) - "ComputeLevel1RequestedAboveNormal"( "MWD" ) ) * $ "7 State Plan Data.Share of CA Ag Surplus" ["Fraction", "Coachella"] ELSE IF ( diversion == "IID" ) THEN ( "ComputeLevel1VolumeAvailable"( "MWD" ) - "ComputeLevel1RequestedAboveNormal"( "MWD" ) ) * $ "7 State Plan Data.Share of CA Ag Surplus" ["Fraction", "IID"] ELSE IF ( diversion == "SNWP" ) THEN "ComputeQuantifiedSurplusVolumeByState"( "Nevada" ) + "ComputeUnusedSurplusApportionment"( "Arizona" ) * $ "7 State Plan Data.Share of AZ Unused Surplus" ["Fraction", "Nevada"] ELSE "ComputeQuantifiedSurplusVolumeByState"( "Arizona" ) ENDIF ENDIF ENDIF ENDIF; END; FUNCTION "ComputeQuantifiedLevel1Volume" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "This function takes the computed amount available and limits it to the Level 1 requested amount.
The ComputeLevel1VolumeAvailable is constrained to be >= 0."; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "Min"( "ComputeLevel1RequestedAboveNormal"( diversion ), "ComputeLevel1VolumeAvailable"( diversion ) ); END; END; UTILITY_GROUP "Guideline Shortage Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeStepShortageDiversion" ( STRING diversion, NUMERIC level, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "CAP" ) THEN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "CAPSchedule.Diversion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "Shortage.LowerBasinMexicoShortageAmount" [level - 1.00000000, 0.00000000] * "ComputePriority4UserPercentStepShortage"( diversion ) ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion], date ) ELSE IF ( diversion == "SNWP" ) THEN "SNWPStepShortageRatio"( level, date ) * $ "SNWPSchedule.Diversion Schedule" [date] ELSE IF ( diversion == "Mexico" ) THEN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "MexicoSchedule.Diversion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "Shortage.LowerBasinMexicoShortageAmount" [( level - 1.00000000 ), 0.00000000] * $ "Shortage.MexicoShortagePercent" [] ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion], date ) ELSE "VolumeToFlow"( ( "SumFlowsToVolume"( "GetSlot"( "ArizonaPriority4Schedules.Diversion_" CONCAT diversion ), @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) COMMENTED_BY "If User has no use, ShortagePercent will be 0." - $ "Shortage.LowerBasinMexicoShortageAmount" [level - 1.00000000, 0.00000000] * "ComputePriority4UserPercentStepShortage"( diversion ) ) * ( 1.00000000 / 12.00000000 ), date ) COMMENTED_BY "diversion is other Arizona Priority 4 User" ENDIF ENDIF ENDIF; END; FUNCTION "ComputeStepShortageDepletion" ( STRING diversion, NUMERIC level, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "CAP" ) THEN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "CAPSchedule.Depletion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "Shortage.LowerBasinMexicoShortageAmount" [( level - 1.00000000 ), 0.00000000] * "ComputePriority4UserPercentStepShortage"( diversion ) ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion], date ) ELSE IF ( diversion == "SNWP" ) THEN diversion CONCAT "Schedule.Depletion Schedule" [date] - "VolumeToFlow"( "SNWPAnnualDepletionStepShortage"( level ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion], date ) ELSE IF ( diversion == "Mexico" ) THEN "VolumeToFlow"( ( "SumFlowsToVolume"( $ "MexicoSchedule.Depletion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) - $ "Shortage.LowerBasinMexicoShortageAmount" [( level - 1.00000000 ), 0.00000000] * $ "Shortage.MexicoShortagePercent" [] ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), diversion], date ) ELSE "VolumeToFlow"( ( "SumFlowsToVolume"( "GetSlot"( "ArizonaPriority4Schedules.Depletion_" CONCAT diversion ), @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) COMMENTED_BY "If User has no use, ShortagePercent will be 0." - $ "Shortage.LowerBasinMexicoShortageAmount" [level - 1.00000000, 0.00000000] * "ComputePriority4UserPercentStepShortage"( diversion ) ) * ( 1.00000000 / 12.00000000 ), date ) COMMENTED_BY "diversion is other Arizona Priority 4 User" ENDIF ENDIF ENDIF; END; FUNCTION "SNWPStepShortageRatio" ( NUMERIC level, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN 1.00000000 - ( "FlowToVolume"( $ "SNWPSchedule.Depletion Schedule" [date], date ) - ( "FlowToVolume"( $ "SNWPSchedule.Depletion Schedule" [date], date ) - "SNWPAnnualDepletionStepShortage"( level ) * $ "Surplus.MonthlyPercents" ["GetMonthAsString"( date ), "SNWP"] ) ) / "FlowToVolume"( $ "SNWPSchedule.Depletion Schedule" [date], date ); END; FUNCTION "SNWPAnnualDepletionStepShortage" ( NUMERIC level ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Shortage.LowerBasinMexicoShortageAmount" [( level - 1.00000000 ), 0.00000000] * $ "Shortage.NevadaShortagePercent" []; END; FUNCTION "DetermineShortageTier" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] < 1025.00000000 "ft" ) THEN 3.00000000 ELSE IF ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] < 1050.00000000 "ft" AND $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] >= 1025.00000000 "ft" ) THEN 2.00000000 ELSE IF ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] <= 1075.00000000 "ft" AND $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] >= 1050.00000000 "ft" ) THEN 1.00000000 ELSE 0.00000000 ENDIF ENDIF ENDIF; END; END; UTILITY_GROUP "80P1050 and Abs Pro Shortage Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "TotalLevel1LBShortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalLevel1ArizonaShortage"( ) / $ "Shortage.ArizonaShortagePercent" []; END; FUNCTION "CAPShortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "AnnualVolume"( $ "CAPSchedule.Total Depletion Schedule" ) - $ "Shortage.MinDiversionCAP" []; END; FUNCTION "TotalAnnualStage1Shortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalAnnualArizonaStage1Shortage"( ) / $ "Shortage.ArizonaShortagePercent" []; END; FUNCTION "ComputeShortageDepletion" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN WITH NUMERIC totalshort = "TotalLevel1LBShortage"( ) DO IF ( diversion == "SNWP" ) THEN $ "SNWPSchedule.Depletion Schedule" [date] - "VolumeToFlow"( totalshort * $ "Shortage.NevadaShortagePercent" [] * ( 1.00000000 / 12.00000000 ), date ) ELSE IF ( diversion == "CAP" ) THEN $ "CAPSchedule.Depletion Schedule" [date] - "VolumeToFlow"( "CAPShortage"( ) * ( 1.00000000 / 12.00000000 ), date ) ELSE IF ( diversion == "Mexico" ) THEN $ "MexicoSchedule.Depletion Schedule" [date] - "VolumeToFlow"( totalshort * $ "Shortage.MexicoShortagePercent" [] * ( 1.00000000 / 12.00000000 ), date ) ELSE ( "ArizonaPriority4Schedules.Depletion_" CONCAT diversion [date] - "VolumeToFlow"( "OtherArizonaPriority4Shortage"( ) * "ComputeOtherPriority4UserShortagePercentNoCAP"( diversion ) * ( 1.00000000 / 12.00000000 ), date ) ) COMMENTED_BY "Diversion is other Arizona Priority 4 User" ENDIF ENDIF ENDIF ENDWITH; END; FUNCTION "ComputeShortageDiversion" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN WITH NUMERIC totalshort = "TotalLevel1LBShortage"( ) DO IF ( diversion == "SNWP" ) THEN $ "SNWPSchedule.Diversion Schedule" [date] - "VolumeToFlow"( totalshort * $ "Shortage.NevadaShortagePercent" [] * ( 1.00000000 / 12.00000000 ), date ) * ( $ "SNWPSchedule.Diversion Schedule" [] / $ "SNWPSchedule.Depletion Schedule" [] ) ELSE IF ( diversion == "CAP" ) THEN $ "CAPSchedule.Diversion Schedule" [date] - "VolumeToFlow"( "CAPShortage"( ) * ( 1.00000000 / 12.00000000 ), date ) ELSE IF ( diversion == "Mexico" ) THEN $ "MexicoSchedule.Diversion Schedule" [date] - "VolumeToFlow"( totalshort * $ "Shortage.MexicoShortagePercent" [] * ( 1.00000000 / 12.00000000 ), date ) ELSE ( "ArizonaPriority4Schedules.Diversion_" CONCAT diversion [date] - "VolumeToFlow"( "OtherArizonaPriority4Shortage"( ) * "ComputeOtherPriority4UserShortagePercentNoCAP"( diversion ) * ( 1.00000000 / 12.00000000 ), date ) * "ComputeAzOtherPriority4Ratio"( diversion, date ) ) COMMENTED_BY "Diversion is other Arizona Priority 4 User" ENDIF ENDIF ENDIF ENDWITH; END; FUNCTION "Stage2ShortageAmount" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" OR diversion == "Mexico" ) THEN IF ( "ComputeMWDShortedDepletion"( "MWD", diversionObj ) <= 0.00000000 "acre-ft/month" ) THEN IF ( IsNaN $ "Shortage.CritPeriodLevel 2 Shortage Flag" [] ) THEN ( $ "MWDSchedule.Input Depletion Schedule" [] / "CaliforniaStage2ShortagePercent"( ) + "TotalLevel2ArizonaShortage"( ) / $ "Shortage.ArizonaShortagePercent" [] ) * "ComputeProrationFactorDrought"( diversion ) * - 1.00000000 + "VolumeToFlow"( $ "Shortage.Annual Level 1 Shortage" [@"24:00:00 January 31, Current Year"], @"t" ) * "ComputeProrationFactorDrought"( diversion ) / 12.00000000 ELSE $ "MWDSchedule.Input Depletion Schedule" [] / "CaliforniaStage2ShortagePercent"( ) * "ComputeProrationFactorDrought"( diversion ) * - 1.00000000 ENDIF ELSE "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) * "ComputeProrationFactorDrought"( diversion ) ENDIF ELSE IF ( diversionObj IN "ArizonaPriority2and3UsersWaterUser"( ) ) THEN IF ( "ComputeMWDShortedDepletion"( "MWD", diversionObj ) <= 0.00000000 "acre-ft/month" ) THEN $ "MWDSchedule.Input Depletion Schedule" [] / "CaliforniaStage2ShortagePercent"( ) * ( "ComputePriority2and3UserShortagePercent"( diversion ) * "ComputeTotalPriority2and3UserShortagePercent"( ) ) * - 1.00000000 ELSE "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) * ( "ComputePriority2and3UserShortagePercent"( diversion ) * "ComputeTotalPriority2and3UserShortagePercent"( ) ) ENDIF ELSE IF ( "ComputeMWDShortedDepletion"( "MWD", diversionObj ) <= 0.00000000 "acre-ft/month" ) THEN $ "MWDSchedule.Input Depletion Schedule" [] * - 1.00000000 ELSE ( "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) * "CaliforniaStage2ShortagePercent"( ) ) ENDIF COMMENTED_BY "diversion is MWD" ENDIF ENDIF COMMENTED_BY "Returns shortage amount as a negative."; END; FUNCTION "ComputePriority2and3UserShortagePercent" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( "GetSlot"( "ArizonaPriority2and3Schedules.Depletion_" CONCAT diversion ), @"24:00:00 January 31, Previous Year", @"24:00:00 December 31, Previous Year" ) / $ "ArizonaPriority2and3Schedules.TotalScheduledUse" [@"24:00:00 December 31, Previous Year"]; END; FUNCTION "TotalAnnualArizonaStage1Shortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "ArizonaPriority4Schedules.TotalScheduleUse" [@"24:00:00 December 31, Current Year"]; END; FUNCTION "ComputeTotalPriority2and3UserShortagePercent" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( $ "Shortage.Arizona Allocation" [] - "TotalAnnualArizonaStage1Shortage"( ) ) / ( ( $ "Shortage.Arizona Allocation" [] + $ "Shortage.Nevada Allocation" [] + $ "Shortage.California Allocation" [] + $ "Shortage.Mexico Allocation" [] ) - "TotalAnnualStage1Shortage"( ) ); END; FUNCTION "CaliforniaStage2ShortagePercent" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN 1.00000000 - ( $ "Shortage.NevadaShortagePercent" [] + $ "Shortage.MexicoShortagePercent" [] + "ComputeTotalPriority2and3UserShortagePercent"( ) ); END; FUNCTION "ComputeAzPriority2and3Ratio" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ArizonaPriority2and3Schedules.Depletion_" CONCAT diversion [date] == 0.00000000 "acre-ft/month" ) THEN 0.00000000 ELSE ( "ArizonaPriority2and3Schedules.Diversion_" CONCAT diversion [date] / "ArizonaPriority2and3Schedules.Depletion_" CONCAT diversion [date] ) ENDIF; END; FUNCTION "ComputeAbsoluteProtectionShortageDiversion" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN "ComputeAbsoluteProtectionShortageDepletion"( diversion, diversionObj ) * ( $ "SNWPSchedule.Diversion Schedule" [] / $ "SNWPSchedule.Depletion Schedule" [] ) ELSE IF ( diversionObj IN "OtherArizonaPriority4UsersWaterUser"( ) ) THEN ( "ComputeAbsoluteProtectionShortageDepletion"( diversion, diversionObj ) * "ComputeAzOtherPriority4Ratio"( diversion, @"t" ) ) ELSE IF ( diversionObj IN "ArizonaPriority2and3UsersWaterUser"( ) ) THEN ( "ComputeAbsoluteProtectionShortageDepletion"( diversion, diversionObj ) * "ComputeAzPriority2and3Ratio"( diversion, @"t" ) ) ELSE "ComputeAbsoluteProtectionShortageDepletion"( diversion, diversionObj ) ENDIF ENDIF ENDIF; END; FUNCTION "ComputeAbsoluteProtectionShortageDepletion" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft/month"; BEGIN IF ( ( "ComputeAbsoluteProtectionShortageDepletionNumber"( "CAP", diversionObj ) == 0.00000000 "acre-ft/month" ) COMMENTED_BY "Determine if CAP needs to go to 0. If so, go into Stage 2 shortage." ) THEN IF ( diversion == "SNWP" OR diversion == "Mexico" ) THEN ( diversion CONCAT "Diversion.Total Depletion Requested" [] + "Stage2ShortageAmount"( diversion, diversionObj ) ) COMMENTED_BY "SNWP and Mexico remain at fixed percents (3.33, 16.67) of Total Shortage (Stage 1 or Stage 2)." ELSE IF ( diversionObj IN "ArizonaPriority2and3UsersWaterUser"( ) ) THEN diversionObj CONCAT ".Depletion Requested" [] + "Stage2ShortageAmount"( diversion, diversionObj ) ELSE IF ( diversion == "MWD" ) THEN diversion CONCAT "Diversion.Total Depletion Requested" [] + "Stage2ShortageAmount"( diversion, diversionObj ) ELSE "ComputeAbsoluteProtectionShortageDepletionNumber"( diversion, diversionObj ) COMMENTED_BY "Diversion is Arizona Priority 4 User (CAP or Other) and will be set to 0." ENDIF ENDIF ENDIF ELSE IF ( $ "Shortage.MWDShortageCounter" [@"t"] == 1.00000000 ) THEN IF ( diversion == "CAP" OR diversionObj IN "OtherArizonaPriority4UsersWaterUser"( ) ) THEN 0.00000000 "acre-ft/month" ELSE IF ( diversion == "SNWP" OR diversion == "Mexico" ) THEN ( diversion CONCAT "Schedule.Depletion Schedule" [] - "TotalLBShortageArizonaPriority4Zero"( ) * "ComputeProrationFactorDrought"( diversion ) ) ELSE IF ( diversion == "MWD" ) THEN $ "MWDDiversion.Total Depletion Requested" [] ELSE diversionObj CONCAT ".Depletion Requested" [] COMMENTED_BY "diversion is Arizona Priority 2 and 3" ENDIF ENDIF ENDIF ELSE IF ( diversion == "MWD" ) THEN $ "MWDDiversion.Total Depletion Requested" [] ELSE IF ( diversionObj IN "ArizonaPriority2and3UsersWaterUser"( ) ) THEN diversionObj CONCAT ".Depletion Requested" [] ELSE "ComputeAbsoluteProtectionShortageDepletionNumber"( diversion, diversionObj ) ENDIF ENDIF ENDIF COMMENTED_BY "Arizona Priority 4 Users do not need to go to 0. Short Arizona Priority 4, Mexico and SNWP appropriately. No shortage to MWD or Arizona Priority 2 and 3." ENDIF; END; FUNCTION "ComputeAPCritPeriodShortageDiversion" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN "ComputeAPCritPeriodShortageDepletion"( diversion ) * ( $ "SNWPSchedule.Diversion Schedule" [] / $ "SNWPSchedule.Depletion Schedule" [] ) ELSE "ComputeAPCritPeriodShortageDepletion"( diversion ) ENDIF; END; FUNCTION "ComputeAPCritPeriodShortageDepletion" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft/month"; BEGIN WITH NUMERIC totalShort = "TotalLBShortageArizonaPriority4Zero"( ) DO IF ( diversion == "SNWP" ) THEN diversion CONCAT "Schedule.Depletion Schedule" [] - "NevadaShortage"( "SNWP", totalShort ) ELSE IF ( diversion == "Mexico" ) THEN diversion CONCAT "Schedule.Depletion Schedule" [] - "MexicoShortage"( "Mexico", totalShort ) ELSE 0.00000000 "acre-ft/month" COMMENTED_BY "Set Arizona Priority 4 Users (including CAP) to zero." ENDIF ENDIF ENDWITH; END; FUNCTION "ComputeProrationFactorDrought" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "SNWP" ) THEN $ "Shortage.NevadaShortagePercent" [] ELSE IF ( diversion == "CAP" ) THEN $ "Shortage.ArizonaShortagePercent" [] ELSE IF ( diversion == "Mexico" ) THEN $ "Shortage.MexicoShortagePercent" [] ELSE $ "Shortage.MWDShortagePercent" [] COMMENTED_BY "MWD, if CAP = 0, then MWD gets 100%-Mexico of the total" ENDIF ENDIF ENDIF; END; FUNCTION "ComputeAbsoluteProtectionShortageDepletionNumber" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft/month"; BEGIN IF ( diversion == "SNWP" OR diversion == "Mexico" ) THEN diversion CONCAT "Diversion.Total Depletion Requested" [] + "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) * "ComputeProrationFactorDrought"( diversion ) ELSE "ComputeCAPAndOtherPriority4ShortageDepletionLevel2"( diversion, diversionObj ) ENDIF COMMENTED_BY "This function only called for SNWP and Mexico if CAP and other AZ Priority 4 users are NOT reduced to 0. This functions is never called for MWD."; END; FUNCTION "EstimateWaterAvailableFromMeadAboveAnElevationCritPeriod" ( DATETIME criticalMonth ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Mead.Storage" [@"t - 1"] - "ElevationToStorage"( % "Mead", $ "Shortage.Level 2 Shortage Trigger" [0.00000000, 0.00000000] ) + "SumTableRow"( $ "UBRuleCurveData.PowellMinObjectiveRelease", 0.00000000, "GetMonth"( @"t" ) - 1.00000000, "GetMonth"( criticalMonth ) - 1.00000000 ) + "SumGainsBelowVolume"( % "Powell", @"t", criticalMonth ) - "SumDepletionsBelowVolume"( % "Powell", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "VirginRiver.Inflow", @"t", criticalMonth ) - "Estimate Bank Storage without Evap"( % "Mead", $ "Mead.Storage" [@"t - 1"], "ElevationToStorage"( % "Mead", $ "Shortage.AbsoluteMeadProtectionLevel" [0.00000000, 0.00000000] ) ) - "EstimateEvaporation"( % "Mead", $ "Mead.Storage" [@"t - 1"], "ElevationToStorage"( % "Mead", $ "Shortage.AbsoluteMeadProtectionLevel" [0.00000000, 0.00000000] ), @"t", criticalMonth ) - "SumFlowsToVolume"( $ "SNWPDiversion.Total Depletion Requested", @"t", criticalMonth ); END; FUNCTION "SumCurrentInflowBelowMeadCritPeriod" ( DATETIME criticalMonth ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "BelowMead", "Local Inflow", "SUM", "INPUT", TRUE, @"t", criticalMonth ) + "SumFlowsToVolume"( $ "NevadaDesalination.Inflow", @"t", criticalMonth ) COMMENTED_BY "Need to add in Desal local inflow, which is not input."; END; FUNCTION "SumCurrentDemandsBelowMeadCritPeriod" ( DATETIME criticalMonth ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumDepletionsBelowVolume"( % "Mead", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "MWDDiversion.Total Depletion Requested", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "CAPDiversion.Total Depletion Requested", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "CoachellaDiversion.Total Depletion Requested", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "IIDDiversion.Total Depletion Requested", @"t", criticalMonth ) + "SumFlowsToVolume"( $ "MexicoDiversion.Total Depletion Requested", @"t", criticalMonth ) + "TotalOtherPriority4ActualUse"( @"t", criticalMonth ) + "TotalPriority2and3ActualUse"( @"t", criticalMonth ) COMMENTED_BY "Priority 1 Users included in Below Mead subbasin"; END; FUNCTION "ComputeWaterAvailableFromMeadAboveAnElevation" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "VolumeToFlow"( $ "Mead.Storage" [@"t - 1"] - "ElevationToStorage"( % "Mead", $ "Shortage.AbsoluteMeadProtectionLevel" [0.00000000, 0.00000000] ) + "FlowToVolume"( $ "Mead.Inflow" [], @"t" ) - "Estimate Bank Storage without Evap"( % "Mead", $ "Mead.Storage" [@"t - 1"], "ElevationToStorage"( % "Mead", $ "Shortage.AbsoluteMeadProtectionLevel" [0.00000000, 0.00000000] ) ) - "EstimateEvaporation"( % "Mead", $ "Mead.Storage" [@"t - 1"], "ElevationToStorage"( % "Mead", $ "Shortage.AbsoluteMeadProtectionLevel" [0.00000000, 0.00000000] ), @"t", @"t" ) - "FlowToVolume"( $ "SNWPDiversion.Total Depletion Requested" [], @"t" ), @"t" ); END; FUNCTION "AbsoluteProtectionLevelShortageToAllocateMONTH" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ComputeWaterAvailableFromMeadAboveAnElevation"( ) < "CurrentDemandBelowMead"( ) ) THEN "ComputeWaterAvailableFromMeadAboveAnElevation"( ) - "CurrentDemandBelowMead"( ) ELSE 0.00000000 "cfs" ENDIF COMMENTED_BY "Returns negative number if shortage is needed!"; END; FUNCTION "ComputeMWDShortedDepletion" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) * "CaliforniaStage2ShortagePercent"( ) ) + $ "MWDDiversion.Total Depletion Requested" []; END; FUNCTION "CriticalPeriodVolumeCheck" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( DATETIME month IN "DateMax"( @"24:00:00 April 30, Current Year", @"t" ) TO @"24:00:00 September 30, Current Year" ) WITH BOOLEAN result = FALSE DO result OR IF ( month == @"t" ) THEN "FlowToVolume"( "ComputeWaterAvailableFromMeadAboveAnElevation"( ), @"t" ) COMMENTED_BY "If in current month, use real info, not forecasted." ELSE "EstimateWaterAvailableFromMeadAboveAnElevationCritPeriod"( month ) ENDIF < "EstimateDemandBelowMeadCritPeriod"( month ) ENDFOR; END; FUNCTION "EstimateDemandBelowMeadCritPeriod" ( DATETIME criticalMonth ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumCurrentDemandsBelowMeadCritPeriod"( criticalMonth ) + ( "RuleCurveStorage"( % "Havasu", criticalMonth ) - "PreviousStorage"( % "Havasu" ) ) + ( "RuleCurveStorage"( % "Mohave", criticalMonth ) - "PreviousStorage"( % "Mohave" ) ) + "EstimateEvapForDownstreamDemands"( % "Havasu", "PreviousStorage"( % "Havasu" ), "RuleCurveStorage"( % "Havasu", criticalMonth ) ) + "EstimateEvapForDownstreamDemands"( % "Mohave", "PreviousStorage"( % "Mohave" ), "RuleCurveStorage"( % "Mohave", criticalMonth ) ) - "SumCurrentInflowBelowMeadCritPeriod"( criticalMonth ); END; FUNCTION "DetermineMonthlyPercent" ( STRING diversion ) RETURN_TYPE SLOT; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( diversion == "MWD" AND NOT "NotShortageYear"( ) ) THEN $ "Shortage.MonthlyPercents" ELSE $ "Surplus.MonthlyPercents" ENDIF; END; END; UTILITY_GROUP "Shortage Arizona Priority 4 Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "TotalLevel1ArizonaShortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "CAPShortage"( ) / "CAPPercentOfPriority4Use"( ); END; FUNCTION "TotalLBShortageArizonaPriority4Zero" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalLevel2ArizonaShortage"( ) / $ "Shortage.ArizonaShortagePercent" []; END; FUNCTION "ComputeAzOtherPriority4Ratio" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "ArizonaPriority4Schedules.Depletion_" CONCAT diversion [date] == 0.00000000 "acre-ft/month" ) THEN 0.00000000 ELSE ( "ArizonaPriority4Schedules.Diversion_" CONCAT diversion [date] / "ArizonaPriority4Schedules.Depletion_" CONCAT diversion [date] ) ENDIF; END; FUNCTION "OtherArizonaPriority4Shortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalLevel1ArizonaShortage"( ) - "CAPShortage"( ); END; FUNCTION "TotalOtherPriority4ActualUse" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Other Arizona Priority 4 Users", "Depletion Requested", "SUM", "ALL", TRUE, startDate, endDate ); END; FUNCTION "TotalOtherPriority4ScheduledUse" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft" DO result + "SumFlowsToVolume"( "GetSlot"( "MakeSlotNameWaterUser"( diversion ) ), startDate, endDate ) ENDFOR + FOR ( OBJECT diversion IN "OtherArizonaPriority4UsersAggDivSite"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft" DO result + "SumFlowsToVolume"( "GetSlot"( "MakeSlotNameAggDiv"( diversion ) ), startDate, endDate ) ENDFOR; END; FUNCTION "CAPPercentOfPriority4Use" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "AnnualVolume"( $ "CAPSchedule.Total Depletion Schedule" ) / ( "TotalOtherPriority4ScheduledUse"( @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ) + "AnnualVolume"( $ "CAPSchedule.Total Depletion Schedule" ) ); END; FUNCTION "MakeSlotNameWaterUser" ( OBJECT diversion ) RETURN_TYPE STRING; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ArizonaPriority4Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ); END; FUNCTION "MakeSlotNameAggDiv" ( OBJECT diversion ) RETURN_TYPE STRING; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ArizonaPriority4Schedules.Depletion_" CONCAT STRINGIFY diversion; END; FUNCTION "ComputeOtherPriority4UserShortagePercentNoCAP" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( "GetSlot"( "ArizonaPriority4Schedules.Depletion_" CONCAT diversion ), @"24:00:00 January 31, Previous Year", @"24:00:00 December 31, Previous Year" ) / "SumSlot"( $ "ArizonaPriority4Schedules.TotalOtherScheduledUse", @"24:00:00 January 31, Previous Year", @"24:00:00 December 31, Previous Year" ); END; FUNCTION "ComputePriority4UserShortagePercent" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumFlowsToVolume"( "GetSlot"( "ArizonaPriority4Schedules.Depletion_" CONCAT diversion ), @"24:00:00 January 31, Previous Year", @"24:00:00 December 31, Previous Year" ) / $ "ArizonaPriority4Schedules.TotalScheduleUse" [@"24:00:00 December 31, Previous Year"]; END; FUNCTION "TotalMonthlyArizonaPriority4ScheduledUse" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "CAPSchedule.Depletion Schedule" [] + FOR ( OBJECT diversion IN "OtherArizonaPriority4UsersWaterUser"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft/month" DO result + "ArizonaPriority4Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ) [] ENDFOR; END; FUNCTION "TotalLevel2ArizonaShortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "TotalMonthlyArizonaPriority4ScheduledUse"( ) COMMENTED_BY "This is the total Level 2 shortage amount only if all Arizona Priority 4 Users (including CAP) are taken to 0."; END; FUNCTION "ComputeCAPAndOtherPriority4ShortageDepletionLevel2" ( STRING diversion, OBJECT diversionObj ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft/month"; BEGIN IF ( diversion == "CAP" ) THEN ( "ComputePriority4UserShortagePercent"( diversion ) * $ "Shortage.ArizonaShortagePercent" [] * "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) ) + $ "CAPDiversion.Total Depletion Requested" [] ELSE ( "ComputePriority4UserShortagePercent"( diversion ) * $ "Shortage.ArizonaShortagePercent" [] * "AbsoluteProtectionLevelShortageToAllocateMONTH"( ) ) + diversionObj CONCAT ".Depletion Requested" [] ENDIF; END; FUNCTION "NevadaShortage" ( STRING diversion, NUMERIC totalShort ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN totalShort * $ "Shortage.NevadaShortagePercent" []; END; FUNCTION "MexicoShortage" ( STRING diversion, NUMERIC totalShort ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft/month"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN totalShort * $ "Shortage.MexicoShortagePercent" []; END; FUNCTION "ComputePriority4UserPercentStepShortage" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Shortage.ArizonaShortagePercent" [] * "ComputePriority4UserShortagePercent"( diversion ); END; END; UTILITY_GROUP "ICS Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "NotSurplusOrShortageYear" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "NotSurplusYear"( ) AND "NotShortageYear"( ) ) THEN TRUE ELSE FALSE ENDIF; END; FUNCTION "NotSurplusYear" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 December 31, 2026" AND ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] >= $ "Surplus Triggers.7 State Plan Level 2" [@"24:00:00 December 31, Previous Year"] ) OR $ "Surplus.SurplusRelease" [] > 0.00000000 "acre-feet" ) THEN FALSE ELSE TRUE ENDIF; END; FUNCTION "IsDomesticSurplusYear" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 December 31, 2026" AND ( $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] >= $ "Surplus Triggers.7 State Plan Level 2" [@"24:00:00 December 31, Previous Year"] ) ) THEN TRUE ELSE FALSE ENDIF; END; FUNCTION "NotShortageYear" ( ) RETURN_TYPE BOOLEAN; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 December 31, 2026" AND $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] < $ "Shortage.Step Shortage Mead Tier" [2.00000000, 0.00000000] OR ( @"t" >= @"24:00:00 January 31, 2027" AND $ "Mead.Pool Elevation" [@"24:00:00 December 31, Previous Year"] < $ "Shortage.Mead Trigger 80P1050" [@"24:00:00 December 31, Previous Year"] ) ) THEN FALSE ELSE TRUE ENDIF; END; FUNCTION "GetPreviousYear" ( ) RETURN_TYPE DATETIME; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"Start Timestep" ) THEN @"24:00:00 December 31, Start Year" ELSE @"24:00:00 December 31, Previous Year" ENDIF; END; FUNCTION "CAPExchangeWithYumaCountyWUA" ( DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 January 31, 2026" ) THEN ( $ "Arizona ICS.ActualMonthlyPut" [date] / "SystemTaxAdjustment"( ) ) COMMENTED_BY "Need to add system tax loss back for real water" ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "MWDExchangeWithIID" ( DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 January 31, 2026" ) THEN ( $ "California ICS.ActualMonthlyPut" [date] / "SystemTaxAdjustment"( ) ) COMMENTED_BY "Need to add system tax loss back for real water" ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineArizonaAnnualTake" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "Min"( "MaxAnnualTake"( "Arizona" ), ( "PreviousYearBankBalance"( "Arizona" ) + "DetermineArizonaAnnualPut"( ) ) ); BEGIN IF ( "NotSurplusOrShortageYear"( ) AND @"t" <= @"24:00:00 December 31, 2036" ) THEN $ "Arizona ICS.AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineCaliforniaAnnualTake" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "Min"( 1250000.00000000 "acre-ft" COMMENTED_BY "MWD at full ditch" - "SumFlowsToVolume"( $ "MWDSchedule.Depletion Schedule", @"24:00:00 January 31, Current Year", @"24:00:00 December 31, Current Year" ), "Min"( "MaxAnnualTake"( "California" ), ( "PreviousYearBankBalance"( "California" ) + "DetermineCaliforniaAnnualPut"( ) ) ) ); BEGIN IF ( "NotSurplusOrShortageYear"( ) ) THEN IF ( @"t" <= @"24:00:00 December 31, 2030" ) THEN IF ( "AnnualVolume"( $ "TotVal.Powell" ) < $ "California ICS.AnnualRequestedPutTake" [3.00000000, 1.00000000] ) THEN $ "California ICS.AnnualRequestedPutTake" [3.00000000, 3.00000000] ELSE IF ( "AnnualVolume"( $ "TotVal.Powell" ) >= $ "California ICS.AnnualRequestedPutTake" [3.00000000, 1.00000000] AND "AnnualVolume"( $ "TotVal.Powell" ) < $ "California ICS.AnnualRequestedPutTake" [2.00000000, 1.00000000] ) THEN $ "California ICS.AnnualRequestedPutTake" [2.00000000, 3.00000000] ELSE 0.00000000 "acre-ft" ENDIF ENDIF ELSE IF ( @"t" > @"24:00:00 December 31, 2030" AND @"t" <= @"24:00:00 December 31, 2036" ) THEN $ "California ICS.TakeScheduleBeginning2031" [] ELSE 0.00000000 "acre-ft" ENDIF ENDIF ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineNevadaAnnualTake" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT IF ( @"t" <= @"24:00:00 December 31, 2026" ) THEN "Min"( "MaxAnnualTake"( "Nevada" ), IF ( "NotShortageYear"( ) ) THEN ( "PreviousYearBankBalance"( "Nevada" ) + "DetermineNevadaAnnualPut"( ) ) ELSE "DetermineNevadaAnnualPut"( ) ENDIF COMMENTED_BY "If in shortage, do not take from bank. Take only what was put for the current year." ) ELSE "DetermineNevadaAnnualPut"( ) ENDIF; BEGIN IF ( "NotSurplusYear"( ) ) THEN $ "Nevada ICS.TributaryConsAnnualTake" [@"24:00:00 December 31, Current Year"] ELSE IF ( "IsDomesticSurplusYear"( ) ) THEN IF ( ( "PreviousYearBankBalance"( "Nevada" ) + "DetermineNevadaAnnualPut"( ) ) > "MaxAnnualCapacity"( "Nevada" ) ) THEN "PreviousYearBankBalance"( "Nevada" ) + "DetermineNevadaAnnualPut"( ) - "MaxAnnualCapacity"( "Nevada" ) ELSE 0.00000000 "acre-ft" ENDIF ELSE 0.00000000 "acre-ft" ENDIF COMMENTED_BY "If in Domestic Surplus and not taking will put Nevada over their max bank capacity, allow take. Take is adjusted to be the amount to not put Nevada over their max bank." ENDIF COMMENTED_BY "Nevada Tributary Conservation ICS put/take of same amount can occur during Shortage"; END; FUNCTION "DetermineArizonaAnnualPut" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "Min"( "MaxAnnualPut"( "Arizona" ), ( "MaxAnnualCapacity"( "Arizona" ) - "PreviousYearBankBalance"( "Arizona" ) ) ); BEGIN IF ( "NotSurplusOrShortageYear"( ) AND @"t" <= @"24:00:00 December 31, 2026" ) THEN $ "Arizona ICS.AnnualRequestedPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineNevadaAnnualPut" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT IF ( @"t" <= @"24:00:00 December 31, 2026" ) THEN IF ( "IsDomesticSurplusYear"( ) ) THEN ( $ "Nevada ICS.TributaryConsAnnualPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ) ELSE "Min"( "MaxAnnualPut"( "Nevada" ), ( "MaxAnnualCapacity"( "Nevada" ) - "PreviousYearBankBalance"( "Nevada" ) ) ) ENDIF ELSE ( $ "Nevada ICS.TributaryConsAnnualPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ) COMMENTED_BY "No max constraint after 2026" ENDIF; BEGIN ( $ "Nevada ICS.TributaryConsAnnualPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ) COMMENTED_BY "Through 2026, put is constrained by ICS max capacity and put. After 2026, no constraint."; END; FUNCTION "DetermineCaliforniaAnnualPut" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "Min"( "MaxAnnualPut"( "California" ), ( 600000.00000000 "acre-ft" COMMENTED_BY "not using the MaxCapacity function (would return 1.5 maf) because MWD specified that the max capacity should be 600 kaf (Hasencamp, November 2009) Rcallejo 12/16/09" - "PreviousYearBankBalance"( "California" ) ) ); BEGIN IF ( "NotSurplusOrShortageYear"( ) AND @"t" <= @"24:00:00 December 31, 2026" ) THEN IF ( "AnnualVolume"( $ "TotVal.Powell" ) >= $ "California ICS.AnnualRequestedPutTake" [0.00000000, 1.00000000] ) THEN $ "California ICS.AnnualRequestedPutTake" [0.00000000, 2.00000000] * "SystemTaxAdjustment"( ) ELSE IF ( "AnnualVolume"( $ "TotVal.Powell" ) < $ "California ICS.AnnualRequestedPutTake" [0.00000000, 1.00000000] AND "AnnualVolume"( $ "TotVal.Powell" ) >= $ "California ICS.AnnualRequestedPutTake" [1.00000000, 1.00000000] ) THEN $ "California ICS.AnnualRequestedPutTake" [1.00000000, 2.00000000] * "SystemTaxAdjustment"( ) ELSE 0.00000000 "acre-ft" ENDIF ENDIF ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineSNWPAdditionalProjectWater" ( DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Nevada ICS.NonSystemExchangesActualMonthlyTake" [date] + $ "Nevada ICS.GroundwaterActualMonthlyTake" [date] + $ "Nevada ICS.Drop2ActualMonthlyTake" [date] + $ "Nevada ICS.TributaryConsActualMonthlyTake" [date]; END; FUNCTION "DetermineNVGroundwaterTake" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "DetermineNVGroundwaterPut"( ); BEGIN IF ( "NotSurplusYear"( ) ) THEN $ "Nevada ICS.GroundwaterAnnualTake" [@"24:00:00 December 31, Current Year"] ELSE 0.00000000 "acre-ft" ENDIF COMMENTED_BY "Nevada Imported ICS (groundwater) put/take of same amount can occur during Shortage."; END; FUNCTION "DetermineNVGroundwaterPut" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( "NotSurplusYear"( ) ) THEN $ "Nevada ICS.GroundwaterAnnualPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ELSE 0.00000000 "acre-ft" ENDIF COMMENTED_BY "Nevada Imported ICS (groundwater) put/take of same amount can occur during Shortage"; END; FUNCTION "DetermineNVDesalTake" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MAX_CONSTRAINT "DetermineNVDesalPut"( ); BEGIN $ "Nevada ICS.NonSystemExchangesAnnualTake" [@"24:00:00 December 31, Current Year"] COMMENTED_BY "Nevada Imported ICS (desalination) put/take of same amount to occur during all river conditions (except flood control)."; END; FUNCTION "DetermineNVDesalPut" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( $ "Nevada ICS.NonSystemExchangesAnnualPut" [@"24:00:00 December 31, Current Year"] * "SystemTaxAdjustment"( ) ) COMMENTED_BY "Nevada Imported ICS (desalination) put/take of same amount to occur during all river conditions (except flood control)."; END; FUNCTION "DetermineNVDrop2Take" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN IF ( "NotShortageYear"( ) ) THEN IF ( $ "Nevada ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] + "SumSlotSkipNaN"( $ "Nevada ICS.Drop2ActualMonthlyTake", @"24:00:00 December 31, Start Year", "GetPreviousYear"( ) ) >= $ "Nevada ICS.Drop2Maximum" [] ) THEN ( $ "Nevada ICS.Drop2Maximum" [] - "SumSlotSkipNaN"( $ "Nevada ICS.Drop2ActualMonthlyTake", @"24:00:00 December 31, Start Year", "GetPreviousYear"( ) ) ) COMMENTED_BY "Min constraint of 0 acre-ft" ELSE $ "Nevada ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] ENDIF ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineCADrop2Take" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN IF ( "NotSurplusOrShortageYear"( ) ) THEN IF ( "SumSlotSkipNaN"( $ "Shortage.ShortageFlag", @"Start Timestep", @"t" ) == 0.00000000 ) THEN IF ( "PreviousYearCADrop2Balance"( ) - $ "California ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] < 0.00000000 "acre-ft" ) THEN "PreviousYearCADrop2Balance"( ) COMMENTED_BY "set the actual take to the available balance" ELSE $ "California ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] COMMENTED_BY "set the actual take to the requested take" ENDIF COMMENTED_BY "if no shortage and the available balance is less than the requested take" ELSE IF ( "PreviousYearCADrop2Balance"( ) - $ "California ICS.Drop2Recovery" [] < 0.00000000 "acre-ft" ) THEN "PreviousYearCADrop2Balance"( ) COMMENTED_BY "set the actual take to the available balance" ELSE $ "California ICS.Drop2Recovery" [] COMMENTED_BY "set the actual take to the recovery amount" ENDIF COMMENTED_BY "if there has been a shortage and the available balance is less than the recovery amount" ENDIF COMMENTED_BY "check to see if a shortage has occurred during the run" ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineCADrop2RepayInShortage" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN IF ( @"t" == @"24:00:00 January 31, 2011" OR @"t" == @"24:00:00 January 31, 2012" ) THEN IF ( NOT "NotShortageYear"( ) ) THEN IF ( "SumSlot"( $ "California ICS.Drop2ActualMonthlyRepayInShortage", @"24:00:00 January 31, Previous Year", @"24:00:00 December 31, Previous Year" ) == 0.00000000 "acre-ft" ) THEN $ "California ICS.Drop2AnnualScheduledRepayInShortage" [@"24:00:00 December 31, Current Year"] COMMENTED_BY "set the actual repay to the scheduled repay" ELSE 0.00000000 "acre-ft" ENDIF COMMENTED_BY "if it is a shortage year and have not yet repayed" ELSE 0.00000000 "acre-ft" ENDIF ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "DetermineAZDrop2Take" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN IF ( "NotShortageYear"( ) ) THEN IF ( $ "Arizona ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] + "SumSlotSkipNaN"( $ "Arizona ICS.Drop2ActualMonthlyTake", @"24:00:00 December 31, 2007", "GetPreviousYear"( ) ) >= $ "Arizona ICS.Drop2Maximum" [] ) THEN ( $ "Arizona ICS.Drop2Maximum" [] - "SumSlotSkipNaN"( $ "Arizona ICS.Drop2ActualMonthlyTake", @"24:00:00 December 31, 2007", "GetPreviousYear"( ) ) ) COMMENTED_BY "Min constraint of 0 acre-ft" ELSE $ "Arizona ICS.Drop2AnnualRequestedTake" [@"24:00:00 December 31, Current Year"] ENDIF ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "MaxAnnualTake" ( STRING player ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Mead Bank.Parameters" [player, "Max Take"]; END; FUNCTION "MaxAnnualPut" ( STRING player ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Mead Bank.Parameters" [player, "Max Put"]; END; FUNCTION "MaxAnnualCapacity" ( STRING player ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN $ "Mead Bank.Parameters" [player, "Max Capacity"]; END; FUNCTION "PreviousYearBankBalance" ( STRING player ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"Start Timestep" ) THEN player CONCAT " ICS" CONCAT ".InitialBalance" [] ELSE "Mead Bank." CONCAT player CONCAT " Bank" [@"24:00:00 December 31, Previous Year"] ENDIF; END; FUNCTION "PreviousYearCADrop2Balance" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"Start Timestep" ) THEN $ "California ICS.Drop2InitialBalance" [] ELSE $ "California ICS.Drop2AvailableBalance" [@"24:00:00 December 31, Previous Year"] ENDIF; END; FUNCTION "SystemTaxAdjustment" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN 1.00000000 - $ "Mead Bank.SystemTaxPercent" []; END; FUNCTION "SumPreviousYearICSCredits" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION "This function returns the beginning of the year ICS balance for Arizona, California, Nevada and Unassigned. There is no participation assumed by Unassgined for the current Guidelines ruleset. If the current timestep is after 2036, when the ICS program expires, this function returns 0. "; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" <= @"24:00:00 January 31, 2036" ) THEN "PreviousYearBankBalance"( "Arizona" ) + "PreviousYearBankBalance"( "California" ) + "PreviousYearBankBalance"( "Nevada" ) ELSE 0.00000000 "acre-ft" ENDIF; END; FUNCTION "Remaining Falllowing" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000 "acre-ft"; BEGIN "MaxItem"( { $ "California ICS.Minimum PVID Fallow Amount" [] , "Fallowing to date"( "MWD" ) , "Fallowing to date"( "PVID" ) } ) - "Fallowing to date"( diversion ); END; FUNCTION "RemainingMonthlyFallow" ( STRING diversion, DATETIME date ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( $ "California ICS.PVID Fallow Amount" [@"24:00:00 December 31, Current Year"] > 0.00000000 "acre-ft" ) THEN "VolumeToFlow"( "Remaining Falllowing"( diversion ) * ( "DetermineMonthlyPercent"( diversion ) ["GetMonthAsString"( date ), diversion] / "SumTableColumn"( "DetermineMonthlyPercent"( diversion ), "GetColumnIndex"( "DetermineMonthlyPercent"( diversion ), diversion ), "GetRowIndex"( "DetermineMonthlyPercent"( diversion ), "GetMonthAsString"( @"t" ) ), "GetRowIndex"( "DetermineMonthlyPercent"( diversion ), "GetMonthAsString"( @"24:00:00 December 31, Current Year" ) ) ) ), date ) ELSE 0.00000000 "acre-ft/month" ENDIF; END; FUNCTION "PVID Fallow Amount" ( DATETIME date, STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "VolumeToFlow"( $ "California ICS.PVID Fallow Amount" [@"24:00:00 December 31, Current Year"] * "DetermineMonthlyPercent"( diversion ) ["GetMonthAsString"( date ), diversion], date ); END; FUNCTION "Fallowing to date" ( STRING diversion ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN IF ( @"t" == @"January" ) THEN 0.00000000 "acre-ft" ELSE "Abs"( "SumFlowsToVolume"( "GetSlot"( diversion CONCAT "Schedule.Input Depletion Schedule" ), @"24:00:00 January 31, Current Year", @"t - 1" ) - "SumFlowsToVolume"( "GetSlot"( diversion CONCAT "Schedule.Depletion Schedule" ), @"24:00:00 January 31, Current Year", @"t - 1" ) ) ENDIF; END; END; UTILITY_GROUP "Arizona Priority 4 User Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "GetSlotNameForScheduleWaterUser" ( STRING diversion ) RETURN_TYPE STRING; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN ( GET @INDEX 1.00000000 FROM "Split"( diversion, ":" ) ) COMMENTED_BY "Returns name of water user without object name and the colon. For example, if diversion is TownOfParkerAndOtherUsers:AZ Uses, return AZ Uses"; END; FUNCTION "OtherArizonaPriority4UsersWaterUser" ( ) RETURN_TYPE LIST; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FilterByObjType"( "ListSubbasin"( "Other Arizona Priority 4 Users" ), { "WaterUser" } ) COMMENTED_BY "Returns a list of OBJECTS"; END; FUNCTION "OtherArizonaPriority4UsersAggDivSite" ( ) RETURN_TYPE LIST; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FilterByObjType"( "ListSubbasin"( "Other Arizona Priority 4 Users" ), { "AggDiversionSite" } ) COMMENTED_BY "Returns a list of OBJECTS"; END; END; UTILITY_GROUP "Arizona Priority 2 and 3 User Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ArizonaPriority2and3UsersWaterUser" ( ) RETURN_TYPE LIST; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "FilterByObjType"( "ListSubbasin"( "Arizona Priority 2 and 3 Users" ), { "WaterUser" } ) COMMENTED_BY "Returns a list of OBJECTS"; END; FUNCTION "TotalPriority2and3ActualUse" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SumObjectsAggregatedOverTime"( "Arizona Priority 2 and 3 Users", "Depletion Requested", "SUM", "ALL", TRUE, startDate, endDate ); END; FUNCTION "MakeSlotNameWaterUserPriority2and3" ( OBJECT diversion ) RETURN_TYPE STRING; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "ArizonaPriority2and3Schedules.Depletion_" CONCAT "GetSlotNameForScheduleWaterUser"( STRINGIFY diversion ); END; FUNCTION "TotalPriority2and3ScheduledUse" ( DATETIME startDate, DATETIME endDate ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-ft"; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN FOR ( OBJECT diversion IN "ArizonaPriority2and3UsersWaterUser"( ) ) WITH NUMERIC result = 0.00000000 "acre-ft" DO result + "SumFlowsToVolume"( "GetSlot"( "MakeSlotNameWaterUserPriority2and3"( diversion ) ), startDate, endDate ) ENDFOR; END; END; UTILITY_GROUP "Stochastic Functions"; DESCRIPTION ""; ACTIVE TRUE; BEGIN FUNCTION "ComputeMeadStoragePlusInflowBeforeRelease" ( ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; BEGIN "SolveStorage"( % "Mead", $ "Mead.Inflow" [], 0.00000000 "acre-feet/month", $ "Mead.Storage" [@"t - 1"], @"t" ); END; FUNCTION "ComputeStorageAtGivenInOut" ( OBJECT reservoir, NUMERIC outflow, NUMERIC inflow ) RETURN_TYPE NUMERIC; SCALE_UNITS "acre-feet"; DESCRIPTION "KGW - This function does not solve if the reservoir solves below the elevation volume table, therefore its usefulness is limited to solving within the viable range"; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT "InactiveCapacity"( reservoir ); MAX_CONSTRAINT "LiveCapacity"( reservoir ); BEGIN "SolveStorage"( reservoir, inflow, outflow, "PreviousStorage"( reservoir ), @"t" ); END; FUNCTION "ComputeOutflowAtGivenStorage_Critical" ( OBJECT reservoir, NUMERIC storage ) RETURN_TYPE NUMERIC; SCALE_UNITS ""; DESCRIPTION ""; ACTIVE TRUE; PRE_EXEC_DIAG TRUE; POST_EXEC_DIAG TRUE; MIN_CONSTRAINT 0.00000000; MAX_CONSTRAINT "MaxRelease"( reservoir ); BEGIN "SolveOutflow"( reservoir, reservoir & "Inflow" [], storage, "PreviousStorage"( reservoir ), @"t" ); END; END; END