duheng
2024-03-26 bb006801e4d7fc281e8c1b43ab4b7b83da044ab6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace IStation.InternalModel
{
    internal class PumpCurveInfo
    {
        public int PumpIndex { get; set; }
        public long ID { get; set; }
        public string Name { get; set; }
        public int Status { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public IStation.Model.Pump RatedParas { get; set; }
        /// <summary>
        /// 曲线信息
        /// </summary>    
        public IStation.Model.FeatCurveExpressGroup CurveInfo { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<IStation.Model.GroupPoint> GroupPoints  { get { return _grpPoints; }    set {
                _grpPoints = value;
                maxHead = (from yyy in _grpPoints select yyy.H).Max();
                minHead = (from yyy in _grpPoints select yyy.H).Min();
                groupPointCount = _grpPoints.Count;
            } }
        double maxHead, minHead;
        int groupPointCount = 0;
        List<IStation.Model.GroupPoint> _grpPoints = null;
        public IStation.Model.GroupPoint GetPointByH(double h)
        {
            //在范围内 
            if (h <= maxHead && h >= minHead)
            {
                return GetInterPointExX(h);
            }
  
            //判断是否在前面的延长部分
            double x_start = IStation.Untity.LineHelper.GetXbyY(_grpPoints[0].Q, _grpPoints[0].H, _grpPoints[1].Q, _grpPoints[1].H, h);
            if (x_start <= _grpPoints[0].Q)
            {
                if (x_start > 0 && x_start > _grpPoints[0].Q * 0.5)//放一点余量
                {
                    IStation.Model.GroupPoint grpPt =  new IStation.Model.GroupPoint();
                    grpPt.Q = x_start;
                    grpPt.H = h;
                    grpPt.P = _grpPoints[0].P;
                    return grpPt;
                }
            }
 
            //判断是否在后面的延长部分:U型曲线 是前后都有
            double x_end = IStation.Untity.LineHelper.GetXbyY(_grpPoints[_grpPoints.Count - 2].Q, _grpPoints[_grpPoints.Count - 2].H, _grpPoints[_grpPoints.Count - 1].Q, _grpPoints[_grpPoints.Count - 1].H, h);
            if (x_end >= _grpPoints[_grpPoints.Count - 1].Q && x_end < _grpPoints[_grpPoints.Count - 1].Q * 2)//放一点余量
            { 
                IStation.Model.GroupPoint grpPt = new IStation.Model.GroupPoint();
                grpPt.Q = x_end;
                grpPt.H = h;
                grpPt.P = _grpPoints[_grpPoints.Count - 1].P;
                return grpPt;
            }
 
            return null;
        }
 
        //获得Y值的坐标位置,可能有多个点(是线形插值,不是曲线上的点):会计算延长部分:而且要求_grpPoints点按照从小到大排序
        public IStation.Model.GroupPoint GetInterPointExX(  double H)
        {
            if (GroupPoints == null)
                return  null;
            List<double> sect_pts = new List<double>();
            foreach (var pt in GroupPoints)
            {
                if (Math.Abs(pt.H - H) < 0.02)
                    return pt ;
            }
 
            for (int i = 0; i < groupPointCount - 1; i++)//少一个点
            {
                if ((H >= _grpPoints[i].H && H <= _grpPoints[i + 1].H) || (H <= _grpPoints[i].H && H >= _grpPoints[i + 1].H))
                {//直线插值
                    double Q;
                    if (Math.Abs(_grpPoints[i].H - _grpPoints[i + 1].H) < 0.01)
                        Q = (_grpPoints[i].Q + _grpPoints[i + 1].Q) * 0.5;
                    else
                        Q = _grpPoints[i].Q + (_grpPoints[i + 1].Q - _grpPoints[i].Q) * (H - _grpPoints[i].H) / (_grpPoints[i + 1].H - _grpPoints[i].H);
 
                    double P  = _grpPoints[i].P + (_grpPoints[i + 1].P - _grpPoints[i].P) * (Q - _grpPoints[i].Q) / (_grpPoints[i + 1].Q - _grpPoints[i].Q);
 
                    return new Model.GroupPoint() {  Q = Q, P = P , H= H };
                }
            }
 
 
 
            return null ;
        }
 
    }
}