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