background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
1/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Organization (S):
EDF-R & D/AMA















Instruction manual
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 main products are:
·
A loop Python,
·
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).
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
2/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
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
main 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 one of
NS
calculations can be
fact independently of the others. In order to reduce the size memory necessary, them
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 the key word
PAR_LOT
control
BEGINNING
on the value
“NOT”
:
BEGINNING (CODE=_F (NAME = “SDNS001”), PAR_LOT=' NON')
The loop python in it even starts with the control 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
allows
COMMANDE2
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”.
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
3/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
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 controls
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 stop rubber bands, a modulus Young, etc). In it
case one modelizes uncertainties of modeling by a parametric probabilistic approach and one
use then
GENE_VARI_ALEA
.
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 modelizes at the same time uncertainties of model and modeling by an approach
not-parametric probabilist, and one uses
GENE_MATR_ALEA
.
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. The 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 the key word
INIT_ALEA
, all values generated by
three controls
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
controls 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 the key word should be used
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 the control
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.
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
4/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
Let us take for example a sample of spectra of oscillators
(
)
{
}
NS
p
SRO
p
1
;
,
, for
which for each pulsation we wish to calculate the moments of command 1 and 2. These moments have
for expression:
1
1
1
(,)
(,)
NS
p
p
m
SRO
NS
=
=
,
2
2
1
1
(,)
(,)
NS
p
p
m
SRO
NS
=
=
.
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
2
(,)
m
:
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)
DYNA
=DYNA_TRAN_MODAL (
MASS_GENE=MATM,
RIGI_GENE=MATK,
AMOR_GENE=MATD,
…)
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
=
CALC_FONCTION (PUISSANCE=_F (FONCTION=SRO,
EXPOSANT=2),)
M2_1
=
CALC_FONCTION (
COMB= (_F (FONCTION=M2_0, COEF=1.),
_F (FONCTION=M2_3, COEF=1.)) )
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 the key word POWER of the control
CALC_FONCTION. The sum
(
)
2
,
,
p
SRO
is stored, with the fur is as them
achievements are produced, in M2_3 using key words POWER and COMB of
order CALC_FONCTION, intermediate functions M2_0 and M2_1 and control
TO DESTROY. 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 them
NS
iterations carried out, the function
2
(,)
m
is evaluated and corresponds to the object m2
product at the end of the example.
Note:
When the control is used
GENE_FONC_ALEA,
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.
generation of one
realization
random of
spectrum
of oscillator
evaluation
sum
(
)
p
SRO
,
,
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
5/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
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
conventional 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, stresses, etc).
Principle of probabilistic calculation
The stiffnesses of stops 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 loop Python
the structure is:
Beginning loops, for p = 1,…, NS:
has) Generation of p
ième
achievements of the random variables (parametric approach) with
the aid of GENE_VARI_ALEA.
Generation of p
iè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) Calculation of p
ème
realization Q
N
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 conventional 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 T p
I
N
for preset ddls, via
operator RECU_FONCTION.
Construction of the standardized spectra
has
S (; )
J
p
answers of the ddls
&&
(; )
Z T p
I
N
by operator CALC_FONCTION (SPEC_OSCI).
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^
max
,
p
J
and min.
)
;
,
(
S^
min
,
p
J
of sample for the spectra
standardized:
)
1
;
,
(
m
^
)
;
,
(
S
)
;
,
(
m
^
1
1
-
+
=
p
p
p
J
J
J
,
)
1
;
,
(
m
^
)
;
,
(
S
)
;
,
(
m
^
2
2
2
-
+
=
p
p
p
J
J
J
,
{
}
)
1
;
,
(
S^
),
;
,
(
S
Max
)
;
,
(
S^
max
,
max
,
-
=
p
p
p
J
J
J
,
{
}
)
1
;
,
(
S^
),
;
,
(
S
Min
)
;
,
(
S^
min
,
min
,
-
=
p
p
p
J
J
J
.
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:
)
;
,
(
m
^
1
)
,
(
m
1
1
S
J
S
J
N
N
=
,
)
;
,
(
m
^
1
)
,
(
m
2
2
S
J
S
J
N
N
=
.
2
1
2
)
,
(
)
,
(
)
,
(
J
J
J
m
m
-
=
,
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
6/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A

Command file purified corresponding:
# SDNS01A: MODELS PROBABILISTIC NONPARAMETRIQUE D A PLATE WITH ELASTIC STOP
BEGINNING (PAR_LOT=' NON')
# ----------- Construction of the average model finite elements then reduction on
elastic modes using the following controls:
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.,
NOT = 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,
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
7/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A
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),) # Calculation of
average
M23201= CALC_FONCTION (COMB=_F (FONCTION=M2_3201, COEF=1./NS),) # Calculation of
variance
N3201= CALC_FONCTION (NORME=_F (FONCTION=M13201),)
# Calculation of the L2 standard
END ()
background image
Code_Aster
®
Version
7.3
Titrate:
S
numerical imulation of Monte Carlo
Date:
17/06/04
Author (S):
S. CAMBIER, C. DESCELIERS
Key
:
U2.08.05-B1
Page:
8/8
Manual of Reference
U2.08 booklet: Advanced function and control of calculations
HT-66/04/004/A


























Intentionally white left page.