tangxu
2022-11-02 05f522e321a742f03bf1e3e26edaeb5147da42f4
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using IStation.Calculation.DispatchAna.Model;
 
namespace IStation.Calculation.DispatchAna
{
    /// <summary>
    /// 金海泵站调度方案计算器(最优方案)
    /// </summary>
    public  class Calculator_OptAna_SHYS_金海泵站: CalculatorBase_SHYS_金海泵站, IOptAnaCalc
    {
        List<Model.MachineDetail> _allMachineList = null;
 
 
 
       
 
        #region 计算 最优方案 
        /// <summary>
        /// 计算 最优方案 
        /// </summary>
        /// <param name="complex_request_paras"></param>
        /// <param name="eta_ana_records"></param>
        /// <param name="machine_run_status"></param>
        /// <param name="error_info"></param>
        /// <returns></returns>
        public List<IStation.Calculation.DispatchAna.Model.AnaScheme> CalcSchemes(
            IStation.Calculation.DispatchAna.Model.RequestParasComplex complex_request_paras,
            IStation.Calculation.DispatchAna.Model.EtaAnaRecord4Station eta_ana_records,
            IStation.Calculation.DispatchAna.Model.MachineRunPara machine_run_status,
            out string error_info)
        {
            this._corpID = complex_request_paras.CorpID;
            this._stationID = complex_request_paras.StationID;
 
 
 
 
            var isUsePress = complex_request_paras.PressValueType == Model.RequestParasComplex.ePressValueType.压力 ? true : false;
 
     
            if (isUsePress)
                return CalcSchemes压力(complex_request_paras, machine_run_status, out error_info);
            else
                return CalcSchemes扬程(complex_request_paras, machine_run_status, out error_info);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="complex_request_paras"></param>
        /// <param name="machine_run_status"></param>
        /// <param name="error_info"></param>
        /// <returns></returns>
        protected override  List<IStation.Calculation.DispatchAna.Model.AnaScheme> CalcSchemes压力(
                    IStation.Calculation.DispatchAna.Model.RequestParasComplex complex_request_paras,
                    IStation.Calculation.DispatchAna.Model.MachineRunPara machine_run_status,
                    out string error_info)
        {
            error_info = "";
            if (complex_request_paras == null)
            {
                error_info = "ERROR 30";
                return null;
            }
            if (complex_request_paras.OutletPipePara == null ||
                complex_request_paras.OutletPipePara.Count < 3)
            {
                error_info = "ERROR 35,金海泵站需要3个出口管路的流量";
                return null;
            }
            double inlet_press = 0;//进口压力(有两个进口压力)
            if (complex_request_paras.InletPipePara != null && complex_request_paras.InletPipePara.Count > 0)
            {
                if (complex_request_paras.InletPipePara.Count == 1)
                {
                    inlet_press = complex_request_paras.InletPipePara[0].Value;
                }
                else
                {//用平均值
                    inlet_press = complex_request_paras.InletPipePara[0].Value +
                        complex_request_paras.InletPipePara[1].Value;
                    inlet_press = inlet_press / 2;
                }
            }
 
 
 
            double pipe1_TargetFlow = complex_request_paras.OutletPipePara[0].TargetFlow;
            double pipe2_TargetFlow = complex_request_paras.OutletPipePara[1].TargetFlow;
            double pipe3_TargetFlow = complex_request_paras.OutletPipePara[2].TargetFlow;
            if (pipe1_TargetFlow < 50 && pipe2_TargetFlow < 50 && pipe3_TargetFlow < 50)
            {//都关机
                error_info = "ERROR 35,金海泵站需要3个出口管路的流量都为0";
                return null;
            }
 
            double pipe1_TargetPess = complex_request_paras.OutletPipePara[0].TargetPress;
            double pipe2_TargetPess = complex_request_paras.OutletPipePara[1].TargetPress;
            double pipe3_TargetPess = complex_request_paras.OutletPipePara[2].TargetPress;
            if (pipe1_TargetFlow > 50)
            {
                if (pipe1_TargetPess < inlet_press+0.01)
                {
                    error_info = "ERROR 35,金海泵站需要一号管压力未赋值";
                    return default;
                }
            }
            if (pipe2_TargetFlow > 50)
            {
                if (pipe2_TargetPess < inlet_press + 0.01)
                {
                    error_info = "ERROR 35,金海泵站需要二号管压力未赋值";
                    return default;
                }
            }
            if (pipe3_TargetFlow > 50)
            {
                if (pipe3_TargetPess < inlet_press + 0.01)
                {
                    error_info = "ERROR 35,金海泵站需要三号管压力未赋值";
                    return default;
                }
            }
 
 
 
 
 
 
            //机泵信息
            if (_allMachineList == null)
            {
                if (!BuildMachineList(
                    out _allMachineList,
                    out error_info))
                {
                    error_info = "机泵组无法构建,ERROR 70,错误信息:" + error_info;
                    return null;
                }
            }
 
 
 
 
            Common.DispatchAnaGeneralHelper压力 calc_pipe1_helper
                = new Common.DispatchAnaGeneralHelper压力();
 
            Common.DispatchAnaGeneralHelper压力 calc_pipe2_helper
                = new Common.DispatchAnaGeneralHelper压力();
 
            Common.DispatchAnaGeneralHelper压力 calc_pipe3_helper
                = new Common.DispatchAnaGeneralHelper压力();
 
 
            double totalQ = 0, totalH = 0, totalP = 0;
            int pipe_count = 0;
 
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe1_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe1_results = null;
            if (pipe1_TargetFlow > 50)
            {
                calc_pipe1_helper.InitialParas(
                pipe1_TargetFlow,
                inlet_press, false ,
                pipe1_TargetPess,false,
              null, null,
             (from x in _allMachineList where pipe1_machineIds.Contains(x.MachineID) select x).ToList(),
            machine_run_status == null ? null : machine_run_status.MachineRunFilter);
                pipe1_results = calc_pipe1_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe1_results == null || pipe1_results.Count() == 0)
                {
                    error_info = String.Format("管路一调度方案无法计算,请确认数据是否合理,进口压力:{0}MPa,出口压力:{1}MPa,流量要求:{2}",
                        Math.Round( inlet_press,4), Math.Round(pipe1_TargetPess,4), pipe1_TargetFlow);
                    return null;
                }
                pipe1_result = pipe1_results[0];
                totalQ += pipe1_result.TotalWrkQ;
                totalP += pipe1_result.TotalWrkP;
                totalH += pipe1_result.TotalWrkH;
                pipe_count++;
            }
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe2_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe2_results = null;
            if (pipe2_TargetFlow > 50)
            {
                calc_pipe2_helper.InitialParas(
                pipe2_TargetFlow,
             inlet_press, false,
              pipe2_TargetPess,false ,
              null, null,
             (from x in _allMachineList where pipe2_machineIds.Contains(x.MachineID) select x).ToList(),
            machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                pipe2_results = calc_pipe2_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe2_results == null || pipe2_results.Count() == 0)
                {
                    error_info = String.Format("管路2调度方案无法计算,请确认数据是否合理,进口压力:{0}MPa,出口压力:{1}MPa,流量要求:{2}",
                   Math.Round(inlet_press, 4), Math.Round(pipe2_TargetPess, 4), pipe2_TargetFlow);
                    return null;
                }
                pipe2_result = pipe2_results[0];
                totalQ += pipe2_result.TotalWrkQ;
                totalP += pipe2_result.TotalWrkP;
                totalH += pipe2_result.TotalWrkH;
                pipe_count++;
            }
 
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe3_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe3_results = null;
            if (pipe3_TargetFlow > 50)
            {
                calc_pipe3_helper.InitialParas(
                pipe3_TargetFlow,
             inlet_press, false,
                pipe3_TargetPess,false ,
                null, null,
             (from x in _allMachineList where pipe3_machineIds.Contains(x.MachineID) select x).ToList(),
            machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                pipe3_results = calc_pipe3_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe3_results == null || pipe3_results.Count() == 0)
                {
                    error_info = String.Format("管路3调度方案无法计算,请确认数据是否合理,进口压力:{0}MPa,出口压力:{1}MPa,流量要求:{2}",
                        Math.Round(inlet_press, 4), Math.Round(pipe3_TargetPess, 4),  pipe3_TargetFlow);
                    return null;
                }
                pipe3_result = pipe3_results[0];
                totalQ += pipe3_result.TotalWrkQ;
                totalP += pipe3_result.TotalWrkP;
                totalH += pipe3_result.TotalWrkH;
                pipe_count++;
            }
 
            var plan = new Model.AnaScheme();
            plan.ID = 1;
            plan.TotalWrkQ = Math.Round(totalQ, 1);
            plan.TotalWrkH = Math.Round(totalH / pipe_count, 2);
            plan.TotalWrkP = Math.Round(totalP, 1);
 
            plan.TotalWrkE = IStation.Common.PumpParaHelper.CalculateE(plan.TotalWrkQ, plan.TotalWrkH, plan.TotalWrkP);
 
 
            plan.UWP = CalculateUWP(plan.TotalWrkP, plan.TotalWrkQ, plan.TotalWrkH);
            plan.WP = CalculateWP(plan.TotalWrkP, plan.TotalWrkQ);
 
            plan.Items = new List<Model.AnaSchemeItem>();
            if (pipe1_result.Items != null && pipe1_result.Items.Count > 0)
                plan.Items.AddRange(pipe1_result.Items);
            if (pipe2_result.Items != null && pipe2_result.Items.Count > 0)
                plan.Items.AddRange(pipe2_result.Items);
            if (pipe3_result.Items != null && pipe3_result.Items.Count > 0)
                plan.Items.AddRange(pipe3_result.Items);
 
 
            return new List<Model.AnaScheme>() { plan };   
        }
 
 
 
        private List<IStation.Calculation.DispatchAna.Model.AnaScheme> CalcSchemes扬程(
                    IStation.Calculation.DispatchAna.Model.RequestParasComplex complex_request_paras,
                    IStation.Calculation.DispatchAna.Model.MachineRunPara machine_run_status,
                    out string error_info)
        {
            error_info = "";
            if (complex_request_paras == null)
            {
                error_info = "ERROR 30";
                return null;
            }
            if (complex_request_paras.OutletPipePara == null ||
                complex_request_paras.OutletPipePara.Count < 2)
            {
                error_info = "ERROR 35,金海泵站需要两个管路的流量";
                return null;
            }
 
            double pipe1_TargetFlow = complex_request_paras.OutletPipePara[0].TargetFlow;
            double pipe2_TargetFlow = complex_request_paras.OutletPipePara[1].TargetFlow;
            double pipe3_TargetFlow = complex_request_paras.OutletPipePara[2].TargetFlow;
            if (pipe1_TargetFlow < 50 && pipe2_TargetFlow < 50 && pipe3_TargetFlow < 50)
            {//都关机
                error_info = "ERROR 35,金海泵站需要两个管路的流量 都为0";
                return null;
            }
 
            double pipe1_TargetHead = complex_request_paras.OutletPipePara[0].TargetPress;
            double pipe2_TargetHead = complex_request_paras.OutletPipePara[1].TargetPress;
            double pipe3_TargetHead = complex_request_paras.OutletPipePara[2].TargetPress;
            if (pipe1_TargetFlow > 50)
            {
                if (pipe1_TargetHead < 0.01)
                {
                    error_info = "ERROR 35,金海泵站需要一号管压力未赋值";
                    return default;
                }
            }
            if (pipe2_TargetFlow > 50)
            {
                if (pipe2_TargetHead < 0.01)
                {
                    error_info = "ERROR 35,金海泵站需要二号管压力未赋值";
                    return default;
                }
            }
            if (pipe3_TargetFlow > 50)
            {
                if (pipe3_TargetHead < 0.01)
                {
                    error_info = "ERROR 35,金海泵站需要3号管压力未赋值";
                    return default;
                }
            }
 
 
            //机泵信息
            if (_allMachineList == null)
            {
                if (!BuildMachineList(
                out _allMachineList,
                out error_info))
                {
                    error_info = "机泵组无法构建,ERROR 70,错误信息:" + error_info;
                    return null;
                }
            }
 
             
          
      
/*
 
                Common.DispatchAnaGeneralHelper扬程 calc_pipe1_helper =
         new Common.DispatchAnaGeneralHelper扬程();
 
                Common.DispatchAnaGeneralHelper扬程 calc_pipe2_helper =
          new Common.DispatchAnaGeneralHelper扬程();
 
                if (pipe2_TargetFlow < 50)
                {//只开一号泵二号泵
                    calc_pipe1_helper.InitialParas(
                        pipe1_TargetFlow,
                        pipe1_TargetHead,
                        null, null,
                        (from x in _allMachineList where pipe1_machineIds.Contains(x.MachineID) select x).ToList(),
                    machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                    return calc_pipe1_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                }
                else if (pipe1_TargetFlow < 50)
                {
                    calc_pipe2_helper.InitialParas(
                        pipe2_TargetFlow,
                        pipe2_TargetHead,
                        null, null,
                     (from x in _allMachineList where pipe2_machineIds.Contains(x.MachineID) select x).ToList(),
                    machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                    return calc_pipe2_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                }
                calc_pipe1_helper.InitialParas(
                    pipe1_TargetFlow,
                    pipe1_TargetHead,
                  null, null,
                 (from x in _allMachineList where pipe1_machineIds.Contains(x.MachineID) select x).ToList(),
               machine_run_status == null ? null : machine_run_status.MachineRunFilter);
                var pipe1_result = calc_pipe1_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
 
 
                calc_pipe2_helper.InitialParas(
                    pipe2_TargetFlow,
                    pipe2_TargetHead,
                    null, null,
                 (from x in _allMachineList where pipe2_machineIds.Contains(x.MachineID) select x).ToList(),
                 machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                var pipe2_result = calc_pipe2_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
 
                if (pipe1_result == null || pipe2_result == null)
                    return default;
 
                var result_1 = pipe1_result.First();
                var result_2 = pipe2_result.First();
 
                var plan = new Model.AnaScheme();
                plan.ID = 1;
                plan.TotalWrkQ = result_1.TotalWrkQ + result_2.TotalWrkQ;
                plan.TotalWrkH = result_1.TotalWrkH + result_2.TotalWrkH;
                plan.TotalWrkP = result_1.TotalWrkP + result_2.TotalWrkP;
                plan.TotalWrkE = IStation.Common.PumpParaHelper.CalculateE(plan.TotalWrkQ, plan.TotalWrkH, plan.TotalWrkP);
                plan.UWP = CalculateUWP(plan.TotalWrkP, plan.TotalWrkQ, plan.TotalWrkH);
                plan.WP = CalculateWP(plan.TotalWrkP, plan.TotalWrkQ);
 
                plan.Items = new List<Model.AnaSchemeItem>();
                if (result_1.Items != null && result_1.Items.Count > 0)
                    plan.Items.AddRange(result_1.Items);
                if (result_2.Items != null && result_2.Items.Count > 0)
                    plan.Items.AddRange(result_2.Items);
 
 
                return new List<Model.AnaScheme>() { plan };
*/
 
 
            Common.DispatchAnaGeneralHelper扬程 calc_pipe1_helper
                = new Common.DispatchAnaGeneralHelper扬程();
 
            Common.DispatchAnaGeneralHelper扬程 calc_pipe2_helper
                = new Common.DispatchAnaGeneralHelper扬程();
 
            Common.DispatchAnaGeneralHelper扬程 calc_pipe3_helper
                = new Common.DispatchAnaGeneralHelper扬程();
 
 
            double totalQ = 0, totalH = 0, totalP = 0;
            int pipe_count = 0;
 
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe1_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe1_results = null;
            if (pipe1_TargetFlow > 50)
            {
                calc_pipe1_helper.InitialParas(
                pipe1_TargetFlow,
                pipe1_TargetHead,
              null, null,
             (from x in _allMachineList where pipe1_machineIds.Contains(x.MachineID) select x).ToList(),
            machine_run_status == null ? null : machine_run_status.MachineRunFilter);
                pipe1_results = calc_pipe1_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe1_results == null || pipe1_results.Count() == 0)
                {
                    error_info = String.Format("管路一调度方案无法计算,请确认数据是否合理,扬程要求:{0}m,流量要求:{1}",
                        pipe1_TargetHead, pipe1_TargetFlow);
                    return null;
                }
                pipe1_result = pipe1_results[0];
                totalQ += pipe1_result.TotalWrkQ;
                totalP += pipe1_result.TotalWrkP;
                totalH += pipe1_result.TotalWrkH;
                pipe_count++;
            }
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe2_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe2_results = null;
            if (pipe2_TargetFlow > 50)
            {
                calc_pipe2_helper.InitialParas(
                pipe2_TargetFlow,
                pipe2_TargetHead,
                null, null,
                (from x in _allMachineList where pipe2_machineIds.Contains(x.MachineID) select x).ToList(),
                machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                pipe2_results = calc_pipe2_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe2_results == null || pipe2_results.Count() == 0)
                {
                    error_info = String.Format("管路一调度方案无法计算,请确认数据是否合理,扬程要求:{0}m,流量要求:{1}",
                        pipe2_TargetHead, pipe1_TargetFlow);
                    return null;
                }
                pipe2_result = pipe2_results[0];
                totalQ += pipe2_result.TotalWrkQ;
                totalP += pipe2_result.TotalWrkP;
                totalH += pipe2_result.TotalWrkH;
                pipe_count++;
            }
 
            IStation.Calculation.DispatchAna.Model.AnaScheme pipe3_result = null;
            List<IStation.Calculation.DispatchAna.Model.AnaScheme> pipe3_results = null;
            if (pipe3_TargetFlow > 50)
            {
                calc_pipe3_helper.InitialParas(
                pipe3_TargetFlow,
                pipe3_TargetHead,
                null, null,
             (from x in _allMachineList where pipe3_machineIds.Contains(x.MachineID) select x).ToList(),
            machine_run_status == null ? null : machine_run_status.MachineRunFilter);
 
                pipe3_results = calc_pipe3_helper.CalcOptList(complex_request_paras.SchemeSortType, 3);
                if (pipe3_results == null || pipe3_results.Count() == 0)
                {
                    error_info = String.Format("管路一调度方案无法计算,请确认数据是否合理,扬程要求:{0}m,流量要求:{1}",
                        pipe3_TargetHead, pipe3_TargetFlow);
                    return null;
                }
                pipe3_result = pipe3_results[0];
                totalQ += pipe3_result.TotalWrkQ;
                totalP += pipe3_result.TotalWrkP;
                totalH += pipe3_result.TotalWrkH;
                pipe_count++;
            }
 
            var plan = new Model.AnaScheme();
            plan.ID = 1;
            plan.TotalWrkQ = Math.Round(totalQ, 1);
            plan.TotalWrkH = Math.Round(totalH / pipe_count, 2);
            plan.TotalWrkP = Math.Round(totalP, 1);
            plan.TotalWrkE = CalcConnectPipeEta(new List<AnaScheme>() { pipe1_result, pipe2_result, pipe3_result });
            plan.UWP = CalculateUWP(plan.TotalWrkP, plan.TotalWrkQ, plan.TotalWrkH);
            plan.WP = CalculateWP(plan.TotalWrkP, plan.TotalWrkQ);
 
            plan.Items = new List<Model.AnaSchemeItem>();
            if (pipe1_result.Items != null && pipe1_result.Items.Count > 0)
                plan.Items.AddRange(pipe1_result.Items);
            if (pipe2_result.Items != null && pipe2_result.Items.Count > 0)
                plan.Items.AddRange(pipe2_result.Items);
            if (pipe3_result.Items != null && pipe3_result.Items.Count > 0)
                plan.Items.AddRange(pipe3_result.Items);
 
 
            return new List<Model.AnaScheme>() { plan };
        }
 
 
        #endregion
 
 
 
 
    }
}