External functions

Overview

Some data items in OrcaFlex can vary during the course of a simulation, and this can be achieved in a number of different ways. For example some data items can be specified by a time history or an interpolated table. Sometimes this may not provide sufficient flexibility, and for these cases OrcaFlex allows the data to be externally calculated by an external function that you can write yourself.

With externally calculated variable data, OrcaFlex calls an external function that calculates the value for a variable data item. OrcaFlex provides information on the model and current simulation state, and the external function can use this and additional information to determine the value for a data item. There are two methods for creating external functions, described below.

Python External Functions

Python is a dynamically typed scripting language which offers many advantages, especially to those who feel they do not have the programming experience to use C++. The Python environment takes care of many of the low level programming tasks (such as memory management and type casting), the code is easy to read and it is straightforward to learn. The development cycle (write—test—modify) is short since there is no need to compile and link code. For these reasons Python is a productive language to use with OrcaFlex, and a fairly complex external function can be written in a just few lines of code. See Python External Functions for details on how to write a Python external function and Python interface for details on using Python to interface to OrcaFlex.

Native External Functions

External functions can also be written in C++ or Delphi. Native external functions, however, are far more complex to write than Python external functions. The coder is responsible for memory management tasks, type conversions and compiling the code into a DLL. This means the development cycle is longer and demands more programming experience. The advantage of native external functions is that they offer improved speed over the interpreted Python code so should be used if this is a serious issue. See Native External Functions for more details.

Examples

A number of examples of both Native and Python external functions can be found on the OrcaFlex CD, in the OrcaFlex installation directory or on our website.