]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA9/Macro/reca_utilitaires.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA9 / Macro / reca_utilitaires.py
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.                                                  
11 #                                                                       
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.                              
16 #                                                                       
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 # ======================================================================
21
22 import Numeric, LinearAlgebra, copy, os, string, types, sys, glob
23 from Numeric import take
24 from externe_mess import UTMESS
25
26 try:    import Gnuplot
27 except: pass
28
29 try:
30    from Cata.cata import INFO_EXEC_ASTER, DEFI_FICHIER, IMPR_FONCTION, DETRUIRE
31    from Accas import _F
32 except : pass
33
34
35 # ------------------------------------------------------------------------------
36 # ------------------------------------------------------------------------------
37
38 #_____________________________________________
39 #
40 # DIVERS UTILITAIRES POUR LA MACRO
41 #_____________________________________________
42
43
44 def transforme_list_Num(parametres,res_exp):
45    """
46       Transforme les données entrées par l'utilisateur en tableau Numeric
47    """
48
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)
53    para = []
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
60
61
62 # ------------------------------------------------------------------------------
63
64 def mes_concepts(list_concepts=[],base=None):
65    """
66       Fonction qui liste les concepts créés
67    """
68    for e in base.etapes:
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)
76
77
78 # ------------------------------------------------------------------------------
79
80 def detr_concepts(self):
81    """
82       Fonction qui detruit les concepts créés
83    """
84    liste_concepts=mes_concepts(base=self.parent)
85    for e in liste_concepts:
86       nom = string.strip(e)
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]
89    del(liste_concepts)
90
91
92 # ------------------------------------------------------------------------------
93
94
95
96
97
98
99
100
101 #_____________________________________________
102 #
103 # CALCUL DU TEMPS CPU RESTANT
104 #_____________________________________________
105
106
107 #def temps_CPU(self,restant_old,temps_iter_old):
108 def temps_CPU(restant_old,temps_iter_old):
109    """
110       Fonction controlant le temps CPU restant
111    """
112    CPU=INFO_EXEC_ASTER(LISTE_INFO = ("CPU_RESTANT",))
113    TEMPS=CPU['CPU_RESTANT',1]
114    DETRUIRE(CONCEPT=_F(NOM='CPU'),INFO=1)
115    err=0
116    # Indique une execution interactive
117    if (TEMPS>1.E+9):
118      return 0.,0.,0
119    # Indique une execution en batch
120    else:
121       restant=TEMPS
122       # Initialisation
123       if (restant_old==0.):
124          temps_iter=-1.
125       else:
126          # Première mesure
127          if (temps_iter_old==-1.):
128             temps_iter=(restant_old-restant)
129          # Mesure courante
130          else:
131             temps_iter=(temps_iter_old + (restant_old-restant))/2.
132          if ((temps_iter>0.96*restant)or(restant<0.)):
133             err=1
134             UTMESS('F','MACR_RECAL',"Arret de MACR_RECAL par manque de temps CPU.")
135
136    return restant,temps_iter,err
137
138
139
140
141 #_____________________________________________
142 #
143 # IMPRESSIONS GRAPHIQUES
144 #_____________________________________________
145
146
147 def graphique(FORMAT, L_F, res_exp, reponses, iter, UL_out, pilote, fichier=None, INFO=0):
148
149   if iter: txt_iter = 'Iteration : ' + str(iter)
150   else:    txt_iter = ''
151
152   # Le try/except est la pour eviter de planter betement dans un trace de courbes (DISPLAY non defini, etc...)
153   try:
154      if FORMAT=='XMGRACE':
155          for i in range(len(L_F)):
156              _tmp = []
157              courbe1 = res_exp[i]
158              _tmp.append( { 'ABSCISSE': courbe1[:,0].tolist(), 'ORDONNEE': courbe1[:,1].tolist(), 'COULEUR': 1, 'LEGENDE' : 'Expérience'} )
159              courbe2 = L_F[i]
160              _tmp.append( { 'ABSCISSE': courbe2[:,0].tolist(), 'ORDONNEE': courbe2[:,1].tolist(), 'COULEUR': 2, 'LEGENDE' : 'Calcul'} )
161
162              motscle2= {'COURBE': _tmp }
163              motscle2['PILOTE']= pilote
164
165              IMPR_FONCTION(FORMAT='XMGRACE',
166                            UNITE=int(UL_out),
167                            TITRE='Courbe : ' + reponses[i][0],
168                            SOUS_TITRE=txt_iter,
169                            LEGENDE_X=reponses[i][1],
170                            LEGENDE_Y=reponses[i][2],
171                            **motscle2
172                            );
173              dic = {''           : '',
174                     'POSTSCRIPT' : '.ps',
175                     'EPS'        : '.eps',
176                     'MIF'        : '.mif',
177                     'SVG'        : '.svg',
178                     'PNM'        : '.pnm',
179                     'PNG'        : '.png',
180                     'JPEG'       : '.jpg',
181                     'PDF'        : '.pdf', 
182                     'INTERACTIF' : '.agr'
183                     }
184              ext = dic[pilote]
185              if ext!='':
186                os.system('mv ./fort.%s ./REPE_OUT/courbes_%s_iter_%s%s' % (str(UL_out), reponses[i][0], str(iter), ext ) )
187
188      elif FORMAT=='GNUPLOT':
189
190          if fichier:
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')
194             for fic in liste:
195                try:    os.remove(fic)
196                except: pass
197
198          graphe=[]
199          impr=Gnuplot.Gnuplot()
200          Gnuplot.GnuplotOpts.prefer_inline_data=1
201          impr('set data style linespoints')
202          impr('set grid')
203          impr('set pointsize 1.')
204          impr('set terminal postscript color')
205          impr('set output "fort.'+str(UL_out)+'"')
206
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':
217                   graphe[i]('pause 5')
218                else:
219                   if fichier:
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)
222
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'))
227
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) )
230