Exemplo n.º 1
0
        /// <summary>
        /// Roll up our counties and voltages
        /// </summary>
        public void RollUpCountiesAndVoltages()
        {
            //Go through our substations to pull in county and kv information
            HashSet <MM_KVLevel>  KVs        = new HashSet <MM_KVLevel>();
            HashSet <MM_Boundary> Boundaries = new HashSet <MM_Boundary>();

            if (Substations != null)
            {
                foreach (MM_Substation Sub in Substations)
                {
                    foreach (MM_KVLevel KVLevel in Sub.KVLevels)
                    {
                        if (!KVs.Contains(KVLevel))
                        {
                            KVs.Add(KVLevel);
                        }
                    }
                    if (!Boundaries.Contains(Sub.County))
                    {
                        Boundaries.Add(Sub.County);
                    }
                }
            }

            if (ConElements != null && ConElements.Count > 0)
            {
                foreach (var teid in ConElements)
                {
                    MM_Element con = null;
                    MM_Repository.TEIDs.TryGetValue(teid, out con);
                    if (con != null && con.Contingencies.All(c => c.Name != con.Name))
                    {
                        con.Contingencies.Add(this);
                    }
                }
            }

            KVLevels = KVs.ToArray();
            Counties = Boundaries.ToArray();
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a new element
        /// </summary>
        /// <param name="TEID"></param>
        /// <param name="ElemType"></param>
        /// <param name="AddIfNew"></param>
        ///  <param name="BaseElement"></param>
        ///  <param name="mI"></param>
        /// <returns></returns>
        public static MM_Element CreateElement(Int32 TEID, Type ElemType, bool AddIfNew, MM_Element BaseElement, MemberInfo mI)
        {
            MM_Element OutElement;

            if (MM_Repository.TEIDs.TryGetValue(TEID, out OutElement))
            {
                return(OutElement);
            }

            OutElement      = Activator.CreateInstance(ElemType) as MM_Element;
            OutElement.TEID = TEID;

            if (AddIfNew)
            {
                MM_Repository.TEIDs.Add(TEID, OutElement);
                if (ElemType == typeof(MM_Element) || OutElement.ElemType == null)
                {
                    Dictionary <MM_Element, MemberInfo> Mapping;
                    if (!UnknownElements.TryGetValue(TEID, out Mapping))
                    {
                        UnknownElements.Add(TEID, Mapping = new Dictionary <MM_Element, MemberInfo>(5));
                    }
                    Mapping.Add(BaseElement, mI);
                }
            }
            return(OutElement);
        }