CHEMCAD CALCULATOR/PARSER MODULE

[Pages:38]CHEMCAD CALCULATOR/PARSER MODULE

GENERAL INFORMATION The Calculator/Parser module in CHEMCAD is a powerful utility module, which offers the power and flexibility of the high level C-like language without having to use a compiler. The module allows the user to do the following things:

? Create your own unit operation within a flowsheet. ? Retrieve stream/equipment/component information in a flowsheet. ? Perform mathematical calculation. Most mathematical functions are built into the standard library. ? The "for statement" for loop calculation, the "if else" statement for information control and the

"goto" statement are allowed in the module. ? All flash functions, physical property routines and many other useful functions can be called to

perform necessary calculations. ? Print the calculated results by the "printf" statement. ? Put the calculated results back to the flowsheet. Typical applications of the calculator/parser module include: ? Calculate stream compositions or property for use by the controller. ? Calculate size/cost of process equipment. ? Calculate the flowrate of the makeup streams for better convergence. ? Simulate a special unit operation as required. The usefulness of the module is limited only by the imagination of the user.

COSTING CALCULATIONS

All of the cost calculating routines in CHEMCAD are done using the Parser language described here. This is to enable users to modify the costing routines for their own use. The source code for these calculations is stored in the CHEMCAD program directory (typically C:\CC5) and have the following names:

$$$aclr.sf $$$cfug.sf $$$comp.sf $$$crsh.sf $$$crys.sf $$$cycl.sf $$$dpip.sf $$$evap.sf $$$expn.sf

Air cooled heat exchanger costing Centrifuge costing Compressor costing Crusher costing Crystallizer costing Cyclone costing Double pipe heat exchanger costing Evaporator heat exchanger costing Expander costing

1

Calculator/Parser Module

$$$fire.sf $$$flas.sf $$$fltr.sf $$$htxr.sf $$$pump.sf $$$rfrg.sf $$$scds.sf $$$scre.sf $$$towr.sf $$$tpls.sf $$$vesl.sf

Fired heater costing Flash (vessel) costing Filter costing Shell and tube heat exchanger costing Pump costing Refrigeration costing SCDS distillation column costing Screen costing TOWR distillation costing TPLS distillation costing Vessel costing

CHEMCAD Version 5.1

DIALOG BOXES FOR PARSER UNITS

If your CALC unitop needs to use a dialog screen, it must be built according to the Screen Builder manual and documentation. Please see the screen builder documentation for more details.

For a Parser unit op, the screen files will be named in the same format as the program file, as "CALC#.MY" and "CALC#.MAP" where # is the unit ID number. For example, if your unit id number is 5, then the files would be named "calc5.my" and "calc5.map". Please see the screen builder section of this manual for more details on these files.

PARSER LANGUAGE SYNTAX AND STRUCTURE

The Calculator/Parser module uses a C-like language to perform all calculations. It is recommended that the user be familiar with some of the basic C language syntax before writing the code for this module. Several examples at the end of this chapter should be studied before you proceed.

Data types:

int float double

integer floating point real numbers double precision real numbers

Examples:

int double float

i, j, k; x, y, z; a, b, c;

Both one dimensional array and two dimensional arrays are supported.

Examples:

int double float float

ix[100]; x[50]; uspec[300]; matirx[10][10];

2

CHEMCAD Version 5.1

Intrinsic functions:

+ * / exp log log10 pow(x,y) fabs abs sqrt sin cos tan asin acos atan == > >= < 20. ) a = 1.;

- if( expression ) { expressions; }

Example:

a = 0.; b = 0.; if( x > 20. ) {

a = 1.; b = 2.; }

- if( expression) { expressions; } else if( expression ) { expressions; } else if( expression ) { expressions; } else { expressions; }

Example:

a = 0.; b = 0.; if( x > 10. ) {

4

CHEMCAD Version 5.1

CHEMCAD Version 5.1

a = 1.; b = 1.; } else if( x > 20. ) { a = 2.; b = 2.; } else if( x > 30. ) { a = 3.; b = 3.; } else { a = 4.; b = 4.; }

Note: Nested "if else" up to two levels are allowed.

Example:

if( a > (b * 23.)) {

if( c > 25. ) {

..... } } else { .... }

Calculator/Parser Module

- goto LABEL;

Example:

x = 23 * y; if( x > 100. ) goto THERE; .... ... THERE: ...

Note: The goto statement can only be used to jump to the statement below to goto line. It cannot be used to jump back to the previous statement.

5

Calculator/Parser Module

CHEMCAD Version 5.1

printf statement

printf statement can be used similar to the C language. Up to 5 arguments can be included in one printf statement.

For debugging purpose, it is recommended that the user use the "Generate Run History" checkbox on the "Convergence" screen of the "Run" menu so that the printf and any error messages can be seen on the screen when you run the calculator module.

Example:

printf("Calculate area = %g, heat duty = %g\n",area,duty); printf("Stream %d, Temperature = %13.2f\n",str_ID,temp);

Return Values of the Arguments:

In the standard C syntax, the return value of an argument in a function call should be passed by the address. This is omitted in the calculator module as illustrated by the following example.

Standard C:

ProgramX() {

float input_data; float output_data;

/* Notice the address sign (&) for the output data */

functionX(input_data,&output_data);

}

CHEMCAD Calculator:

CHEMCAD_Link Program_Name {

float input_data; float output_data;

/* Notice the address sign (&) is omitted here */

functionX(input_data,output_data); }

PROGRAM STRUCTURE A program file has to be created in the job subdirectory with the file name CALC#.TXT where # is the equipment ID number of the calculator. For example, if the calculator number is 5, you need to write a program CALC5.TXT and put this file in your job subdirectory. The program file has to have the following structure:

CHEMCAD_Link Program_Name {

/* Section 1 : Variable declarations */ ..... ;

6

CHEMCAD Version 5.1

Calculator/Parser Module

..... ; /* Sections 2: Perform all calculations */ ..... ; ..... ; }

Creating a dialog screen for a Parser (Calculator) unit op

If your unit has any settings, such as output pressure for a pump or # of stages for a distillation column, you will need to generate a dialog box. The construction of dialogs is covered in the Screen Builder section of this manual.

For a Parser unit op, the screen files will be named in the same format as the program file, as "CALC#.MY" and "CALC#.MAP" where # is the unit ID number. For example, if your unit id number is 5, then the files would be named "calc5.my" and "calc5.map". Please see the screen builder section of this manual for more details on these files.

7

Calculator/Parser Module

CHEMCAD Version 5.1

CHEMCAD LIBRARY FUNCTIONS The following functions may be accessed from a Parser unit. They fall into the general categories of:

Flowsheet Interface: Functions to move data from the flowsheet into the calculator and back Thermodynamics/Engineering Calcs Functions used to calculate properties of mixtures

FLOWSHEET INTERFACE FUNCTIONS: These functions are used to pass information into the calculator function and back. CC_Get_Equip_Parameters-returns the unitop array for a specified unit CC_Put_Equip_Parameters-overwrites the unitop array for a specified unit CC_Get_Process_Stream-returns a flowsheet stream data CC_Put_Process_Stream-overwrites a flowsheet stream with new data CC_Get_Input_Stream-returns stream data for a stream connected to the Calculator unit's inlet CC_Put_Inlet_Stream-overwrites the stream data for a stream connected to the Calculator unit's inlet CC_Get_Outlet_Stream-returns stream data for a stream connected as an outlet to the Calculator unit. CC_Put_Outlet_Stream-overwrites the stream data for a stream connected to the Calculator unit's outlet CC_No_Of_Components-returns the number of components CC_Int_Array_Function-returns an array of flowsheet information CC_Get_Stream_Property-returns a property of a given stream CC_Get_Value-generic interface to pure component, stream and unit data Function: CC_Get_Equip_Parameters Get equipment parameters for a specified equipment ID number. Prototype: int CC_Get_Equip_Parameters(int id, float uspec[]) Parameters: input id equipment ID if id = 0, the current (active) equipment parameters in the memory will be retrieved. output uspec[] an array stores all parameters for the specified equipment Return Value:

8

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download