Tutorial 1d – Python limit-state function

In this tutorial we formulate the limit-state function of the problem introduced in Tutorial 1 in Python and use Fesslix to perform the reliability analysis. Subset Simulation is employed to estimate the probability of failure.

This tutorial is based on Tutorial 1b. Please perform Tutorial 1b before you start with this tutorial. The code given in this tutorial (Tutorial 1d) replaces the code given in Section 1.3 of Tutorial 1b. The code given in Sections 1.1 and 1.2 of Tutorial 1b precedes all code given in this tutorial (Tutorial 1d); and the code given in Section 1.4 of Tutorial 1b succeedes all code given in this tutorial (Tutorial 1d).

For this tutorial you must have a 64-bit version of Python 2.7 installed on your system. You can download the latest 2.7 release from here: https://www.python.org/downloads/windows/.

1   Step by Step Instruction

1.1   Python file

We begin with expressing the limit-state function in Python. We create a file tutorial_1d_lsf.py with content:

Python code "tutorial_1d_lsf.py"
import flx;

def PyLSF():
  res = -60.
  for i in flx.vec('rv_vec'):
   res = res + i
  return res

What is done in this file? First, we load the module flx. This module provides an interface that allows us retrieving data from the current Fesslix session. In the function above, we use the function flx.vec to retrieve a tuple from Fesslix that contains the components of vector rv_vec.

1.2   Fesslix parameter file

First, we need to load the Python interface in Fesslix:

Fesslix parameter file
loadlib "python";

Next, we link the Python function PyLSF in file tutorial_1d_lsf.py to Fesslix as FlxFunction lsf_fun.

Fesslix parameter file
# add current path to Python search path
  python_path $pwd();
# load the module 'tutorial_1d_lsf'
  python_module tutorial_1d_lsf;
# link the Python function to Fesslix
  python_fun lsf_fun = tutorial_1d_lsf.PyLSF;

Now, we can link the Python limit-state function to Fesslix. In the Fesslix parameter file, we define the var-variable lsf as follows:

Fesslix parameter file
var lsf = objexec(lsf_fun(),{
   rbrv_vec_get x: rv_vec = "RVS";

where objexec is a function that executes the code in curly brakes before it evaluates function lsf_fun, and rbrv_vec_get retrievs a vector containing the realizations of all all random variables in the set RVS and assigns it to vector rv_vec.

2   The complete input files of this tutorial

fesslix.org – Home  |  Contact  |  Impressum  |  © 2015-2017 Wolfgang Betz