Upload
shail-joshi
View
225
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Design Of Plug Flow reactor using vba and rk4 techniques.
Citation preview
C H G 3 3 3 1 D R A N D R E W S O W I N S K I
FractionalConversionofPackedBedReactorsolvedwithVBAShailJoshi(7282674)HusseinHaider(7534475)
Tuesday,December8th,2015
08Fall
1
ExecutiveSummary Thisreportexploresthedesignofapackedbedreactorthatisgovernedbya
systemofdifferentialequations,allofwhichrelatepressure,temperature,and
fractionalconversion.Fractionalconversionreferstothereactionthattakesplaceinside
thereactor;itisthemassormolarpercentageoftheinletreactantsthatconverttothe
products.Allthreeofthesegoverningparameters(referredtoasX,PandT)areagain
relatedtotheweightofthecatalystpresentinthereactor.
Giventhatthethreegoverningequationsaregiven,itisstandardengineering
practicetofirstmodeltheprocess-inthiscaseareactiontakingplaceinsideapacked-
bedreactor–toexplorethedynamicsofthesystem.Alotofthevariablesofthereactor
arefixed(suchastheinletconcentration,flowrate)asonlyonetypeofreactorisbeing
explored,howeverthecodeconstructedinVBAconsidersthesetobevariableswhose
valuesmaybechangedintheirrespectivecellstoproveforarobustfunction.And
buildingarobustcodeisoneoftheaimsofthisproject,aswillbeexploredinthe
relevantsectionsofthisreport.
Runge-Kutta4methodisusedtosolveforX,PandT.Preliminarilytowritingthe
codeinVBA,pseudo-codewaswrittenandavalidationsheetmade,asareferencefor
latercalculations.ThecodeinVBAwasthenslowlywrittenwithonemainfunction
callingonthethreefunctionsrelatingX,PandT,iteratinguntilthefinalvaluesofthese
threeparameterswerefoundwhenthetotalweightofthecatalystwasinsidethe
reactor.
Thecodewasbuilttoberobustanduser-friendly,alongwithgraphsintheexcel
sheetsothattheusercoulddeduceatwhichpointdidaddingmorecatalystweight
becomeinefficientinregardstoincreasingfractionalconversionofthereactants.
2
TableofContentsExecutiveSummary.....................................................................................................1
TableofContents.........................................................................................................2
Background..................................................................................................................3Runge-KuttaMethodsforODEs...........................................................................................................................5
Design..........................................................................................................................7FinalDesign...............................................................................................................................................................10
Validation..................................................................................................................11
ImprovementsandExtensions...................................................................................13
Conclusion.................................................................................................................14
Appendices................................................................................................................17Code..............................................................................................................................................................................17ListofTablesandFigures...................................................................................................................................19TaskAllocationSheet............................................................................................................................................20Shail..............................................................................................................................................................................20Hussein........................................................................................................................................................................20PersonalEthicsStatement..................................................................................................................................21SampleCalculations(stepsize0.1).................................................................................................................22References..................................................................................................................................................................24
3
Background
Theprojectinvolvesapackedbedreactorandahypotheticalfirstorder
reaction.Aschemicalengineersitisourtasktodeterminehowtooptimizethe
processsothatityieldsthehighestfractionalconversionandisstilleconomically
viable.Thefractionalconversion(X)ofthereactingspecies,basicallyrelatesthe
molesfedintothereactorwiththemolesreacted.Itisdefinedasfollows
𝑋 =𝑚𝑜𝑙𝑒𝑠 𝑟𝑒𝑎𝑐𝑡𝑒𝑑
𝑚𝑜𝑙𝑒𝑠 𝑓𝑒𝑑 𝑡𝑜 𝑟𝑒𝑎𝑐𝑡𝑜𝑟
Thefractionalconversionisdependentonthecatalystmass(W)asisthe
pressureandtemperatureofthereaction.Thusasystemof3-coupledordinary
differentialequationscanbeformedasfollows:
Where X is the conversion, W is the catalyst mass (kg), 𝐶!!is the initial
concentration of species A (mol/m^3), 𝐹!! is the initial molar flow rate of the species A,
k’ is the modified rate constant (m3/kg·s), 𝐸! is the activation energy (kJ/mol), R is the
gas constant (kJ/mol·K), ε is a parameter based on the difference of moles reacted and
produced, T is the temperature at a given point in the reactor (K), P is the pressure at a
given point of the reactor (Pa), α is a constant that is characteristic of the particle bed
properties (kg‐1), ΔHr is the heat of reaction (kJ/mol), and 𝐶! is the average head
capacity of the reactant and products (kJ/mol·K).
Alltheparametersoftheprocessaresummarizedbelow
4
Table1:TestParameters
To simplify the system of ODEs a dimensionless system will be used and
substituted into equations 1,2,3. This will make the general analysis of the system clearer
thus resulting in an easier application of Runge-Kutta. The dimensionless system is as
follows:
Where 𝑊! is the total mass of the catalyst. These diminsionaless parameters will
now be plugged back into equations 1,2,3. This results in the follwing equations:
5
Sinceitisunknownwhichcatalystweightwillyieldthehighestconversion,
themainaimforthisprojectwillbetodeterminewhatcatalystweightcorresponds
tohighestfractionalconversion,thusoptimizingtheprocess.UsingRunge-Kutta
methods,thefractionalconversion,pressureandtemperaturewillbedeterminedat
differentdimensionlesscatalystweightsfrom0to1.P(hat) and T(hat) will finally be
solved using runge kutta technique and graphed with respect to W(hat). Thenbasedon
theresultanoptimumcatalystweightwillbechosenthatissatisfactoryboth
economicallyandfromachemicalstandpoint.
Runge-KuttaMethodsforODEs
WidelyusedinengineeringmathematicsandotherdisciplinesRunge-Kutta
methodsaresomeofthemostcommon,simpleandrobustmethodstoapproaching
systemsofODEs.Runge-Kuttamethodsfallintoawidebranchofiterative
techniquesthatareimplicitandexplicit.Euler,Heun’sandMidpointmethodscanall
beclassifiedasRunge-Kuttatechniques.Howeverforthisprojectthemoreclassical
andexplicitRK4techniquewillbeused.
ThemainprocedureinRK4withnODEsisgivenbelow:
[10]
TheRK4methodusesfourkvaluestoreachafinalestimationofthevalueofa
certainvariable.Thesearereferredtointhefunctionask1,k2,k3andk4.Onceall
thekvaluesaredeterminedtheyaresimplysubstitutedintoequation10summed
andthefinalvaluefortheODEisdetermined.Thusthefirststepinusingthis
techniqueistocalculatethekconstants,theyaredefinedinliteraturebelow:
6
[11]
[12]
[13]
[14]
RK4isconsiderablymorepowerfulthanothertechniquessuchasEuler’sor
midpoint,andforthisreasonitconvergesfasteranddoesnotrequirealowstepsize
togetanaccurateanswer.HoweverthemaindrawbackwithRK4isthatitistime
consumingespeciallywhentherearelotsofsteps.Consequentlyitisalsoveryeasy
tomakeanerrorwhencalculatingbyhand,ifamistakeismadeearlyoninthe
initialcalculationthenitisoftencarriedthroughtherestoftheprocedureresulting
inanexponentialincreaseinerror.Thususeofaniterativeprogramsuchasexcel
minimizesthechanceorerrorandsubsequentlyreducesthecalculationtime.
HowevercreatinganRK4programusingVBAorsettingupanexcelsheetis
neverthelessconsiderablymorechallengingincomparisontoothermethods.This
projectusedRK4primarilyduetoitsefficiencyandeffectivenessinsolvingmultiple
ODEequations.
7
DesignThecodeconstructedwasbasedontheRunge-Kutta4thorder(RK4)method
tosolveasystemofdifferentialequations.Therearethreedimensionlessvariables;
X,P(hat)andT(hat),allofwhicharedifferentiatedwithrespectedtothesame
parameter,W(hat).Thefunctionsare:
Thesethreedifferentialequationsgovernthepropertiesofthepackedbed
reactor.SinceitissoughttosolveforthethreevaluesofX,P(hat),andT(hat)fora
certaintotalweightWt,theRK4methodwillbeusedforeachvariablewiththethree
functionsabove,andanoverallgoverningprocedurethatthecodewillbebasedon,
thiswillthecode’smainfunction.
Oncethesevaluesarecalculated,theyarethenusedtofindtheRK4estimate
forthevariable’snextvalue:
RK4estimate
Theseestimatesarecalculateduntilavalueisreached,orconvergeduntilthe
proportionalweightvalueW(hat)isequalto1,meaningthefullvalueofthetotal
weight.ThisistheentiretyoftheRK4method.Althoughitmayseemsimple,itis
quitetime-consumingifdonemanually,sincetheprocessmustberepeatedforeach
ofthethreevariablesX,P(hat)andT(hat).
Sincetheprocedureforcalculatingthenextestimationofeachofthethree
variablesfollowsthesameorder;thecodemustreflectthat.Itmustbeoneskeleton
forallthreevariables(andpossiblyanyothervariablethatwoulddefinethepacked
bedreactorsystem;ifadifferentgoverningfunctionshouldbespecifiedsimilarto
equations[7],[8],and[9]).Thisistheapproachthatthecodewasconstructedwith.
8
Firstoffthethreefunctionsareconstructedthatcorrespondtoequations[7],
[8]and[9]:Public Function dXdW(parameters As Range, X As Double, Ph As Double, Th As Double, wt As Double) As Variant
Dim Cao, Fao, k, e, a, Ea, Hr, Cp, X0, T0, P0 As Double
Cao = parameters(1, 1) Fao = parameters(2, 1) k = parameters(3, 1) e = parameters(4, 1) a = parameters(5, 1) Ea = parameters(6, 1) Hr = parameters(7, 1) Cp = parameters(8, 1) X0 = parameters(9, 1) T0 = parameters(10, 1) P0 = parameters(11, 1)
If Cao <= 0 Or Fao <= 0 Or Ea <= 0 Or T0 = 0 Or Cp = 0 Then dXdW = "PARAMETERS INVALID" Else dXdW = (Cao / Fao) * k * Exp(Ea * ((1 / T0) - (1 / (T0 * Th)))) * (1 - X) * Ph * wt / ((1 + (e * X)) * Th) End If End Function
Andtheremainingtwofunctionsfollowasimilarstructure,withtheir
correspondingequations:
dTdW = (Hr / Cp) * (Cao / Fao) * k * Exp(Ea * ((1 / T0) - (1 / (T0 * Th)))) * (1 - X) * (Ph * wt / ((1 + (e * X)) * T0 * Th)) dPdW = -(a / 2) * (1 + e * X) * (Th / Ph) * wt
Thesethreefunctionsaretobecalledupon,takinginthearrayofcellsthat
theusermaysimplyscrolloverintheExcelspreadsheet,checkingfirstthatnoneof
theinputcellsareinvalidvalues,andthencalculatingthefunctionvalueforthe
purposesoffindingaKoranestimationvalue.
Themainfunctionthenconstructsaforloopthatperformsaseriesof
calculationsforanumberoftimesdeemedno_of_steps,whichistheinverseofthe
stepsizeh,sincethisiswhatdetermineshowextensivelythecodewilliterate
estimationsfor(forexample,astepsizeofh=0.01willtake100steps).Itshouldalso
takeintheinitialestimatesofXi,Pi,Ti.Themainfunctionthenholdstheframe:Public Function RungeKutta(ByVal parameters As Range, ByVal h As Double, ByVal wt As Double, ByVal Xi As Double, ByVal Pi As Double, ByVal Ti As Double) As Variant
If wt < 0 Or h <= 0 Or dXdW(parameters, Xnew, Thnew, Phnew, w) = "PARAMETERS INVALID" Then
9
RungeKutta = "CHECK PARAMETERS" Else
For i = 1 To no_of_steps …………… …………… ……………… ……………… ……………… ……………… Next i
End If RungeKutta = Runge End Function
Theusercansimplyselectthearrayof11parameters,alongwithstepsize,
totalweightandinitialestimates.Insidetheloop,theRunge-Kutta4methodis
simply“translated”intocodeform:X = Xnew
Ph = Phnew Th = Thnew k1X = dXdW(parameters, X, Ph, Th, wt) k1P = dPdW(parameters, X, Ph, Th, wt) k1T = dTdW(parameters, X, Ph, Th, wt) X = Xnew + (k1X * 0.5 * h) Ph = Phnew + (k1P * 0.5 * h) Th = Thnew + (k1T * 0.5 * h)
AspertheRK4method,Kvaluesarecalculatedbycallinguponthethree
previouslydefinedfunctions.ThefirstK1valuesarecalculatedonlywiththeinitial
estimatesandthesubsequentKvaluesmusttakeinmodifiedestimates.Thesesteps
arefolloweduntilall4Kvaluesarecalculatedtothencalculatetheestimationsand
outputthemasathree-cellarrayinexcel:Xnew = Xnew + (h / 6) * (k1X + (2 * k2X) + (2 * k3X) + k4X) Thnew = Thnew + (h / 6) * (k1T + (2 * k2T) + (2 * k3T) + k4T) Phnew = Phnew + (h / 6) * (k1P + (2 * k2P) + (2 * k3P) + k4P) w = w + h Runge(i, 1) = Xnew Runge(i, 2) = Phnew Runge(i, 3) = Thnew
TheVBAcodeisthereforeasimpleone,followingthestructureand
procedureoftheRK4method.Itperformsaloopwithacontrollednumberof
iterations.ThethreefunctionsdXdW,dPdWanddTdWarecalleduponforeachK
value.Theusersimplyneedstoselecttheparameters,stepsize,weightandinitial
valuesofX,P(hat),T(hat)bydraggingandclickingontheappropriatecellsonly
onceandthecodefinishestherest.
10
WhengraphingthevaluesofX,P(hat),T(hat)obtainedbythethe
RungeKuttafunction,withrespecttoW(hat),itisapparentthatXconvergestoit’s
highestapproximatevaluenear1at0.65.Meaningthatreadingthetableinthe
“Design”taboftheexcelsheet,conversionXreaches0.99whentheproportion
W(hat)is0.65,or65%ofthetotalweight(inthiscase35kg).Anidealcatalyst
weightforthispackedbedreactoristherefor65%(35kg)=22.75kg.
FinalDesign
Theidealcatalystweightwasdeterminedbasedonallofthefractional
conversions,pressuresandtemperaturescalculatedintheexcelsheet.Froma
purelythermodynamicstandpointitwasseenthatincreasingcatalystweight
correspondedtoahigherfractionalconversionandtemperature.Pressure,onthe
otherhand,graduallydecreasedasweightwasincreased.
Thusthetotalcatalystweightof35kgyieldsthehighestamountofproduct.
Howeveritwasseenthattheincreaseinfractionalconversionwastrivialasthe
proportionalweightreachedthetotalweight.Thiscanbeseenonthegraphwhere
theconversionandtemperatureslinesleveloutafteraW(hat)ofabout50.Thisis
becauseitimpossibletohaveaconversionthatis100percentbasedon
thermodynamiclaws.Thereforeitwouldnotmakesensetobuy35kgofcatalystifit
onlyincreasesthefractionalconversionbyanegligibleamount.Inapackedbed
reactorthatisoperatingonamacro-scalethisdifferencewouldbeinfinitesimal.
Thusthefinalcatalystweightwaschosentobearound22.75kg.Thisweightyieldsa
conversionof99%ensuringahighfractionalyieldisobtainedwhilebeingas
economicalaspossible.Thetablebelowsummarizesthepressure,temperatureand
pressurethatcorrespondtoaweightof22.75kgTable2ChosenOperatingConditions
W(hat) X P(hat) T(hat)0.65 0.990098208 0.840611223 1.96259548
ERROR 0.1088% 0.4874% 0.0534%Weight X P(Pa) T(K)22.75kg 99% 85174.93 883.168
11
ValidationAseparateRK4wasdoneonthesystemwithoutusinganyprograming
techniquestocompareandvalidatethevaluesobtainedusingVBA.Averysmallstep
sizeof0.01wasusedtoensurethemethodwasasaccurateaspossible.Sinceno
programingwasusedthespreadsheetofthevalidationisconsiderablylargerthanthat
oftheVBA.Thisisbecausenumerouscolumnsandrowshadtousedinorderto
accommodatethesheernumberofvaluesandconstantsthatneededtobecalculated.
TheValidationvalueswerethencomparedwiththevaluesobtainedthroughVBA.This
wasdonetoensurethecodewasworkingandoutputtingthecorrectvalues.Asummary
ofthecomparisonissummarizedinthetablebelow:
Table3ComparisonsBetweenValidationandVBA
12
Initiallytheerrorwashighduetotheinitialguessfortheconversion,P(hat),and
T(hat).Howeverforthemajorityofcasesthedifferencebetweenthevalues
calculatedusingVBAandexcelisminute.Theerrorisalsoverysmalltherefore
confirmingthattheprogramisoutputtingcorrectvalues.
Ascanbeseenbelow,bothtechniquesyieldalmostanidenticalgraph:Figure1ComparisonsBetweenValidationandVBA
Additionallythecodeitselfwasdesignedtovalidateandeliminateanyusererrorduring
theentryofparameters.
If wt < 0 Or h <= 0 Or dXdW(parameters, Xnew,
Thnew, Phnew, w) = "PARAMETERS INVALID" Then
RungeKutta = "CHECK PARAMETERS"
Thisensuresthatusersdon’tentervaluesthatcantbephysicallyormathematically
possiblesuchasnegativevalues.
13
ImprovementsandExtensions Afterhavingcompletedtheproject,itwasclearthattherewasaminute
differencebetweentheresultsofthevalidationandthatofthecode.Asseeninthe
“Comparison”taboftheexcelfile:Table4ComparisonBetweenValidationandVBAatW(hat)1
Validation VBA ErrorW(hat) X P(hat) T(hat) X P(hat) T(hat) X P(hat) T(hat)
1 0.999778 0.6773 1.972 0.99976 0.68237 1.97199 0.0022% 0.7494% 0.0011%
Thediscrepancyofthevaluesobtainedbybothmethodsisnegligible,asseen
bytheerrorvaluescomparingthetwomethodsonthethreeright-mostcolumns.
ThegreatesterrorisintheP(hat)pressurevaluesatapproximately0.75%.
Nevertheless,extrastepscouldhavebeentakentoavoidthesediscrepancies.One
exampleisintegratingadaptivestepsizingintothecode.Thiswasinitiallyavoided
asitwasdeemedunnecessaryandaninefficientuseoftime,asitwouldrequirea
verycomplexmodificationtothecurrentcode.Howeverhavingdonethiscould’ve
improvedthecodebytakingstepsizesbasedonthedesirederrorinvaluesand
precisionofconvergence.Consequentlyitwouldhaveincreasedthecode’s
complexityconsiderablyandmadeitpossiblylessuserfriendly.Thustaking
uniformstepswasusedasitwassimpleranddidn’toutputabigerror.
Anideatoconsiderwhenitcomestoextendingtheprojectisthatconcerning
cost:asdesignengineersitisimportanttoconsiderthecostofmaterialsandthe
costofthereactor.AsthefractionalconversionXbeginstoconvergetoitsupper
limitataround65%ofthetotalweight(asseeninExcel).Assuchthecostperunit
weightofthematerialcouldbeintegratedintotheVBAcodeandthegraph’s
relatingXtoweightW(hat)toseethatatacertainpoint,spendingmoreonthe
catalystweightwillnotyieldasmuchreactionproduct
14
Conclusion
Inconclusiontheconversionanddimensionlesspressureandtemperature
weresolvedforthegivencatalystweightof35kg.Thecodewasrobustand
versatilesothatausercouldinputanydesiredweight,aswellmakechangestoany
ofthedifferentdependantparameters.Thevalidationwasdoneinsuchamanner
aswellsotheusercouldchangeanyofthegivenparameters.Thisensuresthatour
programandexcelsheetisadaptableandcanbeappliedonamultitudeof
situations.Makingitidealforuseinchemicalindustrywhereconstantsand
parametersneedtobeconstantlyvariedtoensurethesystemisasoperatingatits
peakefficiency.
Theexcelsheetwasdesignedtooutputgraphsoftheresultsthuschoosing
theidealoperatingconditionseasierandmakingtheoverallprogrammoreuser
friendly.Thefractionalconversion,dimensionlesspressureandtemperaturewere
plottedagainsttheproportionalweight(W(hat)).AscanbeseeninFigures1
through3thefractionalconversionincreaseswithW(hat)howeverafterabouta
W(hat)of0.5thefunctionstartstoleveloffasitapproachesitshorizontal
asymptoteof1.Thisisbecauseitischemicallyandphysicallyimpossibletohavea
conversiongreaterorequalto1.Asimilartrendwasseenwiththedimensionless
temperature,howeverthetemperatureapproachedahorizontalasymptoteof2.
Thissuggeststhereactionwasexothermicsinceanincreaseinproductsledtoa
highertemperature.Ascanbeseeninthegraphsbothconversionand
dimensionlesstemperatureoutputnearlyidenticallines,theonlydifferenceliesin
thelocationoftheasymptoteandthestartingpositionofthelines.The
dimensionlesspressureontheotherhandwasseentodecreasewithincreasing
catalystweightandincreasingconversion.Thissuggestsperhapsahighpressure
wouldholdthereactionback.Thustoshiftthereactionequilibriumtofavourthe
products,thepressurecouldbedecreasedinordertooptimizetheprocess.
Thegraphswereusedtodeterminetheidealcatalystweighttooptimizethe
process.Aweightof22.75kgwaschosenwhichcorrespondsW(hat)onthegraphs.
15
Thiswaschosenbecauseitwasseenthatafterthispointtheincreaseinconversion
wastrivial.Thusitdidnotmakesenseexpendingadditionalmoneyfor35kgof
catalystifyieldincreaseisinfinitesimal.Theoperatingconditionsofthisweightare
summarizedintable2shownbelow:
Table2:ChosenOperatingConditions
W(hat) X P(hat) T(hat)0.65 0.990098208 0.840611223 1.96259548
ERROR 0.1088% 0.4874% 0.0534%Weight X P(Pa) T(K)22.75kg 99% 85174.93 883.168
Chemicalengineersoperateinindustrytooptimizeprocessesboth
economicallyandchemically.Forthisreasontheseoperatingconditionswere
chosen.Thoughtheydonotyieldthehighestamountofproducttheyarethemost
idealwhencostofcatalystistakenintoaccount.Ascanbeseeninthetable,the
conversionisat99%thusyieldingahighproduct.Theerrorvaluesofallthree
parametersarealsosufficientlylowthereforemakingitsafetooperateunderthese
conditions.
TheresultscouldhavebeenimprovedbyusingahigherorderRunge-Kutta
technique;orbyusingadaptivestepsizinginthecode,buttheseweredeemed
unnecessarysincetheRK4methodthatwasimplementedoutputtedsatisfactory
valueswithlowerrors.
16
Figure2ValidationGraph
Figure3VBAGraph
17
Appendices
Code
18
19
ListofTablesandFiguresTable1:TestParameters.......................................................................................................................4Table2ChosenOperatingConditions............................................................................................10Table3ComparisonsBetweenValidationandVBA.................................................................11Table4ComparisonBetweenValidationandVBAatW(hat)1..........................................13Figure1ComparisonsBetweenValidationandVBA...............................................................12Figure2ValidationGraph....................................................................................................................16Figure3VBAGraph................................................................................................................................16
20
TaskAllocationSheetHusseinHaider(7534475)&ShailJoshi(7282674)
ShailSetuptheinitialexcelsheet,withequations,namingvariables,and
doingtheinitialvalidations.
WritescodefordX/dW,dP/dWaswellasstartedwritingthemain
Runge-Kuttacode.
Startedwritingreport.
HusseinHelpedmakethemainexcelsheetclearer.
WritescodefordT/dW,aswellashelpingwiththemainRunge-Kutta
code.
Implementingarrayandrangeoutputsinthecodewhereneeded,
makingthecodemoreefficient.
Willwriteanequalhalfofthefinalreport.
Whenwearedonewritingeachofourrespectivepartsofthereport,we
willgatherourVBAcodes,functionsandwrittenreportparts.Wewill
discussourfindings,combineourreports,peerrevieweachother’s
work,makingourreportsandcodesclearerandmoreefficient.Weplan
toholdregularbi-latstoupdateeachotherastoourprogress.
Wewillalsousethird-partyresources,suchasonlinetutorialsforVBA,
allofwhichwillbeproperlycitedaccordingtoUniversityofOttawa
standards.
21
PersonalEthicsStatement
7282674SHAIL JOSHI
HUSSEIN HAIDER
08/12/2015
7534475
08/12/2015
22
SampleCalculations(stepsize0.1)
23
24
ReferencesChapra,StevenC.,andRaymondP.Canale.NumericalMethodsforEngineers.6thed.Boston:McGraw-HillHigherEducation,2010.