1 #@ MODIF reca_utilitaires Macro DATE 11/05/2010 AUTEUR COURTOIS M.COURTOIS
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 # ======================================================================
36 CPU_Exception = aster.ArretCPUError
37 from Cata.cata import INFO_EXEC_ASTER, DEFI_FICHIER, IMPR_FONCTION, DETRUIRE
39 from Utilitai.Utmess import UTMESS, MessageLog
41 CPU_Exception = StandardError
44 # ------------------------------------------------------------------------------
45 # ------------------------------------------------------------------------------
47 #_____________________________________________
49 # DIVERS UTILITAIRES POUR LA MACRO
50 #_____________________________________________
53 def transforme_list_Num(parametres,res_exp):
55 Transforme les données entrées par l'utilisateur en tableau numpy
58 dim_para = len(parametres) #donne le nb de parametres
59 val_para = NP.zeros(dim_para)
60 borne_inf = NP.zeros(dim_para)
61 borne_sup = NP.zeros(dim_para)
63 for i in range(dim_para):
64 para.append(parametres[i][0])
65 val_para[i] = parametres[i][1]
66 borne_inf[i] = parametres[i][2]
67 borne_sup[i] = parametres[i][3]
68 return para,val_para,borne_inf,borne_sup
71 # ------------------------------------------------------------------------------
73 def mes_concepts(list_concepts=[],base=None):
75 Fonction qui liste les concepts créés
78 if e.nom in ('INCLUDE','MACR_RECAL',) :
79 list_concepts=list(mes_concepts(list_concepts=list_concepts,base=e))
80 elif (e.sd != None) and (e.parent.nom=='INCLUDE') :
81 nom_concept=e.sd.get_name()
82 if not(nom_concept in list_concepts):
83 list_concepts.append( nom_concept )
84 return tuple(list_concepts)
87 # ------------------------------------------------------------------------------
89 def detr_concepts(self):
91 Fonction qui detruit les concepts créés
93 liste_concepts=mes_concepts(base=self.parent)
94 for e in liste_concepts:
96 DETRUIRE( OBJET =self.g_context['_F'](CHAINE = nom), INFO=1, ALARME='NON')
97 if self.jdc.g_context.has_key(nom) : del self.jdc.g_context[nom]
101 # ------------------------------------------------------------------------------
102 def Random_Tmp_Name(prefix=None):
105 nombre = int(random.random()*10000000)
106 if prefix: fic = prefix + str(nombre)
108 if os.environ.has_key('TEMP'): fic = os.path.join( os.environ['TEMP'], 'file%s' % str(nombre) )
109 else: fic = '/tmp/file' + str(nombre)
110 if not os.path.isfile(fic): crit = True
116 #_____________________________________________
118 # CALCUL DU TEMPS CPU RESTANT
119 #_____________________________________________
122 def temps_CPU(restant_old,temps_iter_old):
124 Fonction controlant le temps CPU restant
126 CPU=INFO_EXEC_ASTER(LISTE_INFO = ("CPU_RESTANT",))
127 TEMPS=CPU['CPU_RESTANT',1]
128 DETRUIRE(CONCEPT=_F(NOM=CPU),INFO=1)
130 # Indique une execution interactive
133 # Indique une execution en batch
137 if (restant_old==0.):
141 if (temps_iter_old==-1.):
142 temps_iter=(restant_old-restant)
145 temps_iter=(temps_iter_old + (restant_old-restant))/2.
146 if ((temps_iter>0.96*restant)or(restant<0.)):
148 msg = MessageLog.GetText('F', 'RECAL0_53')
149 raise CPU_Exception, msg
151 return restant,temps_iter,err
156 #_____________________________________________
158 # IMPRESSIONS GRAPHIQUES
159 #_____________________________________________
162 def graphique(FORMAT, L_F, res_exp, reponses, iter, UL_out, pilote, fichier=None, INFO=0):
164 if iter: txt_iter = 'Iteration : ' + str(iter)
167 # Le try/except est la pour eviter de planter betement dans un trace de courbes (DISPLAY non defini, etc...)
169 if FORMAT=='XMGRACE':
170 for i in range(len(L_F)):
173 _tmp.append( { 'ABSCISSE': courbe1[:,0].tolist(), 'ORDONNEE': courbe1[:,1].tolist(), 'COULEUR': 1, 'LEGENDE' : 'Expérience'} )
175 _tmp.append( { 'ABSCISSE': courbe2[:,0].tolist(), 'ORDONNEE': courbe2[:,1].tolist(), 'COULEUR': 2, 'LEGENDE' : 'Calcul'} )
177 motscle2= {'COURBE': _tmp }
178 motscle2['PILOTE']= pilote
180 IMPR_FONCTION(FORMAT='XMGRACE',
182 TITRE='Courbe : ' + reponses[i][0],
184 LEGENDE_X=reponses[i][1],
185 LEGENDE_Y=reponses[i][2],
189 'POSTSCRIPT' : '.ps',
197 'INTERACTIF' : '.agr'
201 os.system('mv ./fort.%s ./REPE_OUT/courbes_%s_iter_%s%s' % (str(UL_out), reponses[i][0], str(iter), ext ) )
203 elif FORMAT=='GNUPLOT':
206 if INFO>=2: UTMESS('I','RECAL0_41',valk=fichier )
207 # On efface les anciens graphes
208 liste = glob.glob(fichier + '*.ps')
214 impr=Gnuplot.Gnuplot()
215 Gnuplot.GnuplotOpts.prefer_inline_data=1
216 impr('set data style linespoints')
218 impr('set pointsize 1.')
219 impr('set terminal postscript color')
220 impr('set output "fort.'+str(UL_out)+'"')
222 for i in range(len(L_F)):
223 graphe.append(Gnuplot.Gnuplot(persist=0))
224 graphe[i]('set data style linespoints')
225 graphe[i]('set grid')
226 graphe[i]('set pointsize 1.')
227 graphe[i].xlabel(reponses[i][1])
228 graphe[i].ylabel(reponses[i][2])
229 graphe[i].title(reponses[i][0]+' ' + txt_iter)
230 graphe[i].plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
231 if pilote=='INTERACTIF':
235 if INFO>=2: UTMESS('I','RECAL0_41',valk=fichier + '_' + str(i) + '.ps' )
236 graphe[i].hardcopy(fichier + '_' + str(i) + '.ps', enhanced=1, color=1)
238 impr.xlabel(reponses[i][1])
239 impr.ylabel(reponses[i][2])
240 impr.title(reponses[i][0]+' Iteration '+str(iter))
241 impr.plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
243 except Exception, err:
244 UTMESS('A','RECAL0_42',valk=str(err) )