background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
1/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
Organization (S):
EDF-R & D/AMA















Instruction manual
U1.0- booklet: Introduction to Code_Aster
Document: U1.03.02


Methods Python of access to the Aster objects




Summary:

This document presents the Python methods giving access the information contained in
structures of data Aster. This information can be processed by programming python, or to be useful for
the conditional sequence of the following controls.
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
2/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
1
Introduction and precautions for use
In Code_Aster, the majority of the controls are programmed in FORTRAN. Structures of
produced data are accessible only via the manager from memory
JEVEUX
, him
even written in FORTRAN. In a standard execution of the code, only names of the concepts (and not of
objects carrying themselves calculated information) are transmitted to the level of the supervisor, of
order from control by the key words.
In a more advanced use of Python than the simple statement of Code_Aster controls, it
command file written in Python can use the contents of the structures of data suitable for
Code_Aster. Indeed, Python can be used in the command files to create
macro-controls and of the operations like loops (
for
,
while
,…), of the tests (
yew
,…), of
external executions of controls (via the module
bone
), etc… The page “Use/Examples/
Examples of use of Python in Aster “of the Web site www.code-aster.org gathers some
a number of cases of application. It is then interesting for the user to recover the product of
calculations FORTRAN in space python, i.e. its command file. Several methods
Python were developed in order to reach the contents of other structures of data.
To recover calculated data (in memory JEVEUX), it is absolutely necessary that
the instructions involving their obtaining were indeed carried out as a preliminary. In other words, it is
essential to carry out the code in mode
PAR_LOT=' NON'
(key word of the control
BEGINNING
or
CONTINUATION
). Indeed, in this case, there is no total analysis of the command file, but
each instruction is carried out sequentially. When one arrives on an instruction, all them
concepts preceding it already were thus calculated.
BEGINNING (PAR_LOT = “NOT”)
It should then be noted that the command file thus produced is not readable by EFICAS which does not tolerate
that files exclusively made up of controls specific to ASTER. Only variables
simple (realities, entireties, strings) defined in declaratory mode (a=' toto') or algebraic (n=3+4) are
readable by EFICAS.
The information read again in the memory JEVEUX, product of a preliminary calculation, can be exploited by
example for (nonexhaustive list):
·
To connect conditionally other controls (execution of loop
while
until
obtaining a computed value of stress ultimate)
·
To handle in python of the contents of a table, a function, at ends of calculations
·
To recover the attributes of a mesh: list groups of nodes and meshs, co-ordinates.

background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
3/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
2 Them
tables
Structures of data
count
are produced in ASTER by creation (
CREA_TABLE
), by reading
in a file (
LIRE_TABLE
) or recovery in another concept (
RECU_TABLE
). It is
functionally heterogeneous tables of figures (whole, real, character strings) of which
the columns are identified by names of label.
These are practical structures whose employment is generalized in the code. For example, majority of
controls of postprocessing produce tables: to raise of the stresses in places
geometrical given, to produce calculated macroscopic sizes (postprocessings of
breaking process).
That is to say for example the table
tab1
following exit of a calculation ASTER:
NODE NUME_ORDRE DX
N2 14
0.93
N2 15
1.16
N1 3
0.70
N1 2
0.46
N1 1
0.23
It could also have been directly created like concept ASTER of the type counts by:
tab1=CREA_TABLE (LIST = (
_F (PARA=' NOEUD',
VALE_K= (“N2”, “N2”, “N1”, “N1”, “N1”),),
_F (PARA=' NUME_ORDRE',
VALE_I= (14,15,3,2,1),),
_F (PARA=' DX',
VALE_R= (0
.93, 1.16, 0.70, 0.46, 0.23),),)
One can directly recover an unspecified value of the table which one knows the access key (name
of label of column) and the number of line:
>>> print tab1 [“DX”, 3]
0.70
It is also possible to recover the totality of the table in the environment python via a class
dedicated, produced by the method
EXTR_TABLE
, attached to the class of the concept ASTER:
tab2 = tab1.EXTR_TABLE ()
tab2
is a python object, authority of the class
Count
module
Utilitai.Table
. It is
easy to handle with the methods associated with this class; one will be able to make
help (Table)
for
to know the methods of this class.
The table
tab2
could also have been directly defined by a dictionary:
From Utilitai.Table importation Counts
listdic = [
{“NODE”: “N2”, “NUME_ORDRE”: 14, “DX”: 0.93,},
{“NODE”:
“N2”
, “NUME_ORDRE”:
15, “DX”:
1.
16,},
{“NODE”:
“N1”
, “NUME_ORDRE”:
3
, “DX”:
0.70,
},
{“NODE”:
“N1”
, “NUME_ORDRE”:
2
, “DX”:
0.46,
},
{“NODE”:
“N1”
, “NUME_ORDRE”:
1
, “DX”:
0.23,
},
]
listpara= [“NODE”, “NUME_ORDRE”, “DX”]
listtype= [“K8”, “I”, “R”]
tab2=Table (listdic, will listpara, listtype)
Possible operations on
tab2
are described hereafter.
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
4/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
2.1 Impression
>>> tab2
----------------------------------------------
NODE
NUME_ORDRE
DX
N2
14
9.30000E-01
N2
15
1.16000E+00
N1
3
7.00000E-01
N1
2
4.60000E-01
N1
1
2.30000E-01
Also possible:
>>> print tab2
Display of only one parameter:
>>> t.DX
----------------------------------------------
DX
9.30000E-01
1.16000E+00
7.00000E-01
4.60000E-01
2.30000E-01
The control
IMPR_TABLE
exploit the functionalities of impression offered by this class.
interested reader will be able to read the programming python of this macro-control. In particular
possibility of printing cross tables.
2.2
Creation or impression of a under-table extracted by filter
Extraction according to only one criterion:
>>> print tab2.NUME_ORDRE <=5
----------------------------------------------
NODE
NUME_ORDRE
DX
N1
3
7.00000E-01
N1
2
4.60000E-01
N1
1
2.30000E-01
Extraction according to two criteria with logical association “&”/AND:
>>> print (t.NUME_ORDRE < 10) & (t.DX>=0.3)
----------------------------------------------
NODE
NUME_ORDRE
DX
N1
3
7.00000E-01
N1
2
4.60000E-01
Extraction according to two criteria with logical association “ | ”/OR:
>>> print (t.NUME_ORDRE < 2) | (t.DX<0.5)
----------------------------------------------
NODE
NUME_ORDRE
DX
N1
1
2.30000E-01
N1
2
4.60000E-01
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
5/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
Extraction of a restricted number of labels:
>>> T [“DX”, “NUME_ORDRE”]
----------------------------------------------
DX
NUME_ORDRE
9.30000E-01 14
1.16000E+00 15
7.00000E-01 3
4.60000E-01 2
2.30000E-01 1
Extraction according to a criterion of equality (here with value of the criterion deduced itself from the table)
>>> t.DX == max (t.DX)
----------------------------------------------
NODE
NUME_ORDRE
DX
N2
15
1.16000E+00
2.3 Sorting
Sorting of the whole table according to a label:
>>> t.sort (“NUME_ORDRE”)
>>> T

----------------------------------------------
NODE
NUME_ORDRE
DX
N1
1
2.30000E-01
N1
2
4.60000E-01
N1
3
7.00000E-01
N2
14
9.30000E-01
N2
15
1.16000E+00
For sorting according to several labels, the command of precedence being that in which the labels are declared,
it is necessary to write:
>>> t.sort (“NUME_ORDRE”, “NODE”)
2.4
Access to the values
The contents of the table are accessible by the method
been worth ()
who produces a dictionary of which them
keys are the parameters of access of the table and the values the columns:
>>> tab2.values ()
{“NODE”: [“N1”, “N1”, “N1”, “N2”, “N2”], “NUME_ORDRE”: [1, 2, 3, 14, 15],
“DX”: [0.23, 0.46, 0.70, 0.93, 1.156]}

The parameters are given by the attribute
para
(idem
tab2.values () .keys ()
)
>>> will tab2.para
[“NODE”, “NUME_ORDRE”, “DX”]
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
6/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
3
Simple access methods on the concepts
Access to the contents of a SD lists
lst = [listr8] .Valeurs ()
lst
is a list python which contains the values of the Aster list:
lst = [0., 1.1, 2.3,…]
Access to the contents of a SD function or a SD tablecloth
lst1, lst2, (lst3) = [function/tablecloth] .Valeurs ()
lst1
and
lst2
are two lists python which contain the X-coordinates and the ordinates. If the function is
complex, one obtains a third list and
lst2
and
lst3
the lists of the real parts will contain and
imaginary.
lst1 = [function] .Absc ()
lst1
is the list of the X-coordinates, that is to say also the first list returned by
Values ()
.
lst2 = [function] .Ordo ()
lst2
is the list of the ordinates, that is to say also the second list returned by
Values ()
.
dico1 = [function] .Parametres ()
turn over a dictionary containing the parameters of the function; the jeveux type (
FUNCTION
,
FONC_C
,
TABLECLOTH
) is not turned over, the dictionary can thus be provided to
CALC_FONC_INTERP
just as it is (see
efica02a).
Evaluation of a SD function or formula
The functions in R and the formulas are appraisable simply in the space of name python, therefore
the command file, as follows:
FONC1=FORMULE (VALE=' (Y ** 2) +
X',
NOM_PARA= (“X”, “Y”,)),
);
>>> print FONC1 (1., 2.)
5.
or with a function:
FONC2=DEFI_FONCTION (NOM_PARA=' X', VALE= (0., 0., 1., 4.,))
>>> print FONC2 (0.5)
2.
Access to the contents of a SD mesh
Two methods make it possible to recover the list of the groups of meshs and nodes of a structure
of data of the mesh type:
[(tuple),…]
= [mesh] .LIST_GROUP_MA ()
return a list of tuples, each one containing the name of each group of meshs, the number of
meshs which it contains and the dimension (0, 1, 2 or 3) highest of its meshs:
tuple = (“GMA”, Nb meshs, dim. meshs)
[(tuple),…]
= [mesh] .LIST_GROUP_NO ()
return the list of the groups of nodes in the form:
tuple = (name of the group_no, Nb of nodes of the group_no)
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
7/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
Access to the keys of a SD
result
If
EVOL
is a structure of data
result
, then:
dictionary = EVOL.LIST_CHAMPS ()
is a dictionary whose keys are the names of the fields
who index the list of the calculated sequence numbers.
Example:
>>> print dictionary [“DEPL”]
[0,1,2]
(field DEPL is calculated with the numbers
of command 0, 1 and 2)
>>> print dictionary [“SIEF_ELNO_ELGA”]
[]
(the field is not calculated)

dictionary = EVOL.LIST_VARI_ACCES ()
is a dictionary whose keys are the variables of access
who index their own values.
Example:
>>> print dictionary [“NUME_ORDRE”]
[0,1,2]
(sequence numbers of the result
EVOL
are: 0, 1 and 2)
>>> print dictionary [“INST”]
[0., 2., 4.]
(calculated moments of the result
EVOL
are: 0.s, 2.s and 4.s)

dictionary = EVOL.LIST_PARA ()
is a dictionary whose keys are the parameters of
calculation which indexes the lists (of cardinal equal to the number
calculated sequence numbers) their values.
Example:
>>> print dictionary [“MODEL”]
[“MO”, “MO”, “MO”]
(name of the concept models reference
for each sequence number)
>>> print dictionary [“ITER_GLOB”]
[4,2,3]
(iteration count of convergence
for each sequence number)


4
Access method to an unspecified structure of data
It is possible, with the help of the knowledge of name JEVEUX of the object, to recover any vector or
any collection presents in the memory.
Two methods are available:
getvectjev
(vector) and
getcolljev
(collection).
Access to a structure of data of the vector type
Method
getvectjev
the access to a structure of data of the vector type allows. It applies
always on the object “aster”, and takes in argument the character string supplements (space y
included/understood) defining the name of the object contained in the structure of data which one wants to reach.
The aforementioned can be given thanks to the Aster control
IMPR_CO (CO = name)
.
Example: to recover the co-ordinates of the nodes of a mesh named MA:
LMBO = aster.getvectjev (“MA .COORDO .VALE”)
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
8/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
Access to a structure of data of the collection type
In a similar way, method
getcolljev
the consultation of the collections allows since python.
It renvoit a dictionary whose keys are the names of the objects in the event of named collection, them
numbers of index if not.
Example: to recover information concerning the connectivity of the elements of mesh MA:
LMBO = aster.getcolljev (“MA .CONNEX”)
One obtains in this case a dictionary resembling:
{3: (2, 1, 5), 2: (6, 9, 10, 7, 11, 12, 13, 8), 1: (1, 6, 7, 2, 3, 8, 5)}


5
Recovery in python of the fields by elements and
fields with the nodes (
EXTR_COMP
)
Method
EXTR_COMP
, applied to a field, recovery in python of the contents allows of
field.

Example of use:
U = STAT_NON_LINE (…)

U104 = CREA_CHAMP (
TYPE_CHAM = “NOEU_DEPL_R”,
OPERATION = “EXTR”,
RESULT = U,
NOM_CHAM = “DEPL”,
NUME_ORDRE = 104,
)

U104NP = U104.
EXTR_COMP (“DX”, [“S_SUP”,])

print U104NP.valeurs


V104 = CREA_CHAMP (
TYPE_CHAM = “ELGA_VARI_R”,
OPERATION = “EXTR”,
RESULT = U,
NOM_CHAM = “VARI_ELGA”,
NUME_ORDRE = 104,
)

V104NP =
V104.EXTR_COMP (“V22”, [], 1)

print V104NP.valeurs
print V104NP.maille
print V104NP.point
print V104NP.sous_point

Thus starting from the result U:
1) One creates a field (
node
or
elXX
) agent at one moment by
CREA_CHAMP
.
2) One extracts the component by the method
EXTR_COMP
(declared for
cham_elem
and them
cham_no
) which creates a new type of python object:
post_comp_cham_el
and
post_comp_cham_no
whose attributes are described hereafter.
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
9/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A
Arguments of the control
EXTR_COMP
:
The control has 3 arguments:
ch1 = EXTR_COMP (comp, lgma, topo=0)
comp
component of the field on the list
lgma
.
lgma
list groups of meshs, if vacuum then one takes all them
group_ma
(equivalent with
TOUT=' OUI'
in the controls Aster.
topo
one reference of information on topology if >0 (optional, defect = 0).

Results of the control
EXTR_COMP
:
ch1.valeurs: Numeric.array
containing the values
If there is request topology (
topo>0)
:
·
ch1.maille
: number of meshs
·
ch1.point
: number of the point in the mesh
·
ch1.sous_point
: number of under point in the mesh
background image
Code_Aster
®
Version
7.4
Titrate:
Method Python of access to the Aster objects
Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE
Key
:
U1.03.02-B
Page
:
10/10
Instruction manual
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

























Intentionally white left page.