Example #1
0
        /// <summary>
        /// Clear currents and Calculate the currents And voltage
        /// </summary>
        private void PowerUpdateCurrentChange()
        {
            for (var i = 0; i < UnconditionalSupplies.Count; i++)
            {
                var categoryHashset = AliveSupplies[OrderList[i]];
                foreach (var supply in categoryHashset)
                {
                    if (NUCurrentChange.Contains(supply) && !NUStructureChangeReact.Contains(supply) && !NUResistanceChange.Contains(supply))
                    {
                        //Does all the updates for the constant sources since they don't have to worry about other supplies being on or off since they just go steaming ahead
                        supply.PowerUpdateCurrentChange();
                        NUCurrentChange.Remove(supply);
                    }
                }
            }

            var doneSupplies = new HashSet <ElectricalNodeControl>();
            ElectricalNodeControl lowestReactive = null;
            var lowestReactiveInt = 9999;
            var nodeToRemove      = new List <ElectricalNodeControl>();

            //This is to calculate the lowest number of supplies that are above the reactive supply so therefore the one that needs to be updated first
            while (NumberOfReactiveSupplies_f() > 0)
            {
                foreach (var supply in NUCurrentChange)
                {
                    if (!doneSupplies.Contains(supply))
                    {
                        if (TotalSupplies.Contains(supply))
                        {
                            if (ReactiveSuppliesSet.Contains(supply.Node.InData.Categorytype))
                            {
                                if (NUCurrentChange.Contains(supply) && !(NUStructureChangeReact.Contains(supply)) &&
                                    !(NUResistanceChange.Contains(supply)))
                                {
                                    if (lowestReactive == null)
                                    {
                                        lowestReactive    = supply;
                                        lowestReactiveInt = NumberOfReactiveSupplies(supply.Node.InData);
                                    }
                                    else if (lowestReactiveInt > NumberOfReactiveSupplies(supply.Node.InData))
                                    {
                                        lowestReactive    = supply;
                                        lowestReactiveInt = NumberOfReactiveSupplies(supply.Node.InData);
                                    }
                                }
                                else
                                {
                                    nodeToRemove.Add(supply);
                                }
                            }
                        }
                        else
                        {
                            nodeToRemove.Add(supply);
                        }
                    }
                    else
                    {
                        nodeToRemove.Add(supply);
                    }
                }

                if (lowestReactive != null)
                {
                    lowestReactive.PowerUpdateCurrentChange();
                    NUCurrentChange.Remove(lowestReactive);
                    doneSupplies.Add(lowestReactive);
                }

                lowestReactive    = null;
                lowestReactiveInt = 9999;
                foreach (var node in nodeToRemove)
                {
                    NUCurrentChange.Remove(node);
                }

                nodeToRemove = new List <ElectricalNodeControl>();
            }
        }
    /// <summary>
    /// Clear currents and Calculate the currents And voltage
    /// </summary>
    private void PowerUpdateCurrentChange()
    {
        //Logger.Log("PowerUpdateCurrentChange");
        for (int i = 0; i < UnconditionalSupplies.Count; i++)
        {
            foreach (ElectricalNodeControl TheSupply in AliveSupplies[OrderList[i]])
            {
                if (NUCurrentChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)) &&
                    !(NUResistanceChange.Contains(TheSupply)))
                {
                    TheSupply
                    .PowerUpdateCurrentChange();                             //Does all the updates for the constant sources since they don't have to worry about other supplies being on or off since they just go steaming ahead
                    NUCurrentChange.Remove(TheSupply);
                }
            }
        }

        HashSet <ElectricalNodeControl> DoneSupplies   = new HashSet <ElectricalNodeControl>();
        ElectricalNodeControl           LowestReactive = null;
        int LowestReactiveint = 9999;
        List <ElectricalNodeControl> QToRemove = new List <ElectricalNodeControl>();

        while (NumberOfReactiveSupplies_f() > 0
               )  //This is to calculate the lowest number of supplies that are above the reactive supply so therefore the one that needs to be updated first
        {
            foreach (ElectricalNodeControl TheSupply in NUCurrentChange)
            {
                if (!DoneSupplies.Contains(TheSupply))
                {
                    if (TotalSupplies.Contains(TheSupply))
                    {
                        if (ReactiveSuppliesSet.Contains(TheSupply.Node.InData.Categorytype))
                        {
                            if (NUCurrentChange.Contains(TheSupply) && !(NUStructureChangeReact.Contains(TheSupply)) &&
                                !(NUResistanceChange.Contains(TheSupply)))
                            {
                                if (LowestReactive == null)
                                {
                                    LowestReactive    = TheSupply;
                                    LowestReactiveint = NumberOfReactiveSupplies(TheSupply.Node.InData);
                                }
                                else if (LowestReactiveint > NumberOfReactiveSupplies(TheSupply.Node.InData))
                                {
                                    LowestReactive    = TheSupply;
                                    LowestReactiveint = NumberOfReactiveSupplies(TheSupply.Node.InData);
                                }
                            }
                            else
                            {
                                QToRemove.Add(TheSupply);
                            }
                        }
                    }
                    else
                    {
                        QToRemove.Add(TheSupply);
                    }
                }
                else
                {
                    QToRemove.Add(TheSupply);
                }
            }

            if (LowestReactive != null)
            {
                LowestReactive.PowerUpdateCurrentChange();
                NUCurrentChange.Remove(LowestReactive);
                DoneSupplies.Add(LowestReactive);
            }

            LowestReactive    = null;
            LowestReactiveint = 9999;
            foreach (ElectricalNodeControl re in QToRemove)
            {
                NUCurrentChange.Remove(re);
            }

            QToRemove = new List <ElectricalNodeControl>();
        }
    }