You can use Fortran in Aspen Plus to perform any task that can be written as valid Fortran expressions. You can input Fortran expressions in a number of ways in Aspen Plus:
•
n Fortran !alculator blocks "n the Fortran sheets of other blocks# such as design specifications# sensitivity or optimi$ation problems
•
n external Fortran subroutines
•
Fortran !alculator blocks :
•
!ontain Fortran expressions used to perform user%defined tasks !an read and&or write flowsheet variables
•
Are executed at a specific point in the simulation
•
Aspen Plus checks your Fortran code interactively interactively as you enter it so most syntax errors are detected before a run. f the status indicator on a Fortran sheet is # use 'ext to find out what is incomplete. You can write external User Fortran subroutines subroutines when the models provided by Aspen Plus do not meet your needs. After you compile these subroutines# they are dynamically linked when the simulation is run. Aspen Plus allows extensive customi$ation of the models through the use of these external user subroutines. For more information on external user subroutines# see Aspen Plus User (odels . Aspen Plus can interpret most in%line Fortran. Fortran that cannot be interpreted is compiled and dynamically linked to the Aspen Plus module. )ecause dynamic linking is used# the overhead for in%line Fortran re*uiring compilation is small. f the Fortran cannot be interpreted# interpreted# a Fortran compiler is needed. +ee chapter , of Aspen Plus User (odels for information on supported compilers and on configuring Aspen Plus to use your compiler.
!alculator blocks let you insert Fortran statements or -xcel spreadsheets into flowsheet computations to perform user%defined tasks.
+ince Aspen Plus is a se*uential modular simulator that executes one unit operation at a time# you must specify where in the se*uence of unit operations each !alculator block is to be executed. You can do this by specifying one of these: •
•
hich flowsheet variables are mported from and -xported to Aspen Plus by the !alculator block /he position of the !alculator block in the list of unit operation blocks
0efine a !alculator block by: ,. !reating !reating the !alculat !alculator or block. block. 1. dentifying the flowsheet flowsheet variables variables that that the block block samples or manipulates. 2. -ntering the -xcel -xcel formulas formulas or Fortran Fortran statements. statements. 3. +pecifyi +pecifying ng when the !alculat !alculator or block is executed executed. . 4ariables changed by a !alculator will remain at their last values at the start of the next run if you do not reinitiali$e the problem. f you modify the problem so that these variables are no longer changed# the old changed variables will retain their last values from the !alculator 5rather than values previously specified on other forms6 until otherwise changed or reinitiali$ed.
/o create a Fortran !alculator block: ,. From From the the menu# point to then . 1. n the !alculator !alculator "b7ect "b7ect (anager# (anager# click click
# .
2. n the !reate !reate 'ew 0 dialog dialog box# enter enter an 0 or accept accept the default# and click "8. 3. "n the !alculate !alculate sheet# select select Fortran Fortran 5default6. 5default6.
!alculator blocks let you insert Fortran statements into flowsheet computations to perform user%defined tasks# such as:
•
!alculating and setting input variables before they are used 5feedforward control6 riting information to the !ontrol Panel
•
9eading input from a file
•
riting results to the Aspen Plus report or to any external file
•
!alling external subroutines
•
riting your own user models
•
0efine a Fortran !alculator block by: ,. !reating the !alculator block. 1. dentifying the flowsheet variables that the block samples or manipulates. 2. -ntering the Fortran statements on the !alculate sheet. 3. +pecifying when the !alculator block is executed.
!alculator blocks let you insert Fortran statements or -xcel spreadsheets into flowsheet computations to perform user%defined tasks. +ince Aspen Plus is a se*uential modular simulator that executes one unit operation at a time# you must specify where in the se*uence of unit operations each !alculator block is to be executed. You can do this by specifying one of these: •
hich flowsheet variables are mported from and -xported to Aspen Plus by the !alculator block
•
/he position of the !alculator block in the list of unit operation blocks
0efine a !alculator block by: ,. !reating the !alculator block. 1. dentifying the flowsheet variables that the block samples or manipulates. 2. -ntering the -xcel formulas or Fortran statements. 3. +pecifying when the !alculator block is executed. 4ariables changed by a !alculator will remain at their last values at the start of the next run if you do not reinitiali$e the problem. f you modify the problem so that these variables are no longer changed# the old changed variables will retain their last values from the !alculator 5rather than values previously specified on other forms6 until otherwise changed or reinitiali$ed.
/o create a Fortran !alculator block: ,. From the 0ata menu# point to Flowsheeting "ptions# then !alculator. 1. n the !alculator "b7ect (anager# click 'ew. 2. n the !reate 'ew 0 dialog box# enter an 0 or accept the default# and click "8. 3. "n the !alculate sheet# select Fortran 5default6.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the 0esign +pec form# click the Fortran sheet. 1. Use elp to review rules and restrictions for in line Fortran. 2. -nter your Fortran statements.
/o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the "ptimi$ation or !onstraint form# click the Fortran tab. 1. 9eview the rules and restrictions for in line Fortran 2. -nter your Fortran statements. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/o enter executable Fortran statements on the !alculate sheet: ,. !lick the !alculate tab on the !alculator nput form. /o review rules and restrictions for in line Fortran# see 9ules for n%;ine Fortran +tatements . 1. -nter your Fortran statements. 2. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the !alculate sheet.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the +ensitivity nput form# click the Fortran sheet. 1. 9eview the rules and restrictions for in line Fortran
2. -nter your Fortran statements. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/o achieve successful compilation of your Fortran statements# follow these rules: •
• •
)y default# variables beginning with A through # or " through <# are double precision real. 4ariables beginning with through ' are integer. Use double precision functions 5for example# 0+=9/6 and double precision constants 5for example# ,0>6. 0o not use variable names beginning with < or <<. )ecause Fortran is column%sensitive# this table shows how to do certain things:
/o do this
Use
ndicate comments
!olumn one for ! and leave column two blank
-nter statement labels "nly columns three# four# and five )egin executable !olumn seven or beyond statements • You can call your own subroutines or functions. You can use labeled or blank 5unlabeled6 !"(("' blocks. • Fortran variables you define on the +pecification sheet cannot be placed in a !"(("'. • 0o not use (P;!/# +U)9"U/'-# -'/9Y# 9-/U9'# -'0 statements# nor arithmetic statement functions. • 9-A0 and 9/- statements to numbered file units 5as in 9/5'/-9(#?66 only work if the same compiler was used to compile the code containing these statements and the code which opened the files. Aspen Plus now uses the ntel Fortran compiler to open its built%in units for the report file# history file# and control panel. +ee !hapter , of Aspen Plus User (odels for more information.
)y default# Aspen Plus will interpret in%line Fortran if it is possible. Fortran that cannot be interpreted is compiled and linked into a shared library or dynamic link library 50;;6. A Fortran compiler is needed for compiling the code. t is possible to compile all of the Fortran by selecting on the sheet. /he following Fortran can be interpreted: • • • • •
• • • •
All declarations besides !"(("' statements Arithmetic expressions and assignment statements F statements "/" statements# except assigned "/" 9/- statements that use the built%in unit number variables '/-9(# '9P/# or '+/9Y. 5 f these statements appear in code that is compiled# you must use the ntel Fortran compiler. +ee chapter , of Aspen Plus User (odels for more information.6 F"9(A/ statements !"'/'U- statements 0" loops !alls to these built%in Fortran functions:
0A)+
0-9F
0(',
0'/
0A!"+
0-BP
0("0
(AB>
0A+'
0F;"A/
0+'
('>
0A/A'
0A((A
0+'
("0
0A/A'1
0;A(A
0+=9/
0!"+
0;"
0/A'
0!"+
0;",>
0/A'
0!"/A'
0(AB,
A)+
You can use the e*uivalent single precision or generic function names in your Fortran statements. owever# Aspen Plus always performs double precision calculations# and using the other names will re*uire compilation. f you use the following statements# you must enter them on the 0eclaration sheet: • • •
9-A; or '/--9 statements 0"U);- P9-!+"' statements 0(-'+"' statements
•
!"(("' statements
/he following statements re*uire compilation: !A;;
-'/9Y
P9'/
!A9A!/-9
-=U4A;-'!-
9-/U9'
!"(("'
(P;!/
9-A0
!"(P;-B
;"!A;
+/"P
0A/A
PA9A(-/-9
+U)9"U/'-
/o achieve successful compilation of your Fortran statements# follow these rules: •
• •
)y default# variables beginning with A through # or " through <# are double precision real. 4ariables beginning with through ' are integer. Use double precision functions 5for example# 0+=9/6 and double precision constants 5for example# ,0>6. 0o not use variable names beginning with < or <<. )ecause Fortran is column%sensitive# this table shows how to do certain things:
/o do this
Use
ndicate comments
!olumn one for ! and leave column two blank
-nter statement labels "nly columns three# four# and five )egin executable statements •
•
•
•
!olumn seven or beyond
You can call your own subroutines or functions. You can use labeled or blank 5unlabeled6 !"(("' blocks. Fortran variables you define on the +pecification sheet cannot be placed in a !"(("'. 0o not use (P;!/# +U)9"U/'-# -'/9Y# 9-/U9'# -'0 statements# nor arithmetic statement functions. 9-A0 and 9/- statements to numbered file units 5as in 9/5'/-9(#?66 only work if the same compiler was used to compile the code containing these statements and the code which opened the files. Aspen Plus now uses the ntel Fortran compiler to open its built%in units for the report file# history file# and
control panel. +ee !hapter , of Aspen Plus User (odels for more information.
You have the option of entering any Fortran statements needed to compute the design specification terms or manipulated variable limits. Any variable that is computed by the Fortran statements can be used in the expressions on the +pec and 4ary sheets. Fortran statements are needed only if the functions involved are too complex to enter on the +pec and 4ary sheets. You can enter Fortran statements: • •
"n the Fortran sheet n your text editor 5for example# 'otepad6# and then copy and paste them onto the Fortran sheet
-nter Fortran declarations in the same way as executable Fortran statements# using the 0eclarations sheet instead of the Fortran sheet. You can include any Fortran declarations in a 0esign +pec block# such as:
•
nclude statements !"(("' definitions
•
0(-'+"' definitions
•
0ata type definitions 5'/--9 and 9-A;6
•
f a Fortran variable meets one of these criteria# you should place it in a !"(("': • •
t is also used by another block. ts value must be retained from one iteration of a block to another.
Fortran variables that you defined on the +pecification sheet should not be declared on the 0eclarations sheet.
You can enter Fortran statements: • •
"n the !alculate sheet n your text editor 5for example# 'otepad6# and then copy and paste them onto the !alculate sheet
!lick the Fortran 0eclarations button to enter Fortran declarations in the 0eclarations dialog box# in the same way you enter executable Fortran statements on !alculate sheet. You can include any Fortran declarations in a !alculator block# such as:
•
nclude statements !"(("' definitions
•
0(-'+"' definitions
•
0ata type definitions 5'/--9 and 9-A;6
•
f a Fortran variable meets one of these criteria# you should place it in a !"(("': • •
t is also used by another block. ts value must be retained from one iteration of a !alculator block to another.
Fortran variables that you defined on the 0efine sheet should not be declared in the 0eclarations dialog box.
You enter Fortran declarations in the same way as executable Fortran statements# using the 0eclarations sheet instead of the Fortran sheet. You can include any Fortran declarations in an optimi$ation problem# including:
•
!"(("' definitions 0(-'+"' definitions
•
0ata type definitions 5'/--9 and 9-A;6
•
f a Fortran variable meets one of these criteria# you should place it in a !"(("': • •
t is also used by another block. ts value must be retained from one iteration of an optimi$ation problem to another.
Fortran variables that you defined on the 0efine sheet should not be declared on the 0eclarations sheet.
)y default# Aspen Plus interactively checks your Fortran statements. You can turn off interactive syntax checking. You might need to do this# for example# if you are using a compiler that accepts nonstandard Fortran extensions# or if the syntax checker incorrectly flags correct Fortran as incomplete. /o turn off Fortran syntax checking: ,. From the /ools menu# click "ptions. 1. -nsure the !heck nline Fortran for +yntax -rrors checkbox is clear.
Fortran unit operation models use a Fortran subroutine to perform the calculations for the model. /hese models may be included in a simulation by using the User or User1 block in Aspen Plus. +ee # !hapter C# for detailed information about Aspen Plus User (odels writing these models. -xcel unit operation models use an -xcel spreadsheet to perform the calculations re*uired by the model. /hese models also use the User1 block in Aspen Plus. +ee Aspen Plus User (odels # !hapter C# for detailed information about writing these models.
-xternal user Fortran is an open and extensive customi$ation capability in Aspen Plus. An Aspen Plus user model consists of one or
more Fortran subroutines that you write yourself when the models provided by Aspen Plus do not meet your needs. A proper argument list is needed in the subroutine to interface your user model to Aspen Plus. You can write the following kinds of user models for use in Aspen Plus: -xternal Fortran Application /ypes
Use
User Unit "peration (odels
Units not represented by Aspen Plus unit operation models
8inetic (odels
9eactors# 9eactive 0istillation# Pressure 9elief
Physical Property (odels Pure and mixture# activity models# 8;;# user e*uations%of%state +tream Properties
+pecial properties to be calculated for a stream
Unit "peration !ustomi$ation
9eactor heat transfer# column hydraulics# ;(/0 correction# pressure drop# li*uid% li*uid distribution coefficients
!ustomi$ed 9eports
User%defined stream report# user block reports# applications based on the +ummary File /oolkit
+i$ing and !osting
User cost blocks
/emplates that include the argument list and other useful code for starting a user model are provided in the /emplates directories where Aspen Plus is installed. For more information on how to write a user model# see Aspen Plus User (odels .
You can use Fortran in Aspen Plus to perform any task that can be written as valid Fortran expressions. You can input Fortran expressions in a number of ways in Aspen Plus:
•
n Fortran !alculator blocks "n the Fortran sheets of other blocks# such as design specifications# sensitivity or optimi$ation problems
•
n external Fortran subroutines
•
Fortran !alculator blocks :
•
!ontain Fortran expressions used to perform user%defined tasks !an read and&or write flowsheet variables
•
Are executed at a specific point in the simulation
•
Aspen Plus checks your Fortran code interactively as you enter it so most syntax errors are detected before a run. f the status indicator on a Fortran sheet is # use 'ext to find out what is incomplete. You can write external User Fortran subroutines when the models provided by Aspen Plus do not meet your needs. After you compile these subroutines# they are dynamically linked when the simulation is run. Aspen Plus allows extensive customi$ation of the models through the use of these external user subroutines. For more information on external user subroutines# see Aspen Plus User (odels . Aspen Plus can interpret most in%line Fortran. Fortran that cannot be interpreted is compiled and dynamically linked to the Aspen Plus module. )ecause dynamic linking is used# the overhead for in%line Fortran re*uiring compilation is small. f the Fortran cannot be interpreted# a Fortran compiler is needed. +ee chapter , of Aspen Plus User (odels for information on supported compilers and on configuring Aspen Plus to use your compiler.
n Fortran 9/- statements# you can use the following predefined variables for the unit number: Unit
0estination
'/-9(
!ontrol Panel 5if running from the user interface6 /erminal 5if running interactively outside of the user interface6# or ;og file 5if running batch6
'9P/
Aspen Plus report
'+/9Y
+imulation history
-xamples: For writing to the !ontrol Panel# enter:
9/-5'/-9(# ?6 A# )# !# B For writing to the report file# enter: 9/-5'9P/# ?6 A# )# !# B f writing to the Aspen Plus report from a Fortran !alculator block# select 9eport in the -xecute field on the +e*uence +heet. "utput written to the report file will appear in the Flowsheet section of the !alculator block report. hen writing to a user%defined file# use a Fortran unit number between C> and ,>>. riting to the predefined Aspen Plus units will only work in compiled Fortran if the Fortran is compiled with the ntel compiler. riting to user%defined files will only work if the code that opened the file and the code with the write statement were compiled with the same compiler. +ee !hapter , in Aspen Plus User (odels for more information. -xcel !alculator blocks do not have the ability to write to the !ontrol Panel or Aspen Plus report or history files# but you may use 4)A macros to display information in dialog boxes.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the 0esign +pec form# click the Fortran sheet. 1. Use elp to review rules and restrictions for in line Fortran. 2. -nter your Fortran statements. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the "ptimi$ation or !onstraint form# click the Fortran tab. 1. 9eview the rules and restrictions for in line Fortran 2. -nter your Fortran statements. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined
4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/o enter executable Fortran statements on the Fortran sheet: ,. "n the +ensitivity nput form# click the Fortran sheet. 1. 9eview the rules and restrictions for in line Fortran 2. -nter your Fortran statements. /o ensure that you enter accurate variable names# click the right mouse button. n the popup menu# click 4ariable ;ist. /he 0efined 4ariable ;ist window appears. You can drag and drop the variables from the 0efined 4ariable ;ist to the Fortran sheet.
/he message levels for Fortran variable diagnostics are: ;evel
0escription
>..3
'o messages
C
0efined%variable values before block execution are listed
D..E
;evel C and defined%variable values after block execution are listed
Flowsheet Connectivity for User
(aterial +treams "ne to four inlet material streams "ne to four outlet material streams eat +treams "ne heat stream 5optional6 "ne heat stream 5optional6 ork +treams "ne work stream 5optional6 "ne work stream 5optional6
Specifying User You must specify the name of the subroutine model on the nput +pecifications sheet. You have the option of specifying: • •
A report subroutine name +i$e of the integer and real arrays 5'/ and 9-A;6 passed to the user model subroutine
•
4alues of the integer and real arrays passed to the user model subroutine
•
;ength of integer and real workspace vectors
•
/hermodynamic conditions of each outlet stream
•
/ype of flash calculations 5vapor# li*uid# two%phase# three% phase6
For information on writing Fortran subroutines for user models# see Aspen Plus User (odels reference manual.
User can model any unit operation model. You must write a Fortran subroutine to calculate the values of the outlet streams based on the inlet streams and parameters you specify. User and User1 differ only in the number of inlet and outlet streams allowed and the argument lists to the model subroutine. User is limited to a maximum of four material and one heat or work inlet stream and a maximum of four material and one heat or work outlet stream. User1 has no limits on the number of inlet and outlet streams.
User can model any unit operation model. You must write a Fortran subroutine to calculate the values of the outlet streams based on the inlet streams and parameters you specify. User and User1 differ only in the number of inlet and outlet streams allowed and the argument lists to the model subroutine. User is limited to a maximum of four material and one heat or work inlet stream and a maximum of four material and one heat or work outlet stream. User1 has no limits on the number of inlet and outlet streams. Use the following forms to enter specifications and view results for User: Use this form /o do this nput
+pecify name and parameters for user subroutine#
calculation options# and outlet stream conditions and flash convergence parameters )lock"ptions
"verride global values for physical properties# simulation options# diagnostic message levels# and report options for this block
9esults
4iew summary of User results and material and energy balances
Specifying User You must specify the name of the subroutine model on the nput +pecifications sheet. You have the option of specifying: • •
A report subroutine name +i$e of the integer and real arrays 5'/ and 9-A;6 passed to the user model subroutine
•
4alues of the integer and real arrays passed to the user model subroutine
•
;ength of integer and real workspace vectors
•
/hermodynamic conditions of each outlet stream
•
/ype of flash calculations 5vapor# li*uid# two%phase# three% phase6
For information on writing Fortran subroutines for user models# see Aspen Plus User (odels reference manual.
-xternal user Fortran is an open and extensive customi$ation capability in Aspen Plus. An Aspen Plus user model consists of one or more Fortran subroutines that you write yourself when the models provided by Aspen Plus do not meet your needs. A proper argument list is needed in the subroutine to interface your user model to Aspen Plus.
You can write the following kinds of user models for use in Aspen Plus: -xternal Fortran Application /ypes
Use
User Unit "peration (odels
Units not represented by Aspen Plus unit operation models
8inetic (odels
9eactors# 9eactive 0istillation# Pressure 9elief
Physical Property (odels Pure and mixture# activity models# 8;;# user e*uations%of%state +tream Properties
+pecial properties to be calculated for a stream
Unit "peration !ustomi$ation
9eactor heat transfer# column hydraulics# ;(/0 correction# pressure drop# li*uid% li*uid distribution coefficients
!ustomi$ed 9eports
User%defined stream report# user block reports# applications based on the +ummary File /oolkit
+i$ing and !osting
User cost blocks
/emplates that include the argument list and other useful code for starting a user model are provided in the /emplates directories where Aspen Plus is installed. For more information on how to write a user model# see Aspen Plus User (odels .
Aspen Plus provides several methods for you to create your own unit operation models:
•
Fortran -xcel
•
!"( (odels based on the !AP-%"P-' standard
•
-xported Aspen (odeler flowsheets 5from products such as Aspen
•
!ustom (odeler ™ and Aspen 0ynamics ™6
/hese models can simulate any unit operation model. For each type of model# you write your own program or spreadsheet to calculate the values of outlet streams# based on the specified inlet streams and parameters.
Fortran and Excel Unit Operation Models Fortran unit operation models use a Fortran subroutine to perform the calculations for the model. /hese models may be included in a simulation by using the User or User1 block in Aspen Plus. +ee # !hapter C# for detailed information about Aspen Plus User (odels writing these models. -xcel unit operation models use an -xcel spreadsheet to perform the calculations re*uired by the model. /hese models also use the User1 block in Aspen Plus. +ee Aspen Plus User (odels # !hapter C# for detailed information about writing these models.