Shuxia Ning
2025-01-08 0a1bf56909464e938a68c29b26ab88ff51380fad
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
using DevExpress.XtraEditors;
 
namespace Yw.WinFrmUI.Phart
{
    /// <summary>
    /// 
    /// </summary>
    public partial class PumpChartPointImportCtrl : XtraUserControl
    {
        public PumpChartPointImportCtrl()
        {
            InitializeComponent();
 
            this.repTxtk0.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
            this.repTxtFlow.AllowNullInput = DevExpress.Utils.DefaultBoolean.True;
 
        }
 
 
        private List<Yw.Geometry.Point2d> _def_qh_pt_list = null;
        private List<Yw.Geometry.Point2d> _def_qe_pt_list = null;
        private List<Yw.Geometry.Point2d> _def_qp_pt_list = null;
        private List<Yw.Geometry.Point2d> _def_npsh_pt_list = null;
        private Ahart.eFeatType _feat_type_qh = Ahart.eFeatType.Cubic;
        private Ahart.eFeatType _feat_type_qe = Ahart.eFeatType.Cubic;
        private Ahart.eFeatType _feat_type_qp = Ahart.eFeatType.Cubic;
 
 
 
        /// <summary>
        /// 绑定数据
        /// </summary> 
        public void SetBindingData(double flow, double head, double n, double? eff, double stage_number, bool is_sxp)
        {
            this.barTxtFlow.EditValue = flow;
            this.barTxtHead.EditValue = head;
            this.barTxtN.EditValue = n;
            this.barTxtEff.EditValue = eff;
            this.barSpinLevel.EditValue = stage_number;
            this.barCekIsSxp.Checked = is_sxp;
 
            this.repImgCmbPumpType.AddEnum<eCalcPumpType>();
            this.barImgCmbPumpType.EditValue = eCalcPumpType.单级单吸离心泵;
 
            this.repImgCmbPumpType.ButtonClick += (s, e) =>
            {
                if (e.Button.Tag is string reckon)
                {
                    CalcByPumpType();
                }
            };
 
            this.repTxtEff.ButtonClick += (s, e) =>
            {
                CalcEff();
            };
 
            this.repTxtPower.ButtonClick += (s, e) =>
            {
                CalcPower();
            };
 
            this.barTxtFlow.EditValueChanged += (s, e) =>
            {
                CalcNs();
            };
 
            this.barTxtHead.EditValueChanged += (s, e) =>
            {
                CalcNs();
            };
 
            this.barTxtN.EditValueChanged += (s, e) =>
            {
                CalcNs();
            };
 
            this.barSpinLevel.EditValueChanged += (s, e) =>
            {
                CalcNs();
            };
 
            Create();
        }
 
        //是否是无效数据
        private bool IsInvalidData()
        {
            if (this.barTxtFlow.EditValue == null)
            {
                return true;
            }
            if (this.barTxtHead.EditValue == null)
            {
                return true;
            }
            if (this.barTxtN.EditValue == null)
            {
                return true;
            }
            if (this.barSpinLevel.EditValue == null)
            {
                return true;
            }
 
            if (this.barTxtN.EditValue is not double n)
            {
                return true;
            }
            if (this.barTxtFlow.EditValue is not double flow)
            {
                return true;
            }
            if (this.barTxtHead.EditValue is not double head)
            {
                return true;
            }
            if (this.barImgCmbPumpType.EditValue is not eCalcPumpType pump_type)
            {
                return true;
            }
 
            return false;
        }
 
        //根据泵类型计算(估算)
        private void CalcByPumpType()
        {
            if (IsInvalidData())
                return;
            var n = Convert.ToDouble(this.barTxtN.EditValue);
            if (n < 10)
                return;
            var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
            var head = Convert.ToDouble(this.barTxtHead.EditValue);
            var pump_type = (eCalcPumpType)this.barImgCmbPumpType.EditValue;
            var eff = Yw.Pump.CalculationHelper.CalcuEByPumpType(flow, head, n, (int)pump_type);
            var npsh_r = Yw.Pump.CalculationHelper.CalcuNPSHrByPumpType(flow, head, n, (int)pump_type);
 
            eff = Math.Round(eff, 1);
            npsh_r = Math.Round(npsh_r, 1);
            this.barTxtEff.EditValue = eff;
            this.barTxtNPSH.EditValue = npsh_r;
        }
 
        //计算转速比
        private void CalcNs()
        {
            if (IsInvalidData())
                return;
 
            var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
            var head = Convert.ToDouble(this.barTxtHead.EditValue);
            var n = Convert.ToDouble(this.barTxtN.EditValue);
            var stage_number = Convert.ToInt32(this.barSpinLevel.EditValue);
 
            if (this.barCekIsSxp.Checked)
                flow /= 2;
            var ns = Yw.Pump.CalculationHelper.CalcuNs(flow, head / stage_number, n);
            ns = Math.Round(ns, 2);
            this.barTxtNRatio.EditValue = ns;
        }
 
        //计算效率
        private void CalcEff()
        {
            if (IsInvalidData())
                return;
            if (this.barTxtPower.EditValue is not double)
                return;
            var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
            var head = Convert.ToDouble(this.barTxtHead.EditValue);
            var power = Convert.ToDouble(this.barTxtPower.EditValue);
 
            var eff = Yw.Pump.CalculationHelper.CalcuE(flow, head, power);
            eff = Math.Round(eff, 1);
            this.barTxtEff.EditValue = eff;
            if (eff > 99)
            {
                MessageBox.Show("功率是否输入有误?");
                return;
            }
        }
 
        //计算功率
        private void CalcPower()
        {
            if (IsInvalidData())
                return;
            if (this.barTxtEff.EditValue is not double)
                return;
 
            var flow = Convert.ToDouble(this.barTxtFlow.EditValue);
            var head = Convert.ToDouble(this.barTxtHead.EditValue);
            var eff = Convert.ToDouble(this.barTxtEff.EditValue);
 
            var power = Yw.Pump.CalculationHelper.CalcuP(flow, head, eff);
            var digits = 0;
            if (power < 1)
                digits = 3;
            else if (power < 10)
                digits = 2;
            else if (power < 100)
                digits = 1;
            power = Math.Round(power, digits);
            this.barTxtPower.EditValue = power;
        }
 
        //生成曲线
        private bool CreateCurve(out List<Yw.Geometry.Point2d> qh_pt_list, out List<Yw.Geometry.Point2d> qe_pt_list, out List<Yw.Geometry.Point2d> qp_pt_list)
        {
            qh_pt_list = null;
            qe_pt_list = null;
            qp_pt_list = null;
            if (IsInvalidData())
                return false;
            if (this.barTxtEff.EditValue == null)
            {
                CalcEff();
            }
            if (this.barTxtPower.EditValue == null)
            {
                CalcPower();
            }
 
 
            double? k0 = 0;
            if (this.barTxtk0.EditValue != null)
            {
                k0 = Convert.ToDouble(barTxtk0.EditValue);
                if (k0 < 1.001)
                {
                    XtraMessageBox.Show("关死点系数不能小于1");
                    return false;
                }
            }
 
            double flow, head, eff, power, n;
            flow = Convert.ToDouble(this.barTxtFlow.EditValue);
            head = Convert.ToDouble(this.barTxtHead.EditValue);
            eff = Convert.ToDouble(this.barTxtEff.EditValue);
            power = Convert.ToDouble(this.barTxtPower.EditValue);
            n = Convert.ToDouble(this.barTxtN.EditValue);
 
 
            if (eff > 99)
            {
                XtraMessageBox.Show("效率有这么大吗?");
                return false;
            }
 
            if (this.barTxtNPSH.EditValue == null)
            {
                var pump_type = (eCalcPumpType)this.barImgCmbPumpType.EditValue;
                var npsh_r = Yw.Pump.CalculationHelper.CalcuNPSHrByPumpType(flow, head, n, (int)pump_type);//双吸离心泵
                npsh_r = Math.Round(npsh_r, 1);
                this.barTxtNPSH.EditValue = npsh_r;
            }
 
            var pt = new PumpQueryPointViewModel();
            pt.Q = flow;
            pt.H = head;
            pt.E = eff;
            pt.P = power;
            pt.N = n;
            pt.Hz = 50;
 
 
            //得到点位置
            var stage_number = Convert.ToInt32(this.barSpinLevel.EditValue);
            bool is_ok = Yw.Pump.PerformDimensionlessCurveHelper.CalcPoints(pt.Q, pt.H, pt.E ?? 0, pt.P ?? 0, n, k0,
                _feat_type_qh, _feat_type_qe, _feat_type_qp,
                ref qh_pt_list, ref qe_pt_list, ref qp_pt_list, barCekIsSxp.Checked, stage_number);
            if (!is_ok)
            {
                XtraMessageBox.Show("计算失败!");
                return false;
            }
 
            //消除驼峰
            if (k0 == null || k0 < 0.1)
            {
                double space_head = head / 200;//200为预估值 
                for (int i = qh_pt_list.Count - 2; i >= 0; i--)
                {
                    if (qh_pt_list[i].Y < qh_pt_list[i + 1].Y)
                    {
                        qh_pt_list[i].Y = qh_pt_list[i + 1].Y + space_head;
                    }
                }
            }
 
            if (this.barTxtFlowMaxRatio.EditValue != null)
            {
                var qre = Convert.ToDouble(this.barTxtFlowMaxRatio.EditValue);
                if (qre > 1.01 && qre < 1.8)
                {
                    var ex_q = flow * qre;
                    var max_q = qh_pt_list.Last().X;
                    var ratio = ex_q / max_q;
                    if (qre > 1.35)
                    {
                        var index1 = qe_pt_list.Count - 2;
                        var index2 = qe_pt_list.Count - 1;
                        var x1 = qe_pt_list[index1].X;
                        var y1 = qe_pt_list[index1].Y;
                        var x2 = qe_pt_list[index2].X;
                        var y2 = qe_pt_list[index2].Y;
                        var x = qre * flow;
 
 
                        var max_powert_E = Yw.Geometry.LineHelper.GetLineInsert(x1, x2, y1, y2, x);
                        qe_pt_list.Add(new Yw.Geometry.Point2d(qre * flow, max_powert_E));
 
                        qh_pt_list = qh_pt_list.GetExpandPointList(_feat_type_qh, 1, ratio);
                        qe_pt_list = qe_pt_list.GetPointList(_feat_type_qe, 20);
                        qp_pt_list = Yw.Pump.CalculationHelper.CalcuP(_feat_type_qp, qh_pt_list, _feat_type_qh, qe_pt_list, _feat_type_qe);
                    }
                    else
                    {
                        qh_pt_list = qh_pt_list.GetExpandPointList(_feat_type_qh, 1, ratio);
                        qe_pt_list = qe_pt_list.GetExpandPointList(_feat_type_qe, 1, ratio);
                        qp_pt_list = qp_pt_list.GetExpandPointList(_feat_type_qp, 1, ratio);
                    }
                }
            }
 
            return true;
 
        }
 
        private void Create()
        {
            if (IsInvalidData())
                return;
 
            var bol = CreateCurve(out List<Yw.Geometry.Point2d> qh_pt_list, out List<Yw.Geometry.Point2d> qe_pt_list, out List<Yw.Geometry.Point2d> qp_pt_list);
            _def_qh_pt_list = qh_pt_list;
            _def_qe_pt_list = qe_pt_list;
            _def_qp_pt_list = qp_pt_list;
 
            if (!bol)
            {
                this.pumpViewChart1.ClearBindingData();
            }
            else
            {
                var vm = new PumpCurveViewModel();
                vm.CurveQH = _def_qh_pt_list;
                vm.CurveQE = _def_qe_pt_list;
                vm.CurveQP = _def_qp_pt_list;
                this.pumpViewChart1.SetBindingData(vm);
            }
        }
 
 
        //生成
        private void barBtnCreate_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Create();
        }
 
 
        /// <summary>
        /// 获取数据
        /// </summary> 
        public bool Get(
           out List<Yw.Geometry.Point2d> def_qh_pt_list,
           out List<Yw.Geometry.Point2d> def_qe_pt_list,
           out List<Yw.Geometry.Point2d> def_qp_pt_list,
           out Yw.Ahart.eFeatType feat_type_qh,
           out Yw.Ahart.eFeatType feat_type_qe,
           out Yw.Ahart.eFeatType feat_type_qp)
        {
            def_qh_pt_list = _def_qh_pt_list;
            def_qe_pt_list = _def_qe_pt_list;
            def_qp_pt_list = _def_qp_pt_list;
            feat_type_qh = _feat_type_qh;
            feat_type_qe = _feat_type_qe;
            feat_type_qp = _feat_type_qp;
            if (def_qh_pt_list == null || !def_qh_pt_list.Any())
                return false;
            return true;
        }
    }
}