Salome HOME
CCAR: creation V1_13a1 a partir de la branche Liv-V1_12
[tools/eficas.git] / Aster / Cata / cataSTA9 / Macro / macr_cabri_mail_ops.py
1 #@ MODIF macr_cabri_mail_ops Macro  DATE 29/08/2006   AUTEUR MCOURTOI M.COURTOIS 
2 # -*- coding: iso-8859-1 -*-
3 #            CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2003  EDF R&D                  WWW.CODE-ASTER.ORG
6 # THIS PROGRAM IS FREE SOFTWARE; YOU CAN REDISTRIBUTE IT AND/OR MODIFY  
7 # IT UNDER THE TERMS OF THE GNU GENERAL PUBLIC LICENSE AS PUBLISHED BY  
8 # THE FREE SOFTWARE FOUNDATION; EITHER VERSION 2 OF THE LICENSE, OR     
9 # (AT YOUR OPTION) ANY LATER VERSION.                                                  
10 #                                                                       
11 # THIS PROGRAM IS DISTRIBUTED IN THE HOPE THAT IT WILL BE USEFUL, BUT   
12 # WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF            
13 # MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. SEE THE GNU      
14 # GENERAL PUBLIC LICENSE FOR MORE DETAILS.                              
15 #                                                                       
16 # YOU SHOULD HAVE RECEIVED A COPY OF THE GNU GENERAL PUBLIC LICENSE     
17 # ALONG WITH THIS PROGRAM; IF NOT, WRITE TO EDF R&D CODE_ASTER,         
18 #    1 AVENUE DU GENERAL DE GAULLE, 92141 CLAMART CEDEX, FRANCE.        
19 # ======================================================================
20
21 import os
22
23 def macr_cabri_mail_ops(self,EXEC_MAILLAGE,RAFF_MAILLAGE,VERI_MAIL,GEOM_BRID,
24                         IMPRESSION,**args):
25   """
26      Ecriture de la macro MACR_CABRI_MAIL
27   """
28   import types
29   from Accas import _F
30
31   ier=0
32
33   # On importe les definitions des commandes a utiliser dans la macro
34   # Le nom de la variable doit etre obligatoirement le nom de la commande
35   EXEC_LOGICIEL = self.get_cmd('EXEC_LOGICIEL')
36   LIRE_MAILLAGE = self.get_cmd('LIRE_MAILLAGE')
37   PRE_GIBI      = self.get_cmd('PRE_GIBI')
38   IMPR_RESU     = self.get_cmd('IMPR_RESU')
39
40   # La macro compte pour 1 dans la numerotation des commandes
41   self.set_icmd(1)
42
43   # Le concept sortant (de type mail) est nommé 'nomres' dans 
44   # le contexte de la macro
45   
46   self.DeclareOut('nomres',self.sd)
47   
48   # Chemin de Gibi
49   import aster
50   loc_gibi=aster.repout()
51   gibi2000=loc_gibi+'gibi'
52   
53   # Unité pour le fichier maillage produit (format GIBI)
54   unite_mgib = EXEC_MAILLAGE['UNITE_MGIB']
55   # Unité pour le fichier de commandes GIBI
56   unite_datg = EXEC_MAILLAGE['UNITE_DATG']
57   # Niveau gibi
58   niveau_gibi = EXEC_MAILLAGE['NIVE_GIBI']
59  
60   # Verif mail
61   ver_apla = VERI_MAIL['APLAT']
62   ver_veri = VERI_MAIL['VERIF']
63   
64   # Impression
65   if IMPRESSION['UNITE']!=None:
66    imp_unit = IMPRESSION['UNITE']
67    imp_unitF = 1
68   else:
69    imp_unitF = 0  
70   if IMPRESSION['FORMAT']!=None:
71    imp_form = IMPRESSION['FORMAT']
72    imp_formF = 1
73   else:
74    imp_formF = 0 
75 #  if IMPRESSION['FICHIER']!=None:
76 #   imp_fich = IMPRESSION['FICHIER']
77 #   imp_fichF = 1
78 #  else:
79 #   imp_fichF = 0 
80  
81   # Maillage  
82   nrad = RAFF_MAILLAGE['NB_RADIAL']
83   ncir = RAFF_MAILLAGE['NB_CIRCONF']
84   nver = RAFF_MAILLAGE['NB_VERTICAL']
85   nsect = RAFF_MAILLAGE['NB_ALESAGE']
86   temps = 5.
87     
88   maillage = {'nrad': nrad,
89               'ncir': ncir,
90               'nver': nver,
91               'nsect': nsect,
92               'temps' : temps,}
93
94   # Création du fichier datg
95   
96   if GEOM_BRID['NORME'] == 'OUI':
97     # Bride standard
98     type_bride = GEOM_BRID['TYPE']
99     ### Ecriture du fichier GIBI principal (dgib) - Bride STANDARD
100     write_file_dgib_STD(unite_mgib,unite_datg,maillage,type_bride) 
101   else:
102     # Bride quelconque
103     geo_bride_qqe = {'nbgouj': GEOM_BRID['GOUJ_N_GOUJON'],
104                 'dint':   GEOM_BRID['BRID_D_INT'],
105                 'dex1':   GEOM_BRID['TUBU_D_EXT'],
106                 'dex2':   GEOM_BRID['BRID_D_CONGE'],
107                 'dex3':   GEOM_BRID['BRID_D_EPAUL'],
108                 'dtrou':  GEOM_BRID['BRID_P_ALESAG'],
109                 'dext':   GEOM_BRID['BRID_D_EXT'],
110                 'dt':     GEOM_BRID['BRID_D_ALESAG'],
111                 'drd':    GEOM_BRID['GOUJ_D_RONDEL'],
112                 'dg':     GEOM_BRID['GOUJ_D_GOUJON'],
113                 'dec':    GEOM_BRID['GOUJ_D_ECROU'],
114                 'rcong':  GEOM_BRID['BRID_R_CONGE'],
115                 'he':     GEOM_BRID['GOUJ_E_ECROU'],
116                 'e':      GEOM_BRID['GOUJ_E_RONDEL'],
117                 'hc1':    GEOM_BRID['BRID_H'],
118                 'hcg1':   GEOM_BRID['TUBU_H'],
119                 'hb':     GEOM_BRID['BRID_H_EPAUL'],
120                 'htrou':  GEOM_BRID['BRID_H_ALESAG'],
121                 'pf':     GEOM_BRID['GOUJ_E_FILET'],
122                 'j':      GEOM_BRID['ETAN_E_JOINT']}  
123     ### Ecriture du fichier GIBI principal (dgib) - Bride QUELCONQUE
124     write_file_dgib_QQE(unite_mgib,unite_datg,maillage,geo_bride_qqe)  
125
126   fichier_datg = 'fort.'+str(unite_datg)
127   fichier_mgib = 'fort.'+str(unite_mgib)
128   
129   # Lancement de GIBI
130   EXEC_LOGICIEL(
131                LOGICIEL=gibi2000,
132                ARGUMENT=(fichier_datg, fichier_mgib),
133                )
134   # Lecture du maillage GIBI dans ASTER
135   PRE_GIBI(
136           UNITE_GIBI = unite_mgib,
137           )
138   
139   nomres = LIRE_MAILLAGE(VERI_MAIL=_F(APLAT = ver_apla,
140                                       VERIF = ver_veri ),)
141                                       
142 #  if (imp_fichF == 1):  
143 #   print imp_fich
144   if (imp_formF == 1):  
145    print imp_form
146   if (imp_unitF == 1):  
147    print imp_unit    
148   # Impression du fichier maillage
149   if (imp_formF == 1):
150     if (imp_form == 'CASTEM'):
151       imp_ngib = IMPRESSION['NIVE_GIBI']
152       IMPR_RESU( RESU = _F(MAILLAGE=nomres, ),
153                  FORMAT = 'CASTEM', NIVE_GIBI = imp_ngib )
154     if (imp_form == 'IDEAS'):
155       imp_nver = IMPRESSION['VERSION']
156       IMPR_RESU(RESU = _F(MAILLAGE=nomres,),
157                 FORMAT = 'IDEAS', VERSION = imp_nver )
158                                 
159   return ier
160
161
162 ##############################################################################################
163 # Liste des fonctions
164 ##############################################################################################
165
166 #############
167 ## EXTERNES (appelables depuis l'extérieur)
168 #############
169
170 ### Ecriture du fichier GIBI principal (dgib) - Bride STANDARD
171 # null = write_file_dgib_STD(unite_mgib,unite_datg,msh_bride,geo_bride)
172
173 ### Ecriture du fichier GIBI principal (dgib) - Bride QUELCONQUE
174 # null = write_file_dgib_QQE(unite_mgib,unite_datg,msh_bride,geo_bride)
175
176 ### Imprime tout le catalogue des brides standards disponibles dans un fichier texte
177 # null = print_bride_std(nom_fichier)
178  
179 ### Catalogue complet des brides standards disponibles
180 # txt = bride_std()
181
182 #############
183 ## INTERNES (réservées au travail interne)
184 #############
185
186 ### Génération du nom du fichier pour le fichier maillage résultant (format GIBI)
187 # NomFichier(txt) = name_file_mgib(unite_mgib):
188
189 ### Génération du nom du fichier pour le fichier générant le maillage (commandes GIBI)
190 # NomFichier(txt) = name_file_datg(unite_datg):
191
192 ### Récupère un fichier texte DATG
193 # Txt = text_datg(fichier_datg):
194
195 ### Génération du texte pour les variables
196 # Txt = para_text(dico_var,var): 
197
198
199
200 #=============================================================================================
201 # Importation des modules Python
202 #=============================================================================================
203
204 from Macro.macr_cabri_mail_dat import dico_var_geo,dico_var_msh,dico_bride_std
205
206 #=============================================================================================
207 # Fonctions principales
208 #=============================================================================================
209 # Ecriture du fichier GIBI principal (dgib) - Bride STANDARD
210 def write_file_dgib_STD(unite_mgib,unite_datg,msh_bride,geo_bride):
211
212     # Nom du fichier maillage produit par GIBI
213     nomFichierMGIB = name_file_mgib(unite_mgib)
214  
215     # Nom du fichier de commandes pour GIBI
216     nomFichierDATG = name_file_datg(unite_datg)
217         
218     # Ouverture du fichier d'entrée de commandes
219     fdgib=open(nomFichierDATG,'w')
220     
221     # En-tete
222     text =        "**************************************************************\n"
223     text = text + "* Fichier GIBI pour le maillage d'une bride \n"
224     text = text + "**************************************************************\n"
225     text = text + "\n"
226     text = text + "* Ce fichier a été généré automatiquement par la macro ASTER MACR_CABRI_MAIL \n"
227     text = text + "* Ne pas modifier\n"
228     text = text + "\n"    
229     text = text + "**************************************************************\n"
230     text = text + "* Type bride: Bride standard \n"
231     text = text + "**************************************************************\n"
232     text = text + "titre '"+"Bride standard"+"';\n"
233     text = text + "** Type bride standard: "+geo_bride+"\n"
234    
235     text = text + "\n"
236     text = text + "nomfich = CHAINE \n"
237     if len(nomFichierMGIB)>72:
238       raise Exception, 'Nom de fichier trop long (limité à 72 caractères ' \
239          'pour GIBI) :\n',nomFichierMGIB
240     elif len(nomFichierMGIB)<=69:
241       text = text + "'"+nomFichierMGIB+"';\n"
242     else:
243       text = text + "'"+nomFichierMGIB[:69]+"'\n" \
244                   + "'"+nomFichierMGIB[69:]+"';\n"
245     text = text + "opti dime 3 elem cub8 SAUV FORM nomfich;\n"
246     text = text + "dens 1;\n"
247     text = text + "\n"
248     fdgib.write(text)
249     
250     # Procédures internes supplémentaires
251     text =        "**************************************************************\n"
252     text = text + "* Procédures supplémentaires \n"
253     text = text + "**************************************************************\n"
254     text = text + text_datg_pro()
255     fdgib.write(text)
256     
257     # Début de procédure de création du maillage
258     text =        "**************************************************************\n"
259     text = text + "**************************************************************\n"
260     text = text + "********* Début de procédure de création du maillage *********\n"
261     text = text + "**************************************************************\n"
262     text = text + "**************************************************************\n"
263     text = text + "\n debproc constru;\n"
264     fdgib.write(text)
265
266     # Paramètres géométriques
267     car_bride = dico_bride_std[geo_bride]
268     text =        "**************************************************************\n"
269     text = text + "* Paramètres géométriques \n"
270     text = text + "**************************************************************\n"
271     text = text + para_text(dico_var_geo,car_bride)
272     fdgib.write(text) 
273
274     # Paramètres du maillage
275     text =        "**************************************************************\n"
276     text = text + "* Paramètres physiques \n"
277     text = text + "**************************************************************\n"
278     text = text + para_text(dico_var_msh,msh_bride)
279     fdgib.write(text) 
280
281     # Algorithme du maillage
282     text =        "**************************************************************\n"
283     text = text + "* Algorithme de maillage \n"
284     text = text + "**************************************************************\n"
285     text = text + text_datg_std()
286     fdgib.write(text)
287     
288     # Fermeture du fichier maillage
289     fdgib.close()
290     
291     
292 # Ecriture du fichier GIBI principal (dgib) - Bride QUELCONQUE
293 def write_file_dgib_QQE(unite_mgib,unite_datg,msh_bride,geo_bride):
294         
295     # Nom du fichier maillage produit par GIBI
296     nomFichierMGIB = name_file_mgib(unite_mgib)
297  
298     # Nom du fichier de commandes pour GIBI
299     nomFichierDATG = name_file_datg(unite_datg)
300       
301     # Ouverture du fichier d'entree de commandes
302     fdgib=open(nomFichierDATG,'w')
303     
304     # En-tete
305     text =        "**************************************************************\n"
306     text = text + "* Fichier GIBI pour le maillage d'une bride \n"
307     text = text + "**************************************************************\n"
308     text = text + "\n"
309     text = text + "* Ce fichier a été généré automatiquement par la macro ASTER MACR_CABRI_MAIL \n"
310     text = text + "* Ne pas modifier\n"
311     text = text + "\n"    
312     text = text + "**************************************************************\n"
313     text = text + "* Type bride: Bride quelconque\n"
314     text = text + "**************************************************************\n"
315     text = text + "titre '"+"Bride Quelconque"+"';\n"
316     text = text + "\n"
317     text = text + "nomfich = CHAINE \n"
318     if len(nomFichierMGIB)>72:
319       raise Exception, 'Nom de fichier trop long (limité à 72 caractères ' \
320          'pour GIBI) :\n',nomFichierMGIB
321     elif len(nomFichierMGIB)<=69:
322       text = text + "'"+nomFichierMGIB+"';\n"
323     else:
324       text = text + "'"+nomFichierMGIB[:69]+"'\n" \
325                   + "'"+nomFichierMGIB[69:]+"';\n"
326     text = text + "opti dime 3 elem cub8 SAUV FORM nomfich;\n"
327     text = text + "dens 1;\n"
328     text = text + "\n"
329     fdgib.write(text)
330     
331     # Procédures internes supplémentaires
332     text =        "**************************************************************\n"
333     text = text + "* Procédures supplémentaires \n"
334     text = text + "**************************************************************\n"
335     text = text + text_datg_pro()
336     fdgib.write(text)
337     
338     # Début de procédure de création du maillage
339     text =        "**************************************************************\n"
340     text = text + "**************************************************************\n"
341     text = text + "********* Début de procédure de création du maillage *********\n"
342     text = text + "**************************************************************\n"
343     text = text + "**************************************************************\n"
344     text = text + "\n debproc constru;\n"
345     fdgib.write(text)
346
347     # Paramètres géométriques
348     text =        "**************************************************************\n"
349     text = text + "* Paramètres géométriques \n"
350     text = text + "**************************************************************\n"
351     text = text + para_text(dico_var_geo,geo_bride)
352     fdgib.write(text) 
353
354     # Paramètres du maillage
355     text =        "**************************************************************\n"
356     text = text + "* Paramètres physiques \n"
357     text = text + "**************************************************************\n"
358     text = text + para_text(dico_var_msh,msh_bride)
359     fdgib.write(text) 
360
361     # Algorithme du maillage
362     text =        "**************************************************************\n"
363     text = text + "* Algorithme de maillage \n"
364     text = text + "**************************************************************\n"
365     text = text + text_datg_qqe()
366     fdgib.write(text)
367     
368     # Fermeture du fichier maillage
369     fdgib.close()
370
371 # Génération du nom du fichier pour le fichier maillage résultant (format GIBI)
372 def name_file_mgib(unite_mgib):
373     cur_dir = os.getcwd()
374     nomFichier = cur_dir+'/fort.'+str(unite_mgib)
375     return nomFichier
376
377
378 # Génération du nom du fichier pour le fichier générant le maillage (commandes GIBI)
379 def name_file_datg(unite_datg):
380     cur_dir = os.getcwd()
381     nomFichier = cur_dir+'/fort.'+str(unite_datg)
382     return nomFichier
383
384 # Récupère un fichier texte DATG: texte GIBI pour procédures
385 def text_datg_pro():
386    import aster
387    loc_datg = aster.repdex()
388    datg_bridePro  = loc_datg+"macr_cabri_mail_proc.datg"
389    fproc=open(datg_bridePro,'r')
390    procText = fproc.read()
391    fproc.close()
392
393    return procText
394
395 # Récupère un fichier texte DATG: texte GIBI pour bride quelconque
396 def text_datg_qqe():
397    import aster
398    loc_datg = aster.repdex()
399    datg_brideQqe  = loc_datg+"macr_cabri_mail_qqe.datg"      
400    fproc=open(datg_brideQqe,'r')
401    procText = fproc.read()
402    fproc.close()
403
404    return procText
405
406 # Récupère un fichier texte DATG: texte GIBI pour bride standard
407 def text_datg_std():
408    import aster
409    loc_datg = aster.repdex()
410    datg_brideStd  = loc_datg+"macr_cabri_mail_std.datg"      
411    fproc=open(datg_brideStd,'r')
412    procText = fproc.read()
413    fproc.close()
414
415    return procText
416
417 # Génération du texte pour les variables
418 def para_text(dico_var,var):
419     text = '\n'
420     for nom_var in var.keys():
421         text = text+"* "+dico_var[nom_var]+"\n"
422         text = text+nom_var+" = "+`var[nom_var]`+";\n"
423     return text
424
425 #=============================================================================================
426 # Accès au catalogue des brides standards
427 # (les brides standards sont décrites dans le fichier Data_Brides.py)
428 #=============================================================================================
429
430
431
432 # Imprime tout le catalogue des brides standards disponibles dans un fichier texte
433 def print_bride_std(nom_fichier):
434     text = bride_std()
435     # Ouverture du fichier
436     finfo=open(nom_fichier,'w')
437     # Ecriture des infos
438     finfo.write(text)
439     # Fermeture du fichier
440     finfo.close()
441
442 # Catalogue complet des brides standards disponibles
443 def bride_std():
444     # Ligne d'info
445     text = "Liste des brides standards avec leurs dimensions\n"
446     # Première ligne
447     text = text+"\t"
448     for nom_variable in dico_var_geo.keys():      
449         text = text + nom_variable+"\t\t"
450     text = text + "\n"
451     # Lignes suivantes
452     for nom_bride in dico_bride_std.keys():
453         bride = dico_bride_std[nom_bride]    
454         text = text + nom_bride + '\t'
455         for nom_var in dico_var_geo.keys():
456             chaine = "%f" % (bride[nom_var])
457             text = text+chaine+"\t"               
458         text = text + "\n"
459     return text