Ejemplo n.º 1
0
        /// <summary>
        /// Compute the distances between two lat/longs
        /// </summary>
        /// <param name="LngLat"></param>
        /// <param name="OtherLngLat"></param>
        /// <returns></returns>
        public double DistanceTo(Sim_Substation OtherSub)
        {
            double R         = 3963.1; //Radius of the earth in miles
            double deltaLat  = (Latitude - OtherSub.Latitude) * Math.PI / 180.0;
            double deltaLong = (Longitude - OtherSub.Longitude) * Math.PI / 180.0;
            double a         = Math.Sin(deltaLat / 2.0) * Math.Sin(deltaLat / 2.0) + Math.Cos(OtherSub.Longitude * Math.PI / 180.0) * Math.Cos(Longitude * Math.PI / 180.0) * Math.Sin(deltaLong / 2.0) * Math.Sin(deltaLong / 2.0);
            double c         = 2f * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1f - a));

            return(R * c);
        }
Ejemplo n.º 2
0
 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();
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 /// <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);
 }
Ejemplo n.º 6
0
 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();
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Initialize our bus
 /// </summary>
 /// <param name="Sub"></param>
 /// <param name="BusNumber"></param>
 /// <param name="Name"></param>
 /// <param name="PerUnitVoltage"></param>
 /// <param name="Builder"></param>
 public Sim_Bus(Sim_Substation Sub, int BusNumber, String Name, double PerUnitVoltage, Sim_Builder Builder)
 {
     this.ElemGuid       = Guid.NewGuid();
     this.Name           = Name;
     this.Substation     = Sub;
     this.Voltage        = Builder.GetVoltage();
     this.PerUnitVoltage = PerUnitVoltage;
     this.Substation.Elements.Add(this);
     this.BusNumber = BusNumber;
     this.Owner     = Builder.GetOwner();
     this.ElemGuid  = Guid.NewGuid();
     this.NodeGuid  = Guid.NewGuid();
     this.Operator  = Builder.GetOperator();
     this.TEID      = Builder.NextTEID();
     this.NodeTEID  = Builder.NextTEID();
 }
Ejemplo n.º 8
0
 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;
 }
Ejemplo n.º 9
0
 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);
 }
Ejemplo n.º 10
0
 public SubstationDistance(Sim_Substation Sub, double Dist)
 {
     this.Sub  = Sub;
     this.Dist = Dist;
 }
Ejemplo n.º 11
0
        /// <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);
                }
            }
        }
Ejemplo n.º 12
0
        /// <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>");
            }
        }