Vous êtes sur la page 1sur 20

Using Fortran in Aspen Plus

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:

In Fortran Calculator blocks


On the Fortran sheets of other blocks, such as design
specifications, sensitivity or optimization problems

In external Fortran subroutines

Fortran Calculator blocks:

Contain Fortran expressions used to perform user-defined tasks


Can 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. If the status indicator
on a Fortran sheet is
, use Next 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 customization of the models through
the use of these external user subroutines. For more information on
external user subroutines, see Aspen Plus User Models.
Aspen Plus can interpret most in-line Fortran. Fortran that cannot be
interpreted is compiled and dynamically linked to the Aspen Plus
module. Because dynamic linking is used, the overhead for in-line
Fortran requiring compilation is small.
Note: If the Fortran cannot be interpreted, a Fortran compiler is
needed. See chapter 1 of Aspen Plus User Models for information on
supported compilers and on configuring Aspen Plus to use your
compiler.

About Calculator Blocks


Calculator blocks let you insert Fortran statements or Excel
spreadsheets into flowsheet computations to perform user-defined
tasks.

Since Aspen Plus is a sequential modular simulator that executes one


unit operation at a time, you must specify where in the sequence of
unit operations each Calculator block is to be executed. You can do
this by specifying one of these:

Which flowsheet variables are Imported from and Exported to


Aspen Plus by the Calculator block
The position of the Calculator block in the list of unit
operation blocks

Define a Calculator block by:


1. Creating the Calculator block.
2. Identifying the flowsheet variables that the block samples or
manipulates.
3. Entering the Excel formulas or Fortran statements.
4. Specifying when the Calculator block is executed.
Note: Variables changed by a Calculator will remain at their last
values at the start of the next run if you do not reinitialize the
problem. If you modify the problem so that these variables are no
longer changed, the old changed variables will retain their last
values from the Calculator (rather than values previously specified
on other forms) until otherwise changed or reinitialized.

Creating a Calculator Block Using Fortran

To create a Fortran Calculator block:


1. From the Data menu, point to Flowsheeting Options,
then Calculator.
2. In the Calculator Object Manager, click New.
3. In the Create New ID dialog box, enter an ID or accept
the default, and click OK.
4. On the Calculate sheet, select Fortran (default).

Using Fortran in Calculator Blocks


Calculator blocks let you insert Fortran statements into flowsheet
computations to perform user-defined tasks, such as:

Calculating and setting input variables before they are used


(feedforward control)
Writing information to the Control Panel

Reading input from a file

Writing results to the Aspen Plus report or to any external


file

Calling external subroutines

Writing your own user models

Define a Fortran Calculator block by:


1. Creating the Calculator block.
2. Identifying the flowsheet variables that the block samples or
manipulates.
3. Entering the Fortran statements on the Calculate sheet.
4. Specifying when the Calculator block is executed.

About Calculator Blocks


Calculator blocks let you insert Fortran statements or Excel
spreadsheets into flowsheet computations to perform user-defined
tasks.
Since Aspen Plus is a sequential modular simulator that executes one
unit operation at a time, you must specify where in the sequence of
unit operations each Calculator block is to be executed. You can do
this by specifying one of these:

Which flowsheet variables are Imported from and Exported to


Aspen Plus by the Calculator block

The position of the Calculator block in the list of unit


operation blocks

Define a Calculator block by:


1. Creating the Calculator block.
2. Identifying the flowsheet variables that the block samples or
manipulates.
3. Entering the Excel formulas or Fortran statements.
4. Specifying when the Calculator block is executed.
Note: Variables changed by a Calculator will remain at their last
values at the start of the next run if you do not reinitialize the
problem. If you modify the problem so that these variables are no
longer changed, the old changed variables will retain their last
values from the Calculator (rather than values previously specified
on other forms) until otherwise changed or reinitialized.

Creating a Calculator Block Using Fortran


To create a Fortran Calculator block:
1. From the Data menu, point to Flowsheeting Options, then
Calculator.
2. In the Calculator Object Manager, click New.
3. In the Create New ID dialog box, enter an ID or accept the
default, and click OK.
4. On the Calculate sheet, select Fortran (default).

Using the Fortran Sheet


To enter executable Fortran statements on the Fortran sheet:
1. On the Design Spec form, click the Fortran sheet.
2. Use Help to review rules and restrictions for in line Fortran.
3. Enter your Fortran statements.

To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined
Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

To enter executable Fortran statements on the Fortran sheet:


1. On the Optimization or Constraint form, click the Fortran tab.
2. Review the rules and restrictions for in line Fortran
3. Enter your Fortran statements.
To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined
Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

Using the Calculate Sheet to Enter Fortran Statements


To enter executable Fortran statements on the Calculate sheet:
1. Click the Calculate tab on the Calculator Input form.
To review rules and restrictions for in line Fortran, see Rules for
In-Line Fortran Statements.
2. Enter your Fortran statements.
3. To ensure that you enter accurate variable names, click the
right mouse button. In the popup menu, click Variable List.
The Defined Variable List window appears. You can drag and drop the
variables from the Defined Variable List to the Calculate sheet.

Using the Sensitivity Input Fortran Sheet


To enter executable Fortran statements on the Fortran sheet:
1. On the Sensitivity Input form, click the Fortran sheet.
2. Review the rules and restrictions for in line Fortran

3. Enter your Fortran statements.


To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined
Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

Rules for In-Line Fortran Statements


To achieve successful compilation of your Fortran statements, follow
these rules:

By default, variables beginning with A through H, or O through


Z, are double precision real. Variables beginning with I
through N are integer. Use double precision functions (for
example, DSQRT) and double precision constants (for example,
1D0).
Do not use variable names beginning with IZ or ZZ.
Because Fortran is column-sensitive, this table shows how to do
certain things:

To do this
Use
Indicate comments
Column one for C and leave column two blank
Enter statement labels Only columns three, four, and five
Begin executable
Column seven or beyond
statements
You can call your own subroutines or functions. You can use
labeled or blank (unlabeled) COMMON blocks.
Fortran variables you define on the Specification sheet cannot
be placed in a COMMON.
Do not use IMPLICIT, SUBROUTINE, ENTRY, RETURN, END statements,
nor arithmetic statement functions.
READ and WRITE statements to numbered file units (as in WRITE
(NTERM,*)) 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 Intel Fortran compiler to
open its built-in units for the report file, history file, and
control panel. See Chapter 1 of Aspen Plus User Models for more
information.

About the Interpreter


By 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 (DLL). A Fortran
compiler is needed for compiling the code. It is possible to compile
all of the Fortran by selecting Write Inline Fortran to a
Subroutine to be Compiled and Dynamically Linked on the Setup |
Simulation Options | System sheet.
The following Fortran can be interpreted:

DABS
DACOS
DASIN
DATAN
DATAN2
DCOS
DCOSH
DCOTAN

All declarations besides COMMON statements


Arithmetic expressions and assignment statements
IF statements
GOTO statements, except assigned GOTO
WRITE statements that use the built-in unit number variables
NTERM, NRPT, or NHSTRY. (Note: If these statements appear in
code that is compiled, you must use the Intel Fortran compiler.
See chapter 1 of Aspen Plus User Models for more information.)
FORMAT statements
CONTINUE statements
DO loops
Calls to these built-in Fortran functions:
DERF
DEXP
DFLOAT
DGAMMA
DLGAMA
DLOG
DLOG10
DMAX1

DMIN1
DMOD
DSIN
DSINH
DSQRT
DTAN
DTANH
IABS

IDINT
MAX0
MIN0
MOD

You can use the equivalent single precision or generic function names
in your Fortran statements. However, Aspen Plus always performs
double precision calculations, and using the other names will require
compilation.
If you use the following statements, you must enter them on the
Declaration sheet:

REAL or INTEGER statements


DOUBLE PRECISION statements
DIMENSION statements

COMMON statements

The following statements require compilation:


CALL
CHARACTER
COMMON
COMPLEX
DATA

ENTRY
EQUIVALENCE
IMPLICIT
LOGICAL
PARAMETER

PRINT
RETURN
READ
STOP
SUBROUTINE

Rules for In-Line Fortran Statements


To achieve successful compilation of your Fortran statements, follow
these rules:

By default, variables beginning with A through H, or O through


Z, are double precision real. Variables beginning with I
through N are integer. Use double precision functions (for
example, DSQRT) and double precision constants (for example,
1D0).
Do not use variable names beginning with IZ or ZZ.
Because Fortran is column-sensitive, this table shows how to do
certain things:

To do this
Use
Indicate comments
Column one for C and leave column two blank
Enter statement labels Only columns three, four, and five
Begin executable
Column seven or beyond
statements
You can call your own subroutines or functions. You can use
labeled or blank (unlabeled) COMMON blocks.
Fortran variables you define on the Specification sheet cannot
be placed in a COMMON.
Do not use IMPLICIT, SUBROUTINE, ENTRY, RETURN, END statements,
nor arithmetic statement functions.
READ and WRITE statements to numbered file units (as in WRITE
(NTERM,*)) 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 Intel Fortran compiler to
open its built-in units for the report file, history file, and

control panel. See Chapter 1 of Aspen Plus User Models for more
information.

Entering Optional Fortran Statements


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 Spec and Vary sheets. Fortran
statements are needed only if the functions involved are too complex
to enter on the Spec and Vary sheets.
You can enter Fortran statements:

On the Fortran sheet


In your text editor (for example, Notepad), and then copy and
paste them onto the Fortran sheet

Enter Fortran declarations in the same way as executable Fortran


statements, using the Declarations sheet instead of the Fortran
sheet.
You can include any Fortran declarations in a Design Spec block, such
as:

Include statements
COMMON definitions

DIMENSION definitions

Data type definitions (INTEGER and REAL)

If a Fortran variable meets one of these criteria, you should place


it in a COMMON:

It is also used by another block.


Its value must be retained from one iteration of a block to
another.

Fortran variables that you defined on the Specification sheet should


not be declared on the Declarations sheet.

Entering Fortran Statements and Declarations


You can enter Fortran statements:

On the Calculate sheet


In your text editor (for example, Notepad), and then copy and
paste them onto the Calculate sheet

Click the Fortran Declarations button to enter Fortran declarations


in the Declarations dialog box, in the same way you enter executable
Fortran statements on Calculate sheet.
You can include any Fortran declarations in a Calculator block, such
as:

Include statements
COMMON definitions

DIMENSION definitions

Data type definitions (INTEGER and REAL)

If a Fortran variable meets one of these criteria, you should place


it in a COMMON:

It is also used by another block.


Its value must be retained from one iteration of a Calculator
block to another.

Fortran variables that you defined on the Define sheet should not be
declared in the Declarations dialog box.

Fortran Declarations
You enter Fortran declarations in the same way as executable Fortran
statements, using the Declarations sheet instead of the Fortran
sheet.
You can include any Fortran declarations in an optimization problem,
including:

COMMON definitions
DIMENSION definitions

Data type definitions (INTEGER and REAL)

If a Fortran variable meets one of these criteria, you should place


it in a COMMON:

It is also used by another block.


Its value must be retained from one iteration of an
optimization problem to another.

Fortran variables that you defined on the Define sheet should not be
declared on the Declarations sheet.

Disabling Syntax Checking


By 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.
To turn off Fortran syntax checking:
1. From the Tools menu, click Options.
2. Ensure the Check Inline Fortran for Syntax Errors checkbox is
clear.

Fortran and Excel Unit Operation Models


Fortran unit operation models use a Fortran subroutine to perform the
calculations for the model. These models may be included in a
simulation by using the User or User2 block in Aspen Plus. See
Aspen Plus User Models, Chapter 5, for detailed information about
writing these models.
Excel unit operation models use an Excel spreadsheet to perform the
calculations required by the model. These models also use the User2
block in Aspen Plus. See Aspen Plus User Models, Chapter 5, for
detailed information about writing these models.

About External Fortran Subroutines


External user Fortran is an open and extensive customization
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:
External Fortran
Application Types
User Unit Operation
Models
Kinetic Models

Use

Units not represented by Aspen Plus unit


operation models
Reactors, Reactive Distillation, Pressure
Relief
Physical Property Models Pure and mixture, activity models, KLL, user
equations-of-state
Stream Properties
Special properties to be calculated for a
stream
Unit Operation
Reactor heat transfer, column hydraulics,
Customization
LMTD correction, pressure drop, liquidliquid distribution coefficients
Customized Reports
User-defined stream report, user block
reports, applications based on the Summary
File Toolkit
Sizing and Costing
User cost blocks
Templates that include the argument list and other useful code for
starting a user model are provided in the Templates directories where
Aspen Plus is installed. For more information on how to write a user
model, see Aspen Plus User Models.

Using Fortran in Aspen Plus


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:

In Fortran Calculator blocks


On the Fortran sheets of other blocks, such as design
specifications, sensitivity or optimization problems

In external Fortran subroutines

Fortran Calculator blocks:

Contain Fortran expressions used to perform user-defined tasks


Can 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. If the status indicator
on a Fortran sheet is
, use Next 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 customization of the models through
the use of these external user subroutines. For more information on
external user subroutines, see Aspen Plus User Models.
Aspen Plus can interpret most in-line Fortran. Fortran that cannot be
interpreted is compiled and dynamically linked to the Aspen Plus
module. Because dynamic linking is used, the overhead for in-line
Fortran requiring compilation is small.
Note: If the Fortran cannot be interpreted, a Fortran compiler is
needed. See chapter 1 of Aspen Plus User Models for information on
supported compilers and on configuring Aspen Plus to use your
compiler.

Writing to the Screen and Aspen Plus Files


In Fortran WRITE statements, you can use the following predefined
variables for the unit number:
Unit
NTERM

NRPT
NHSTRY

Destination
Control Panel (if running from the user
interface)
Terminal (if running interactively
outside of the user interface), or
Log file (if running batch)
Aspen Plus report
Simulation history

Examples:
For writing to the Control Panel, enter:

WRITE(NTERM, *) A, B, C, X
For writing to the report file, enter:
WRITE(NRPT, *) A, B, C, X
If writing to the Aspen Plus report from a Fortran Calculator block,
select Report in the Execute field on the Sequence Sheet. Output
written to the report file will appear in the Flowsheet section of
the Calculator block report.
When writing to a user-defined file, use a Fortran unit number
between 50 and 100.
Writing to the predefined Aspen Plus units will only work in compiled
Fortran if the Fortran is compiled with the Intel compiler. Writing
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. See Chapter 1 in Aspen Plus User Models for more
information.
Excel Calculator blocks do not have the ability to write to the
Control Panel or Aspen Plus report or history files, but you may use
VBA macros to display information in dialog boxes.

Using the Fortran Sheet


To enter executable Fortran statements on the Fortran sheet:
1. On the Design Spec form, click the Fortran sheet.
2. Use Help to review rules and restrictions for in line Fortran.
3. Enter your Fortran statements.
To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined
Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

To enter executable Fortran statements on the Fortran sheet:


1. On the Optimization or Constraint form, click the Fortran tab.
2. Review the rules and restrictions for in line Fortran
3. Enter your Fortran statements.
To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined

Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

Using the Sensitivity Input Fortran Sheet


To enter executable Fortran statements on the Fortran sheet:
1. On the Sensitivity Input form, click the Fortran sheet.
2. Review the rules and restrictions for in line Fortran
3. Enter your Fortran statements.
To ensure that you enter accurate variable names, click the right
mouse button. In the popup menu, click Variable List. The Defined
Variable List window appears. You can drag and drop the variables
from the Defined Variable List to the Fortran sheet.

Fortran Variable Diagnostic Message Levels


The message levels for Fortran variable diagnostics are:
Level
0..4
5
6..8

Description
No messages
Defined-variable values before block
execution are listed
Level 5 and defined-variable values after
block execution are listed

Flowsheet Connectivity for User

Material Streams
inlet One to four inlet material streams
outlet One to four outlet material streams
Heat Streams
inlet One heat stream (optional)
outlet One heat stream (optional)
Work Streams
inlet One work stream (optional)
outlet One work stream (optional)

Specifying User
You must specify the name of the subroutine model on the Input
Specifications sheet. You have the option of specifying:

A report subroutine name


Size of the integer and real arrays (INT and REAL) passed to
the user model subroutine

Values of the integer and real arrays passed to the user model
subroutine

Length of integer and real workspace vectors

Thermodynamic conditions of each outlet stream

Type of flash calculations (vapor, liquid, two-phase, threephase)

For information on writing Fortran subroutines for user models, see


Aspen Plus User Models reference manual.

User Reference
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 User2 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. User2 has no limits on the number of inlet and outlet
streams.

Working with User


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 User2 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. User2 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 To do this
Input
Specify name and parameters for user subroutine,

BlockOptions

Results

calculation options, and outlet stream


conditions and flash convergence parameters
Override global values for physical properties,
simulation options, diagnostic message levels,
and report options for this block
View summary of User results and material and
energy balances

Specifying User
You must specify the name of the subroutine model on the Input
Specifications sheet. You have the option of specifying:

A report subroutine name


Size of the integer and real arrays (INT and REAL) passed to
the user model subroutine

Values of the integer and real arrays passed to the user model
subroutine

Length of integer and real workspace vectors

Thermodynamic conditions of each outlet stream

Type of flash calculations (vapor, liquid, two-phase, threephase)

For information on writing Fortran subroutines for user models, see


Aspen Plus User Models reference manual.

About External Fortran Subroutines


External user Fortran is an open and extensive customization
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:
External Fortran
Application Types
User Unit Operation
Models
Kinetic Models

Use

Units not represented by Aspen Plus unit


operation models
Reactors, Reactive Distillation, Pressure
Relief
Physical Property Models Pure and mixture, activity models, KLL, user
equations-of-state
Stream Properties
Special properties to be calculated for a
stream
Unit Operation
Reactor heat transfer, column hydraulics,
Customization
LMTD correction, pressure drop, liquidliquid distribution coefficients
Customized Reports
User-defined stream report, user block
reports, applications based on the Summary
File Toolkit
Sizing and Costing
User cost blocks
Templates that include the argument list and other useful code for
starting a user model are provided in the Templates directories where
Aspen Plus is installed. For more information on how to write a user
model, see Aspen Plus User Models.

User Models
Aspen Plus provides several methods for you to create your own unit
operation models:

Fortran
Excel

COM Models based on the CAPE-OPEN standard

Exported Aspen Modeler flowsheets (from products such as Aspen


Custom Modeler

and Aspen Dynamics )

These 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. These models may be included in a
simulation by using the User or User2 block in Aspen Plus. See
Aspen Plus User Models, Chapter 5, for detailed information about
writing these models.
Excel unit operation models use an Excel spreadsheet to perform the
calculations required by the model. These models also use the User2
block in Aspen Plus. See Aspen Plus User Models, Chapter 5, for
detailed information about writing these models.

Vous aimerez peut-être aussi