cloudflight
2024-06-17 b62f5f0104845c2a3a74707792ebf28a506e24f1
Hydraulic/Hydro.MapView/MapViewNetWork.cs
@@ -33,6 +33,9 @@
        private NodeViewModelList _nodes = new NodeViewModelList();
        public NodeViewModelList Nodes { get { return _nodes; }set { base.Nodes = _nodes = value; } }
        private List<AreaViewModel> _areas = new List<AreaViewModel>();
        public List<AreaViewModel> Areas { get { return _areas; } set {  _areas = value; } }
        public NodeViewModel StartPoint { get; set; }
        public NodeViewModel EndPoint { get; set; }
@@ -853,33 +856,43 @@
        public List<TimePoint> Calc(string inpPath, string configPath = null)
        {
            WdnmoParam wdnmoParam = new WdnmoParam();
            Nodes.ForEach(n =>
            bool CalcByConfig = false;
            List<TimePoint> list = new List<TimePoint>();
            if (CalcByConfig)
            {
                //if (n is JunctionViewModel || n is MeterViewModel || n is NozzleViewModel)
                WdnmoParam wdnmoParam = new WdnmoParam();
                Nodes.ForEach(n =>
                {
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Press_{n.ID}" });
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Head_{n.ID}" });
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Demand_{n.ID}" });
                }
            });
            Links.ForEach(n =>
                    //if (n is JunctionViewModel || n is MeterViewModel || n is NozzleViewModel)
                    {
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Press_{n.ID}" });
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Head_{n.ID}" });
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Demand_{n.ID}" });
                    }
                });
                Links.ForEach(n =>
                {
                    //if (n is PipeViewModel || n is PumpViewModel || n is ValveViewModel)
                    {
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Flow_{n.ID}" });
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Velocity_{n.ID}" });
                        wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Headloss_{n.ID}" });
                    }
                });
                calc c = new calc();
                list = c.GetCalcResult(inpPath, wdnmoParam, configPath);
                if (list == null) return list;
            }
            else
            {
                //if (n is PipeViewModel || n is PumpViewModel || n is ValveViewModel)
                {
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Flow_{n.ID}" });
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Velocity_{n.ID}" });
                    wdnmoParam.ResultPoints.Add(new TimePoint { Key = $"Headloss_{n.ID}" });
                list= base.Calc(inpPath);
            }
                }
            });
            calc c = new calc();
            var list = c.GetCalcResult(inpPath, wdnmoParam, configPath);
            if (list == null) return list;
            list.Sort((a, b) => string.Compare(a.Key, b.Key));
            Nodes.Sort((a, b) => string.Compare(a.ID, b.ID));
            Links.Sort((a, b) => string.Compare(a.ID, b.ID));
@@ -1006,6 +1019,101 @@
            return list;
            //return new List<TimePoint>();
        }
        public string CheckValidate()
        {
            BuildRelation();
            string result = null;
            StringBuilder result_sb=new StringBuilder();
            //to-do
            var objs = new List<LinkViewModel>() { Links[0] }; //Links.FindAll(o => o is LinkViewModel).Select(o => o as LinkViewModel).ToList();
            //objs去掉重复的元素
            objs = objs.Distinct().ToList();
            var visitedNodes = new HashSet<NodeViewModel>();
            FindObjs = new HashSet<IBaseViewModel>();
            objs.ForEach(o => TraversePipeNetworkALL(o, visitedNodes));
            for(int i=0;i<Nodes.Count;i++)
            {
                if (!FindObjs.Contains(Nodes[i])) result_sb .AppendLine($"节点{Nodes[i].ID}是孤立点");
            }
            //属性判断
            pipes.ForEach(p =>
            {
                if (p.StartNode == null || p.EndNode == null)
                {
                    result_sb.AppendLine($"{p.ID}管道未连接");
                }
                if (p.Length<=0)
                {
                    result_sb.AppendLine($"{p.ID}管道长度小于等于0");
                }
                if (p.Roughness<=0.1 || p.Roughness>10000)
                {
                    result_sb.AppendLine($"{p.ID}粗糙系数设置错误");
                }
                if (p.Diameter<=0.1 || p.Diameter>10000)
                {
                    result_sb.AppendLine($"{p.ID}管径设置错误");
                }
            });
            return result_sb.ToString();
        }
        HashSet<IBaseViewModel> FindObjs;
        private void TraversePipeNetworkALL(LinkViewModel startLink, HashSet<NodeViewModel> visitedNodes = null, int direction = 0)
        {
            Queue<LinkViewModel> queue = new Queue<LinkViewModel>();
            queue.Enqueue(startLink);
            if (visitedNodes == null)
                visitedNodes = new HashSet<NodeViewModel>();
            //visitedNodes.Add(startLink.StartNode);
            //visitedNodes.Add(startLink.EndNode);
            while (queue.Count > 0)
            {
                LinkViewModel currentLink = queue.Dequeue();
                //Console.WriteLine("Traversing Link: " + currentLink.ID);
                foreach (var node in new NodeViewModel[] { currentLink.StartNode, currentLink.EndNode })
                {
                    if (direction == 1 && currentLink.EN_FLOW >= 0 && node == currentLink.StartNode) continue;
                    if (direction == -1 && currentLink.EN_FLOW <= 0 && node == currentLink.EndNode) continue;
                    if (node != null && !visitedNodes.Contains(node))
                    {
                        visitedNodes.Add(node);
                        if (!FindObjs.Contains(node)) FindObjs.Add(node);
                        //Console.WriteLine("Visiting Node: " + node.ID);
                        foreach (var link in node.ViewLinks)
                        {
                            if (!visitedNodes.Contains(link.StartNode) || !visitedNodes.Contains(link.EndNode))
                            {
                                if (!FindObjs.Contains(link)) FindObjs.Add(link);
                                queue.Enqueue(link);
                            }
                        }
                    }
                }
            }
        }
        public List<TimePoint> CalcByValAndHead(WDNModelOptimizer wdo, Result val,double Head)
        {