Running a parametric study (tutorial)


your first simulation

This page describes how to run massively simulations for managing a parametric study

It is highly probable that you wonder to manage a parametric study. For instance, you may want to study the impact of one (or more) micro-mechanical parameter on the macroscopic response of your discrete domain. To manage such a study, GranOO embeds interesting tools.

Note that this tutorial step is based on the Example/00004_{tutorial}_{parallel-run}_TENSILE-TEST. So, you can copy/paste/edit this example to try this tutorial by yourself.

Building a template inp file

You must build first a template (generic) input file where your parameter of interest appears. For example, imagine that you want to study the impact of the micro Young’s modulus of a beam lattice on the macroscopic response.

To do such thing, the trick here, is to replace the corresponding value in the *.inp by a unique string ID.

<GRANOO Version="3"  OutDir="TENSILE-TEST-__YOUNG-MODULUS__-Pa" Verbose="No" ThreadNumber="1">
  <STEP Label="pre-processing">
    <READ-DOMAIN FileName="gdd/cube-2000.agdd"/>
    <CONVERT-ELEMENT-PAIR-TO-BEAM YoungModulus="__YOUNG-MODULUS__" RadiusRatio="0.2"/>
    <COMPUTE-OPTIMAL-TIME-STEP Ratio="0.14" />
  <STEP Label="processing" IterNumber="5000">
    <INTEGRATE-ACCELERATION Linear="Yes" Angular="Yes" BetaLinear="1.3" BetaAngular="1.3"/>
    <APPLY-DISPLACEMENT X="2e-7*it*-1" Set="Boundary-xMin"/>
    <APPLY-DISPLACEMENT X="2e-7*it"    Set="Boundary-xMax"/>
    <CHECK />
    <UPDATE-SUPPORT-SHAPE EveryIter="10" />
    <WRITE-SENSOR-DATA EveryIter="20" />

You can note the usage of the __YOUNG-MODULUS__ unique string ID instead of a numeric value for the Young’s modulus. Now, we will use the magic of command line for substituting on-the-fly this string ID by a given numeric value. After compiling the corresponding granoo project, you can run granoo with the following command line :

:prompt: ./build/tension.exe ./inp/beam-elastic-tension.inp -s __YOUNG-MODULUS__ -b 10e9

Here, we use the -s option for giving the substitution pattern and the -b option for telling the value. In such a way, these command options are able to substitute the occurrences of the __YOUNG-MODULUS__ in the *.inp file by another string. Of course, you can specify more than one substitution.

So, now, if you take a look into the backup folder located in the simulation result directory named TENSILE-TEST-10e9-Pa you should see the original *.inp file where the substitution was done.

Running simulations in parallel

The previous section shows how to use substition patterns into *.inp file. Now, we will re-use this trick in combination with python scripts for running massively simulations in parallel.

To do such job we will use the run python module of granoo. Thanks to this module, we are able to write very simple python scripts able to manage many simulations. Here, we will run 8 simulations by varying the microscopic Young’s modulus from 10 GPa to 80 GPa. It can simply done with the following python script named

import sys, os
from optparse import OptionParser
import as inp

# catch the number of wanted process from command line argument
parser = OptionParser()
parser.add_option("-p", "--proc" , type="int", dest="proc", default=True, help="simu to run in //")
(options, args) = parser.parse_args()

# a simple list that contains all the wanted values of microscopic Young's modulus
YOUNG_MODULUS  = ['10e9', '20e9', '30e9', '40e9', '50e9', '60e9', '70e9', '80e9']

lineArgumentList = []
    lineArgument = ['./c++/build/tension.exe', './inp/beam-elastic-tension.inp', '-s', '__YOUNG-MODULUS__', '-b', e]

inp.MassiveRun(lineArgumentList, options.proc)

Here, we re-use the granoo string substitution trick into a python script in comination with run granoo’s module. Now, we can simply run our simulations by invoking this script with the -p option as follows

:prompt: python ./py/ -p 4 

The -p option allows to run simulation in parrallel. Here, 4 simulations are running in parralel. When a simulation ends a, other one is launching automatically until it reaches all the wanted the simulation.

Post-treating a parametric study

Thanks to the plot module of granoo. It is quite easy to post-treat parametric studies. You can take a look into the script located into the py directory. Indeed, note that the most important thing is to build a unique output directory identifier which can be re-used by the python post-treatment script for retrieving the corresponding results. In this example, it is simply done by substituting the Young’s modulus into the output directory name that gives the following structure :

├── build
├── c++
├── gdd
├── inp
├── py
├── TENSILE-TEST-10e9-Pa # result dir for 10 GPa
├── TENSILE-TEST-20e6-Pa # result dir for 20 GPa
├── TENSILE-TEST-30e6-Pa # result dir for 30 GPa
├── TENSILE-TEST-40e6-Pa # result dir for 40 GPa
├── TENSILE-TEST-50e6-Pa # result dir for 50 GPa
├── TENSILE-TEST-60e6-Pa # result dir for 60 GPa
├── TENSILE-TEST-70e6-Pa # result dir for 70 GPa
└── TENSILE-TEST-80e6-Pa # result dir for 80 GPa