External interfaces » advanced in-line coding in Strurel

STRUREL supports the following five external engines: Matlab, Python, Maple, Mathematica and Ruby. In previous posts, we discussed exemplarily for Matlab and Python how in-line code and external scripts can be evaluated with STRUREL. In case computational performance matters, external scripts should be preferred over in-line code, as in-line code needs to be re-processed each time a limit-state function is evaluated.

Nevertheless, for testing purposes you might prefer to simply work with in-line code in STRUREL. For multi-line code, you can split-up your code as is shown in the following Python-based example:

FLIM(1) = pythonf("%import math")
+ pythonf("%A=math.sqrt(R)")
+ pythonf("R-S+A")

Note that the individual pythonf-calls are connected by a ‘+’. However, except for the actual limit-state function call R-S+A, all code-lines start with a ‘%’. This character is interpreted by STRUREL and not forwarded to the external engine (Python in the example above). The ‘%’ at the beginning of a code line tells STRUREL that the associated line of code does NOT return a value. In the example above, both R and S are random variables defined through STRUREL.

How to use in-line Python in Strurel

Did you know? You can use in-line Python functions directly in a symbolic expression in STRUREL.

For example, assume a problem for which you have the two random variables R and S in your stochastic model, where R represents the resistance of a system of interest and S is the system load. The symbolic expression for the corresponding limit-state function in the native syntax of STRUREL would be:

FLIM(1) = R-S

However, if you have Python installed on your system and if the Python interface of Strurel is configured correctly, you could also use the following expression:

FLIM(1) = pythonf("R-S")

Sure, calling the Python interpreter for this simple demonstration example is like taking a sledgehammer to crack a nut. However, the interface-function pythonf is a tool that gives you access to the full power of Python directly in the symbolic expression of Strurel.