1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2007-2021 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
21 Ce module contient le plugin generateur de fichier au format
25 from __future__ import print_function
26 from __future__ import absolute_import
28 from builtins import str
35 from .generator_python import PythonGenerator
37 listeCalParName = ('Time' , 'Temperature', 'DoseRate', 'Thickness') #'calculation_parameter_names'
42 Retourne les informations necessaires pour le chargeur de plugins
44 Ces informations sont retournees dans un dictionnaire
49 # La factory pour creer une instance du plugin
50 'factory' : MapGenerator,
54 class MapGenerator(PythonGenerator):
56 Ce generateur parcourt un objet de type JDC et produit
57 un texte au format eficas et
62 def gener(self,obj,format='brut',config=None,appliEficas=None):
63 self.appliEficas=appliEficas
64 self.cata=self.appliEficas.readercata.cata
66 self.text=PythonGenerator.gener(self,obj,format)
67 if obj.isValid() :self.genereTexte(obj)
74 self.listeEquations=[]
78 def genereTexte(self,obj) :
79 print ('genereTexte', self.typeEtude)
80 if self.typeEtude == "Calculation" : self.genereCalculation()
83 def generPROC_ETAPE(self,obj):
84 s=PythonGenerator.generPROC_ETAPE(self,obj)
85 if obj.nom == "Calculation_for_Mechanistic" : print ('hjkhjkh');self.typeEtude="Calculation"
88 def genereCalculation(self) :
90 Prepare le contenu du fichier de parametres python
93 self.texteInput += self.genereCsv()
94 self.texteInput += self.genereCalculationParams()
95 self.texteInput += self.txtNomCst
96 self.texteInput += self.txtVal
97 self.texteInput += self.txtValAct
98 self.texteInput += self.txtNomCstNA
99 self.texteInput += self.txtValNA
100 self.texteInput += self.txtInitName
101 self.texteInput += self.txtInitVal
102 self.texteInput += self.genereEquations()
103 print (self.texteInput)
105 def writeDefault(self, fn):
106 # normalement c_solver_polymer_kinetics_myStudy.input ou myStudy est le nom de l etude
107 fileInput = fn[:fn.rfind(".")] + '.input'
108 f = open( str(fileInput), 'wb')
109 f.write( self.texteInput )
113 def genereCalculationParams(self) :
114 txtNom = "calculation_parameter_names = [ "
115 txtVal = "calculation_parameters = [ "
116 for param in ('Time' , 'Temperature', 'DoseRate', 'Thickness') :
117 if param in self.dictValeur.keys() :
118 txtNom += "'"+param + "', "
119 txtVal += str(self.dictValeur[param]) + ", "
120 # on enleve les dernieres , et on ferme
121 txtNom = txtNom[0:-2]
123 txtVal = txtVal[0:-2]
125 txt = txtNom + txtVal
128 def genereEquations(self) :
131 TechnicalUse = self.dictValeur['TechnicalUse']
132 ModelName = self.dictValeur['ModelName']
133 for param in self.listInitialParameters:
134 print ('*******************************************')
135 print (' je traite ', param , 'index : ', index)
138 if index != 0 : txtParam = 'Dy[j*5 + '+str(index)+ '] = '
139 else : txtParam = 'Dy[j*5] = '
141 for equation in self.listeEquations :
142 if param in (self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation].keys()):
143 print ('____________ trouve : ', param , 'in ', equation, ' ', self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation][param])
145 if self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation][param][0] == '-' :
146 txtParam += ' ' + self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation][param]
149 txtParam += ' + ' + self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation][param]
151 txtParam += self.cata.dicoEquations[TechnicalUse][ModelName]['equa_diff'][equation][param]
152 print (' txtParam intermediaire ', txtParam)
155 txtParam = txtParam + ", "
159 print ('fin param', param, 'trouve ', trouveParam, '___________________________')
160 print ('*************************************************')
162 print ('_________________fin for')
167 def genereCsv(self) :
168 txt = 'study_name = ' +self.dictValeur['SimulationName'] + "\n"
169 txt += 'csv_output_file_name = ' + self.dictValeur['OutPutFolder'] + '/c_solver_stiff_ode_1d_' + self.dictValeur['SimulationName']+ '.csv\n'
173 def generMCList(self,obj):
174 s=PythonGenerator.generMCList(self,obj)
175 if obj.nom == 'ConstantesArrhenius' :
176 self.txtNomCst = "Arrhenius_Name = [ "
177 self.txtVal = "Arrhenius_A = [ "
178 self.txtValAct = "Arrhenius_Ea = [ "
179 for objFils in obj.data:
180 for mc in objFils.mcListe :
181 self.txtNomCst += "'" + mc.nom + "', "
182 self.txtVal += str(mc.valeur[0]) + ", "
183 self.txtValAct += str(mc.valeur[1]) + ", "
184 self.txtNomCst = self.txtNomCst[0:-2]
185 self.txtVal = self.txtVal[0:-2]
186 self.txtValAct = self.txtValAct [0:-2]
187 self.txtNomCst += ']\n'
189 self.txtValAct += ']\n'
191 if obj.nom == 'ConstantesNonArrhenius' :
192 self.txtNomCstNA = "non_Arrhenius_coefs_names = [ "
193 self.txtValNA = "non_Arrhenius_coefs = [ "
194 for objFils in obj.data:
195 for mc in objFils.mcListe :
196 self.txtNomCstNA += "'" + mc.nom + "', "
197 self.txtValNA += str(mc.valeur) + ", "
198 self.txtNomCstNA = self.txtNomCstNA[0:-2]
199 self.txtValNA = self.txtValNA[0:-2]
200 self.txtNomCstNA += ']\n'
201 self.txtValNA += ']\n'
203 if obj.nom == 'InitialParameters' :
204 self.listInitialParameters =[]
205 self.txtInitName = "initial_Value_names = [ "
206 self.txtInitVal = "initial_Values = [ "
207 for objFils in obj.data:
208 for mc in objFils.mcListe :
209 self.txtInitName += "'" + mc.nom + "', "
210 self.txtInitVal += str(mc.valeur) + ", "
211 self.listInitialParameters.append(mc.nom)
212 self.txtInitName = self.txtInitName[0:-2]
213 self.txtInitVal = self.txtInitVal[0:-2]
214 self.txtInitName += ']\n'
215 self.txtInitVal += ']\n'
217 if obj.nom in( 'initiation','propagation','termination','stabilization') :
219 for mc in o.mcListe :
220 nom=mc.nom.replace (' ','').replace ('+','_').replace ('-','_').replace ('>','_').replace('(','').replace(')','').replace('*','').replace('[','').replace(']','')
222 self.listeEquations.append(nom )
225 def generMCSIMP(self,obj) :
227 Convertit un objet MCSIMP en texte python
228 Remplit le dictionnaire des MCSIMP
230 s=PythonGenerator.generMCSIMP(self,obj)
231 if obj.nom=='Consigne' : return s
233 if obj.getGenealogie()[0][-6:-1]=="_PARA":
234 self.dictParam[obj.nom]=obj.valeur
236 self.dictValeur[obj.nom]=obj.valeur