예제 #1
0
        /// <summary>
        /// Initialize a new DCTie around its base line.
        /// </summary>
        /// <param name="BaseLine">The line on which the tie is based</param>
        /// <param name="TieDescriptor">The descriptor of the tie</param>
        public MM_Tie(MM_Line BaseLine, String TieDescriptor)
        {
            //Retrieve our information from our base line
            IntegrateFromLine(BaseLine);

            //Assign our tie descriptor and KV Level.
            this.TieDescriptor = MM_Repository.TitleCase(TieDescriptor);
            this.ElemType      = MM_Repository.FindElementType("Tie");
            //this.KVLevel = MM_Repository.KVLevels["DC Tie"];     //mn - was at "DCTIE vs "DC TIE" check to ensure what one is right - 20130610 -mn
        }
예제 #2
0
        /// <summary>
        /// Integrate the information from a base line into the DCTie.
        /// </summary>
        /// <param name="BaseLine"></param>
        public void IntegrateFromLine(MM_Line BaseLine)
        {
            try
            {
                //Pull all data in from the base line
                foreach (FieldInfo fI in BaseLine.GetType().GetFields(BindingFlags.Instance | BindingFlags.DeclaredOnly | BindingFlags.Public))
                {
                    this.GetType().GetField(fI.Name).SetValue(this, fI.GetValue(BaseLine));
                }

                //Check our line length. If it's less than 10 miles, expand the side closest to the border to make it wider
                float MileLength = 20f;
                if (this.Length < MileLength)
                {
                    float[] Dist = new float[] { float.NaN, float.NaN };
                    foreach (PointF PtToCheck in MM_Repository.Counties["STATE"].Coordinates)
                    {
                        for (int a = 0; a < 2; a++)
                        {
                            if (float.IsNaN(Dist[a]) || CalculateDistance(ConnectedStations[a].LngLat, PtToCheck) < Dist[a])
                            {
                                Dist[a] = CalculateDistance(ConnectedStations[a].LngLat, PtToCheck);
                            }
                        }
                    }

                    //Now, determine which one is closer, and keep moving it until we are at our minimum mile length.
                    int i = 1000;
                    while (this.Length < MileLength && i < 1000)
                    {
                        //Now, find the station with the DC tie elements

                        int TieStation = Math.Max(0, Array.IndexOf(ConnectedStations, this.Unit == null ? this.Substation : this.Unit.Substation));

                        //int ShorterStation = (Dist[0] < Dist[1] ? 0 : 1);
                        ConnectedStations[TieStation].LngLat.X += .01f * Math.Sign(ConnectedStations[TieStation].LngLat.X - ConnectedStations[1 - TieStation].LngLat.X);
                        ConnectedStations[TieStation].LngLat.Y += .01f * Math.Sign(ConnectedStations[TieStation].LngLat.Y - ConnectedStations[1 - TieStation].LngLat.Y);
                        i++;
                    }
                }
            } catch (Exception ex)
            {
                MM_System_Interfaces.LogError(ex);
            }
        }
예제 #3
0
        /// <summary>
        /// Create a new element based on its definition
        /// </summary>
        /// <param name="xElem">The definition for the element</param>
        /// <param name="Prefix">The prefix for the element, if any</param>
        /// <param name="AddIfNew">Whether to add a new element to our master repository</param>
        /// <returns></returns>
        public static MM_Element CreateElement(XmlElement xElem, string Prefix, bool AddIfNew)
        {
            MM_Element OutElement = null;
            String     ElemType;

            if (xElem.HasAttribute("ElemType"))
            {
                ElemType = String.IsNullOrEmpty(Prefix) ? xElem.Attributes["ElemType"].Value : xElem.HasAttribute(Prefix + ".ElemType") ? xElem.Attributes[Prefix + ".ElemType"].Value : Prefix;
            }
            else
            {
                ElemType = xElem.Name;
            }
            if (Prefix == "EPSMeter")
            {
                OutElement          = new MM_EPSMeter();
                OutElement.ElemType = MM_Repository.FindElementType(Prefix);
            }
            else if (xElem.HasAttribute("BaseElement.IsSeriesCompensator") && XmlConvert.ToBoolean(xElem.Attributes["BaseElement.IsSeriesCompensator"].Value))
            {
                OutElement = new MM_Line();
            }
            else if (ElemType == "Breaker" || ElemType == "Switch")
            {
                OutElement = new MM_Breaker_Switch();
            }
            else if (ElemType == "DCTie")
            {
                OutElement = new MM_Tie();
            }
            else if (ElemType == "Tie")
            {
                OutElement = new MM_Tie();
            }
            else if (ElemType == "ElectricalBus")
            {
                OutElement = new MM_Electrical_Bus();
            }
            else if (ElemType == "Line")
            {
                OutElement = new MM_Line();
            }
            else if (ElemType == "Load" || ElemType.Equals("LaaR", StringComparison.CurrentCultureIgnoreCase))
            {
                OutElement = new MM_Load();
            }
            else if (ElemType == "Unit")
            {
                OutElement = new MM_Unit();
            }
            else if (ElemType == "Capacitor" || ElemType == "Reactor")
            {
                OutElement = new MM_ShuntCompensator();
            }
            else if (ElemType == "Transformer")
            {
                OutElement = new MM_Transformer();
            }
            else if (ElemType == "TransformerWinding")
            {
                OutElement = new MM_TransformerWinding();
            }
            else if (ElemType == "StaticVarCompensator")
            {
                OutElement = new MM_StaticVarCompensator();
            }
            else if (ElemType == "Node")
            {
                OutElement = new MM_Node();
            }
            else if (ElemType == "BusbarSection")
            {
                OutElement = new MM_Bus();
            }
            else if (ElemType == "PricingVector")
            {
                OutElement = new MM_PricingVector();
                ((MM_PricingVector)OutElement).EPSMeter = (MM_EPSMeter)CreateElement(xElem, "EPSMeter", false);
            }
            else if (ElemType == "EPSMeter")
            {
                OutElement = new MM_EPSMeter();
            }
            else if (ElemType == "County" || ElemType == "State")
            {
                OutElement = new MM_Boundary();
            }
            else if (ElemType == "Company")
            {
                OutElement = new MM_Company();
            }
            else if (ElemType == "Flowgate")
            {
                OutElement = new MM_Flowgate();
            }
            else if (ElemType == "Contingency")
            {
                OutElement = new MM_Contingency();
            }
            else if (ElemType == "Substation")
            {
                OutElement = new MM_Substation();
            }
            else if (ElemType == "VoltageLevel")
            {
                //OutElement = new MM_KVLevel();
            }
            else
            {
                OutElement = new MM_Element();
            }
            OutElement.ElemType = MM_Repository.FindElementType(ElemType);



            //Now, pull in our attributes
            foreach (XmlAttribute xAttr in xElem.Attributes)
            {
                if ((String.IsNullOrEmpty(Prefix) && xAttr.Name.IndexOf('.') == -1))
                {
                    MM_Serializable.AssignValue(xAttr.Name, xAttr.Value, OutElement, AddIfNew);
                }
                else if (!String.IsNullOrEmpty(Prefix) && xAttr.Name.StartsWith(Prefix + "."))
                {
                    MM_Serializable.AssignValue(xAttr.Name.Substring(xAttr.Name.IndexOf('.') + 1), xAttr.Value, OutElement, AddIfNew);
                }
            }

            if (xElem.HasAttribute("Contingencies"))
            {
                String[] splStr = xElem.Attributes["Contingencies"].Value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (OutElement.Contingencies == null || OutElement.Contingencies.Count == 0)
                {
                    OutElement.Contingencies = new List <MM_Contingency>();
                }
                else
                {
                    OutElement.Contingencies = OutElement.Contingencies.ToList();
                }
                foreach (string str in splStr)
                {
                    MM_Contingency con = null;
                    MM_Repository.Contingencies.TryGetValue(str, out con);
                    if (con != null && !OutElement.Contingencies.Any(c => c.Name == con.Name))
                    {
                        OutElement.Contingencies.Add(con);
                    }
                }
            }

            //If we're a transformer, pull in our windings
            if (ElemType == "Transformer")
            {
                List <MM_TransformerWinding> Windings = new List <MM_TransformerWinding>();
                foreach (XmlElement xWind in xElem.SelectNodes("Winding"))
                {
                    Windings.Add(MM_Element.CreateElement(xWind, "BaseElement", AddIfNew) as MM_TransformerWinding);
                }
                if (xElem.HasAttribute("BaseElement.KVLevel1"))
                {
                    Windings[0].Voltage = XmlConvert.ToSingle(xElem.Attributes["BaseElement.KVLevel1"].Value.Split(' ')[0]);
                }
                if (xElem.HasAttribute("BaseElement.KVLevel2"))
                {
                    Windings[1].Voltage = XmlConvert.ToSingle(xElem.Attributes["BaseElement.KVLevel2"].Value.Split(' ')[0]);
                }
                (OutElement as MM_Transformer).Windings = Windings.ToArray();
            }

            //If we're a line, check for series compensator status to upgrade our type
            if (OutElement is MM_Line && xElem.HasAttribute("BaseElement.IsSeriesCompensator") && XmlConvert.ToBoolean(xElem.Attributes["BaseElement.IsSeriesCompensator"].Value))
            {
                OutElement.ElemType = MM_Repository.FindElementType("SeriesCompensator");
            }
            //Return our new element
            return(OutElement);
        }