首页专业论文技术应用政策标准解决方案常用资料经验交流教育培训企业技术专家访谈电力期刊
您现在的位置:北极星电力网 > 技术频道 > 专业论文 > 渠道水力计算在delphi上的实现(1)

渠道水力计算在delphi上的实现(1)

北极星电力网技术频道    作者:佚名   2008/1/16 18:16:53   

 关键词:  delphi 渠道 计算

摘要:渠道水力计算一直以来在渠道设计中就是一件烦琐的事情,因为其涉及到大量的试算工作,在水利工程灌溉渠系设计中常令人不胜其烦。为化繁为简,减少设计中的工作量,考虑使用计算机技术实现试算工作的程序化。我局正使用delphi编程技术进行管理信息系统(mis)的开发建设工作,故决定将其纳入mis系统建设中,成为本局mis系统的一部分。delphi技术是美国inprise公司开发的基于pascal语言的程序开发软件,其不仅在数据库编程方面有卓越表现,而且在数学计算中也成绩斐然。

关键词:水力计算delphi谢才系数流量模数业务服务器客户端

一、水力计算简介

将渠道内水流视作明渠均匀流这是渠道水力计算的前提,故计算公式采用明渠均匀流公式。主要任务是解决渠道的过水能力问题,即设计渠道的断面尺寸,以保证通过所需的流量,或校核渠道是否满足输水流量的要求等。总体而言,渠道水力计算的问题主要分两类:1、校核渠道过水能力;2、计算渠道的断面尺寸。

校核渠道的过水能力主要指在渠道的断面形式、尺寸、糙率、底坡等都已确定的情况下,计算其过水能力。计算步骤为:先根据水深h,底宽b及边坡系数m计算出过水断面面积ω、湿周χ、水力半径r。再根据糙率n及水力半径r计算(或查表)求出谢才系数c。最后用明渠均匀流公式q=ωc(ri)1/2计算出流量。

计算渠道的断面尺寸是渠系工程设计中遇到最多的问题。在规划设计新渠道时,设计流量由工程要求而定,坡度一般是由渠道大小根据地形条件确定,边坡系数m及糙率n,则由土质及渠壁材料与施工、管理运用等条件而定。也即已知q、m、n、i,求渠道的水深h及底宽b。此问题有两个未知数b及h,故须经过试算才能确定。计算步骤为:1、根据已知的流量q及渠道底坡i,求出流量模数k0(标准流量模数);2、初步假定一水深,计算其相应的过水断面ω、湿周χ、水力半径r,并根据糙率n及水力半径r计算或查表求出相应的谢才系数c值。然后,按公式k=ωcr1/2求出相应的流量模数值(设计流量模数);3、将计算出的设计流量模数与标准流量模数比较,若两者相等,则所设水深即为所求。若不等,则可另设一水深,重复上述步骤,直到计算出的设计流量模数与标准流量模数相等为止。然后经综合考虑各方面因素,如施工便利,防洪超高和其他用途后最终确定渠道断面尺寸。

二、delphi技术简介

delphi是由美国inprise公司(前borland公司)推出的可视化编程环境,它提供了一种方便、快捷的windows应用程序开发工具。delphi使用了microsoftwindows图形用户界面的许多先进特性和设计思想,采用了可重复利用的完整的面向对象程序语言(object-orientedlanguage)、当今世界上最快的编辑器、最为领先的数据库技术。delphi技术的基础源自pascal语言,是对pascal语言编程的可视化、面向对象化发展,从早期的对turbopascal的windows化到如今对网络化编程拥有强大功能,delphi已经升级到了如今的第七个版本,功能更加强大,对网络开发的需求更为适应,对数据库开发的技术更为成熟与稳定。

三、程序实现的方法

本程序作为我局管理信息系统(mis)的一部分外挂于我局管理信息系统的主界面上,属于水利常用计算模块。我局管理信息系统采用客户端、业务服务器、数据库管理系统(dbms)三级结构,客户端和业务服务器采用dephi开发实现,数据库管理系统(dbms)选择美国microsoft公司倍受业界好评的sqlserver2000。因此,本程序的数据计算、数据添加和数据删除功能以函数的形式建于业务服务器中,在客户端通过函数调用达到功能的实现。为实现数据的保存与查询,相应地在我局管理信息系统的业务数据库lsdata中建立一个数据库表watercalculationtable。客户端除实现业务服务器相关函数的调用外,还承担程序外观界面设置和部分简单功能的实现。用户只能通过程序客户端实现对软件的操作。

1、功能设计

本程序设计的主要目的在于实现对渠道水力计算的程序化和智能化,主要功能包括计算、成果显示、数据打印,另外为方便数据输入加入重置功能,为便于数据管理加入删除功能,另外为实现计算界面的退出而加入界面退出功能。

2、界面设计

为实现计算成果的显示功能在界面上添加一个dxdbgrid控件,作为成果显示的载体。为方便数据的录入和计算成果的单条显示添加十五个coastedit控件,为逐一说明各个coastedit控件代表的数据而增入十五个与之对应的label控件,为程序美观用一个groupbox将所有coastedit控件和label控件归为一组。为了实现计算、删除、重置、打印、退出功能,引入五个button控件其中计算按钮除在单击时触发计算功能外,在计算结束后自动执行数据添加功能,将计算数据添加入数据库中;删除按钮实现对库内单条数据的删除;重置按钮主要对coastedit控件中的数据进行清除,以利于新数据的输入;打印功能作用在于将计算所得的成果通过外接打印机打印出来;退出按钮的功能在于实现界面的退出,返回主界面。

程序界面中渠道名称、试算次序数、渠道底宽、渠道水深、渠道比降、边坡系数、渠道糙率、设计流量等数据可以手动输入,其他数据不能在界面上输入,由程序自动计算,并显示。根据渠道水力计算原理,可输入的数据除设计流量外均不允许为空,此外渠道糙率和渠道比降不能为零,出现上述情况,计算时程序将予以提示。

为实现程序的打印功能,特增加一打印界面,在点击打印按钮时自动弹出,打印界面可以实现打印、打印预览功能,在此界面可以调用windows打印程序。

具体界面设计图样见图1。

(图一)

3、数据库表设计

本程序只有一张库表,即渠道水力计算表(watercalculationtable),经过慎密的数据分析,设计该表共包含十五个字段,分别为:渠道名称、试算次序数、渠道宽度、渠道水深、渠道比降、边坡系数、设计流量、渠道糙率、湿周、标准流量模数、过水断面面积、水力半径、谢才系数、设计断面过水流量、设计流量模数。具体库表设计见表一:

渠道水力计算表(watercalculationtable)
表一

编号

中文名

字段名

数据类型

数据长度

可否为空

备注

1

渠道名称

ditchname

char

20

主键

2

试算次序数

calculationno

char

8

3

渠道底宽

ditchwidth

numer

8

4

渠道水深

ditchheight

numer

8

5

渠道比降

ditchslope

numer

8

6

边坡系数

slopenumer

numer

8

7

设计流量

planvolume

numer

8

8

渠道糙率

ditchrough

numer

8

9

湿周

xnumer

numer

12

10

标准流量模数

kstandard

numer

12

11

过水断面面积

flowarea

numer

12

12

水力半径

waterradius

numer

12

13

谢才系数

cnumer

numer

12

14

过水流量

designvolume

numer

12

15

设计流量模数

kdesign

numer

12

4、内置代码设计

内置代码主要是针对程序中相关控件触发的事件而设定的相应响应。本程序包含的事件主要有各button控件引发的单击事件、单击dxdbgrid控件引发的事件(dxdbgridclick)、数据集控件滚动事件(adodataset1afterscroll)和程序界面建立时的事件(formcreat)。另外,业务服务器(teoperationserver)中包含的两个函数addwatercalculation和deletewatercalculation也用程序代码建立。

各事件代码分别如下:

1)addwatercalculation函数,代码为:

functiontteoperationserver.addwatercalculation(

constditchname:widestring;ditchwidth,ditchheight,ditchslope,

slopenumer,ditchrough,planvolume:currency;

constcalculationno:widestring):longword;

var

strsql:string;

dwaffected:integer;

kstandard,flowarea,waterradius,cnumer,designvolume,kdesign,xnumer:currency;

begin

result:=makeresult(sev_error,facility_account,err_suc);

kstandard:=strtofloat(formatfloat(''0.00'',(planvolume/sqrt(ditchslope))));flowarea:=strtofloat(formatfloat(''0.00'',((ditchwidth slopenumer*ditchheight)*ditchheight)));xnumer:=strtofloat(formatfloat(''0.00'',(ditchwidth 2*ditchheight*sqrt(1 sqr(slopenumer)))));

waterradius:=strtofloat(formatfloat(''0.000'',(flowarea/xnumer)));cnumer:=strtofloat(formatfloat(''0.00'',(1/ditchrough*power(waterradius,1/6))));

kdesign:=strtofloat(formatfloat(''0.00'',(flowarea*cnumer*sqrt(waterradius))));designvolume:=strtofloat(formatfloat(''0.00'',(flowarea*cnumer*sqrt(waterradius*ditchslope))));

strsql:=''insertintowatercalculationtable(ditchname,ditchwidth,ditchheight,''

''ditchslope,slopenumer,planvolume,ditchrough,kstandard,''

''flowarea,waterradius,cnumer,designvolume,kdesign,xnumer,calculationno)''

''values('' '''''''' ditchname '''''',''

'''''''' floattostr(ditchwidth) '''''',''

'''''''' floattostr(ditchheight) '''''',''

'''''''' floattostr(ditchslope) '''''',''

'''''''' floattostr(slopenumer) '''''',''

'''''''' floattostr(planvolume) '''''',''

'''''''' floattostr(ditchrough) '''''',''

'''''''' floattostr(kstandard) '''''',''

'''''''' floattostr(flowarea) '''''',''

'''''''' floattostr(waterradius) '''''',''

'''''''' floattostr(cnumer) '''''',''

'''''''' floattostr(designvolume) '''''',''

'''''''' floattostr(kdesign) '''''',''

'''''''' floattostr(xnumer) '''''',''

'''''''' calculationno '''''')'';

executesql(strsql,@dwaffected);

ifdwaffected<=0then

begin

result:=makeresult(sev_error,facility_account,err_insert);

exit;

end;

end;

2)deletewatercalculation函数的代码为:

functiontteoperationserver.deletewatercalculation(constditchname,

calculationno:widestring):longword;

var

strsql:string;

dwaffected:integer;

begin

result:=makeresult(sev_error,facility_account,err_suc);

strsql:=''deletefromwatercalculationtable''

''whereditchname='' '''''''' ditchname ''''''''

''andcalculationno='' '''''''' calculationno '''''''';

executesql(strsql,@dwaffected);

ifdwaffected<0then

begin

result:=makeresult(sev_error,facility_account,err_delete);

exit;

end;

end;

3)计算按钮(button1click)的代码为:

proceduretformprice.button1click(sender:tobject);

var

resultcode:hresult;

begin

resultcode:=-1;

ifcoastedit1.text=''''then

begin

application.messagebox(''对不起,''''渠道名称''''不能为空.'',''提示'',mb_ok mb_iconwarning);

coastedit1.setfocus;

exit;

end;

ifcoastedit2.text=''''then

begin

application.messagebox(''对不起,''''渠道底宽'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit2.setfocus;

exit;

end;

ifcoastedit3.text=''''then

begin

application.messagebox(''对不起,''''渠道水深'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit3.setfocus;

exit;

end;

ifcoastedit4.text=''''then

begin

application.messagebox(''对不起,''''边坡系数'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit4.setfocus;

exit;

end;

ifcoastedit5.text=''''then

begin

application.messagebox(''对不起,''''渠道糙率'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit5.setfocus;

exit;

end;

ifcoastedit6.text=''''then

begin

application.messagebox(''对不起,''''渠道比降'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit6.setfocus;

exit;

end;

ifcoastedit15.text=''''then

begin

application.messagebox(''对不起,''''试算次序数'''',不能为空'',''提示'',mb_ok mb_iconwarning);

coastedit15.setfocus;

exit;

end;

ifcoastedit2.value=0then

begin

application.messagebox(''对不起,''''渠道底宽'''',不能为零'',''提示'',mb_ok mb_iconwarning);

coastedit2.setfocus;

exit;

end;

ifcoastedit3.value=0then

begin

application.messagebox(''对不起,''''渠道水深'''',不能为零'',''提示'',mb_ok mb_iconwarning);

coastedit3.setfocus;

exit;

end;

ifcoastedit6.value=0then

begin

application.messagebox(''对不起,''''渠道比降'''',不能为零'',''提示'',mb_ok mb_iconwarning);

coastedit6.setfocus;

exit;

end;

ifcoastedit5.value=0then

begin

application.messagebox(''对不起,''''渠道糙率'''',不能为零'',''提示'',mb_ok mb_iconwarning);

coastedit5.setfocus;

exit;

end;

try

teoperationserver.begintrans;resultcode:=teoperationserver.addwatercalculation(coastedit1.text,coastedit2.value,coastedit3.value,coastedit6.value,coastedit4.value,coastedit5.value,coastedit7.value,coastedit15.text);

finally

ifhresultcode(resultcode)=0then

begin

teoperationserver.commit;

refresh;

coastedit1.text:='''';

coastedit2.text:='''';

coastedit3.text:='''';

coastedit4.text:='''';

coastedit5.text:='''';

coastedit6.text:='''';

coastedit7.text:='''';

coastedit8.text:='''';

coastedit9.text:='''';

coastedit10.text:='''';

coastedit11.text:='''';

coastedit12.text:='''';

coastedit13.text:='''';

coastedit14.text:='''';

coastedit15.text:='''';

coastedit1.setfocus;

end

else

begin

teoperationserver.rollback;

application.messagebox(''添加失败'',''提示'',mb_ok mb_iconwarning);

coastedit1.setfocus;

end;

end;

end;

4)打印按钮(button2click)的代码为:

proceduretformprice.button2click(sender:tobject);

var

svdata:string;

iheader:integer;

iheaderobject:integer;

strsql:string;

recordset10:_recordset;

begin

svdatafile:=getparentdir(extractfilepath(paramstr(0))) ''datawatercalculation.txt'';

ppreport1.closedatapipelines;

ifhfile<>0thenfileclose(hfile);

iffileexists(svdatafile)then

deletefile(svdatafile);

hfile:=filecreate(svdatafile);

strsql:=''select*fromlsdata.dbo.watercalculationtable'';

svdata:=teoperationserver.resultstrorder(strsql);

filewrite(hfile,pointer(svdata)^,length(svdata));

fileclose(hfile);

pptextpipeline1.filename:=svdatafile;

ppreport1.datapipeline:=pptextpipeline1;

//处理表尾

ifppreport1.objectbyname(iheader,iheaderobject,''pplabel8'')then

tpplabel(ppreport1.bands[iheader].objects[iheaderobject]).caption:=fmainframeobject.operatorname;

withtfrmreportpreview1.create(self)do

try

ppviewer1.report:=ppreport1;

ppviewer1.firstpage;

show;

except

free;

end;

ppreport1.closedatapipelines;

fileclose(hfile);

end;

5)重置按钮(button5click)的代码为:

proceduretformprice.button5click(sender:tobject);

begin

coastedit1.text:='''';

coastedit2.text:='''';

coastedit3.text:='''';

coastedit4.text:='''';

coastedit5.text:='''';

coastedit6.text:='''';

coastedit7.text:='''';

coastedit8.text:='''';

coastedit9.text:='''';

coastedit10.text:='''';

coastedit11.text:='''';

coastedit12.text:='''';

coastedit13.text:='''';

coastedit14.text:='''';

coastedit15.text:='''';

end;

end.

6)删除按钮(button4click)的代码为:

proceduretformprice.button4click(sender:tobject);

var

resultcode:hresult;

begin

resultcode:=-1;

ifapplication.messagebox(''您确实要删除吗?'',''删除确认'',mb_yesno mb_iconwarning mb_defbutton2 mb_systemmodal)=idnothen

exit;

try

teoperationserver.begintrans;

resultcode:=teoperationserver.deletewatercalculation(coastedit1.text,coastedit15.text);

finally

ifhresultcode(resultcode)=0then

begin

application.messagebox(''删除成功'',''提示'',mb_ok mb_iconwarning);

teoperationserver.commit;

refresh;

coastedit1.text:='''';

coastedit2.text:='''';

coastedit3.text:='''';

coastedit4.text:='''';

coastedit5.text:='''';

coastedit6.text:='''';

coastedit7.text:='''';

coastedit8.text:='''';

coastedit9.text:='''';

coastedit10.text:='''';

coastedit11.text:='''';

coastedit12.text:='''';

coastedit13.text:='''';

coastedit14.text:='''';

coastedit15.text:='''';

end

else

begin

application.messagebox(''删除失败'',''提示'',mb_ok mb_iconwarning);

teoperationserver.rollback;

end;

end;

end;

7)退出按钮(button4click)的代码为:

proceduretformprice.button3click(sender:tobject);

begin

close;

end;

8)程序界面创建事件(formcreat)的代码为:

proceduretformprice.formcreate(sender:tobject);

var

strsql:string;

codestring1:string;

begin

teoperationserver:=getserver(''teoperationserver'');

refresh;

coastedit1.text:='''';

coastedit2.text:='''';

coastedit3.text:='''';

coastedit4.text:='''';

coastedit5.text:='''';

coastedit6.text:='''';

coastedit7.text:='''';

coastedit8.text:='''';

coastedit9.text:='''';

coastedit10.text:='''';

coastedit11.text:='''';

coastedit12.text:='''';

coastedit13.text:='''';

coastedit14.text:='''';

coastedit15.text:='''';

end;

9)单击dxdbgrid事件和数据集控件滚动事件的代码(两事件代码基本一样):

begin

if(adodataset1.recordset<>nil)and(adodataset1.recordcount>0)then

begin

coastedit1.text:=adodataset1.fields[0].value;

coastedit2.value:=adodataset1.fields[1].value;

coastedit3.value:=adodataset1.fields[2].value;

coastedit4.value:=adodataset1.fields[3].value;

coastedit5.value:=adodataset1.fields[4].value;

coastedit6.value:=adodataset1.fields[5].value;

coastedit7.value:=adodataset1.fields[6].value;

coastedit8.value:=adodataset1.fields[7].value;

coastedit9.value:=adodataset1.fields[8].value;

coastedit10.value:=adodataset1.fields[9].value;

coastedit11.value:=adodataset1.fields[10].value;

coastedit12.value:=adodataset1.fields[11].value;

coastedit13.value:=adodataset1.fields[12].value;

coastedit14.value:=adodataset1.fields[13].value;

coastedit15.text:=adodataset1.fields[14].value;

end;

10)refresh函数的代码为:

proceduretformprice.refresh;

var

strsql:string;

begin

strsql:=''select*fromwatercalculationtable'';

adodataset1.recordset:=vartorecordset(teoperationserver.query(strsql));

end;

四、程序最终成果

1)计算成果

点击“计算”按钮,则程序根据输入的已知值自动进行计算,并将计算所得以一条数据的形式,自动添加入数据库,并在dxdbgrid控件中显示出来。具体如图二

(图二)

2)打印成果

点击“打印”按钮,则程序自动弹出打印界面,从此可以预览计算成果,并完成打印功能。打印操作界面见图3。

(图三)

结束语

渠道水力计算作为水利工程中常遇到的问题尽管其计算难度不算高,但由于计算涉及多次试算,因而计算量大,且较为单调烦琐。但由于其计算步骤明确,没有过多的非公式化计算数据,故可以考虑用计算机代替人工手算。作为当前编程工具的一种优秀产品,delphi系列不仅在数据库开发上具有无以伦比的优越性,在数学计算中也同样具有强大的功能,其计算的精度,比起科学计算中常用的面向程序的开发语言fortran并不逊色。实践证明,水利工作中部分常用的程式化高的计算利用编程的方法将其计算机软件化,对于提高设计工作中的效率是大有裨益的。

来源:找论文网
友情链接
北极星工程招聘网北极星电气招聘网北极星火电招聘网北极星风电招聘网北极星水电招聘网北极星环保招聘网北极星光伏招聘网北极星节能招聘网招标信息分类电子资料百年建筑网PLC编程培训

广告直拨:   媒体合作/投稿:陈女士 13693626116

关于北极星 | 广告服务 | 会员服务 | 媒体报道 | 营销方案 | 成功案例 | 招聘服务 | 加入我们 | 网站地图 | 联系我们 | 排行

京ICP证080169号京ICP备09003304号-2京公网安备11010502034458号电子公告服务专项备案

网络文化经营许可证 [2019] 5229-579号广播电视节目制作经营许可证 (京) 字第13229号出版物经营许可证新出发京批字第直200384号人力资源服务许可证1101052014340号

Copyright © 2022 Bjx.com.cn All Rights Reserved. 北京火山动力网络技术有限公司 版权所有