You are on page 1of 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(eldemet@ucy.ac.cy)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:shibuiitb@yahoo.in 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 11b_mesn2002@yahoo.comon14September,2010said: HelloMr.Eliades, MynameisBirhanu.IwastryingtocallEPANETinMatlabformyoptimizationmodelinwater distributionnetworkdesign.Iamtryingtocoupleoptimizationmodelwiththehydraulicsimulation model(EPANET).Theobjectiveistoselectasetofpipesizesandpressuregeneratingdevicesthat minimizesthetotalcost.Thedistributionnetworkwillbeusedfordrinkingwatersupply.Iwas wonderingifyourcodeishelpfultocallEPANETinMatlabanduseitforthepurposementioned above? Thankyou, Birhanu. Reply 12b_mesn2002@yahoo.comon7October,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 me?myemailaddressisqixuewei@gmail.com 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:siva_nerist@yahoo.co.inandpsiva.nerist@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