© 2024 Jasper van Baten, AmsterCHEM

SciLab script

The calculations performed by the unit operations are defined by SciLab script. You can enter the script by editing the unit operation, and select Script on the SciLab tab.

The SciLab script is run in a fresh SciLab environment, in which useful global variables and functions are predefined. The script should:

Catching errors

The SciLab script will be run, such that SciLab exits when an error is encountered. The error will be reflected in the calculation results of the unit operation. If you need to catch errors inside SciLab script without exiting, please use try, catch (mind that a problem with SciLab is that it may get stuck when a syntax error is present inside a try, catch block).

If the simulation appears to be stuck, it is possible that SciLab is not responding or waiting for user input. If this is the case, use the Windows Task Manager to end the SciLex.exe process.

DOs and DON'Ts

Do

Don't

Testing

To test your SciLab input, make sure the ports are connected. Then, while writing the script, click the Test button for feedback.

Editing

You can edit the input in the text field inside the window, or click the Edit button to open an editor. The default editor is notepad.exe, but you can select a different editor by holding down the Ctrl button when clicking Edit.

The SciLab Unit Operation dialog will block until you close the editor.

Help

Clicking Help will open the online help for the latest SciLab. Alternatively, you can start SciLab from the Start Menu, and click Help in the Help menu.

Example

Example script for a simple adiabatic mixer with two feeds and one product:

f1=getFeedProp(1,"flow")
f2=getFeedProp(2,"flow")
h1=getFeedProp(1,"enthalpy")
h2=getFeedProp(2,"enthalpy")
p1=getFeedProp(1,"pressure")
p2=getFeedProp(2,"pressure")
p=min(p1,p2)
f=f1+f2
h=(h1*f1+h2*f2)/f
totF=sum(f)
setProduct(1,totF,f/totF,"pressure",p,"enthalpy",h)

(This particular script does not take into account that the total flow may be zero; it will fail in this case).

INDEX
Acknowledgements
Additional files
Boolean parameters
Calculation
compNames
Dimensionality
Disclaimer
DOs and DONTs
Error trapping
Examples
Feeds
Files
Formulas
Function reference
getAggregationState
getAggregationStateName
getCompoundConstant
getEquilibrium
getEquilibriumProperty
getFeedEquilibrium
getFeedProp
getNumberOfFeeds
getNumberOfProducts
getParameter
getPDependentProperty
getPropertyUnitOfMeasure
getSinglePhaseProperty
getTDependentProperty
getTwoPhaseProperty
getUnitOperationName
Global variables
Integer parameters
License
Loading models
logMessage
Model files
nComp
nPhase
Parameters
phaseAggregationStates
phaseNames
Products
Real parameters
Reports
Requirements
Saving models
SCI files
setParameter
setProduct
setReport
String parameters
SUM files
Welcome
CONTENT
 Welcome
 Feed and product ports
 Parameters
 Reports
 SciLab Calculation Script
 Additional files
 Global variables
 Function reference
 Saving and loading models
 License and disclaimer