1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013 EDF R&D
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 """Ce module contient le plugin generateur de fichier au format Code_Carmel3D pour EFICAS.
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
31 from enumDicoTelemac import TelemacdicoEn
32 DicoEnumCasEnInverse={}
33 for motClef in TelemacdicoEn.keys():
35 for valTelemac in TelemacdicoEn[motClef].keys():
36 valEficas= TelemacdicoEn[motClef][valTelemac]
37 d[valEficas]=valTelemac
38 DicoEnumCasEnInverse[motClef]=d
46 Retourne les informations necessaires pour le chargeur de plugins
47 Ces informations sont retournees dans un dictionnaire
52 # La factory pour creer une instance du plugin
53 'factory' : TELEMACGenerator,
57 class TELEMACGenerator(PythonGenerator):
59 Ce generateur parcourt un objet de type JDC et produit
60 un texte au format eficas et
61 un texte au format dictionnaire
65 #----------------------------------------------------------------------------------------
66 def gener(self,obj,format='brut',config=None,appli=None,statut="Entier"):
69 self.langue=appli.langue
71 # Pour Simplifier les verifs d ecriture
72 if hasattr(appli,'listeTelemac') : self.listeTelemac=appli.listeTelemac
73 else : self.listeTelemac = ()
76 self.dicoCasToCata=appli.readercata.dicoCasToCata
77 for motClef in self.dicoCasToCata.keys():
78 self.dicoCataToCas[self.dicoCasToCata[motClef]]=motClef
82 # Cette instruction genere le contenu du fichier de commandes (persistance)
83 self.text=PythonGenerator.gener(self,obj,format)
87 #----------------------------------------------------------------------------------------
89 #----------------------------------------------------------------------------------------
96 if self.langue == "fr" :
97 self.textPE = 'COTES IMPOSEES :'
98 self.textFE = 'DEBITS IMPOSES :'
99 self.textVE = 'VITESSES IMPOSEES :'
101 self.textPE = 'PRESCRIBED ELEVATIONS :'
102 self.textFE = 'PRESCRIBED FLOWRATES :'
103 self.textVE = 'PRESCRIBED VELOCITIES :'
110 #----------------------------------------------------------------------------------------
112 #----------------------------------------------------------------------------------------
114 def writeDefault(self,fn) :
115 self.texteDico+='\n&ETA\n&FIN\n'
116 if self.statut == 'Leger' : extension = ".Lcas"
117 else : extension = ".cas"
118 fileDico = fn[:fn.rfind(".")] + extension
119 f = open( str(fileDico), 'wb')
120 f.write( self.texteDico )
123 #----------------------------------------------------------------------------------------
125 #----------------------------------------------------------------------------------------
127 def writeLeger(self,fn,jdc,config,appli) :
128 jdc_formate=self.gener(jdc,config=config,appli=appli,statut="Leger")
129 self.writeDefault(fn)
132 #----------------------------------------------------------------------------------------
133 # analyse de chaque noeud de l'arbre
134 #----------------------------------------------------------------------------------------
136 def generPROC_ETAPE(self,obj):
137 self.texteDico += '/------------------------------------------------------/\n'
138 self.texteDico += '/\t\t\t'+obj.nom +'\n'
139 self.texteDico += '/------------------------------------------------------/\n'
140 s=PythonGenerator.generPROC_ETAPE(self,obj)
143 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
147 def generMCSIMP(self,obj) :
148 """recuperation de l objet MCSIMP"""
149 s=PythonGenerator.generMCSIMP(self,obj)
150 #if obj.nom == "Title" :
152 # print str(obj.valeur)
153 #print repr(obj.valeur)
156 # Attention pas sur --> ds certains cas non traite par MCFACT ?
157 # a reflechir avec Yoann
158 # ajouter le statut ?
159 if self.statut == 'Leger' :
160 if hasattr(obj.definition,'defaut') and (obj.definition.defaut == obj.valeur) and (obj.nom not in self.listeTelemac) : return s
161 if hasattr(obj.definition,'defaut') and obj.definition.defaut != None and (type(obj.valeur) == types.TupleType or type(obj.valeur) == types.ListType) and (tuple(obj.definition.defaut) == tuple(obj.valeur)) and (obj.nom not in self.listeTelemac) : return s
164 #nomMajuscule=obj.nom.upper()
165 #nom=nomMajuscule.replace('_',' ')
166 #if nom in listeSupprime or s == "" : return s
167 if s == "" : return s
172 if not( type(obj.valeur) in (types.TupleType,types.ListType) ):
173 if obj.nom in DicoEnumCasEnInverse.keys():
174 try : sTelemac=str(DicoEnumCasEnInverse[obj.nom][obj.valeur])
175 except : print "generMCSIMP Pb valeur avec ", obj.nom, obj.valeur
176 if type(obj.valeur) in (types.TupleType,types.ListType) :
177 #print "je passe pour", obj.nom
178 if obj.nom in DicoEnumCasEnInverse.keys():
182 try : sT +=str(DicoEnumCasEnInverse[obj.nom][v]) +";"
183 except : print "generMCSIMP Pb Tuple avec ", obj.nom, v, obj.valeur
184 #sTelemac=sT[0:-1]+"'"
187 sTelemac=sTelemac[0:-1]
188 if sTelemac.find("'") > 0 :
189 sTelemac= sTelemac.replace (',',';\n ')
192 if self.langue=='fr' :
193 s1=str(sTelemac).replace('True','OUI')
194 s2=s1.replace('False','NON')
196 s1=str(sTelemac).replace('True','YES')
197 s2=s1.replace('False','NO')
198 s3=s2.replace(',',';')
199 if s3 != "" and s3[0]=='(' :
200 try : s3=s3[1:-1] # cas de liste vide
205 if obj.nom in ('PRESCRIBED_FLOWRATES','PRESCRIBED_VELOCITIES','PRESCRIBED_ELEVATIONS') :
208 if obj.nom not in self.dicoCataToCas :
209 if obj.nom == 'Consigne' : return ""
210 print obj.nom , ' non traite'
213 nom=self.dicoCataToCas[obj.nom]
214 if nom == "VARIABLES FOR GRAPHIC PRINTOUTS" : s3=s3.replace(';',',')
215 if nom == "VARIABLES POUR LES SORTIES GRAPHIQUES" : s3=s3.replace(';',',')
216 if s3 == "" or s3 == " " : s3 = "None"
217 ligne=nom+ " : " + s3 + "\n"
218 if len(ligne) > 72 : ligne=self.redecoupeLigne(nom,s3)
219 self.texteDico+=ligne
220 #print "_______________________"
223 #print "_______________________"
226 def generMCFACT(self,obj):
229 s=PythonGenerator.generMCFACT(self,obj)
230 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
235 def LIQUID_BOUNDARIES(self,obj):
236 if 'BOUNDARY_TYPE' in obj.liste_mc_presents() :
237 objForme=obj.get_child('BOUNDARY_TYPE')
238 valForme=objForme.valeur
239 if valForme == None : return
241 nomBloc='b_'+valForme.split(" ")[1]
242 if nomBloc in obj.liste_mc_presents() :
243 objBloc=obj.get_child(nomBloc)
244 objValeur=objBloc.get_child(objBloc.liste_mc_presents()[0])
245 valeur=objValeur.valeur
246 if valeur== None : valeur="0."
247 if valForme == 'Prescribed Elevations' :
249 self.textPE += str(valeur) +"; "
250 else : self.textPE += "0.; "
251 if valForme == 'Prescribed Flowrates' :
253 self.textFE += str(valeur) +"; "
254 else : self.textFE += "0.; "
255 if valForme == 'Prescribed Velocity' :
257 self.textVE += str(valeur) +"; "
258 else : self.textVE += "0.; "
259 print self.textPE, self.textFE,self.textVE
261 def BOUNDARY_CONDITIONS(self,obj):
263 if self.FE : self.texteDico += self.textFE[0:-2]+'\n'
264 if self.PE : self.texteDico += self.textPE[0:-2]+'\n'
265 if self.VE : self.texteDico += self.textVE[0:-2]+'\n'
267 def TRACERS(self,obj):
268 if self.nbTracers != 0 : self.texteDico += 'NUMBER_OF_TRACERS : '+str(self.nbTracers) + '\n'
271 def NAME_OF_TRACER(self,obj):
273 print obj.get_genealogie_precise()
275 def Validation(self,obj):
276 self.texteDico += "VALIDATION : True \n"
278 def Date_De_L_Origine_Des_Temps (self,obj):
279 an=obj.get_child('Year').valeur
280 mois=obj.get_child('Month').valeur
281 jour=obj.get_child('Day').valeur
282 #print an, mois, jour
283 self.texteDico += "ORIGINAL DATE OF TIME :"+ str(an)+ " ,"+str(mois)+ "," +str(jour)+ "\n"
285 def Original_Hour_Of_Time (self,obj):
286 hh=obj.get_child('Hour').valeur
287 mm=obj.get_child('Minute').valeur
288 ss=obj.get_child('Second').valeur
290 self.texteDico += "ORIGINAL HOUR OF TIME :"+str(hh)+" ,"+str(mm)+ ","+str(ss)+"\n"
292 def Type_Of_Advection(self,obj):
293 listeAdvection=[1,5,1,1]
295 listeUpwind=[1.,1.,1.,1.]
296 self.listeMCAdvection=[]
297 self.chercheChildren(obj)
298 dicoSuf={ 'U_And_V' : 0, 'H' : 1, 'K_And_Epsilon' : 2, 'Tracers' : 3}
299 for c in self.listeMCAdvection:
301 if c.nom[0:18] == 'Type_Of_Advection_' and c.valeur!=None:
305 #print DicoEnumCasEnInverse['Type_Of_Advection']
306 listeAdvection[index]=DicoEnumCasEnInverse['Type_Of_Advection'][c.valeur]
307 if c.nom[0:13] == 'Supg_Option_' and c.valeur!=None:
310 listeAdvection[index]=DicoEnumCasEnInverse['Supg_Option'][c.valeur]
311 if c.nom[0:23] == 'Upwind_Coefficients_Of_' and c.valeur!=None:
314 listeUpwind[index]=c.valeur
315 self.texteDico += "TYPE OF ADVECTION = "+ str(listeAdvection) + "\n"
316 self.texteDico += "SUPG OPTION = "+ str(listeSupg) + "\n"
317 self.texteDico += "UPWIND COEFFICIENTS = "+ str(listeUpwind) + "\n"
319 def chercheChildren(self,obj):
320 for c in obj.liste_mc_presents():
321 objc=obj.get_child(c)
322 if hasattr(objc,'liste_mc_presents') and objc.liste_mc_presents() != [] : self.chercheChildren(objc)
323 else : self.listeMCAdvection.append(objc)
327 def redecoupeLigne(self,nom,valeur) :
330 if valeur.find("'") > -1:
331 lval=valeur.split(";")
332 for v in lval : text+=' '+v+';'
335 lval=valeur.split(";")
338 if len(ligne) < 70 : ligne += str(v)+'; '
341 ligne=" "+str(v)+'; '
342 text+= ligne[0:-2]+'\n'