duheng
2024-10-09 f4bf35513c50f86556d5e3c75a037052f53c971d
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
using DevExpress.XtraEditors;
using NPOI.Util;
 
 
namespace Yw.WinFrmUI.Phart
{
    /// <summary>
    /// (待修改)
    /// </summary>
    public partial class ImportPumpPerform2dByOnePointCtrl : XtraUserControl
    {
 
        //构造函数
        public ImportPumpPerform2dByOnePointCtrl()
        {
            InitializeComponent();
            this.comboBoxType.SelectedIndex = 0;
            this.txtQ.Focus();
            this.txtQ.SelectAll();
 
        }
 
        double _ratedn = -1;
        PumpGroupPt _work_point = null;
        List<Yw.Geometry.Point2d> _pt_qh_list = null;
        List<Yw.Geometry.Point2d> _pt_qe_list = null;
        List<Yw.Geometry.Point2d> _pt_qp_list = null; 
        List<Yw.Geometry.Point2d> _npsh_pt_list = null;
 
 
        //计算转速比
        private void CalcNs()
        {
            if (string.IsNullOrEmpty(this.txtQ.Text) ||
                string.IsNullOrEmpty(this.txtH.Text) ||
                string.IsNullOrEmpty(this.txtN.Text))
                return;
 
            var YLJS = Convert.ToInt32(this.spinEditYLJS.Text);
            var Q = Convert.ToDouble(this.txtQ.Text);
            var H = Convert.ToDouble(this.txtH.Text);
            var N = Convert.ToDouble(this.txtN.Text);
 
            double ns = 0;
            if (this.checkEditSXB.Checked)
            {
                ns = PumpCalcHelper.CalculateNs(Q / 2, H / YLJS, N);
            }
            else
            {
                ns = PumpCalcHelper.CalculateNs(Q, H / YLJS, N);
            }
 
            this.txtNS.EditValue = Math.Round(ns, 2);
        }
 
        //产生曲线
        private bool CreateCurveCore()
        {
            double? k0 = 0;
            if (double.TryParse(this.txtK0.Text, out double value))
            {
                k0 = Convert.ToDouble(txtK0.Text);
                if (k0 < 1.001)
                {
                    XtraMessageBox.Show("关死点系数不能小于1");
                    return false;
                }
            }
 
            if (string.IsNullOrEmpty(this.txtQ.Text) || string.IsNullOrEmpty(this.txtH.Text))
            {
                MessageBox.Show("流量扬程不能为空");
                return false;
            }
            if (string.IsNullOrEmpty(this.txtN.Text))
            {
                MessageBox.Show("转速不能为空");
                return false;
            }
 
            _ratedn = double.Parse(this.txtN.Text);
            if (_ratedn < 10)
            {
                MessageBox.Show("转速有这么小吗?");
                return false;
            }
 
            _work_point = new PumpGroupPt();
            _work_point.Q = double.Parse(this.txtQ.Text);
            _work_point.H = double.Parse(this.txtH.Text);
            if (_work_point.H < 1 || _work_point.Q < 1)
            {
                MessageBox.Show("流量扬程有这么小吗?");
                return false;
            }
 
            if (string.IsNullOrWhiteSpace(this.txtE.Text))
            {
                double ns = PumpCalcHelper.CalculateNs(_work_point.Q, _work_point.H, _ratedn);
                double eff = PumpCalcHelper.CalculateEByPumpType(_work_point.Q, _work_point.H, _ratedn, comboBoxType.SelectedIndex + 1);
 
                _work_point.E = eff;
                this.txtE.EditValue = Math.Round(eff, 1);
            }
            else
            {
                _work_point.E = double.Parse(this.txtE.Text);
            }
            if (_work_point.E > 99)
            {
                MessageBox.Show("效率有这么大吗?");
                return false;
            }
            _work_point.P = PumpCalcHelper.CalculateP(_work_point.Q, _work_point.H, _work_point.E);
            if (string.IsNullOrWhiteSpace(this.txtP.Text))
            {
                this.txtP.EditValue = Math.Round(_work_point.P, 1);
            }
            //汽蚀
            double NPSHr = 0;
            if (!double.TryParse(this.txtNPSH.Text, out NPSHr))
            {
                NPSHr = PumpCalcHelper.CalculateNPSHrByPumpType(_work_point.Q, _work_point.H, _ratedn, comboBoxType.SelectedIndex + 1);//双吸离心泵
                NPSHr = Math.Round(NPSHr, 1);
                this.txtNPSH.EditValue = NPSHr;
            }
            _work_point.NPSH = NPSHr;
 
            //得到点位置
 
            bool iOK = PumpDimensionlessCurvesHelper.CalcPoints(_work_point, _ratedn, k0,
                ref _pt_qh_list, ref _pt_qe_list, ref _pt_qp_list, ref _npsh_pt_list, checkEditSXB.Checked, Convert.ToInt32(spinEditYLJS.Value));
            if (!iOK)
            {
                XtraMessageBox.Show("Error:265");
                return false;
            }
 
            //消除驼峰
            if (k0 == null || k0 < 0.1)
            {
                double spaceH = _work_point.H / 200;//200为预估值
 
                for (int i = _pt_qh_list.Count - 2; i >= 0; i--)
                {
                    if (_pt_qh_list[i].Y < _pt_qh_list[i + 1].Y)
                    {
                        _pt_qh_list[i].Y = _pt_qh_list[i + 1].Y + spaceH;
                    }
                }
            }
 
            if (!string.IsNullOrEmpty(txtMaxRatio.Text))
            {
                double qre = 0;
                if (double.TryParse(txtMaxRatio.Text, out qre))
                {
                    if (qre > 1.01 && qre < 1.8)
                    {
                        var ratio = _work_point.Q * qre / _pt_qh_list.Last().X;
                        if (qre > 1.35)
                        {
                            var pointInfoQH2 = GetFitPointListByExtend(_pt_qh_list, ratio);
                            var maxPt_E = GetLineInsert(_pt_qe_list[_pt_qe_list.Count - 2].X, _pt_qe_list[_pt_qe_list.Count - 1].X, _pt_qe_list[_pt_qe_list.Count - 2].Y, _pt_qe_list[_pt_qe_list.Count - 1].Y, qre * _work_point.Q);
                            _pt_qe_list.Add(new Yw.Geometry.Point2d(qre * _work_point.Q, maxPt_E));
                            _pt_qh_list = pointInfoQH2;
                            _pt_qe_list = _pt_qe_list.GetFitPointList(20);
                            _pt_qp_list = CalculateP(_pt_qh_list, _pt_qe_list);
                        }
                        else
                        {
                            _pt_qh_list = GetFitPointListByExtend(_pt_qh_list, ratio);
                            _pt_qe_list = GetFitPointListByExtend(_pt_qe_list, ratio);
                            _pt_qp_list = GetFitPointListByExtend(_pt_qp_list, ratio);
                        }
                    }
                }
            }
 
            var pt_qh_list = _pt_qh_list.ToList();
            var pt_qe_list = _pt_qe_list.ToList();
            var pt_qp_list = _pt_qp_list.ToList();
 
            var qhCurve = new Yw.Geometry.CubicSpline2d(pt_qh_list);
            var qeCurve = new Yw.Geometry.CubicSpline2d(pt_qe_list);
            var qPCurve = new Yw.Geometry.CubicSpline2d(pt_qp_list);
 
            this.xtrPerform2dChart1.SetBindingData(qhCurve, qeCurve, qPCurve);
            return true;
        }
 
 
 
        public List<Yw.Geometry.Point2d> GetFitPointListByExtend(List<Yw.Geometry.Point2d> points, double ratioExtend, int pointNumber = 20)
        {
            if (points == null)
                return default;
 
            var express = new Yw.Geometry.CubicSpline2d(points); 
            return express.GetPointListByXRatioRange(express.MinX, express.MaxX * ratioExtend, pointNumber);
        }
 
        public double GetLineInsert(double X1, double X2, double Y1, double Y2, double X)
        {
            if (Math.Abs(X2 - X1) < 1E-06)
            {
                return 0.0;
            }
 
            if (Math.Abs(Y2 - Y1) < 1E-06)
            {
                return 0.0;
            }
 
            return Y1 + (Y2 - Y1) / (X2 - X1) * (X - X1);
        }
 
 
     
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        public bool Get(out string other_name, out Yw.Pump.CurveQH qh, out Yw.Pump.CurveQE qe, out Yw.Pump.CurveQP qp)
        {
            other_name = this.txtCurveCode.Text.Trim();
            qh = null;
            qe = null;
            qp = null;
 
            if (!CreateCurveCore())
                return false;
 
            if (string.IsNullOrEmpty(other_name))
            {
                XtraMessageBox.Show("请输入曲线名称!");
                return false;
            }
            qh = new Pump.CurveQH(Yw.Pump.eFeatType.Cubic, _pt_qh_list);
            qe = new Pump.CurveQE(Yw.Pump.eFeatType.Cubic, _pt_qe_list);
            qp = new Pump.CurveQP(Yw.Pump.eFeatType.Cubic, _pt_qp_list);
 
            return true;
        }
 
 
        #region 事件
 
        private void txtQ_EditValueChanged(object sender, EventArgs e)
        {
            CalcNs();
        }
 
        private void txtH_EditValueChanged(object sender, EventArgs e)
        {
            CalcNs();
        }
 
        private void txtN_EditValueChanged(object sender, EventArgs e)
        {
            CalcNs();
        }
 
        private void spinEditYLJS_EditValueChanged(object sender, EventArgs e)
        {
            CalcNs();
        }
 
        private void labReckon_Click(object sender, EventArgs e)
        {
            //水力参数
            try
            {
                if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text))
                {
                    MessageBox.Show("流量扬程不能为空");
                    return;
                }
                //转速
                if (string.IsNullOrEmpty(txtN.Text))
                {
                    MessageBox.Show("转速不能为空");
                    return;
                }
                _ratedn = double.Parse(txtN.Text);
                if (_ratedn < 10)
                {
                    MessageBox.Show("转速有这么小吗?");
                    return;
                }
                _work_point = new  ();
                _work_point.Q = double.Parse(txtQ.Text);
                _work_point.H = double.Parse(txtH.Text);
                if (_work_point.H < 1 || _work_point.Q < 1)
                {
                    MessageBox.Show("流量扬程有这么小吗?");
                    return;
                }
 
            }
            catch
            {
                MessageBox.Show("请输入数字");
                return;
            }
             
 
            double eff = PumpCalcHelper.CalculateEByPumpType(_work_point.Q, _work_point.H, _ratedn, comboBoxType.SelectedIndex + 1);
            txtE.Text = string.Format("{0:0.0}", eff);
            _work_point.E = eff;
 
            double NPSHr = PumpCalcHelper.CalculateNPSHrByPumpType(_work_point.Q, _work_point.H, _ratedn, comboBoxType.SelectedIndex + 1);//双吸离心泵
 
            NPSHr = Math.Round(NPSHr, 1);
            txtNPSH.Text = NPSHr.ToString();
        }
 
        private void labCalcuE_Click(object sender, EventArgs e)
        {
            #region 得到参数
            double Q, H, P;
            try
            {
                if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text) || string.IsNullOrEmpty(txtE.Text))
                {
                    MessageBox.Show("流量,扬程和功率,不能为空");
                    return;
                }
                H = double.Parse(txtH.Text);
                Q = double.Parse(txtQ.Text);
                P = double.Parse(txtP.Text);
                if (H < 1 || Q < 1 || P < 1)
                {
                    MessageBox.Show("参数有这么小吗");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("请输入数字");
                return;
            }
            #endregion
 
            double E = PumpCalcHelper.CalculateE(Q, H, P);
            txtE.Text = string.Format("{0:0.0}", E);
 
            if (E > 99)
            {
                MessageBox.Show("功率是否输入有误?");
                return;
            }
        }
 
        private void labCalcuP_Click(object sender, EventArgs e)
        {
            #region 得到参数
            double Q, H, E;
            try
            {
                if (string.IsNullOrEmpty(txtH.Text) || string.IsNullOrEmpty(txtQ.Text) || string.IsNullOrEmpty(txtE.Text))
                {
                    MessageBox.Show("流量,扬程和功率,不能为空");
                    return;
                }
                H = double.Parse(txtH.Text);
                Q = double.Parse(txtQ.Text);
                E = double.Parse(txtE.Text);
                if (H < 0.1 || Q < 0.1 || E < 1)
                {
                    MessageBox.Show("参数有这么小吗");
                    return;
                }
            }
            catch
            {
                MessageBox.Show("请输入数字");
                return;
            }
            #endregion
 
            double P = PumpCalcHelper.CalculateP(Q, H, E);
            if (P < 1)
            {
                txtP.Text = string.Format("{0:0.000}", P);
            }
            else if (P < 10)
            {
                txtP.Text = string.Format("{0:0.00}", P);
            }
            else if (P < 100)
            {
                txtP.Text = string.Format("{0:0.0}", P);
            }
            else
            {
                txtP.Text = string.Format("{0:N0}", P);
            }
        }
 
        //生成曲线
        private void btnCreate_Click(object sender, EventArgs e)
        {
            CreateCurveCore();
        }
 
        #endregion
 
 
        public static List<Yw.Geometry.Point2d> CalculateP(List<Yw.Geometry.Point2d> pointQH, List<Yw.Geometry.Point2d> pointQE)
        {
            if (pointQH == null || pointQH.Count() <= 2)
                return null;
            bool isFromZero = true;
            if (pointQH.First().X > 500 || pointQH.First().X > pointQH.Last().X * 0.2)
                isFromZero = false;
            return CalculateP_RefZero(pointQH, pointQE, Constant.WaterDensity, -1, isFromZero);
        }
 
        //有时 会把零流量点扬程传入 ref_zero_power
        public static List<Yw.Geometry.Point2d> CalculateP_RefZero(
            List<Yw.Geometry.Point2d> pointQH,
            List<Yw.Geometry.Point2d> pointQE,
            double midu,
            double ref_zero_power,
            bool isFromZero)
        {
            if (pointQH == null || pointQH.Count < 3)
                return null;
            if (pointQE == null || pointQE.Count < 3)
                return null;
 
            var expressQH = new Yw.Geometry.CubicSpline2d(pointQH);
            var expressQE = new Yw.Geometry.CubicSpline2d(pointQE);
 
            var expressQP = CalculateP_RefZero(expressQH, expressQE, midu, ref_zero_power, isFromZero, false);
 
            return expressQP.GetPointList(pointQE.Count());
        }
 
        public static Yw.Geometry.CubicSpline2d CalculateP_RefZero(
         Yw.Geometry.CubicSpline2d expressQH,
         Yw.Geometry.CubicSpline2d expressQE,
         double midu, double ref_zero_power, bool isFromZero, bool isSavePointInExpress)
        {
            if (expressQH == null)
                return null;
            if (expressQE == null)
                return null;
            int point_num = 16;//点不能太多
            var pointQH = expressQH.GetPointList(point_num);
            if (pointQH == null || pointQH.Count < 3)
                return null;
            var pointQE = expressQE.GetPointList(point_num);
            if (pointQE == null || pointQE.Count < 3)
                return null;
 
            List<Yw.Geometry.Point2d> pointQP = new List<Yw.Geometry.Point2d>();
            //间距
            double minQ = Math.Max(pointQH.First().X, pointQE.First().X);
            double maxQ = Math.Min(pointQH.Last().X, pointQE.Last().X);
 
            //
            double Q, H, E, P;
 
            double space = (maxQ - minQ) / (point_num - 1);
 
            var fitCurveQE = expressQE.Copy();
            var fitCurveQH = expressQH.Copy();
 
            if (isFromZero)
            {
                #region 保证从0开始:  保证Q=0时,P不是计算出来的;
                for (int i = 5; i < point_num; i++)//前面几个点不要
                {
                    Q = pointQE.First().X + space * i;
                    E = fitCurveQE.GetPointY(Q);
                    H = fitCurveQH.GetPointY(Q);
                    if (H < 0.1 || E < 0.5)
                        continue;
 
                    P = PumpCalcHelper.CalculateP(Q, H, E, midu);
                    if (P < 2)
                    {
                        P = Math.Round(P, 3);
                    }
                    else if (P < 30)
                    {
                        P = Math.Round(P, 2);
                    }
                    else if (P < 100)
                    {
                        P = Math.Round(P, 1);
                    }
                    else
                    {
                        P = Math.Round(P, 0);
                    }
                    pointQP.Add(new Yw.Geometry.Point2d(Q, P));
                }
 
                pointQP = pointQP.GetFitPointList(  point_num);
                if (pointQP == null)
                    return null;
 
 
 
                if (ref_zero_power > 0.1)
                {
                    pointQP.Insert(0, new Yw.Geometry.Point2d(0, ref_zero_power));
                }
                else
                {
                    if (pointQP[0].Y >= pointQP[1].Y)
                    {
                        pointQP[0].Y = pointQP[1].Y * 0.95;
                    }
                    double startP =  Yw.Geometry. LineHelper.GetYbyX(pointQP[0].X, pointQP[0].Y, pointQP[1].X, pointQP[1].Y, 0);
                    if (startP < 0.001)
                        startP = pointQP[0].Y;
 
                    if (startP < 2)
                    {
                        startP = Math.Round(startP, 3);
                    }
                    else if (startP < 30)
                    {
                        startP = Math.Round(startP, 2);
                    }
                    else if (startP < 100)
                    {
                        startP = Math.Round(startP, 1);
                    }
                    else
                    {
                        startP = Math.Round(startP, 0);
                    }
 
                    pointQP.Insert(0, new Yw.Geometry.Point2d(0, startP));
                }
 
 
                return new Yw.Geometry.CubicSpline2d(pointQP);
                #endregion
            }
            else
            {
                #region 保证从0开始:  保证Q=0时,P不是计算出来的;
                for (int i = 0; i < point_num; i++)//前面几个点不要
                {
                    Q = pointQE.First().X + space * i;
                    E = fitCurveQE.GetPointY(Q);
                    H = fitCurveQH.GetPointY(Q);
                    if (H < 0.1 || E < 0.5)
                        continue;
 
                    P = PumpCalcHelper.CalculateP(Q, H, E, midu);
                    if (P < 2)
                    {
                        P = Math.Round(P, 3);
                    }
                    else if (P < 30)
                    {
                        P = Math.Round(P, 2);
                    }
                    else if (P < 100)
                    {
                        P = Math.Round(P, 1);
                    }
                    else
                    {
                        P = Math.Round(P, 0);
                    }
                    pointQP.Add(new Yw.Geometry.Point2d(Q, P));
                }
 
                pointQP = pointQP.GetFitPointList(point_num);
                if (pointQP == null)
                    return null;
 
                return new Yw.Geometry.CubicSpline2d(pointQP);
                #endregion
            }
 
        }
 
    }
}