You are on page 1of 13

Petrel TIPS&TRICKS from SCM

Knowledge Worth Sharing

TipsforWritingWorkflows
The Process Manager is the tool used to write workflows. A workflow manages Petrel processes
(hencethename),files,graphics,andparameters.Aworkflowcanexecutemanydozensor 100s of
steps without interruption. Using workflows allows you to document what you are doing and rerun
the steps when data or parameters change. Workflows allow users to build multiple models to test
uncertaintyaroundspecificparameters.Workflowsarethetoolsthatallowexperienceduserstoup
theirPetrelmodelingefficiencybyoneortwoordersofmagnitude.
Writing good workflows in Petrel requires that you set conventions and follow them whenever
possible. By this we mean that you use the same organization in each workflow, document
consistently and in the same way, use variables in an organized fashion, set up loops the same way
eachtime,managefileseffectively,andthelistgoeson.Thesearenotdifficultthingstodobutfor
those who do not write workflows or programs on a daily basis, their implementation may not be
obvious. This TIPS&TRICKS article describes several techniques that, when used, will let you write
betterqualityworkflowsfaster.
ThisTIPS&TRICKSarticleassumesthatyoualreadyknowhowtowriteaPetrelworkflow.Ifyoudont
know how, we suggest you take a one day Process Manager class to learn the syntax and basics of
workflowwriting.SCMhassuchaclassanditsscheduleisonourwebsite.Evenifyoudontknow
how to write a workflow, we feel you will gain a better understanding of what a workflow is from
readingthisarticle.

WorkflowTechniques
Thereareprobablyasmanyworkflowwritingtechniquesasthereareworkflowwriters.Wehave
selectedfivethatwefeelsignificantlyimprovethequalityofaworkflowandtheeaseofwritingand
usingit.Eachisdiscussedbelowwithexamples.

Organization
APetrelworkflowisaprogram.ManyoftheProcessManagertoolsareprogrammingtools.Youwill
needtolearntousethesetoolsinordertobeaneffectiveWorkflowwriter.Likeawellwritten
program,thewellwrittenworkflowshouldhaveasimpleorganizationthatiseasytofollow.The
approachthatweuseistoplaceallitemsthatwillchangeatthetopoftheworkflow;theInput
section.Thesearefollowedbycommandsthatinitializevariouspetrelwindowsandactions;the
Initializationsection.TheProcessingsectionisthethirdpartoftheworkflow.Generallythe
Processingsectionismuchlargerthantheothertwosections.Spacesandcommentsareusedto
separatethesectionsandtotelltheuserwhatisandisnottobechanged.Spacesandcommentsare
alsousedtomakealongworkfloweasiertoreadandtelltheuserwhatishappeningineachsection.
Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

Thefigurebelowshowsasimplebuteffectiveworkfloworganization.Version2010isthefirstPetrel
versiontohavelinenumbersintheworkflow.ThisisawelcomeadditiontotheProcessManager.
Figure:WorkflowshowingtheInput,Initialization,andProcessingsections(top)thefolderinputtothe
workflow(bottomleft)andthemessageswrittenbytheworkflow(bottomright).

VariableUsage
Definition
Iffilesarethepackagesthataremovedaroundbytheworkflowthenvariablesarethehandles
attachedtothepackages(files)thatallowtheworkflow(andyou)tograbandmovethem.Bylinkinga
variabletoafiletheneverytimethatfileisneededbytheworkflow,thevariableisusedtopointtoit.
Thishasahugeadvantagewhenbuildingaworkflowbecausethefileisonlyinputonceatthetopof
theworkflow.Atthattimeitislinkedtothevariable.Thenevenifthefilemustbeused5or100times
Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

intheworkflow,youhaveonlyhadtopointtothefileonce.Whenyouwanttopointtoadifferent
file,youdonthavetochange100locations,butratheronlythesingleinputlocation.
Figure:Twoworkflowsthatdothesamething.Theleftworkflowrequiresthatthegridnamebe
entered4timesandtherightworkflowrequiresonlyoneentry.

NameConventions
Variablesarethemessiestpartofmostworkflows.Normallythereisnoorganizationintheway
variablesareusedanditishardtofollowthelogic.True,youmustthinkinadistortedmanner(sortof
likeaprogrammer)whenusingvariables,butthereisnoreasonthethoughtprocesscantbe
somewhatorganized.Wefollowasimpleconventionwhenassigningvariablesinaworkflow.Forthe
inputfileswestartatthetopofthevariablelistanduseAforthefirstfile,Bforthesecondandsoon.
FortheassignmentofvariableswhenprocessingwestartatthebottomanduseAZforthefirst
processingassignment,AYforthenext,andsoon.Thiswaytheorganizationofthevariableshassome
meaninganditisalittleeasiertofollowthelogic.Also,whenyouarehalfwayfinishedwritingthe
workflowandrememberanotherinputfilethatisneeded,itcanbeassignedthenextletterinthe
variablelist.Thiskeepstheworkflowneatandorganized.Thisisparticularlyhelpfulinlongworkflows
sothatyoudonthavetogobackandtrytofindwhichvariableshaventbeenusedwhenyouneeda
newone.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

Figure:VariablesavailableforuseinaPetrelworkflow.NotethatvariablesAAthruAZareonly
availableinPetrel2010andlaterversions.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

Figure:WorkflowusingvariablesfromthetopofthevariablelistfortheInputfilesandfromthe
bottomofthelistfortheprocessingfiles.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

Figure:Displaycreatedbytheaboveworkflow(left),messageswrittenbytheworkflow(center),and
filescreatedbytheworkflow(right).

Documenting
NotethatforeachinputvariableassignmentthereisacommentlineinfrontoftheSetreferencestep.
Thatcommentlinesayswhatthevariablenameisandwhattypeoffileislinkedtoit.Italsotellsyouif
thefilewillbemodifiedbytheworkflow(e.g.,thefolderscontentswillbedeleted).Usingthese
commentsisahabityoushouldadopt.IfthefilelinkedtovariableAisdeleted,then,withoutthe
comment,thereisnowayyouwillknowwhatfiletorelinktowithoutstudyingthelogic.Oftenthe
logicissocomplexittakesalongtimetofigureitout.Thisproblemalsooccurswhenyoucopya
workflowfromonePetrelprojecttoanotheranddontalsocopythedata.
Figure:Fileexistinginleftworkflowandhavingbeendeletedinrightworkflow.Withthecomment
youknowwhatfilewassupposetobelinkedtovariableA.

Documentation
Documentationisakeycomponentofanyworkflow.Thelogicinworkflowscanquicklybecome
complex,therefore,youmustaddcommentssothat,whenyoureturntoyourworkflow6months
afteryouwriteit,youcanquicklydeterminewhatisbeingdone.Therearethreetoolsweuseto
commentworkflows,oneistheCommentline,anotheristheEmptyline,andthethirdthe
Messageline.TheCommentlineisjustthat,alinewithtextcomments.Itisusedthroughoutthe
workflowtodescribewhatishappening.Newuserstendtoputinacommentlineforeachstepand
theworkflowquicklybecomeshuge.SincethedevelopersofPetrelhavenotchosentoprovideaway
toprintaworkflow,multiplescreencapturesmustbeusedtosavetheworkflowtoaWorddocument
andthenthatisprinted.Iftheworkflowishugethisprintingbecomesevenmorepainful.Wetendto
statewhatishappeninginagroupofworkflowstepsusingjustoneortwocommentlines,thus,
Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

providingtheinformationbutkeepingtheworkflowlengthshorter.ACommentlineisalwaysused
infrontofaSetreferencelineasdescribedinthesectionabove.
Figure:Exampleofcommentlinesusedtoseparatemajorsectionsoftheworkflow.

Figure:Lines3536inthisworkflowareanexampleofonecommentdescribingseveralsteps.

Anotherformofdocumentationofvariablesthatmanyworkflowwritersuseistosummarizethe
variablesatthebottomoftheInputsection.Thissummaryisasetofcommentsdescribingtheuseof
allvariablesintheworkflow.Thissummaryaidsinknowingwhichvariablesareusedintheworkflow
(whethertheyaredescribedatthetoporthroughouttheworkflow).Ifnewvariablesareaddedtothe
workflow,theyneedtobeaddedtothissummary.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

Figure:Lines1319aretheVariableSummary

Emptylinesarekeytomakingtheworkflowreadable.Aworkflowshouldbetreatedlikeachapterin
abook.Itcontainsparagraphs,eachcoveringaspecifictopicandthoseparagraphsareseparatedone
fromanotherbyspaces.
Figure:Workflowwithnoemptylines(left)andwithemptylinesusedtomaketheworkflowreadable.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

MessagelinesaremeanttowriteinformationtothePetrelmessagelogsothatyouknowwhatis
happeningwhiletheworkflowruns.Ifamessagelineiscarefullywritten,itwillusuallyactasbotha
messageandacomment.Thesethenreducetheneedforsomeofyourcommentlines.Inalong
runningworkflow,messagesshouldbeusedtoinformyouoftheworkflowsprogress.
Figure:Line14isamessageusedbothtoinformabouttheWorkflowsactionsandasacommentline.

LoopManagement
Loopsareusedinwelloverhalfoftheworkflowsthatarewritten.Followingsimpleconventions
whenwritingloopswillmakethemeasiertounderstand,towrite,andtodecipher6monthsdownthe
road.Mostworkflowsloopoverfoldersofobjects.Thelooprunsasmanytimesasthereareobjects
ofaspecifictypeinthefolder.Becauseitisloopingoverobjectsitdoesnothaveacounterandyou
mustcreateacounter.ThisisdonewiththeNumericexpressionline.Beforethelooptheexpression
issetequalzero.Justafterthestartoftheloopitissettoitselfplus1.0.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.


Figure:Singleloopsetupwithcounterandmessagestatingwhatiterationtheloopison(top,line18)
andmessageloggeneratedbytheloop(bottom).

Manyloopsneedtobenested.Forexample,youmaywishtodisplayseveralisochoregridsalongwith
theirdataonapicture.Youneedtwoloops,oneoverthefolderofthicknessgridsandoneoverthe
folderofthicknessdata.Theloopsarenested,eachhasitsowncounter,andanIfstatementisused
totestthatthetwoloopsareatthesameiterationbeforedisplayingthepicture.Messagesareused
toreportwhatishappeningintheloops.Ofcourse,ifyouusethistechnique,thedatainthetwo
foldersmustbethesame.ItisusuallywisetoplacethedatainStratigraphicorder,shallowestto
deepest,tokeepobjectsinthesameorder.TheMessagecommandprintsoutwhichfilesarebeing
used.Youcanusethisprintouttoensurethecorrectfilesareusedeachtimethrutheloops.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

10

Figure:Nestedpairofloops(top,lines1722)andmessagesstatingwhatishappeningineachloop
(bottom).

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

11

FileManagement
Filemanagementisrequiredtomakeaworkflowruncorrectly.Awellwrittenworkflowcanberun
manytimeswiththecorrectanswereachtimeandwithnoduplicatefilesremaining.Thismeansthat
itdoesnotchangetheinputdatawhilerunning,itclearsoutpermanentfilesbeforeitrecreatesthem
thenexttimeitruns,itdeletestemporaryfilesbeforeitquits,anditclearsthemessagesanddisplaysit
createseitherattheendorwhenitisrestarted.Theworkflowspresentedinthispapermeetthese
criteria.
Ausefultechniqueinfilemanagementistocreateaworkfolderspecificallyfortheworkflowandto
placeallfilesthataretobekeptaftertheworkflowfinishesinthatfolder.Thefoldershouldexist
beforetheworkflowisrun(isnotcreatedbytheworkflow)anditscontentsarecleanedoutatthetop
oftheworkflowandrefilledastheworkflowexecutes.Afterafileiscreated,itismovedintothe
folder.Ifafileisnottobekept,itisnotmovedintothefolderbutinsteadisdeletedattheendofthe
workflow.
Figure:Portionofworkflowshowinguseofaworkfolder(linkedtoVariableC)thatiscleanedouteach
timetheworkflowisrun.

Figure:Portionofaworkflowshowingthecopytoafolder,naming,anduseofafile.

Ifaworkflowbombspartwaythruexecution,itwilloftenleavetemporaryfilesatthebottomofthe
inputtab.Ifyoucan,cleanupanypossibleleftoverfilesatthebeginningoftheworkflowexecution
beforegeneratingthemagain.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

12

Summary
Rememberthe5mainingredientstoagoodworkflow:
1. Organization
Placeallitemsthatwillchangeatthetopoftheworkflow
SeparateintoSectionsInput,Initialization,ProcessingandsplitProcessingintotasks
SeparateSectionswithemptylinesandcomments
2. VariableUsage
Defineallvariablesthatyoucanatthetopoftheworkflow
Assignallobjectsthatmaychangetovariables
Findanamingandusageconventionthatworksforyou.Inthispaper,westarted
namingallvariablesthatrepresentedPetrelobjectswithnamesfromthetopofthe
variablelist;(A,B,etc.).WenamedallvariablesthatweredefinedintheProcessing
areaoftheworkflowfromthebottomofthelist;(AZ,AY,etc.).
UseaCommenttoexplaineachvariablesuse
Optionally,useaVariableSummarysectiontoshowallvariablesused.
3. Documentation
UseComments,EmptylinesandMessagestotellaboutallvariablesandwhatthe
workflowisdoingineachsection.
4. LoopManagement
UseLoopstoperformthesameworkflowstepsoverdifferentfilesinafolder.
UseNumericexpressiontocountthenumberoftimesaloopisiterated
Ifloopsmustbenested,matchthecounterfromanouterlooptoaninnerloopto
performtheworkflowstepsonthecorrectobjectsinthefolders
UseaMessagecommandtoensurethecorrectfilesarebeingusedeachtimethruthe
loop.
5. FileManagement
Aworkflowshouldbeabletoberunmultipletimes(alwaysgivingthecorrectanswer)
withoutleavingextrafilesinPetrelsInputtab.
Useaworkfoldertokeeptrackoffilesgeneratedintheworkflow
Cleanouttheworkfolderatthebeginningoftheworkflow
Deleteanytemporaryfilescreatedbytheworkflowattheendoftheworkflow.

Usingthese5ingredientsinthesuggestedmannerswillhelpininitiallywritingaworkflowandkeeping
itsimpletounderstand.Itwillalsohelpifyouwroteaworkflowawhileagoandnowwantto
rememberwhatitdoesandpossiblymodifyit.Athirdwaythishelpsisifsomeoneelseneedsto
modifyaworkflowwrittenbyyou.Ifyouusedthesefiveingredientsproperlywhencreatingthe
workflow,itwillgreatlyspeedtheirunderstandingofacomplexworkflow.

Petrel is a mark of Schlumberger

4801 Woodway Drive, Suite 150W Houston, TX 77056 www.scminc.com info@scminc.com


2011 SCM E&P Solutions, Inc.

13

You might also like