diff --git b/README.txt a/README.txt new file mode 100644 index 0000000..c2d660a --- /dev/null +++ a/README.txt @@ -0,0 +1,20 @@ +函数:double Calculation_of_InstantaneousFlow(struct param_gate *datas) + +说明:传入的指向void类型的指针,被转换为指向struct param_gate这个结构体的指针 +struct param_gate{ + int wingwall; + int drop_step; + double openning_height_of_gate; + double water_depth_front_of_gate; + double water_depth_behind_of_gate; + double gate_width; +}; + +重要:且该指针指向的内存起始地址,存储的参数必须按照wingwall,drop_step,openning_height_of_gate,water_depth_front_of_gate,water_depth_behind_of_gate,gate_width;这个顺序存储!!! + +wingwall: 翼墙的类型 (扭面翼墙为1 平翼墙为2 八字翼墙为3 平行翼墙为4) +drop_step: 跌槛(根据现场施工状况决定, 有此参数为1,无则为0) +openning_height_of_gate: 闸门开启高度 +water_depth_front_of_gate: 闸前水位 +water_depth_behind_of_gate: 闸后水位 +gate_width: 闸门宽度 diff --git b/cal_gate.c a/cal_gate.c new file mode 100644 index 0000000..c67e360 --- /dev/null +++ a/cal_gate.c @@ -0,0 +1,533 @@ +#include +#include +#include + +#include "cal_gate.h" + + + +typedef enum { + gate_full_open_with_free_flow, /*A*/ + gate_full_open_with_submerged_flow, /*B*/ + gate_control_with_free_flow, /*C*/ + gate_control_with_submerged_flow, /*D*/ + gate_full_open_with_free_flow_drop_step, /*E*/ + gate_full_open_with_submerged_flow_drop_step, /*F*/ + gate_control_with_free_flow_drop_step, /*G*/ + gate_control_with_submerged_flow_drop_step /*H*/ +}patterns_of_water; + +enum { + NOTHINGNESS, + EXIST +}; + +enum{ + warped_wingwall=1, + flat_wingwall, + eight_c_wingwall, + parallel_wingwall +}; + +struct A{ + double m_warped_wingwall; + double m_warped_wingwall_ds; + double m_flat_wingwall; + double m_flat_wingwall_ds; + double m_eight_c_wingwall; + double m_eight_c_wingwall_ds; + double m_parallel_wingwall; + 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 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{ + 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; +}; + + +typedef struct total{ + struct A A; + struct B B; + struct C C; + struct D 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\ + }; + + + +/* + * + * + * + * + * +*/ +char 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->drop_step <0 || param->drop_step >1){ + printf("Invalid parameter of drop_step\r\n"); + return 2; + } + if(param->openning_height_of_gate <0.0000001){ + printf("Invalid parameter of openning_height_of_gate\r\n"); + return 3; + } + 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_behind_of_gate <0.0000001){ + printf("Invalid parameter of water_depth_behind_of_gate\r\n"); + return 5; + } + if(param->gate_width <0.0000001){ + printf("Invalid parameter of gate_width\r\n"); + return 6; + } + return 0; +} + +/* + * + * + * + * + * +*/ + +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) + return gate_full_open_with_free_flow_drop_step; + else + return gate_full_open_with_free_flow; + }else 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) + return gate_full_open_with_submerged_flow_drop_step; + else + return gate_full_open_with_submerged_flow; + }else if((openning_height_of_gate/water_depth_front_of_gate <= 0.65) && (water_depth_behind_of_gate < openning_height_of_gate)){ + if(drop_step == EXIST) + return gate_control_with_free_flow_drop_step; + else + return gate_control_with_free_flow; + }else if((water_depth_behind_of_gate > openning_height_of_gate)&& (water_depth_front_of_gate>openning_height_of_gate)){ + if(drop_step == EXIST) + return gate_control_with_submerged_flow_drop_step; + else + return gate_control_with_submerged_flow; + } +} + + + +/* + * + * + * + * + * +*/ +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; + + if(s>=0.00 && s<0.05) + return 1.00; + else if(s>=0.06 && s<0.15) + return 0.990; + else if(s>=0.15 && s<0.25) + return 0.980; + else if(s>=0.25 && s<0.35) + return 0.970; + else if(s>=0.35 && s<0.45) + return 0.956; + else if(s>=0.45 && s<0.475) + return 0.947; + else if(s>=0.475 && s<0.525) + return 0.937; + else if(s>=0.525 && s<0.575) + return 0.925; + else if(s>=0.575 && s<0.625) + return 0.907; + else if(s>=0.625 && s<0.675) + return 0.885; + else if(s>=0.675 && s<0.710) + return 0.856; + else if(s>=0.710 && s<0.730) + return 0.843; + else if(s>=0.730 && s<0.750) + return 0.828; + else if(s>=0.750 && s<0.770) + return 0.813; + else if(s>=0.770 && s<0.790) + return 0.800; + else if(s>=0.790 && s<0.805) + return 0.778; + else if(s>=0.805 && s<0.815) + return 0.767; + else if(s>=0.815 && s<0.825) + return 0.755; + else if(s>=0.825 && s<0.835) + return 0.742; + else if(s>=0.835 && s<0.845) + return 0.728; + else if(s>=0.845 && s<0.855) + return 0.713; + else if(s>=0.855 && s<0.865) + return 0.698; + else if(s>=0.865 && s<0.875) + return 0.681; + else if(s>=0.875 && s<0.885) + return 0.662; + else if(s>=0.885 && s<0.895) + return 0.642; + else if(s>=0.895 && s<0.9025) + return 0.621; + else if(s>=0.9025 && s<0.9075) + return 0.608; + else if(s>=0.9075 && s<0.9125) + return 0.595; + else if(s>=0.9125 && s<0.9175) + return 0.580; + else if(s>=0.9175 && s<0.9225) + return 0.565; + else if(s>=0.9225 && s<0.9275) + return 0.549; + else if(s>=0.9275 && s<0.9325) + return 0.532; + else if(s>=0.9325 && s<0.9375) + return 0.514; + else if(s>=0.9375 && s<0.9425) + return 0.484; + else if(s>=0.9425 && s<0.9475) + return 0.473; + else if(s>=0.9475 && s<0.9525) + return 0.450; + else if(s>=0.9525 && s<0.9575) + return 0.427; + else if(s>=0.9575 && s<0.9625) + return 0.403; + else if(s>=0.9625 && s<0.9675) + return 0.375; + else if(s>=0.9675 && s<0.9725) + return 0.344; + else if(s>=0.9725 && s<0.9775) + return 0.318; + else if(s>=0.9775 && s<0.9825) + return 0.267; + else if(s>=0.9825 && s<0.9875) + return 0.225; + else if(s>=0.9875 && s<0.9925) + return 0.175; + else if(s>=0.9925 && s<0.9975) + return 0.115; + else if(s>=0.9975 && s<1.000) + return 0.000; +} + + +/* + * + * + * + * + * +*/ + +double cal_gate_full_open_with_free_flow(double water_depth_front_of_gate,double gate_width,int wingwall,int ds) +{ + double instantaneousFlow; + + switch(wingwall){ + 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 + 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: + if(ds == EXIST) + instantaneousFlow=coefficient.A.m_flat_wingwall_ds*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + else + instantaneousFlow=coefficient.A.m_flat_wingwall*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + break; + case eight_c_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.A.m_eight_c_wingwall_ds*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + else + instantaneousFlow=coefficient.A.m_eight_c_wingwall*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + break; + case parallel_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.A.m_parallel_wingwall_ds*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + else + instantaneousFlow=coefficient.A.m_parallel_wingwall*gate_width*water_depth_front_of_gate*sqrt(2*g*water_depth_front_of_gate); + break; + } + return instantaneousFlow; +} + +double cal_gate_full_open_with_submerged_flow(double water_depth_front_of_gate,double water_depth_behind_of_gate,double gate_width,int wingwall,int ds) +{ + double instantaneousFlow; + + switch(wingwall){ + case warped_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.B.fai_warped_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_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) + 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) + 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) + 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 + instantaneousFlow=coefficient.B.fai_parallel_wingwall*gate_width*water_depth_behind_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + break; + } + return instantaneousFlow; +} + +double cal_gate_control_with_free_flow(double water_depth_front_of_gate,double water_depth_behind_of_gate,double height_of_gate,double gate_width,int wingwall,int ds) +{ + double instantaneousFlow; + + switch(wingwall){ + case warped_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.C.miu_warped_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.5*height_of_gate)); + else + instantaneousFlow=coefficient.C.miu_warped_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.65*height_of_gate)); + break; + case flat_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.C.miu_flat_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.5*height_of_gate)); + else + instantaneousFlow=coefficient.C.miu_flat_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.65*height_of_gate)); + break; + case eight_c_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.C.miu_eight_c_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.5*height_of_gate)); + else + instantaneousFlow=coefficient.C.miu_eight_c_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.65*height_of_gate)); + break; + case parallel_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.C.miu_parallel_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.5*height_of_gate)); + else + instantaneousFlow=coefficient.C.miu_parallel_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-0.65*height_of_gate)); + break; + } + return instantaneousFlow; +} + +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) +{ + double instantaneousFlow; + + switch(wingwall){ + case warped_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.D.miu_warped_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + else + instantaneousFlow=coefficient.D.miu_warped_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + break; + case flat_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.D.miu_flat_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + else + instantaneousFlow=coefficient.D.miu_flat_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + break; + case eight_c_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.D.miu_eight_c_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + else + instantaneousFlow=coefficient.D.miu_eight_c_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + break; + case parallel_wingwall: + if(ds == EXIST) + instantaneousFlow=coefficient.D.miu_parallel_wingwall_ds*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + else + instantaneousFlow=coefficient.D.miu_parallel_wingwall*gate_width*height_of_gate*sqrt(2*g*(water_depth_front_of_gate-water_depth_behind_of_gate)); + break; + } + return instantaneousFlow; +} + + +/* + * + * + * + * + * +*/ +#if 0 +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) +{ + patterns_of_water get_pattern; + double temp; + + get_pattern = discrimination_of_flow_pattern(openning_height_of_gate,water_depth_front_of_gate,water_depth_behind_of_gate,drop_step); + switch(get_pattern){ + case gate_full_open_with_free_flow: + temp = cal_gate_full_open_with_free_flow(water_depth_front_of_gate,gate_width,wingwall,drop_step); + break; + case gate_full_open_with_submerged_flow: + temp = cal_gate_full_open_with_submerged_flow(water_depth_front_of_gate,water_depth_behind_of_gate,gate_width,wingwall,drop_step); + break; + case gate_control_with_free_flow: + temp = cal_gate_control_with_free_flow(water_depth_front_of_gate,water_depth_behind_of_gate,openning_height_of_gate,gate_width,wingwall,drop_step); + break; + case gate_control_with_submerged_flow: + temp = cal_gate_control_with_submerged_flow(water_depth_front_of_gate,water_depth_behind_of_gate,openning_height_of_gate,gate_width,wingwall,drop_step); + break; + case gate_full_open_with_free_flow_drop_step: + temp = cal_gate_full_open_with_free_flow(water_depth_front_of_gate,gate_width,wingwall,drop_step); + break; + case gate_full_open_with_submerged_flow_drop_step: + temp = cal_gate_full_open_with_submerged_flow(water_depth_front_of_gate,water_depth_behind_of_gate,gate_width,wingwall,drop_step); + break; + case gate_control_with_free_flow_drop_step: + temp = cal_gate_control_with_free_flow(water_depth_front_of_gate,water_depth_behind_of_gate,openning_height_of_gate,gate_width,wingwall,drop_step); + break; + case gate_control_with_submerged_flow_drop_step: + temp = cal_gate_control_with_submerged_flow(water_depth_front_of_gate,water_depth_behind_of_gate,openning_height_of_gate,gate_width,wingwall,drop_step); + break; + } + return temp; +} +#endif + + + + +//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 +double Calculation_of_InstantaneousFlow(struct param_gate *param) +{ + patterns_of_water get_pattern; + + double temp; + + if(data_validity_check(param)!=0) + return 0; + + 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: + temp = cal_gate_full_open_with_free_flow(param->water_depth_front_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_full_open_with_submerged_flow: + temp = cal_gate_full_open_with_submerged_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_control_with_free_flow: + temp = cal_gate_control_with_free_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,\ + param->openning_height_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_control_with_submerged_flow: + temp = cal_gate_control_with_submerged_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,\ + param->openning_height_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_full_open_with_free_flow_drop_step: + temp = cal_gate_full_open_with_free_flow(param->water_depth_front_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_full_open_with_submerged_flow_drop_step: + temp = cal_gate_full_open_with_submerged_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_control_with_free_flow_drop_step: + temp = cal_gate_control_with_free_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,\ + param->openning_height_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + case gate_control_with_submerged_flow_drop_step: + temp = cal_gate_control_with_submerged_flow(param->water_depth_front_of_gate,param->water_depth_behind_of_gate,\ + param->openning_height_of_gate,param->gate_width,param->wingwall,param->drop_step); + break; + } + return temp; +} + + + + + + + + + + + + + + + + + + diff --git b/cal_gate.h a/cal_gate.h new file mode 100644 index 0000000..75d310b --- /dev/null +++ a/cal_gate.h @@ -0,0 +1,21 @@ +#ifndef __CAL_GATE_H +#define __CAL_GATE_H + +#define g 9.81 + +struct param_gate{ + int wingwall; + 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); +double Calculation_of_InstantaneousFlow(struct param_gate *param); + + + +#endif diff --git b/test a/test new file mode 100644 index 0000000..60d6a6b --- /dev/null +++ a/test diff --git b/test.c a/test.c new file mode 100644 index 0000000..6c154d6 --- /dev/null +++ a/test.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include "cal_gate.h" + + + +int main() +{ + void *param; + + param=malloc(40); + + *((int*)param)=1; + *((int*)param+1)=0; + *((double*)param+1)=5.0; + *((double*)param+2)=1.2; + *((double*)param+3)=0.1; + *((double*)param+4)=1.2; + + + + printf("For Test\r\n"); + + + printf("ins:%f\r\n",Calculation_of_InstantaneousFlow(param)); + //printf("ins:%f\r\n",Calculation_of_InstantaneousFlow(5,1.2,0.1,1.2,1,0)); + free(param); + return 0; +} + +