]> SALOME platform Git repositories - tools/eficas.git/blob - generator/generator_CARMELCND.py
Salome HOME
premiere version
[tools/eficas.git] / generator / generator_CARMELCND.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 import Accas
28
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"
43
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 "
47
48
49 def entryPoint():
50    """
51       Retourne les informations necessaires pour le chargeur de plugins
52       Ces informations sont retournees dans un dictionnaire
53    """
54    return {
55         # Le nom du plugin
56           'name' : 'CARMELCND',
57         # La factory pour creer une instance du plugin
58           'factory' : CARMELCNDGenerator,
59           }
60
61
62 class CARMELCNDGenerator(PythonGenerator):
63    """
64       Ce generateur parcourt un objet de type JDC et produit
65       un texte au format eficas et 
66       un texte au format dictionnaire
67
68    """
69    # Les extensions de fichier permis?
70    extensions=('.comm',)
71
72 #----------------------------------------------------------------------------------------
73    def gener(self,obj,format='brut',config=None):
74        
75       self.initDico()
76       
77       # Cette instruction genere le contenu du fichier de commandes (persistance)
78       self.text=PythonGenerator.gener(self,obj,format)
79       self.racine=obj
80       return self.text
81
82
83 #----------------------------------------------------------------------------------------
84 # initialisations
85 #----------------------------------------------------------------------------------------
86    
87    def initDico(self) :
88  
89       self.dictMCVal={}
90
91 #----------------------------------------------------------------------------------------
92 # ecriture
93 #----------------------------------------------------------------------------------------
94
95    def writeDefault(self,fn) :
96
97        self.texteIngendof=""
98        self.texteParam=debutTexteParam
99        self.chercheFichier()
100        self.traiteSourceVCut()
101        fileIngendof = fn[:fn.rfind(".")] + '.ingendof'
102        f = open( str(fileIngendof), 'wb')
103        f.write( self.texteIngendof )
104        f.close()
105
106        self.textePhys=debutTextePhys
107        self.traiteMateriaux()
108        filePhys = fn[:fn.rfind(".")] + '.phys'
109        f = open( str(filePhys), 'wb')
110        f.write( self.textePhys )
111        f.close()
112
113        fileParam = fn[:fn.rfind(".")] + '.param'
114        self.traiteParam()
115        f = open( str(fileParam), 'wb')
116        f.write( self.texteParam )
117        f.close()
118        
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 )
123        f.close()
124        
125        nomBaseFichier=os.path.basename(fileParam).split(".med")[0]
126        
127        self.texteInfcarmel=nomBaseFichier
128        fileInfcarmel = fn[:fn.rfind(".")] + '.infcarmel'
129        f = open( str(fileInfcarmel), 'wb')
130        f.write( self.texteInfcarmel )
131        f.close()
132        
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 )
137        f.close()
138
139 #----------------------------------------------------------------------------------------
140 #  analyse des commentaires pour trouver le nom du fichier
141 #----------------------------------------------------------------------------------------
142
143    def chercheFichier(self) :
144        nomFichier="inconnu"
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 : ":
149                   debut=e.valeur[17:]
150                   liste=debut.split(" - ")
151                   nomFichier=liste[0]
152                   print 'nom=',nomFichier
153                   print 'e.va=',e.valeur.split(" ")[-1]
154                   print 'liste=',liste
155                   nomDomaine=e.valeur.split(" ")[-1]
156                   break
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"
160
161 #----------------------------------------------------------------------------------------
162 #  analyse du dictionnaire  pour trouver les sources et les VCut
163 #----------------------------------------------------------------------------------------
164
165    def traiteSourceVCut(self) :
166        listeSource=[]
167        listeVCut=[]
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])
176        listeSource.sort()
177        for source in listeSource:
178            debutKey=source+"______SOURCE__"
179            texteSource=self.dictMCVal[debutKey+"NomDomaine"]+"\n"
180            texteSource+="2\n"
181            for val in self.dictMCVal[debutKey+"VecteurDirecteur"] :
182                texteSource+=str(val)+" "
183            texteSource+="\n"
184            for val in self.dictMCVal[debutKey+"Centre"] :
185                texteSource+=str(val)+" "
186            texteSource+="\n"
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"
194          
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"
203        
204         
205 #----------------------------------------------------------------------------------------
206    def traiteMateriaux(self) :
207 #----------------------------------------------------------------------------------------
208        listeCond=[]
209        listeNoCond=[]
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])
217    
218        for c in listeCond:
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"
227
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"
235
236        self.textePhys+="]\n"
237        self.textePhys+=self.texteSourcePhys
238
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]"
248
249
250 #----------------------------------------------------------------------------------------
251 #  analyse de chaque noeud de l'arbre 
252 #----------------------------------------------------------------------------------------
253
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+"____"
258         else: clef=""
259         for i in obj.get_genealogie() :
260             clef=clef+"__"+i
261         self.dictMCVal[clef]=obj.valeur
262
263         return s
264
265    def get_repExeCarmel(self) :
266        return self.dictMCVal["__PARAMETRES__RepCarmel"]
267