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
29 from aideAuxConvertisseurs import listeSupprime, DicoAglomere, DicoEficasToCas
30 from enumDicoTelemac import DicoEnumCasEnInverse
35 Retourne les informations necessaires pour le chargeur de plugins
36 Ces informations sont retournees dans un dictionnaire
41 # La factory pour creer une instance du plugin
42 'factory' : TELEMACGenerator,
46 class TELEMACGenerator(PythonGenerator):
48 Ce generateur parcourt un objet de type JDC et produit
49 un texte au format eficas et
50 un texte au format dictionnaire
54 #----------------------------------------------------------------------------------------
55 def gener(self,obj,format='brut',config=None):
60 # Cette instruction genere le contenu du fichier de commandes (persistance)
61 self.text=PythonGenerator.gener(self,obj,format)
65 #----------------------------------------------------------------------------------------
67 #----------------------------------------------------------------------------------------
74 self.textPE = 'PRESCRIBED ELEVATIONS :'
75 self.textFE = 'PRESCRIBED FLOWRATES :'
76 self.textVE = 'PRESCRIBED VELOCITY :'
82 #----------------------------------------------------------------------------------------
84 #----------------------------------------------------------------------------------------
86 def writeDefault(self,fn) :
87 self.texteDico+='\n&ETA\n'
88 fileDico = fn[:fn.rfind(".")] + '.py'
89 f = open( str(fileDico), 'wb')
90 f.write( self.texteDico )
93 #----------------------------------------------------------------------------------------
94 # analyse de chaque noeud de l'arbre
95 #----------------------------------------------------------------------------------------
97 def generPROC_ETAPE(self,obj):
98 self.texteDico += '/------------------------------------------------------/\n'
99 self.texteDico += '/\t\t\t'+obj.nom +'\n'
100 self.texteDico += '/------------------------------------------------------/\n'
101 s=PythonGenerator.generPROC_ETAPE(self,obj)
104 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
108 def generMCSIMP(self,obj) :
109 """recuperation de l objet MCSIMP"""
110 s=PythonGenerator.generMCSIMP(self,obj)
111 if obj.nom == "Title" :
113 print str(obj.valeur)
114 #print repr(obj.valeur)
117 # Attention pas sur --> ds certains cas non traite par MCFACT ?
118 # a reflechir avec Yoann
119 if hasattr(obj.definition,'defaut') :
120 if obj.definition.defaut == obj.valeur : return s
122 nomMajuscule=obj.nom.upper()
123 nom=nomMajuscule.replace('_',' ')
124 if nom in listeSupprime or s == "" : return s
127 if not( type(obj.valeur) in (types.TupleType,types.ListType) ):
128 if obj.nom in DicoEnumCasEnInverse.keys():
129 try : sTelemac=str(DicoEnumCasEnInverse[obj.nom][obj.valeur])
130 except : print "generMCSIMP Pb valeur avec ", obj.nom, obj.valeur
131 if type(obj.valeur) in (types.TupleType,types.ListType) :
132 if obj.nom in DicoEnumCasEnInverse.keys():
135 try : sT +=str(DicoEnumCasEnInverse[obj.nom][v]) +";"
136 except : print "generMCSIMP Pb Tuple avec ", obj.nom, v, obj.valeur
137 sTelemac=sT[0:-1]+"'"
139 if nom in DicoEficasToCas.keys() : nom=DicoEficasToCas[nom]
140 self.texteDico+=nom+ ":" + str(sTelemac) + "\n"
143 def generMCFACT(self,obj):
146 s=PythonGenerator.generMCFACT(self,obj)
147 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
152 def Liquid_Boundaries(self,obj):
153 #print obj.nom , dir(obj)
154 if 'Type_Condition' in obj.liste_mc_presents() :
155 objForme=obj.get_child('Type_Condition')
156 valForme=objForme.valeur
157 if valForme == None : return
159 nomBloc='b_'+valForme.split(" ")[1]
160 if nomBloc in obj.liste_mc_presents() :
161 objBloc=obj.get_child(nomBloc)
162 objValeur=objBloc.get_child(objBloc.liste_mc_presents()[0])
163 valeur=objValeur.valeur
164 if valeur== None : valeur="0."
165 if valForme == 'Prescribed Elevations' :
167 self.textPE += str(valeur) +"; "
168 else : self.textPE += "0.; "
169 if valForme == 'Prescribed Flowrates' :
171 self.textFE += str(valeur) +"; "
172 else : self.textFE += "0.; "
173 if valForme == 'Prescribed Velocity' :
175 self.textVE += str(valeur) +"; "
176 else : self.textVE += "0.; "
177 #print self.textPE, self.textFE,self.textVE
179 def BOUNDARY_CONDITIONS(self,obj):
180 if self.FE : self.texteDico += self.textFE[0:-1]+'\n'
181 if self.VE : self.texteDico += self.textVE[0:-1]+'\n'
182 if self.PE : self.texteDico += self.textPE[0:-1]+'\n'
184 def Validation(self,obj):
185 self.texteDico += "VALIDATION : True \n"
187 def Date_De_L_Origine_Des_Temps (self,obj):
188 an=obj.get_child('Year').valeur
189 mois=obj.get_child('Month').valeur
190 jour=obj.get_child('Day').valeur
191 #print an, mois, jour
192 self.texteDico += "ORIGINAL DATE OF TIME :"+ str(an)+ " ,"+str(mois)+ "," +str(jour)+ "\n"
194 def Original_Hour_Of_Time (self,obj):
195 hh=obj.get_child('Hour').valeur
196 mm=obj.get_child('Minute').valeur
197 ss=obj.get_child('Second').valeur
199 self.texteDico += "ORIGINAL HOUR OF TIME :"+str(hh)+" ,"+str(mm)+ ","+str(ss)+"\n"
201 def Type_Of_Advection(self,obj):
202 listeAdvection=[1,5,1,1]
204 listeUpwind=[1.,1.,1.,1.]
205 self.listeMCAdvection=[]
206 self.chercheChildren(obj)
207 dicoSuf={ 'U_And_V' : 0, 'H' : 1, 'K_And_Epsilon' : 2, 'Tracers' : 3}
208 for c in self.listeMCAdvection:
210 if c.nom[0:18] == 'Type_Of_Advection_' and c.valeur!=None:
214 #print DicoEnumCasEnInverse['Type_Of_Advection']
215 listeAdvection[index]=DicoEnumCasEnInverse['Type_Of_Advection'][c.valeur]
216 if c.nom[0:13] == 'Supg_Option_' and c.valeur!=None:
219 listeAdvection[index]=DicoEnumCasEnInverse['Supg_Option'][c.valeur]
220 if c.nom[0:23] == 'Upwind_Coefficients_Of_' and c.valeur!=None:
223 listeUpwind[index]=c.valeur
224 self.texteDico += "TYPE OF ADVECTION = "+ str(listeAdvection) + "\n"
225 self.texteDico += "SUPG OPTION = "+ str(listeSupg) + "\n"
226 self.texteDico += "UPWIND COEFFICIENTS = "+ str(listeUpwind) + "\n"
228 def chercheChildren(self,obj):
229 for c in obj.liste_mc_presents():
230 objc=obj.get_child(c)
231 if hasattr(objc,'liste_mc_presents') and objc.liste_mc_presents() != [] : self.chercheChildren(objc)
232 else : self.listeMCAdvection.append(objc)