Salome HOME
sauvegarde du 2 mai
[tools/eficas.git] / generator / generator_TELEMAC.py
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2013   EDF R&D
3 #
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.
8 #
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.
13 #
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
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 """Ce module contient le plugin generateur de fichier au format  Code_Carmel3D pour EFICAS.
21 """
22
23 import traceback
24 import types,string,re,os
25 from Extensions.i18n import tr
26 from generator_python import PythonGenerator
27
28 extensions=('.comm',)
29 from aideAuxConvertisseurs import listeSupprime, DicoAglomere, DicoEficasToCas
30 from enumDicoTelemac       import DicoEnumCasEnInverse
31
32
33 def entryPoint():
34    """
35       Retourne les informations necessaires pour le chargeur de plugins
36       Ces informations sont retournees dans un dictionnaire
37    """
38    return {
39         # Le nom du plugin
40           'name' : 'TELEMAC',
41         # La factory pour creer une instance du plugin
42           'factory' : TELEMACGenerator,
43           }
44
45
46 class TELEMACGenerator(PythonGenerator):
47    """
48       Ce generateur parcourt un objet de type JDC et produit
49       un texte au format eficas et 
50       un texte au format dictionnaire
51
52    """
53
54 #----------------------------------------------------------------------------------------
55    def gener(self,obj,format='brut',config=None):
56        
57       self.initDico()
58       #print self.texteDico
59       
60       # Cette instruction genere le contenu du fichier de commandes (persistance)
61       self.text=PythonGenerator.gener(self,obj,format)
62       return self.text
63
64
65 #----------------------------------------------------------------------------------------
66 # initialisations
67 #----------------------------------------------------------------------------------------
68    
69    def initDico(self) :
70  
71       self.PE=False
72       self.FE=False
73       self.VE=False
74       self.textPE = 'PRESCRIBED ELEVATIONS :'
75       self.textFE = 'PRESCRIBED FLOWRATES :'
76       self.textVE = 'PRESCRIBED VELOCITY :'
77       self.texteDico = ""
78  
79
80
81
82 #----------------------------------------------------------------------------------------
83 # ecriture
84 #----------------------------------------------------------------------------------------
85
86    def writeDefault(self,fn) :
87        fileDico = fn[:fn.rfind(".")] + '.py'
88        f = open( str(fileDico), 'wb')
89        f.write( self.texteDico )
90        f.close()
91
92 #----------------------------------------------------------------------------------------
93 #  analyse de chaque noeud de l'arbre 
94 #----------------------------------------------------------------------------------------
95
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)
101         #print obj
102         #print obj.nom
103         if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
104         
105         return s
106
107    def generMCSIMP(self,obj) :
108         """recuperation de l objet MCSIMP"""
109         s=PythonGenerator.generMCSIMP(self,obj)
110         if obj.nom == "Title" :
111             print s
112             print str(obj.valeur)
113             print repr(obj.valeur)
114
115        
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
120
121         nomMajuscule=obj.nom.upper()
122         nom=nomMajuscule.replace('_',' ') 
123         if nom in listeSupprime or s == "" : return s
124
125         sTelemac=s[0:-1]
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():  
132              sT = "'"
133              for v in obj.valeur:
134                try : sT +=DicoEnumCasEnInverse[obj.nom][v] +";"
135                except : print "generMCSIMP Pb avec ", obj.nom, v
136              sTelemac=sT[0:-1]+"'"
137
138         if nom in DicoEficasToCas.keys() : nom=DicoEficasToCas[nom]
139         self.texteDico+=nom+ ":" + str(sTelemac) + "\n"
140         return s
141
142    def generMCFACT(self,obj):
143       """
144       """
145       s=PythonGenerator.generMCFACT(self,obj)
146       if obj.nom in TELEMACGenerator.__dict__.keys() : apply(TELEMACGenerator.__dict__[obj.nom],(self,obj))
147  
148       return s
149
150   
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
157
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' :
165               self.PE=True
166               self.textPE += str(valeur) +"; "
167           else : self.textPE += "0.; "
168           if valForme == 'Prescribed Flowrates' :
169               self.FE=True
170               self.textFE += str(valeur) +"; "
171           else : self.textFE += "0.; "
172           if valForme == 'Prescribed Velocity'  :
173               self.VE=True
174               self.textVE += str(valeur) +"; "
175           else : self.textVE += "0.; "
176       #print self.textPE, self.textFE,self.textVE
177
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' 
182
183    def Validation(self,obj):
184        self.texteDico += "VALIDATION : True \n"
185  
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"
192
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
197        #print hh, mm, ss
198        self.texteDico += "ORIGINAL HOUR OF TIME :"+str(hh)+" ,"+str(mm)+ ","+str(ss)+"\n"
199
200    def Type_Of_Advection(self,obj):
201        listeAdvection=[1,5,1,1]
202        listeSupg=[2,2,2,2]
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:
208            #print c.nom
209            if c.nom[0:18] == 'Type_Of_Advection_' and c.valeur!=None:
210               suf=c.nom[18:]
211               index=dicoSuf[suf]
212               #print c.valeur
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:
216               suf=c.nom[13:]
217               index=dicoSuf[suf]
218               listeAdvection[index]=DicoEnumCasEnInverse['Supg_Option'][c.valeur]
219            if c.nom[0:23] == 'Upwind_Coefficients_Of_' and c.valeur!=None:
220               suf=c.nom[23:]
221               index=dicoSuf[suf]
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"
226        
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)
232
233       
234