From 368869e50aa1bc741d4cc319dbd24e798e48b3a2 Mon Sep 17 00:00:00 2001
From: cloudflight <cloudflight@126.com>
Date: 星期六, 20 七月 2024 11:12:06 +0800
Subject: [PATCH] 更新项目名称

---
 Hydraulic/Hydro.MapView/MapViewNetWork.cs |  288 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 281 insertions(+), 7 deletions(-)

diff --git a/Hydraulic/Hydro.MapView/MapViewNetWork.cs b/Hydraulic/Hydro.MapView/MapViewNetWork.cs
index b44af9c..d99cb73 100644
--- a/Hydraulic/Hydro.MapView/MapViewNetWork.cs
+++ b/Hydraulic/Hydro.MapView/MapViewNetWork.cs
@@ -1,5 +1,5 @@
 锘縰sing Hydro.Core.Model;
-using Hydro.Inp;
+//using Hydro.Inp;
 using Newtonsoft.Json.Linq;
 using Newtonsoft.Json;
 using System;
@@ -33,9 +33,48 @@
         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; }
+
+        public double[] getMinMax(ColourType colourType)
+        {
+            //鏍规嵁褰撳墠閫変腑鐨凜olourType,鍒ゆ柇鏄惁鏈夊搴旂殑缃戠粶鏁版嵁
+        
+            double max = 0;
+            double min = 0;
+
+            switch (colourType)
+            {
+                case ColourType.鑺傜偣鑷敱鍘嬪姏:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
+                    break;
+                case ColourType.鑺傜偣缁濆鍘嬪姏:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_PRESSURE);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_PRESSURE);
+                    break;
+                case ColourType.鑺傜偣闇�姘撮噺:
+                    max = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Max(node => node.EN_DEMAND);
+                    min = Nodes.Where(node => !(node is ReservoirViewModel || node is TankViewModel)).Min(node => node.EN_DEMAND);
+                    break;
+                case ColourType.绠$嚎娴侀噺:
+                    max = Links.Max(link => link.EN_FLOW);
+                    min = Links.Min(link => link.EN_FLOW);
+                    break;
+                case ColourType.绠$嚎娴侀��:
+                    max = Links.Max(link => link.EN_VELOCITY);
+                    min = Links.Min(link => link.EN_VELOCITY);
+                    break;
+                default:
+                    break;
+
+            }
+            return new double[] { min, max };
+        }
 
         /// <summary>
         /// 褰撻噺闆嗗悎锛屽綋閲忔ā鏉縄D锛�<鍣ㄥ叿ID锛屾暟閲�>
@@ -393,6 +432,7 @@
             pipe.Status = StatusType.DEFAULT;
             pipe.StartNode = node1;
             pipe.EndNode = node2;
+            pipe.Length = -1;
 
 
 
@@ -618,7 +658,9 @@
             });
             if (ConnectNode!=null)
             {
-                list.Add(AddPipe(ConnectNode, net.StartPoint));
+                var l = AddPipe(ConnectNode, net.StartPoint);
+                list.Add(l);
+                Hash_ID.Add(l.ID);
             }
             //BuildRelation();
             return list;
@@ -814,10 +856,72 @@
 
         public List<TimePoint> Calc(string inpPath, string configPath = null)
         {
+            bool CalcByConfig = false;
+            List<TimePoint> list = new List<TimePoint>();
+            if (CalcByConfig)
+            {
 
+                WdnmoParam wdnmoParam = new WdnmoParam();
+                Nodes.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
+            {
+                list= base.Calc(inpPath); 
+            }
+            
+           
+
+            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));
+            SetNodeFromWparam(this, list, "Press");
+            SetNodeFromWparam(this, list, "Head");
+            SetNodeFromWparam(this, list, "Demand");
+
+            SetLinkFromWparam(this, list, "Flow");
+            SetLinkFromWparam(this, list, "Velocity");
+            SetLinkFromWparam(this, list, "Headloss");
+
+            Links.ForEach(l=>
+            {
+                l.EN_HEADLOSS_MINOR = (float)Math.Round(l.MinorLoss * Math.Pow(l.EN_VELOCITY, 2) / 2 / 9.8, 4);
+                l.EN_HEADLOSS_LINE = l.EN_HEADLOSS - l.EN_HEADLOSS_MINOR;
+            });
+            this._isCalculated = true;
+            return list;
+            //return new List<TimePoint>();
+        }
+        public List<TimePoint> WaterDistribution(string inpPath, string configPath = null,List<WaterEquivalentSettings> settings=null,double TotalDemand=-1,double InitPress=100)
+        {
+            if (TotalDemand < 0)
+            {
+                throw new Exception("TotalDemand must be set");
+            }
             WdnmoParam wdnmoParam = new WdnmoParam();
-
-
+            wdnmoParam.UpdateWParamByWaterEquivalentSettings(settings, TotalDemand);
+            wdnmoParam.ScadaPoints.Add(new TimePoint { Key = "initPress", Value= InitPress });
             Nodes.ForEach(n =>
             {
                 //if (n is JunctionViewModel || n is MeterViewModel || n is NozzleViewModel)
@@ -852,15 +956,18 @@
             SetLinkFromWparam(this, list, "Velocity");
             SetLinkFromWparam(this, list, "Headloss");
 
-            Links.ForEach(l=>
+            Links.ForEach(l =>
             {
                 l.EN_HEADLOSS_MINOR = (float)Math.Round(l.MinorLoss * Math.Pow(l.EN_VELOCITY, 2) / 2 / 9.8, 4);
                 l.EN_HEADLOSS_LINE = l.EN_HEADLOSS - l.EN_HEADLOSS_MINOR;
             });
+            Nodes.ForEach(n => n.Demand = n.EN_DEMAND);
             this._isCalculated = true;
             return list;
             //return new List<TimePoint>();
         }
+
+        
 
         public List<TimePoint> CalcByVal(WDNModelOptimizer wdo, Result val)
         {
@@ -912,6 +1019,171 @@
             return list;
             //return new List<TimePoint>();
         }
+        public Dictionary<string, List<string>> CheckValidate()
+        {
+            BuildRelation();
+            string result = null;
+            Dictionary<string, List<string>> result_dict = new Dictionary<string, List<string>>();
+            StringBuilder result_sb=new StringBuilder();
+            //to-do
+            var objs = Links.Select(o => o as LinkViewModel).ToList();//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));
+            List<string> list_瀛ょ珛鐐� = new List<string>();
+            for(int i=0;i<Nodes.Count;i++)
+            {
+                if (!FindObjs.Contains(Nodes[i]))
+                {
+                    result_sb.AppendLine($"鑺傜偣{Nodes[i].ID}鏄绔嬬偣");
+                    list_瀛ょ珛鐐�.Add(Nodes[i].ID);
+                }
+                    
+            }
+            if (list_瀛ょ珛鐐�.Count>0)result_dict.Add("瀛ょ珛鐐�", list_瀛ょ珛鐐�);
+            //灞炴�у垽鏂�
+            var list_绠¢亾杩炴帴鍏崇郴寮傚父 = new List<string>();
+            var list_绠¢亾闀垮害灏忎簬绛変簬0 = new List<string>();
+            var list_绮楃硻绯绘暟璁剧疆閿欒 = new List<string>();
+            var list_绠″緞璁剧疆閿欒 = new List<string>();
+
+            pipes.ForEach(p =>
+            {
+                if (p.StartNode == null || p.EndNode == null)
+                {
+                    result_sb.AppendLine($"{p.ID}绠¢亾杩炴帴鍏崇郴寮傚父");
+                    list_绠¢亾杩炴帴鍏崇郴寮傚父.Add(p.ID);
+                }
+                if (p.Length<=0)
+                {
+                    result_sb.AppendLine($"{p.ID}绠¢亾闀垮害灏忎簬绛変簬0");
+                    list_绠¢亾闀垮害灏忎簬绛変簬0.Add(p.ID);
+                }
+                if (p.Roughness<=0.1 || p.Roughness>10000)
+                {
+                    result_sb.AppendLine($"{p.ID}绮楃硻绯绘暟璁剧疆閿欒");
+                    list_绮楃硻绯绘暟璁剧疆閿欒.Add(p.ID);
+                }
+                if (p.Diameter<=0.1 || p.Diameter>10000)
+                {
+                    result_sb.AppendLine($"{p.ID}绠″緞璁剧疆閿欒");
+                    list_绠″緞璁剧疆閿欒.Add(p.ID);
+                }
+
+            });
+            if (list_绠¢亾杩炴帴鍏崇郴寮傚父.Count > 0) result_dict.Add("绠¢亾杩炴帴鍏崇郴寮傚父", list_绠¢亾杩炴帴鍏崇郴寮傚父);
+            if (list_绠¢亾闀垮害灏忎簬绛変簬0.Count > 0) result_dict.Add("绠¢亾闀垮害灏忎簬绛変簬0", list_绠¢亾闀垮害灏忎簬绛変簬0);
+            if (list_绮楃硻绯绘暟璁剧疆閿欒.Count > 0) result_dict.Add("绮楃硻绯绘暟璁剧疆閿欒", list_绮楃硻绯绘暟璁剧疆閿欒);
+            if (list_绠″緞璁剧疆閿欒.Count > 0) result_dict.Add("绠″緞璁剧疆閿欒", list_绠″緞璁剧疆閿欒);
+            return result_dict;
+
+          
+
+        }
+        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)
+        {
+
+            WdnmoParam wdnmoParam = new WdnmoParam();
+
+
+            Nodes.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}" });
+
+                }
+            });
+            calcParam calcParam = new calcParam();
+            calcParam.vars = val.arrayTryValue;
+            calcParam.setVars = new List<SetVar>();
+            reservoirs.ForEach(r =>
+            {
+                calcParam.setVars.Add(new SetVar(r.ID, true, (int)EpanetEnum.NodeValueType.姘存睜姘翠綅, (float)Head));
+            });
+
+            wdnmoParam = wdo.CalcbyResult(calcParam, wdnmoParam);
+            var list = wdnmoParam.ResultPoints;
+            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));
+            SetNodeFromWparam(this, list, "Press");
+            SetNodeFromWparam(this, list, "Head");
+            SetNodeFromWparam(this, list, "Demand");
+
+            SetLinkFromWparam(this, list, "Flow");
+            SetLinkFromWparam(this, list, "Velocity");
+            SetLinkFromWparam(this, list, "Headloss");
+            this._isCalculated = true;
+            return list;
+            //return new List<TimePoint>();
+        }
 
         private void SetNodeFromWparam(MapViewNetWork net, List<TimePoint> list, string valueType)
         {
@@ -934,7 +1206,8 @@
                     }
                     if (k2 == list.Count)
                     {
-                        throw new Exception($"鏈壘鍒癗ode[{J.ID}]鐨剓valueType}");
+                        return;
+                        //throw new Exception($"鏈壘鍒癗ode[{J.ID}]鐨剓valueType}");
                     }
                     switch (valueType)
                     {
@@ -975,7 +1248,8 @@
                     }
                     if (k2 == list.Count)
                     {
-                        throw new Exception($"鏈壘鍒癓ink[{J.ID}]鐨剓valueType}");
+                        return;
+                        //throw new Exception($"鏈壘鍒癓ink[{J.ID}]鐨剓valueType}");
                     }
                     switch (valueType)
                     {

--
Gitblit v1.9.3