]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA8/Macro/reca_utilitaires.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA8 / Macro / reca_utilitaires.py
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.                                                  
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
25 try:
26    from Cata.cata import INFO_EXEC_ASTER, DEFI_FICHIER, IMPR_FONCTION, DETRUIRE
27    from Accas import _F
28 except: pass
29
30 try:    import Gnuplot
31 except: pass
32
33 try:
34    from Utilitai.Utmess import UTMESS
35 except ImportError:
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()
40
41
42
43 # ------------------------------------------------------------------------------
44 # ------------------------------------------------------------------------------
45
46 #_____________________________________________
47 #
48 # DIVERS UTILITAIRES POUR LA MACRO
49 #_____________________________________________
50
51
52 def transforme_list_Num(parametres,res_exp):
53    """
54       Transforme les données entrées par l'utilisateur en tableau Numeric
55    """
56
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)
61    para = []
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
68
69
70 # ------------------------------------------------------------------------------
71
72 def mes_concepts(list_concepts=[],base=None):
73    """
74       Fonction qui liste les concepts créés
75    """
76    for e in base.etapes:
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)
84
85
86 # ------------------------------------------------------------------------------
87
88 def detr_concepts(self):
89    """
90       Fonction qui detruit les concepts créés
91    """
92    liste_concepts=mes_concepts(base=self.parent)
93    for e in liste_concepts:
94       nom = string.strip(e)
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]
97    del(liste_concepts)
98
99
100 # ------------------------------------------------------------------------------
101
102
103
104
105
106
107
108
109 #_____________________________________________
110 #
111 # CALCUL DU TEMPS CPU RESTANT
112 #_____________________________________________
113
114
115 #def temps_CPU(self,restant_old,temps_iter_old):
116 def temps_CPU(restant_old,temps_iter_old):
117    """
118       Fonction controlant le temps CPU restant
119    """
120    CPU=INFO_EXEC_ASTER(LISTE_INFO = ("CPU_RESTANT",))
121    TEMPS=CPU['CPU_RESTANT',1]
122    DETRUIRE(CONCEPT=_F(NOM='CPU'),INFO=1)
123    err=0
124    # Indique une execution interactive
125    if (TEMPS>1.E+9):
126      return 0.,0.,0
127    # Indique une execution en batch
128    else:
129       restant=TEMPS
130       # Initialisation
131       if (restant_old==0.):
132          temps_iter=-1.
133       else:
134          # Première mesure
135          if (temps_iter_old==-1.):
136             temps_iter=(restant_old-restant)
137          # Mesure courante
138          else:
139             temps_iter=(temps_iter_old + (restant_old-restant))/2.
140          if ((temps_iter>0.96*restant)or(restant<0.)):
141             err=1
142             UTMESS('F','MACR_RECAL',"Arret de MACR_RECAL par manque de temps CPU.")
143
144    return restant,temps_iter,err
145
146
147
148
149 #_____________________________________________
150 #
151 # IMPRESSIONS GRAPHIQUES
152 #_____________________________________________
153
154
155 def graphique(FORMAT, L_F, res_exp, reponses, iter, UL_out, interactif, fichier=None, INFO=0):
156
157   if iter: txt_iter = 'Iteration : ' + str(iter)
158   else:    txt_iter = ''
159
160   # Le try/except est la pour eviter de planter betement dans un trace de courbes (DISPLAY non defini, etc...)
161   try:
162      if FORMAT=='XMGRACE':
163          for i in range(len(L_F)):
164              _tmp = []
165              courbe1 = res_exp[i]
166              _tmp.append( { 'ABSCISSE': courbe1[:,0].tolist(), 'ORDONNEE': courbe1[:,1].tolist(), 'COULEUR': 1 } )
167              courbe2 = L_F[i]
168              _tmp.append( { 'ABSCISSE': courbe2[:,0].tolist(), 'ORDONNEE': courbe2[:,1].tolist(), 'COULEUR': 2 } )
169
170              motscle2= {'COURBE': _tmp }
171              if interactif: motscle2['PILOTE']= 'INTERACTIF'
172              else:          motscle2['PILOTE']= 'POSTSCRIPT'
173
174              IMPR_FONCTION(FORMAT='XMGRACE',
175                            UNITE=int(UL_out),
176                            TITRE='Courbe de : ' + reponses[i][0],
177                            SOUS_TITRE=txt_iter,
178                            LEGENDE_X=reponses[i][1],
179                            LEGENDE_Y=reponses[i][2],
180                            **motscle2
181                            );
182
183      elif FORMAT=='GNUPLOT':
184          if INFO>=2: UTMESS('I','MACR_RECAL',"Trace des courbes dans le fichier " + fichier )
185
186          if fichier:
187             # On efface les anciens graphes
188             liste = glob.glob(fichier + '*.ps')
189             for fic in liste:
190                try:    os.remove(fic)
191                except: pass
192
193          graphe=[]
194          impr=Gnuplot.Gnuplot()
195          Gnuplot.GnuplotOpts.prefer_inline_data=1
196          impr('set data style linespoints')
197          impr('set grid')
198          impr('set pointsize 2.')
199          impr('set terminal postscript color')
200          impr('set output "fort.'+str(UL_out)+'"')
201
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'))
211                if interactif:
212                   graphe[i]('pause 5')
213                else:
214                   if fichier:
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)
217
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'))
222
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) )
225