1 #@ MODIF post_dyna_alea_ops Macro DATE 10/10/2006 AUTEUR MCOURTOI M.COURTOIS
2 # -*- coding: iso-8859-1 -*-
3 # CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2006 EDF R&D WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
9 # (AT YOUR OPTION) ANY LATER VERSION.
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
18 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
19 # ======================================================================
21 def post_dyna_alea_ops(self,INTE_SPEC,NUME_VITE_FLUI,TOUT_ORDRE,NUME_ORDRE_I,
22 NOEUD_I,OPTION,MOMENT,TITRE,INFO,**args):
24 from types import ListType, TupleType
25 EnumTypes = (ListType, TupleType)
27 from Utilitai.Utmess import UTMESS
28 from Utilitai.t_fonction import t_fonction
29 from Utilitai.Table import Table
32 from math import pi,sqrt
34 commande='POST_DYNA_ALEA'
37 # La macro compte pour 1 dans la numerotation des commandes
40 # Le concept sortant (de type table_sdaster ou dérivé) est tab
41 self.DeclareOut('tabout', self.sd)
43 # On importe les definitions des commandes a utiliser dans la macro
44 # Le nom de la variable doit etre obligatoirement le nom de la commande
45 CREA_TABLE = self.get_cmd('CREA_TABLE')
46 CALC_TABLE = self.get_cmd('CALC_TABLE')
47 IMPR_TABLE = self.get_cmd('IMPR_TABLE')
48 RECU_FONCTION = self.get_cmd('RECU_FONCTION')
49 IMPR_FONCTION = self.get_cmd('IMPR_FONCTION')
51 intespec=INTE_SPEC.EXTR_TABLE()
53 # ------------------------------------------------------------------
54 # Liste des moments spectraux
55 # repérer le type de l'interspectre et son nom
56 # 1- concept interspectre
57 # 2- table de table d interspectre
59 if 'NUME_VITE_FLUI' in intespec.para :
61 jnuor=intespec['NUME_VITE_FLUI'].values()['NUME_VITE_FLUI']
62 jvite=dict([(i,0) for i in jnuor]).keys()
64 jvite=[NUME_VITE_FLUI,]
68 # ------------------------------------------------------------------
69 # Repérer les couples d'indices selectionnés
70 # vérification de l'égalité du nombre d indices en i et j
72 if NUME_ORDRE_I!=None :
74 l_ind_j=args['NUME_ORDRE_J']
75 if type(l_ind_i) not in EnumTypes : l_ind_i=[l_ind_i]
76 if type(l_ind_j) not in EnumTypes : l_ind_j=[l_ind_j]
77 if len(l_ind_i)!=len(l_ind_j) :
78 txt = "il faut autant d indices en I et J"
79 UTMESS('F',commande, txt)
80 listpara=['NUME_ORDRE_I','NUME_ORDRE_J']
82 dicotabl={'NUME_ORDRE_I' : l_ind_i ,\
83 'NUME_ORDRE_J' : l_ind_j , }
86 l_ind_j=args['NOEUD_J']
87 l_cmp_i=args['NOM_CMP_I']
88 l_cmp_j=args['NOM_CMP_J']
89 if type(l_cmp_i) not in EnumTypes : l_cmp_i=[l_cmp_i]
90 if type(l_cmp_j) not in EnumTypes : l_cmp_j=[l_cmp_j]
91 if type(l_ind_i) not in EnumTypes : l_ind_i=[l_ind_i]
92 if type(l_ind_j) not in EnumTypes : l_ind_j=[l_ind_j]
93 if len(l_ind_i)!=len(l_ind_j) :
94 txt = "il faut autant d indices en I et J"
95 UTMESS('F',commande, txt)
96 if len(l_cmp_i)!=len(l_cmp_j) :
97 txt = "il faut autant de composantes en I et J"
98 UTMESS('F',commande, txt)
99 if len(l_ind_i)!=len(l_cmp_i) :
100 txt = "il faut autant de composantes que de noeuds"
101 UTMESS('F',commande, txt)
102 listpara=['NOEUD_I','NOEUD_J','NOM_CMP_I','NOM_CMP_J']
103 listtype=['K8','K8','K8','K8',]
104 dicotabl={'NOEUD_I' : l_ind_i,\
105 'NOEUD_J' : l_ind_j,\
106 'NOM_CMP_I': l_cmp_i,\
107 'NOM_CMP_J': l_cmp_j }
108 # ------------------------------------------------------------------
109 # Cas de tous les indices centraux
112 if 'NUME_ORDRE_I' in intespec.para :
113 inuor=intespec['NUME_ORDRE_I'].values()['NUME_ORDRE_I']
114 imode=dict([(i,0) for i in inuor]).keys()
117 listpara=['NUME_ORDRE_I','NUME_ORDRE_J']
119 dicotabl={'NUME_ORDRE_I' : l_ind_i ,\
120 'NUME_ORDRE_J' : l_ind_j , }
122 if 'NUME_VITE_FLUI' in intespec.para :
123 intespec=intespec.NUME_VITE_FLUI==jvite[0]
124 l_ind_i=intespec['NOEUD_I'].values()['NOEUD_I']
125 l_ind_j=intespec['NOEUD_J'].values()['NOEUD_J']
126 if len(l_ind_i)!=len(l_ind_j) :
127 txt = "il faut autant d indices en I et J"
128 UTMESS('F',commande, txt)
129 l_cmp_i=intespec['NOM_CMP_I'].values()['NOM_CMP_I']
130 l_cmp_j=intespec['NOM_CMP_J'].values()['NOM_CMP_J']
131 if (len(l_ind_i)!=len(l_cmp_i) or len(l_ind_j)!=len(l_cmp_j)) :
132 txt = "il faut autant de composantes que de noeuds"
133 UTMESS('F',commande, txt)
134 l_l=zip(zip(l_ind_i,l_cmp_i),zip(l_ind_j,l_cmp_j))
141 l_ind_i.append(ai[0])
142 l_ind_j.append(aj[0])
143 l_cmp_i.append(ai[1])
144 l_cmp_j.append(aj[1])
145 listpara=['NOEUD_I','NOEUD_J','NOM_CMP_I','NOM_CMP_J']
146 listtype=['K8','K8','K8','K8',]
147 dicotabl={'NOEUD_I' : l_ind_i*len(jvite) ,\
148 'NOEUD_J' : l_ind_j*len(jvite) ,\
149 'NOM_CMP_I': l_cmp_i*len(jvite) ,\
150 'NOM_CMP_J': l_cmp_j*len(jvite) }
153 listpara.append('NUME_VITE_FLUI')
155 dicotabl['NUME_VITE_FLUI']=[]
156 # ------------------------------------------------------------------
157 # Liste des moments spectraux
159 l_moments=[0,1,2,3,4]
161 l_moments=l_moments+list(MOMENT)
162 l_moments=dict([(i,0) for i in l_moments]).keys()
164 # ------------------------------------------------------------------
165 # Boucle sur les tables
167 l_ind=zip(l_ind_i,l_ind_j)
170 texte='POUR LA MATRICE INTERSPECTRALE '+INTE_SPEC.nom+'\n'
171 aster.affiche('MESSAGE',texte)
175 dicotabl['NUME_VITE_FLUI'].append(vite)
176 mcfact.append(_F(NOM_PARA='NUME_VITE_FLUI',VALE_I=vite))
177 if 'NOEUD_I' in listpara :
178 mcfact.append(_F(NOM_PARA='NOEUD_I',VALE_K=ind[0]))
179 mcfact.append(_F(NOM_PARA='NOEUD_I',VALE_K=ind[1]))
181 aster.affiche('MESSAGE','INDICES :'+ind[0]+' - '+ind[1]+'\n')
183 mcfact.append(_F(NOM_PARA='NUME_ORDRE_I',VALE_I=ind[0]))
184 mcfact.append(_F(NOM_PARA='NUME_ORDRE_J',VALE_I=ind[1]))
186 aster.affiche('MESSAGE','INDICES :'+str(ind[0])+' - '\
188 __fon1=RECU_FONCTION(TABLE = INTE_SPEC,
189 NOM_PARA_TABL= 'FONCTION_C',
191 val = __fon1.Valeurs()
192 fvalx= Numeric.array(val[0])
193 fvaly= Numeric.array(val[1])
196 #--- moments spectraux
199 for i_mom in l_moments :
200 trapz = Numeric.zeros(len(fvaly),Numeric.Float)
202 valy = fvaly*(2*pi*fvalx)**i_mom
203 trapz[1:] = (valy[1:]+valy[:-1])/2*(fvalx[1:]-fvalx[:-1])
204 prim_y = Numeric.cumsum(trapz)
205 val_mom[i_mom] = prim_y[-1]
206 for i_mom in l_moments :
207 chmo='LAMBDA_'+str(i_mom).zfill(2)
208 if dicotabl.has_key(chmo) : dicotabl[chmo].append(val_mom[i_mom])
210 dicotabl[chmo]=[val_mom[i_mom],]
211 listpara.append(chmo)
214 #--- fonctions statistiques
216 pstat = {'ECART' :0.,\
217 'NB_PASS_ZERO_P_S':0.,\
218 'NB_EXTREMA_P_S' :0.,\
221 if (NUME_VITE_FLUI or frez>=0.) :
222 #--- cas NUME_VITE_FLUI, seule la partie positive du spectre est utilisée
223 #--- Il faut donc doubler lambda pour calculer le bon écart type
224 pstat['ECART'] = sqrt(val_mom[0]*2.)
226 pstat['ECART'] = sqrt(val_mom[0])
227 if abs(val_mom[2])>=1e-20 :
228 pstat['NB_EXTREMA_P_S'] = 1./pi*sqrt(val_mom[4]/val_mom[2])
229 if abs(val_mom[0])>=1e-20 :
230 pstat['NB_PASS_ZERO_P_S'] = 1./pi*sqrt(val_mom[2]/val_mom[0])
231 pstat['FREQ_APPAR'] = 0.5*pstat['NB_PASS_ZERO_P_S']
232 if abs(val_mom[4])>=1e-20 :
233 pstat['FACT_IRRE'] = sqrt( val_mom[2]*val_mom[2]/val_mom[0]/val_mom[4])
235 for key in pstat.keys():
236 if dicotabl.has_key(key) : dicotabl[key].append(pstat[key])
238 dicotabl[key]=[pstat[key],]
242 #--- construction de la table produite
245 for i in range(len(listpara)) :
247 mcfact.append(_F(PARA=listpara[i] ,LISTE_R=dicotabl[listpara[i]] ))
248 if listtype[i]=='K8':
249 mcfact.append(_F(PARA=listpara[i] ,LISTE_K=dicotabl[listpara[i]] ))
251 mcfact.append(_F(PARA=listpara[i] ,LISTE_I=dicotabl[listpara[i]] ))
252 tabout = CREA_TABLE(LISTE=mcfact,TITRE = 'POST_DYNA_ALEA concept : '+self.sd.nom)