Calculator
General Information
The Calculator is a versatile utility module useful for a variety of purposes in
flowsheet simulation. Parameters may be retrieved from the flowsheet and
calculations performed using a FORTRAN-like language. Parameters may be
returned to the flowsheet for use by other unit operations. Some uses for the
Calculator include:
> Calculating special stream properties
Simulating special processing units such as reactors,
Determining operating conditions for other unit operations
Performing design calculations using flowsheet information
Producing special output values for reports
Computing utility costs and economic functions
Calculating target values for Controllers or objective functions for
Flowsheet Optimizers
vvvvvy
This is by no means an exhaustive list; the usefulness of this module is limited
only by the ingenuity of the user.
All Calculators have two main sections: Setup and Procedure. In the setup
section, unit and stream parameters are retrieved from the flowsheet, constants
are defined, names are assigned to calculated results, a sequence table is set up
for the streams used for input and output, and the dimensions for the various
working arrays may be expanded if desired.
‘The Procedure section is where all calculations are performed, using a simple
language based on FORTRAN 77. The language permits the use of
mathematical functions, branching and looping, and assignment statements
commonly used in programming. Special intrinsic functions are available for
retrieving flowsheet component and stream information. Special subroutines are
provided for storing calculated results directly in flowsheet streams. Calculated
results may also be stored in the *Results” array, making them available to the
other unit operations in PRO/II. A special solution “flag” is provided for use when
a Calculator models a unit operation.
Chapter 9 Unit Operations and Utility Modules 149Calculator Setup
Start Setup by clicking Edit/View Declarations on the Calculator main data entry
window to open the View Area:
>
Click Paramitersill to retrieve flowsheet parameters into the Calculator.
These variables are accessed in the Calculator procedure as elements of
array P. Click the Calculator parameter linked text to open the Definition
window where you can specify the stream or unit flowsheet parameter to
be retrieved. The format for this window is identical to that used for the
DEFINE and is described in the SPEC/VARY/DEFINE section of this
chapter. In this window, you will find a list of the unit and stream
parameters that may be retrieved via DEFINE.
Click Constants... to enter the constant values. These variables are
accessed in the Calculator procedure as elements of array C. Although
you can enter constants directly in the procedure, this array provides a
means for collecting constants that need to be updated occasionally into
a common location.
Click RESUItS!., to enter names for the Calculator results. These values
are accessed in the Calculator procedure as elements of array R. These
names will be used in the output report.
Click Stream Sequences to define an ordered table of flowsheet
streams. There are two functions for this table, First, it provides a
necessary link between the procedure and the flowsheet streams for
information flow. Second, a calculation loop may be performed in the
procedure for a range of streams, using the positions of the streams in
the table to control the loop order.
Click Arraysill to declare the length of the storage arrays used by the
Calculator. These arrays include the P, C, R arrays defined above, and
the IS array that is used to hold stream variables. This array is described
in the Calculator Procedure discussion. Two additional arrays appear
here. In earlier versions of the Calculator, all local variables had to reside
in one of these arrays, V for real variables and IX for integers. Now that
any valid FORTRAN variable name can be used, these arrays are no
longer needed. Nonetheless, they are stil available so that older
Calculators will work without rewriting.
Once Setup is complete, click Hide Declarations to close the View Area.
150 PRO/Il User Guide March 2008Calculator Procedure
Note: The PROCEDURE section is required and must end with a RETURN
statement.
‘The FORTRAN procedure is entered directly into the Procedure field on the
Calculator main data entry window. The procedure may be checked as is it
composed by clicking Check Procedure
The supported features of the language are discussed in the following sections.
Elements of the Language
Each statement may contain up to 80 characters. The ampersand (&) at the end
of a line denotes continuation of a statement on the following line. Note that an
asterisk (*) is not valid as a continuation marker, since it signifies multiplication.
All lines of code except the PROCEDURE statement may be preceded by a
unique numeric label from 1 to 99999 (shown as “nn” in this manual).
A dollar sign ($) causes all following characters on the remainder of the line to be
interpreted as a comment rather than as code. Unlike in FORTRAN, a “C” in
column one does not designate a comment statement.
Predefined Variables
Definitions of predefined variables, including default dimensions for arrays,
appear in the following table. Use a DIMENSION statement in the Calculator
setup section to reset the number of elements in each array.
Arrays C, P, V, and R store values in floating-point form. Array IX stores integer
values. Forms of use include:
An
where Ais any of C, P, V, R, or B, and nis an integer that indicates a single
element of the array.
A(index)
Ais any of C, P, V, R, or B, and (index) is an expression, such as (IX2 * 5).
The parentheses are required. “A(n)" denotes the same element as "An’.
Instead of, or in addition to the supplied V and IX arrays, standard FORTRAN,
variables may be used. They may be up to 8 characters long and may not
duplicate the names of any supplied variables; otherwise they follow the
conventional FORTRAN rules. The introduction of this feature in PRO/II 5.0
means that the V and IX arrays need not be used. If this is the case, the arrays
can be dimensioned to one word each to save memory.
Chapter 9 Unit Operations and Utility Modules 151Array "IS" is normally used as the index of a DO loop to step through a sequence
of streams in the order defined on the SEQUENCE statement.
It may serve as the stream index in PRO/II intrinsic functions. The only form
allowed is ISn. IS(index) is never valid.
Pena ene
Variable | Default
Name (for arrays) Description and Comments
and Form
Cn or 1 Open the Calculator main data entry window by double-clicking the
Calculator icon on the PFD.
> Click Edi/View Declarations to display the View Area box. Click
Parameters to display the Parameters data entry table.
> Enter a number in the Parameter Number data entry field to enable the
Calculator Parameter linked text. Click on the linked text to open the
Definitions window.
> Check the Set Up Definition for Calculator Parameter P(1) box to enable
the “Calculator Parameter = Parameter’ linked text.
> Click the Parameter... hypertext to open the Parameter window where
you can specify whether the parameter will be a constant, a stream
parameter or a unit parameter. The Constan/Stream/Unit list box
displays a list with the options “Constant,” “Stream” and the various types
of unit operations that have been placed on the flowsheet.
> For this sample problem, select the Stream option and choose V1 from
the Stream Name: drop-down list box. Choosing a stream name enables
the Parameter... hypertext.
> Click the linked text to open the Parameter Selection data entry window.
> For this sample, choose Distilation Curve from the options in the
Parameter window. The center window will now display the available
distillation curve options. Select D86 from the distillation curve options
and choose the desired cut point (here, 10%) from the Volume Percent
Distillate drop-down list box.
162 PROIII User Guide March 2008This completes the parameter specification for the D86(10%) point of the first.
stream, V1. Repeat these steps to define the D86(Initial Point) for the first
stream, V1, then define the D86(10%) and D86(Initial Point) for the remaining
five streams.
Chapter 9
> Enter the following code into the Procedure window (at this point, this
window should still be outlined in red).
DIMENSION D8610(6), D86IP(6)
O10 I=
$
$ COPY PARAMETERS TO LOCAL ARRAYS,
§ CONVERTING TO DEG F
D8610(l) = P(2"I-1) * 1.8 + 32.
DBsIP(!) = P(2*1-1) * 1.8 +32,
$
§ EVALUATE FORMULA
D8GAVG = (D8610(!) + D86IP(I)) /2.
FP = (D8GAVG * .64 - 100.
$
$ CONVERT BACK TO DEG C AND STORE
RO) = (FP -32.) 1.8
40 CONTINUE
RETURN
> Commit the code by clicking OK.
Unit Operations and Utility Modules 163Example 2: Material Balancing with the Calculator
This sample demonstrates the use of the Calculator to compute the material
balance of hydrogen (component 2) about a recycle loop. We will set the solution
flag to indicate “unit not solved" if the hydrogen balance is not met to within
0.01% based on the overall feeds. This specification forces the recycle to
continue iterating, even if the flowing streams have changed less than the
fiowsheet stream tolerance. See the ISOLVE and ISn entries in the Predefined
Variables table on page 152 for a listing of solution flags and for an explanation
of the use of the Isn variable in SEQUENCE staternents,
Before entering the procedure code, we must:
> Establish the Stream Sequence for the recycle loop.
> Provide a label for the Result.
Establishing the Stream Sequence:
The streams pertinent to this example are a hydrogen feed stream (H2FD), two
feed streams (FD1, FD2), a purge gas stream (PURG), and vapor and liquid
product streams (PRDV, PRDL).
To set up the stream sequence that will be used by the Calculator, carry out the
following steps:
> Open the Calculator main data entry window by double-clicking the
Calculator icon.
> Click Stream Sequence to display two windows, one containing a list of
Available Streams and the other a list of Selected Streams,
& Add the streams H2FD, FD1, FD2, PURG, PRDV and PRDL in the given
order. If you add the streams in the wrong order, you can easily change
their sequence by removing the improperly posit
Selected Streams window and reinserting it before or after the
appropriate stream that you have highlighted in the Selected Streams
window.
Labeling the Result:
> When you have established the desired stream sequence, click Results
to display the Result Number and Print Name data entry table.
> Enter "1" in the Result Number field of the first row to enable the Print
Name entry field. This integer is stored in the first position of the R()
array. For this sample problem, call the result “Relative MB.”
> Enter the following code into the Procedure window, which should stil be
outlined in red at this point:
164 PRO/II User Guide March 2008$ SUM UP H2 IN FEED STREAMS
'§ HYDROGEN IS THE SECOND COMPONENT IN THE COMPONENT LIST
'$§ SCMR(2, n) IS THE MOLAR FLOWRATE IN THE nth STREAM
H2FEED =0.0
DO 10 ISt = H2FD, FD2
H2FEED = H2FEED + SCMR(2,IS1)
10 CONTINUE
$
$ CHECK IF ANY H2 IN FEED. IF NOT, SET “NOT SOLVED” FLAG.
$
IF (H2FEED .LT. 0.0001) THEN
R(1)=0
ISOLVE =2
GOTO 99
ENDIF
s
§ SUM UP H2 IN PRODUCTS
$
H2PROD= 0.0
DO 20 IS1 = PURG, PRDL
H2PROD = H2PROD + SCMR(2, IS1)
20 CONTINUE
$ CALCULATE IMBALANCE
s
R(1) = (H2FEED - H2PROD) / H2FEED
$
§ CHECK IF IN BALANCE. IF SO, RETURN.
$ IF NOT, SET “NOT SOLVED” FLAG.
s
IF(ABS(R(1)).LE.0.001) THEN
ISOLVE =1
ELSE
ISOLVE =2
ENDIF
s
99 RETURN
Chapter 9 Unit Operations and Utility Modules 165This page intentionally is left blank.
166 PRO/II User Guide March 2008