Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 1/16
Organization (S): EDF-R & D/AMA
Handbook of Descriptif Informatique
D5.01 booklet: -
Document: D5.01.02
To introduce a new macro-command
Summary
This document describes how to define and use the macro-commands in python.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 2/16
1 Introduction
This document describes the use and the development of the macro-commands in Python for
Code_Aster. These macro-commands can be restored in the code and visible of the user
like commands with whole share. But they can also be placed in the file of
order itself without the user has to touch neither with the executable one, nor with the catalog of
commands. Moreover, they have the advantage of being written “naturally” in the language of
order: the body of a macro-command is similar to an ordinary command file which
the same sequence of commands would generate.
The developer will may find it beneficial great to read the programming of existing macro-commands, under
bibpyt/Macro in the repertory of installation of Code_Aster.
2
What macro?
Macro is a command which gathers the execution of several subcommands. It is
usable in a command file like any other command and has its characteristic
catalog, defining its syntax. Several types of macro are possible:
·
macros specific to the supervisor, implemented in Python and FORTRAN: for example
FORMULATE, INCLUDE, BEGINNING…
·
macros developers implemented in Python.
This document treats definition and use of the macros in Python.
3
To use the macros
To use the macros in Python is simple. Compared to simple commands like OPER or
PROC, the only difference relate to the concepts produced by the macro one. A simple command, of
type OPER, has only one produced concept which one will find on the left of the sign “=”, as follows:
concept = command (word-key-simple-or-factors)
A simple ordering of type PROC does not have any produced concept and is written:
order (word-key-simple-or-factors)
A macro-command, of type MACRO, can have several produced concepts. One which one will find with
left of the sign =, as for a OPER, others like arguments of the simple key words or
factors. One will present the instructions for a simple key word. It extends easily to the key words
factors. Certain key words are likely to produce concepts. To ask one
macro-command to produce this concept, the user will write on the right sign = following the name of
key word, CO (“nom_concept”), as in the example which follows:
MACRO_MATR_ASSE (NUMEDDL=CO (“num”))
This causes to create a produced concept of name num at output of the command
MACRO_MATR_ASSE. Its type will be given according to the conditions of call of the command. CO
is a reserved name which makes it possible to create named produced concepts, not typified, before
the call of the command. It is the command which will allot the good type to this concept.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 3/16
4
To define a macro-command in Python
It is necessary to define:
· the catalog itself of the key words composing the macro one,
· method of typing of the structures of produced data,
· the Python method defining the body of macro: produced “basic” commands
by the macro one and their sequence.
The first two points are common with the writing of an ordinary command (except for one
minor difference in the method of typing).
It is possible to restore all this in the catalog of commands of the code and to thus return
visible macro-command of all. One can also preserve his development deprived with
the advantage of not having to modify the parameters of execution or the executable one while placing these three
elements directly at the head of the command file, or the important one (Python importation) since
an agreed localization.
4.1
To write the catalog of the macro-command
The catalog of macro is similar to that of a simple command. The three differences are:
· an object MACRO is declared (and not PROC or OPER),
· the key word reserved COp does not contain an entirety (indicating the number of routine FORTRAN of
high level for OPER and PROC) but a name of method python,
· the produced concept necessarily single, is not declared on the left a sign “=”.
Produced concepts can be specified as arguments of a simple key word. If a key word
simple can accept a concept produced like argument, it is necessary, in addition to the type, specify CO in
tuple typ.
Simple example of key word accepting a produced concept or an existing concept:
NUME_DDL =SIMP (statut=' o', typ= (nume_ddl, CO))
Here, the key word accepts in argument an existing concept of nume_ddl type or a concept to be produced
of a type which will be determined by the command.
4.2
To define the type of the produced concepts
The definition of the type of the produced concepts of a macro-command is carried out in a way similar to
that of a simple ordering of type OPER.
If the command produces only one concept which one will find on the left of the sign = as in:
=COMMANDE has ()
one will proceed in the same way as for a simple command of type OPER.
If the macro-command can produce several concepts whose some in arguments of
key words, some additional information should be added. First of all, it is necessary absolutely
to provide a Python function, named sd_prod, in the definition of macro. Then, key words
simple containing the name user of the concept to be produced must be of type CO (reserved name).
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 4/16
For example:
def ma_macro_prod (coil, NUME_DDL, MATRICE, ** args):
yew isinstance (NUME_DDL, CO):
self.type_sdprod (NUME_DDL, nume_ddl_sdaster)
self.type_sdprod (MATRICE, matr_asse_depl_r)
return evol_noli
….
MA_MACRO =MACRO (sd_prod=ma_macro_prod,…
MATRICE
=
SIMP (statut=' o', typ=CO),
….
NUME_DDL
=
SIMP (statut=' o', typ= (CO, numeddl)
),
)
In this case, three concepts can be produced:
· in a traditional way, a concept of the evol_noli type which will have been given by the user to
left of the sign “=”
· a concept of the matr_asse_depl_r type whose name will have been provided by the user behind
single-ended spanner word MATRICE
· for case NUME_DDL, the user has the choice between providing here a concept numeddl already
existing or to make it produce by the macro one, in which case it determines itself its naming
as in case MATRICE.
When a key word can have in argument a concept to produce, the key word must appear in
list arguments of the function sd_prod and the concept must be typified by using the method
type_sdprod of the argument self-service which is the macro-command object.
NB: This argument self-service is not present for a OPER or a PROC.
4.3
To define the body of macro
4.3.1 Transmission of the key words the macro one with the method of construction (it
body)
The body the macro one will be defined in a function whose arguments are similar to those of
function sd_prod. The first argument is the macro-command object, coil, the following are them
key words necessary to express the body of macro. Useless key words to express it
bodies the macro one will be ignored by the use of the argument ** args.
Only the high level key words are transmitted: MCSIMP of first level, MCFACT. These
key words are then called upon very simply by their name.
Example of function body:
def ma_macro_ops (coil, UNITE_MAILLAGE, ** args):
..................
_NOMLMA = LIRE_MAILLAGE (UNIT = UNITE_MAILLAGE)
..................
Here, UNITE_MAILLAGE is a MCSIMP the macro one, its contents (concept, list, string,… little
import) is affected with MCSIMP UNITE of command LIRE_MAILLAGE.
Case of a key word factor:
def ma_macro_ops (coil, MATR_ASSE_GENE, ** args):
..................
yew MATR_ASSE_GENE [“MATR_ASSE”]:
..................
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 5/16
MATR_ASSE_GENE is a MCFACT the macro one, MATR_ASSE is one of its under-MCSIMP. One
MCFACT is handled like a dictionary.
Easy way: in this last example, one tests very simply the presence of MATR_ASSE: if the user
a key word (simple or factor did not inform), it is worth by None defect.
4.3.2 To call a command in the body the macro one
To call a command in the body the macro one, it is possible to use two methods.
The first is simplest. It is possible if the command exists in the total context of
function defining the body of macro. One is in this case within the catalog of reference
code. One will make then simply:
num=NUME_DDL (METHODE=…,…)
If the command does not exist in the context, it is necessary to question the catalog by
the intermediary of the method get_cmd of the object macro-command coil to obtain this
order:
NUME_DDL=self.get_cmd (“NUME_DDL”)
num=NUME_DDL (METHODE=…,…)
It is essential to use the exact name of the command as name of the variable which will contain
the return of the method get_cmd. Indeed this name is used to locate the line of text containing
this name and thus to identify the name of the produced concept (here num).
There is no obstacle so that the commands “girls” produced by the macro-command are
they-even of the macro-commands.
4.3.3 Concept interlinks produced in the body and concepts produced by
macro
The concepts produced in the body of macro are several kinds:
·
concepts named automatically and destroyed at the end of the execution the macro one
order. One thus should not any more need some thereafter and it is necessary in particular to take care of it
that the concept produced by the macro one does not refer there. To indicate that it is about one
concept of this kind, it is enough to give him a name which starts with _ _ (double
underscore)
Example:
__a=CALC_MATR_ELEM (MODELE=MODELE)
Then, as one can read it in the file of messages, an automatic name of concept,
preceded by a point is generated:
.9000005=CALC_MATR_ELEM (MODELE=MODELE)
Once left macro, the object corresponding in the name of concept .9000005 does not exist any more,
neither in the space of names of the supervisor, nor in the jeveux base.
·
concepts named automatically and preserved in the jeveux base at the end of
macro-command. To indicate that it is about a concept of this kind, it is enough to give him
a name which starts with _ (simple underscore)
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 6/16
Example:
_a=CALC_MATR_ELEM (MODELE=MODELE)
Then, as one can read it in the file of messages, an automatic name of concept,
preceded by a underscore is generated:
_9000005=CALC_MATR_ELEM (MODELE=MODELE)
Once left macro, the object corresponding in the name of concept _9000005 does not exist
in the space of names of the supervisor, it is on the other hand present under this name in the base
jeveux.
This type of object answers the particular situations where the concept produced by the macro one
“depends” on a concept upstream which will have to be always present: for example a model
relative with a grid, one matr_asse relative with a nume_ddl.
·
concepts intended to become produced concepts of macro. To indicate that it acts
of a concept of this kind, it is necessary to call the DeclareOut method of the object macro coil
with, like arguments, the name of the variable of return of the command and the object resulting from
key words of the macro-command.
Example with matrix, argument of a key word the macro one:
self.DeclareOut (“me, matrix)
mm=ASSE_MATRICE (............)
·
the concept of output the macro one (necessarily single) is treated in a similar way in
indicating the concept of output self.sd.
self.DeclareOut (“me, self.sd)
mm=ASSE_MATRICE (............)
mm will become the concept of output the macro one, it will bear the name given by the user in
its command file (and not mm).
4.3.4 To number the macro one
In the displays of the file of messages, all the commands are numbered. For
to increment this meter, it is systematically necessary to at the head invite the following method body of
macro: self.set_icmd (1)
It is particularly important to appeal this before any command “
girl
” of
macro-command because this method also initializes the total measurement of time CPU for
macro.
4.3.5 To treat the errors
As for a command in FORTRAN, it is possible to detect errors of use in
body the macro one by the Utmess utility, identical in its operation to its homonym
FORTRAN [D6.04.01]. With this intention, it is necessary to import this method since the module of the utilities
Python.
Example:
from Utilitai.Utmess importation UTMESS
…
message= “the two ends must be \
message=message+' of the same length in the case of symmetry \
UTMESS (“F”, “MACR_ASCOUF_MAIL”, message)
The first argument indicates the nature of the error or alarm, the second specifies the appealing routine and
the last contains the message bound for the user.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 7/16
4.3.6
displays
The displays in the files of message and result can come from the programmed part
in Python like that programmed in FORTRAN. So that sequencing of these displays
that is to say well respected (and thus that the aforementioned files are quite readable), it is strongly disadvised using
the command Python print but rather to employ the utility displays, of the module aster.
Example:
importation aster
…
aster.affiche (“MESSAGE”, mon_texte_dans_une_string)
The first argument is worth “MESSAGE” or “RESULTAT” following the target file.
4.3.7 To identify the concepts produced by the macro one
In certain circumstances, it is necessary to determine if a concept is produced by macro itself or has
summer produced by a preceding command. This is possible while testing if the concept in question is
present or not in the list of the concepts produced by the macro one which is given by the attribute sdprods
object macro coil.
Example:
yew nume_ddl in self.sdprods:
# the concept nume_ddl is produced by the macro one
# it is necessary to call command NUME_DDL
lnume = 1
else:
# the concept nume_ddl already exists.
lnume=0
Attention, sdprods does not contain the produced concept turned over by the macro one which is in
the attribute sd of coil.
4.3.8 Dynamic creation of commands: a number of variable key words, contained
contextual
In certain cases, according to the value of the options, the same command will be called with different
key words or of the different arguments. To treat this situation and to generate dynamically
order, one builds a dictionary containing the key words to write which is then transmitted in
argument of the command, preceded by the characters “**”. The dictionary “is then unfolded”, the keys
are the arguments (key words), followed contents of the key, behind the sign “=”.
This Python dictionary can be built progressively with the examination of the options.
Example:
moscles= {}
moscles [“INFO”] = 2
standard yew (“GROUP_MA_BORD”) ==types.StringType:
motscles [“CREA_GROUP_NO”] = _F (GROUP_MA = GROUP_MA_BORD)
else:
motscles [“CREA_GROUP_NO”] = []
for grma in GROUP_MA_BORD:
motscles [“CREA_GROUP_NO”]. suspends (_F (GROUP_MA = grma))
_nomlma = DEFI_GROUP (reuse = _nomlma
MAILLAGE
=
_nomlma,
** motscles
)
The list of MCFACT behind key “CREA_GROUP_NO” of the dictionary motscles contains a _F object
in the first case and a list of _F in the second case. The list is built by one suspends in
a loop.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 8/16
Note:
In this example, if CREA_GROUP_NO contains only one element, it is not a singleton
but a string, from where need for importing the module standards to call upon StringType or
ListType.
4.3.9 Call to an external code
If one wishes to carry out in macro third code by command EXEC_LOGICIEL or by
the instruction python os.system, one must recover the path of the appealable software in a chain
characters turned over by routine FORTRAN repout.f; this routine is appealable since python
by the method repout of the module aster.
importation os.path
importation aster
path = aster.repout ()
miss 3D = os.path.join (path, “miss 3D”)
EXEC_LOGICIEL (…, LOGICIEL = miss 3D,…)
5
Considerations on the use of the macros in Python
5.1
Definition of macro except catalog
Standard method to add the definition of macro in Python for an execution of
Code_Aster is to add it in the catalog of reference of the code.
However, in certain cases:
·
macro personal,
·
test during the development,
it can be practical to add the definition of macro apart from the catalog. With this intention, it is enough to
to create a Python module at the head containing the definition of macro by adding module the importation of
variables of the catalog.
Simplified example:
from Cata.cata importation *
def ma_macro_prod (coil,…):
.....
def ma_macro_ops (coil,…):
….
MA_MACRO=MACRO (nom=' MA_MACRO',…)
Then with the use, the weather is enough in the command file to be during the importation of macro previously
defined.
Example of command file:
# the macro MA_MACRO is defined in the module ma_macro.py
from ma_macro importation MA_MACRO
a=MA_MACRO (...)
It is also possible to use the functionality of INCLUDE:
# the macro MA_MACRO is defined in file INCLUDE 45
INCLUDE (UNITE=45)
a=MA_MACRO (...)
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 9/16
6 Some
errors
During the development or use of a macro-command in Python, errors of use
or of definition of macro can occur. The most characteristic errors are presented
below.
6.1
Invalid argument of key word detected in the body of macro
A possible user error can be detected on the level of the body of the macro-command
during the phase of construction of the macros.
The user will obtain a report of the form then:
JDC.py: Construction of JdC INVALIDE
CR of 1ere phase of construction of JDC
Stage: MA_MACRO line: 42 file:
“/home01/chris/ASTER/bugs/Pymacros/tmp.1670/ahlv100a_err20”
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! THE FIRST OPTION MUST BE RIGI_MECA OR RIGI_THER OR RIGI_ACOU OR
! RIGI_MECA_LAGR
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fine Stage: MA_MACRO
fine CR of 1ere phase of construction of JDC
6.2
Invalid argument of key word detected by a subcommand
Macro recovers the values of its key words to transmit them to commands called
subcommands the macro one. It is possible that all the checks not having been made in
definition of macro, an argument of key word of the subcommand is invalid. This error will be
detected at the time of construction the macro one: Build method of the command set object J
JDC.py file. The user will obtain a report of the following form:
JDC.py: Construction of JdC INVALIDE
DEBUT CR validation: SansNom
Stage: MA_MACRO line: 42 file:
“/home01/chris/ASTER/bugs/Pymacros/tmp.1677/ahlv100a_err10”
Stage: NUME_DDL line: 102 file: “./ma_macro_err1.py”
Simple key word: METHODE
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! louse is not an authorized value!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! The value: “louse” is not allowed for the key word: METHODE!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fine simple Word-key: METHODE
Fine Stage: NUME_DDL
Fine Stage: MA_MACRO
FIN CR validation:SansNom
One can see that the command NUME_DDL which is a subcommand macro MA_MACRO is
invalid because key word METHODE is invalid.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 10/16
6.3
Error of syntax in the function body the macro one
If an error of syntax is made in the function body of macro, the user will obtain one
report of the following form:
JDC.py: ERROR ACCAS - INTERRUPTION
>> JDC.py: REPORT/RATIO BEGINNING
CR phase of initialization
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! error not envisaged and not traitee to prevent maintenance ahlv100a_err4.py
!
! Traceback (most recent cal last): !
! Slip by “./Eficas/Accas/commandes.py”, line 2029, in __init__!
! exec self.proc_compile in self.g_context!
! Slips by “/home01/chris/ASTER/bugs/Pymacros/tmp.1634/ahlv100a_err40”, line 13, in?
!
! from ma_macro_err4 importation MA_MACRO!
! Slip by “./ma_macro_err4.py”, line 46!
! a=!
! ^!
! SyntaxError: invalid syntax!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
fine CR phase of initialization
>> JDC.py: FINE REPORT/RATIO
6.4
Programming error in the function body the macro one
If a programming error is made in the function body of macro, the user will obtain
a report of the following form:
JDC.py: Construction of JdC INVALIDE
CR of 1ere phase of construction of JDC
Stage: MA_MACRO line: 41 file:
“/home01/chris/ASTER/bugs/Pymacros/tmp.1649/ahlv100a_err50”
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! impossible to build the macro MA_MACRO!
! Traceback (most recent cal last): !
! Slip by “./Eficas/Cata/asterexec.py”, line 174, in Build_MACRO!
! ier= apply (self.definition.proc, (coil,), D)!
! Slip by “./ma_macro_err5.py”, line 44, in ma_macro_ops!
! a=1/0!
! ZeroDivisionError: integer division gold modulo by zero!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Fine Stage: MA_MACRO
fine CR of 1ere phase of construction of JDC
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 11/16
6.5
Programming error in the function sd_prod the macro one
If a programming error is made in the function sd_prod the macro one, the user
a report of the following form will obtain:
JDC.py: ERROR ACCAS - INTERRUPTION
>> JDC.py: REPORT/RATIO BEGINNING
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Stage MA_MACRO line: 41 file: !
! /home01/chris/ASTER/bugs/Pymacros/tmp.1301/ahlv100a_err60 impossible D
to assign a type to the result!
! Slip by “./ma_macro_err6.py”, line 10, in ma_macro_prod!
! a=1/0!
! ZeroDivisionError: integer division gold modulo by zero!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>> JDC.py: FINE REPORT/RATIO
Important:
Moreover interpretation of the command file is stopped on the level of the error. In
consequence the possible errors on the following commands will be detected only
during later executions
7
An example of macro-command
One presents below an example of definition and use of macro-command in Python.
macro-command is defined in a Python module of name ma_macro.py. This module includes/understands 4
parts: a heading, a function sd_prod for the typing of the produced concepts [§7.1], a function
for the definition of the body the macro one [§7.2] and the definition of the key words the macro one [§7.3]. This
macro almost completely reproduces the functionalities of macro FORTRAN
MACRO_MATR_ASSE.
Note:
For better including/understanding the paragraphs [§7.1] and [§7.2], one will be able to start by reading them
paragraphs [§7.3] and [§7.4].
7.1
Typing of the produced concepts
# The function ma_macro_prod makes it possible to define the type of all the concepts
# produced by the macro one. It is identical to that of MACRO_MATR_ASSE
def ma_macro_prod (coil, NUME_DDL, MATR_ASSE, ** args):
yew not MATR_ASSE: raise AsException (“Impossible to typify the concepts
results ")
yew not NUME_DDL: raise AsException (“Impossible to typify the concepts
results ")
self.type_sdprod (NUME_DDL, nume_ddl)
for m in MATR_ASSE:
opti=m [“OPTION”]
yew opti in (“RIGI_MECA”, “RIGI_FLUI_STRU”, “RIGI_MECA_LAGR”,
“MASS_MECA”, “MASS_FLUI_STRU”, “RIGI_GEOM”, “RIGI_ROTA”,
“AMOR_MECA”, “IMPE_MECA”,
“ONDE_FLUI”, “MASS_MECA_DIAG”): t=matr_asse_depl_r
yew opti == “RIGI_MECA_HYST”: t= matr_asse_depl_c
yew opti == “RIGI_THER”: t= matr_asse_temp_r
yew opti == “MASS_THER”: t= matr_asse_temp_r
yew opti == “RIGI_THER_CONV”: t= matr_asse_temp_r
yew opti == “RIGI_THER_CONV_D”: t= matr_asse_temp_r
yew opti == “RIGI_ACOU”: t= matr_asse_pres_c
yew opti == “MASS_ACOU”: t= matr_asse_pres_c
yew opti == “AMOR_ACOU”: t= matr_asse_pres_c
self.type_sdprod (m [“MATRICE”], T)
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 12/16
# The macro one does not have a produced concept turned over on the left sign =.
# It is necessary to turn over None
return None
7.2
Body the macro one
def ma_macro_ops (coil, MODELE, CHAM_MATER, CARA_ELEM, MATR_ASSE,
SOLVEUR, NUME_DDL, LOAD, INST,
** args):
"""
Example of macro in Python reproducing part of
functionalities of MACRO_MATR_ASSE
"""
# Initialization of the meter of errors
ier=0
# importation of the utility of error messages
from Utilitai.Utmess importation UTMESS
nom_macro=' MACRO_MATR_ASSE "
# One puts key word NUME_DDL in a local variable to protect it
numeddl=NUME_DDL
# One imports the definitions of the commands has to use in the macro one
# The name of the variable must be obligatorily the name of the command
CALC_MATR_ELEM=self.get_cmd (“CALC_MATR_ELEM”)
NUME_DDL=self.get_cmd (“NUME_DDL”)
ASSE_MATRICE=self.get_cmd (“ASSE_MATRICE”)
# The macro account for 1 in the classification of the commands
self.set_icmd (1)
yew SOLVEUR:
# If the key word factor SOLVEUR is present
# One can recover the values of the single-ended spanner words
methode=SOLVEUR [“METHODE”]
renum=SOLVEUR [“RENUM”]
else:
# If the key word factor SOLVEUR misses
# One assigns to the single-ended spanner words default values
methode=' MULT_FRONT'
renum=' MDA'
yew method == “LDLT”:
yew renum not in (“SANS”, “RCMK”):
# An error was detected. One increments the meter and records
# a fatal message
ier=ier+1
UTMESS (“F”, nom_macro, “Avec method LDLT, RENUM must be SANS or
RCMK.“)
yew numeddl in self.sdprods:
# If the concept numeddl is in self.sdprods
# it must be produced by the macro one
# it will thus be necessary to call command NUME_DDL
lnume = 1
else:
lnume = 0
iocc=0
for m in MATR_ASSE:
iocc=iocc+1
option=m [“OPTION”]
yew iocc == 1 and lnume == 1 and option not in (“RIGI_MECA”,
“RIGI_MECA_LAGR”, “RIGI_THER”, “RIGI_ACOU”):
ier=ier+1
UTMESS (“F”, nom_macro,” PREMIERE OPTION DOIT ETRE RIGI_MECA OR
RIGI_THER OR RIGI_ACOU OR RIGI_MECA_LAGR ")
# An error was detected. One stops the construction of
macro.
return ier
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 13/16
motscles= {“OPTION”:option}
yew CHAM_MATER!= Nun: motscles [“CHAM_MATER”] =CHAM_MATER
yew CARA_ELEM!= Nun: motscles [“CARA_ELEM”] =CARA_ELEM
yew CHARGE:
yew option not in (“RIGI_ACOU”, “MASS_ACOU”):
motscles [“CHARGE”] =CHARGE
yew INST:motscles [“INST”] =INST
yew option == “AMOR_MECA”:
motscles [“RIGI_MECA”] =rigel
motscles [“MASS_MECA”] =masel
sigg=m [“SIEF_ELGA”]
yew sigg:motscles [“SIEF_ELGA”] =sigg
mh=m [“MODE_FOURIER”]
yew mh:motscles [“MODE_FOURIER”] =mh
__a=CALC_MATR_ELEM (MODELE=MODELE, THETA=m [“THETA”],
PROPAGATION=m [“PROPAGATION”], ** motscles)
yew option == “RIGI_MECA”:
# One preserves in rigel the result at the case or
rigel=__a
yew option == “MASS_MECA”:
# One preserves in masel the result at the case or
masel=__a
yew lnume and option in
(“RIGI_MECA”, “RIGI_THER”, “RIGI_ACOU”, “RIGI_MECA_LAGR”):
# One declares that the produced concept of name num is actually it
concept numeddl
self.DeclareOut (“num”, numeddl)
# One can pass from the equal key words has None. They are are unaware of
num=NUME_DDL (MATR_RIGI=__a, METHODE=methode,
RENUM=renum, TAILLE_BLOC=rbloc)
else:
num=numeddl
self.DeclareOut (“me, m [“MATRICE”])
mm=ASSE_MATRICE (MATR_ELEM=__a, NUME_DDL=num)
# One turns over the calculation of the errors
return ier
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 14/16
7.3
Definition of the key words
MA_MACRO = MACRO (nom= " MA_MACRO ", op=ma_macro_ops, sd_prod=ma_macro_prod,
fr= " Calcul of the matrices assembled (matr_asse_gd) for example of
rigidity, of mass “,
MODELE =SIMP (statut=' o', typ=modele),
CHAM_MATER =SIMP (statut=' f', typ=cham_mater),
CARA_ELEM =SIMP (statut=' f', typ=cara_elem),
CHARGE
=SIMP (statut=' f', typ= (char_meca, char_ther, char_acou)),
INST =SIMP (statut=' f', typ=' R'),
NUME_DDL =SIMP (statut=' o', typ= (nume_ddl, CO)),
SOLVEUR =FACT (statut=' of, min=01, max=01,
METHODE =SIMP (statut=' f', typ=' TXM', defaut= " MULT_FRONT ",
into= (“LDLT”, “MULT_FRONT”, “GCPC”)),
TAILLE_BLOC =SIMP (statut=' f', typ=' R'),
RENUM=SIMP (statut=' f', typ=' TXM', into= (“SANS”, “RCMK”, “MANDELEVIUM”, “MDA”, “METIS”)),
),
MATR_ASSE =FACT (statut=' o', min=01, max=' ** ',
MATRICE =SIMP (statut=' o', typ= (matr_asse, CO)),
OPTION =SIMP (statut=' o', typ=' TXM',
into= (“RIGI_MECA”, “MASS_MECA”, “MASS_MECA_DIAG”,
“AMOR_MECA”, “RIGI_MECA_HYST”, “IMPE_MECA”,
“ONDE_FLUI”, “RIGI_FLUI_STRU”, “MASS_FLUI_STRU”,
“RIGI_ROTA”, “RIGI_GEOM”, “RIGI_MECA_LAGR”,
“RIGI_THER”, “MASS_THER”, “RIGI_ACOU”, “MASS_ACOU”,
“AMOR_ACOU”)),
SIEF_ELGA =SIMP (statut=' f', typ=cham_elem_sief_r),
MODE_FOURIER =SIMP (statut=' f', typ=' I'),
THETA =SIMP (statut=' f', typ=theta_geom),
PROPAGATION =SIMP (statut=' f', typ=' R'),
),
TITER =SIMP (statut=' f', typ=' TXM', max=' ** '),
INFO =SIMP (statut=' f', typ=' I', defaut=1, into= (1,2)),
);
7.4
Use of macro
# This test of use is derived from the case test ahlv100a
# The macro MA_MACRO is defined in the private module ma_macro
# It should be imported with the command Python importation
from ma_macro importation MA_MACRO
BEGINNING (CODE=_F (NAME = “AHLV100A”))
F=500.
MAIL=LIRE_MAILLAGE ()
AIR=DEFI_MATERIAU (FLUIDE=_F (RHO = 1.3, CELE_C = (“IH”, 343., 0.,)))
CHAMPMAT=AFFE_MATERIAU (MAILLAGE=MAIL,
AFFE=_F (ALL = “YES”, MATER = AIR))
GUIDE=AFFE_MODELE (MAILLAGE=MAIL, VERIF=' MAILLE',
AFFE=_F (ALL = “YES”, MODELING = “3D”,
PHENOMENON = “ACOUSTIC”))
CHARACOU=AFFE_CHAR_ACOU (MODELE=GUIDE,
VITE_FACE=_F (GROUP_MA = “ENTERED”, VNOR =
(“IH”, 0.014, 0.,)))
IMPEACOU=AFFE_CHAR_ACOU (MODELE=GUIDE,
IMPE_FACE=_F (GROUP_MA = “LEFT”, IMPE =
(“IH”, 445.9, 0.,)))
# If one compares the use of the macro MA_MACRO with that of
MACRO_MATR_ASSE
# one will be able to note that there is no difference
MA_MACRO (
MODELE=GUIDE, CHARGE=IMPEACOU,
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 15/16
CHAM_MATER=CHAMPMAT,
NUME_DDL=CO (“NUM”),
MATR_ASSE= (
_F (MATRIX = CO (“MATASK”), OPTION = “RIGI_ACOU”),
_F (MATRIX = CO (“MATASM”), OPTION = “MASS_ACOU”),
_F (MATRIX = CO (“MATASI”), OPTION = “AMOR_ACOU”))
)
#
VECTELEM=CALC_VECT_ELEM (OPTION=' CHAR_ACOU',
CHAM_MATER=CHAMPMAT,
CHARGE=CHARACOU)
#
# IMPRESSION OF COMPLEX VECT_ELEM VECTELEM ACCORDING TO THE GRAIN NETS
#
IMPR_MATRICE (MATR_ELEM=_F (MATRIX = VECTELEM,
FORMAT = “RESULT”,
FILE = “RESULT”,
GRAIN = “MESH”))
VECTASS=ASSE_VECTEUR (VECT_ELEM=VECTELEM, NUME_DDL=NUM)
#
# _______________________CALCUL OF THE MODES_______________________________
#
# As for macro in FORTRAN, one uses the concepts produced by
the identifier
# created by the macro MATASK for CO (“MATASK”) for example.
MATASKR=COMB_MATR_ASSE (COMB_R=_F (MATR_ASSE = MATASK,
PART = “REAL”, COEF_R = 1.))
MATASMR=COMB_MATR_ASSE (COMB_R=_F (MATR_ASSE = MATASM,
PART = “REAL”, COEF_R = 1.))
#
MODES=MODE_ITER_SIMULT (MATR_A=MATASKR,
MATR_B=MATASMR,
CALC_FREQ=_F (OPTION = “TAPE”,
NMAX_FREQ = 10,
FREQ = (1., 1000.,))
)
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Code_Aster ®
Version
8.1
Titrate:
To introduce a new macro-command
Date:
01/12/05
Author (S):
C. Key DURAND
:
D5.01.02-C Page
: 16/16
Intentionally white left page.
Handbook of Descriptif Informatique
D5.01 booklet: - HT-66/05/003/A
Outline document