From c4b3f80d78846cb67ab21b09cc2b3224aca37311 Mon Sep 17 00:00:00 2001
From: ningshuxia <ningshuxia0927@outlook.com>
Date: 星期一, 17 三月 2025 11:36:53 +0800
Subject: [PATCH] 系统曲线修改

---
 WinFrmUI/PBS.WinFrmUI.Hydro/01-system-curve/SystemCurvePage.cs |  119 +++++++++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 91 insertions(+), 28 deletions(-)

diff --git a/WinFrmUI/PBS.WinFrmUI.Hydro/01-water-supply-system-curve/SystemCurvePage.cs b/WinFrmUI/PBS.WinFrmUI.Hydro/01-system-curve/SystemCurvePage.cs
similarity index 72%
rename from WinFrmUI/PBS.WinFrmUI.Hydro/01-water-supply-system-curve/SystemCurvePage.cs
rename to WinFrmUI/PBS.WinFrmUI.Hydro/01-system-curve/SystemCurvePage.cs
index 6e9a5b0..36e1d07 100644
--- a/WinFrmUI/PBS.WinFrmUI.Hydro/01-water-supply-system-curve/SystemCurvePage.cs
+++ b/WinFrmUI/PBS.WinFrmUI.Hydro/01-system-curve/SystemCurvePage.cs
@@ -60,7 +60,8 @@
 
         public class CalcNodeViewModel
         {
-            public int NodeIndex { get; set; }
+            public int NodeIndex { get; set; }  
+            public double Elevation { get; set; }
             public double Flow { get; set; }
             public double Pressure { get; set; }
         }
@@ -122,6 +123,11 @@
             _constantLineDynamicPressure.ShowInLegend = false;
             _constantLineStaticPressure.ShowInLegend = false;
 
+            _constantLineDynamicPressure.Title.Alignment = ConstantLineTitleAlignment.Far;
+            _constantLineStaticPressure.Title.Alignment = ConstantLineTitleAlignment.Far;
+
+            _constantLineDynamicPressure.LineStyle.Thickness = 2;
+            _constantLineStaticPressure.LineStyle.Thickness = 2;
 
             _xyDiagram.EnableAxisXZooming = true;
             _xyDiagram.EnableAxisYZooming = true;
@@ -137,10 +143,11 @@
             var minDemand = 0;   // 鏈�灏忔�婚渶姘撮噺(m鲁/h)
             var maxDemand = 43;  // 鏈�澶ф�婚渶姘撮噺(m鲁/h)
             var reservoirElevation = -4; //姘存睜鏍囬珮
-            var calcCount = 5000;           // 璁$畻娆℃暟
-            var staticPressure = 22; //闈欏帇
+            var calcCount = 1000;           // 璁$畻娆℃暟
+            var staticPressure = 22.5; //闈欏帇
+            var requiredEndPressure = 18; //闈欏帇
 
-            CalcSystemCurve(file_path, minDemand, maxDemand, reservoirElevation, staticPressure, calcCount);
+            CalcSystemCurve(file_path, minDemand, maxDemand, reservoirElevation, staticPressure, requiredEndPressure, calcCount);
         }
 
         private void CalcSystemCurve(
@@ -149,15 +156,13 @@
             double maxDemand,
             double reservoirElevation,
             double staticPressure,
+            double requiredEndPressure,
             int calcCount)
         {
 
             var pressure = 0d;
-
             var nodeConfig = new List<WaterDistributionCalculator.NodeConfig>();
-            var userNodeList = new List<int>();
             var calcResultList = new List<CalcResultViewModel>(calcCount);
-
             using (var helper = new Yw.Epanet.InteropXHelper())
             {
                 var code = helper.Open(inpFilePath, "", "");
@@ -169,10 +174,11 @@
                     helper.GetNodeType(nodeIndex, out Yw.Epanet.eNodeType nodeType);
                     if (nodeType == Yw.Epanet.eNodeType.Junction)
                     {
-                        userNodeList.Add(nodeIndex);
+                        helper.GetNodeValue(nodeIndex, Yw.Epanet.eNodeProperty.Elevation, out double elevation);
                         nodeConfig.Add(new WaterDistributionCalculator.NodeConfig()
                         {
                             NodeIndex = nodeIndex,
+                            Elevation = elevation,
                             MinFlow = 0,
                             MaxFlow = rand.NextDouble() * 5
                         });
@@ -184,9 +190,10 @@
                     }
                 }
 
-                var userNodeCount = userNodeList.Count;
+                var userNodeCount = nodeConfig.Count;
                 var calculator = new WaterDistributionCalculator(nodeConfig, calcCount, minDemand, maxDemand);
                 var allDemands = calculator.CalculateDistributions();
+
                 code = helper.OpenH();
                 for (int count = 0; count < allDemands.Count; count++)
                 {
@@ -195,8 +202,9 @@
 
                     helper.InitH(false);
                     var demands = allDemands[count];
-                    foreach (var userNodeIndex in userNodeList)
+                    foreach (var node in nodeConfig)
                     {
+                        var userNodeIndex = node.NodeIndex;
                         double demand = demands.NodeFlows[userNodeIndex];
                         code = helper.SetNodeValue(userNodeIndex, Yw.Epanet.eNodeProperty.BaseDemand, demand);
                         CheckCode(code);
@@ -211,17 +219,23 @@
                     helper.RunH(out long t);
 
 
-                    foreach (var userNodeIndex in userNodeList)
+                    foreach (var node in nodeConfig)
                     {
+                        var userNodeIndex = node.NodeIndex;
                         pressure = 0;
-                        //code = helper.GetNodeValue(userNodeIndex, Yw.Epanet.eNodeProperty.Pressure, out pressure);
-                        code = helper.GetNodeValue(userNodeIndex, Yw.Epanet.eNodeProperty.Head, out pressure);
-                        CheckCode(code);
-                        calcNodelDict[userNodeIndex].Pressure = pressure;
 
-                        if (calcEndPressure > pressure)
+                        //code = helper.GetNodeValue(userNodeIndex, Yw.Epanet.eNodeProperty.Pressure, out pressure);
+                        //CheckCode(code);
+                        //var endPressure = pressure + node.Elevation;
+
+                        code = helper.GetNodeValue(userNodeIndex, Yw.Epanet.eNodeProperty.Pressure, out pressure);
+                        CheckCode(code);
+                        var endPressure = pressure + node.Elevation;
+                        calcNodelDict[userNodeIndex].Pressure = endPressure;
+
+                        if (calcEndPressure > endPressure)
                         {
-                            calcEndPressure = pressure;
+                            calcEndPressure = endPressure;
                         }
 
                     }
@@ -243,7 +257,6 @@
 
 
 
-
             this.chartControl1.BeginInit();
 
 
@@ -253,17 +266,18 @@
             _waterPointList = null;
 
 
-            // _seriesWaterPoint.BindToData(null, "", "");
-            // _seriesUpperPressure.Points.Clear();
-            //_seriesLowerPressure.Points.Clear();
-            // _seriesAveragePressure.Points.Clear();
+            _seriesWaterPoint.Points.Clear();
+            _seriesUpperPressure.Points.Clear();
+            _seriesLowerPressure.Points.Clear();
+            _seriesAveragePressure.Points.Clear();
 
             _constantLineDynamicPressure.Visible = false;
             _constantLineStaticPressure.Visible = false;
 
             if (calcResultList.Any())
             {
-                _waterPointList = calcResultList.Select(x => new PointViewModel(x.TotalFlow, x.EndPressure + staticPressure)).ToList();
+                _waterPointList = calcResultList.Select(x => new PointViewModel(x.TotalFlow, x.EndPressure + staticPressure + requiredEndPressure)).ToList();
+                //_waterPointList = calcResultList.Select(x => new PointViewModel(x.TotalFlow, x.EndPressure + staticPressure)).ToList();
 
                 var waterPointGroup = _waterPointList.GroupBy(x => Math.Round(x.X, 1));
                 var upperPressurePtList = new List<Yw.Geometry.Point2d>();
@@ -293,17 +307,66 @@
                 var lowerPressureCurvePtList = _curveLowerPressure.GetPointList(100);
                 var averagePressureCurvePtList = _curveAveragePressure.GetPointList(100);
 
-                _seriesWaterPoint.BindToData(_waterPointList, "X", "Y");
-                _seriesUpperPressure.BindToData(upperPressureCurvePtList, "X", "Y");
-                _seriesLowerPressure.BindToData(lowerPressureCurvePtList, "X", "Y");
-                _seriesAveragePressure.BindToData(averagePressureCurvePtList, "X", "Y");
 
+                foreach (var item in _waterPointList)
+                {
+                    _seriesWaterPoint.Points.Add(new SeriesPoint(item.X, item.Y));
+                }
+                foreach (var item in upperPressureCurvePtList)
+                {
+                    _seriesUpperPressure.Points.Add(new SeriesPoint(item.X, item.Y));
+                }
+                foreach (var item in lowerPressureCurvePtList)
+                {
+                    _seriesLowerPressure.Points.Add(new SeriesPoint(item.X, item.Y));
+                }
+                foreach (var item in averagePressureCurvePtList)
+                {
+                    _seriesAveragePressure.Points.Add(new SeriesPoint(item.X, item.Y));
+                }
+
+                var minX = _waterPointList.Min(x => x.X);
+                var maxX = _waterPointList.Max(x => x.X);
+
+                var minY = _waterPointList.Min(x => x.Y);
+                var maxY = _waterPointList.Max(x => x.Y);
+
+               
+                var minDynamicPressure = minY;
+                _constantLineDynamicPressure.AxisValue = minDynamicPressure;
+                _constantLineDynamicPressure.Title.Text = $"鏈�浣庝緵姘村帇鍔�:{minDynamicPressure:N2}m";
+                _constantLineDynamicPressure.Visible = true;
 
                 var totalStaticPressure = staticPressure + Math.Abs(reservoirElevation);
                 _constantLineStaticPressure.AxisValue = totalStaticPressure;
-                _constantLineStaticPressure.Title.Text = $"闈欏帇:{totalStaticPressure:N2}";
+                _constantLineStaticPressure.Title.Text = $"鏈�楂樻ゼ灞傞珮搴�:{totalStaticPressure:N2}m";
                 _constantLineStaticPressure.Visible = true;
 
+                minY = Math.Min(staticPressure, minY);
+                maxY = Math.Max(staticPressure, maxY);
+
+                minY = Math.Min(staticPressure, minY);
+                maxY = Math.Max(staticPressure, maxY);
+
+                maxY = Math.Floor(maxY);
+                maxX = Math.Floor(maxX);
+
+                _xyDiagram.AxisX.WholeRange.Auto = true;
+                _xyDiagram.AxisX.VisualRange.Auto = true;
+                _xyDiagram.AxisX.WholeRange.SideMarginsValue = 0;
+                _xyDiagram.AxisX.VisualRange.SideMarginsValue = 0;
+                _xyDiagram.AxisX.NumericScaleOptions.AutoGrid = true;
+                _xyDiagram.AxisX.WholeRange.SetMinMaxValues(minX, 50);
+                _xyDiagram.AxisX.VisualRange.SetMinMaxValues(minX, 50);
+
+                _xyDiagram.AxisY.WholeRange.Auto = true;
+                _xyDiagram.AxisY.VisualRange.Auto = true;
+                _xyDiagram.AxisY.NumericScaleOptions.AutoGrid = true; 
+                _xyDiagram.AxisY.WholeRange.SideMarginsValue = 0;
+                _xyDiagram.AxisY.VisualRange.SideMarginsValue = 0;
+                _xyDiagram.AxisY.WholeRange.SetMinMaxValues(minY, 70);
+                _xyDiagram.AxisY.VisualRange.SetMinMaxValues(minY, 70);
+
             }
             this.chartControl1.EndInit();
         }

--
Gitblit v1.9.3