1 #@ MODIF reca_utilitaires Macro DATE 31/10/2006 AUTEUR ASSIRE A.ASSIRE
2 # -*- coding: iso-8859-1 -*-
3 # RESPONSABLE ASSIRE A.ASSIRE
4 # CONFIGURATION MANAGEMENT OF EDF VERSION
5 # ======================================================================
6 # COPYRIGHT (C) 1991 - 2006 EDF R&D WWW.CODE-ASTER.ORG
7 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY
8 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY
9 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR
10 # (AT YOUR OPTION) ANY LATER VERSION.
12 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT
13 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF
14 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU
15 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.
17 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE
18 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,
19 # 1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.
20 # ======================================================================
22 import Numeric, LinearAlgebra, copy, os, string, types, sys, glob
23 from Numeric import take
26 from Cata.cata import INFO_EXEC_ASTER, DEFI_FICHIER, IMPR_FONCTION, DETRUIRE
34 from Utilitai.Utmess import UTMESS
36 def UTMESS(code,sprg,texte):
37 fmt='\n <%s> <%s> %s\n\n'
38 print fmt % (code,sprg,texte)
39 if code=='F': sys.exit()
43 # ------------------------------------------------------------------------------
44 # ------------------------------------------------------------------------------
46 #_____________________________________________
48 # DIVERS UTILITAIRES POUR LA MACRO
49 #_____________________________________________
52 def transforme_list_Num(parametres,res_exp):
54 Transforme les données entrées par l'utilisateur en tableau Numeric
57 dim_para = len(parametres) #donne le nb de parametres
58 val_para = Numeric.zeros(dim_para,Numeric.Float)
59 borne_inf = Numeric.zeros(dim_para,Numeric.Float)
60 borne_sup = Numeric.zeros(dim_para,Numeric.Float)
62 for i in range(dim_para):
63 para.append(parametres[i][0])
64 val_para[i] = parametres[i][1]
65 borne_inf[i] = parametres[i][2]
66 borne_sup[i] = parametres[i][3]
67 return para,val_para,borne_inf,borne_sup
70 # ------------------------------------------------------------------------------
72 def mes_concepts(list_concepts=[],base=None):
74 Fonction qui liste les concepts créés
77 if e.nom in ('INCLUDE','MACR_RECAL',) :
78 list_concepts=list(mes_concepts(list_concepts=list_concepts,base=e))
79 elif (e.sd != None) and (e.parent.nom=='INCLUDE') :
80 nom_concept=e.sd.get_name()
81 if not(nom_concept in list_concepts):
82 list_concepts.append( nom_concept )
83 return tuple(list_concepts)
86 # ------------------------------------------------------------------------------
88 def detr_concepts(self):
90 Fonction qui detruit les concepts créés
92 liste_concepts=mes_concepts(base=self.parent)
93 for e in liste_concepts:
95 DETRUIRE( CONCEPT =self.g_context['_F'](NOM = nom), INFO=1, ALARME='NON')
96 if self.jdc.g_context.has_key(nom) : del self.jdc.g_context[nom]
100 # ------------------------------------------------------------------------------
109 #_____________________________________________
111 # CALCUL DU TEMPS CPU RESTANT
112 #_____________________________________________
115 #def temps_CPU(self,restant_old,temps_iter_old):
116 def temps_CPU(restant_old,temps_iter_old):
118 Fonction controlant le temps CPU restant
120 CPU=INFO_EXEC_ASTER(LISTE_INFO = ("CPU_RESTANT",))
121 TEMPS=CPU['CPU_RESTANT',1]
122 DETRUIRE(CONCEPT=_F(NOM='CPU'),INFO=1)
124 # Indique une execution interactive
127 # Indique une execution en batch
131 if (restant_old==0.):
135 if (temps_iter_old==-1.):
136 temps_iter=(restant_old-restant)
139 temps_iter=(temps_iter_old + (restant_old-restant))/2.
140 if ((temps_iter>0.96*restant)or(restant<0.)):
142 UTMESS('F','MACR_RECAL',"Arret de MACR_RECAL par manque de temps CPU.")
144 return restant,temps_iter,err
149 #_____________________________________________
151 # IMPRESSIONS GRAPHIQUES
152 #_____________________________________________
155 def graphique(FORMAT, L_F, res_exp, reponses, iter, UL_out, interactif, fichier=None, INFO=0):
157 if iter: txt_iter = 'Iteration : ' + str(iter)
160 # Le try/except est la pour eviter de planter betement dans un trace de courbes (DISPLAY non defini, etc...)
162 if FORMAT=='XMGRACE':
163 for i in range(len(L_F)):
166 _tmp.append( { 'ABSCISSE': courbe1[:,0].tolist(), 'ORDONNEE': courbe1[:,1].tolist(), 'COULEUR': 1 } )
168 _tmp.append( { 'ABSCISSE': courbe2[:,0].tolist(), 'ORDONNEE': courbe2[:,1].tolist(), 'COULEUR': 2 } )
170 motscle2= {'COURBE': _tmp }
171 if interactif: motscle2['PILOTE']= 'INTERACTIF'
172 else: motscle2['PILOTE']= 'POSTSCRIPT'
174 IMPR_FONCTION(FORMAT='XMGRACE',
176 TITRE='Courbe de : ' + reponses[i][0],
178 LEGENDE_X=reponses[i][1],
179 LEGENDE_Y=reponses[i][2],
183 elif FORMAT=='GNUPLOT':
184 if INFO>=2: UTMESS('I','MACR_RECAL',"Trace des courbes dans le fichier " + fichier )
187 # On efface les anciens graphes
188 liste = glob.glob(fichier + '*.ps')
194 impr=Gnuplot.Gnuplot()
195 Gnuplot.GnuplotOpts.prefer_inline_data=1
196 impr('set data style linespoints')
198 impr('set pointsize 2.')
199 impr('set terminal postscript color')
200 impr('set output "fort.'+str(UL_out)+'"')
202 for i in range(len(L_F)):
203 graphe.append(Gnuplot.Gnuplot(persist=0))
204 graphe[i]('set data style linespoints')
205 graphe[i]('set grid')
206 graphe[i]('set pointsize 2.')
207 graphe[i].xlabel(reponses[i][1])
208 graphe[i].ylabel(reponses[i][2])
209 graphe[i].title(reponses[i][0]+' ' + txt_iter)
210 graphe[i].plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
215 if INFO>=2: UTMESS('I','MACR_RECAL',"Trace des courbes dans le fichier " + fichier + '_' + str(i) + '.ps' )
216 graphe[i].hardcopy(fichier + '_' + str(i) + '.ps', enhanced=1, color=1)
218 impr.xlabel(reponses[i][1])
219 impr.ylabel(reponses[i][2])
220 impr.title(reponses[i][0]+' Iteration '+str(iter))
221 impr.plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
223 except Exception, err:
224 UTMESS('A','MACR_RECAL',"Probleme lors de l'affichage des courbes. On ignore et on continue. Erreur :\n" + str(err) )