tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
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
 
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
 
namespace IStation.Calc
{
    internal partial class ErQuCalcBaseHelper
    {
        protected double _start_level水库水位;
   
 
        protected bool _isHaveLevelLimit = false;
        protected double  _min_level水库水位 = 0, _max_level水库水位 = 10000;
 
      
        protected List<double> _reservoirDropFlowList = null;//排水流量时间分配(万方)
        protected List<double?> _reservoirMinLimitHours = null;
        protected List<double?> _reservoirMaxLimitHours = null;
 
 
        protected bool Initial水库参数(IStation.CalcModel.AnaRequest anaRequest)
        { 
            //var list水库面积 = IStation.BLL.ReservoirHelper.GetList();
            //if (list水库面积 != null)
            //{
            //    _area水库面积 = list水库面积.First().Area; 
            //}
      
 
            this._reservoirDropFlowList = anaRequest.ReservoirDropFlow;
            this._reservoirMinLimitHours = anaRequest.ReservoirMinLimitHours;
            this._reservoirMaxLimitHours = anaRequest.ReservoirMaxLimitHours;
 
            return true;
        }
 
 
 
        /// <summary>
        /// 计算因用水,造成的水位下降
        /// </summary>
        private void CalcReservoirTimeData()
        { 
            if (this._reservoirDropFlowList == null ||
                this._reservoirDropFlowList.Count() == 0)
                return;
 
    
            var time_count = 60.0 / this._calcSpaceMinute; 
 
 
            int last_hour = _calStartTime.Hour;
            int inx_hour = 0; 
            double flowTotal = 0;
            int i = 0;
            double flow_space = _reservoirDropFlowList[0] / time_count;
            for (var time = _calStartTime; time < this._calEndTime; time = time.AddMinutes(this._calcSpaceMinute))
            { 
                if (time.Hour != last_hour)
                {
                    last_hour = time.Hour;
                    inx_hour++; 
                    if (inx_hour > _reservoirDropFlowList.Count)
                    {
                        flow_space = 0;
                    }
                    else
                    {
                        flow_space = _reservoirDropFlowList[inx_hour] / time_count;
                    }
                }
                if (time.Minute == 0)
                {
                    if (_reservoirMinLimitHours != null && _reservoirMinLimitHours[inx_hour] != null)
                    {
                        _timeList[i].ReservoirMinLevel = _reservoirMinLimitHours[inx_hour].Value;
                    }
                    if (_reservoirMaxLimitHours != null && _reservoirMaxLimitHours[inx_hour] != null)
                    {
                        _timeList[i].ReservoirMaxLevel = _reservoirMaxLimitHours[inx_hour].Value;
                    }
                }
 
                flowTotal = flowTotal + flow_space;
                _timeList[i+1].ReservoirDropFlowTotal = flowTotal * 10000;
                i++; 
            }
            if (_reservoirMinLimitHours != null && _reservoirMinLimitHours.Last() != null)
            {
                _timeList.Last().ReservoirMinLevel = _reservoirMinLimitHours.Last().Value;
            }
            if (_reservoirMaxLimitHours != null && _reservoirMaxLimitHours.Last() != null)
            {
                _timeList.Last().ReservoirMaxLevel = _reservoirMaxLimitHours.Last().Value;
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="time"></param>
        /// <param name="total_flow"></param>
        /// <param name="start_level"></param>
        protected double CalcReservoirHeight(
            int start_time_index,
            int end_time_index,
            double in_total_flow,
            double start_level)
        {
            if (start_time_index >= end_time_index)
            {
                return start_level;
            }
 
            double out_total_flow = GetReservoirDropFlowTotalByTimeIndex(end_time_index) -
                GetReservoirDropFlowTotalByTimeIndex(start_time_index);
 
            return IStation.AnaGlobalParas.CalcReservoirLevel(start_level, in_total_flow - out_total_flow);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="out_total_flow"></param>
        /// <param name="in_total_flow"></param>
        /// <param name="start_level"></param>
        /// <returns></returns>
        protected double CalcReservoirHeight(
             double out_total_flow,
             double in_total_flow,
             double start_level)
        {
            return IStation.AnaGlobalParas.CalcReservoirLevel(start_level, in_total_flow - out_total_flow);
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="start_level"></param>
        /// <param name="end_level"></param>
        /// <returns></returns>
        protected bool CheckReservoirHeight(double level)
        {
            if (level < this._min_level水库水位)
                return false;
            if (level > this._max_level水库水位)
                return false;
            //if (_reservoirLimitTimeIndexDict == null)
            //    return true;
 
            return true;
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="first_block"></param>
        /// <returns></returns>
        protected bool CheckReservoirHeightOnlyOne(RunBlock first_block)
        {
            double min_height = _start_level水库水位;
            min_height = Math.Min(min_height, first_block.ReservoirStartHeight);
            min_height = Math.Min(min_height, first_block.ReservoirEndHeight);
 
            double max_height = _start_level水库水位;
            max_height = Math.Max(max_height, first_block.ReservoirEndHeight);
            max_height = Math.Max(max_height, first_block.ReservoirEndHeight);
 
 
            var total_drop_flow = this._timeList.Last().ReservoirDropFlowTotal -
    this._timeList[first_block.EndIndx].ReservoirDropFlowTotal;
            var last_heigt = CalcReservoirHeight(total_drop_flow, 0,
                first_block.ReservoirEndHeight);
            min_height = Math.Min(min_height, last_heigt);
 
 
 
 
 
            bool isOk_min = false;
            if (min_height <= this._min_level水库水位)
                isOk_min = true;
 
            bool isOk_max = false;
            if (max_height >= this._max_level水库水位)
                isOk_max = true;
 
 
 
 
            if (isOk_max && isOk_min)
                return true;
            else
                return false;
        }
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="first_block"></param>
        /// <returns></returns>
        protected bool CheckReservoirHeight (double height1,double height2)
        { 
            if (Math.Min(height1, height2) > this._min_level水库水位)
                return false;
      
            if (Math.Max(height1, height2) < this._max_level水库水位)
                return false;
 
            return true;   
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="first_block"></param>
        /// <returns></returns>
        protected bool CheckReservoirHeight(double height1, double height2, double height3)
        {
            if (Min(height1, height2,height3) > this._min_level水库水位)
                return false;
 
            if (Max(height1, height2, height3) < this._max_level水库水位)
                return false;
 
            return true;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="v1"></param>
        /// <param name="v2"></param>
        /// <param name="v3"></param>
        /// <returns></returns>
        protected double Min(double v1,double v2,double v3)
        {
            double min = Math.Min(v1, v2);
            min = Math.Min(min,v3);
            return min;
        }
        protected double Max(double v1, double v2, double v3)
        {
            double max = Math.Max(v1, v2);
            max = Math.Max(max, v3);
            return max;
        }
    }
}