#
Oil Refinery Production Model Code

to optimize a __Company's__ entire Distillation units

in one run.

**Goal for this page**: show how to use a Calculus Language 'Find' statement to tweak parameters in order to achieve production objective(s) that are stated in a 'Find' statement.

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.

After setup and other models are called that initialize things, then a Find statement is executed. A Find statement loops through ones code many many times in order to find optimal parameter values. See the arrows pointing to new code additions.

global all
problem OilProduction

**nRefineries = 22: nProducts = 33**
call setup ! initial values
call history ! extrapolate 4 today’s usage
! find product percentages for all Refineries in order
! to maximize profit.

**find supplyEst; in refineries; by jupiter;
matching ****supplyErr**; to maximize profit
End
model

**refineries**
ooo

Next, are the 'processing' model changes.

model Processing ! All distillation units @ All refinery

**do i = 1, nRefineries**
! assume distillation requires solving a PDE or two.
! below is the bases for solving a PDE.
t = 0: tPrt = tPrint

**do j = 1, nDistillUnits(i)**
Initiate ISIS for PDEquations ooo
do while (t .lt. tFinal)
ooo

**Total model** is summed up next. The solver will vary your (independent) parameters, see 'supplyEst' 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 supplyEst; in refineries; by jupiter;
matching ****supplyErr**; to maximize profit
End
model

**refineries**
pollution = 0:

**profit** = 0: cost = 0:

**supplyErr** = 0
do i = 1, nRefineries
do k = 1, nProducts
supplyQty(k) =

**supplyEst**(i, k)
end do
crudeUsed = 0: crudeErr = 0
! finds qty production at each refinery to minimize overall
! pollution to restrict 'supplyQty(k)' to equal 'supplyEst(k)'
find supplyQty; in processing; by Jove;
with upper hi; and lower low;
matching crudeErr; to minimize pollution
do k = 1, nProducts

**supplyErr** =

**supplyErr** + (supplyQty(k) -

**supplyEst**(i, k))**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 Processing ! All distillation units

**do i = 1, nRefineries**
! assume distillation requires solving a PDE or two.
! below is the bases for solving a PDE.

**do j = 1, nDistillUnit(i)**
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
end do
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** + ???
end
model distribution
distPollution = 0
! your (algebraic?) equations that model your distribution go here.
ooo
end
procedure Setup
allot supplyEst(nRefineries, nProducts),
hi(nProducts), low(nProducts), ooo
! today’s available Crude Oil at different refineries
totCrudeIn = data( …’ available crude INPUT levels
' at each Refinery goes here’ …)
totHi = data( … storage limits for various products goes here …)
totLow = data( … target amounts less inventory goes here …)
nDistillUnit = data( … # of distillation units @
each refinery goes here …)
End
procedure history
! here, use past history to estimate today’s oil needs
salesHistory( 1,1) >= data( …’ amount of crude oil to be targeted
' for today at the 1st Refinery goes here’
salesHistory( 2,1) >= data( …’ 2nd Refinery’ …)
ooo
salesHistory( nRefineries,1) >= data( …’ nth Refinery’ …)
end

This example shows nesting of find statements that will help maximize productivity. Getting agreement on what a company's objective is or should 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.

**Maintenance Model:** may be an ongoing model to build. For example, how often do the light bulbs need changing? How about the pipes carrying oil? Those with experience have said oil pipes in refineries need repair every 3 months to 6 months. 3 months, what a problem! Is that to say every 89 days and 4.5678 hours? When to schedule a repair? Oh, this could be a huge problem for a computer model.

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.