Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
1/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
Organization (S):
EDF-R & D/AMA
Instruction manual
U4.3- booklet: Function
Document: U4.31.05
Operator
FORMULATE
1 Goal
To define a real formula starting from its mathematical expression.
The formula will be usable in a further order like argument of the function type/formula
or evaluated with particular values of the variables.
In many applications, one can tabuler this formula for particular values by
order
CALC_FONC_INTERP
[U4.32.01] which produces a concept of the type
function
like
DEFI_FONCTION
[U4.31.02] or
DEFI_NAPPE
[U4.31.03].
Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
2/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
2 Syntax
F = FORMULA
(
NOM_PARA
=
name
parameters
[l_K8]
VALE
= """ definition of the function """
[K]
)
Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
3/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
3 Operands
3.1
Definition of the function, key word VALE
The body of the function is an algebraical expression PYTHON represented by a channel of
characters. It must be appraisable in the context: thus to respect syntax PYTHON and not to use
that functions, methods or constants defined before the moment of its evaluation.
In the event of error of syntax, it is the language PYTHON which transmits the error message and not
Code_Aster itself.
3.2 Functions
standards
For a formula represented by an ordinary algebraic function, to refer to:
“Using PYTHON have has calculator”, paragraph [§3.1.1]
http://docs.python.org/tut/tut.html
In addition to the ordinary algebraical signs + -/***, functions standards are also available
(buildins): min, max, ABS, float…
Attention, the sign of division indicates real division here:
1/2 = 0.5
If one wishes to make a whole division operation, the operator should be used//:
1//2 = 0
3.3 Functions
mathematics
The main functions of the module maths of PYTHON are imported by defect. They are thus
directly usable in the body of the formulas.
http://docs.python.org/lib/module-math.html
sin sinh
cos cosh
tan tanh
atan sqrt
atan2 log
asin log10
acos exp
Moreover, constant pi, same module, is also available.
Caution:
The goniometrical functions are thus those of PYTHON and await angles expressed in
radians. It is necessary to be vigilant on coherence with single-ended spanner words ANGL_ * of the language of
order which requires angles in degrees in general.
One can use others of them by taking care to before import them the statement of
formulate. Example of redefinition of the exponential one:
from maths importation E, pow
f_exp = FORMULA (NOM_PARA=' X', VALE=' pow (E, X) ')
Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
4/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
4 Examples
of use
For various examples one will refer to the case test ZZZZ100A.
4.1
A formula is used like a tabulée function
Definition of the Sia formula:
SIa = FORMULA (NOM_PARA=' X', VALE=' sin (X) ')
LR = DEFI_LIST_REEL (BEGINNING = 0.,
INTERVAL = _F (JUSQU_A = pi, NOT = 0.01))
Equivalent tabulée function IF:
IF = CALC_FONC_INTERP (FUNCTION = SIa,
LIST_PARA = LR,
NOM_PARA = “X”,
NOM_RESU = “DEPL”,)
To thus define a function tabulée starting from an interpretable formula, to see
CALC_FONC_INTERP
[U4.32.01].
Use of IF or of SIa in a single-ended spanner word awaiting a function or a formula:
champ=CREA_CHAMP (… AFFE = _F (… VALE_F = IF or SIa,))
4.2
A formula can be evaluated like a reality
In the body of the command file:
SIa = FORMULA (NOM_PARA=' X', VALE=' sin (X) ')
X = SIa (1.57)
print SIa (1.57)
Behind a single-ended spanner word awaiting a reality:
LR = DEFI_LIST_REEL (BEGINNING = SIa (0.),
INTERVAL = _F (JUSQU_A = SIa (pi/2.) , NOT = 0.01))
In another formula:
SIb = FORMULA (NOM_PARA=' X', VALE=' X * SIa (5.)')
4.3
To call upon a formula in another formula
SIa = FORMULA (NOM_PARA=' X', VALE=' sin (X) ')
SIb = FORMULA (NOM_PARA=' X', VALE=' X * SIa (X) ')
Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
5/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
4.4
Formulate with several parameters
NAP = FORMULA (NOM_PARA = (“FREQ”, “AMOR”),
VALE = ''' (1./((2.* pi * FREQ) ** 2 - OMEGA ** 2) ** 2
+ (2.* AMOR * 2.* pi * FREQ * OMEGA) ** 2) ''')
In this example, one defines a formula in 3 parameters. Taking into account the length of the expression,
it is written for more convenience on several lines with triple dimensions to delimit it.
constant pi is constant a standard (cf paragraph [§3.2]), the OMEGA constant will have been defined
higher by the user.
In the current state, only the formulas of R
N
in R are possible: only one produced reality.
4.5
Formulate resulting from programming of function PYTHON
One can refer in a formula to functions programmed in PYTHON, which authorizes
formulas much more complex than of simple algebraical expressions.
For example a function of Heavyside:
HEAVYSIDE
()
X
if X
if X
.
.
=
<
0
0
1
0
The method python is programmed as follows:
def HEAVYSIDE (X):
yew x<0. : return 0.
Yew x>=0. : return 1.
F_HVS = FORMULA (NOM_PARA = “INST”,
VALE = “HEAVYSIDE (INST)”)
Caution:
The use of programming PYTHON in the command file (here method HEAVYSIDE)
is incompatible with the edition of this file with EFICAS.
Code_Aster
®
Version
8.2
Titrate:
Operator
FORMULATE
Date:
31/01/06
Author (S):
C. DURAND
Key
:
U4.31.05-G1
Page:
6/6
Instruction manual
U4.3- booklet: Function
HT-62/06/004/A
Intentionally white left page.