#
Oil Refinery Production Model Code

to simulate ONE distillation unit at a time.

### Problem Description: An oil company may have many different distillation processes going on at each of its refineries. Each time new crude oil arrives at a refinery, or one distillation unit goes in or out of service, a new tweaking of all distillation parameters must be done in order to maximize / minimize the company’s objective.

**Goal for this page**: simulate one distillation unit at a time in each refinery. Verify results and fix any discrepancies.

On this page, we'll attempt to guide you through the various model routines in order to create a 'picture' for you to understand what's going on.

1. To start, set iRefinery = 'i'th unit and any Distillation unit 'jDistillUnit' at this refinery and test to see if working, then try another 'jDistillUnit' and so on until all units at this 'iRefinery' refinery are running properly. Next, change 'iRefinery' refinery setting to another refinery and step through all it's Distillation units until all are working properly and results agree with what is presently being produced.

iRefinery = 2: jDistillUnit = 7

2. Build the **Processing model** that states how the crude oil is broken down into the sellable oil units; e.g., 10, 20, 30, 90 grades. Think distribution! Where are the different grades to be sold? Heavy grades in the cold parts and light grades in the hot parts of the country. So, in order to help minimize cost, produce the oil products in their appropriate regions.

Lots of (PDE) equation work goes in this model. It is a key to a good model and may take some time to complete, but be careful that your results agree with current day productions.

model Processing ! 'j'th distillation unit @ ith refinery
i = iRefinery: j = jDistillUnit

! assume distillation requires solving a PDE or two.
! below is the bases for solving a PDE.
t = 0: tPrt = tPrint
Initiate ISIS for PDEquations ooo
do while (t .lt. tFinal)
Integrate PDEquations by ISIS
if( t .ge. tPrt) print 79, t, (U(ii),ii = 1,ip)
tPrt = tPrt + tPrint
end do
end do
crudeErr = crudeErr+(totCrudeIn(i, j)– crudeUsed)**2
79 format( 1x,f8.4,20(g14.5, 1x))
end
model PDEquations
if( j .eq. 1) then
pde_1 = pde equations with parameters
! assume # 3, 7, & 8 products are created
qtyProd(3) = qtyProd(3) + ???
qtyProd(7) = qtyProd(7) + ???
qtyProd(8) = qtyProd(8) + ???
elseif( j .eq. 2) then
pde_2 = pde equations with parameters
! assume # 2 & 8 products are created
qtyProd(2) = qtyProd(2) + ???
qtyProd(8) = qtyProd(8) + ???
ooo
end if
crudeUsed = crudeUsed + ???
pollution = pollution + ???
cost = cost + mfgCost + distCost + ???
profit = profit + ??? - cost
end

This example shows solving just ONE distillation unit in one refinery. Step through all distillation units in each refinery. Be sure each run's output is in agreement with what is currently being produced by each distillation unit. Once in agreement, move on to another unit and continue testing to be sure your math model agrees with reality.

The next article will show an entire refinery model being solved in one run, do results look good? This is the next building block for this project.