diff --git a/cal_gate.c b/calc_gate.c index e05e479..743b50e 100644 --- a/cal_gate.c +++ b/calc_gate.c @@ -1,13 +1,10 @@ #include #include #include - -#include "cal_gate.h" - - +#include "calc_gate.h" typedef enum { - gate_full_open_with_free_flow, /*A 闸门全开自由流*/ + gate_full_open_with_free_flow = 0, /*A 闸门全开自由流*/ gate_full_open_with_submerged_flow, /*B 闸门全开淹没流*/ gate_control_with_free_flow, /*C 闸门控制自由流*/ gate_control_with_submerged_flow, /*D 闸门控制淹没流*/ @@ -18,10 +15,9 @@ typedef enum { }patterns_of_water; enum { - NOTHINGNESS, + NOTHINGNESS = 0, EXIST }; - enum{ warped_wingwall=1, /*弯曲墙面*/ flat_wingwall, /*平整墙面*/ @@ -29,7 +25,7 @@ enum{ parallel_wingwall /*平行墙面*/ }; -struct A{ +struct warped_wingwall_para{ double m_warped_wingwall; double m_warped_wingwall_ds; double m_flat_wingwall; @@ -40,31 +36,15 @@ struct A{ double m_parallel_wingwall_ds; }; - -struct B{ - double fai_warped_wingwall; - //float m_warped_wingwall_ds; - double fai_flat_wingwall; - //float m_flat_wingwall_ds; - double fai_eight_c_wingwall; - //float m_eight_c_wingwall_ds; - double fai_parallel_wingwall; - //float m_parallel_wingwall_ds; +struct flat_wingwall_para{ + double fai_warped_wingwall; //float m_warped_wingwall_ds; + double fai_flat_wingwall; //float m_flat_wingwall_ds; + double fai_eight_c_wingwall; //float m_eight_c_wingwall_ds; + double fai_parallel_wingwall; //float m_parallel_wingwall_ds; }; -struct C{ - double miu_warped_wingwall; - double miu_warped_wingwall_ds; - double miu_flat_wingwall; - double miu_flat_wingwall_ds; - double miu_eight_c_wingwall; - double miu_eight_c_wingwall_ds; - double miu_parallel_wingwall; - double miu_parallel_wingwall_ds; -}; - -struct D{ +struct eight_c_wingwall_para{ double miu_warped_wingwall; double miu_warped_wingwall_ds; double miu_flat_wingwall; @@ -74,32 +54,23 @@ struct D{ double miu_parallel_wingwall; double miu_parallel_wingwall_ds; }; - - typedef struct total{ - struct A A; - struct B B; - struct C C; - struct D D; + struct warped_wingwall_para A; + struct flat_wingwall_para B; + struct eight_c_wingwall_para C; + struct eight_c_wingwall_para D; }coefficient_infor; - - /* *几种墙面分别对应的系数 * */ -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,\ - .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,\ - .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,\ - .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,\ - .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, - .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,\ - .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\ - }; - - - +const coefficient_infor coefficient={ + {0.325, 0.380, 0.310, 0.365, 0.330, 0.390, 0.295, 0.355}, + {0.85, 0.825, 0.860, 0.795}, + {0.6, 0.625, 0.58, 0.60, 0.62, 0.64, 0.61, 0.65}, + {0.6, 0.625, 0.6, 0.6, 0.64, 0.64, 0.63, 0.65} +}; /* *函数名: data_validity_check() *参数: *param @@ -107,38 +78,32 @@ coefficient_infor coefficient={.A.m_warped_wingwall=0.325, .A.m_warped_wingwall *返回值: 0表示参数是合法的,非0表示不合法 * */ -char data_validity_check(struct param_gate *param) +int data_validity_check(struct param_gate *param) { - if(param->wingwall <1 || param->wingwall>4){ - printf("Invalid parameter of wingwall\r\n"); - return 1; + if(param->wingwall wingwall>parallel_wingwall){ + return -1; } - if(param->drop_step <0 || param->drop_step >1){ - printf("Invalid parameter of drop_step\r\n"); - return 2; + if(!(param->drop_step = 0 || param->drop_step >1)){ + return -1; } - if(param->openning_height_of_gate <0.0000001){ - printf("Invalid parameter of openning_height_of_gate\r\n"); - return 3; + if(param->openning_height_of_gate <-0.0000001){ + return -1; } - if(param->water_depth_front_of_gate <0.0000001){ - printf("Invalid parameter of water_depth_front_of_gate\r\n"); - return 4; + if(param->water_depth_front_of_gate <-0.0000001){ + return -1; } - if(param->water_depth_behind_of_gate <0.0000001){ - printf("Invalid parameter of water_depth_behind_of_gate\r\n"); - return 5; + if(param->water_depth_behind_of_gate <-0.0000001){ + return -1; } if(param->gate_width <0.0000001){ - printf("Invalid parameter of gate_width\r\n"); - return 6; + return -1; } return 0; } /* *函数名: discrimination_of_flow_pattern() - *参数: openning_height_of_gate 开闸高度 + *参数: openning_height_of_gate 开闸高度 * water_depth_front_of_gate 闸前水位 * water_depth_behind_of_gate 闸后水位 * drop_step 跌槛 @@ -150,7 +115,7 @@ char data_validity_check(struct param_gate *param) 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) { if((openning_height_of_gate/water_depth_front_of_gate > 0.65) && (water_depth_behind_of_gate/water_depth_front_of_gate < 0.7)){ - if(drop_step == EXIST) + if(drop_step == EXIST) return gate_full_open_with_free_flow_drop_step; else return gate_full_open_with_free_flow; @@ -178,16 +143,54 @@ struct datas{ double original_data_after; double value; }; - -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},\ - {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},\ - {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},\ - {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},\ - {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},\ - {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},\ - {0.9975,1.0000,0.000} +const 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}, + {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}, + {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}, + {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}, + {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}, + {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}, + {0.9975,1.0000,0.000} }; - double find(double target) { int i=0; @@ -210,15 +213,13 @@ double find(double target) double get_coefficient_rou(double water_depth_front_of_gate,double water_depth_behind_of_gate) { double s; - s=water_depth_behind_of_gate/water_depth_front_of_gate; return find(s); } - /* - *函数名: cal_gate_full_open_with_free_flow() - *参数: water_depth_front_of_gate 闸前水深 + *函数名: cal_gate_full_open_with_free_flow() + *参数: water_depth_front_of_gate 闸前水深 * water_depth_behind_of_gate 闸后水深 * gate_width 闸门宽度 * wingwall 翼墙类型 @@ -227,7 +228,6 @@ double get_coefficient_rou(double water_depth_front_of_gate,double water_depth_b *返回值: 瞬时流量 * */ - double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double gate_width,int wingwall,int ds) { double instantaneousFlow; @@ -236,7 +236,7 @@ double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double case warped_wingwall: if(ds == EXIST) instantaneousFlow=coefficient.A.m_warped_wingwall_ds*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); - else + else instantaneousFlow=coefficient.A.m_warped_wingwall*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); break; case flat_wingwall: @@ -262,8 +262,8 @@ double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double } /* - *函数名: cal_gate_full_open_with_submerged_flow() - *参数: water_depth_front_of_gate 闸前水深 + *函数名: cal_gate_full_open_with_submerged_flow() + *参数: water_depth_front_of_gate 闸前水深 * water_depth_behind_of_gate 闸后水深 * gate_width 闸门宽度 * wingwall 翼墙类型 @@ -285,21 +285,21 @@ double cal_gate_full_open_with_submerged_flow(double water_depth_front_of_gate,d 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)); break; case flat_wingwall: - if(ds == EXIST) + if(ds == EXIST) 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\ *sqrt(2*g*water_depth_front_of_gate); else 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)); break; case eight_c_wingwall: - if(ds == EXIST) + if(ds == EXIST) 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\ *sqrt(2*g*water_depth_front_of_gate); else 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)); break; case parallel_wingwall: - if(ds == EXIST) + if(ds == EXIST) 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\ *sqrt(2*g*water_depth_front_of_gate); else @@ -310,8 +310,8 @@ double cal_gate_full_open_with_submerged_flow(double water_depth_front_of_gate,d } /* - *函数名: cal_gate_control_with_free_flow() - *参数: water_depth_front_of_gate 闸前水深 + *函数名: cal_gate_control_with_free_flow() + *参数: water_depth_front_of_gate 闸前水深 * water_depth_behind_of_gate 闸后水深 * height_of_gate 闸门开启高度 * gate_width 闸门宽度 @@ -355,15 +355,15 @@ double cal_gate_control_with_free_flow(double water_depth_front_of_gate,double w } /* - *函数名: cal_gate_control_with_submerged_flow() - *参数: water_depth_front_of_gate 闸前水深 + *函数名: cal_gate_control_with_submerged_flow() + *参数: water_depth_front_of_gate 闸前水深 * water_depth_behind_of_gate 闸后水深 * height_of_gate 闸门开启高度 * gate_width 闸门宽度 * wingwall 翼墙类型 * ds 跌槛 - *功能: 根据参数,计算出闸门控制淹没流模型下的瞬时流量 - *返回值: 瞬时流量 + *功能: 根据参数,计算出闸门控制淹没流模型下的瞬时流量 + *返回值: 瞬时流量 * */ 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 return instantaneousFlow; } - - - - - - /* *函数名: Calculation_of_InstantaneousFlow() - *参数: *param 指向struct param_gate的指针 + *参数: *param 指向struct param_gate的指针 * *功能: 根据参数,计算出瞬时流量 *返回值: 瞬时流量 @@ -416,10 +410,10 @@ double cal_gate_control_with_submerged_flow(double water_depth_front_of_gate,dou int Calculation_of_InstantaneousFlow(double *value,struct param_gate *param) { patterns_of_water get_pattern; - + if(data_validity_check(param)!=0) return -1; - + 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); switch(get_pattern){ case gate_full_open_with_free_flow: diff --git a/cal_gate.h b/calc_gate.h index e5e335d..540a7b8 100644 --- a/cal_gate.h +++ b/calc_gate.h @@ -1,21 +1,17 @@ -#ifndef __CAL_GATE_H -#define __CAL_GATE_H +#ifndef _CALC_GATE_H +#define _CALC_GATE_H #define g 9.81 struct param_gate{ int wingwall; - int drop_step; + int drop_step; double openning_height_of_gate; double water_depth_front_of_gate; double water_depth_behind_of_gate; double gate_width; }; - -//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); int Calculation_of_InstantaneousFlow(double *value,struct param_gate *param); - - #endif