]> SALOME platform Git repositories - tools/eficas.git/blob - Aster/Cata/cataSTA8/Macro/macr_lign_coupe_ops.py
Salome HOME
Modif V6_4_°
[tools/eficas.git] / Aster / Cata / cataSTA8 / Macro / macr_lign_coupe_ops.py
1 #@ MODIF macr_lign_coupe_ops Macro  DATE 01/04/2008   AUTEUR MACOCCO K.MACOCCO 
2 # -*- coding: iso-8859-1 -*-
3 #            CONFIGURATION MANAGEMENT OF EDF VERSION
4 # ======================================================================
5 # COPYRIGHT (C) 1991 - 2002  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
22
23 ########################################################################
24 # script PYTHON de creation d un maillage de ligne de coupe
25
26 def crea_mail_lig_coup(dimension,lignes,groups):
27
28   import os,sys,copy
29   from Utilitai.Utmess     import UTMESS
30
31 # construction du maillage au format Aster des segments de lignes de coupe
32
33   nblig=len(lignes)
34   nbngr=len(groups)
35
36   resu='TITRE\n'
37   titre='Maillage ligne de coupe'+'\n'
38   resu=resu+'FINSF\n'
39   resu=resu+'COOR_'+str(dimension)+'D\n'
40
41 # creation des noeuds
42   nbno=0
43   for i in range(nblig):
44     pt1           = lignes[i][0]
45     pt2           = lignes[i][1]
46     nbp_lig_coupe = lignes[i][2]
47     for j in range(nbp_lig_coupe):
48       if dimension==2:
49         x=pt1[0]+j*(pt2[0]-pt1[0])/(nbp_lig_coupe-1)
50         y=pt1[1]+j*(pt2[1]-pt1[1])/(nbp_lig_coupe-1)
51         nbno=nbno+1
52         noeud='  N'+str(nbno)+'   '+str(x)+'    '+str(y)+'\n'
53         resu=resu+noeud
54       elif dimension==3:
55         x=pt1[0]+j*(pt2[0]-pt1[0])/(nbp_lig_coupe-1)
56         y=pt1[1]+j*(pt2[1]-pt1[1])/(nbp_lig_coupe-1)
57         z=pt1[2]+j*(pt2[2]-pt1[2])/(nbp_lig_coupe-1)
58         nbno=nbno+1
59         noeud='  N'+str(nbno)+'   '+str(x)+'   '+str(y)+'   '+str(z)+'\n'
60         resu=resu+noeud
61   for i in range(nbngr):
62     for pt in groups[i][1:]:
63       if dimension==2:
64         nbno=nbno+1
65         noeud='  N'+str(nbno)+' '+str(pt[0])+'    '+str(pt[1])+'\n'
66         resu=resu+noeud
67       elif dimension==3:
68         nbno=nbno+1
69         noeud='  N'+str(nbno)+' '+str(pt[0])+'    '+str(pt[1])+'    '+str(pt[2])+'\n'
70         resu=resu+noeud
71   resu=resu+'FINSF\n'
72
73 # creation des mailles
74   nbma=0
75   for i in range(nblig):
76     nbp_lig_coupe = lignes[i][2]
77     resu=resu+'SEG2\n'
78     for j in range(nbp_lig_coupe-1):
79         nbma=nbma+1
80         maille='  M'+str(nbma)+' N'+str(nbma+i)+' N'+str(nbma+1+i)+'\n'
81         resu=resu+maille
82     resu=resu+'FINSF\n'
83   for i in range(nbngr):
84     resu=resu+'SEG2\n'
85     for pt in groups[i][1:-1]:
86         nbma=nbma+1
87         maille='  M'+str(nbma)+' N'+str(nbma+nblig+i)+' N'+str(nbma+nblig+1+i)+'\n'
88         resu=resu+maille
89     resu=resu+'FINSF\n'
90
91 # creation des groupes de mailles (1 par ligne de coupe)
92   nbma=0
93   for i in range(nblig):
94     resu=resu+'GROUP_MA\n'
95     resu=resu+'  LICOU'+str(i+1)
96     nbp_lig_coupe = lignes[i][2]
97     for j in range(nbp_lig_coupe-1):
98         nbma=nbma+1
99         resu=resu+'  M'+str(nbma)+'\n'
100     resu=resu+'\n'
101     resu=resu+'FINSF\n'
102   for i in range(nbngr):
103     resu=resu+'GROUP_MA\n'
104     resu=resu+groups[i][0]
105     nbp_lig_coupe = len(groups[i])-1
106     for j in range(nbp_lig_coupe-1):
107         nbma=nbma+1
108         resu=resu+'  M'+str(nbma)+'\n'
109     resu=resu+'\n'
110     resu=resu+'FINSF\n'
111   resu=resu+'FIN\n'
112
113   return resu
114
115
116 ########################################################################
117 def macr_lign_coupe_ops(self,RESULTAT,UNITE_MAILLAGE,LIGN_COUPE,NOM_CHAM,
118                MODELE,GROUP_MA,MAILLE,**args):
119   """
120      Ecriture de la macro MACR_LIGN_COUPE
121   """
122   import os,string,types
123   from Accas import _F
124   from Noyau.N_utils import AsType
125   import aster,math
126   from Utilitai.UniteAster import UniteAster
127   from Utilitai.Utmess import UTMESS
128   ier=0
129
130   # On importe les definitions des commandes a utiliser dans la macro
131   LIRE_MAILLAGE  =self.get_cmd('LIRE_MAILLAGE')
132   DEFI_GROUP     =self.get_cmd('DEFI_GROUP')
133   AFFE_MODELE    =self.get_cmd('AFFE_MODELE')
134   PROJ_CHAMP     =self.get_cmd('PROJ_CHAMP')
135   POST_RELEVE_T  =self.get_cmd('POST_RELEVE_T')
136   CREA_TABLE     =self.get_cmd('CREA_TABLE')
137   MODI_REPERE    =self.get_cmd('MODI_REPERE')
138
139   # La macro compte pour 1 dans la numerotation des commandes
140   self.set_icmd(1)
141   
142   nomresu=RESULTAT.nom
143   l_modele=aster.getvectjev(nomresu.ljust(19)+'.MODL')
144   n_modele=string.strip(l_modele[0])
145   if n_modele=='' :
146      if MODELE==None:
147        UTMESS('F', "MACR_LIGN_COUPE", "nom du modele absent dans le concept resultat "+nomresu)
148      else : n_modele=MODELE.nom
149   l_mailla=aster.getvectjev(n_modele.ljust(8)+'.MODELE    .NOMA')
150   n_mailla=string.strip(l_mailla[0])
151   dime=aster.getvectjev(n_mailla.ljust(8)+'.DIME')[5]
152   collgrno=aster.getcolljev(n_mailla.ljust(8)+'.GROUPENO')
153
154   lignes=[]
155   groups=[]
156   minidim=dime
157   for m in LIGN_COUPE :
158       if m['NB_POINTS'] !=None :
159          lignes.append((m['COOR_ORIG'],m['COOR_EXTR'],m['NB_POINTS']))
160          minidim=min(minidim,len(m['COOR_ORIG']),len(m['COOR_EXTR']))
161       elif m['GROUP_NO']!=None :
162         ngrno=m['GROUP_NO'].ljust(8).upper()
163         if ngrno not in collgrno.keys() :
164           UTMESS('F', "MACR_LIGN_COUPE", "le group_no "+ngrno+" n est pas dans le maillage "+n_mailla)
165         grpn=collgrno[ngrno]
166         l_coor_group=[ngrno,]
167         for node in grpn:
168           l_coor_group.append(aster.getvectjev(n_mailla.ljust(8)+'.COORDO    .VALE',3*(node-1),3))
169         groups.append(l_coor_group)
170
171   if minidim!=dime:
172     UTMESS('F', "MACR_LIGN_COUPE", "dimensions de maillage et de coordonnees incoherentes")
173
174
175   # Création du maillage des NB_POINTS segments entre COOR_ORIG et COOR_EXTR
176   # ainsi que des segments reliant les noeuds issus des group_no demandés
177   # par appel au script python crea_mail_lig_coup
178   # le maillage est ensuite recopié dans l unité logique UNITE_MAILLAGE
179
180   resu_mail=crea_mail_lig_coup(dime,lignes,groups)
181   UL = UniteAster()
182   nomFichierSortie = UL.Nom(UNITE_MAILLAGE)
183   fproc=open(nomFichierSortie,'w')
184   fproc.write(resu_mail)
185   fproc.close()
186   UL.EtatInit(UNITE_MAILLAGE)
187
188   # Lecture du maillage de seg2 contenant toutes les lignes de coupe
189
190   __macou=LIRE_MAILLAGE(UNITE=UNITE_MAILLAGE,);
191
192   motscles={}
193   iocc=1
194   motscles['CREA_GROUP_NO']=[]
195   for m in LIGN_COUPE :
196       if m['NB_POINTS'] !=None :
197         motscles['CREA_GROUP_NO'].append(_F(GROUP_MA='LICOU'+str(iocc),) )
198         iocc=iocc+1
199       elif m['GROUP_NO']!=None :
200         motscles['CREA_GROUP_NO'].append(_F(GROUP_MA=m['GROUP_NO'].ljust(8).upper(),) )
201   __macou=DEFI_GROUP( reuse =__macou , MAILLAGE=__macou , **motscles );
202
203   if AsType(RESULTAT).__name__ in ('evol_elas','evol_noli') :
204     __mocou=AFFE_MODELE(MAILLAGE=__macou,
205                         AFFE=_F(TOUT='OUI',
206                                 PHENOMENE='MECANIQUE',
207                                 MODELISATION='BARRE',),);
208   elif AsType(RESULTAT).__name__ in ('evol_ther',) :
209     __mocou=AFFE_MODELE(MAILLAGE=__macou,
210                         AFFE=_F(TOUT='OUI',
211                                 PHENOMENE='THERMIQUE',
212                                 MODELISATION='PLAN',),);
213
214   motscles={}
215   motscles['VIS_A_VIS']=[]
216   if GROUP_MA != None :
217     motscles['VIS_A_VIS'].append(_F(GROUP_MA_1 = GROUP_MA,TOUT_2='OUI'),)     
218   if MAILLE != None :
219     motscles['VIS_A_VIS'].append(_F(MAILLE_1 = MAILLE,TOUT_2='OUI'),)     
220     
221   if n_modele in self.get_global_contexte().keys() : MODELE_1=self.get_global_contexte()[n_modele]
222   else                                             : MODELE_1=self.jdc.current_context[n_modele]
223   __recou=PROJ_CHAMP(METHODE='ELEM',
224                      RESULTAT=RESULTAT,
225                      MODELE_1=MODELE_1,
226                      MODELE_2=__mocou,
227                      TYPE_CHAM='NOEU',
228                      NOM_CHAM=NOM_CHAM, **motscles);     
229
230
231
232   # Expression des contraintes aux noeuds ou des déplacements dans le repere local
233   __remodr=__recou
234   icham=0
235   ioc2=0
236   mcACTION=[]
237   if AsType(RESULTAT).__name__ in ('evol_elas','evol_noli') :
238    if  NOM_CHAM in ('DEPL','SIEF_ELNO_ELGA','SIGM_NOEU_DEPL','SIGM_NOEU_SIEF','SIGM_NOEU_ELGA','SIGM_NOEU_COQU'):icham=1
239   # Gestion du calcul en repère local - VECT_Y
240    rep_local=0
241    if m['NB_POINTS'] !=None :
242       if m['VECT_Y'] !=None :
243          if icham: rep_local=1
244          else :
245            UTMESS('A','MACR_LIGN_COUPE','LE CHAMP '+NOM_CHAM+' N EST PAS TRAITE PAR MACR_LIGNE_COUPE EN REPERE LOCAL.'
246                    +'LE CALCUL EST EFFECTUE EN REPERE GLOBAL.')
247
248    for m in LIGN_COUPE :
249       if rep_local:
250         epsi=0.00000001
251         # --- determination des angles nautiques
252         cx1=m['COOR_EXTR'][0]-m['COOR_ORIG'][0]
253         cx2=m['COOR_EXTR'][1]-m['COOR_ORIG'][1]
254         cx3=0.
255         if dime == 3:
256           cx3=m['COOR_EXTR'][2]-m['COOR_ORIG'][2]
257         nvx=math.sqrt(cx1**2+cx2**2+cx3**2)
258         if abs(nvx) < epsi:
259             UTMESS('F', "MACR_LIGN_COUPE", "definition incorrecte de la ligne de coupe")
260         cx1=cx1/nvx
261         cx2=cx2/nvx
262         cx3=cx3/nvx
263         cy1=m['VECT_Y'][0]
264         cy2=m['VECT_Y'][1]
265         cy3=0.
266         if dime == 3:
267           cy3=m['VECT_Y'][2]
268         nvy=math.sqrt(cy1**2+cy2**2+cy3**2)
269         if abs(nvy) < epsi:
270             UTMESS('F', "MACR_LIGN_COUPE", "valeurs incorrectes pour VECT_Y")
271         cy1=cy1/nvy
272         cy2=cy2/nvy
273         cy3=cy3/nvy
274         if ((abs(cx1-cy1)<epsi and abs(cx2-cy2)<epsi and  abs(cx3-cy3)<epsi) or \
275            (abs(cx1+cy1)<epsi and abs(cx2+cy2)<epsi and  abs(cx3+cy3)<epsi)):
276             UTMESS('F', "MACR_LIGN_COUPE", "valeurs incorrectes pour VECT_Y: x colineaire a y")
277         if abs(cx1*cy1+cx2*cy2+cx3*cy3) > epsi  :
278           cz1=cx2*cy3-cx3*cy2
279           cz2=cx3*cy1-cx1*cy3
280           cz3=cx1*cy2-cx2*cy1
281           nvz=math.sqrt(cz1**2+cz2**2+cz3**2)
282           cz1=cz1/nvz
283           cz2=cz2/nvz
284           cz3=cz3/nvz
285           cy1=cz2*cx3-cz3*cx2
286           cy2=cz3*cx1-cz1*cx3
287           cy3=cz1*cx2-cz2*cx1
288           nvy=math.sqrt(cy1**2+cy2**2+cy3**2)
289           cy1=cy1/nvy
290           cy2=cy2/nvy
291           cy3=cy3/nvy
292           UTMESS('A','MACR_LIGN_COUPE','LE VECTEUR Y N EST PAS ORTHOGONAL A LA LIGNE DE COUPE'
293                   +'LE VECTEUR Y A ETE ORTHONORMALISE POUR VOUS')
294           UTMESS('A','MACR_LIGN_COUPE','VECT_Y=('+str(cy1)+','+str(cy2)+','+str(cy3)+')')
295         else:     
296           cz1=cx2*cy3-cx3*cy2
297           cz2=cx3*cy1-cx1*cy3
298           cz3=cx1*cy2-cx2*cy1
299         beta=0.
300         gamma=0.
301         if dime ==2:
302           alpha = math.atan2(cx2,cx1)
303         else:
304           if cx1**2 + cx2**2 > epsi :
305             alpha=math.atan2(cx2,cx1)
306             beta=math.asin(cx3)
307             gamma=math.atan2(cy3,cz3)
308           else:
309             alpha=math.atan2(cy1,cz1)
310             beta=math.asin(cx3)
311             gamma=0.
312         alpha=alpha*180/math.pi
313         beta=beta*180/math.pi
314         gamma=gamma*180/math.pi
315         # --- MODI_REPERE
316         motscles={}
317         motscles['MODI_CHAM']=[]
318         motscles['DEFI_REPERE']=[]
319         # MODI_CHAM
320         if NOM_CHAM == 'DEPL':
321            if dime == 2:
322               LCMP=['DX','DY']
323               TYPE_CHAM='VECT_2D'
324            elif dime ==3 :
325               LCMP=['DX','DY','DZ']
326               TYPE_CHAM='VECT_3D'
327            motscles['MODI_CHAM'].append(_F(NOM_CHAM=NOM_CHAM,NOM_CMP=LCMP,TYPE_CHAM=TYPE_CHAM),)
328         elif NOM_CHAM in ('SIGM_NOEU_DEPL','SIEF_ELNO_ELGA','SIGM_NOEU_SIEF','SIGM_NOEU_ELGA','SIGM_NOEU_COQU'):
329            if dime == 2:
330               LCMP=['SIXX','SIYY','SIZZ','SIXY']
331               TYPE_CHAM='TENS_2D'
332            elif dime ==3 :
333               LCMP=['SIXX','SIYY','SIZZ','SIXY','SIXZ','SIYZ']
334               TYPE_CHAM='TENS_3D'
335            motscles['MODI_CHAM'].append(_F(NOM_CHAM=NOM_CHAM,NOM_CMP=LCMP,TYPE_CHAM=TYPE_CHAM),)
336
337         # DEFI_REPERE
338         ANGL_NAUT=[]
339         ANGL_NAUT.append(alpha)
340         if dime ==3:
341            ANGL_NAUT.append(beta)
342            ANGL_NAUT.append(gamma)
343         motscles['DEFI_REPERE'].append(_F(REPERE='UTILISATEUR',ANGL_NAUT=ANGL_NAUT),)
344         __remodr=MODI_REPERE(RESULTAT=__recou,**motscles)
345
346         if m['NB_POINTS'] !=None :
347           ioc2=ioc2+1
348           groupe='LICOU'+str(ioc2)
349           if m['INTITULE'] !=None : intitl=m['INTITULE']
350           else                    : intitl='l.coupe'+str(ioc2)
351         elif m['GROUP_NO']!=None :
352           groupe=m['GROUP_NO'].ljust(8).upper()
353           if m['INTITULE'] !=None : intitl=m['INTITULE']
354           else                    : intitl=groupe
355         mcACTION.append( _F(INTITULE  = intitl,
356                             RESULTAT  = __remodr,
357                             GROUP_NO  = groupe,
358                             NOM_CHAM  = NOM_CHAM,
359                             TOUT_CMP  = 'OUI',
360                             OPERATION = 'EXTRACTION', )           )
361
362       else:
363
364
365   # Production d'une table pour toutes les lignes de coupe
366              if m['NB_POINTS'] !=None :
367               ioc2=ioc2+1
368               groupe='LICOU'+str(ioc2)
369               if m['INTITULE'] !=None : intitl=m['INTITULE']
370               else                    : intitl='l.coupe'+str(ioc2)
371              elif m['GROUP_NO']!=None :
372               groupe=m['GROUP_NO'].ljust(8).upper()
373               if m['INTITULE'] !=None : intitl=m['INTITULE']
374               else                    : intitl=groupe
375              mcACTION.append( _F(INTITULE  = intitl,
376                                 RESULTAT  = __recou,
377                                 GROUP_NO  = groupe,
378                                 NOM_CHAM  = NOM_CHAM,
379                                 TOUT_CMP  = 'OUI',
380                                 OPERATION = 'EXTRACTION', )           )
381  
382   elif AsType(RESULTAT).__name__ in ('evol_ther',) :
383      for m in LIGN_COUPE :
384         if m['NB_POINTS'] !=None :
385           ioc2=ioc2+1
386           groupe='LICOU'+str(ioc2)
387           if m['INTITULE'] !=None : intitl=m['INTITULE']
388           else                    : intitl='l.coupe'+str(ioc2)
389         elif m['GROUP_NO']!=None :
390           groupe=m['GROUP_NO'].ljust(8).upper()
391           if m['INTITULE'] !=None : intitl=m['INTITULE']
392           else                    : intitl=groupe
393         mcACTION.append( _F(INTITULE  = intitl,
394                             RESULTAT  = __recou,
395                             GROUP_NO  = groupe,
396                             NOM_CHAM  = NOM_CHAM,
397                             TOUT_CMP  = 'OUI',
398                             OPERATION = 'EXTRACTION', )           )
399  
400  
401   __tabitm=POST_RELEVE_T(ACTION=mcACTION,);
402
403   # on repasse par les tables python pour supprimer les paramètres inutiles
404   # NOEUD (car il est propre au maillage de la ligne) et RESU
405
406   self.DeclareOut('nomres',self.sd)
407   dictab=__tabitm.EXTR_TABLE()
408
409   del dictab['NOEUD']
410   del dictab['RESU']
411   dprod = dictab.dict_CREA_TABLE()
412
413   nomres=CREA_TABLE(**dprod)
414
415   return ier