#
Oil Refinery Production Model for Business Strategies

### 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.

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

1. State number of plants / refineries and the number of products. To start, nRefineries = 1 until all Refineries are up and running this Production model. When all Refineries have this working, then increase nRefineries = 2 then 3 and so on.

```
nRefineries = 22: nProducts = 33
```

2. Execute ALL departments involved in this model. Start with a minimum departments and increase departments as you build this model and are confident things are working as planned. **Processing** model is the **only one necessary** to get things rolling.

```
model departments
call processing ! distillation model for 'i'th Refinery
call inventory ! present supply of various products
call demand ! estimated demands
call distribution ! shipping costs
call maintenance ! repairs, continual maintenance, etc.
call accountants ! fixed asset costs, etc.
! call ??? ! other departments as developed
End
```

3. The **Processing model** 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.

```
model Processing ! jth distillation unit @ refinery
! assume distillation requires solving a PDE or two. So below is the bases for solving a PDE.
t = 0: tPrt = tPrint
do k = 1, nDistUnits( j)
kDistModel = ???
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(j)– crudeUsed)**2
79 format( 1x,f8.4,20(g14.5, 1x))
end
model PDEquations
if( kDistModel .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( kDistModel .eq. 2) then
pde_2 = pde equations with parameters
! assume # 2 & 8 products are created
qtyProd(2) = qtyProd(2) + ???
qtyProd(8) = qtyProd(8) + ???
ooo
elseif( kDistModel .eq. k) then
pde_k = pde equations with parameters
! assume # 1, 2, & 8 products are created
qtyProd(1) = qtyProd(1) + ???
qtyProd(2) = qtyProd(2 )+ ???
qtyProd(8) = qtyProd(8 )+ ???
end if
crudeUsed = crudeUsed + ???
pollution = pollution + ???
cost = cost + mfgCost + distCost + ???
profit = profit + ??? - cost
end
```

4. The **distribution** department should model all routes used to deliver your oil products. Assuming pollution and costs are key (dependent) parameters,key track of all that affect them. The solver may find new routes that minimize / maximize things.

```
model distribution
distPollution = 0: distCosts = 0
! your (algebraic?) equations that model your distribution go here.
ooo
distPollution = distPollution + ???
distCosts = distCosts + ???
End
```

**Total model** is summed up next. The solver will vary your (independent) variables, see 'totProdPrct' in model, in order to meet company's objectives.

```
global all
problem OilProduction
nRefineries = 22: nProducts = 33
dynamic hi, low, totCrudeIn, ooo
call setup ! initial values
call history ! extrapolate 4 today’s usage
! find product percentages for all Refineries in order to maximize profit.
```**find totProdPrct in refineries by jupiter
matching errsum to maximize profit**
End
model refineries
pollution = 0: profit = 0: cost = 0: errSum = 0
do i = 1, nProducts
do j = 1, nRefineries
sameProd(j) = totProdPrct(j, i) * totCrudeIn(i)
end do
crudeUsed = 0: crudeErr = 0
! finds qty production @ each refinery to minimize overall pollution
! to restrict prod., e.g. 3rd qty, set hi(3) = low(3)
find sameProd in processing by Jove
with upper hi and lower low
matching crudeErr to minimize pollution
do j = 1, nRefineries
errSum = errSum+ (sameProd(j) - totProdPrct(j,i) * totCrudeIn(i))**2
end do
end do
! find best routes to deliver products
ooo
find routes in distribution ooo to minimize distPollution
profit = ??? ! calculate / measure it!
cost = ??? ! ditto
profit = profit - cost
end
model distribution
distPollution = 0
! your (algebraic?) equations that model your distribution go here.
ooo
end
model Processing ! jth distillation unit @ refinery
! assume distillation requires solving a PDE or two. So below is the bases for solving a PDE.
t = 0: tPrt = tPrint
do k = 1, nDistUnits( j)
kDistModel = ???
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(j)– crudeUsed)**2
79 format( 1x,f8.4,20(g14.5, 1x))
end
model PDEquations
if( kDistModel .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( kDistModel .eq. 2) then
pde_2 = pde equations with parameters
! assume # 2 & 8 products are created
qtyProd(2) = qtyProd(2) + ???
qtyProd(8) = qtyProd(8) + ???
ooo
elseif( kDistModel .eq. k) then
pde_k = pde equations with parameters
! assume # 1, 2, & 8 products are created
qtyProd(1) = qtyProd(1) + ???
qtyProd(2) = qtyProd(2 )+ ???
qtyProd(8) = qtyProd(8 )+ ???
end if
crudeUsed = crudeUsed + ???
pollution = pollution + ???
cost = cost + mfgCost + distCost + ???
profit = profit + ???
end
procedure Setup
allot totProdPrct(nRefineries, nProducts), hi(nProducts), low(nProducts), ooo
! today’s available Crude Oil at different refineries
= data( …’ available crude INPUT levels at each Refinery goes here’ …>
= data( … storage limits for various products goes here …)
= data( … target amounts less inventory goes here …)
= data( … # of distillation units @ each refinery goes here …)
End
procedure history
! here, use past history to estimate today’s oil needs
totQtyOut( 1,1)> = data( …’ amount of crude oil to be targeted for today at the 1st Refinery goes here’
totQtyOut ( 2,1)> = data( …’ 2nd Refinery’ …)
ooo
totQtyOut (nRefineries,1)> = data( …’ nth Refinery’ …)
end

This example shows nesting of find statements that will help maximize productivity. Getting agreement on what a companies objective is or should be may take some time. It is hoped that this example will aide you on solving your problem with Calculus programming. Solve not just one equation but your entire problem/project in one program.

**Communication:**Have you seen movie *Hidden Figures*, if you haven’t seen it, you should. It may help understand the communication problem between different types of people; e.g. NASA’s Engineers, Scientists, and Mathematicians. The movie shows engineers trying to solve some equations and getting no where fast! A mathematician comes along and solves the problem. But numbers say little to engineers. Near the movie’s end, the mathematician draws a graph showing a solution. The engineers finally get the ‘picture’ of what the equations are trying to say to them. Remember, a picture is worth a 1,000 words, right?

**Feedback Request:** How many companies are interested in solving their similar problem? At present, this program may not work due to amount of storage necessary. In order to fix this storage problem, we need your values for ‘nRefineries’ & ‘nProducts’. The product of nRefineries * nProducts may be the problem. Assume each is 100 then their product is 104. Internal arrays (e.g. jacobian) is the square of this product, 108! Knowing that the majority of problems would work with 10n would provide a target value for future releases of Calculus compilers.

## If interested in solving such production problems, please contact Optimal Designs Enterprise.

The next article will show a **Buy, Sell, or Hold** model. This model can be executed every day, month, or when a CEO wants to see their options. It can be very helpful, but practice is key to reading the output and understanding what it truly says.