/// <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); } } }