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.
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.
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 # ======================================================================
23 ########################################################################
24 # script PYTHON de creation d un maillage de ligne de coupe
26 def crea_mail_lig_coup(dimension,lignes,groups):
29 from Utilitai.Utmess import UTMESS
31 # construction du maillage au format Aster des segments de lignes de coupe
37 titre='Maillage ligne de coupe'+'\n'
39 resu=resu+'COOR_'+str(dimension)+'D\n'
43 for i in range(nblig):
46 nbp_lig_coupe = lignes[i][2]
47 for j in range(nbp_lig_coupe):
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)
52 noeud=' N'+str(nbno)+' '+str(x)+' '+str(y)+'\n'
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)
59 noeud=' N'+str(nbno)+' '+str(x)+' '+str(y)+' '+str(z)+'\n'
61 for i in range(nbngr):
62 for pt in groups[i][1:]:
65 noeud=' N'+str(nbno)+' '+str(pt[0])+' '+str(pt[1])+'\n'
69 noeud=' N'+str(nbno)+' '+str(pt[0])+' '+str(pt[1])+' '+str(pt[2])+'\n'
73 # creation des mailles
75 for i in range(nblig):
76 nbp_lig_coupe = lignes[i][2]
78 for j in range(nbp_lig_coupe-1):
80 maille=' M'+str(nbma)+' N'+str(nbma+i)+' N'+str(nbma+1+i)+'\n'
83 for i in range(nbngr):
85 for pt in groups[i][1:-1]:
87 maille=' M'+str(nbma)+' N'+str(nbma+nblig+i)+' N'+str(nbma+nblig+1+i)+'\n'
91 # creation des groupes de mailles (1 par ligne de coupe)
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):
99 resu=resu+' M'+str(nbma)+'\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):
108 resu=resu+' M'+str(nbma)+'\n'
116 ########################################################################
117 def macr_lign_coupe_ops(self,RESULTAT,UNITE_MAILLAGE,LIGN_COUPE,NOM_CHAM,
118 MODELE,GROUP_MA,MAILLE,**args):
120 Ecriture de la macro MACR_LIGN_COUPE
122 import os,string,types
124 from Noyau.N_utils import AsType
126 from Utilitai.UniteAster import UniteAster
127 from Utilitai.Utmess import UTMESS
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')
139 # La macro compte pour 1 dans la numerotation des commandes
143 l_modele=aster.getvectjev(nomresu.ljust(19)+'.MODL')
144 n_modele=string.strip(l_modele[0])
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')
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)
166 l_coor_group=[ngrno,]
168 l_coor_group.append(aster.getvectjev(n_mailla.ljust(8)+'.COORDO .VALE',3*(node-1),3))
169 groups.append(l_coor_group)
172 UTMESS('F', "MACR_LIGN_COUPE", "dimensions de maillage et de coordonnees incoherentes")
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
180 resu_mail=crea_mail_lig_coup(dime,lignes,groups)
182 nomFichierSortie = UL.Nom(UNITE_MAILLAGE)
183 fproc=open(nomFichierSortie,'w')
184 fproc.write(resu_mail)
186 UL.EtatInit(UNITE_MAILLAGE)
188 # Lecture du maillage de seg2 contenant toutes les lignes de coupe
190 __macou=LIRE_MAILLAGE(UNITE=UNITE_MAILLAGE,);
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),) )
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 );
203 if AsType(RESULTAT).__name__ in ('evol_elas','evol_noli') :
204 __mocou=AFFE_MODELE(MAILLAGE=__macou,
206 PHENOMENE='MECANIQUE',
207 MODELISATION='BARRE',),);
208 elif AsType(RESULTAT).__name__ in ('evol_ther',) :
209 __mocou=AFFE_MODELE(MAILLAGE=__macou,
211 PHENOMENE='THERMIQUE',
212 MODELISATION='PLAN',),);
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'),)
219 motscles['VIS_A_VIS'].append(_F(MAILLE_1 = MAILLE,TOUT_2='OUI'),)
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',
228 NOM_CHAM=NOM_CHAM, **motscles);
232 # Expression des contraintes aux noeuds ou des déplacements dans le repere local
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
241 if m['NB_POINTS'] !=None :
242 if m['VECT_Y'] !=None :
243 if icham: rep_local=1
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.')
248 for m in LIGN_COUPE :
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]
256 cx3=m['COOR_EXTR'][2]-m['COOR_ORIG'][2]
257 nvx=math.sqrt(cx1**2+cx2**2+cx3**2)
259 UTMESS('F', "MACR_LIGN_COUPE", "definition incorrecte de la ligne de coupe")
268 nvy=math.sqrt(cy1**2+cy2**2+cy3**2)
270 UTMESS('F', "MACR_LIGN_COUPE", "valeurs incorrectes pour VECT_Y")
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 :
281 nvz=math.sqrt(cz1**2+cz2**2+cz3**2)
288 nvy=math.sqrt(cy1**2+cy2**2+cy3**2)
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)+')')
302 alpha = math.atan2(cx2,cx1)
304 if cx1**2 + cx2**2 > epsi :
305 alpha=math.atan2(cx2,cx1)
307 gamma=math.atan2(cy3,cz3)
309 alpha=math.atan2(cy1,cz1)
312 alpha=alpha*180/math.pi
313 beta=beta*180/math.pi
314 gamma=gamma*180/math.pi
317 motscles['MODI_CHAM']=[]
318 motscles['DEFI_REPERE']=[]
320 if NOM_CHAM == 'DEPL':
325 LCMP=['DX','DY','DZ']
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'):
330 LCMP=['SIXX','SIYY','SIZZ','SIXY']
333 LCMP=['SIXX','SIYY','SIZZ','SIXY','SIXZ','SIYZ']
335 motscles['MODI_CHAM'].append(_F(NOM_CHAM=NOM_CHAM,NOM_CMP=LCMP,TYPE_CHAM=TYPE_CHAM),)
339 ANGL_NAUT.append(alpha)
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)
346 if m['NB_POINTS'] !=None :
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']
355 mcACTION.append( _F(INTITULE = intitl,
360 OPERATION = 'EXTRACTION', ) )
365 # Production d'une table pour toutes les lignes de coupe
366 if m['NB_POINTS'] !=None :
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']
375 mcACTION.append( _F(INTITULE = intitl,
380 OPERATION = 'EXTRACTION', ) )
382 elif AsType(RESULTAT).__name__ in ('evol_ther',) :
383 for m in LIGN_COUPE :
384 if m['NB_POINTS'] !=None :
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']
393 mcACTION.append( _F(INTITULE = intitl,
398 OPERATION = 'EXTRACTION', ) )
401 __tabitm=POST_RELEVE_T(ACTION=mcACTION,);
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
406 self.DeclareOut('nomres',self.sd)
407 dictab=__tabitm.EXTR_TABLE()
411 dprod = dictab.dict_CREA_TABLE()
413 nomres=CREA_TABLE(**dprod)