Tutorial 1e – C++ limit-state function

In this tutorial we formulate the limit-state function of the problem introduced in Tutorial 1 in a C++ library 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 1e) 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 1e); and the code given in Section 1.4 of Tutorial 1b succeedes all code given in this tutorial (Tutorial 1e).

1   Step by Step Instruction

1.1   Create a C++-library

Step 1:
Download the template for compliling external C++-libraries with Fesslix from Source code downloads.

Step 2:
Replace the content of the file mylib.cpp with:

C++-file mylib.cpp
#if defined(_MSC_VER)
  #include "lsflib4flx_export.h"
#else
  #define LSFLIB4FLX_EXPORT
#endif

extern "C" LSFLIB4FLX_EXPORT const double lsfcall(const double* vp, const int* N) {
  double res(-60.);
  for (int i=0;i<*N;++i) {
   res += vp[i];
  }
  return res;
}

Step 3:
In the file CMakeLists.txt, replace all occurences of cpplib4flx with lsflib4flx.

Step 4:
Configure and compile the source code of the library:

If you work in Linux, go to the directory containing the source code of the library and execute:

Terminal
mkdir build
cd build
cmake ../
make

Finally, you need to copy the library liblsflib4flx.so located in the build-directory to the directory that also contains your Fesslix parameter file.

If you work in Windows, use CMake for configuration. Use your preferred build-environment to compile the code. Make sure to copy the created library lsflib4flx.dll into the directory that contains your Fesslix parameter file.

1.2   Fesslix parameter file

First, we need to load the limit-state function lsfcall from the external C++ library and associate it with function lsf_fun. Depending on whether we work in Linux or Windows, we need to load either a .so-library or a .DLL-library:

Fesslix parameter file
if (is_win) {
  strconst libstr = "lsflib4flx.dll";    # the name of the library in Windows
} else {
  strconst libstr = "liblsflib4flx.so";  # the name of the library in Linux
};
loadlibfun name=lsf_fun, iname=lsfcall, lib=$strconst(libstr);

In a next step, we can define the limit-state function in Fesslix. In the Fesslix parameter file, we define the var-variable lsf as follows:

Fesslix parameter file
var lsf = lsf_fun(tmpx!{
   rbrv_vec_get x: tmpx = "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