3. The command language#
3.1. Python and the command language#
A command file for*Code_Aster* consists exclusively of Python instructions. The first of the constraints is therefore to comply with the rules of this language. You can read the Python tutorial ( `www.python.org`_ < http://www.python.org/>) or the numerous introductory Python books for more detail, but it’s not necessary to use Aster.
A command file can contain Python instructions of two types: Aster commands and… any other python instruction. Indeed, a command file is a Python program in its own right and you can in particular place control structures (loops), tests (if), numerical calculations, calls to pre- and post-processing functions there.
In the context of a « classic » use of code where the command file contains exclusively Aster commands, the two Python-specific rules to remember are:
No indentation on the first statement line of an instruction.
email = LIRE_MAILLAGE ()
Do not place blanks or tabs before the email character string.
The arguments of the functions, in other words the keywords of the commands, are separated by commas; they consist of a keyword, the « = » sign, the content of the keyword.
Important:
The EFICAS editor only allows you to produce command files of this type: containing exclusively ASTER commands, without any other Python instructions. Using EFICAS basically guarantees three things:
the file produced will have correct python syntax,
the orders produced will be consistent with the order catalog,
the concepts produced will be linked correctly (no step to use a concept without it having been created by a previous order).
The user who has composed his command file in this way will be protected from being stopped at execution due to a syntax problem.
3.2. Concept concept#
Definition: Aster data structures are called concept, which the user can manipulate and name. These concepts are typed at the time they are created and can only be used as input arguments of the corresponding type in a later command.
The concept of concept therefore allows the user to manipulate objects symbolically and independently of their internal representation (which he may not know). Moreover, the Python object referred to by the name of the concept does not contain any information other than its type, its class in the Python sense (cf. doc D). Its name, transmitted by the supervisor to FORTRAN, allows Aster to find the corresponding data structure in the global database. But it is not possible to have visibility of the data structure from the command file. For example, the following instructions do not allow you to print the mesh and email name data structure:
mail= LIRE_MAILLAGE ()
Print mail
but generate the following message:
<Cata.cata.maillage_sdaster object at 0x593cad0>
There is one exception to this rule: tables. Indeed, a programming device makes it possible to simply retrieve information contained in a TABLE data structure by manipulating it as an array with two entries:
to print a value: print resu ['DX', 1]
to assign it to a variable: value = resu ['DX', 1]
This of course assumes that the resu data structure, of type TABLE, has already been calculated when we encounter this instruction: therefore in step-by-step execution mode (PAR_LOT =” NON “).
Lexical note:
Concept names should be no longer than 8 characters. Alphanumeric characters are legal (lower and upper case letters and numbers not placed in the first position) as well as the underscore “_”. The case is important: the concepts « MAIL » and « Mail » can be used in the same command file and will be considered different… this is however not recommended for the readability of the file!
3.3. Possible operations#
The structure of the command language is in the form of a linear sequence of instructions. In addition to Python instructions other than Aster commands, which are not discussed at the moment, three types of instructions (or commands) are available:
the operator who performs an action and who provides a product concept of a predefined type that can be used by the following instructions in the command set,
the procedure that performs an action but does not provide a concept,
the macro-command that generates a sequence of instructions of the two previous types and that can produce zero, one or more concepts.
Typically, an operator will be an assignment or resolution command, a procedure will be a print command (in a file).
Syntactically speaking, an operator takes the form:
concept name = operator (arguments...)
Whereas a procedure takes the form of:
procedure (arguments...)
The syntax of an operator or procedure is described in the next paragraph.
3.4. Rules on the concept produced by an operator#
3.4.1. Basic principle#
Each time an operator executes, this one provides a new product concept of the type predefined in the order catalog.
The concepts appearing as command input arguments are not changed.
3.4.2. Product concept and reused concept#
We call a reused concept, a concept that, being produced by an operator, is modified by a new occurrence of this operator or by another operator.
The use of a reused concept is only possible, as a derogation from the Basic Principle, under two conditions:
authorization given, by the catalog and the programming of the order, to use reusable concepts for the operator: the reentering attribute of the catalog is equal to “o” or “f”,
explicit request from the user to reuse a concept produced by the attribute reuse=name_of_concept in the arguments of the commands that allow it.
3.4.3. Checks carried out by the supervisor on product concepts#
Product concept respecting the basic principle:
The supervisor checks that the name of the product concept is not already assigned by one of the previous orders, in particular by a command from a previous execution in the case of a POURSUITE or a INCLUDE.
Concept used for reuse:
The supervisor verifies that:
The name of the product concept has already been successfully assigned.
the operator is well qualified to accept reused concepts,
the type of the concept is in accordance with the type of concept produced by the operator.
Examples with comments:
DEBUT ()
concept=operator () # (1) is correct: we define the concept,
concept=operator () # (2) is incorrect: we are trying to redefine the
# concept but without saying it,
concept=operator (reuse = concept) # (3) is correct, if the operator accepts
# existing concepts and if the type is # consistent; it is incorrect if the operator # don’t accept them.
FIN ()
In fact, a concept can only be created once: which means appearing to the left of the = (equal) sign without reuse being used in the command arguments.
In the case of reuse, specifying the name of the concept again behind the reuse attribute is redundant; especially since the supervisor verifies that the two concept names are identical.
Note:
You can destroy a concept, and therefore reuse its name later.
3.5. Body of an order#
3.5.1. Introduction#
The body of a command contains the « variable » part of the command. Declarations are separated by commas and apart from the reuse attribute mentioned above, they are all of the form:
[keyword] = [argument]
The keyword is necessarily a keyword for the current order, declared in the catalog of the order in progress.
3.5.2. Key word#
A keyword is a formal identifier, it is the name of the attribute receiving the argument.
Example: MATRICE =…
Syntactic notes:
the order in which keywords appear is free, it is not imposed by the order in which they are declared in catalogs,
keywords cannot exceed 16 characters (but only the first 10 characters are significant) .
There are two types of keywords: simple keywords and factor keywords that differ in the nature of their arguments.
3.5.3. Simple keyword argument#
3.5.3.1. The type of arguments#
The basic types recognized by the supervisor are:
integers,
the real ones,
complexes,
the texts,
the logics,
the concepts,
as well as the lists of these types of bases.
Integers and reals correspond exactly to equivalent types in Python.
Optional simple keyword expecting a real one:
Catalog: VALE = SIMP (status='f', typ = 'R'),
Command file: VALE = 10. ,
Optional simple keyword expecting an integer:
Catalog: INFO = SIMP (status='f', typ = 'I'),
Command file: INFO = 1,
The representation of the complex type is a Python « tuple » containing a character string indicating the mode of representation of the complex number (real and imaginary parts or modules-phase) then the numerical values.
Catalog: VALE_C = SIMP (status='f', typ = 'C'),
Command file: VALE_C = ('RI', 0.732, -0.732),
Command file: VALE_C = ('MP', 1., -45.),
The two notations are strictly equivalent. In “MP” notation, the phase is in degrees.
The text type is declared between simple dimensions. The case is respected. However, when a keyword must take a value from a predefined list in the catalog, it is customary for this value to be always in capitals today.
Catalog: TOUT = SIMP (typ=' TXM ', into =(' OUI ',' NON ')),
Command file: TOUT = 'OUI',
Case is important and, in the context above, the following command line will fail:
Command file: TOUT = 'yes',
The logical type is not used in the order catalog today.
The concept is declared simply by name, with no quotes or quotes.
3.5.3.2. List concept#
Attention:
The word « list » is a misnomer here. This is not the Python « list » type but rather tuples, in the Python sense: the various items are declared between an opening bracket and a closing bracket; they are separated by commas.
Lists are homogeneous lists, that is to say whose elements are of the same basic type. Any type of base can be used as a list.
List examples:
integer list |
(1, 2, 3, 4), |
text list |
(“this”, “is”, “is”, “a”, “list”, “of”, “text”), |
concept list |
(resu1, resu2, resu3), |
Ease of use:
It is accepted that a list reduced to one element can be described without brackets.
Example of an erroneous list:
Heterogeneous list of integers and reals
3.5.4. Keyword factor#
Some information cannot be given globally (all at once in the order), so it is important to provide for the repetition of certain keywords, in order to be able to assign different arguments to them. The factor keyword offers this possibility; under a factor keyword, we will therefore find a set of (simple) keywords, which can be used at each occurrence of the factor keyword. This also makes it possible to improve the readability of the command file by grouping keywords that share a common meaning: for example the different parameters of the same material.
Unlike the simple keyword, the factor keyword can only receive one type of object: the supervisor object « _F », or a list of this one.
Let the keyword factor have only one occurrence and you can write for example, at your choice:
IMPRESSION = _F (RESULTAT = resu, UNITE = 6),
or
IMPRESSION = (_F (RESULTAT = resu, UNITE = 6),),
In the first case, the keyword factor IMPRESSIONreçoit an _F object, in the other case, it receives a singleton. Beware of the comma; in Python, a one-element tuple is written as: (element,)
Let the keyword factor have several occurrences, two in this example:
IMPRESSION = (_F (RESULTAT = resu1, UNITE = 6),
_F (RESULTAT = resu2, UNITE = 7)),
The expected number of occurrences (minimum and/or maximum) of a factor keyword is defined in the order catalog.
Default value notion
It is possible to have the supervisor assign values by default. These values are defined in the order catalog and not in FORTRAN.
From the point of view of the routine associated with the command, there is no distinction between a value provided by the user and a value by default introduced by the supervisor. This appears when user commands are printed by the supervisor in the message file: all default values appear in the command text, if they were not provided by the user
Reminder: you cannot give a concept a step value by default.