public Sim_TransformerWinding(string Name, Sim_Transformer Transformer, Sim_Bus Bus, Sim_Company Owner, Sim_Company Operator, bool IsPrimary, Sim_Builder Builder) { this.Name = Name; this.TEID = Builder.NextTEID(); this.Owner = Owner; this.Operator = Operator; this.Bus = Bus; this.IsPrimary = IsPrimary; this.Transformer = Transformer; this.Substation = Transformer.Substation; this.WindingNodeTEID = Builder.NextTEID(); }
public Sim_Load(String Name, Sim_Substation Parent, Sim_Bus Bus, double MW_Est, double MVAR_Est, Sim_Builder Builder) { this.Substation = Parent; this.ElemGuid = Guid.NewGuid(); this.Substation.Elements.Add(this); this.Name = Name; this.MW_Est = MW_Est; this.MVAR_Est = MVAR_Est; this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.TEID = Builder.NextTEID(); this.Bus = Bus; }
public Sim_Breaker(String Name, Sim_Substation Sub, Sim_Bus NearBus, Sim_Bus FarBus, Sim_Builder Builder, bool Open, bool IsBreaker) { this.Name = Name; this.ElemGuid = Guid.NewGuid(); this.IsBreaker = IsBreaker; this.Substation = Sub; this.NearBus = NearBus; this.FarBus = FarBus; this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.TEID = Builder.NextTEID(); this.Open = Open; this.Substation.Elements.Add(this); }
public Sim_ShuntCompensator(String Name, Sim_Substation Sub, Sim_Bus Bus, bool Open, double MVAR_Est, double MVAR_Nominal, bool IsCapacitor, Sim_Builder Builder) { this.Name = Name; this.Substation = Sub; this.Bus = Bus; this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.TEID = Builder.NextTEID(); this.Open = Open; this.Nominal_MVAR = MVAR_Nominal; Sub.Elements.Add(this); this.Estimated_MVAR = MVAR_Est; this.IsCapacitor = IsCapacitor; this.ElemGuid = Guid.NewGuid(); }
public Sim_Unit(String Name, Sim_Bus Bus, Sim_Substation Parent, Sim_UnitType UnitType, double MW_Est, double MVAR_Est, double PercentageCapacity, Sim_Builder Builder) { this.Substation = Parent; this.Substation.Elements.Add(this); this.ElemGuid = Guid.NewGuid(); this.Name = Name; this.UnitType = UnitType; this.MW_Est = MW_Est; this.MVAR_Est = MVAR_Est; this.LMP = Builder.NextRandom(2, 50); this.MVA_Est = Math.Round(Math.Sqrt(MW_Est * MW_Est + MVAR_Est * MVAR_Est)); this.Capacity = this.MW_Est / PercentageCapacity; this.TEID = Builder.NextTEID(); this.UnitTEID = Builder.NextTEID(); this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.Bus = Bus; }
public Sim_Line(Sim_Substation From, Sim_Substation To, List <Sim_Line> Lines, Sim_Builder Builder, double MW_Est, double MVAR_Est, double LineLoading) { this.ElemGuid = Guid.NewGuid(); this.From = From; this.To = To; this.Name = "Line" + Lines.Count.ToString("000"); this.MW_Est = MW_Est; this.MVAR_Est = MVAR_Est; this.MVA_Est = Math.Sqrt(MW_Est * MW_Est + MVAR_Est * MVAR_Est); this.NormalLimit = this.MVA_Est / LineLoading; this.EmergencyLimit = this.NormalLimit + Builder.Randomizer.Next(10); this.LoadshedLimit = this.EmergencyLimit + Builder.Randomizer.Next(10); this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.TEID = Builder.NextTEID(); this.From.Elements.Add(this); this.To.Elements.Add(this); this.NearBus = From.FindBus(Builder); this.FarBus = To.FindBus(Builder, this.NearBus.Voltage); }
/// <summary> /// Locate a bus /// </summary> /// <param name="Builder"></param> /// <param name="RequiredVoltages"></param> /// <returns></returns> public Sim_Bus FindBus(Sim_Builder Builder, params Sim_VoltageLevel[] RequiredVoltages) { List <Sim_Bus> BusCandidates = new List <Sim_Bus>(); foreach (Sim_Bus Bus in this.Elements.OfType <Sim_Bus>()) { if (RequiredVoltages.Length == 0 || Array.IndexOf(RequiredVoltages, Bus.Voltage) != -1) { BusCandidates.Add(Bus); } } //If we don't have a bus of the proper voltage, create it. if (RequiredVoltages.Length > 0 && BusCandidates.Count == 0) { Sim_Bus NewBus = new Sim_Bus(this, Builder.Buses.Count, "Bus" + Builder.Buses.Count.ToString(), Builder.Randomizer.GenerateNumber(1, Builder.Config.BusVoltageStdDev / 100.0), Builder); Builder.Buses.Add(NewBus); BusCandidates.Add(NewBus); } return(BusCandidates[Builder.Randomizer.Next(0, BusCandidates.Count)]); }
/// <summary> /// Build our simulated model /// </summary> /// <param name="Config"></param> public Sim_Builder(Sim_Builder_Configuration Config, String SubstationText) { this.Config = Config; //Start by building our companies for (int a = 0; a < Config.CompanyCount; a++) { Companies.Add(new Sim_Company("Company" + a.ToString(), "TCOM" + a.ToString(), "-Unknown-", "-Unknown-", this)); } //Add in our voltage levels Voltages.Add(new Sim_VoltageLevel(345)); Voltages.Add(new Sim_VoltageLevel(230)); Voltages.Add(new Sim_VoltageLevel(138)); Voltages.Add(new Sim_VoltageLevel(69)); //Add in our unit types UnitTypes.Add(new Sim_UnitType("NuclearGeneratingUnit")); UnitTypes.Add(new Sim_UnitType("ThermalGeneratingUnit")); UnitTypes.Add(new Sim_UnitType("WindGeneratingUnit")); //Add in our county and state boundaries if (Config.BaseModel != null) { LoadModel(Config.BaseModel); } else { LoadBoundary(Config.CountyBoundary, true); LoadBoundary(Config.StateBoundary, false); } //Now, add in our substations AddSubstations(Config.SubstationCount, SubstationText); //Now, for each sub, add our buses and breakers foreach (Sim_Substation Sub in Subs) { Sim_Bus NewBus = new Sim_Bus(Sub, Buses.Count, "Bus" + Buses.Count.ToString("000"), Randomizer.GenerateNumber(1, Config.BusVoltageStdDev / 100.0), this); Buses.Add(NewBus); bool IsOpen = NextRandom(0, 1) > 0.5; bool IsBreaker = NextRandom(0, 1) > 0.5; if (!IsOpen) { Breakers.Add(new Sim_Breaker((IsBreaker ? "Breaker" : "Switch") + Breakers.Count.ToString("000"), Sub, NewBus, NewBus, this, false, IsBreaker)); } else { Sim_Bus FarBus = new Sim_Bus(Sub, Buses.Count, "Bus" + Buses.Count.ToString("000"), Randomizer.GenerateNumber(1, Config.BusVoltageStdDev / 100.0), this); FarBus.Voltage = NewBus.Voltage; Buses.Add(FarBus); Breakers.Add(new Sim_Breaker((IsBreaker ? "Breaker" : "Switch") + Breakers.Count.ToString("000"), Sub, NewBus, FarBus, this, true, IsBreaker)); } } //Now, add in our lines foreach (Sim_Substation FromSub in Subs) { if (Randomizer.NextDouble() < Config.LineProbability) { Sim_Substation ToSub = FromSub.FindNearbySubstation(Subs, Config.LineDistance, Lines, this); if (ToSub != null && !FromSub.ConnectedSubstations(Lines).ContainsKey(ToSub)) { Lines.Add(new Sim_Line(FromSub, ToSub, Lines, this, Randomizer.GenerateNumber(Config.LineMW), Randomizer.GenerateNumber(Config.LineMW) * 0.3, Math.Abs(Randomizer.GenerateNumber(Config.LineLoad) / 100.0))); } } } //Add in our shunt compensators, reactors and loads foreach (Sim_Substation Sub in Subs) { while (Randomizer.NextDouble() < Config.CapacitorProbability) { double MVAR = Randomizer.GenerateNumber(Config.CapacitorMVAR); bool IsOpen = Randomizer.NextDouble() >= Config.CapacitorOpenProbability; ShuntCompensators.Add(new Sim_ShuntCompensator("Cap" + ShuntCompensators.Count.ToString("000"), Sub, Sub.FindBus(this), IsOpen, (IsOpen ? 0 : MVAR), MVAR, true, this)); } while (Randomizer.NextDouble() < Config.ReactorProbability) { double MVAR = Randomizer.GenerateNumber(Config.ReactorMVAR); bool IsOpen = Randomizer.NextDouble() >= Config.ReactorOpenProbability; ShuntCompensators.Add(new Sim_ShuntCompensator("Reac" + ShuntCompensators.Count.ToString("000"), Sub, Sub.FindBus(this), IsOpen, (IsOpen ? 0 : MVAR), MVAR, false, this)); } while (Randomizer.NextDouble() < Config.UnitProbability) { Sim_Bus FoundGenBus; if (Randomizer.NextDouble() > 0.25) { FoundGenBus = Sub.FindBus(this, GenVoltage); } else { FoundGenBus = Sub.FindBus(this); } Units.Add(new Sim_Unit("Unit" + Units.Count.ToString("000"), FoundGenBus, Sub, UnitTypes[Randomizer.Next(0, UnitTypes.Count)], Randomizer.GenerateNumber(Config.UnitMW), Randomizer.GenerateNumber(Config.UnitMW) * 0.25, Randomizer.GenerateNumber(Config.UnitCapacity), this)); } while (Randomizer.NextDouble() < Config.LoadProbability) { Loads.Add(new Sim_Load("Load" + Loads.Count.ToString("000"), Sub, Sub.FindBus(this), Randomizer.GenerateNumber(Config.LoadMW), Randomizer.GenerateNumber(Config.LoadMW) * 0.25, this)); } } //Now, add any transformers within substations with different voltages foreach (Sim_Substation Sub in Subs) { Dictionary <Sim_VoltageLevel, List <Sim_Bus> > Voltages = new Dictionary <Sim_VoltageLevel, List <Sim_Bus> >(); foreach (Sim_Bus Bus in Sub.Elements.OfType <Sim_Bus>()) { if (!Voltages.ContainsKey(Bus.Voltage)) { Voltages.Add(Bus.Voltage, new List <Sim_Bus>()); } Voltages[Bus.Voltage].Add(Bus); } for (int a = 0; a < Voltages.Count - 1; a++) { //Create a transformer between two of our voltages Sim_VoltageLevel Volt1 = Voltages.Keys.ToArray()[0]; Sim_VoltageLevel Volt2 = Voltages.Keys.ToArray()[1]; Sim_Bus Bus1 = Voltages[Volt1][Randomizer.Next(0, Voltages[Volt1].Count)]; Sim_Bus Bus2 = Voltages[Volt2][Randomizer.Next(0, Voltages[Volt2].Count)]; Sim_Transformer NewXf = new Sim_Transformer("XF" + Transformers.Count.ToString("000"), Sub, Randomizer.GenerateNumber(Config.TransformerMW), Randomizer.GenerateNumber(Config.TransformerMW) * 0.25, Bus1, Bus2, this); Transformers.Add(NewXf); } } }
/// <summary> /// Generate our one-line /// </summary> /// <param name="Substation"></param> /// <param name="TargetDirectory"></param> /// <returns></returns> public void GenerateOneLine(Sim_Substation Substation, String TargetDirectory) { //First, build our list of buses and connected equipment Dictionary <Sim_Bus, List <Sim_Element> > Elements = new Dictionary <Sim_Bus, List <Sim_Element> >(); Dictionary <Sim_Bus, int> ElementRight = new Dictionary <Sim_Bus, int>(); foreach (Sim_Bus Bus in Substation.Elements.OfType <Sim_Bus>()) { Elements.Add(Bus, new List <Sim_Element>()); } foreach (Sim_Element Elem in Substation.Elements) { if (Elem is Sim_Transformer) { Sim_TransformerWinding Winding1 = ((Sim_Transformer)Elem).Winding1; Sim_TransformerWinding Winding2 = ((Sim_Transformer)Elem).Winding2; if (Elements.ContainsKey(Winding1.Bus) && !Elements[Winding1.Bus].Contains(Winding1)) { Elements[Winding1.Bus].Add(Winding1); } if (Elements.ContainsKey(Winding2.Bus) && !Elements[Winding2.Bus].Contains(Winding2)) { Elements[Winding2.Bus].Add(Winding2); } } else if (Elem is Sim_Bus == false) { Sim_Bus Bus = Elem.GetBuses()[0]; if (Elements.ContainsKey(Bus) && !Elements[Bus].Contains(Elem)) { Elements[Bus].Add(Elem); } } } using (StreamWriter sW = new StreamWriter(Path.Combine(Config.OneLineFolder, Substation.Name + ".MM_OneLine"), false, new UTF8Encoding(false))) { sW.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>"); sW.WriteLine($"<One_Line BaseElement.ElemType=\"Substation\" BaseElement.TEID=\"{Substation.TEID}\" BaseElement.ConnectedLines=\"\" BaseElement.County=\"{Substation.Parent.Name}\" BaseElement.DisplayName=\"{Substation.Name}\" BaseElement.{Substation.ElemTypes} BaseElement.{Substation.KVLevels} BaseElement.Latitude=\"{Substation.Latitude}\" BaseElement.LatLong=\"{Substation.Latitude},{Substation.Longitude}\" BaseElement.Longitude=\"{Substation.Longitude}\" BaseElement.Operator=\"{Substation.Operator.TEID}\" BaseElement.Owner=\"{Substation.Owner.TEID}\" BaseElement.Permitted=\"true\" Font=\"Microsoft Sans Serif, 8.25pt\" BaseElement.Name=\"{Substation.Name}\" BaseElement.LongName=\"{Substation.Name}\">"); //Now, determine the Y coordinate of the bus int YVal = 50; foreach (Sim_Bus Bus in Elements.Keys) { Bus.Y = YVal; YVal += 50; } sW.WriteLine("<Elements>"); foreach (KeyValuePair <Sim_Bus, List <Sim_Element> > kvp in Elements) { int XVal = 50; foreach (Sim_Element Elem in kvp.Value) { if (Elem is Sim_TransformerWinding) { sW.WriteLine(((Sim_TransformerWinding)Elem).Transformer.GetOneLineXml(ref XVal, kvp.Key.Y)); } else { sW.WriteLine(Elem.GetOneLineXml(ref XVal, kvp.Key.Y)); } } ElementRight.Add(kvp.Key, XVal); } sW.WriteLine("</Elements>"); sW.WriteLine("<Nodes>"); foreach (Sim_Bus Bus in Elements.Keys) { int XVal = 25; Bus.XWidth = ElementRight[Bus]; sW.WriteLine(Bus.GetOneLineXml(ref XVal, Bus.Y)); } sW.WriteLine("</Nodes>"); sW.WriteLine("</One_Line>"); } }
/// <summary> /// Initialize a new transformer /// </summary> /// <param name="Name"></param> /// <param name="Sub"></param> /// <param name="MW_Est"></param> /// <param name="MVAR_Est"></param> /// <param name="Bus1"></param> /// <param name="Bus2"></param> /// <param name="Builder"></param> public Sim_Transformer(String Name, Sim_Substation Sub, double MW_Est, double MVAR_Est, Sim_Bus Bus1, Sim_Bus Bus2, Sim_Builder Builder) { this.Name = Name; this.Substation = Sub; this.ElemGuid = Guid.NewGuid(); this.Substation.Elements.Add(this); this.Owner = Builder.GetOwner(); this.Operator = Builder.GetOperator(); this.MW_Est = MW_Est; this.MVAR_Est = MVAR_Est; this.TEID = Builder.NextTEID(); this.Winding1 = new Sim_TransformerWinding(Name + "_1", this, Bus1, Owner, Operator, true, Builder); this.Winding2 = new Sim_TransformerWinding(Name + "_2", this, Bus2, Owner, Operator, false, Builder); }