Cranium and Synapse provide an internal programming language that enables you to enter new estimation technique models and new constraint functions for use in designs and selections. The code written in this language is entered using the Code Edit dialog.
|The Code control is the large edit box in which you enter code.
|The list of available functions. Some functions are only available for certain model types. For example, the Technique() function is applicable for estimation models but not for design constraint functions.
|The documentation for the selected function.
|The Default Args button inserts default code into the Code edit control. Pressing the Default Args button is typically the first step when entering a new estimation technique.
|The Std Units button displays the standard units for all known properties. All estimation techniques assume input variables, e.g., temperature and pressure, are in standard units and must output property estimates in standard units.
The Insert button a menu listing commands
for inserting common names and values:
|The Compile button compiles the code and reports any errors.
The modeling language used by Cranium and Synapse is easy to learn and use. The language is extremely similar to many of today’s modern programming languages such as C++ and Java. Some of the language's key aspects include:
However, because the modeling language is tailored to the task of physical property estimation there are some differences with conventional languages including:
To further explain the language's concepts, we use the example of entering a new technique to estimate a chemical's critical temperature. The new technique's model is:
The final code is shown in the listing to the right. The following sections document each line of our example code.
The MKS modeling language allows you to specify two types of comments. The double forward slash comment
ignores all following text up to and including the next carriage return. The multiple line comment ignores all text between the characters /* and */.
The declaration section accomplishes the task of declaring all variables before they are used. Cranium and Synapse use four types of variables: double, string, bool and int. The type double is used for all floating point numbers. Almost all computations are performed on variables of type double. The string type is used for all character text. Names of properties, chemicals, mixtures, techniques, and groups are stored in variables of type string. The bool type is used for storing TRUE/FALSE values. Boolean control variables are often needed to direct the logic within models. The int type is used for all integers. Counts and indices are typically stored in variables of type int.
Our example code contains two declaration sections.
These variables are used to store the names of a technique and a chemical. This declaration is part of the "default arguments" section of the code. The default arguments section can be automatically inserted using the Default Args button found in the Code Edit dialog.
The second set of declarations includes the variables we will use to compute our estimate.
You can declare one or more variables in a single statement. You can also have any number of declaration statements. For example, the first declaration statement could be rewritten as two statements.
Cranium allows you to declare one and two dimensional arrays of any type. The syntax of array declaration is the same as a variable declaration followed by a dimensional specification. Dimensional specifications must be integer constants enclosed by brackets.
A declaration can be placed anywhere within a model although it is common to place all declarations near the code’s beginning.
All variable names must start with a letter. Following this starting letter can be any quantity and combination of letters (a through z and A through Z) and numbers (0 through 9).
A string is a sequence of characters surrounded by double quotation marks. Strings are widely used in code as names of chemicals, mixtures, groups, etc.
The MKS modeling language has a number of library functions available for use in models. Some functions return values. Some functions do not return values. Some functions modify their arguments.
The CProp function, shown in the above code, is commonly used and is a good example of library function usage. CProp takes five arguments: a chemical’s name; the name of a physical property; the temperature value; the pressure value; an error variable. CProp returns either a data value or estimate.
In addition to returning a value, a library function may also modify one or more of its arguments. For example, the CProp function takes the error variable, err, as its fifth argument. This variable is assigned an integer value indicating the success of the function. A value of zero indicates no errors occurred.
Many library functions use an error variable to indicate execution success or failure. If no errors occur, the variable is assigned a value of 0. If an error does occur, the variable is assigned a non-zero value. The meaning of this value is documented in the function description shown at the bottom of the Code Edit dialog.
If-then-else statements have two general forms:
The test must evaluate to either TRUE or FALSE. If the test evaluates to TRUE then expression1 is executed. If the test evaluates to FALSE then expression1 is skipped and the else clause’s expression2 is executed if it is present.
The expressions contained within an if-then-else statement can themselves be if-then-else statements.
Multi-statement expressions must be enclosed in braces.
All models produce two values. One value is a number representing either a property estimate, an estimation error or a constraint function value. The SetResult function assigns this value. The other value returned is either TRUE or FALSE indicating the model's applicability or its successful execution. The return statement assigns this value.
Typically a model will have only one SetResult function and several return statements. However, there is no restriction on the number of SetResult functions which may occur within a model.
Iteration or looping is a very common operation in estimation techniques. Many techniques iterate through all groups in a molecular structure or all components in a mixture. The MKS modeling language provides two iteration statements.
The for statement has the general form:
The initialize clause assigns the starting value to the iteration variable. The test clause is executed before each iteration to determine if the loop should continue. The increment clause is executed after each iteration to prepare the iteration variable for the next loop. For example, the following code collects and totals group contributions.
In this example, i is the iteration variable and n is the number of groups. The code iterates for each group exiting once all n groups have been processed. The error variable is checked on each iteration. If any group does not have a contribution (error varaible not equal to 0), the code exits returning FALSE indicating failure.
The while statement is very similar to the for statement. The while statement has the general form:
The iteration continues executing the expression until the test clause evaluates to FALSE. Rewriting the previous example using while would result in the following code.
In the documentation for the Text Export Dialog, a new model for the critical temperature was developed using the regression tools of Microsoft Excel.
The following steps detail how to create a new estimation technique based upon this new equation.
The Technique() function returns the name of the technique to which code belongs. This name is used by other functions for retrieving parameters, groups and contributions. Similarly, the Chemical() function returns the name of the chemical currently being estimated. This name is used by other functions for retrieving property values and molecular structure.
Note that we test the CProp function's error variable. If the function could not retrieve a value for the normal boiling point, the value of the variable err will equal zero. If err is equal to zero then the model returns FALSE stopping the execution.
Cranium and Synapse check all internal operations. If an improper operation is performed, e.g., a division by zero, the execution of the model is stopped and a value of FALSE is returned.
Many published estimation techniques generate estimates in non-standard units. For these techniques it is best to develop the model as published. Then, just before you assign the result using the SetResult function, convert the estimate to standard units. For example:
When you press the Code Edit dialog's Save button or Test button, Cranium and Synapse will compile the code and report any errors detected. These detected errors are displayed in the Code Error dialog.
Note that the boiling point variable, "tbb", is misspelled. The variable should be "tb" as specified in the declarations.
|Getting Started using Synapse
|provides a quick tour of Synapse's capabilities including examples of chemical product design.
|Getting Started using Cranium
|provides a quick tour of Cranium's capabilities including a discussion of structure editing.
|Estimating Chemical Properties
|a short video demonstrating how to estimate the physical properties of chemicals using either Synapse or Cranium.
|Estimating Mixture Properties
|a short video demonstrating how to estimate the physical properties of mixtures using either Synapse or Cranium.