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 fileDico = fn[:fn.rfind(".")] + '.py'
88 f = open( str(fileDico), 'wb')
89 f.write( self.texteDico )
92 #----------------------------------------------------------------------------------------
93 # analyse de chaque noeud de l'arbre
94 #----------------------------------------------------------------------------------------
96 def generPROC_ETAPE(self,obj):
97 self.texteDico += '/------------------------------------------------------/\n'
98 self.texteDico += '/\t\t\t'+obj.nom +'\n'
99 self.texteDico += '/------------------------------------------------------/\n'
100 s=PythonGenerator.generPROC_ETAPE(self,obj)
103 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
107 def generMCSIMP(self,obj) :
108 """recuperation de l objet MCSIMP"""
109 s=PythonGenerator.generMCSIMP(self,obj)
110 if obj.nom == "Title" :
112 print str(obj.valeur)
113 print repr(obj.valeur)
116 # Attention pas sur --> ds certains cas non traite par MCFACT ?
117 # a reflechir avec Yoann
118 if hasattr(obj.definition,'defaut') :
119 if obj.definition.defaut == obj.valeur : return s
121 nomMajuscule=obj.nom.upper()
122 nom=nomMajuscule.replace('_',' ')
123 if nom in listeSupprime or s == "" : return s
126 if not( type(obj.valeur) in (types.TupleType,types.ListType) ):
127 if obj.nom in DicoEnumCasEnInverse.keys():
128 try : sTelemac=DicoEnumCasEnInverse[obj.nom][obj.valeur]
129 except : print "generMCSIMP Pb avec ", obj.nom, obj.valeur
130 if type(obj.valeur) in (types.TupleType,types.ListType) :
131 if obj.nom in DicoEnumCasEnInverse.keys():
134 try : sT +=DicoEnumCasEnInverse[obj.nom][v] +";"
135 except : print "generMCSIMP Pb avec ", obj.nom, v
136 sTelemac=sT[0:-1]+"'"
138 if nom in DicoEficasToCas.keys() : nom=DicoEficasToCas[nom]
139 self.texteDico+=nom+ ":" + str(sTelemac) + "\n"
142 def generMCFACT(self,obj):
145 s=PythonGenerator.generMCFACT(self,obj)
146 if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
151 def Liquid_Boundaries(self,obj):
152 #print obj.nom , dir(obj)
153 if 'Type_Condition' in obj.liste_mc_presents() :
154 objForme=obj.get_child('Type_Condition')
155 valForme=objForme.valeur
156 if valForme == None : return
158 nomBloc='b_'+valForme.split(" ")[1]
159 if nomBloc in obj.liste_mc_presents() :
160 objBloc=obj.get_child(nomBloc)
161 objValeur=objBloc.get_child(objBloc.liste_mc_presents()[0])
162 valeur=objValeur.valeur
163 if valeur== None : valeur="0."
164 if valForme == 'Prescribed Elevations' :
166 self.textPE += str(valeur) +"; "
167 else : self.textPE += "0.; "
168 if valForme == 'Prescribed Flowrates' :
170 self.textFE += str(valeur) +"; "
171 else : self.textFE += "0.; "
172 if valForme == 'Prescribed Velocity' :
174 self.textVE += str(valeur) +"; "
175 else : self.textVE += "0.; "
176 #print self.textPE, self.textFE,self.textVE
178 def BOUNDARY_CONDITIONS(self,obj):
179 if self.FE : self.texteDico += self.textFE[0:-1]+'\n'
180 if self.VE : self.texteDico += self.textVE[0:-1]+'\n'
181 if self.PE : self.texteDico += self.textPE[0:-1]+'\n'
183 def Validation(self,obj):
184 self.texteDico += "VALIDATION : True \n"
186 def Date_De_L_Origine_Des_Temps (self,obj):
187 an=obj.get_child('Year').valeur
188 mois=obj.get_child('Month').valeur
189 jour=obj.get_child('Day').valeur
190 #print an, mois, jour
191 self.texteDico += "ORIGINAL DATE OF TIME :"+ str(an)+ " ,"+str(mois)+ "," +str(jour)+ "\n"
193 def Original_Hour_Of_Time (self,obj):
194 hh=obj.get_child('Hour').valeur
195 mm=obj.get_child('Minute').valeur
196 ss=obj.get_child('Second').valeur
198 self.texteDico += "ORIGINAL HOUR OF TIME :"+str(hh)+" ,"+str(mm)+ ","+str(ss)+"\n"
200 def Type_Of_Advection(self,obj):
201 listeAdvection=[1,5,1,1]
203 listeUpwind=[1.,1.,1.,1.]
204 self.listeMCAdvection=[]
205 self.chercheChildren(obj)
206 dicoSuf={ 'U_And_V' : 0, 'H' : 1, 'K_And_Epsilon' : 2, 'Tracers' : 3}
207 for c in self.listeMCAdvection:
209 if c.nom[0:18] == 'Type_Of_Advection_' and c.valeur!=None:
213 #print DicoEnumCasEnInverse['Type_Of_Advection']
214 listeAdvection[index]=DicoEnumCasEnInverse['Type_Of_Advection'][c.valeur]
215 if c.nom[0:13] == 'Supg_Option_' and c.valeur!=None:
218 listeAdvection[index]=DicoEnumCasEnInverse['Supg_Option'][c.valeur]
219 if c.nom[0:23] == 'Upwind_Coefficients_Of_' and c.valeur!=None:
222 listeUpwind[index]=c.valeur
223 self.texteDico += "TYPE OF ADVECTION = "+ str(listeAdvection) + "\n"
224 self.texteDico += "SUPG OPTION = "+ str(listeSupg) + "\n"
225 self.texteDico += "UPWIND COEFFICIENTS = "+ str(listeUpwind) + "\n"
227 def chercheChildren(self,obj):
228 for c in obj.liste_mc_presents():
229 objc=obj.get_child(c)
230 if hasattr(objc,'liste_mc_presents') and objc.liste_mc_presents() != [] : self.chercheChildren(objc)
231 else : self.listeMCAdvection.append(objc)