///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before after each annual run. </summary>
        /// <param name="year"> The year just run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        ///
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PostProcess(int year, WaterSimManagerClass WSim)
        {
            Difference = Diff;
            Slope      = LocalSlope;

            return(base.PostProcess(year, WSim));
        }
示例#2
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary> method that is called right before the first year of a simulation is called.
        ///     </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. </returns>
        ///-------------------------------------------------------------------------------------------------


        public override bool ProcessStarted(int year, WaterSimManagerClass WSim)
        {
            // Initialize these add arrays
            //for (int i = 0; i < FAddOnPop.Length; i++) FAddOnPop[i] = 0;
            //for (int i = 0; i < FAddOffPop.Length; i++) FAddOffPop[i] = 0;

            return(base.ProcessStarted(year, WSim));
        }
示例#3
0
        public override bool PostProcess(int year, WaterSimManagerClass WS)
        {
            FSURFManagementFactor    = WS.ParamManager.Model_ParameterBaseClass(eModelParam.epSurfaceWaterManagement).Value;
            FGWManagementFactor      = WS.ParamManager.Model_ParameterBaseClass(eModelParam.epGroundwaterManagement).Value;
            FDroughtManagementFactor = WS.ParamManager.Model_ParameterBaseClass(eModelParam.epClimateDrought).Value;

            return(base.PostProcess(year, WS));
        }
示例#4
0
        // ----------------------------------------------------
        // =======================================================================
        //
        public override bool PreProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            PreProcessMyWaterManagementProcess(year, WSim);
            PreProcessMyDroughtManagementProcess(year, WSim);
            PreProcessIndicatorsProcess(year, WSim);
            return(base.PreProcess(year, WSim));
        }
 //------------------------------------------------------
 public void BuildAnnualParameterStream(WaterSimManagerClass WSIM, SimulationResults SimRes, string fldname, string fieldlabel, bool start)
 {
     if (start)
     {
         StreamW(@"Outputs\\"); StreamW1(@"Outputs\\"); StreamW2(@"Outputs\\"); StreamW3(@"Outputs\\");
     }
     //if (fldname == "POP_P") { StreamW(@"Outputs\\"); StreamW1(@"Outputs\\"); StreamW2(@"Outputs\\"); StreamW3(@"Outputs\\"); }
     BuildAnnualParameterStream(WSIM, SimRes, fldname, fieldlabel, null);
 }
示例#6
0
        public override bool ProcessStarted(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WS = (WSimClass as WaterSimManager);

            //
            ProcessWaterManagement(year, WS);
            ProcessDrought(year, WS);
            ProcessIndicators(year, WS);
            //
            return(base.ProcessStarted(year, WS));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> method that is called right before the first year of a simulation is called.
        ///     </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool ProcessStarted(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            // OK Simulation Starting, Parameters have been set, fetch the ReduceGOCD factor and use it to calculate rate
            YrCount            = 1;
            FGPCDDeclineFactor = WSim.ParamManager.Model_Parameter(eModelParam.epPCT_Alter_GPCD).Value;  // 7/29  WSim.ParamManager.BaseModel_ParameterBaseClass(eModelParam.epPCT_Reduce_GPCD).Value;
            double TotalYears = Convert.ToDouble((WSim.Simulation_End_Year - WSim.Simulation_Start_Year) + 1);

            AdjustFactor_Double = (Convert.ToDouble(FGPCDDeclineFactor) / 100) / TotalYears;
            return(base.ProcessStarted(year, WSim));
        }
示例#8
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before each annual run. </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PreProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);
            //               ProviderIntArray NewPopOff = new ProviderIntArray(0);

            bool TempLock = WSim.isLocked();

            WSim.UnLockSimulation();


            //bool ManagingPop = false;
            // for 2000 to 2010 just grab the projections
            if (year < 2015)
            {
            }        //WSim.Simulation_Start_Year + 1))
            else
            {
                ProviderIntArray YearForZero = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epYearCreditsGoesNeg).ProviderProperty.getvalues();
                ProviderIntArray IsTriggered = new ProviderIntArray(0);
                // Check which are in unassured year range
                for (int i = 0; i < YearForZero.Length; i++)
                {
                    if (TestPolicy(YearForZero[i], (WSim as WaterSimManager)))
                    {
                        ConsecutiveDeficitYears[i]++;
                        if (ConsecutiveDeficitYears[i] > Max_Years_Deficit_Trigger)
                        {
                            IsTriggered[i] = 1;
                            // Once triggered always being managed
                            BeingManaged[i] = 1;
                        }
                    }
                    else
                    {
                        ConsecutiveDeficitYears[i] = 0;
                    }
                }
                PolicyClass.ManagePolicies(WSim, year, BeingManaged, IsTriggered);
                //PopulationClass.LimitAndReallocateGrowth(WSim, year, BeingManaged, IsTriggered, FMaxUnassuredYears, ref NewPopOn, ref NewPopOff);
            }
            // Ok Set PopOverride Values
            //    for (int i = 0; i < NewPopOn.Length; i++)
            //    {
            //        WSim.Population_Override_On[i] = NewPopOn[i];
            //    }
            //    for (int i = 0; i < NewPopOff.Length; i++)
            //    {
            //        WSim.Population_Override_Other[i] = NewPopOff[i];
            //    }
            //    if (TempLock) WSim.LockSimulation();

            return(base.PreProcess(year, WSim));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method called when Sumulation is stopped. </summary>
        /// <param name="WSim"> The simulation. </param>
        /// <returns> true if it succeeds, false if it fails. </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool ProcessStop(WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            // Reset Pop Overide
            ProviderIntArray Reset = new ProviderIntArray(-1);

            WSim.Population_Override_On.setvalues(Reset);
            WSim.Population_Override_Other.setvalues(Reset);

            return(base.ProcessStop(WSim));
        }
        public override bool PreProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            bool TempLock = WSim.isLocked();

            WSim.UnLockSimulation();
            FetchValuesForPersonal(WSim);
            if (TempLock)
            {
                WSim.LockSimulation();
            }

            return(base.PreProcess(year, WSim));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> method that is called right before the first year of a simulation is called.
        ///     </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        ///
        /// <returns> true if it succeeds, false if it fails. </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool ProcessStarted(int year, WaterSimManagerClass WSim)
        {
            // zero out accumulating arrays
            for (int i = 0; i < FYearsOfZeroOrBelow.Length; i++)
            {
                FPctCreditsAvail[i]  = 0;
                FYearsNegative[i]    = 0;
                FInitialLevel[i]     = 0;
                FAvailSlope[i]       = 0.0;
                FSlopeIntercept[i]   = 0.0;
                FYearCreditsGoNeg[i] = 0;

                // Get Initial Levels
            }
            return(base.ProcessStarted(year, WSim));
        }
        //----------------------------------------------------
        /// <summary>
        /// This is the ProcessMethod that keeps track of Deficits by provider
        /// </summary>
        /// <param name="year">Simulation Year (not used)</param>
        /// <param name="WSim">The WaterSimManager object (used to get data)</param>
        /// <returns></returns>
        override public bool PostProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            ProviderIntArray Deficits       = new ProviderIntArray();
            ProviderIntArray CreditDeficits = new ProviderIntArray();

            // get the deficit data
            Deficits       = WSim.Demand_Deficit.getvalues();
            CreditDeficits = WSim.AF_water_CreditDeficits.getvalues();

            foreach (eProvider ep in ProviderClass.providers())
            {
                if (Deficits[ep] > FMaxDeficit)
                {
                    CountList[ep]++;
                    TotalList[ep] += Deficits[ep];
                    ContinuousList[ep]++;
                    if (LongestContinuous[ep] < ContinuousList[ep])
                    {
                        LongestContinuous[ep] = ContinuousList[ep];
                    }
                }
                else
                {
                    ContinuousList[ep] = 0;
                }
                //
                if (CreditDeficits[ep] > FMaxCreditDeficit)
                {
                    CountList_2[ep]++;
                    TotalList_2[ep] += CreditDeficits[ep];
                    ContinuousList_2[ep]++;
                    if (LongestContinuous_2[ep] < ContinuousList_2[ep])
                    {
                        LongestContinuous_2[ep] = ContinuousList_2[ep];
                    }
                }
            }
            return(true);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before after each annual run. </summary>
        /// <param name="year"> The year just run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        ///
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PostProcess(int year, WaterSimManagerClass WSim)
        {
            return(base.PostProcess(year, WSim));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before each annual run. </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PreProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager  WSim         = (WSimClass as WaterSimManager);
            ProviderIntArray PulledPopOn  = WSim.Projected_OnProject_Pop.getvalues();
            ProviderIntArray PulledPopOff = WSim.Projected_Other_Pop.getvalues();
            ProviderIntArray NewPopOn     = new ProviderIntArray(0);
            ProviderIntArray NewPopOff    = new ProviderIntArray(0);

            bool TempLock = WSim.isLocked();

            WSim.UnLockSimulation();


            //bool ManagingPop = false;
            // for 2000 to 2010 just grab the projections
            if (year < 2011)
            {
                for (int i = 0; i < NewPopOn.Length; i++)
                {
                    NewPopOn[i] = PulledPopOn[i];
                }

                for (int i = 0; i < NewPopOff.Length; i++)
                {
                    NewPopOff[i] = PulledPopOff[i];
                }
            }    //WSim.Simulation_Start_Year + 1))
            else
            {
                ProviderIntArray LastYearOnPop  = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epOnProjectPopulation).ProviderProperty.getvalues();
                ProviderIntArray LastYearOffPop = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epOtherPopulation).ProviderProperty.getvalues();
                ProviderIntArray YearForZero    = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epYearGWGoesZero).ProviderProperty.getvalues();
                ProviderIntArray IsTriggered    = new ProviderIntArray(0);
                // Check which are in unassured year range
                for (int i = 0; i < YearForZero.Length; i++)
                {
                    if (TestUnassured(YearForZero[i], (WSim as WaterSimManager)))
                    {
                        ConsecutiveUnassuredYears[i]++;
                        if (ConsecutiveUnassuredYears[i] > FMaxUnassuredYears)
                        {
                            IsTriggered[i] = 1;
                            // Once triggered always being managed
                            BeingManaged[i] = 1;
                        }
                    }
                    else
                    {
                        ConsecutiveUnassuredYears[i] = 0;
                    }
                }

                PopulationClass.LimitAndReallocateGrowth(WSim, year, BeingManaged, IsTriggered, FMaxUnassuredYears, ref NewPopOn, ref NewPopOff);
            }
            // Ok Set PopOverride Values
            for (int i = 0; i < NewPopOn.Length; i++)
            {
                WSim.Population_Override_On[i] = NewPopOn[i];
            }
            for (int i = 0; i < NewPopOff.Length; i++)
            {
                WSim.Population_Override_Other[i] = NewPopOff[i];
            }
            if (TempLock)
            {
                WSim.LockSimulation();
            }

            return(base.PreProcess(year, WSim));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> method that is called when a Simulation is initialized. </summary>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. </returns>
        /// ### <seealso cref="ProcessStarted"/>
        ///-------------------------------------------------------------------------------------------------

        public override bool ProcessInitialized(WaterSimManagerClass WSim)
        {
            return(base.ProcessInitialized(WSim));
        }
        public void BuildAnnualParameterStream(WaterSimManagerClass WSIM, SimulationResults SimRes, string fldname, string fieldlabel, string[] Regions)
        {
            List <string> debug = new List <string>();
            int           year  = 0;

            int yearCount = SimRes.Length;

            // run through once
            if (fldname == "AD_P")
            {
                int ProviderCount = SimRes[0].Outputs.ProviderOutput[0].Values.Length;


                for (int i = 0; i < 89; i++)
                {
                    // cities and towns demand
                    if (i == 18)
                    {
                        for (int j = 0; j < 36; j++)
                        {
                            year = j + 2015;
                            for (int k = 0; k < 24; k++)
                            {
                                string ProviderName = ProviderClass.ProviderNameList[k];
                                int[]  R            = SimRes[j].Outputs.ProviderOutput[i].Values;
                                sw.WriteLine(ProviderName + "," + i + "," + j + "," + k + "," + year + "," + R[k]);
                            }
                        }
                    }
                }
                sw.Flush();
                sw.Close();
                for (int i = 0; i < 89; i++)
                {
                    // industry
                    if (i == 22)
                    {
                        for (int j = 0; j < 36; j++)
                        {
                            year = j + 2015;
                            for (int k = 0; k < 24; k++)
                            {
                                string ProviderName = ProviderClass.ProviderNameList[k];
                                int[]  R            = SimRes[j].Outputs.ProviderOutput[i].Values;
                                sw1.WriteLine(ProviderName + "," + i + "," + j + "," + k + "," + year + "," + R[k]);
                            }
                        }
                    }
                }
                sw1.Flush();
                sw1.Close();
                for (int i = 0; i < 89; i++)
                {
                    // power
                    if (i == 26)
                    {
                        for (int j = 0; j < 36; j++)
                        {
                            year = j + 2015;
                            for (int k = 0; k < 24; k++)
                            {
                                string ProviderName = ProviderClass.ProviderNameList[k];
                                int[]  R            = SimRes[j].Outputs.ProviderOutput[i].Values;
                                sw2.WriteLine(ProviderName + "," + i + "," + j + "," + k + "," + year + "," + R[k]);
                            }
                        }
                    }
                }
                sw2.Flush();
                sw2.Close();
                for (int i = 0; i < 89; i++)
                {
                    // Agriculture
                    if (i == 20)
                    {
                        for (int j = 0; j < 36; j++)
                        {
                            year = j + 2015;
                            for (int k = 0; k < 24; k++)
                            {
                                string ProviderName = ProviderClass.ProviderNameList[k];
                                int[]  R            = SimRes[j].Outputs.ProviderOutput[i].Values;
                                sw3.WriteLine(ProviderName + "," + i + "," + j + "," + k + "," + year + "," + R[k]);
                            }
                        }
                    }
                }
                sw3.Flush();
                sw3.Close();
            }
        }
 public CreateNewFileDialog(WaterSimManagerClass WSim, string Database)
 {
     InitializeComponent();
     MyWaterSimManager = WSim;
 }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before each annual run. </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------


        public override bool PreProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);
            double          GPCD_Decline_Double = 0;
            double          MyGPCD = 0;

            // I  yet do not understand "Step"
            Step = true;
            // // Check if first run
            ProviderIntArray FUSED_GPCD = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epGPCD_Used).ProviderProperty.getvalues();
            ProviderIntArray RAW_GPCD   = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epGPCDraw).ProviderProperty.getvalues();

            // OK Not First year
            // Check if model is locked, if so unlock it.
            bool TempLock = WSim.isLocked();

            if (TempLock)
            {
                WSim.UnLockSimulation();
            }
            double[] previousBalance = new double[ProviderClass.NumberOfProviders];
            // Get data we need to evaluate GPCD
            ModelParameterBaseClass MP;

            MP = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epGroundwater_Balance);

            ProviderIntArray FBalance  = MP.ProviderProperty.getvalues();
            ProviderIntArray FPCT_BAL  = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epGroundwater_Balance).ProviderProperty.getvalues();
            ProviderIntArray New_slope = new ProviderIntArray(0);

            // ---------------------------------------------------------------------------------------------------------------------------------------------------
            if (Step)
            {
                MyGPCDProcess(year, (WSim as WaterSimManager));
            }
            else
            {
                for (int i = 0; i < Initial_Credits.Length; i++)
                {
                    if (year == 2001)
                    {
                        PBalance[i] = Initial_Credits[i];
                    }
                    else
                    {
                        PBalance[i] = Bcurrent[i];
                    }
                    PreviousBal[i] = PBalance[i];
                    Bcurrent[i]    = Convert.ToDouble(FBalance[i]);
                }
                if (2011 < year)
                {
                    //
                    for (int i = 0; i < ProviderClass.NumberOfProviders; i++)
                    {
                        New_slope[i] = Convert.ToInt32(WSim.API_defaultSlope_GPCD[i]);
                    }
                    WSim.PCT_alter_GPCD.setvalues(New_slope);
                    //
                    // create and array to set GPCD
                    // ProviderIntArray FSet_GPCD = new ProviderIntArray(0);
                    double Islope      = 0;
                    double maxResponse = -10;
                    // Loop through providers and check for PCT_Deficit that exceed FMaxDifference
                    bool SetGPCDS = false;
                    for (int i = 0; i < FPCT_BAL.Length; i++)
                    {
                        //if (i == provider)
                        //{
                        Diff   = 0;
                        Islope = 0;
                        // this is strange code! how does it work?
                        eProvider ep = (eProvider)i;
                        Islope = utilities.Slope(Convert.ToDouble(year - 1), Convert.ToDouble(year), PreviousBal[i], Bcurrent[i]);
                        Diff   = utilities.Difference(Bcurrent[i], PreviousBal[i]);

                        MyGPCD = GPCD_original[i];

                        GPCD_Decline_Double = 0;
                        int    myDiff  = 0;
                        double DiffUse = 0;

                        if (0 <= Diff)
                        {
                            myDiff = 1;
                            MyGPCD = GPCD_raw[i];
                        }
                        if (Diff < 0)
                        {
                            myDiff = 2;
                        }

                        double divide    = 0;
                        double alterGPCD = 0;
                        Slope = Islope;

                        switch (myDiff)
                        {
                        case 1:
                            GPCD_Decline_Double = MyGPCD;
                            break;

                        case 2:
                            DiffUse = Math.Abs(Math.Max(-0.999999, Diff));
                            divide  = 2000 * (1 - DiffUse);
                            //GPCD_Decline_Double = MyGPCD + (Math.Min(maxResponse, (Islope / divide) * (1 + (DiffUse / 1.5))) * ModResponse);
                            alterGPCD           = Math.Max(maxResponse, ((Islope * ModResponse) / divide) * (1 + DiffUse) / 2);
                            GPCD_Decline_Double = MyGPCD + alterGPCD;

                            // Force flat responses to decrease by one GPCD per year
                            // for those water providers with a decreasing trend in GPCD
                            // 09.22.15 DAS
                            if (GPCD_Decline_Double == MyGPCD)
                            {
                                if (WSim.PCT_alter_GPCD.getvalues().Values[i] < 0)
                                {
                                    GPCD_Decline_Double = MyGPCD - 1;
                                }
                            }
                            if (MyGPCD < GPCD_Decline_Double)
                            {
                                if (WSim.PCT_alter_GPCD.getvalues().Values[i] == 0)
                                {
                                    GPCD_Decline_Double = MyGPCD - alterGPCD;
                                }
                            }

                            break;

                        default:
                            GPCD_Decline_Double = MyGPCD;

                            break;
                        }

                        int New_GPCD = Convert.ToInt32(GPCD_Decline_Double);
                        if ((New_GPCD > FMinGPCD))
                        {
                            FUSED_GPCD[i] = New_GPCD;
                        }
                        else
                        {
                            FUSED_GPCD[i] = FMinGPCD;
                        }
                        GPCD_old[i] = FUSED_GPCD[i];
                        SetGPCDS    = true;

                        if (Islope == 0)
                        {
                            GPCD_old[i]   = AdjustGPCD(GPCD_old[i]);
                            FUSED_GPCD[i] = Convert.ToInt32(GPCD_old[i]);
                        }

                        //} // provider
                        //
                    }
                    // All Done
                    if (SetGPCDS)
                    {
                        WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epUse_GPCD).ProviderProperty.setvalues(FUSED_GPCD);
                    }

                    // if model was locked comming in, set lock going out
                    if (TempLock)
                    {
                        WSim.LockSimulation();
                    }
                }     // 2012 < year
            }
            return(base.PreProcess(year, WSim));
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called before each annual run. </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PreProcess(int year, WaterSimManagerClass WSim)
        {
            // Check if first run
            ProviderIntArray FUSED_GPCD = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epGPCD_Used).ProviderProperty.getvalues();

            YrCount++;
            // Set oldGOCD to these values.
            for (int i = 0; i < FUSED_GPCD.Values.Length; i++)
            {
                GPCD_old[i] = Convert.ToDouble(FUSED_GPCD[i]);
            }
            //}
            // not first year, do it
            WSim.ParamManager.Model_Parameter(eModelParam.epProvider_Demand_Option).Value = 4;  // 7/29 WSim.ParamManager.BaseModel_ParameterBaseClass(eModelParam.epProvider_Demand_Option).Value = 4;
            // OK Not First year
            // Check if model is locked, if so unlock it.
            bool TempLock = WSim.isLocked();

            if (TempLock)
            {
                WSim.UnLockSimulation();
            }

            // Get data we need to evaluate AWS

            ProviderIntArray AWS_Years = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epYearsNotAssured).ProviderProperty.getvalues();
            ProviderIntArray FPOP      = WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epPopulation_Used).ProviderProperty.getvalues();
            // create and array to set GPCD
            ProviderIntArray FSet_GPCD = new ProviderIntArray(0);
            // Loop through providers and check for AWS_Years FMaxAWS
            bool SetGPCDS = false;

            for (int i = 0; i < AWS_Years.Length; i++)
            {
                if (AWS_Years[i] > FMaxAWS)
                {
                    eProvider ep = (eProvider)i;
                    // OK Calculated how much lower GPCD needs to go to accomodate
                    ////int MyDeficit_AF = FDeficit[i];
                    //double MyDeficit_G = util.ConvertAFtoGallons(MyDeficit_AF);
                    //int MyPCTDeficit = FPCT_Deficit[i];
                    //int MyPop = FPOP[i];
                    //double GPCD_Decline_Double = 0.0;
                    int GPCD_Decline_Int = 0;
                    int MyGPCD           = FUSED_GPCD[i];
                    //// if (MyPop > MyDeficit) then it will be 1
                    //GPCD_Decline_Double = util.CalcGPCD(MyDeficit_G, MyPop);
                    //GPCD_Decline_Int = Convert.ToInt32(GPCD_Decline_Double);
                    GPCD_Decline_Int = (MyGPCD * FAnnualPercentDecline) / 100;
                    int New_GPCD = MyGPCD - GPCD_Decline_Int;
                    // Checl if New GPCD not to low
                    if ((New_GPCD > FMinGPCD))
                    {
                        FUSED_GPCD[i] = New_GPCD;
                    }
                    else
                    {
                        FUSED_GPCD[i] = FMinGPCD;
                    }
                    GPCD_old[i] = FUSED_GPCD[i];
                    SetGPCDS    = true;
                }
                else
                {
                    GPCD_old[i]   = AdjustGPCD(GPCD_old[i]);
                    FUSED_GPCD[i] = Convert.ToInt32(GPCD_old[i]);
                }
            }
            //
            // All Done
            if (SetGPCDS)
            {
                WSim.ParamManager.Model_ParameterBaseClass(eModelParam.epUse_GPCD).ProviderProperty.setvalues(FUSED_GPCD);
            }


            // if model was locked comming in, set lock going out
            if (TempLock)
            {
                WSim.LockSimulation();
            }

            return(base.PreProcess(year, WSim));
        }
示例#20
0
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Builds an annual parameter graph. </summary>
        /// <param name="DT">           The datatable. </param>
        /// <param name="DbConnection"> The database connection. </param>
        /// <param name="Providers">    The providers to be charted. </param>
        /// <param name="fldname">      The fldname or column name to be charted. </param>
        ///-------------------------------------------------------------------------------------------------
        //public void BuildAnnualParameterGraph(DataTable DT, UniDbConnection DbConnection, string ScenarioName, List<providerinfo> Providers, string fldname, string fieldlabel)

        public void BuildAnnualParameterGraph(WaterSimManagerClass WSIM, SimulationResults SimRes, string fldname, string fieldlabel, string[] Regions)
        {
            List <string> debug = new List <string>();

            // create a lits for data
            List <ChartPointsByYear> ChartSeriesList = new List <ChartPointsByYear>();

            // ok clear up chart
            FChart.Series.Clear();
            FChart.Legends.Clear();
            FChart.ChartAreas.Clear();
            //                    ProviderPopChart.Update();

            // Setup legend

            FChart.ChartAreas.Add(FTitle);
            System.Windows.Forms.DataVisualization.Charting.Legend MyLegend = new System.Windows.Forms.DataVisualization.Charting.Legend("Default");
            FChart.Legends.Add(MyLegend);
            // get data


            int    pIndex    = -1;
            int    year      = 0;
            int    pop       = 0;
            string pcode     = "";
            int    yearCount = 0;
            int    yearIndex = 0;
            // OK, figure out the years Min Max and Count
            int MaxYear = -1;
            int MinYear = 9999;


            // There must be a way to speed this up!
            foreach (AnnualSimulationResults ASR in SimRes)
            {
                year = ASR.year;
                if (year > MaxYear)
                {
                    MaxYear = year;
                }
                if (year < MinYear)
                {
                    MinYear = year;
                }
            }


            yearCount = (MaxYear - MinYear) + 1;

            // OK can set up the dta
            int ProviderCount = SimRes[0].Outputs.ProviderOutput[0].Values.Length;

            //int ProviderCount = Providers.Count;
            // create provider value data array
            int[][] ValueData = null; // new int[ProviderCount][];
                                      // now create new arrays (years length) for each provider array
                                      //for (int i = 0; i < ProviderCount; i++)
                                      //  ValueData[i] = new int[yearCount];

            // Cycle through each record and stick data into the right slot

            // first get the parmeters index into AnnualResults arrays
            ModelParameterClass theModelParmeter = WSIM.ParamManager.Model_Parameter(fldname);
            int ModelParmIndex = SimRes[0].GetParmIndex(theModelParmeter);

            ValueData = GrabProviderDataByYear(SimRes, theModelParmeter);

            // OK create the series
            // First create a year array
            int[] allYearValues = new int[yearCount];
            for (int i = 0; i < yearCount; i++)
            {
                allYearValues[i] = MinYear + i;
            }
            for (int i = 0; i < ProviderCount; i++)
            {
                string ProviderName   = ProviderClass.ProviderNameList[i];
                bool   DoThisProvider = false;

                if ((Regions == null) || (Regions.Length == 0))
                {
                    DoThisProvider = true;
                }
                else
                {
                    foreach (string RegName in Regions)
                    {
                        if (RegName == ProviderName)
                        {
                            DoThisProvider = true;
                            break;
                        }
                    }
                }

                if (DoThisProvider)
                {
                    ChartPointsByYear points = new ChartPointsByYear(allYearValues, ValueData[i], ProviderName);
                    ChartSeriesList.Add(points);
                }
            }
            //  Now Sort By Size
            ChartSeriesList.Sort(ChartPointsByYear.CompareForSort_UseMax);


            foreach (ChartPointsByYear points in ChartSeriesList)
            {
                Series dSeries = new Series();
                int[]  Years   = points.Years;
                int[]  Values  = points.Values;
                dSeries.LegendText   = points.SeriesLabel;
                dSeries.ChartType    = FChartType;
                dSeries.BorderWidth  = 3;
                dSeries.MarkerSize   = 20;
                dSeries.LabelToolTip = points.SeriesLabel;
                for (int j = 0; j < Years.Length; j++)
                {
                    dSeries.Points.AddXY(Years[j], Values[j]);
                }
                FChart.Series.Add(dSeries);
            }


            FChart.ChartAreas[0].AxisX.Minimum  = MinYear;
            FChart.ChartAreas[0].AxisX.Maximum  = MaxYear;
            FChart.ChartAreas[0].AxisX.Interval = 5;
            // Chart Label
            bool  addTitle = false;
            Title myTitle  = null;

            if (FChart.Titles.Count > 0)
            {
                myTitle = FChart.Titles.FindByName("MAIN");
            }
            if (myTitle == null)
            {
                myTitle  = new Title();
                addTitle = true;
            }
            myTitle.Name      = "MAIN";
            myTitle.Text      = fieldlabel + " by Water Provider and Year";
            myTitle.Font      = new Font(myTitle.Font.Name, 14.0F, FontStyle.Bold, myTitle.Font.Unit);
            myTitle.Alignment = ContentAlignment.MiddleCenter;
            if (addTitle)
            {
                FChart.Titles.Add(myTitle);
            }
            // Chart Legend
            /// <summary> The second column. </summary>
            LegendCellColumn secondColumn = new LegendCellColumn();

            secondColumn.ColumnType      = LegendCellColumnType.Text;
            secondColumn.HeaderText      = "Name";
            secondColumn.Text            = "#LEGENDTEXT";
            secondColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(secondColumn);

            // Set Min cell column attributes
            LegendCellColumn maxColumn = new LegendCellColumn();

            maxColumn.Text            = "#MAX{N1}";
            maxColumn.HeaderText      = "Max";
            maxColumn.Name            = "MaxColumn";
            maxColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(maxColumn);
            // Add Color column
            LegendCellColumn firstColumn = new LegendCellColumn();

            firstColumn.ColumnType      = LegendCellColumnType.SeriesSymbol;
            firstColumn.HeaderText      = "Color";
            firstColumn.HeaderBackColor = Color.WhiteSmoke;
            FChart.Legends["Default"].CellColumns.Add(firstColumn);
            // OK let's see what happens

            //FChart.Update;
            //FChart.Scale(new SizeF())
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary> Method that is called after each annual run. </summary>
        /// <param name="year"> The year about to be run. </param>
        /// <param name="WSim"> The WaterSimManager that is making call. </param>
        /// <returns> true if it succeeds, false if it fails. Error should be placed in FErrorMessage.
        ///     </returns>
        ///-------------------------------------------------------------------------------------------------

        public override bool PostProcess(int year, WaterSimManagerClass WSimClass)
        {
            WaterSimManager WSim = (WSimClass as WaterSimManager);

            // check if GW is zero or below
            ProviderIntArray CreditBal = new ProviderIntArray(0);

            CreditBal = WSim.AF_water_CreditDeficits.getvalues();
            if (year == WSim.Simulation_Start_Year)
            {
                for (int i = 0; i < CreditBal.Length; i++)
                {
                    FInitialLevel[i] = CreditBal[i];
                    if (CreditBal[i] > 0)
                    {
                        FPctCreditsAvail[i]  = 100;
                        FYearCreditsGoNeg[i] = 1;
                    }
                    else
                    {
                        FPctCreditsAvail[i]  = 0;
                        FYearCreditsGoNeg[i] = 0;
                    }
                }
            }
            else
            {
                for (int i = 0; i < CreditBal.Length; i++)
                {
                    if (CreditBal[i] < 1)
                    // If zero or below, start counting
                    {
                        FYearsOfZeroOrBelow[i]++;
                        if (FYearOfZero[i] == 0)
                        {
                            FYearOfZero[i] = year;
                        }
                    }
                    // calculate slope and X intercept (ie projected year 0)
                    double Y1   = Convert.ToDouble(CreditBal[i]);
                    double Rise = Y1 - Convert.ToDouble(FInitialLevel[i]);
                    double X1   = Convert.ToDouble(year);
                    double Run  = Convert.ToDouble(year - WSim.Simulation_Start_Year);
                    if ((Rise < 0) && (Run > 0))
                    {
                        FAvailSlope[i] = Rise / Run;
                        double eqconstant = Y1 - (FAvailSlope[i] * X1);
                        if ((FAvailSlope[i] != 0) && (eqconstant != 0))
                        {
                            FSlopeIntercept[i] = (-1 * eqconstant) / FAvailSlope[i];
                        }
                        else
                        {
                            FSlopeIntercept[i] = 0;
                        }
                    }
                    else
                    {
                        FAvailSlope[i]     = 0;
                        FSlopeIntercept[i] = 0;
                    }
                    // check if first year
                    if ((FSlopeIntercept[i] > WSim.Simulation_Start_Year) && (FSlopeIntercept[i] < year + SlopeYears))
                    {
                        FYearsNegative[i]++;
                    }
                    // This should only happen if the utility has no groundwater
                    if (FInitialLevel[i] > 0)
                    {
                        // calculate PCT GW Avail
                        double InitLevel = Convert.ToDouble(FInitialLevel[i]);
                        FPctCreditsAvail[i] = Convert.ToInt32((Convert.ToDouble((CreditBal[i]) / InitLevel) * 100));
                    }
                    else
                    {  // no groundwater
                        // OK here is a wierd rule.  It is possible for a utility to start with no ground water and acquire ground water,
                        // If that is the case, then the first time groundwater is acquired, then balance is set to that.
                        if (CreditBal[i] > 0)
                        {
                            FInitialLevel[i]     = CreditBal[i];
                            FPctCreditsAvail[i]  = 100;
                            FYearCreditsGoNeg[i] = 1;
                        }
                        else
                        {
                            FPctCreditsAvail[i]  = 0;
                            FYearCreditsGoNeg[i] = 0;
                        }
                    }
                }
            }

            return(base.PostProcess(year, WSim));
        }
示例#22
0
 public void BuildAnnualParameterGraph(WaterSimManagerClass WSIM, SimulationResults SimRes, string fldname, string fieldlabel)
 {
     BuildAnnualParameterGraph(WSIM, SimRes, fldname, fieldlabel, null);
 }