2. The tables#
Table data structures are produced in Aster by creation (CREA_TABLE), by reading from a file (LIRE_TABLE), or by retrieving from another concept (RECU_TABLE). They are functionally heterogeneous data tables (integers, real, character strings) whose columns are identified by label names.
These are practical structures that are widely used in the code. For example, most post-processing commands produce tables: to identify constraints in given geometric locations, to produce calculated macroscopic quantities (fracture mechanics post-treatments).
For example, consider the following tab1 table from an Aster calculation:
NOEUD |
|
DX |
\(\mathit{N2}\) |
14 |
0.93 |
\(\mathit{N2}\) |
15 |
1.16 |
\(\mathit{N1}\) |
3 |
0.70 |
\(\mathit{N1}\) |
2 |
0.46 |
\(\mathit{N1}\) |
1 |
0.23 |
Table 2-1
It could also have been directly created as a table-type Aster concept by:
tab1= CREA_TABLE (LISTE = (
_F (PARA =” NOEUD “, LISTE_K =(” N2 “,” N2 “,” N2 “,” N1 “,” N1 “,” N1 “),), _F (PARA =” NUME_ORDRE “, LISTE_I =( 14,15,3,2,1),), _F (PARA =”DX”, LISTE_R =( 0.93,1.16,16,0.70,0.46,0.23),),)
You can directly retrieve any value from the table whose access key (column label name) and row number are known:
> >> print tab1 [“DX”,3”]
0.70
It is also possible to retrieve the entire table in the python environment via a dedicated class, produced by the EXTR_TABLE method, attached to the concept class ASTER:
tab2 = tab1. EXTR_TABLE ()
tab2 is a Python object, an instance of the Table class in the Utility.Table module. It can be manipulated with the methods associated with this class; you can use help (Table) to find out the methods of this class.
The tab2 table could also have been defined directly by a dictionary:
From Utilitai.Table import Table
listdic = [{'NOEUD': 'N2', 'NUME_ORDRE': 14, 'X': 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, listpara, listtype)
The possible operations on tab2 are described below.
2.1. Impression#
> >> tab2
----------------------------------------------
NOEUD NUME_ORDRE DX
N2 14 9.30000E-01
N2 15 1.16000E+00
NO. 3 7.00000E-01
NO. 2 4.60000E-01
N.1 1 2.30000E-01
Also possible:
> >> print tab2
Display of a single parameter:
> >> T.Dx
----------------------------------------------
DX
9.30000E-01
1.16000E+00
7.00000E-01
4.60000E-01
2.30000E-01
The IMPR_TABLE command takes advantage of the printing features offered by this class. The interested reader will be able to read the Python programming of this macro command. In particular the possibility of printing cross tables.
2.2. Create or print a subtable extracted by filter#
Extraction according to a single criterion:
> >> print tab2. NUME_ORDRE <=5
----------------------------------------------
NOEUD NUME_ORDRE DX
NO. 3 7.00000E-01
NO. 2 4.60000E-01
N.1 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
NO. 3 7.00000E-01
NO. 2 4.60000E-01
Extraction according to two criteria with logical association « | »/OR:
> >> print (t.Nume_order < 2) | (t.dx<0.5)
----------------------------------------------
NOEUD NUME_ORDRE DX
N.1 1 2.30000E-01
NO. 2 4.60000E-01
Extraction of a limited 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 an equality criterion (here with the value of the criterion itself deduced from the table)
> > T.Dx = max (T.dX)
----------------------------------------------
NOEUD NUME_ORDRE DX
N2 15 1.16000E+00
2.3. Tris#
Sorting the entire table according to a label:
> >> t.sort ('NUME_ORDRE')
> >> t
----------------------------------------------
NOEUD NUME_ORDRE DX
N.1 1 2.30000E-01
NO. 2 4.60000E-01
NO. 3 7.00000E-01
N2 14 9.30000E-01
N2 15 1.16000E+00
To sort by several labels, the order of precedence being the order of precedence being that in which the labels are declared, you must provide the labels in the form of a list or a tuple:
> >> t.sort (['NUME_ORDRE', 'X'])
A second order argument, equal to “CROISSANT” or “DECROISSANT”, allows you to specify the order of sorting:
> >> t.sort (['NUME_ORDRE', 'X'], 'DECROISSANT')
2.4. Access to values#
The content of the table is accessible by the values () method, which produces a dictionary whose keys are the access parameters of the table and the values the columns:
> >> tab2.values ()
{'NOEUD': [:ref:`'N1', 'N1', 'N1', 'N2', 'N2' <'N1', 'N1', 'N1', 'N2', 'N2'>`], 'NUME_ORDRE': [:ref:`1, 2, 3, 14, 15 <1, 2, 3, 14, 15>`], 'DX': [:ref:`0.23, 0.46, 0.70, 0.93, 1.156 <0.23, 0.46, 0.70, 0.93, 1.156>`]}
The parameters are given by the para attribute (idem tab2.values () .keys ())
> >> tab2.para
['NOEUD', 'NUME_ORDRE', 'DX']