private void SetupControls() { if (FWSim != null) { foreach (string StateName in ProviderClass.StateNames) { StateClass TempStateClass = new StateClass(StateName); TheStates.Add(TempStateClass); } for (int i = 0; i < ProviderClass.ProviderNameList.Length; i++) { string MySTate = ProviderClass.RegionStateName[i]; StateClass MyStateClass = TheStates.Find( delegate(StateClass SC) { return(SC.Name == MySTate); }); if (MyStateClass != null) { string RName = ProviderClass.ProviderNameList[i]; eProvider Ep = (eProvider)i; string RFld = ProviderClass.FieldNameList[i]; MyStateClass.AddRegion(RName, Ep, i, RFld); } } foreach (StateClass SC in TheStates) { TreeNode TempStateNode = new TreeNode(SC.Name); foreach (RegionClass RC in SC.Regions) { TempStateNode.Nodes.Add(new TreeNode(RC.Name)); } this.Nodes.Add(TempStateNode); } } }
////------------------ /// <summary> /// indexer for indexed array gets and sets based on eProvider enum values /// </summary> /// <param name="index">eProvider index</param> /// <value>indexed Model Parameter value</value> /// <returns>value in provider array for eProvider index</returns> /// <exception cref="WaterSim_Exception">Should throw exception if set and value viloates a range rule</exception> public override int this[eProvider index] { get { if (!ProviderClass.valid(index)) { throw new WaterSim_Exception(WS_Strings.wsInvalidProvider); } return(Values[index]); } set { if (!ProviderClass.valid(index)) { throw new WaterSim_Exception(WS_Strings.wsInvalidProvider); } string errMessage = ""; if (Fpm.CheckProviderValueRange(Femp, value, (eProvider)index, ref errMessage)) { Values[index] = value; } else { throw new WaterSim_Exception(errMessage); } } }
public RegionClass(string aName, eProvider AnEProvider, int aIndex, string aFieldName, StateClass owner) { Fname = aName; FeP = AnEProvider; FIndex = aIndex; FOwner = owner; FFldName = aFieldName; }
public void AddRegion(string aName, eProvider aProvider, int anIndex, string aField) { RegionClass Temp = FRegions.Find(delegate(RegionClass Reg) { return(Reg.Name == aName); }); if (Temp == null) { FRegions.Add(new RegionClass(aName, aProvider, anIndex, aField, this)); } }
public static eProvider[] GetRegion(eProvider ep) { switch (ep) { case eProvider.eState: return(RegionProviders); default: return(null); } }
public bool WriteResults(SimulationResults SR, string ScenarioName, myVariables mine, System.IO.StreamWriter SW) { bool result = false; string IDS = ""; string build = wsim.ModelBuild; // get the start year int FirstYear = SR.StartYear; // loop through all years in SR for (int yeari = 0; yeari < SR.Length; yeari++) { // Set the calender year int ThisYear = FirstYear + yeari; if (ThisYear < 2060) { // get results for this year AnnualSimulationResults ASR = SR.ByYear(ThisYear); // set the key, the scenario name and the year string BaseStr = RecCount.ToString() + "," + '"' + build + '"' + "," + ScenarioName + ThisYear.ToString(); // now loop through base outputs and set those int index = 0; foreach (int emp in ASR.Outputs.BaseOutputModelParam) { // check if this is one of the output fields if (isOutPutParam(mine, emp)) { BaseStr += "," + ASR.Outputs.BaseOutput.Values[index].ToString(); } index++; } // lopp through base inputs index = 0; foreach (int emp in ASR.Inputs.BaseInputModelParam) { if (isOutPutParam(mine, emp)) { BaseStr += "," + ASR.Inputs.BaseInput.Values[index].ToString(); } index++; } // OK, have all base stuff, now loop through providers eProvider ep = eProvider.Regional; //foreach (eProvider ep in ProviderClass.providersAll()) { // Increment the rec count RecCount++; // set the base string IDS = BaseStr + "," + '"' + ProviderClass.FieldName(ep) + '"'; // loop through provider outputs index = 0; foreach (int emp in ASR.Outputs.ProviderOutputModelParam) { // check if for output if (isOutPutParam(mine, emp)) { if ((ep < eProvider.Regional) || (ASR.Outputs.ProviderOutput[index].IncludesAggregates)) { IDS += "," + ASR.Outputs.ProviderOutput[index].Values[ProviderClass.index(ep, true)].ToString(); } else { IDS += "," + SpecialValues.MissingIntValue.ToString(); } } index++; } // loop through provider inputs index = 0; foreach (int emp in ASR.Inputs.ProviderInputModelParam) { // check if for output if (isOutPutParam(mine, emp)) { if ((ep < eProvider.Regional) || (ASR.Inputs.ProviderInput[index].IncludesAggregates)) { IDS += "," + ASR.Inputs.ProviderInput[index].Values[ProviderClass.index(ep, true)].ToString(); } else { IDS += "," + SpecialValues.MissingIntValue.ToString(); } } index++; } // ok write it out SW.WriteLine(IDS); } // provider } } // year SW.Flush(); result = true; return(result); }
///------------------------------------------------------------------------------------------------- /// <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)); }
///------------------------------------------------------------------------------------------------- /// <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)); }