Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
1/8
Organization (S): EDF-R & D/AMA
Handbook of Utilization
U2.08 booklet: Advanced function and control of calculations
Document: U2.08.05
Digital simulation of Monte Carlo
Summary:
This document gives the elements for the implementation of digital simulations of Monte Carlo to leave
command file and operators of random generation. The three principal ingredients are:
·
A Python loop,
·
A generator of random variables (GENE_VARI_ALEA) and/or a generator of matrices
random (GENE_MATR_ALEA) for dynamics, and/or a generator of random functions
(GENE_FONC_ALEA),
·
The calculation of the statistical estimators (CALC_FONCTION).
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
2/8
1 General information
The numerical method of Monte Carlo makes it possible to calculate various statistical sizes from one
random variable or of a stochastic process. In the context of a mechanical calculation (or
thermomechanical,…) , the principle is to obtain NS achievements of this random variable or it
stochastic process then to deduce the required statistical estimates from them. Three
principal stages of the Monte Carlo method are:
1) Generation of a sample of NS achievements of the random data of input of the model
mechanics,
2) Calculation
NS sizes results corresponding to these data,
3) Calculation of the statistical estimators of the required sizes.
In the Monte Carlo method simple or direct that one uses, each NS calculations can be
fact independently of the others. In order to reduce the size memory necessary, the NS generations and
calculations are thus carried out sequentially in a loop with destruction of the results
useless intermediaries.
2
Loop Python in the command file Aster
In order to allow the use of a loop python in the command file, it is first of all necessary
to position key word PAR_LOT of command DEBUT on value “NON”:
BEGINNING (CODE=_F (NAME = “SDNS001”), PAR_LOT=' NON')
The loop python in it even starts with the command for, and includes all the lines of
even indentation
for K in arranges (1,1000):
COMMANDE1
for m in arranges (1,500):
COMMANDE2
COMMANDE3
In this example, one finds two loops python encased. The first, on the variable K, allows
to carry out 999 times instructions COMMANDE1, the second loop python, and COMMANDE3.
second internal loop python, on the variable m makes it possible COMMANDE 2d' to be carried out 499 times
for each K going from 1 to 999.
Notice
There is no instruction of end of loop. The indentations alone mark the body of
the instruction “for”.
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
3/8
3
Generation of random variables
The terminology of random generators must here be taken in the broad sense. These random variables
can be with values scalar, matric, or even functional calculuses (stochastic process).
Code_Aster is able to generate of such random variables respectively by the commands
GENE_VARI_ALEA, GENE_MATR_ALEA and GENE_FONC_ALEA.
The random variables can be parameters of the model finite elements (parameters
materials, values of a play, a stiffness of thrust rubber bands, a modulus Young, etc). In it
case one models uncertainties of modeling by a parametric probabilistic approach and one
use GENE_VARI_ALEA then.
In dynamics of the structures, these random variables can also be the generalized matrices
of mass, stiffness and damping and/or local parameters of the model to the finite elements.
In this case, one models at the same time uncertainties of model and modeling by an approach
not-parametric probabilist, and GENE_MATR_ALEA is used.
These random variables with scalar or matric values follow laws of built probabilities
by the use of the principle of the maximum of entropy and information available (see [R4.03.05]).
The random variable can still be a function. Operator GENE_FONC_ALEA allows
to generate trajectories of a monodimensional multivariate stochastic process (i.e with several
components and indexed on only one variable) stationary of null average starting from its density
spectral of power. In the case of a transitory dynamic calculation, one can thus generate
temporal loadings known by their matrix interspectrale.
With less than one contrary indication using key word INIT_ALEA, all the values generated by
three commands GENE_VARI_ALEA, GENE_MATR_ALEA and GENE_FONC_ALEA are statistically
independent between them inside the same execution of Code_Aster. A contrario, of one
execution with the other, a strictly identical command file (even calls to the three
commands in the same order with the same arguments) will provide the same ones exactly
results. If one wishes to generate results statistically independent of an execution with
the other, then it is necessary to use key word INIT_ALEA with values raising the number of terms
used in the former executions.
Caution:
The generator of random variable used is that of the module “random” of Python. It
depends on the version of Python exploited by Code_Aster. Not converged results
statistically can thus vary from one version to another of Code_Aster or one
platform with the other, if the version of Python is not the same one and that between the two
poured the module random evolved/moved (case between Python 2.1 and 2.3).
Note:
In version Python 2.3, the period of the generator is 2 ** 19937-1 (Mr. Matsumoto and
T.
Nishimura, Mersenne Twister: With 623-dimensionally equidistributed uniform
pseudorandom number generator, ACM Transactions one Modeling and Computer
Simulation vol. 8, No 1, January pp.3-30 1998.)
Note:
The module “random” of Python provides an alternative to command GENE_VARI_ALEA
to generate random variables of which the densities are not available in this
order.
4 Estimators
statistics
Of a sample of NS achievements of the quantity of interest, one can deduce the estimates from them from
statistical sizes like the average, the standard deviation,… The estimators must in general be
calculated in two times. Initially, inside the loop of the intermediaries quantity
then in a second after the loop the estimators are calculated are calculated to them-even.
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
4/8
Let us take for example a sample of spectra of oscillators {SRO (; p)}1 p NS, for
which for each pulsation we wish to calculate the moments of command 1 and 2. These moments have
for expression:
1 NS
m (,) =
SRO (,),
1
p
NS p 1=
1 NS
2
m (,) =
SRO (,).
2
p
NS p 1=
The two sums above are easily calculable inside the loop, it is simply
necessary to differentiate the case from the initialization of the sum and the cases of incrementing from this
summon.
Here, for example, a command file purified allowing to evaluate m (,):
2
for K in arranges (1, ns+1):
MATM=GENE_MATR_ALEA (MATR_MOYEN=MASSE, DELTA=0.2)
MATK=GENE_MATR_ALEA (MATR_MOYEN=RIGID, DELTA=0.2)
MATD=GENE_MATR_ALEA (MATR_MOYEN=AMORT, DELTA=0.2)
generation of one
realization DYNA
=DYNA_TRAN_MODAL (
MASS_GENE=MATM,
random of the RIGI_GENE=MATK,
AMOR_GENE=MATD,
spectrum
…)
of oscillator ACC1=RECU_FONCTION (RESU_GENE = DYNA,…)
SRO=
CALC_FONCTION (SPEC_OSCI=_F (NATURE=' ACCE', FONCTION=ACC1,…))
yew k==1:
M2_3=
CALC_FONCTION (PUISSANCE=_F (FONCTION=SRO,
EXPOSANT=2),)
else:
M2_0 evaluation
=
CALC_FONCTION (PUISSANCE=_F (FONCTION=SRO,
EXPOSANT=2),)
M2_1
sum
=
CALC_FONCTION (
COMB= (_F (FONCTION=M2_0, COEF=1.),
_F (FONCTION=M2_3, COEF=1.)) )
SRO (, p)
TO DESTROY (CONCEPT=_F (NOM= (M2_3, M2_0)))
M2_3= CALC_FONCTION (COMB=_F (FONCTION=M2_2, COEF=1.),)
TO DESTROY (CONCEPT=_F (NOM= (M2_2)))
TO DESTROY CONCEPT=_F (NOM= (MATM, MATK, MATD, DYNA, SRO, ACC1)))
M2= CALC_FONCTION (COMB=_F (FONCTION=M2_3, COEF=1./NS),)
When k==1, one initializes the M2_3 function with the square of the first produced realization.
The power énième of a function is carried out by key word PUISSANCE of the command
CALC_FONCTION. Sum SRO (, p) 2
,
is stored, with the fur is as them
achievements are produced, in M2_3 using key words PUISSANCE and COMB of
order CALC_FONCTION, intermediate functions M2_0 and M2_1 and command
DETRUIRE. All various produced concepts (MATM, MATK, MATD, DYNA, SPO, A CC1, etc)
must be destroyed at the end of each iteration except for M2_3, of course. Lastly, one
time the NS iterations carried out, the function m (,) is evaluated and corresponds to the object
2
M2
product at the end of the example.
Note:
When command GENE_FONC_ALEA is used, there is the possibility of not
to use of loop python. The principle is then to generate “end to end” several temporal
(key word NB_TIRAGE in GENE_FONC_ALEA) and post-to treat the results with
order CALC_INTE_SPEC. Case-test ZZZZ180 [V1.01.180] gives an example
of such a use.
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
5/8
5
Example in transitory dynamics
Principle of deterministic calculation
One is based on the SDNS01a case-test concerning the response of a rectangular plate with one
butted elastic subjected to a deterministic impulse load.
One builds the solution of the average dynamic model reduced (determinist) using one
traditional sequence operators (ASSE_MATRICE, MODE_ITER_SIMULT, MACRO_PROJ_BASE
….)
One is interested in the answer of the system calculated by DYNA_TRAN_MODAL, and more exactly with
standardized spectra of the answers and with the temporal observations (fields of displacement,
speed, acceleration, constraints, etc).
Principle of probabilistic calculation
The stiffnesses of thrusts are made random as well as the generalized matrices of mass, of
stiffness and of damping.
The achievements of the corresponding stochastic transitory answer are calculated by the method
of digital simulation of direct Monte Carlo with NS simulations using a Python loop
the structure is:
Beginning loops, for p = 1,…, NS:
has) Génération of the pième achievements of the random variables (parametric approach) with
assistance of GENE_VARI_ALEA.
Generation of the pième achievements of the random generalized matrices of mass, of
stiffness and of damping using GENE_MATR_ALEA (nonparametric approach).
These matrices are not diagonal and thus require a full storage.
b) Calcul of the pème realization Qn (T; p) solution of the stochastic matric system with
non-linearities of shocks, entirety N being the dimension of the small-scale model. This realization
is the solution of the traditional matric system whose matrices are the achievements
previously generated. Calculation is thus carried out by DYNA_TRAN_MODAL.
c) Extraction of the physical ddls in displacement &Z N (T; p) for preset ddls, via
I
operator RECU_FONCTION.
Construction of the standardized spectra
S has (; p) of the answers of the ddls
J
&Z N (T; p) by operator CALC_FONCTION (SPEC_OSCI).
I
D) Evaluation using operator CALC_FONCTION of the contributions to the estimators
averages m
^
(; )
1
p
J
, of the moments of command two m
^
(,
; )
2
p
J
, of the values
max. extremes S^
(; p)
J, max
and min. S^
(; p)
J, min
of sample for the spectra
standardized:
m
^
(; p) = S (; p) + m
^
(; p -)
1
1 J
J
1 J
,
m
^
(; p) = S (; p) 2 + m^ (; p -)
1
2 J
J
2 J
,
S^
(; p) = Max
J, max
{S (; p S^
),
(;
J
J, max
p -}
)
1,
S^
(; p) = Min
J, min
{S (; p S^
),
(;
J
J, min
p -}
)
1.
End of loop.
Following the loop, the averages, the standard deviations, the max. extreme values and min.
of sample for the standardized spectra can be evaluated:
1
1
m (,) =
m
^
(; N)
1 J
1 J
S, m
(,) =
m
^
(; N).
N
2 J
2 J
S
S
NS
2
(,)
J
= m2 (,)
J
- 1
m (,)
J
,
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
6/8
Command file purified corresponding:
# SDNS01A: MODELS PROBABILISTIC NONPARAMETRIQUE D A PLATE WITH ELASTIC THRUST
BEGINNING (PAR_LOT=' NON')
# ----------- Construction of the average model finite elements then reduction on
elastic modes using the following commands:
AFFE_MODELE, AFFE_CARA_ELEM, CALC_MATR_ELEM, ASSE_MATRICE, MODE_ITER_SIMULT,…
MACRO_PROJ_BASE (BASE=MODE200, NB_VECT=5,
PROFILE = “FULL”,
MATR_ASSE_GENE= (_F (MATRIX = CO (“MA_G”), MATR_ASSE = MATM),…
# ----------- Preparation of the loop of simulations of Monte Carlo
ns=50 # 50 achievements of the stochastic processes (50 hard copies)
DELTA_M = 0.2 # scatter coefficients
DELTA_K = 0.2
DELTA_D = 0.2
# ----------- Beginning of the loop of simulations of Monte Carlo
for K in arranges (1, ns+1):
# Generation of the random achievements of the generalized matrices of mass,
# stiffness and damping
MATM = GENE_MATR_ALEA (MATR_MOYEN = MA_G, COEF_VAR = DELTA_M)
MATK = GENE_MATR_ALEA (MATR_MOYEN = RI_G, COEF_VAR = DELTA_K)
MATD = GENE_MATR_ALEA (MATR_MOYEN = AM_G, COEF_VAR = DELTA_D)
# Generation of a random realization of the stiffness of shock
KN =GENE_VARI_ALEA (TYPE=' GAMMA',
BORNE_INF=0.,
VALE_MOY=25000.,
COEF_VAR=0.01)
VKN = KN [“NO.”, 1]
# Calculation of a random realization of the stochastic process “answer
# dynamic "
DM=DYNA_TRAN_MODAL (METHODE=' EULER',
MASS_GENE = MATM,
RIGI_GENE = MATK,
AMOR_GENE = MATD,
INCREMENT=_F (INST_INIT = 0.,
INST_FIN=4.,
PAS = 0.00005),
EXCIT=_F (VECT_GENE = IM_G,
FONC_MULT = IMPULF),
CHOC=_F (NOEUD_1 = “N3201”,
OBSTACLE = PLANZ, PLAY = 0.002,
RIGI_NOR = VKN,
RIGI_TAN = 0., COULOMB = 0.),)
# Calculation of the SRO of the ddl of observation 3201
ACC3201=RECU_FONCTION (RESU_GENE = DM,
NOM_CHAM=' ACCE',
NOM_CMP=' DZ',
NOEUD=' N3201')
SPO3201= CALC_FONCTION (SPEC_OSCI=_F (
NATURE=' ACCE',
FONCTION=ACC3201,
METHODE=' NIGAM',
NORME=9.81,
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
7/8
LIST_FREQ=LFREQ,
AMOR_REDUIT= (0.001)),
INTERPOL=' LOG',)
# Calculation of the statistical estimates
yew k==1: # initialization with the first realization
UP3201 = CALC_FONCTION (COMB=_F (FONCTION=SPO3201, COEF=1.),)
INF3201 = CALC_FONCTION (COMB=_F (FONCTION=SPO3201, COEF=1.),)
M1_3201 = CALC_FONCTION (COMB=_F (FONCTION=SPO3201, COEF=1.),)
M2_3201 = CALC_FONCTION (PUISSANCE=_F (FONCTION=SPO3201, EXPOSANT=2),)
else:
UP1 = CALC_FONCTION (ENVELOPPE=_F (FONCTION= (UP3201, SPO3201),
CRITERE=' SUP'),) # Maximum of sample
INF1= CALC_FONCTION (ENVELOPPE=_F (FONCTION= (INF3201, SPO3201),
CRITERE=' INF'),) # Minimum of sample
M1_2 = CALC_FONCTION (COMB= (_F (FONCTION=SPO3201, COEF=1.),
_F (FONCTION=M1_3201, COEF=1.))) # Summons
M2 = CALC_FONCTION (PUISSANCE=_F (FONCTION=SPO3201, EXPOSANT=2),
M2_2 = CALC_FONCTION (COMB= (_F (FONCTION=M2, COEF=1.),
_F (FONCTION=M2_3201, COEF=1.))) # Summons squares
# Renamings and destruction (bus concepts not réentrant)
TO DESTROY (CONCEPT=_F (NOM= (UP3201, INF3201, M1_3201, M2_3201, M2)))
UP3201= CALC_FONCTION (COMB=_F (FONCTION=UP1, COEF=1.),)
INF3201= CALC_FONCTION (COMB=_F (FONCTION=INF1, COEF=1.),)
M1_3201= CALC_FONCTION (COMB=_F (FONCTION=M1_2, COEF=1.),)
M2_3201= CALC_FONCTION (COMB=_F (FONCTION=M2_2, COEF=1.),)
TO DESTROY (CONCEPT=_F (NOM= (M2_2, M1_2, INF1, UP1)), INFO=2)
# end yew
TO DESTROY (CONCEPT=_F (NOM= (DM, ACC3201, SPO3201, MATM, MATD, MATK100, KN)) INFO=2)
# end for (loops simulations Mr. C)
M13201= CALC_FONCTION (COMB=_F (FONCTION=M1_3201, COEF=1./NS),) # Calcul of
average
M23201= CALC_FONCTION (COMB=_F (FONCTION=M2_3201, COEF=1./NS),) # Calcul of
variance
N3201= CALC_FONCTION (NORME=_F (FONCTION=M13201),)
# Calculation of the L2 standard
FIN ()
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Code_Aster ®
Version
7.3
Titrate:
Digital simulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS Key
:
U2.08.05-B1 Page:
8/8
Intentionally white left page.
Handbook of Référence
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Outline document