Commit ecb81bd90196bcf1ee548fa02d61ae5e75373c7e

Authored by NightIsDark
1 parent 2bd8e770

little modifly

cal_gate.c renamed to calc_gate.c
1 1 #include <stdio.h>
2 2 #include <stdlib.h>
3 3 #include <math.h>
4   -
5   -#include "cal_gate.h"
6   -
7   -
  4 +#include "calc_gate.h"
8 5  
9 6 typedef enum {
10   - gate_full_open_with_free_flow, /*A 闸门全开自由流*/
  7 + gate_full_open_with_free_flow = 0, /*A 闸门全开自由流*/
11 8 gate_full_open_with_submerged_flow, /*B 闸门全开淹没流*/
12 9 gate_control_with_free_flow, /*C 闸门控制自由流*/
13 10 gate_control_with_submerged_flow, /*D 闸门控制淹没流*/
... ... @@ -18,10 +15,9 @@ typedef enum {
18 15 }patterns_of_water;
19 16  
20 17 enum {
21   - NOTHINGNESS,
  18 + NOTHINGNESS = 0,
22 19 EXIST
23 20 };
24   -
25 21 enum{
26 22 warped_wingwall=1, /*弯曲墙面*/
27 23 flat_wingwall, /*平整墙面*/
... ... @@ -29,7 +25,7 @@ enum{
29 25 parallel_wingwall /*平行墙面*/
30 26 };
31 27  
32   -struct A{
  28 +struct warped_wingwall_para{
33 29 double m_warped_wingwall;
34 30 double m_warped_wingwall_ds;
35 31 double m_flat_wingwall;
... ... @@ -40,31 +36,15 @@ struct A{
40 36 double m_parallel_wingwall_ds;
41 37 };
42 38  
43   -
44   -struct B{
45   - double fai_warped_wingwall;
46   - //float m_warped_wingwall_ds;
47   - double fai_flat_wingwall;
48   - //float m_flat_wingwall_ds;
49   - double fai_eight_c_wingwall;
50   - //float m_eight_c_wingwall_ds;
51   - double fai_parallel_wingwall;
52   - //float m_parallel_wingwall_ds;
  39 +struct flat_wingwall_para{
  40 + double fai_warped_wingwall; //float m_warped_wingwall_ds;
  41 + double fai_flat_wingwall; //float m_flat_wingwall_ds;
  42 + double fai_eight_c_wingwall; //float m_eight_c_wingwall_ds;
  43 + double fai_parallel_wingwall; //float m_parallel_wingwall_ds;
53 44 };
54 45  
55 46  
56   -struct C{
57   - double miu_warped_wingwall;
58   - double miu_warped_wingwall_ds;
59   - double miu_flat_wingwall;
60   - double miu_flat_wingwall_ds;
61   - double miu_eight_c_wingwall;
62   - double miu_eight_c_wingwall_ds;
63   - double miu_parallel_wingwall;
64   - double miu_parallel_wingwall_ds;
65   -};
66   -
67   -struct D{
  47 +struct eight_c_wingwall_para{
68 48 double miu_warped_wingwall;
69 49 double miu_warped_wingwall_ds;
70 50 double miu_flat_wingwall;
... ... @@ -74,32 +54,23 @@ struct D{
74 54 double miu_parallel_wingwall;
75 55 double miu_parallel_wingwall_ds;
76 56 };
77   -
78   -
79 57 typedef struct total{
80   - struct A A;
81   - struct B B;
82   - struct C C;
83   - struct D D;
  58 + struct warped_wingwall_para A;
  59 + struct flat_wingwall_para B;
  60 + struct eight_c_wingwall_para C;
  61 + struct eight_c_wingwall_para D;
84 62 }coefficient_infor;
85 63  
86   -
87   -
88 64 /*
89 65 *几种墙面分别对应的系数
90 66 *
91 67 */
92   -coefficient_infor coefficient={.A.m_warped_wingwall=0.325, .A.m_warped_wingwall_ds=0.380, .A.m_flat_wingwall=0.310, .A.m_flat_wingwall_ds=0.365,\
93   - .A.m_eight_c_wingwall=0.330, .A.m_eight_c_wingwall_ds=0.390, .A.m_parallel_wingwall=0.295, .A.m_parallel_wingwall_ds=0.355,\
94   - .B.fai_warped_wingwall=0.850,.B.fai_flat_wingwall=0.825, .B.fai_eight_c_wingwall=0.860,.B.fai_parallel_wingwall=0.795,\
95   - .C.miu_warped_wingwall=0.60, .C.miu_warped_wingwall_ds=0.625,.C.miu_flat_wingwall=0.58, .C.miu_flat_wingwall_ds=0.60,\
96   - .C.miu_eight_c_wingwall=0.62,.C.miu_eight_c_wingwall_ds=0.64,.C.miu_parallel_wingwall=0.61,.C.miu_parallel_wingwall_ds=0.65,
97   - .D.miu_warped_wingwall=0.60, .D.miu_warped_wingwall_ds=0.625,.D.miu_flat_wingwall=0.60, .D.miu_flat_wingwall_ds=0.60,\
98   - .D.miu_eight_c_wingwall=0.64,.D.miu_eight_c_wingwall_ds=0.64,.D.miu_parallel_wingwall=0.63,.D.miu_parallel_wingwall_ds=0.65\
99   - };
100   -
101   -
102   -
  68 +const coefficient_infor coefficient={
  69 + {0.325, 0.380, 0.310, 0.365, 0.330, 0.390, 0.295, 0.355},
  70 + {0.85, 0.825, 0.860, 0.795},
  71 + {0.6, 0.625, 0.58, 0.60, 0.62, 0.64, 0.61, 0.65},
  72 + {0.6, 0.625, 0.6, 0.6, 0.64, 0.64, 0.63, 0.65}
  73 +};
103 74 /*
104 75 *函数名: data_validity_check()
105 76 *参数: *param
... ... @@ -107,38 +78,32 @@ coefficient_infor coefficient={.A.m_warped_wingwall=0.325, .A.m_warped_wingwall
107 78 *返回值: 0表示参数是合法的,非0表示不合法
108 79 *
109 80 */
110   -char data_validity_check(struct param_gate *param)
  81 +int data_validity_check(struct param_gate *param)
111 82 {
112   - if(param->wingwall <1 || param->wingwall>4){
113   - printf("Invalid parameter of wingwall\r\n");
114   - return 1;
  83 + if(param->wingwall <warped_wingwall || param->wingwall>parallel_wingwall){
  84 + return -1;
115 85 }
116   - if(param->drop_step <0 || param->drop_step >1){
117   - printf("Invalid parameter of drop_step\r\n");
118   - return 2;
  86 + if(!(param->drop_step = 0 || param->drop_step >1)){
  87 + return -1;
119 88 }
120   - if(param->openning_height_of_gate <0.0000001){
121   - printf("Invalid parameter of openning_height_of_gate\r\n");
122   - return 3;
  89 + if(param->openning_height_of_gate <-0.0000001){
  90 + return -1;
123 91 }
124   - if(param->water_depth_front_of_gate <0.0000001){
125   - printf("Invalid parameter of water_depth_front_of_gate\r\n");
126   - return 4;
  92 + if(param->water_depth_front_of_gate <-0.0000001){
  93 + return -1;
127 94 }
128   - if(param->water_depth_behind_of_gate <0.0000001){
129   - printf("Invalid parameter of water_depth_behind_of_gate\r\n");
130   - return 5;
  95 + if(param->water_depth_behind_of_gate <-0.0000001){
  96 + return -1;
131 97 }
132 98 if(param->gate_width <0.0000001){
133   - printf("Invalid parameter of gate_width\r\n");
134   - return 6;
  99 + return -1;
135 100 }
136 101 return 0;
137 102 }
138 103  
139 104 /*
140 105 *函数名: discrimination_of_flow_pattern()
141   - *参数: openning_height_of_gate 开闸高度
  106 + *参数: openning_height_of_gate 开闸高度
142 107 * water_depth_front_of_gate 闸前水位
143 108 * water_depth_behind_of_gate 闸后水位
144 109 * drop_step 跌槛
... ... @@ -150,7 +115,7 @@ char data_validity_check(struct param_gate *param)
150 115 patterns_of_water discrimination_of_flow_pattern(double openning_height_of_gate,double water_depth_front_of_gate,double water_depth_behind_of_gate,int drop_step)
151 116 {
152 117 if((openning_height_of_gate/water_depth_front_of_gate > 0.65) && (water_depth_behind_of_gate/water_depth_front_of_gate < 0.7)){
153   - if(drop_step == EXIST)
  118 + if(drop_step == EXIST)
154 119 return gate_full_open_with_free_flow_drop_step;
155 120 else
156 121 return gate_full_open_with_free_flow;
... ... @@ -178,16 +143,54 @@ struct datas{
178 143 double original_data_after;
179 144 double value;
180 145 };
181   -
182   -struct datas table[46]={{0.00,0.05,1.00},{0.05,0.15,0.990},{0.15,0.25,0.980},{0.25,0.35,0.970},{0.35,0.45,0.956},{0.45,0.475,0.947},{0.475,0.525,0.937},{0.525,0.575,0.925},\
183   - {0.575,0.625,0.907},{0.625,0.675,0.885},{0.675,0.710,0.856},{0.710,0.730,0.843},{0.730,0.750,0.828},{0.750,0.770,0.813},{0.770,0.790,0.800},{0.790,0.805,0.778},\
184   - {0.805,0.815,0.767},{0.815,0.825,0.755},{0.825,0.835,0.742},{0.835,0.845,0.728},{0.845,0.855,0.713},{0.855,0.865,0.698},{0.865,0.875,0.681},{0.875,0.885,0.662},\
185   - {0.885,0.895,0.642},{0.895,0.9025,0.621},{0.9025,0.9075,0.608},{0.9075,0.9125,0.595},{0.9125,0.9175,0.580},{0.9175,0.9225,0.565},{0.9225,0.9275,0.549},\
186   - {0.9275,0.9325,0.532},{0.9325,0.9375,0.514},{0.9375,0.9425,0.484},{0.9425,0.9475,0.473},{0.9475,0.9525,0.450},{0.9525,0.9575,0.427},{0.9575,0.9625,0.403},\
187   - {0.9625,0.9675,0.375},{0.9675,0.9725,0.344},{0.9725,0.9775,0.318},{0.9775,0.9825,0.267},{0.9825,0.9875,0.225},{0.9875,0.9925,0.175},{0.9925,0.9975,0.115},\
188   - {0.9975,1.0000,0.000}
  146 +const struct datas table[46]={
  147 + {0.00,0.05,1.00},
  148 + {0.05,0.15,0.990},
  149 + {0.15,0.25,0.980},
  150 + {0.25,0.35,0.970},
  151 + {0.35,0.45,0.956},
  152 + {0.45,0.475,0.947},
  153 + {0.475,0.525,0.937},
  154 + {0.525,0.575,0.925},
  155 + {0.575,0.625,0.907},
  156 + {0.625,0.675,0.885},
  157 + {0.675,0.710,0.856},
  158 + {0.710,0.730,0.843},
  159 + {0.730,0.750,0.828},
  160 + {0.750,0.770,0.813},
  161 + {0.770,0.790,0.800},
  162 + {0.790,0.805,0.778},
  163 + {0.805,0.815,0.767},
  164 + {0.815,0.825,0.755},
  165 + {0.825,0.835,0.742},
  166 + {0.835,0.845,0.728},
  167 + {0.845,0.855,0.713},
  168 + {0.855,0.865,0.698},
  169 + {0.865,0.875,0.681},
  170 + {0.875,0.885,0.662},
  171 + {0.885,0.895,0.642},
  172 + {0.895,0.9025,0.621},
  173 + {0.9025,0.9075,0.608},
  174 + {0.9075,0.9125,0.595},
  175 + {0.9125,0.9175,0.580},
  176 + {0.9175,0.9225,0.565},
  177 + {0.9225,0.9275,0.549},
  178 + {0.9275,0.9325,0.532},
  179 + {0.9325,0.9375,0.514},
  180 + {0.9375,0.9425,0.484},
  181 + {0.9425,0.9475,0.473},
  182 + {0.9475,0.9525,0.450},
  183 + {0.9525,0.9575,0.427},
  184 + {0.9575,0.9625,0.403},
  185 + {0.9625,0.9675,0.375},
  186 + {0.9675,0.9725,0.344},
  187 + {0.9725,0.9775,0.318},
  188 + {0.9775,0.9825,0.267},
  189 + {0.9825,0.9875,0.225},
  190 + {0.9875,0.9925,0.175},
  191 + {0.9925,0.9975,0.115},
  192 + {0.9975,1.0000,0.000}
189 193 };
190   -
191 194 double find(double target)
192 195 {
193 196 int i=0;
... ... @@ -210,15 +213,13 @@ double find(double target)
210 213 double get_coefficient_rou(double water_depth_front_of_gate,double water_depth_behind_of_gate)
211 214 {
212 215 double s;
213   -
214 216 s=water_depth_behind_of_gate/water_depth_front_of_gate;
215 217 return find(s);
216 218 }
217 219  
218   -
219 220 /*
220   - *函数名: cal_gate_full_open_with_free_flow()
221   - *参数: water_depth_front_of_gate 闸前水深
  221 + *函数名: cal_gate_full_open_with_free_flow()
  222 + *参数: water_depth_front_of_gate 闸前水深
222 223 * water_depth_behind_of_gate 闸后水深
223 224 * gate_width 闸门宽度
224 225 * wingwall 翼墙类型
... ... @@ -227,7 +228,6 @@ double get_coefficient_rou(double water_depth_front_of_gate,double water_depth_b
227 228 *返回值: 瞬时流量
228 229 *
229 230 */
230   -
231 231 double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double gate_width,int wingwall,int ds)
232 232 {
233 233 double instantaneousFlow;
... ... @@ -236,7 +236,7 @@ double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double
236 236 case warped_wingwall:
237 237 if(ds == EXIST)
238 238 instantaneousFlow=coefficient.A.m_warped_wingwall_ds*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate);
239   - else
  239 + else
240 240 instantaneousFlow=coefficient.A.m_warped_wingwall*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate);
241 241 break;
242 242 case flat_wingwall:
... ... @@ -262,8 +262,8 @@ double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double
262 262 }
263 263  
264 264 /*
265   - *函数名: cal_gate_full_open_with_submerged_flow()
266   - *参数: water_depth_front_of_gate 闸前水深
  265 + *函数名: cal_gate_full_open_with_submerged_flow()
  266 + *参数: water_depth_front_of_gate 闸前水深
267 267 * water_depth_behind_of_gate 闸后水深
268 268 * gate_width 闸门宽度
269 269 * wingwall 翼墙类型
... ... @@ -285,21 +285,21 @@ double cal_gate_full_open_with_submerged_flow(double water_depth_front_of_gate,d
285 285 instantaneousFlow=coefficient.B.fai_warped_wingwall*gate_width*water_depth_behind_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate));
286 286 break;
287 287 case flat_wingwall:
288   - if(ds == EXIST)
  288 + if(ds == EXIST)
289 289 instantaneousFlow=coefficient.B.fai_flat_wingwall*gate_width*get_coefficient_rou(water_depth_front_of_gate,water_depth_behind_of_gate)*water_depth_behind_of_gate\
290 290 *sqrt(2*g*water_depth_front_of_gate);
291 291 else
292 292 instantaneousFlow=coefficient.B.fai_flat_wingwall*gate_width*water_depth_behind_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate));
293 293 break;
294 294 case eight_c_wingwall:
295   - if(ds == EXIST)
  295 + if(ds == EXIST)
296 296 instantaneousFlow=coefficient.B.fai_eight_c_wingwall*gate_width*get_coefficient_rou(water_depth_front_of_gate,water_depth_behind_of_gate)*water_depth_behind_of_gate\
297 297 *sqrt(2*g*water_depth_front_of_gate);
298 298 else
299 299 instantaneousFlow=coefficient.B.fai_eight_c_wingwall*gate_width*water_depth_behind_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate));
300 300 break;
301 301 case parallel_wingwall:
302   - if(ds == EXIST)
  302 + if(ds == EXIST)
303 303 instantaneousFlow=coefficient.B.fai_parallel_wingwall*gate_width*get_coefficient_rou(water_depth_front_of_gate,water_depth_behind_of_gate)*water_depth_behind_of_gate\
304 304 *sqrt(2*g*water_depth_front_of_gate);
305 305 else
... ... @@ -310,8 +310,8 @@ double cal_gate_full_open_with_submerged_flow(double water_depth_front_of_gate,d
310 310 }
311 311  
312 312 /*
313   - *函数名: cal_gate_control_with_free_flow()
314   - *参数: water_depth_front_of_gate 闸前水深
  313 + *函数名: cal_gate_control_with_free_flow()
  314 + *参数: water_depth_front_of_gate 闸前水深
315 315 * water_depth_behind_of_gate 闸后水深
316 316 * height_of_gate 闸门开启高度
317 317 * gate_width 闸门宽度
... ... @@ -355,15 +355,15 @@ double cal_gate_control_with_free_flow(double water_depth_front_of_gate,double w
355 355 }
356 356  
357 357 /*
358   - *函数名: cal_gate_control_with_submerged_flow()
359   - *参数: water_depth_front_of_gate 闸前水深
  358 + *函数名: cal_gate_control_with_submerged_flow()
  359 + *参数: water_depth_front_of_gate 闸前水深
360 360 * water_depth_behind_of_gate 闸后水深
361 361 * height_of_gate 闸门开启高度
362 362 * gate_width 闸门宽度
363 363 * wingwall 翼墙类型
364 364 * ds 跌槛
365   - *功能: 根据参数,计算出闸门控制淹没流模型下的瞬时流量
366   - *返回值: 瞬时流量
  365 + *功能: 根据参数,计算出闸门控制淹没流模型下的瞬时流量
  366 + *返回值: 瞬时流量
367 367 *
368 368 */
369 369 double cal_gate_control_with_submerged_flow(double water_depth_front_of_gate,double water_depth_behind_of_gate,double height_of_gate,double gate_width,int wingwall,int ds)
... ... @@ -399,15 +399,9 @@ double cal_gate_control_with_submerged_flow(double water_depth_front_of_gate,dou
399 399 return instantaneousFlow;
400 400 }
401 401  
402   -
403   -
404   -
405   -
406   -
407   -
408 402 /*
409 403 *函数名: Calculation_of_InstantaneousFlow()
410   - *参数: *param 指向struct param_gate的指针
  404 + *参数: *param 指向struct param_gate的指针
411 405 *
412 406 *功能: 根据参数,计算出瞬时流量
413 407 *返回值: 瞬时流量
... ... @@ -416,10 +410,10 @@ double cal_gate_control_with_submerged_flow(double water_depth_front_of_gate,dou
416 410 int Calculation_of_InstantaneousFlow(double *value,struct param_gate *param)
417 411 {
418 412 patterns_of_water get_pattern;
419   -
  413 +
420 414 if(data_validity_check(param)!=0)
421 415 return -1;
422   -
  416 +
423 417 get_pattern = discrimination_of_flow_pattern(param->openning_height_of_gate,param->water_depth_front_of_gate,param->water_depth_behind_of_gate,param->drop_step);
424 418 switch(get_pattern){
425 419 case gate_full_open_with_free_flow:
... ...
cal_gate.h renamed to calc_gate.h
1   -#ifndef __CAL_GATE_H
2   -#define __CAL_GATE_H
  1 +#ifndef _CALC_GATE_H
  2 +#define _CALC_GATE_H
3 3  
4 4 #define g 9.81
5 5  
6 6 struct param_gate{
7 7 int wingwall;
8   - int drop_step;
  8 + int drop_step;
9 9 double openning_height_of_gate;
10 10 double water_depth_front_of_gate;
11 11 double water_depth_behind_of_gate;
12 12 double gate_width;
13 13 };
14 14  
15   -
16   -//double Calculation_of_InstantaneousFlow(double openning_height_of_gate, double water_depth_front_of_gate,double water_depth_behind_of_gate,double gate_width,int wingwall,int drop_step);
17 15 int Calculation_of_InstantaneousFlow(double *value,struct param_gate *param);
18 16  
19   -
20   -
21 17 #endif
... ...