External Function Libraries

Top  Previous  Next

When Vensim simulates a model, it makes computations on the model variables and calls to functions when it is appropriate to do so.  Since all model variables are floating point variables, and since all functions return floating point variables, there is not much variety in how functions get called, except in the number of arguments.

External functions are described using a Windows Dynamic Link Library or DLL file (on the Macintosh a dynamically linked library .dylib).  When this DLL is loaded, Vensim requests from it a list of functions and their attributes by calling the user_definition function.  Once this has happened, Vensim recognizes those functions just as it would recognize built in functions.  During model simulation when a model contains an external function, Vensim makes a call to a routine in the DLL called vensim_external passing it information including an index for the function.  The DLL is then responsible for doing the appropriate argument conversion and calling the external function.

You can have more then one external function library, but you can only load one at a time.  The external function library that will be used is shown in the Startup tab of the Global Options dialog accessible from the Tools>Options command.  You can select a new library to change this.  When you change the external function library you should close and reopen any models you are working with.  Each library can have up to 32000 distinct external functions defined.

NOTEBy default Windows hides the names of .dll files so that when you try to select an external function library you may find that the names do not show up in the file selection dialog.  To see .dll files open Windows Explorer and select the Options or Folder Options menu item on the View menu.  There should be a Check Box (possibly on the View tab) to show or not show Hidden and System files. .dll files are considered system files so make a selection that does show those.