1 #@ AJOUT OpenturnsSolver Macro
2 # -*- coding: iso-8859-1 -*-
6 Ce module contient le generateur Etude pour Openturns
13 defaultSTD = """#! /usr/bin/env python
15 class StudyFileGenerationError:
16 def __init__ (self, st):
19 return "'%s'" % self.st
21 raise StudyFileGenerationError, "The study file was not generated. Check analysis type."
24 headerSTD = """#! /usr/bin/env python
26 # Chargement du module systeme
28 sys.path.append( '%s' )
30 # Chargement du module math
33 # Chargement du module Open TURNS
34 from openturns import *
35 from openturns.viewer import ViewImage,StopViewer,WaitForViewer
43 # Flush des messages en attente
46 # Terminaison du fichier
50 #=============================================
51 # La classe de creation du fichier STD
52 #=============================================
57 Generation du fichier python
59 def __init__ (self, appli, DictMCVal, ListeVariables, DictLois ) :
60 self.DictMCVal = DictMCVal
61 self.ListeVariables = ListeVariables
62 self.DictLois = DictLois
63 #print "DictMCVal=", DictMCVal
64 #print "ListeVariables=", ListeVariables
65 #print "DictLois=", DictLois
66 self.texteSTD = defaultSTD
67 self.OpenTURNS_path = appli.CONFIGURATION.OpenTURNS_path
69 # Ce dictionnaire fait la correspondance entre le mot lu dans le dictionnaire des mots-clefs et la methode a appeler
73 { "Experiment Plane" : "ExperimentPlane",
74 "Random Sampling" : "MinMaxRandomSampling",
77 "Central Uncertainty" :
78 ( "CentralUncertainty",
79 { "Taylor Variance Decomposition" : "TaylorVarianceDecomposition",
80 "Random Sampling" : "CentralUncertaintyRandomSampling",
83 "Threshold Exceedence" :
84 ( "ThresholdExceedence",
85 { "Simulation" : "Simulation",
86 "Analytical" : "Analytical",
87 "MonteCarlo" : "MonteCarlo",
89 "ImportanceSampling" : "ImportanceSampling",
90 "FirstOrder" : "FORM",
91 "SecondOrder" : "SORM",
93 "AbdoRackwitz" : "AbdoRackwitz",
98 # Ce dictionnaire liste le nom des variables utilisees dans le script
99 # La clef est le nom attendu par les methodes, la valeur est le nom produit dans le fichier de sortie
100 # Le fait de passer par un dictionnaire permet de controler que les variables existent et sont correctement nommees
101 # meme si clef == valeur
105 "wrapper" : "wrapper",
106 "wrapperdata" : "wrapperdata",
107 "frameworkdata" : "frameworkdata",
108 "framework" : "framework",
109 "studyid" : "studyid",
110 "studycase" : "studycase",
111 "componentname" : "componentname",
113 "scaledVector" : "scaledVector",
114 "translationVector" : "translationVector",
116 "myCenteredReductedGrid" : "myCenteredReductedGrid",
117 "myExperimentPlane" : "myExperimentPlane",
118 "inputSample" : "inputSample",
119 "outputSample" : "outputSample",
120 "minValue" : 'results["minValue"]',
121 "maxValue" : 'results["maxValue"]',
124 "distribution" : "distribution",
125 "marginal" : "marginal",
126 "collection" : "collection",
128 "inputRandomVector" : "inputRandomVector",
129 "outputRandomVector" : "outputRandomVector",
130 "myQuadraticCumul" : "myQuadraticCumul",
131 "meanFirstOrder" : 'results["meanFirstOrder"]',
132 "meanSecondOrder" : 'results["meanSecondOrder"]',
133 "standardDeviationFirstOrder" : 'results["standardDeviationFirstOrder"]',
134 "importanceFactors" : 'results["importanceFactors"]',
135 "importanceFactorsGraph" : "importanceFactorsGraph",
136 "importanceFactorsDrawing" : "importanceFactorsDrawing",
137 "empiricalMean" : 'results["empiricalMean"]',
138 "empiricalStandardDeviation" : 'results["empiricalStandardDeviation"]',
139 "empiricalQuantile" : 'results["empiricalQuantile"]',
142 "PCCcoefficient" : 'results["PCCcoefficient"]',
143 "PRCCcoefficient" : 'results["PRCCcoefficient"]',
144 "SRCcoefficient" : 'results["SRCcoefficient"]',
145 "SRRCcoefficient" : 'results["SRRCcoefficient"]',
147 "kernelSmoothedDist" : "kernelSmoothedDist",
148 "kernelSmoothedPDF" : "kernelSmoothedPDF",
149 "myEvent" : "myEvent",
151 "myResult" : "myResult",
152 "probability" : 'results["probability"]',
153 "standardDeviation" : 'results["standardDeviation"]',
156 "coefficientOfVariation" : 'results["coefficientOfVariation"]',
157 "convergenceGraph" : "convergenceGraph",
158 "iterations" : 'results["iterations"]',
159 "myOptimizer" : "myOptimizer",
160 "specificParameters" : "specificParameters",
161 "startingPoint" : "startingPoint",
162 "hasoferReliabilityIndex" : 'results["hasoferReliabilityIndex"]',
163 "standardSpaceDesignPoint" : 'results["standardSpaceDesignPoint"]',
164 "physicalSpaceDesignPoint" : 'results["physicalSpaceDesignPoint"]',
165 "eventProbabilitySensitivity" : 'results["eventProbabilitySensitivity"]',
166 "hasoferReliabilityIndexSensitivity" : 'results["hasoferReliabilityIndexSensitivity"]',
167 "eventProbabilitySensitivityGraph" : "eventProbabilitySensitivityGraph",
168 "hasoferReliabilityIndexSensitivityGraph" : "hasoferReliabilityIndexSensitivityGraph",
169 "modelEvaluationCalls" : 'results["modelEvaluationCalls"]',
170 "modelGradientCalls" : 'results["modelGradientCalls"]',
171 "modelHessianCalls" : 'results["modelHessianCalls"]',
172 "tvedtApproximation" : 'results["tvedtApproximation"]',
173 "hohenBichlerApproximation" : 'results["hohenBichlerApproximation"]',
174 "breitungApproximation" : 'results["breitungApproximation"]',
177 # Ce dictionnaire fait la correspondance entre le mot-clef du catalogue et le flag de la bibliotheque
179 "DebugMessages" : "Log.DBG",
180 "WrapperMessages" : "Log.WRAPPER",
181 "UserMessages" : "Log.USER",
182 "InfoMessages" : "Log.INFO",
183 "WarningMessages" : "Log.WARN",
184 "ErrorMessages" : "Log.ERROR",
189 Pilotage de la creation du fichier python
192 if ( self.DictMCVal.has_key( 'Type' ) ):
193 TypeAnalyse = self.DictMCVal[ 'Type' ]
197 if ( self.traitement.has_key( TypeAnalyse ) ):
198 (Traitement, subDict) = self.traitement[ TypeAnalyse ]
200 if ( Traitement is not None ):
201 self.texteSTD = apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
207 Imprime l entete commun a tous les fichiers
209 txt = headerSTD % self.OpenTURNS_path
210 txt += "# Definit le niveau d'affichage de la log\n"
211 txt += "%s = Log.NONE\n" % self.variable["flags"]
212 for flag in self.logFlags.keys():
213 if ( self.DictMCVal.has_key( flag ) ):
214 val = self.DictMCVal[ flag ]
218 txt += "%s = %s %s %s\n" % (self.variable["flags"], self.variable["flags"], op, self.logFlags[ flag ])
219 txt += "Log.Show( %s )\n" % self.variable["flags"]
225 Imprime le pied de page commun a tous les fichiers
229 def MinMax (self, subDict):
231 Produit le fichier study correspondant a une analyse Min/Max
234 txt += "# Etude 'Min/Max'\n"
239 if ( self.DictMCVal.has_key( 'Method' ) ):
240 Methode = self.DictMCVal[ 'Method' ]
243 if ( subDict.has_key( Methode ) ):
244 Traitement = subDict[ Methode ]
246 if ( Traitement is not None ):
247 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
249 txt += self.MinMaxComputation()
250 txt += self.MinMaxResult()
257 Importe le modele physique
260 if ( self.DictMCVal.has_key( 'FileName' ) ):
261 name = self.DictMCVal[ 'FileName' ]
262 #fonction = name[name.rfind('/')+1:name.rfind('.xml')]
264 txt = "# Charge le modele physique\n"
265 txt = "%s = WrapperFile( '%s' )\n" % (self.variable["wrapper"], name)
267 txt += "if globals().has_key('%s'):\n" % self.variable["framework"]
268 txt += " %s = %s.getWrapperData()\n" % (self.variable["wrapperdata"], self.variable["wrapper"])
269 txt += " %s = %s.getFrameworkData()\n" % (self.variable["frameworkdata"], self.variable["wrapperdata"])
270 txt += " %s.studyid_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studyid"])
271 txt += " %s.studycase_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["studycase"])
272 txt += " %s.componentname_ = %s['%s']\n" % (self.variable["frameworkdata"], self.variable["framework"], self.variable["componentname"])
273 txt += " %s.setFrameworkData( %s )\n" % (self.variable["wrapperdata"], self.variable["frameworkdata"])
274 txt += " %s.setWrapperData( %s )\n" % (self.variable["wrapper"], self.variable["wrapperdata"])
276 txt += "%s = NumericalMathFunction( %s )\n" % (self.variable["model"], self.variable["wrapper"],)
277 txt += "%s = %s.getInputNumericalPointDimension()\n" % (self.variable["n"], self.variable["model"])
281 def ExperimentPlane (self):
283 Etude par plan d experience
285 txt = "# Etude par plan d'experience\n"
287 txt += self.CenteredReductedGrid()
288 txt += self.ScaledVector()
289 txt += self.TranslationVector()
290 txt += "%s = %s\n" % (self.variable["inputSample"], self.variable["myExperimentPlane"])
294 def MinMaxRandomSampling (self):
296 Etude par echantillonage aleatoire
299 if ( self.DictMCVal.has_key( 'PointsNumber' ) ):
300 size = self.DictMCVal[ 'PointsNumber' ]
302 txt = "# Etude par echantillonage aleatoire\n"
303 txt += self.InputDistribution()
304 txt += self.InputRandomVector()
305 txt += "%s = %d\n" % (self.variable["inSize"], size)
306 txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["inputSample"], self.variable["inputRandomVector"], self.variable["inSize"])
310 def InputDistribution (self):
312 Cree la loi jointe des variables d entree
314 txt = "# Definit la loi jointe des variables d'entree\n"
315 txt += "%s = DistributionCollection( %d )\n" % (self.variable["collection"], len( self.ListeVariables ))
319 for variable in self.ListeVariables:
320 nomVar = variable['ModelVariable'].get_name()
321 dictVariables[ nomVar ] = variable['Distribution']
324 sortedVarNames = dictVariables.keys()
325 sortedVarNames.sort()
326 for variable in sortedVarNames:
327 conceptloi = dictVariables[ variable ]
328 loi = self.DictLois[ conceptloi ]
329 if loi.has_key( 'Kind' ):
330 marginale = "%s_%d" % (self.variable["marginal"], i)
331 txt += "# Definit la loi marginale de la composante %d\n" % i
332 txt += "%s = %s\n" % (marginale, apply( STDGenerateur.__dict__[ loi[ 'Kind' ] ], (self, loi, i, self.variable["collection"]) ))
333 txt += "%s[ %d ] = Distribution( %s )\n" % (self.variable["collection"], i, marginale)
337 txt += self.Copula( len( self.ListeVariables ) )
339 txt += "# Definit la loi jointe\n"
340 txt += "%s = ComposedDistribution( %s, Copula( %s ) )\n" % (self.variable["distribution"], self.variable["collection"], self.variable["copula"])
344 def Copula (self, dimension):
346 Cree la copule de la loi jointe
348 txt = "# Definit la copule de la loi jointe\n"
349 txt += "%s = IndependentCopula( %d )\n" % (self.variable["copula"], dimension)
353 def InputRandomVector (self):
355 Cree le vector aleatoire d entree
357 txt = "# Definit le vecteur aleatoire d'entree\n"
358 txt += "%s = RandomVector( %s )\n" % (self.variable["inputRandomVector"], self.variable["distribution"])
362 def OutputRandomVector (self):
364 Cree le vector aleatoire de sortie
366 txt = "# Definit le vecteur aleatoire de sortie\n"
367 txt += "%s = RandomVector( %s, %s )\n" % (self.variable["outputRandomVector"], self.variable["model"], self.variable["inputRandomVector"])
371 def ScaledVector (self):
373 Definit les coefficients multiplicateurs par composante du vecteur
376 if ( self.DictMCVal.has_key( 'UnitsPerDimension' ) ):
377 unitsPerDimension = self.DictMCVal[ 'UnitsPerDimension' ]
378 dimension = len( unitsPerDimension )
380 txt = "# Definit les facteurs d'echelle dans chaque direction\n"
381 txt += "%s = NumericalPoint( %s )\n" % (self.variable["scaledVector"], self.variable["n"])
382 for i in range(dimension):
383 txt += "%s[%d] = %g\n" % (self.variable["scaledVector"], i, unitsPerDimension[i])
384 txt += "%s.scale( %s )\n" % (self.variable["myExperimentPlane"], self.variable["scaledVector"])
388 def TranslationVector (self):
390 Definit le vecteur de translation
393 if ( self.DictMCVal.has_key( 'Center' ) ):
394 center = self.DictMCVal[ 'Center' ]
395 dimension = len( center )
397 txt = "# Definit le vecteur de translation\n"
398 txt += "%s = NumericalPoint( %s )\n" % (self.variable["translationVector"], self.variable["n"])
399 for i in range(dimension):
400 txt += "%s[%d] = %g\n" % (self.variable["translationVector"], i, center[i])
401 txt += "%s.translate( %s )\n" % (self.variable["myExperimentPlane"], self.variable["translationVector"])
407 Definit les niveaux du plan d experience
410 if ( self.DictMCVal.has_key( 'Levels' ) ):
411 levels = self.DictMCVal[ 'Levels' ]
412 dimension = len( levels )
414 txt = "# Definit les niveaux de la structure de grille\n"
415 txt += "%s = NumericalPoint( %d )\n" % (self.variable["levels"], dimension)
416 for i in range(dimension):
417 txt += "%s[%d] = %g\n" % (self.variable["levels"], i, levels[i])
421 def CenteredReductedGrid (self):
423 Definit la grille reduite du plan d experience
426 if ( self.DictMCVal.has_key( 'ExperimentPlane' ) ):
427 plane = self.DictMCVal[ 'ExperimentPlane' ]
429 txt = "# Cree le plan d'experience centre reduit\n"
430 txt += "%s = %s(%s, %s)\n" % (self.variable["myCenteredReductedGrid"], plane, self.variable["n"], self.variable["levels"])
431 txt += "%s = %s.generate()\n" % (self.variable["myExperimentPlane"], self.variable["myCenteredReductedGrid"])
435 def MinMaxComputation (self):
437 Realise le calcul deterministe
440 txt += "%s = %s( %s )\n" % (self.variable["outputSample"], self.variable["model"], self.variable["inputSample"])
444 def MinMaxResult (self):
446 Produit les resultats de l etude
448 txt = "# Resultats\n"
449 txt += "%s = %s.getMin()\n" % (self.variable["minValue"], self.variable["outputSample"])
450 txt += "print '%s = ', %s\n" % (self.variable["minValue"], self.variable["minValue"])
452 txt += "%s = %s.getMax()\n" % (self.variable["maxValue"], self.variable["outputSample"])
453 txt += "print '%s = ', %s\n" % (self.variable["maxValue"], self.variable["maxValue"])
457 def CentralUncertainty (self, subDict):
459 Produit le fichier study correspondant a une analyse d incertitude en valeur centrale
462 txt += "# Etude 'Central Uncertainty'\n"
465 txt += self.InputDistribution()
466 txt += self.InputRandomVector()
467 txt += self.OutputRandomVector()
470 if ( self.DictMCVal.has_key( 'Method' ) ):
471 Methode = self.DictMCVal[ 'Method' ]
474 if ( subDict.has_key( Methode ) ):
475 Traitement = subDict[ Methode ]
477 if ( Traitement is not None ):
478 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
484 def TaylorVarianceDecomposition (self):
486 Etude par decomposition de Taylor
488 txt = "# Cumul quadratique (decomposition de Taylor)\n"
489 txt += "%s = QuadraticCumul( %s )\n" % (self.variable["myQuadraticCumul"], self.variable["outputRandomVector"])
491 txt += "# Resultats\n"
493 if ( self.DictMCVal.has_key( 'MeanFirstOrder' ) ):
494 if ( self.DictMCVal[ 'MeanFirstOrder' ] == "yes" ):
495 txt += "%s = %s.getMeanFirstOrder()\n" % (self.variable["meanFirstOrder"], self.variable["myQuadraticCumul"])
496 txt += "print '%s = ', %s\n" % (self.variable["meanFirstOrder"], self.variable["meanFirstOrder"])
499 if ( self.DictMCVal.has_key( 'MeanSecondOrder' ) ):
500 if ( self.DictMCVal[ 'MeanSecondOrder' ] == "yes" ):
501 txt += "%s = %s.getMeanSecondOrder()\n" % (self.variable["meanSecondOrder"], self.variable["myQuadraticCumul"])
502 txt += "print '%s = ', %s\n" % (self.variable["meanSecondOrder"], self.variable["meanSecondOrder"])
505 if ( self.DictMCVal.has_key( 'StandardDeviationFirstOrder' ) ):
506 if ( self.DictMCVal[ 'StandardDeviationFirstOrder' ] == "yes" ):
507 txt += "%s = %s.getCovariance()\n" % (self.variable["standardDeviationFirstOrder"], self.variable["myQuadraticCumul"])
508 txt += "dim = %s.getDimension()\n" % self.variable["standardDeviationFirstOrder"]
509 txt += "for i in range( dim ):\n"
510 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
511 txt += "print '%s = ', %s\n" % (self.variable["standardDeviationFirstOrder"], self.variable["standardDeviationFirstOrder"])
514 if ( self.DictMCVal.has_key( 'NumericalResults' ) ):
515 if ( self.DictMCVal[ 'NumericalResults' ] == "yes" ):
516 txt += "if ( %s.getDimension() == 1):\n" % self.variable["outputRandomVector"]
517 txt += " %s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myQuadraticCumul"])
518 txt += " print '%s = ', %s\n" % (self.variable["importanceFactors"], self.variable["importanceFactors"])
521 if ( self.DictMCVal.has_key( 'GraphicalResults' ) ):
522 if ( self.DictMCVal[ 'GraphicalResults' ] == "yes" ):
523 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myQuadraticCumul"])
524 txt += "Show( %s )\n" % self.variable["importanceFactorsGraph"]
525 txt += "%s.draw( '%s' )\n" % (self.variable["importanceFactorsGraph"], self.variable["importanceFactorsDrawing"])
526 txt += "ViewImage( %s.getBitmap() )\n" % self.variable["importanceFactorsGraph"]
527 txt += "print 'bitmap =', %s.getBitmap()\n" % self.variable["importanceFactorsGraph"]
528 txt += "print 'postscript =', %s.getPostscript()\n" % self.variable["importanceFactorsGraph"]
534 def CentralUncertaintyRandomSampling (self):
536 Etude par echantillonage aleatoire
539 if ( self.DictMCVal.has_key( 'PointsNumber' ) ):
540 size = self.DictMCVal[ 'PointsNumber' ]
542 txt = "# Echantillonnage aleatoire de la variable de sortie\n"
543 txt += "%s = %d\n" % (self.variable["inSize"], size)
544 txt += "%s = %s.getNumericalSample( %s )\n" % (self.variable["outputSample"], self.variable["outputRandomVector"], self.variable["inSize"])
547 if ( self.DictMCVal.has_key( 'EmpiricalMean' ) ):
548 if ( self.DictMCVal[ 'EmpiricalMean' ] == "yes" ):
549 txt += "%s = %s.computeMean()\n" % (self.variable["empiricalMean"], self.variable["outputSample"])
550 txt += "print '%s =', %s\n" % (self.variable["empiricalMean"], self.variable["empiricalMean"])
553 if ( self.DictMCVal.has_key( 'EmpiricalStandardDeviation' ) ):
554 if ( self.DictMCVal[ 'EmpiricalStandardDeviation' ] == "yes" ):
555 txt += "%s = %s.computeCovariance()\n" % (self.variable["empiricalStandardDeviation"], self.variable["outputSample"])
556 txt += "dim = %s.getDimension()\n" % self.variable["empiricalStandardDeviation"]
557 txt += "for i in range( dim ):\n"
558 txt += " %s[ i, i ] = math.sqrt( %s[ i, i ] )\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
559 txt += "print '%s = ', %s\n" % (self.variable["empiricalStandardDeviation"], self.variable["empiricalStandardDeviation"])
562 if ( self.DictMCVal.has_key( 'EmpiricalQuantile_Order' ) ):
563 ordre = self.DictMCVal[ 'EmpiricalQuantile_Order' ]
564 txt += "%s = %s.computeQuantile( %s )\n" % (self.variable["empiricalQuantile"], self.variable["outputSample"], ordre)
565 txt += "print '%s =', %s\n" % (self.variable["empiricalQuantile"], self.variable["empiricalQuantile"])
568 if ( self.DictMCVal.has_key( 'AnalysedCorrelations' ) ):
569 if ( self.DictMCVal[ 'AnalysedCorrelations' ] == "yes" ):
570 txt += "# Ou est le %s ?\n" % self.variable["inputSample"]
571 txt += "#if ( ( %s.getDimension() == 1 ) and ( %s.getDimension() == 1 ) ):\n" % (self.variable["inputSample"], self.variable["outputSample"])
572 txt += "# %s = CorrelationAnalysis.PCC( %s, %s )\n" % (self.variable["PCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
573 txt += "# print '%s = ', %s\n" % (self.variable["PCCcoefficient"], self.variable["PCCcoefficient"])
574 txt += "# %s = CorrelationAnalysis.PRCC( %s, %s )\n" % (self.variable["PRCCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
575 txt += "# print '%s = ', %s\n" % (self.variable["PRCCcoefficient"], self.variable["PRCCcoefficient"])
576 txt += "# %s = CorrelationAnalysis.SRC( %s, %s )\n" % (self.variable["SRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
577 txt += "# print '%s = ', %s\n" % (self.variable["SRCcoefficient"], self.variable["SRCcoefficient"])
578 txt += "# %s = CorrelationAnalysis.SRRC( %s, %s )\n" % (self.variable["SRRCcoefficient"], self.variable["inputSample"], self.variable["outputSample"])
579 txt += "# print '%s = ', %s\n" % (self.variable["SRRCcoefficient"], self.variable["SRRCcoefficient"])
582 if ( self.DictMCVal.has_key( 'KernelSmoothing' ) ):
583 if ( self.DictMCVal[ 'KernelSmoothing' ] == "yes" ):
584 txt += "# Kernel Smoohing\n"
585 txt += "%s = KernelSmoothing()\n" % self.variable["kernel"]
586 txt += "if ( %s.getDimension() == 1 ):\n" % self.variable["outputSample"]
587 txt += " %s = %s.buildImplementation( %s, 'TRUE')\n" % (self.variable["kernelSmoothedDist"], self.variable["kernel"], self.variable["outputSample"])
588 txt += " %s = %s.drawPDF()\n" % (self.variable["kernelSmoothedPDF"], self.variable["kernelSmoothedDist"])
589 txt += " Show( %s )\n" % self.variable["kernelSmoothedPDF"]
594 def ThresholdExceedence (self, subDict):
596 Produit le fichier study correspondant a une analyse de depassement de seuil
599 txt += "# Etude 'Threshold Exceedence'\n"
601 txt += self.RandomGenerator()
603 txt += self.InputDistribution()
604 txt += self.InputRandomVector()
605 txt += self.OutputRandomVector()
609 if ( self.DictMCVal.has_key( 'Method' ) ):
610 Methode = self.DictMCVal[ 'Method' ]
613 if ( subDict.has_key( Methode ) ):
614 Traitement = subDict[ Methode ]
616 if ( Traitement is not None ):
617 txt += apply( STDGenerateur.__dict__[ Traitement ], (self, subDict) )
622 def Simulation (self, subDict):
624 Methodes de simulation
627 if ( self.DictMCVal.has_key( 'Algorithm' ) ):
628 Algorithme = self.DictMCVal[ 'Algorithm' ]
631 if ( subDict.has_key( Algorithme ) ):
632 Traitement = subDict[ Algorithme ]
634 if ( Traitement is not None ):
635 txt = apply( STDGenerateur.__dict__[ Traitement ], (self,) )
637 maxOuterSampling = None
638 if ( self.DictMCVal.has_key( 'MaximumOuterSampling' ) ):
639 maxOuterSampling = self.DictMCVal[ 'MaximumOuterSampling' ]
640 txt += "%s.setMaximumOuterSampling( %s )\n" % (self.variable["myAlgo"], maxOuterSampling)
643 if ( self.DictMCVal.has_key( 'BlockSize' ) ):
644 maxOuterSampling = self.DictMCVal[ 'BlockSize' ]
645 txt += "%s.setBlockSize( %s )\n" % (self.variable["myAlgo"], blockSize)
647 maxCoefficientOfVariation = None
648 if ( self.DictMCVal.has_key( 'MaximumCoefficientOfVariation' ) ):
649 maxCoefficientOfVariation = self.DictMCVal[ 'MaximumCoefficientOfVariation' ]
650 txt += "%s.setMaximumCoefficientOfVariation( %s )\n" % (self.variable["myAlgo"], maxCoefficientOfVariation)
652 txt += "%s.run()\n" % self.variable["myAlgo"]
654 txt += "# Resultats de la simulation\n"
655 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
658 if ( self.DictMCVal.has_key( 'Probability' ) ):
659 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
660 txt += "%s = %s.getProbabilityEstimate()\n" % (self.variable["probability"], self.variable["myResult"])
661 txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
664 if ( self.DictMCVal.has_key( 'StandardDeviation' ) ):
665 if ( self.DictMCVal[ 'StandardDeviation' ] == "yes" ):
666 txt += "%s = math.sqrt( %s.getProbabilityEstimate() )\n" % (self.variable["standardDeviation"], self.variable["myResult"])
667 txt += "print '%s =', %s\n" % (self.variable["standardDeviation"], self.variable["standardDeviation"])
670 if ( self.DictMCVal.has_key( 'ConfidenceInterval' ) and self.DictMCVal.has_key( 'Probability' ) ):
671 if ( ( self.DictMCVal[ 'ConfidenceInterval' ] == "yes" ) and ( self.DictMCVal[ 'Probability' ] == "yes" ) ):
672 level = self.DictMCVal[ 'Level' ]
673 txt += "%s = %s.getConfidenceLength( %s )\n" % (self.variable["length"], self.variable["myResult"], level)
674 txt += "print 'confidence interval at %s = [', %s-0.5*%s, ',', %s+0.5*%s, ']'\n" % (level, self.variable["probability"], self.variable["length"], self.variable["probability"], self.variable["length"])
677 if ( self.DictMCVal.has_key( 'VariationCoefficient' ) ):
678 if ( self.DictMCVal[ 'VariationCoefficient' ] == "yes" ):
679 txt += "%s = %s.getCoefficientOfVariation()\n" % (self.variable["coefficientOfVariation"], self.variable["myResult"])
680 txt += "print '%s =', %s\n" % (self.variable["coefficientOfVariation"], self.variable["coefficientOfVariation"])
683 if ( self.DictMCVal.has_key( 'IterationNumber' ) ):
684 if ( self.DictMCVal[ 'IterationNumber' ] == "yes" ):
685 txt += "%s = %s.getOuterSampling()\n" % (self.variable["iterations"], self.variable["myResult"])
686 txt += "print '%s =', %s\n" % (self.variable["iterations"], self.variable["iterations"])
689 if ( self.DictMCVal.has_key( 'ConvergenceGraph' ) ):
690 if ( self.DictMCVal[ 'ConvergenceGraph' ] == "yes" ):
691 txt += "%s = %s.drawProbabilityConvergence()\n" % (self.variable["convergenceGraph"], self.variable["myAlgo"])
692 txt += "Show( %s )\n" % self.variable["convergenceGraph"]
697 def Analytical (self, subDict):
703 OptimizationAlgo = None
704 if ( self.DictMCVal.has_key( 'OptimizationAlgorithm' ) ):
705 OptimizationAlgo = self.DictMCVal[ 'OptimizationAlgorithm' ]
708 if ( subDict.has_key( OptimizationAlgo ) ):
709 Traitement = subDict[ OptimizationAlgo ]
711 if ( Traitement is not None ):
712 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
714 txt += self.OptimizerSettings()
715 txt += self.PhysicalStartingPoint()
718 if ( self.DictMCVal.has_key( 'Approximation' ) ):
719 Approximation = self.DictMCVal[ 'Approximation' ]
722 if ( subDict.has_key( Approximation ) ):
723 Traitement = subDict[ Approximation ]
725 if ( Traitement is not None ):
726 txt += apply( STDGenerateur.__dict__[ Traitement ], (self,) )
728 txt += self.RunAlgorithm()
729 txt += self.AnalyticalResult()
733 def OptimizerSettings (self):
735 Parametrage de l optimiseur
740 if ( self.DictMCVal.has_key( 'MaximumIterationsNumber' ) ):
741 iterations = self.DictMCVal[ 'MaximumIterationsNumber' ]
742 txt += "%s.setMaximumIterationsNumber( %s )\n" % (self.variable["myOptimizer"], iterations)
745 if ( self.DictMCVal.has_key( 'MaximumAbsoluteError' ) ):
746 absoluteError = self.DictMCVal[ 'MaximumAbsoluteError' ]
747 txt += "%s.setMaximumAbsoluteError( %s )\n" % (self.variable["myOptimizer"], absoluteError)
750 if ( self.DictMCVal.has_key( 'MaximumRelativeError' ) ):
751 relativeError = self.DictMCVal[ 'MaximumRelativeError' ]
752 txt += "%s.setMaximumRelativeError( %s )\n" % (self.variable["myOptimizer"], relativeError)
755 if ( self.DictMCVal.has_key( 'MaximumResidualError' ) ):
756 residualError = self.DictMCVal[ 'MaximumResidualError' ]
757 txt += "%s.setMaximumResidualError( %s )\n" % (self.variable["myOptimizer"], residualError)
759 constraintError = None
760 if ( self.DictMCVal.has_key( 'MaximumConstraintError' ) ):
761 constraintError = self.DictMCVal[ 'MaximumConstraintError' ]
762 txt += "%s.setMaximumConstraintError( %s )\n" % (self.variable["myOptimizer"], constraintError)
768 def PhysicalStartingPoint (self):
770 Point physique de depart
772 txt = "# Point physique de depart\n"
774 if ( self.DictMCVal.has_key( 'PhysicalStartingPoint' ) ):
775 point = self.DictMCVal[ 'PhysicalStartingPoint' ]
776 dimension = len( point )
777 txt += "%s = NumericalPoint( %d )\n" % (self.variable["startingPoint"], dimension)
778 for i in range( dimension ):
779 txt += "%s[ %d ] = %g\n" % (self.variable["startingPoint"], i, point[i])
781 txt += "%s = %s.getMean()\n" % (self.variable["startingPoint"], self.variable["inputRandomVector"])
787 def AnalyticalResult (self):
789 Resultat des methodes analytiques
791 txt = "# Resultat des methodes analytiques\n"
792 txt += "%s = %s.getResult()\n" % (self.variable["myResult"], self.variable["myAlgo"])
794 if ( self.DictMCVal.has_key( 'Probability' ) ):
795 if ( self.DictMCVal[ 'Probability' ] == "yes" ):
796 txt += "%s = %s.getEventProbability()\n" % (self.variable["probability"], self.variable["myResult"])
797 txt += "print '%s =', %s\n" % (self.variable["probability"], self.variable["probability"])
800 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndex' ) ):
801 if ( self.DictMCVal[ 'HasoferReliabilityIndex' ] == "yes" ):
802 txt += "%s = %s.getHasoferReliabilityIndex()\n" % (self.variable["hasoferReliabilityIndex"], self.variable["myResult"])
803 txt += "print '%s =', %s\n" % (self.variable["hasoferReliabilityIndex"], self.variable["hasoferReliabilityIndex"])
806 if ( self.DictMCVal.has_key( 'DesignPoint' ) ):
807 if ( self.DictMCVal[ 'DesignPoint' ] == "yes" ):
808 txt += "%s = %s.getStandardSpaceDesignPoint()\n" % (self.variable["standardSpaceDesignPoint"], self.variable["myResult"])
809 txt += "print '%s =', %s\n" % (self.variable["standardSpaceDesignPoint"], self.variable["standardSpaceDesignPoint"])
810 txt += "%s = %s.getPhysicalSpaceDesignPoint()\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["myResult"])
811 txt += "print '%s =', %s\n" % (self.variable["physicalSpaceDesignPoint"], self.variable["physicalSpaceDesignPoint"])
814 if ( self.DictMCVal.has_key( 'ImportanceFactorNumericalResults' ) ):
815 if ( self.DictMCVal[ 'ImportanceFactorNumericalResults' ] == "yes" ):
816 txt += "%s = %s.getImportanceFactors()\n" % (self.variable["importanceFactors"], self.variable["myResult"])
817 txt += "print '%s =', %s\n" % (self.variable["importanceFactors"], self.variable["importanceFactors"])
820 if ( self.DictMCVal.has_key( 'ImportanceFactorGraphicalResults' ) ):
821 if ( self.DictMCVal[ 'ImportanceFactorGraphicalResults' ] == "yes" ):
822 txt += "%s = %s.drawImportanceFactors()\n" % (self.variable["importanceFactorsGraph"], self.variable["myResult"])
823 txt += "Show( %s )\n" % self.variable["importanceFactorsGraph"]
826 if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivityNumericalResults' ) ):
827 if ( self.DictMCVal[ 'FORMEventProbabilitySensitivityNumericalResults' ] == "yes" ):
828 txt += "%s = %s.getEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivity"], self.variable["myResult"])
829 txt += "print '%s =', %s\n" % (self.variable["eventProbabilitySensitivity"], self.variable["eventProbabilitySensitivity"])
832 if ( self.DictMCVal.has_key( 'FORMEventProbabilitySensitivityGraphicalResults' ) ):
833 if ( self.DictMCVal[ 'FORMEventProbabilitySensitivityGraphicalResults' ] == "yes" ):
834 txt += "%s = %s.drawEventProbabilitySensitivity()\n" % (self.variable["eventProbabilitySensitivityGraph"], self.variable["myResult"])
835 txt += "Show( %s[0] )\n" % self.variable["eventProbabilitySensitivityGraph"]
838 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivityNumericalResults' ) ):
839 if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivityNumericalResults' ] == "yes" ):
840 txt += "%s = %s.getHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["myResult"])
841 txt += "print '%s =', %s\n" % (self.variable["hasoferReliabilityIndexSensitivity"], self.variable["hasoferReliabilityIndexSensitivity"])
844 if ( self.DictMCVal.has_key( 'HasoferReliabilityIndexSensitivityGraphicalResults' ) ):
845 if ( self.DictMCVal[ 'HasoferReliabilityIndexSensitivityGraphicalResults' ] == "yes" ):
846 txt += "%s = %s.drawHasoferReliabilityIndexSensitivity()\n" % (self.variable["hasoferReliabilityIndexSensitivityGraph"], self.variable["myResult"])
847 txt += "Show( %s[0] )\n" % self.variable["hasoferReliabilityIndexSensitivityGraph"]
850 if ( self.DictMCVal.has_key( 'TvedtApproximation' ) ):
851 if ( self.DictMCVal[ 'TvedtApproximation' ] == "yes" ):
852 txt += "%s = %s.getEventProbabilityTvedt()\n" % (self.variable["tvedtApproximation"], self.variable["myResult"])
853 txt += "print '%s =', %s\n" % (self.variable["tvedtApproximation"], self.variable["tvedtApproximation"])
856 if ( self.DictMCVal.has_key( 'HohenBichlerApproximation' ) ):
857 if ( self.DictMCVal[ 'HohenBichlerApproximation' ] == "yes" ):
858 txt += "%s = %s.getEventProbabilityHohenBichler()\n" % (self.variable["hohenBichlerApproximation"], self.variable["myResult"])
859 txt += "print '%s =', %s\n" % (self.variable["hohenBichlerApproximation"], self.variable["tvedtApproximation"])
862 if ( self.DictMCVal.has_key( 'BreitungApproximation' ) ):
863 if ( self.DictMCVal[ 'BreitungApproximation' ] == "yes" ):
864 txt += "%s = %s.getEventProbabilityBreitung()\n" % (self.variable["breitungApproximation"], self.variable["myResult"])
865 txt += "print '%s =', %s\n" % (self.variable["breitungApproximation"], self.variable["breitungApproximation"])
871 def RandomGenerator (self):
878 if ( self.DictMCVal.has_key( 'RandomGeneratorSeed' ) ):
879 seed = self.DictMCVal[ 'RandomGeneratorSeed' ]
880 txt += "# Initialise le generateur aleatoire\n"
881 txt += "RandomGenerator.SetSeed( %s )\n" % seed
888 Definition de l evenement de defaillance
891 if ( self.DictMCVal.has_key( 'ComparisonOperator' ) ):
892 operator = self.DictMCVal[ 'ComparisonOperator' ]
895 if ( self.DictMCVal.has_key( 'Threshold' ) ):
896 threshold = self.DictMCVal[ 'Threshold' ]
898 txt = "# Evenement de defaillance\n"
899 txt += "%s = Event( %s, ComparisonOperator( %s() ), %s )\n" % (self.variable["myEvent"], self.variable["outputRandomVector"], operator, threshold)
903 def MonteCarlo (self):
905 Methode de MonteCarlo
907 txt = "# Simulation par MonteCarlo\n"
908 txt += "%s = MonteCarlo( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
917 txt = "# Simulation par LHS\n"
918 txt += "%s = LHS( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
923 def ImportanceSampling (self):
925 Methode de tirage d importance
927 txt = "# Simulation par Tirage d'importance\n"
928 txt += "%s = ImportanceSampling( %s )\n" % (self.variable["myAlgo"], self.variable["myEvent"])
937 txt = "# Algorithme FORM\n"
938 txt += "%s = FORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
947 txt = "# Algorithme SORM\n"
948 txt += "%s = SORM ( NearestPointAlgorithm( %s ), %s, %s )\n" % (self.variable["myAlgo"], self.variable["myOptimizer"], self.variable["myEvent"], self.variable["startingPoint"])
953 def RunAlgorithm (self):
957 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
958 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
959 txt = "%s = %s.getEvaluationCallsNumber()\n" % (self.variable["modelEvaluationCalls"], self.variable["model"])
960 txt += "%s = %s.getGradientCallsNumber()\n" % (self.variable["modelGradientCalls"], self.variable["model"])
961 txt += "%s = %s.getHessianCallsNumber()\n" % (self.variable["modelHessianCalls"], self.variable["model"])
964 txt += "# Perform the computation\n"
965 txt += "%s.run()\n" % self.variable["myAlgo"]
969 if ( self.DictMCVal.has_key( 'FunctionCallsNumber' ) ):
970 if ( self.DictMCVal[ 'FunctionCallsNumber' ] == "yes" ):
971 txt += "%s = %s.getEvaluationCallsNumber() - %s\n" % (self.variable["modelEvaluationCalls"], self.variable["model"], self.variable["modelEvaluationCalls"])
972 txt += "%s = %s.getGradientCallsNumber() - %s\n" % (self.variable["modelGradientCalls"], self.variable["model"], self.variable["modelGradientCalls"])
973 txt += "%s = %s.getHessianCallsNumber() - %s\n" % (self.variable["modelHessianCalls"], self.variable["model"], self.variable["modelHessianCalls"])
975 txt += "print '%s =', %s\n" % (self.variable["modelEvaluationCalls"], self.variable["modelEvaluationCalls"])
976 txt += "print '%s =', %s\n" % (self.variable["modelGradientCalls"], self.variable["modelGradientCalls"])
977 txt += "print '%s =', %s\n" % (self.variable["modelHessianCalls"], self.variable["modelHessianCalls"])
986 txt = "# Optimisation par Cobyla\n"
987 txt += "%s = Cobyla()\n" % self.variable["myOptimizer"]
988 txt += "#%s = CobylaSpecificParameters()\n" % self.variable["specificParameters"]
989 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
994 def AbdoRackwitz (self):
998 txt = "# Optimisation par AbdoRackwitz\n"
999 txt += "%s = AbdoRackwitz()\n" % self.variable["myOptimizer"]
1000 txt += "#%s = AbdoRackwitzSpecificParameters()\n" % self.variable["specificParameters"]
1001 txt += "#%s.setSpecificParameters( %s )\n" % (self.variable["myOptimizer"], self.variable["specificParameters"])
1005 def Beta (self, loi, i, collection):
1007 Definition de la loi Beta
1011 "MuSigma" : "Beta.MUSIGMA",
1013 if loi[ 'Settings' ] == 'RT' :
1018 arg2 = loi[ 'Sigma' ]
1022 txt = "Beta( %g, %g, %g, %g, %s )" % (arg1, arg2, arg3, arg4, settings[ loi[ 'Settings' ] ])
1025 def Exponential (self, loi, i, collection):
1027 Definition de la loi Exponential
1029 arg1 = loi[ 'Lambda' ]
1030 arg2 = loi[ 'Gamma' ]
1031 txt = "Exponential( %g, %g )" % (arg1, arg2)
1034 def Gamma (self, loi, i, collection):
1036 Definition de la loi Gamma
1039 "KLambda" : "Gamma.KLAMBDA",
1040 "MuSigma" : "Gamma.MUSIGMA",
1042 if loi[ 'Settings' ] == 'KLambda' :
1044 arg2 = loi[ 'Lambda' ]
1047 arg2 = loi[ 'Sigma' ]
1049 arg3 = loi[ 'Gamma' ]
1050 txt = "Gamma( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1053 def Geometric (self, loi, i, collection):
1055 Definition de la loi Geometric
1057 txt = "Geometric( %g )" % loi[ 'P' ]
1060 def Gumbel (self, loi, i, collection):
1062 Definition de la loi Gumbel
1065 "AlphaBeta" : "Gamma.ALPHABETA",
1066 "MuSigma" : "Gamma.MUSIGMA",
1068 if loi[ 'Settings' ] == 'AlphaBeta' :
1069 arg1 = loi[ 'Alpha' ]
1070 arg2 = loi[ 'Beta' ]
1073 arg2 = loi[ 'Sigma' ]
1075 txt = "Gamma( %g, %g, %s )" % (arg1, arg2, settings[ loi[ 'Settings' ] ])
1078 def Histogram (self, loi, i, collection):
1080 Definition de la loi Histogram
1082 arg1 = loi[ 'First' ]
1083 arg2 = loi[ 'Values' ]
1084 txt = "Histogram( %g, %s )" % (arg1, arg2)
1087 def Logistic (self, loi, i, collection):
1089 Definition de la loi Logistic
1091 arg1 = loi[ 'Alpha' ]
1092 arg2 = loi[ 'Beta' ]
1093 txt = "Logistic( %g, %g )" % (arg1, arg2)
1096 def LogNormal (self, loi, i, collection):
1098 Definition de la loi LogNormal
1101 "MuSigmaLog" : "LogNormal.MUSIGMA_LOG",
1102 "MuSigma" : "LogNormal.MUSIGMA",
1103 "MuSigmaOverMu" : "LogNormal.MU_SIGMAOVERMU",
1105 if loi[ 'Settings' ] == 'MuSigmaLog' :
1106 arg1 = loi[ 'MuLog' ]
1107 arg2 = loi[ 'SigmaLog' ]
1108 elif loi[ 'Settings' ] == 'MuSigmaOverMu' :
1110 arg2 = loi[ 'SigmaOverMu' ]
1113 arg2 = loi[ 'Sigma' ]
1115 arg3 = loi[ 'Gamma' ]
1116 txt = "LogNormal( %g, %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])
1119 def MultiNomial (self, loi, i, collection):
1121 Definition de la loi MultiNomial
1123 arg1 = loi[ 'Values' ]
1125 txt = "MultiNomial( NumericalPoint( %s ) , %d)" % (arg1, arg2)
1128 def Normal (self, loi, i, collection):
1130 Definition de la loi Normal
1133 arg2 = loi[ 'Sigma' ]
1134 txt = "Normal( %g, %g )" % (arg1, arg2)
1137 def TruncatedNormal (self, loi, i, collection):
1139 Definition de la loi TruncatedNormal
1142 arg2 = loi[ 'SigmaN' ]
1145 txt = "TruncatedNormal( %g, %g, %g, %g )" % (arg1, arg2, arg3, arg4)
1148 def Poisson (self, loi, i, collection):
1150 Definition de la loi
1152 txt = "Poisson( %g )" % loi[ 'Lambda' ]
1155 def Student (self, loi, i, collection):
1157 Definition de la loi Student
1161 txt = "Student( %g, %g )" % (arg1, arg2)
1164 def Triangular (self, loi, i, collection):
1166 Definition de la loi Triangular
1171 txt = "Triangular( %g, %g, %g )" % (arg1, arg2, arg3)
1174 def Uniform (self, loi, i, collection):
1176 Definition de la loi Uniform
1180 txt = "Uniform( %g, %g )" % (arg1, arg2)
1183 def UserDefined (self, loi, i, collection):
1185 Definition de la loi UserDefined
1187 txt = "** UserDefined not defined yet **"
1190 def Weibull (self, loi, i, collection):
1192 Definition de la loi Weibull
1195 "AlphaBeta" : "Weibull.ALPHABETA",
1196 "MuSigma" : "Weibull.MUSIGMA",
1198 if loi[ 'Settings' ] == 'AlphaBeta' :
1199 arg1 = loi[ 'Alpha' ]
1200 arg2 = loi[ 'Beta' ]
1203 arg2 = loi[ 'Sigma' ]
1205 arg3 = loi[ 'Gamma' ]
1206 txt = "Weibull( %g, %g, %s )" % (arg1, arg2, arg3, settings[ loi[ 'Settings' ] ])