]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA8/Macro/reca_message.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA8 / Macro / reca_message.py
1 #@ MODIF reca_message 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 - 2002  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 os, Numeric
23
24 try:
25    from Utilitai.Utmess import UTMESS
26 except:
27    def UTMESS(code,sprg,texte):
28       fmt='\n <%s> <%s> %s\n\n'
29       print fmt % (code,sprg,texte)
30       if code=='F': sys.exit()
31
32 #===========================================================================================
33
34
35 # AFFICHAGE DES MESSAGES
36
37 class Message :
38    """classe gérant l'affichage des messages concernant le déroulement de l'optmisation """
39    #Constructeur de la classe
40
41 # ------------------------------------------------------------------------------
42
43    def __init__(self,para,val_init,resu_exp,ul_out):
44       self.nom_para = para
45       self.resu_exp = resu_exp
46       self.val_init = val_init
47       self.resu_exp = resu_exp
48       self.ul_out = ul_out
49
50 # ------------------------------------------------------------------------------
51    
52    def initialise(self):
53       res=open(os.getcwd()+'/fort.'+str(self.ul_out),'w')
54       res.close()
55
56       txt = ' <INFO>  MACR_RECAL\n\n'
57       self.ecrire(txt)
58
59 # ------------------------------------------------------------------------------
60    
61    def ecrire(self,txt):
62       res=open(os.getcwd()+'/fort.'+str(self.ul_out),'a')
63       res.write(txt+'\n')
64       res.flush()
65       res.close()
66
67
68 # ------------------------------------------------------------------------------
69    
70    def affiche_valeurs(self,val):
71
72       txt = '\n=> Paramètres    = '
73       for i in range(len(val)):
74          txt += '\n         '+ self.nom_para[i]+' = '+str(val[i])
75       self.ecrire(txt)
76
77 # ------------------------------------------------------------------------------
78    
79    def affiche_fonctionnelle(self,J):
80
81       txt = '\n=> Fonctionnelle = '+str(J)
82       self.ecrire(txt)
83
84 # ------------------------------------------------------------------------------
85    
86    def affiche_result_iter(self,iter,J,val,residu,Act=[],):
87
88       txt  = '\n=======================================================\n'
89       txt += 'Iteration '+str(iter)+' :\n'
90       txt += '\n=> Fonctionnelle = '+str(J)
91       txt += '\n=> Résidu        = '+str(residu)
92
93       self.ecrire(txt)
94
95       txt = ''
96       self.affiche_valeurs(val)
97
98       if (len(Act)!=0):
99          if (len(Act)==1):
100             txt += '\n\n Le paramètre '
101          else:
102             txt += '\n\n Les paramètres '
103          for i in Act:
104             txt += self.nom_para[i]+' '
105          if (len(Act)==1):
106             txt += '\n est en butée sur un bord de leur domaine admissible.'
107          else:
108             txt += '\n sont en butée sur un bord de leur domaine admissible.'
109       txt += '\n=======================================================\n\n'
110       self.ecrire(txt)
111
112
113 # ------------------------------------------------------------------------------
114
115    def affiche_etat_final_convergence(self,iter,max_iter,iter_fonc,max_iter_fonc,prec,residu,Act=[]):
116
117       txt = ''
118       if ((iter <= max_iter) or (residu <= prec) or (iter_fonc <= max_iter_fonc) ):
119         txt += '\n=======================================================\n'
120         txt += '                   CONVERGENCE ATTEINTE                '
121         if (len(Act)!=0):
122            txt += "\n\n         ATTENTION : L'OPTIMUM EST ATTEINT AVEC      "
123            txt += "\n           DES PARAMETRES EN BUTEE SUR LE BORD     "
124            txt += "\n               DU DOMAINE ADMISSIBLE                 "
125         txt += '\n=======================================================\n'
126       else:
127         txt += "\n=======================================================\n"
128         txt += '               CONVERGENCE  NON ATTEINTE              '
129         if (iter > max_iter):
130           txt += "\n  Le nombre maximal  d'itération ("+str(max_iter)+") a été dépassé"
131         if (iter_fonc > max_iter_fonc):
132           txt += "\n  Le nombre maximal  d'evaluation de la fonction ("+str(max_iter_fonc)+") a été dépassé"
133         txt += '\n=======================================================\n'
134       self.ecrire(txt)
135
136
137 # ------------------------------------------------------------------------------
138
139    def affiche_calcul_etat_final(self,para,Hessien,valeurs_propres,vecteurs_propres,sensible,insensible):
140
141         txt  = '\n\nValeurs propres du Hessien:\n'
142         txt += str( valeurs_propres)
143         txt += '\n\nVecteurs propres associés:\n'
144         txt += str( vecteurs_propres)
145         txt += '\n\n              --------'
146         txt += '\n\nOn peut en déduire que :'
147         # Paramètres sensibles
148         if (len(sensible)!=0):
149            txt += '\n\nLes combinaisons suivantes de paramètres sont prépondérantes pour votre calcul :\n'
150            k=0
151            for i in sensible:
152               k=k+1
153               colonne=vecteurs_propres[:,i]
154               numero=Numeric.nonzero(Numeric.greater(abs(colonne/max(abs(colonne))),1.E-1))
155               txt += '\n   '+str(k)+') '
156               for j in numero:
157                  txt += '%+3.1E ' %colonne[j]+'* '+para[j]+' '
158               txt += '\n      associée à la valeur propre %3.1E \n' %valeurs_propres[i]
159         # Paramètres insensibles
160         if (len(insensible)!=0):
161            txt += '\n\nLes combinaisons suivantes de paramètres sont insensibles pour votre calcul :\n'
162            k=0
163            for i in insensible:
164               k=k+1
165               colonne=vecteurs_propres[:,i]
166               numero=Numeric.nonzero(Numeric.greater(abs(colonne/max(abs(colonne))),1.E-1))
167               txt += '\n   '+str(k)+') '
168               for j in numero:
169                  txt += '%+3.1E ' %colonne[j]+'* '+para[j]+' '
170               txt += '\n      associée à la valeur propre %3.1E \n' %valeurs_propres[i]
171       
172         self.ecrire(txt)
173