0% found this document useful (0 votes)
846 views

Calling EPANET From Matlab

1) This document describes how to call EPANET (a hydraulic and water quality modeling software) functions from Matlab. 2) It recommends downloading a set of Matlab methods that provide an interface to EPANET's functions. 3) It provides an example code showing how to open an EPANET input file, run simulations, and retrieve results like node counts back in Matlab.

Uploaded by

marting69
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
846 views

Calling EPANET From Matlab

1) This document describes how to call EPANET (a hydraulic and water quality modeling software) functions from Matlab. 2) It recommends downloading a set of Matlab methods that provide an interface to EPANET's functions. 3) It provides an example code showing how to open an EPANET input file, run simulations, and retrieve results like node counts back in Matlab.

Uploaded by

marting69
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Calling EPANET from Matlab | Demetrios G.

Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

DemetriosG.Eliades 14aug08 About Theeasy these way ads touse (http://en.wordpress.com/about EPANET(http://www.epa.gov/nrmrl/wswrd/dw/epanet.html) theseads/) withMatlab,isto DOWNLOADthissetofMatlabmethods(http://goo.gl/uEN07). ThisisanenhancedmodiedversionoftheonesoriginallypostedbyPhilipJonkergouw (http://www.mathworks.com/matlabcentral/leexchange/loadFile.do?objectId=15502& objectType=FILE).Pleasecitetheauthorsofthecodesyouareentitledtomodifyandusethecodeas youwish. Usewithcaution,andverifythealgorithms.Incaseyoundbugs,haveanyremarksorneedextra information,pleasedonothesitatetocontact([email protected])me.ForEPANETquestionsyoucan alwaysrefertotheWaterSimulationForum(http://www.watersimulation.com/wsp/bb/). Inmoredetailnow,forlowerleverprogramming,therstthingonemustdoistoputepanet2.dll andepanet2.hinanewfolderandsetupMatlabtoworkwithinthatfolder.Thelibrarylescanbe importedinMatlabusingtheloadlibrary(http://www.mathworks.com/access/helpdesk/help/techdoc /index.html?/access/helpdesk/help/techdoc/ref/loadlibrary.html&http://www.google.com /search?q=loadlibrary++matlab&ie=utf8&oe=utf8&aq=t&rls=org.mozilla:enGB:ocial& client=refoxa)command.Toseethefunctionsincludedinthelibrary,usethelibfunctions (http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc /ref/libfunctions.html&http://www.google.com/search?q=libfunctions+matlab&ie=utf8&oe=utf 8&aq=t&rls=org.mozilla:enGB:ocial&client=refoxa)command.Forcallingamethod,usethecalllib (http://www.mathworks.com/access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc /ref/calllib.html&http://www.google.com/search?q=calllib++matlab&ie=utf8&oe=utf8&aq=t& rls=org.mozilla:enGB:ocial&client=refoxa)commandwiththesameargumentsasdescribedinthe toolkit.Whenyouhavereferencetopointers,youmustusethelibpointer(http://www.mathworks.com /access/helpdesk/help/techdoc/index.html?/access/helpdesk/help/techdoc/ref/libpointer.html&http: //www.google.com/search?q=libpointer+matlab&ie=utf8&oe=utf8&aq=t&rls=org.mozilla:en GB:ocial&client=refoxa)command. Examplecodeforusewithnet1.inpfromEPANETpackage:

1 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

%MATLABCODE%loadepanet2.dlland.h loadlibrary('epanet2','epanet2') %displaylibrary'sfunctions libfunctionsepanet2full %opennetworkfile,setoutputfileeg.net1.inp calllib('epanet2','ENopen','net1.inp','net1.txt',''); %runhydraulicsimulationandsaveinoutputfile calllib('epanet2','ENsolveH'); %runqualitysimulationsandsaveinoutputfile(afterENsolveH) calllib('epanet2','ENsolveQ'); %formethodswithpointers(returningvaluesinarguments)%setupapointerwithth nnodes=libpointer('int32Ptr',0); %callsthemethod calllib('epanet2','ENgetcount',0,nnodes); %returnsthevaluesstoredinthepointer get(nnodes,'Value'); %writeaformatedtextreportinoutputfile calllib('epanet2','ENreport'); %closetoolkit calllib('epanet2','ENclose'); %unloadlibrary unloadlibraryepanet2

Filedunder:Tools|

27Comments

FeedforthisEntry TrackbackAddress 1Hamidon25October,2008said: Hello atwhattimeaftertime0wecanndtherealchlorinequantity? howcanIdetermineglobalbalkcoecent?

2 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

howcanIshowandrunaninlinechlorinatorinEPANET? thismeanshowIcanmodellingchlorineinjectioninajunction? abotyourprograms: Mymainquastionistondnewpointtoinjectchlorineinordertosolvetheproblemofdead points,Ithinkthesolutionistoinjectchlorineinsomejunctions andthisjunctionsshouldbefondviageneticalgorithmmethod,thereforIshouldlinkEPANET withMATLABforthispurpose. yourprogramworkcorrectly! butIdontknowthatoutputs!!! Plaesehelpme. thanksinadvance Reply 2DemetriosEliadeson21August,2009said: Announcement: IhaveupdatedtheMatlablessothatiseasiertooperateEPANET.Youcandownloadthezipped folderwiththeMatlabcodefromhttp://bit.ly/gRzc Regards, Demetris Reply 3Mahdion27February,2010said: DearDemetris; Iusedsomefunctionofyour.mlesbuttherewasaproblem. WhenIusegetdata(En_nodcount)asbellow: m=getdata(EN_NODECOUNT); q=factorial(m); Ireceivethiserror: ???Errorusing==>factorialat17 Nmustbeamatrixofnonnegativeintegers. Icheckm.Thisvariableisanint32andhasanumericvalueof19foracertain.inple.Idont understandwhattheproblemis.Sofactorial(19)hasaresultbutq=factorial(m)hasnoresult. Couldyoupleasehelpmewhitthismatter? Imlookingforwardforyouranswer. Sincerely Mahdi Reply 4DemetriosEliadeson27February,2010said: Forsomereasonthefactorialmethodrequiresadoublenumber,thereforeyoucoulduse q=factorial(double(m)) demetris 5SHIBUA.on2April,2010said: Hi,CananybodyexpalinhowtolinkEpanet&Matlabwithsimpleexample.

3 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

Reply 6DemetriosEliadeson2April,2010said: Shibu,forusingEPANETandMatlab,youcouldtrythefollowing: 1.downloadandextractthetoolkitinhttp://www.mathworks.com/matlabcentral/leexchange /25100epanetmatlabtoolkit 2.RunmatlabandleopentheExample.m 3.PressF5 4.Inthecode,GETDATAisafunctiontocallEPANET,whichreturnsvariousparameters,such aspipeows,demands,qualitycharacteristics;SETDATAistochange/addcertainparameters inthenetwork. 5.YoucanndtheEN_XXXcodesintheEPANETToolkitReference,whichcanbefoundin http://env1.kangwon.ac.kr/aquatic/knowledge/soft/epanetdoc/toolkit_help.pdf d Reply 7SHIBUA.on12April,2010said: HiDemetriosEliades, Ihavetriedthemethod,butitisshowingsomeerror.Iwillbeverygratefultoyouifyoucan sendthematlabcodetoview/seethedata,toedit/changethedatainmatlabparticularlyfor thenetworkgiveninepanetexamples(Net1.net). Alsothematlabcodetorunthesimulation(snapshot)andalsoforextendedperiod simulation& toplotthetimeseriesplots tosavetheoutputtoaprticularle. Myemailid:[email protected] Expectingfavourablereplyattheearlist. Thankingyou, WithwarmRegards, Shibu Shibu 8minchuon15April,2011said: DearSir, IruntheExample.minMatlabasyourinstruction.ButIsawerrorslikethis: ???Errorusing==>loadlibraryat279 MicrosoftVisualC++2005or2008isrequiredtousethisfeature. Errorin==>epanetloadleat30 if~libisloaded(epanet2)loadlibrary(epanet2,epanet2.h);end Errorin==>Exampleat20 epanetloadle(wdsle); Idontknowhowtosolvethisproblem.So,pleasehelpmetounderstandthis. IuseMatlab7.11.0(R2010b)in64bitWindowns7. Thankyouinadvance. Sincerely, Minchu 9DemetriosEliadeson12April,2010said:
4 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

Shibu, Alltheinformationiswithintheleinthetoolkitlink.IamafraidIdonotunderstandwhere theproblemexists,basedonyourdescription,andIcannotgiveproperfeedbackuntilI understandwherestheproblem isshowingsomeerror:Canyoupleasetellbewhaterroritsays? Canyoupleasedescribethestepsyoutook? demetris Reply 10Haceneon10August,2010said: IwanttheresultsofpressureforsomenodeswiththeirID (Iwanttothankyouforyourhelp,youdonotknowhowyoudogood Reply [email protected],2010said: HelloMr.Eliades, MynameisBirhanu.IwastryingtocallEPANETinMatlabformyoptimizationmodelinwater distributionnetworkdesign.Iamtryingtocoupleoptimizationmodelwiththehydraulicsimulation model(EPANET).Theobjectiveistoselectasetofpipesizesandpressuregeneratingdevicesthat minimizesthetotalcost.Thedistributionnetworkwillbeusedfordrinkingwatersupply.Iwas wonderingifyourcodeishelpfultocallEPANETinMatlabanduseitforthepurposementioned above? Thankyou, Birhanu. Reply [email protected],2010said: IamgladIgureditout.Ihavetotellyou,youdidagreatjob.Yourcodehelpedmealot. Birhanu. Reply 13Ayoubon28September,2010said: hello Iusedthepointeroftheint32Prttypetohavethepressuresofanodewhoseindexisknown,butI receiveanerrormessagePointertypesmustmatchdatatype. myquestionis: doesthereexistarelationbetweenthetypeofpointerusedandthenatrueoftherequireddata (matrix,vector,singlevalue,)? iftheanswerisyes,whicharethevarioustypesofpointersusedforEPANET/MATLAB. Ithankyouinadvance. Reply 14masoumeon16January,2011said: deardemetris iwentlinkepanettomatlabforusinggeneticalgoright pleazeexplainmethodlinking tanks
5 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

Reply 15Dhafaron24July,2011said: Hi, First,thanksforyoureorttomakethiscodefreeforgeneraluse.Iamworkingonoptimizing WDS,andwillingtoknowhowtoreadpumppatternsandpassthemtothe.inpmodel?supposeI havethreepumpsandwillingtoimporttheirpatternseveryoptimizationiterationtothenetwork modeltocheckwhetherthenewpumpsschedulingarefeasibleornot?anykindsuggestion! Regards Reply 16Misuzyon9August,2011said: Youcansharewithmeoneexampleoftheapplicationwhichdochangeparameterssuchas diameters,pumpspeed,amongothers.Thankyouveryverymuch. Reply 17Xueweion17November,2011said: Iamstillworkingonthisproblem,haveyougureditout?Iamtryingtochangethepipesize duringtheloopofmyoptimizatioalgorithm,ButIhavenoideaabouthowtowirtetheINPle (tochangethepipesizeorotherparameters)duringeachloop,couldyousharesomeideawith [email protected] reallyappreciateit! Reply 18UpendranathBhupalon25August,2011said: Howdowemodelareservoirwithmultipleoutlets(likeinanaturaldraughtcoolingtower)in EPANET? Reply 19KennethMuniinaon6February,2012said: Hi, ItriedtheExample.minMatlabR2011binstalledonaWindows7(win64)system,andgotthe followingerror:Errorusingloadlibrary(line421)Therewasanerrorloadingthelibrary epanet2.dllisnotavalidWin32application. Meanwhile,IrunthesameleonaMatlabR2009binaWindows7(win32)system,thelewas compiledsuccessfully. AnysuggestionsIwanttousetheWindows7(win64)systemformylargemodellingwork. Thanks Kenneth Reply 20BrunoBrentanon14September,2012said: Hi, whenItrytocompilemyprogramm,Ireceiveamenssage: ???Errorusing==>loadlibraryat441 Buildingepanet2_thunk_pcwin64failed.Compileroutputis: clIC:\ProgramFiles\MATLAB\R2011a\extern\include/Zp8/W3
6 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

/D_CRT_SECURE_NO_DEPRECATE/D_SCL_SECURE_NO_DEPRECATE/D_SECURE_SCL=0 /nologo IF:\Epanet_Matlab_Toolkit\Epanet_Matlab_ToolkitIF:\Epanet_Matlab_Toolkit \Epanet_Matlab_Toolkitepanet2_thunk_pcwin64.cLDFeepanet2_thunk_pcwin64.dll epanet2_thunk_pcwin64.c epanet2_thunk_pcwin64.c(51):errorC2014:preprocessorcommandmuststartasrstnonwhite space epanet2_thunk_pcwin64.c(52):errorC2059:syntaxerror:{ epanet2_thunk_pcwin64.c(65):errorC2014:preprocessorcommandmuststartasrstnonwhite space Iuseapc64bitswithVisualStudio2008,IdownloadedtheSDKtools,andIcantstillcompilemy programm. Idontknowhowtosolvethisproblem,anybudycanhelpme? Thankyou!! Bruno Reply 21DemetriosEliadeson7December,2012said: Ibelieveyoushouldusethe64bitversionofepanet(http://epanet.de/developer/64bit.html.en) Reply 22Alecson22October,2012said: Hi, IsitpossibletouseEpanetwithSimulinktoolofMatlab? IhavetointroduceaPIDcontrolandIwouldliketorunEpanetinSimulinkandnotwithMatlab script.Isitpossible?How? Thankyou Reply 23DemetriosEliadeson7December,2012said: IhaventusedSimulinkformatlab,butissomethingIwilltrytoworkoninthefuture. Reply 24P.Sivakumaron2December,2012said: DearDemetriosEliadesSir, Iamusingyourepanet_matlabtoolkitfunctionforacoupleofdays,itisagreatserviceyoudid fortheentiretechnocratsandacademicianrelatedwithwaterdistributionnetworkproblem. Myqueriesareasfollows. #1.EPANETisworkingundertheprincipleDemandDrivenAnalysis(DDA)orFlowDependent Analysis(FDA).CanwedoPressureDrivenAnalysis(PDA)orPressureDrivenDemand(PDD)or HeadDependentAnalysis(HDA)withyourtoolkit,Ifyes,howtomodifythetoolkitfunction programmeinmatlables? #2.Forexample,Iwanttochangethenodeproperty(likeemitter)orlinkproperty(likeroughness) ofasimplenetworkwith7junctionnodes.Forthis,Ihavechangedtherequiredpropertiesininp. lefor7timesandload7inputlesintheconcerneddirectory. Icalleditinthematlablefor7timeswithwdsle=Net1.inp; epanetloadle(wdsle);
7 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

Itisnotthatmuchtediousforsimplenetwork.Butitisimpossibleforlargenetworks. Isthereanymethodorprogrammetomodifythechangingpropertywithsingleinputleforlarge networks? Iamexpectingyouradvise.WishyouaHappyChristmasandNewyear. Myemailid:[email protected]@gmail.com Thankingyousir P.Sivakumar Reply 25DemetriosEliadeson7December,2012said: HiSivakumar, 1.ItisnotpossibletorunPDF/PDD/HDAwiththistoolkit.Thisisonlypossiblethrough OOTEN(http://epanet.de/developer/ooten.html.en)orEPANETemitter (http://assela.pathirana.net/EPANETEmitter),howeverIhaventtestedanyofthat. 2.YoucanuseMATLABtomodifytheseparameters,insteadofloadinganewleeachtime. Forexample index=int32(index);%thelinkindex paramcode=int32(paramcode);%forroughness,paramcode=2.Pleasechecktheepanettoolkit helpleformoreinformation. value=single(value);%thenewroughnessvalue calllib(epanet2,ENsetlinkvalue,index,paramcode,value); Hopethesehelps Reply 26P.Sivakumaron19January,2013said: DearDemetriosEliadesSir, Thankyouforyourvaluablecommentsonmyearlierqueryintime. HowtolinkEPANETmatlabtoolkitwithoptimazationsolverslikeGA(ACO,PSO)andfuzzylogic (tocalculatetheuncertaintyproblemslikenodaldemands,piperoughnessetc.,withtriangularand trapezoidalmembershipfunction)? Iamexpectingyourearlyadvise. Thankyou withlove P.Sivakumar Reply 27P.Sivakumaron4February,2013said: DearDemetriosEliadesSir, IhadtrytochangetheNode/linkparameteraccordingtoyourreplyin2ndparagraphon7th December2012,Ihavegottheresult.

8 of 9

4/22/2013 6:08 PM

Calling EPANET from Matlab | Demetrios G. Eliades

http://eldemet.wordpress.com/2008/08/14/epanet-and-matlab/

ButIwanttochangethemorethanvenodes/linkswithasingleparameterlikeroughnessetc.,ata timeinsteadsinglenode/link. Isthereanymethodtosetmyproblem?Ifyes,pleaseadviseme. Thankyou, withwarmregards P.Sivakumar Reply

BlogatWordPress.com.Theme:UnsleepablebyBenGray.

9 of 9

4/22/2013 6:08 PM

You might also like