Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 1/10

Organization (S): EDF-R & D/AMA
Handbook of Utilization
U1.0- booklet: Introduction to Code_Aster
Document: U1.03.02

Python methods of access to the Aster objects

Summary:

This document presents the Python methods giving access the information contained in
structures of Aster data. This information can be processed by programming python, or to be useful for
the conditional sequence of the following commands.
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 2/10

1
Introduction and precautions for use

In Code_Aster, the majority of the commands 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 command by the key words.

In a more advanced use of Python than the simple declaration of Code_Aster commands, 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-commands and of the operations like loops (for, while,…), of the tests (yew,…), of
external executions of commands (via the module bone), etc… The page “Utilization/Exemples/
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 command DEBUT or
POURSUITE). 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 commands 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 commands (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 grid: list groups of nodes and meshs, co-ordinates.

Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 3/10

2 Them
tables

The structures of data table 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
commands of postprocessing produce tables: to raise of the constraints 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 (LISTE = (



_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 method EXTR_TABLE, attached to the class of concept ASTER:

tab2 = tab1.EXTR_TABLE ()

tab2 is an object python, authority of the Table class of the Utilitai.Table module. 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 Table importation
listdic = [
{“NOEUD”: “N2”, “NUME_ORDRE”: 14, “DX”: 0.93,},
{“NOEUD”:
“N2”
, “NUME_ORDRE”:
15, “DX”:
1.
16,},
{“NOEUD”:
“N1”
, “NUME_ORDRE”:
3
, “DX”:
0.70,
},
{“NOEUD”:
“N1”
, “NUME_ORDRE”:
2
, “DX”:
0.46,
},
{“NOEUD”:
“N1”
, “NUME_ORDRE”:
1
, “DX”:
0.23,
},

]
listpara= [“NOEUD”, “NUME_ORDRE”, “DX”]
listtype= [“K8”, “I”, “R”]
tab2=Table (listdic, will listpara, listtype)

The possible operations on tab2 are described hereafter.

Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 4/10

2.1 Impression

>>> tab2
----------------------------------------------
NOEUD
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

Command IMPR_TABLE exploits the functionalities of impression offered by this class.
interested reader will be able to read the programming python of this macro-command. 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
----------------------------------------------
NOEUD
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)
----------------------------------------------
NOEUD
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)
----------------------------------------------
NOEUD
NUME_ORDRE
DX
N1
1
2.30000E-01
N1
2
4.60000E-01
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 5/10

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)
----------------------------------------------
NOEUD
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

----------------------------------------------
NOEUD
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”, “NOEUD”)

2.4
Access to the values

The contents of the table accessible by the method are been worth () which produces a dictionary of which them
keys are the parameters of access of the table and the values the columns:

>>> tab2.values ()
{“NOEUD”: [“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”]

Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 6/10

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, a third list is obtained and lst2 and lst3 will contain the lists of the real parts and
imaginary.

lst1 = [function] .Absc ()

lst1 is the list of the X-coordinates, that is to say also the first list returned by Valeurs ().

lst2 = [function] .Ordo ()

lst2 is the list of the ordinates, that is to say also the second list returned by Valeurs ().

dico1 = [function] .Parametres ()

turn over a dictionary containing the parameters of the function; the jeveux type (FONCTION, FONC_C,
NAPPE) 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 grid

Two methods make it possible to recover the list of the groups of meshs and nodes of a structure
of data of the grid type:

[(tuple),…]
= [grid] .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),…]
= [grid] .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)
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 7/10

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”]
(field DEPL is calculated with the numbers
[0,1,2]
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”]
(sequence numbers of result EVOL
[0,1,2]
are: 0, 1 and 2)
>>> print dictionary [“INST”]
(calculated moments of result EVOL
[0., 2., 4.]
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 [“MODELE”]
(name of the concept models reference
[“MO”, “MO”, “MO”]
for each sequence number)
>>> print dictionary [“ITER_GLOB”]
(iteration count of convergence
[4,2,3]
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

The method getvectjev gives access to a structure of data of the vector type. 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.
This one can be given thanks to the command Aster IMPR_CO (CO = name).

Example: to recover the co-ordinates of the nodes of a grid named MA:
LMBO = aster.getvectjev (“MA .COORDO .VALE”)
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 8/10

Access to a structure of data of the collection type

In a similar way, the method getcolljev allows the consultation of the collections 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 grid 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 nodes (EXTR_COMP)

Method EXTR_COMP, applied to a field, allows recovery in python of the contents 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) correspondent at one moment by CREA_CHAMP.
2) One extracts the component by method EXTR_COMP (declared for the 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.
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 9/10

Arguments of command EXTR_COMP:

The command 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 the group_ma (equivalent with
TOUT=' OUI' in the Aster commands.
topo
one reference of information on topology if >0 (optional, defect = 0).

Results of command 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

Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Code_Aster ®
Version
7.4
Titrate:
Python method of access to the Aster objects


Date:
25/03/05
Author (S):
C. DURAND, A. ASSIRE Key
:
U1.03.02-B Page
: 10/10

Intentionally white left page.
Handbook of Utilization
U3.0- booklet: Introduction to Code_Aster
HT-66/05/004/A

Outline document