Skip to content
Snippets Groups Projects
Code owners
Assign users and groups as approvers for specific file changes. Learn more.

Stochastic Finite Element Method (SFEM)

License: CC BY 4.0 MOAMMM

This repository contains:

  • A spectral generator of random fields (RF) 1.
  • Scripts to vizualize of the random fields.
  • 2 test cases of random fiels generation and 1 test case of Monte-Carlo (MC) stochastic finite element simulations (SFEM).

Table of Contents

  1. Dependencies and Prerequisites
  2. Structure of Repository
  3. Example of application

Dependencies and Prerequisites

python - >=3.11 pandas - >=1.5.3 PyTorch - >=2.10 matplotlib - >-3.5.2

  • Python, pandas, matplotlib, texttabble and latextable are pre requisites for visualizing and navigating the data.

  • For generating mesh and for vizualization, gmsh (www.gmsh.info) is required.

  • For running simulations, cm3Libraries (http://www.ltas-cm3.ulg.ac.be/openSource.htm) is required.

Instructions using apt & pip3 package manager

Instructions for Debian/Ubuntu based workstations are as follows.

python, pandas and dependencies

 sudo apt install python3 python3-scipy libpython3-dev python3-numpy python3-pandas

matplotlib, texttabble and latextable

 pip3 install matplotlib texttable latextable

Pytorch (only for run with cm3Libraries)

 pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu

Structure of Repository

  • generateRF contains all the scripts used to generate and vizualize the random fields
  • cellRF contains an example in which we generate a single variable random field on a lattice unit cell
  • rnnRF contains an example in which we generate a correlated two-dimension random field and the siulations script to run Monte Carlo simulations on a multiscale lattice compression using a MOAMMM stochastic neural network as surrogate of the cell response.

generateRF

  • generateRF.py: file used to generate the random fields
    • The RF is defined from the mean and standard deviation of the variables as well as from their correlation following for example for a 2-dimension RF:
      • meanX = np.array([0.5,10]) # mean of variables
      • stdX = np.array([0.05,0.1]) # std of variables
      • rho = 0.2
      • R0_XY = np.array([[1, rho], [rho, 1]]) #correlation matrix
    • And from a the correlation lengths along the 3 direction
      • lc = [15., 15., 15.] # correlation length
    • The number of RFs to be generated follows from
      • Nsim =10
    • The Random fields will be generated at the spatial points defined in terms of their coordinates.
      • The script tries to read a file in mechDir+'/GPData', where mechDir is the working directory, describing the list of spatial points. One example of points coordinates can be found in rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv stored following: finite element number (for a FE simulation); 3 coordinates; point number in finite element (for a FE simulation).
      • The random field number X is saved in the file mechDir+'/randomFields/RandField_X.csv', where mechDir is the working directory. The number of columns is the dimension of the random vector and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in rnnRF/randomFields/RandField_0.csv.
      • The random field number X along with the spatial points coordinates is saved in the file mechDir+'/randomFields/RandField_And_GP_X.csv', where mechDir is the working directory. The number of columns is the dimension of the random vector plus the 3 spatial coordinates and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in rnnRF/randomFields/RandField_And_GP_0.csv.
    • The variable recomputePDF=True forces the evaluation of the spectral density matrix, which will be saved in mechDir+'/randomFields/H_pdf.dat'.
    • The variable recomputePDF=False reads the spectral density matrix already saved in mechDir+'/randomFields/H_pdf.dat'
  • plotRF.py: file used to vizualize the distribution of the random vector.
    • Reads the N random fields of type 'RandField_X.csv' found in mechDir+'/randomFields/', where mechDir is the working directory. Examples of generated 2-dimension RFs can be found in rnnRF/randomFields/.
    • Plot the distribution of the random vector.
  • vizualizeRF.py: file used to generate a gmsh (www.gmsh.info) compatible file to vizualize the random fields
    • Reads the N random fields of type 'RandField_And_GP_X.csv' found in mechDir+'/randomFields/', where mechDir is the working directory. Examples of generated 2-dimension RFs can be found in rnnRF/randomFields/.
    • Uses the mesh structure of the considered application. The script tries to read stress file in mechDir+'/GPData', where mechDir is the working directory, describing the elements structure. One example of stress file can be found in rnnRF/GPData/stress_step1.msh.
    • The random field number X is saved in format compatible with gmsh (www.gmsh.info) in the file mechDir+'/randomFields/RandField_X.msh', where mechDir is the working directory. One example of generated 2-dimension RF can be found in rnnRF/randomFields/RandField_0.msh.
  • utilRF.py: set of functions used by the RF generator and vizualization files.

rnnRF

cellRF

Example of application

In this example, we consider a multiscale lattice simulation in which the lattice cell response is substituted by a MOAMMM stochastic neural network acting as a surrogate. To this end we generate 10 random fields of correlated cell length and struts radius. MC siulations can then be conducting.

Generate the Gauss-points list and mesh structure for the random field generator

This steps requires cm3Libraries (http://www.ltas-cm3.ulg.ac.be/openSource.htm). From the rnnRF directory, run

python3 generateGPInfo.py

After execution the ouput files are store in 'rnnRF/GPData':

  • The script write the Gauss points coordinates in the directory 'rnnRF/GPData'. One example of points coordinates can be found in rnnRF/GPData/coordinate_P_ZZ_OnPhysical_11.csv stored following 3 coordinates, point number and point volume (for a FE simulation).
  • The script write the mesh structure in the directory 'rnnRF/GPData'. One example of stress file can be found in rnnRF/GPData/stress_step1.msh.

Generate Random Fields

From the generateRF directory, select testNb=1 for 'rnnRF' in the file generateRF.py and then run

python3 generateRF.py 

After execution the ouput files are store in 'rnnRF/randomFields':

  • The random field number X is saved in the file 'rnnRF/randomFields/RandField_X.csv'. The number of columns is the dimension (2) of the random vector and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in rnnRF/randomFields/RandField_0.csv.
  • The random field number X along with the spatial points coordinates is saved in the file 'rnnRF/randomFields/RandField_And_GP_X.csv'. The number of columns is the dimension (2) of the random vector plus the 3 spatial coordinates and the number of lines is the number of spatial points. One example of generated 2-dimension RF can be found in rnnRF/randomFields/RandField_And_GP_0.csv.

Vizualize the random vector distribution

From the generateRF directory, select testNb=1 for 'rnnRF' in the file plotRF.py and then run

python3 plotRF.py 

Vizualize the random field distribution

From the generateRF directory, select testNb=1 for 'rnnRF' in the file vizualizeRF.py and then run

python3 vizualizeRF.py 

After execution the ouput files are store in 'rnnRF/randomFields':

Then, from rnnRF directory run

gmsh rubics.msh randomFields/RandField_*.msh 

to vizualize the RF discretization compatible with the geometry.

Run a MC Stochastic finite element simulation

This steps requires cm3Libraries (http://www.ltas-cm3.ulg.ac.be/openSource.htm). From the rnnRF directory, run

python3 runMCTest.py 

After execution the ouput files are store in 'rnnRF/results':

  • The script saves the simulations results in 'rnnRF/results/RandField_And_GP_X.csv/'

To vizualize the different resulting stress/strain curves

python3 plotMC.py

Disclaimer

Code related to MOAMMM project This project has received funding from the European Union’s Horizon 2020 research and innovation programme under grant agreement No 862015.

Views and opinions expressed are however those of the author(s) only and do not necessarily reflect those of the European Union. Neither the European Union nor the granting authority can be held responsible for them.

  1. The random field generator is described in:
    "Noels, L. (2022). Toward stochastic multi-scale methods in continuum solid mechanics Advances in Applied Mechanics, 55, 1-254. doi:10.1016/bs.aams.2022.03.001" which can be downloaded here. Please note the erratum of the official version. We would be grateful if you could cite this publication in case you use the files.