Esempio n. 1
0
        private async Task UpdateLoadFlowFromRecloser(TopologyModel topology, Dictionary <long, float> loadOfFeeders)
        {
            string verboseMessage = $"{baseLogString} UpdateLoadFlowFromRecloser method called.";

            Logger.LogVerbose(verboseMessage);

            if (topology == null)
            {
                string message = $"{baseLogString} UpdateLoadFlowFromRecloser => Topologies are null.";
                Logger.LogError(message);
                throw new Exception(message);
            }

            foreach (var recloserGid in reclosers)
            {
                if (topology.GetElementByGid(recloserGid, out ITopologyElement recloser))
                {
                    await CalculateLoadFlowFromRecloser(recloser, topology, loadOfFeeders);
                }
            }
        }
        public async Task <UIModel> ConvertTopologyToUIModel(TopologyModel topology)
        {
            string verboseMessage = $"{baseLogString} ConvertTopologyToUIModel method called.";

            Logger.LogVerbose(verboseMessage);

            if (topology == null)
            {
                string message = $"{baseLogString} ConvertTopologyToUIModel => Provider topology is null.";
                Logger.LogError(message);
                throw new Exception(message);
            }

            UIModel      uIModel = new UIModel();
            Stack <long> stack   = new Stack <long>();

            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => Calling GetReclosers method from model provider client.");
            var modelProviderClient = CeModelProviderClient.CreateClient();
            var reclosers           = await modelProviderClient.GetReclosers();

            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => GetReclosers method from model provider client has been called successfully.");

            uIModel.FirstNode = topology.FirstNode;
            stack.Push(topology.FirstNode);
            long nextElementGid;

            while (stack.Count > 0)
            {
                nextElementGid = stack.Pop();
                if (topology.GetElementByGid(nextElementGid, out ITopologyElement element))
                {
                    if (!reclosers.Contains(nextElementGid))
                    {
                        foreach (var child in element.SecondEnd)
                        {
                            long nextElement = child.Id;
                            if (ModelCodeHelper.ExtractTypeFromGlobalId(child.Id) == 0)
                            {
                                if (child is Field field && field.Members.Count > 0)
                                {
                                    nextElement = field.Members.First().Id;
                                }
                                else
                                {
                                    string message = $"{baseLogString} ConvertTopologyToUIModel => Error while getting field in Topology to UIModel convert. Element is not field or field is empty.";
                                    Logger.LogError(message);
                                    throw new Exception(message);
                                }
                            }

                            uIModel.AddRelation(element.Id, nextElement);
                            stack.Push(nextElement);
                        }
                    }

                    List <UIMeasurement> measurements = new List <UIMeasurement>();
                    foreach (var measurementGid in element.Measurements.Keys)
                    {
                        DMSType type = (DMSType)ModelCodeHelper.ExtractTypeFromGlobalId(measurementGid);

                        if (type == DMSType.ANALOG)
                        {
                            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => Calling GetAnalogMeasurement method from measurement provider client for measurement GID {measurementGid:X16}.");
                            var measurementProviderClient       = MeasurementProviderClient.CreateClient();
                            AnalogMeasurement analogMeasurement = await measurementProviderClient.GetAnalogMeasurement(measurementGid);

                            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => GetAnalogMeasurement method from measurement provider client has been called successfully.");

                            measurements.Add(new UIMeasurement()
                            {
                                Gid   = analogMeasurement.Id,
                                Type  = analogMeasurement.GetMeasurementType(),
                                Value = analogMeasurement.GetCurrentValue()
                            });
                        }
                        else if (type == DMSType.DISCRETE)
                        {
                            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => Calling GetDiscreteMeasurement method from measurement provider client for measurement GID {measurementGid:X16}.");
                            var measurementProviderClient           = MeasurementProviderClient.CreateClient();
                            DiscreteMeasurement discreteMeasurement = await measurementProviderClient.GetDiscreteMeasurement(measurementGid);

                            Logger.LogDebug($"{baseLogString} ConvertTopologyToUIModel => GetDiscreteMeasurement method from measurement provider client has been called successfully.");

                            measurements.Add(new UIMeasurement()
                            {
                                Gid   = discreteMeasurement.Id,
                                Type  = discreteMeasurement.GetMeasurementType(),
                                Value = discreteMeasurement.GetCurrentValue()
                            });
                        }
                    }


                    if (!uIModel.Nodes.ContainsKey(element.Id))
                    {
                        UINode newUINode = new UINode()
                        {
                            Id             = element.Id,
                            Name           = element.Name,
                            Mrid           = element.Mrid,
                            Description    = element.Description,
                            DMSType        = element.DmsType,
                            NominalVoltage = element.NominalVoltage,
                            Measurements   = measurements,
                            IsActive       = element.IsActive,
                            IsRemote       = element.IsRemote,
                            NoReclosing    = element.NoReclosing
                        };
                        uIModel.AddNode(newUINode);
                    }
                }
Esempio n. 3
0
        private async Task CalculateLoadFlow(TopologyModel topology, Dictionary <long, float> loadOfFeeders)
        {
            string verboseMessage = $"{baseLogString} CalculateLoadFlow method called.";

            Logger.LogVerbose(verboseMessage);

            if (topology == null)
            {
                string message = $"{baseLogString} CalculateLoadFlow => Topologies are null.";
                Logger.LogError(message);
                throw new Exception(message);
            }

            if (topology.GetElementByGid(topology.FirstNode, out ITopologyElement firsElement))
            {
                Stack <ITopologyElement> stack = new Stack <ITopologyElement>();
                stack.Push(firsElement);
                ITopologyElement nextElement;
                long             currentFider = 0;

                while (stack.Count > 0)
                {
                    nextElement = stack.Pop();

                    if (nextElement is Field field)
                    {
                        stack.Push(field.Members.First());
                    }
                    else
                    {
                        if (nextElement is Feeder)
                        {
                            currentFider = nextElement.Id;
                            if (!feeders.ContainsKey(currentFider))
                            {
                                feeders.Add(currentFider, nextElement);
                            }
                        }

                        Tuple <bool, float> tuple = await IsElementEnergized(nextElement);

                        bool  isEnergized = tuple.Item1;
                        float load        = tuple.Item2;

                        if (!isEnergized)
                        {
                            await DeEnergizeElementsUnder(nextElement);
                        }
                        else
                        {
                            if (loadOfFeeders.ContainsKey(currentFider))
                            {
                                loadOfFeeders[currentFider] += load;
                            }
                            else
                            {
                                loadOfFeeders.Add(currentFider, load);
                            }

                            foreach (var child in nextElement.SecondEnd)
                            {
                                if (!reclosers.Contains(child.Id))
                                {
                                    stack.Push(child);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                Logger.LogDebug($"{baseLogString} CalculateLoadFlowFirst => Element with GID {topology?.FirstNode:X16} does not exist in collection.");
            }

            Logger.LogVerbose($"{baseLogString} CalculateLoadFlowFirst => Calulate load flow finished.");
        }