Sei sulla pagina 1di 25

Tuesday,

December 8th, 2015

Fractional Conversion of Packed Bed


Reactor solved with VBA
Shail Joshi (7282674)
Hussein Haider (7534475)

CHG3331 DR ANDREW SOWINSKI

Executive Summary

This report explores the design of a packed bed reactor that is governed by a

system of differential equations, all of which relate pressure, temperature, and


fractional conversion. Fractional conversion refers to the reaction that takes place inside
the reactor; it is the mass or molar percentage of the inlet reactants that convert to the
products. All three of these governing parameters (referred to as X, P and T) are again
related to the weight of the catalyst present in the reactor.

Given that the three governing equations are given, it is standard engineering

practice to first model the process - in this case a reaction taking place inside a packedbed reactor to explore the dynamics of the system. A lot of the variables of the reactor
are fixed (such as the inlet concentration, flow rate) as only one type of reactor is being
explored, however the code constructed in VBA considers these to be variables whose
values may be changed in their respective cells to prove for a robust function. And
building a robust code is one of the aims of this project, as will be explored in the
relevant sections of this report.

Runge-Kutta 4 method is used to solve for X, P and T. Preliminarily to writing the

code in VBA, pseudo-code was written and a validation sheet made, as a reference for
later calculations. The code in VBA was then slowly written with one main function
calling on the three functions relating X, P and T, iterating until the final values of these
three parameters were found when the total weight of the catalyst was inside the
reactor.

The code was built to be robust and user-friendly, along with graphs in the excel

sheet so that the user could deduce at which point did adding more catalyst weight
become inefficient in regards to increasing fractional conversion of the reactants.

Table of Contents
Executive Summary ..................................................................................................... 1
Table of Contents ......................................................................................................... 2
Background .................................................................................................................. 3
Runge-Kutta Methods for ODEs ........................................................................................................................... 5
Design .......................................................................................................................... 7
Final Design ............................................................................................................................................................... 10
Validation .................................................................................................................. 11
Improvements and Extensions ................................................................................... 13
Conclusion ................................................................................................................. 14
Appendices ................................................................................................................ 17
Code .............................................................................................................................................................................. 17
List of Tables and Figures ................................................................................................................................... 19
Task Allocation Sheet ............................................................................................................................................ 20
Shail .............................................................................................................................................................................. 20
Hussein ........................................................................................................................................................................ 20
Personal Ethics Statement .................................................................................................................................. 21
Sample Calculations (step size 0.1) ................................................................................................................. 22
References .................................................................................................................................................................. 24

Background

The project involves a packed bed reactor and a hypothetical first order
reaction. As chemical engineers it is our task to determine how to optimize the
process so that it yields the highest fractional conversion and is still economically
viable. The fractional conversion (X) of the reacting species, basically relates the
moles fed into the reactor with the moles reacted. It is defined as follows

=

The fractional conversion is dependent on the catalyst mass (W) as is the


pressure and temperature of the reaction. Thus a system of 3-coupled ordinary
differential equations can be formed as follows:


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/kgs), ! is the activation energy (kJ/mol), R is the
gas constant (kJ/molK), 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 (kg1), Hr is the heat of reaction (kJ/mol), and ! is the average head
capacity of the reactant and products (kJ/molK).
All the parameters of the process are summarized below


Table 1: Test Parameters


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:

Since it is unknown which catalyst weight will yield the highest conversion,
the main aim for this project will be to determine what catalyst weight corresponds
to highest fractional conversion, thus optimizing the process. Using Runge-Kutta
methods, the fractional conversion, pressure and temperature will be determined at
different dimensionless catalyst weights from 0 to 1. P(hat) and T(hat) will finally be
solved using runge kutta technique and graphed with respect to W(hat). Then based on
the result an optimum catalyst weight will be chosen that is satisfactory both
economically and from a chemical standpoint.

Runge-Kutta Methods for ODEs



Widely used in engineering mathematics and other disciplines Runge-Kutta
methods are some of the most common, simple and robust methods to approaching
systems of ODEs. Runge-Kutta methods fall into a wide branch of iterative
techniques that are implicit and explicit. Euler, Heuns and Midpoint methods can all
be classified as Runge-Kutta techniques. However for this project the more classical
and explicit RK4 technique will be used.
The main procedure in RK4 with n ODEs is given below:

[10]
The RK4 method uses four k values to reach a final estimation of the value of a
certain variable. These are referred to in the function as k1, k2, k3 and k4. Once all
the k values are determined they are simply substituted into equation 10 summed
and the final value for the ODE is determined. Thus the first step in using this
technique is to calculate the k constants, they are defined in literature below:

[11]



[12]



[13]



[14]

RK4 is considerably more powerful than other techniques such as Eulers or
midpoint, and for this reason it converges faster and does not require a low step size
to get an accurate answer. However the main drawback with RK4 is that it is time
consuming especially when there are lots of steps. Consequently it is also very easy
to make an error when calculating by hand, if a mistake is made early on in the
initial calculation then it is often carried through the rest of the procedure resulting
in an exponential increase in error. Thus use of an iterative program such as excel
minimizes the chance or error and subsequently reduces the calculation time.
However creating an RK4 program using VBA or setting up an excel sheet is
nevertheless considerably more challenging in comparison to other methods. This
project used RK4 primarily due to its efficiency and effectiveness in solving multiple
ODE equations.

Design

The code constructed was based on the Runge-Kutta 4th order (RK4) method

to solve a system of differential equations. There are three dimensionless variables;


X, P(hat) and T(hat), all of which are differentiated with respected to the same
parameter, W(hat). The functions are:


These three differential equations govern the properties of the packed bed

reactor. Since it is sought to solve for the three values of X, P(hat), and T(hat) for a
certain total weight Wt, the RK4 method will be used for each variable with the three
functions above, and an overall governing procedure that the code will be based on,
this will the codes main function.
Once these values are calculated, they are then used to find the RK4 estimate
for the variables next value:

RK4 estimate

These estimates are calculated until a value is reached, or converged until the
proportional weight value W(hat) is equal to 1, meaning the full value of the total
weight . This is the entirety of the RK4 method. Although it may seem simple, it is
quite time-consuming if done manually, since the process must be repeated for each
of the three variables X, P(hat) and T(hat).
Since the procedure for calculating the next estimation of each of the three
variables follows the same order; the code must reflect that. It must be one skeleton
for all three variables (and possibly any other variable that would define the packed
bed reactor system; if a different governing function should be specified similar to
equations [7], [8], and [9]). This is the approach that the code was constructed with.

First off the three functions are constructed that correspond to equations [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

And the remaining two functions follow a similar structure, with their
corresponding equations:

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

These three functions are to be called upon, taking in the array of cells that

the user may simply scroll over in the Excel spreadsheet, checking first that none of
the input cells are invalid values, and then calculating the function value for the
purposes of finding a K or an estimation value.

The main function then constructs a for loop that performs a series of

calculations for a number of times deemed no_of_steps, which is the inverse of the
step size h, since this is what determines how extensively the code will iterate
estimations for (for example, a step size of h=0.01 will take 100 steps). It should also
take in the initial estimates of Xi, Pi, Ti. The main function then holds the frame:
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

RungeKutta = "CHECK PARAMETERS"


Else
For i = 1 To no_of_steps

Next i
End If
RungeKutta = Runge
End Function

The user can simply select the array of 11 parameters, along with step size,

total weight and initial estimates. Inside the loop, the Runge-Kutta 4 method is
simply translated into code form:
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)

As per the RK4 method, K values are calculated by calling upon the three

previously defined functions. The first K1 values are calculated only with the initial
estimates and the subsequent K values must take in modified estimates. These steps
are followed until all 4 K values are calculated to then calculate the estimations and
output them as a three-cell array in excel:
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

The VBA code is therefore a simple one, following the structure and

procedure of the RK4 method. It performs a loop with a controlled number of


iterations. The three functions dXdW, dPdW and dTdW are called upon for each K
value. The user simply needs to select the parameters, step size, weight and initial
values of X, P(hat), T(hat) by dragging and clicking on the appropriate cells only
once and the code finishes the rest.

When graphing the values of X, P(hat), T(hat) obtained by the the

RungeKutta function, with respect to W(hat), it is apparent that X converges to its


highest approximate value near 1 at 0.65. Meaning that reading the table in the
Design tab of the excel sheet, conversion X reaches 0.99 when the proportion
W(hat) is 0.65, or 65% of the total weight (in this case 35kg). An ideal catalyst
weight for this packed bed reactor is therefor 65%(35kg) = 22.75kg.

Final Design

The ideal catalyst weight was determined based on all of the fractional
conversions, pressures and temperatures calculated in the excel sheet. From a
purely thermodynamic standpoint it was seen that increasing catalyst weight
corresponded to a higher fractional conversion and temperature. Pressure, on the
other hand, gradually decreased as weight was increased.

Thus the total catalyst weight of 35kg yields the highest amount of product.
However it was seen that the increase in fractional conversion was trivial as the
proportional weight reached the total weight. This can be seen on the graph where
the conversion and temperatures lines level out after a W(hat) of about 50. This is
because it impossible to have a conversion that is 100 percent based on
thermodynamic laws. Therefore it would not make sense to buy 35kg of catalyst if it
only increases the fractional conversion by a negligible amount. In a packed bed
reactor that is operating on a macro-scale this difference would be infinitesimal.
Thus the final catalyst weight was chosen to be around 22.75kg. This weight yields a
conversion of 99% ensuring a high fractional yield is obtained while being as
economical as possible. The table below summarizes the pressure, temperature and
pressure that correspond to a weight of 22.75kg
Table 2 Chosen Operating Conditions

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

10

Validation

A separate RK4 was done on the system without using any programing

techniques to compare and validate the values obtained using VBA. A very small step
size of 0.01 was used to ensure the method was as accurate as possible. Since no
programing was used the spreadsheet of the validation is considerably larger than that
of the VBA. This is because numerous columns and rows had to used in order to
accommodate the sheer number of values and constants that needed to be calculated.
The Validation values were then compared with the values obtained through VBA. This
was done to ensure the code was working and outputting the correct values. A summary
of the comparison is summarized in the table below:
Table 3 Comparisons Between Validation and VBA

11

Initially the error was high due to the initial guess for the conversion, P(hat), and
T(hat). However for the majority of cases the difference between the values
calculated using VBA and excel is minute. The error is also very small therefore
confirming that the program is outputting correct values.
As can be seen below, both techniques yield almost an identical graph:
Figure 1 Comparisons Between Validation and VBA


Additionally the code itself was designed to validate and eliminate any user error during
the entry of parameters.

If wt < 0 Or h <= 0 Or dXdW(parameters, Xnew,
Thnew, Phnew, w) = "PARAMETERS INVALID" Then
RungeKutta = "CHECK PARAMETERS"
This ensures that users dont enter values that cant be physically or mathematically
possible such as negative values.

12

Improvements and Extensions



After having completed the project, it was clear that there was a minute

difference between the results of the validation and that of the code. As seen in the
Comparison tab of the excel file:
Table 4 Comparison Between Validation and VBA at W(hat) 1


Validation
VBA
Error
W(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%

The discrepancy of the values obtained by both methods is negligible, as seen
by the error values comparing the two methods on the three right-most columns.
The greatest error is in the P(hat) pressure values at approximately 0.75%.
Nevertheless, extra steps could have been taken to avoid these discrepancies. One
example is integrating adaptive step sizing into the code. This was initially avoided
as it was deemed unnecessary and an inefficient use of time, as it would require a
very complex modification to the current code. However having done this couldve
improved the code by taking step sizes based on the desired error in values and
precision of convergence. Consequently it would have increased the codes
complexity considerably and made it possibly less user friendly. Thus taking
uniform steps was used as it was simpler and didnt output a big error.

An idea to consider when it comes to extending the project is that concerning

cost: as design engineers it is important to consider the cost of materials and the
cost of the reactor. As the fractional conversion X begins to converge to its upper
limit at around 65% of the total weight (as seen in Excel). As such the cost per unit
weight of the material could be integrated into the VBA code and the graphs
relating X to weight W(hat) to see that at a certain point, spending more on the
catalyst weight will not yield as much reaction product

13

Conclusion

In conclusion the conversion and dimensionless pressure and temperature


were solved for the given catalyst weight of 35 kg. The code was robust and
versatile so that a user could input any desired weight, as well make changes to any
of the different dependant parameters. The validation was done in such a manner
as well so the user could change any of the given parameters. This ensures that our
program and excel sheet is adaptable and can be applied on a multitude of
situations. Making it ideal for use in chemical industry where constants and
parameters need to be constantly varied to ensure the system is as operating at its
peak efficiency.


The excel sheet was designed to output graphs of the results thus choosing
the ideal operating conditions easier and making the overall program more user
friendly. The fractional conversion, dimensionless pressure and temperature were
plotted against the proportional weight (W(hat)). As can be seen in Figures 1
through 3 the fractional conversion increases with W(hat) however after about a
W(hat) of 0.5 the function starts to level off as it approaches its horizontal
asymptote of 1. This is because it is chemically and physically impossible to have a
conversion greater or equal to 1. A similar trend was seen with the dimensionless
temperature, however the temperature approached a horizontal asymptote of 2.
This suggests the reaction was exothermic since an increase in products led to a
higher temperature. As can be seen in the graphs both conversion and
dimensionless temperature output nearly identical lines, the only difference lies in
the location of the asymptote and the starting position of the lines. The
dimensionless pressure on the other hand was seen to decrease with increasing
catalyst weight and increasing conversion. This suggests perhaps a high pressure
would hold the reaction back. Thus to shift the reaction equilibrium to favour the
products, the pressure could be decreased in order to optimize the process.
The graphs were used to determine the ideal catalyst weight to optimize the
process. A weight of 22.75 kg was chosen which corresponds W(hat) on the graphs.

14

This was chosen because it was seen that after this point the increase in conversion
was trivial. Thus it did not make sense expending additional money for 35kg of
catalyst if yield increase is infinitesimal. The operating conditions of this weight are
summarized in table 2 shown below:
Table 2: Chosen Operating Conditions

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
Chemical engineers operate in industry to optimize processes both

economically and chemically. For this reason these operating conditions were
chosen. Though they do not yield the highest amount of product they are the most
ideal when cost of catalyst is taken into account. As can be seen in the table, the
conversion is at 99% thus yielding a high product. The error values of all three
parameters are also sufficiently low therefore making it safe to operate under these
conditions.

The results could have been improved by using a higher order Runge-Kutta

technique; or by using adaptive step sizing in the code, but these were deemed
unnecessary since the RK4 method that was implemented outputted satisfactory
values with low errors.









15

Figure 2 Validation Graph


Figure 3 VBA Graph

16

Appendices
Code

17

18

List of Tables and Figures



Table 1: Test Parameters ....................................................................................................................... 4
Table 2 Chosen Operating Conditions ............................................................................................ 10
Table 3 Comparisons Between Validation and VBA ................................................................. 11
Table 4 Comparison Between Validation and VBA at W(hat) 1 .......................................... 13

Figure 1 Comparisons Between Validation and VBA ............................................................... 12
Figure 2 Validation Graph .................................................................................................................... 16
Figure 3 VBA Graph ................................................................................................................................ 16


19

Task Allocation Sheet

Hussein Haider (7534475) & Shail Joshi (7282674)



Shail

Set up the initial excel sheet, with equations, naming variables, and
doing the initial validations.
Writes code for dX/dW, dP/dW as well as started writing the main
Runge-Kutta code.
Started writing report.

Hussein

Helped make the main excel sheet clearer.


Writes code for dT/dW, as well as helping with the main Runge-Kutta
code.
Implementing array and range outputs in the code where needed,
making the code more efficient.
Will write an equal half of the final report.

When we are done writing each of our respective parts of the report, we
will gather our VBA codes, functions and written report parts. We will
discuss our findings, combine our reports, peer review each others
work, making our reports and codes clearer and more efficient. We plan
to hold regular bi-lats to update each other as to our progress.
We will also use third-party resources, such as online tutorials for VBA,
all of which will be properly cited according to University of Ottawa
standards.


20

Personal Ethics Statement

SHAIL JOSHI

7282674
08/12/2015

HUSSEIN HAIDER

7534475
08/12/2015

21

Sample Calculations (step size 0.1)

22

23

References
Chapra, Steven C., and Raymond P. Canale. Numerical Methods for Engineers. 6th ed.
Boston: McGraw-Hill Higher Education, 2010.

24

Potrebbero piacerti anche