1 #@ MODIF reca_utilitaires Macro DATE 16/10/2007 AUTEUR REZETTE C.REZETTE
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
24 from externe_mess import UTMESS
30 from Cata.cata import INFO_EXEC_ASTER, DEFI_FICHIER, IMPR_FONCTION, DETRUIRE
35 # ------------------------------------------------------------------------------
36 # ------------------------------------------------------------------------------
38 #_____________________________________________
40 # DIVERS UTILITAIRES POUR LA MACRO
41 #_____________________________________________
44 def transforme_list_Num(parametres,res_exp):
46 Transforme les données entrées par l'utilisateur en tableau Numeric
49 dim_para = len(parametres) #donne le nb de parametres
50 val_para = Numeric.zeros(dim_para,Numeric.Float)
51 borne_inf = Numeric.zeros(dim_para,Numeric.Float)
52 borne_sup = Numeric.zeros(dim_para,Numeric.Float)
54 for i in range(dim_para):
55 para.append(parametres[i][0])
56 val_para[i] = parametres[i][1]
57 borne_inf[i] = parametres[i][2]
58 borne_sup[i] = parametres[i][3]
59 return para,val_para,borne_inf,borne_sup
62 # ------------------------------------------------------------------------------
64 def mes_concepts(list_concepts=[],base=None):
66 Fonction qui liste les concepts créés
69 if e.nom in ('INCLUDE','MACR_RECAL',) :
70 list_concepts=list(mes_concepts(list_concepts=list_concepts,base=e))
71 elif (e.sd != None) and (e.parent.nom=='INCLUDE') :
72 nom_concept=e.sd.get_name()
73 if not(nom_concept in list_concepts):
74 list_concepts.append( nom_concept )
75 return tuple(list_concepts)
78 # ------------------------------------------------------------------------------
80 def detr_concepts(self):
82 Fonction qui detruit les concepts créés
84 liste_concepts=mes_concepts(base=self.parent)
85 for e in liste_concepts:
87 DETRUIRE( CONCEPT =self.g_context['_F'](NOM = nom), INFO=1, ALARME='NON')
88 if self.jdc.g_context.has_key(nom) : del self.jdc.g_context[nom]
92 # ------------------------------------------------------------------------------
101 #_____________________________________________
103 # CALCUL DU TEMPS CPU RESTANT
104 #_____________________________________________
107 #def temps_CPU(self,restant_old,temps_iter_old):
108 def temps_CPU(restant_old,temps_iter_old):
110 Fonction controlant le temps CPU restant
112 CPU=INFO_EXEC_ASTER(LISTE_INFO = ("CPU_RESTANT",))
113 TEMPS=CPU['CPU_RESTANT',1]
114 DETRUIRE(CONCEPT=_F(NOM='CPU'),INFO=1)
116 # Indique une execution interactive
119 # Indique une execution en batch
123 if (restant_old==0.):
127 if (temps_iter_old==-1.):
128 temps_iter=(restant_old-restant)
131 temps_iter=(temps_iter_old + (restant_old-restant))/2.
132 if ((temps_iter>0.96*restant)or(restant<0.)):
134 UTMESS('F','MACR_RECAL',"Arret de MACR_RECAL par manque de temps CPU.")
136 return restant,temps_iter,err
141 #_____________________________________________
143 # IMPRESSIONS GRAPHIQUES
144 #_____________________________________________
147 def graphique(FORMAT, L_F, res_exp, reponses, iter, UL_out, pilote, fichier=None, INFO=0):
149 if iter: txt_iter = 'Iteration : ' + str(iter)
152 # Le try/except est la pour eviter de planter betement dans un trace de courbes (DISPLAY non defini, etc...)
154 if FORMAT=='XMGRACE':
155 for i in range(len(L_F)):
158 _tmp.append( { 'ABSCISSE': courbe1[:,0].tolist(), 'ORDONNEE': courbe1[:,1].tolist(), 'COULEUR': 1, 'LEGENDE' : 'Expérience'} )
160 _tmp.append( { 'ABSCISSE': courbe2[:,0].tolist(), 'ORDONNEE': courbe2[:,1].tolist(), 'COULEUR': 2, 'LEGENDE' : 'Calcul'} )
162 motscle2= {'COURBE': _tmp }
163 motscle2['PILOTE']= pilote
165 IMPR_FONCTION(FORMAT='XMGRACE',
167 TITRE='Courbe : ' + reponses[i][0],
169 LEGENDE_X=reponses[i][1],
170 LEGENDE_Y=reponses[i][2],
174 'POSTSCRIPT' : '.ps',
182 'INTERACTIF' : '.agr'
186 os.system('mv ./fort.%s ./REPE_OUT/courbes_%s_iter_%s%s' % (str(UL_out), reponses[i][0], str(iter), ext ) )
188 elif FORMAT=='GNUPLOT':
191 if INFO>=2: UTMESS('I','MACR_RECAL',"Trace des courbes dans le fichier " + fichier )
192 # On efface les anciens graphes
193 liste = glob.glob(fichier + '*.ps')
199 impr=Gnuplot.Gnuplot()
200 Gnuplot.GnuplotOpts.prefer_inline_data=1
201 impr('set data style linespoints')
203 impr('set pointsize 1.')
204 impr('set terminal postscript color')
205 impr('set output "fort.'+str(UL_out)+'"')
207 for i in range(len(L_F)):
208 graphe.append(Gnuplot.Gnuplot(persist=0))
209 graphe[i]('set data style linespoints')
210 graphe[i]('set grid')
211 graphe[i]('set pointsize 1.')
212 graphe[i].xlabel(reponses[i][1])
213 graphe[i].ylabel(reponses[i][2])
214 graphe[i].title(reponses[i][0]+' ' + txt_iter)
215 graphe[i].plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
216 if pilote=='INTERACTIF':
220 if INFO>=2: UTMESS('I','MACR_RECAL',"Trace des courbes dans le fichier " + fichier + '_' + str(i) + '.ps' )
221 graphe[i].hardcopy(fichier + '_' + str(i) + '.ps', enhanced=1, color=1)
223 impr.xlabel(reponses[i][1])
224 impr.ylabel(reponses[i][2])
225 impr.title(reponses[i][0]+' Iteration '+str(iter))
226 impr.plot(Gnuplot.Data(L_F[i],title='Calcul'),Gnuplot.Data(res_exp[i],title='Experimental'))
228 except Exception, err:
229 UTMESS('A','MACR_RECAL',"Probleme lors de l'affichage des courbes. On ignore et on continue. Erreur :\n" + str(err) )