Salome HOME
Pour Adao
[tools/eficas.git] / generator / OpenturnsBase.py
1 # -*- coding: iso-8859-1 -*-
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
21 """
22 Ce module contient la partie commune 
23 aux generateurs XML et Etude d Openturns
24 """
25
26 __revision__ = "V1.0"
27
28 import os
29 import sys
30
31 path=os.getcwd()
32 pathDef=path+"DefautOpenturns"
33
34 sys.path.append(pathDef)
35
36
37 #=============================================
38 # La classe generale
39 #=============================================
40
41 class Generateur :
42
43   '''
44   Classe generale du generateur
45   DictMCVal : dictionnaire des mots-cles
46   ListeVariables : chaque variable est decrite par un dictionnaire ; cette liste les regroupe
47   DictLois : dictionnaires des lois
48   '''
49   def __init__ (self, appli, DictMCVal = {}, ListeVariables = [], DictLois = {}, DictVariables = {} ) :
50   #---------------------------------------------------------#
51     self.ListeVariables = ListeVariables
52     self.ListeVariablesIn = []
53     self.ListeVariablesOut = []
54     self.DictLois = DictLois
55     self.DictVariables = DictVariables
56     self.DictMCVal = DictMCVal
57     self.DictTypeVar = {}
58     self.nbVarIn = 0
59     self.nbVarOut = 0
60     self.creeInfoVar()
61     self.appli = appli
62     #
63     # On charge eventuellement le Solver par defaut
64     # et les valeurs par defaut du Solver (dans l init)
65     #
66     try :
67     #if 1 :
68         Solver = self.DictMCVal["PhysicalSolver"]
69         import_name = "Defaut"+Solver
70         self.module = __import__( import_name, globals(), locals() )
71         monDefaut = self.module.Defaut( self )
72     #else :
73     except:
74         self.module = None
75
76
77   def getSTDGenerateur(self) :
78   #--------------------------#
79     try :
80         gener = self.module.__dict__["MonSTDGenerateur"]
81         monSTDGenerateur=gener( self.DictMCVal, self.ListeVariablesIn, self.ListeVariablesOut, self.DictLois )
82     except :
83         from OpenturnsSTD import STDGenerateur
84         monSTDGenerateur = STDGenerateur( self.appli, self.DictMCVal, self.ListeVariablesIn, self.ListeVariablesOut, self.DictLois )
85     return monSTDGenerateur
86       
87   def getXMLGenerateur(self) :
88   #--------------------------#
89     try :
90         gener = self.module.__dict__["MonXMLGenerateur"]
91         monXMLGenerateur=gener( self.DictMCVal, self.ListeVariables, self.DictLois )
92     except :
93         from OpenturnsXML import XMLGenerateur
94         monXMLGenerateur = XMLGenerateur( self.appli, self.DictMCVal, self.DictVariables )
95     return monXMLGenerateur
96       
97   def creeInfoVar (self) :
98   #----------------------#
99     """
100     On repere les variables in/out et on les numerote.
101     """
102     num = 0
103     liste = []
104     for DictVariable in self.ListeVariables :
105       if not DictVariable.has_key("Type") : DictVariable["Type"] = "in"
106       self.DictTypeVar[num] = DictVariable["Type"]
107       if DictVariable["Type"] == "in" : 
108          self.nbVarIn = self.nbVarIn + 1
109          self.ListeVariablesIn.append( DictVariable )
110          print "OpenturnsBase.py: new input variable = ", DictVariable
111       else:
112          self.nbVarOut = self.nbVarOut + 1
113          self.ListeVariablesOut.append( DictVariable )
114          print "OpenturnsBase.py: new output variable = ", DictVariable
115       liste.append( DictVariable )
116       num = num + 1
117     self.ListeVariables = liste
118
119
120   def ajouteDictMCVal(self, dicoPlus) :
121   #-----------------------------------#
122   # Appele par le classe Defaut du python specifique au code (exple DefautASTER.py)
123   # enrichit self.DictMCVal avec les valeurs donnees dans dicoPlus
124   # si elles ne sont pas deja dans le dictionnaire
125
126     for clef in dicoPlus.keys():
127         if not self.DictMCVal.has_key(clef) :
128            self.DictMCVal[clef] = dicoPlus[clef]
129
130   def ajouteInfoVariables (self, dicoVariablesIn, dicoVariablesOut) :
131   #-----------------------------------------------------------------#
132   # Appele par le classe Defaut du python specifique au code (exple DefautASTER.py)
133   # met a jour les dictionnaires qui decrivent les variables (regexp par exemple)
134     liste=[]
135     num = 0
136     for dictVariable in self.ListeVariables:
137          if self.DictTypeVar[num] == "in" :
138             dico = dicoVariablesIn
139          else :
140             dico = dicoVariablesOut
141          for nouvelleVariable in dico.keys() :
142             if not dictVariable.has_key(nouvelleVariable):
143                dictVariable[nouvelleVariable] = dico[nouvelleVariable]
144          liste.append( dictVariable )
145          num = num + 1