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 debutTextePhys ="[VERSION\n NUM 1\n FILETYPE PHYS\n]\n"
30 debutTextePhys+="[MATERIALS\n [CONDUCTOR\n"
31 texteConductor =" [CONDUCTIVITY\n LAW LINEAR\n"
32 texteConductor+=" HOMOGENEOUS TRUE\n"
33 texteConductor+=" ISOTROPIC TRUE\n"
34 texteConducto2 =" 0.0000000000000000E+00\n ]\n"
35 texteConducto2+=" [PERMEABILITY\n LAW LINEAR\n"
36 texteConducto2+=" HOMOGENEOUS TRUE\n"
37 texteConducto2+=" ISOTROPIC TRUE\n"
38 texteNoCond =" [PERMITTIVITY\n LAW LINEAR\n"
39 texteNoCond+=" HOMOGENEOUS TRUE\n ISOTROPIC TRUE\n"
40 texteNoCond+=" VALUE COMPLEX 0.1000000000000000E+01 0.0000000000000000E+00\n"
41 texteNoCond+=" ]\n [PERMEABILITY\n LAW LINEAR\n"
42 texteNoCond+=" HOMOGENEOUS TRUE\n ISOTROPIC TRUE\n"
44 debutTexteParam ="[VERSION\n NUM 1\n FILETYPE PARAM\n]\n"
45 debutTexteParam+="[PROBLEM\n NAME HARMONIC\n]\n"
46 debutTexteParam+="[CAR_FILES\n NAME "
51 Retourne les informations necessaires pour le chargeur de plugins
52 Ces informations sont retournees dans un dictionnaire
57 # La factory pour creer une instance du plugin
58 'factory' : CARMELCNDGenerator,
62 class CARMELCNDGenerator(PythonGenerator):
64 Ce generateur parcourt un objet de type JDC et produit
65 un texte au format eficas et
66 un texte au format dictionnaire
69 # Les extensions de fichier permis?
72 #----------------------------------------------------------------------------------------
73 def gener(self,obj,format='brut',config=None):
77 # Cette instruction genere le contenu du fichier de commandes (persistance)
78 self.text=PythonGenerator.gener(self,obj,format)
83 #----------------------------------------------------------------------------------------
85 #----------------------------------------------------------------------------------------
91 #----------------------------------------------------------------------------------------
93 #----------------------------------------------------------------------------------------
95 def writeDefault(self,fn) :
98 self.texteParam=debutTexteParam
100 self.traiteSourceVCut()
101 fileIngendof = fn[:fn.rfind(".")] + '.ingendof'
102 f = open( str(fileIngendof), 'wb')
103 f.write( self.texteIngendof )
106 self.textePhys=debutTextePhys
107 self.traiteMateriaux()
108 filePhys = fn[:fn.rfind(".")] + '.phys'
109 f = open( str(filePhys), 'wb')
110 f.write( self.textePhys )
113 fileParam = fn[:fn.rfind(".")] + '.param'
115 f = open( str(fileParam), 'wb')
116 f.write( self.texteParam )
119 self.texteCMD="[ \n GLOBAL \n] \n[ \nVISU \nDomaine \nMED \nELEMENT \n] "
120 fileCMD = fn[:fn.rfind(".")] + '.cmd'
121 f = open( str(fileCMD), 'wb')
122 f.write( self.texteCMD )
125 nomBaseFichier=os.path.basename(fileParam).split(".med")[0]
127 self.texteInfcarmel=nomBaseFichier
128 fileInfcarmel = fn[:fn.rfind(".")] + '.infcarmel'
129 f = open( str(fileInfcarmel), 'wb')
130 f.write( self.texteInfcarmel )
133 self.texteInpostpro=nomBaseFichier+"\n"+nomBaseFichier.split(".param")[0]+'.xmat\n'+nomBaseFichier.split(".param")[0]+'.cmd'
134 fileInpostpro = fn[:fn.rfind(".")] + '.inpostprocess'
135 f = open( str(fileInpostpro), 'wb')
136 f.write( self.texteInpostpro )
139 #----------------------------------------------------------------------------------------
140 # analyse des commentaires pour trouver le nom du fichier
141 #----------------------------------------------------------------------------------------
143 def chercheFichier(self) :
145 for e in self.racine.etapes:
146 if isinstance(e,Accas.COMMENTAIRE):
147 print 'ùmasdkfh=',e.valeur[0:17]
148 if e.valeur[0:17]=="Cree - fichier : ":
150 liste=debut.split(" - ")
152 print 'nom=',nomFichier
153 print 'e.va=',e.valeur.split(" ")[-1]
155 nomDomaine=e.valeur.split(" ")[-1]
157 self.texteIngendof =os.path.basename(nomFichier)+"\n"
158 self.texteParam += os.path.basename(nomFichier).split(".med")[0]+".car\n]\n"
159 self.texteParam +="[PHYS_FILES\n NAME "+os.path.basename(nomFichier).split(".med")[0]+".phys\n]\n"
161 #----------------------------------------------------------------------------------------
162 # analyse du dictionnaire pour trouver les sources et les VCut
163 #----------------------------------------------------------------------------------------
165 def traiteSourceVCut(self) :
168 self.texteSourcePhys="[SOURCES\n"
169 for k in self.dictMCVal.keys():
170 if k.find ("______SOURCE__") > -1 :
171 noms=k.split("_____")
172 if noms[0] not in listeSource : listeSource.append(noms[0])
173 if k.find ("______VCUT__") > -1 :
174 noms=k.split("_____")
175 if noms[0] not in listeVCut : listeVCut.append(noms[0])
177 for source in listeSource:
178 debutKey=source+"______SOURCE__"
179 texteSource=self.dictMCVal[debutKey+"NomDomaine"]+"\n"
181 for val in self.dictMCVal[debutKey+"VecteurDirecteur"] :
182 texteSource+=str(val)+" "
184 for val in self.dictMCVal[debutKey+"Centre"] :
185 texteSource+=str(val)+" "
187 texteSource+=str(self.dictMCVal[debutKey+"SectionDomaine"])+"\n"
188 self.texteIngendof+=texteSource
189 self.texteSourcePhys+=" [STRANDED_INDUCTOR\n"
190 self.texteSourcePhys+=" NAME "+source+"\n"
191 self.texteSourcePhys+=" NTURNS "+str(self.dictMCVal[debutKey+"NbdeTours"])+"\n"
192 self.texteSourcePhys+=" CURJ POLAR "+str(self.dictMCVal[debutKey+"Amplitude"])
193 self.texteSourcePhys+=" 0.0000000000000000E+00\n ]\n"
195 self.texteSourcePhys+="]\n"
196 for vcut in listeVCut:
197 self.texteIngendof+="1\n"
198 debutKey=vcut+"______VCUT__"
199 if self.dictMCVal[debutKey+"Orientation"] == "Oppose" :self.texteIngendof+="0\n"
200 else : self.texteIngendof+="1\n"
201 if self.dictMCVal["__PARAMETRES__TypedeFormule"]=="APHI" :self.texteIngendof+="1\n"
202 else : self.texteIngendof+="2\n"
205 #----------------------------------------------------------------------------------------
206 def traiteMateriaux(self) :
207 #----------------------------------------------------------------------------------------
210 for k in self.dictMCVal.keys():
211 if k.find ("______CONDUCTEUR") > -1 :
212 noms=k.split("_____")
213 if noms[0] not in listeCond : listeCond.append(noms[0])
214 if k.find ("______NOCOND") > -1 :
215 noms=k.split("_____")
216 if noms[0] not in listeNoCond : listeNoCond.append(noms[0])
219 self.textePhys +=" NAME "+c+"\n"
220 self.textePhys +=texteConductor
221 self.textePhys+=" VALUE COMPLEX "
222 self.textePhys+=str(self.dictMCVal[c+"______CONDUCTEUR__Conductivite"])
223 self.textePhys+=texteConducto2
224 self.textePhys+=" VALUE COMPLEX "
225 self.textePhys+=str(self.dictMCVal[c+"______CONDUCTEUR__Permeabilite"])
226 self.textePhys+=" 0.0000000000000000E+00\n ]\n ]\n"
228 for c in listeNoCond:
229 self.textePhys+=" [DIELECTRIC\n"
230 self.textePhys +=" NAME "+c+"\n"
231 self.textePhys += texteNoCond
232 self.textePhys+=" VALUE COMPLEX "
233 self.textePhys+=str(self.dictMCVal[c+"______NOCOND__Permeabilite"])
234 self.textePhys+=" 0.0000000000000000E+00\n ]\n ]\n"
236 self.textePhys+="]\n"
237 self.textePhys+=self.texteSourcePhys
239 #----------------------------------------------------------------------------------------
240 # Creation du fichier Param
241 #----------------------------------------------------------------------------------------
242 def traiteParam(self):
243 self.texteParam +="[FREQUENCY\n SINGLE "+str(self.dictMCVal["__PARAMETRES__Frequence_en_Hz"])+"\n]\n"
244 self.texteParam +="[SOLVER\n NAME BICGCR\n"
245 self.texteParam +=" [ITERATIVE_PARAM\n"
246 self.texteParam +=" NITERMAX "+str(self.dictMCVal["__PARAMETRES__Nb_Max_Iterations"])+"\n"
247 self.texteParam +=" EPSILON "+ str(self.dictMCVal["__PARAMETRES__Erreur_Max"])+"\n ]\n]"
250 #----------------------------------------------------------------------------------------
251 # analyse de chaque noeud de l'arbre
252 #----------------------------------------------------------------------------------------
254 def generMCSIMP(self,obj) :
255 """recuperation de l objet MCSIMP"""
256 s=PythonGenerator.generMCSIMP(self,obj)
257 if hasattr(obj.etape,'sdnom'): clef=obj.etape.sdnom+"____"
259 for i in obj.get_genealogie() :
261 self.dictMCVal[clef]=obj.valeur
265 def get_repExeCarmel(self) :
266 return self.dictMCVal["__PARAMETRES__RepCarmel"]