From a452a8fa81b7caaa72fe8d1fde50707813bc585c Mon Sep 17 00:00:00 2001 From: Eric Fayolle Date: Tue, 5 Jul 2022 11:52:03 +0200 Subject: [PATCH] =?utf8?q?Gestion=20des=20fonctions=20dagr=C3=A9gation=20m?= =?utf8?q?ultiples?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- ReacteurNumerique/cata_UQ.py | 3 +- generator/generator_UQ.py | 63 ++++++++++++++++++++---------------- generator/textePersalys.py | 13 +++----- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/ReacteurNumerique/cata_UQ.py b/ReacteurNumerique/cata_UQ.py index b470e90d..70f8604d 100644 --- a/ReacteurNumerique/cata_UQ.py +++ b/ReacteurNumerique/cata_UQ.py @@ -1297,6 +1297,7 @@ def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie): # l ordre des motclefs en 3.7 a l air de dépendre de l ordre de creation des objets # et non d un dict ordonné. on retombe toujours sur ce pb return PROC ( nom = "ExpressionIncertitude", UIinfo={"groupes":("CACHE",)}, op_init=definitIntoOuput, + UncertaintyTool = SIMP ( statut = "o", typ = "TXM", into = ['Uranie', 'OpenTurns'], defaut='Uranie',position='global'), Input = FACT( max=1, statut ='o', VariableProbabiliste = FACT ( max='**', statut ='cache', fr = "Variable probabiliste", @@ -1309,7 +1310,7 @@ def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie): ), ), Propagation = FACT( max=1, statut ='o', - UncertaintyTool = SIMP ( statut = "o", typ = "TXM", into = ['Uranie', 'OpenTurns'], defaut='Uranie',position='global'), + #UncertaintyTool = SIMP ( statut = "o", typ = "TXM", into = ['Uranie', 'OpenTurns'], defaut='Uranie',position='global'), Propagation_OT = BLOC( condition = "UncertaintyTool == 'OpenTurns'", Methode = SIMP( statut = "o", typ = "TXM", max=1, into = ('Taylor', 'MonteCarlo'), defaut='Taylor'), BlocMonteCarlo1 = BLOC ( condition = "Methode == 'MonteCarlo'", diff --git a/generator/generator_UQ.py b/generator/generator_UQ.py index 0c457e1c..87356ef2 100644 --- a/generator/generator_UQ.py +++ b/generator/generator_UQ.py @@ -35,7 +35,7 @@ import Accas from .generator_python import PythonGenerator from .textePersalys import headerScriptPersalys, fonctionPersalys, etudeScript, codePersalys from .textePersalys import mainPersalys, inputHeaderPersalys, outputHeaderPersalys -from .textePersalys import getResult +from .textePersalys import getResultCall from .textePersalys import centralTendencyTaylor, resultTaylor from .textePersalys import optionalResultTaylor, optionalPrintResultTaylor from .textePersalys import centralTendencyMC, resultMC @@ -174,30 +174,39 @@ class UQGenerator(PythonGenerator): # self.Seed = self.advancedParameter.getChildOrChildInBloc('Seed')[0] self.lesVariablesOutput = sectionOutput.getChildOrChildInBloc('VariableDeSortie') - self.variablesOutput = {} + #self.variablesOutput = {} self.chaineDesVariablesOutputEncodee='' #listeDesVariablesOutput=[] self.txtOutputVariableInitList='' - self.txtGetResults = "" + self.txtGetAllResults = "" + #TODO? from cata_UQ import FonctionDAggregationDict + fctAggPy={ + 'valeur à t=O':'vIninialTime', + 'valeur à mi-temps':'vHalfTtime', + 'valeur à t final':'vFinalTime', + 'valeur moyenne':'mean', + 'valeur cumulée':'sum', + 'valeur minimale':'min', + 'valeur maximale':'max' + } + for mc in self.lesVariablesOutput : nomVar = mc.getChildOrChildInBloc('VariablePhysique').valeur nomVarEncode = nomVar.replace(' ','__') - #listeDesVariablesOutput.append(nomVar) - self.chaineDesVariablesOutputEncodee+=nomVarEncode+ ', ' nomVarPostraite = mc.getChildOrChildInBloc('VariablePosttraiteeAssociee').valeur - ##TODO : Check [0], liste ou non de fonctions d'agrégation - fonctions = mc.getChildOrChildInBloc('FonctionDAggregation').valeur[0] - ##TODO : Gerer Mean, Med? - tmpFonctionAggregation = fonctions.lower() - self.variablesOutput [nomVar]=fonctions - tmpGetResult =getResult.format( - variablesOutput = nomVarEncode, - variablePostraitee = nomVarPostraite, - fonctionAggregation = tmpFonctionAggregation - ) - self.txtGetResults += tmpGetResult - self.txtOutputVariableInitList += self.indent1 + nomVarEncode + " = persalys.Output('"+ nomVar + "', '"+nomVar + "')\n" - print (self.variablesOutput) + nomFctAggList = mc.getChildOrChildInBloc('FonctionDAggregation').valeur + for nomFctAgg in nomFctAggList: + nomFctAggPy = fctAggPy[nomFctAgg] + nomOutput=nomVarEncode+'_'+nomFctAggPy + self.chaineDesVariablesOutputEncodee+=nomOutput+ ', ' + variablesOutputDesc = nomFctAgg+'('+nomVarPostraite+')' + tmpGetResultCall = getResultCall.format( + variableOutput = nomOutput, + variablePostraitee = nomVarPostraite, + fonctionAggregation = nomFctAggPy + ) + self.txtGetAllResults += tmpGetResultCall + self.txtOutputVariableInitList += self.indent1 + nomOutput + " = persalys.Output('"+ nomVar+' (Agg: '+nomFctAgg+')' + "', '"+variablesOutputDesc + "')\n" self.chaineDesVariablesOutputEncodee=self.chaineDesVariablesOutputEncodee[0:-2] sectionExecution = etapeIncertitude.getChildOrChildInBloc('Execution')[0] @@ -251,15 +260,15 @@ class UQGenerator(PythonGenerator): # chaineDesVariablesInput=reduce(lambda x,y:x+','+y,l) def getStrVarList(l,sep): return reduce(lambda x,y:x+sep+y, l) - def getStrInitClass(l): + def getStrInitList(l): return getStrVarList( map(lambda x:'self.{} = {}'.format(x,x),l), '\n'+2*self.indent1 ) - def getStrReplaceVar(l): + def getStrReplaceVarList(l): return getStrVarList( map(lambda x:"'@{}@': repr(self.{})".format(x,x), l), ',' ) - def getStrSelfVar(l): + def getStrSelfVarList(l): return getStrVarList( map(lambda x:'self.{}'.format(x),l), ',' ) - generatorDir = os.path.abspath(os.path.dirname(__file__)) - nomEtude = "monEtude" + generatorDir = os.path.abspath(os.path.dirname(__file__)) + nomEtude = "monEtude" #TODO if debug : print ('nomEtude : ', nomEtude, 'generatorDir :', generatorDir) self.txtScriptPersalys += headerScriptPersalys @@ -267,19 +276,19 @@ class UQGenerator(PythonGenerator): print('self.nomsDesVariablesInput :',self.nomsDesVariablesInput) self.txtScriptPersalys += etudeScript.format( chaineDesVariablesInput = self.chaineDesVariablesInput, - chaineSelfDesVariablesInput = getStrSelfVar(self.nomsDesVariablesInput), - chaineInitDesVariablesInput = getStrInitClass(self.nomsDesVariablesInput), + chaineSelfDesVariablesInput = getStrSelfVarList(self.nomsDesVariablesInput), + chaineInitDesVariablesInput = getStrInitList(self.nomsDesVariablesInput), commFileUQBalise = self.fichierUQBalise, commFileUQComm = self.fichierUQComm, nproc = self.NbOfProcs, - replaceDataList = getStrReplaceVar(self.nomsDesVariablesInput) + replaceDataList = getStrReplaceVarList(self.nomsDesVariablesInput) ) txtFonctionPersalys = fonctionPersalys.format( currentFile = self.fichierUQModule, chaineDesVariablesInput = self.chaineDesVariablesInput, - getResults = self.txtGetResults, + getAllResults = self.txtGetAllResults, chaineDesVariablesOutput = self.chaineDesVariablesOutputEncodee ) self.txtScriptPersalys += codePersalys.format( diff --git a/generator/textePersalys.py b/generator/textePersalys.py index e325450a..0e3d92cc 100644 --- a/generator/textePersalys.py +++ b/generator/textePersalys.py @@ -97,12 +97,10 @@ class Study: pass - def get_result(self): + def get_result(self,postProcessedVar, aggregationFct): from post_cvs import get_result_from_csv - import random - print('--------------------------------------- 4 ---------------------------------------') - # return self.extract_probe(2,2), self.extract_balance(2, 2) - return 1.0 +random.random() + print('--------------------------------------- 4 ---------------------------------------') + return get_result_from_csv(postProcessedVar, aggregationFct) def run_case(self): print('--------------------------------------- 5 ---------------------------------------') @@ -117,8 +115,7 @@ class Study: # /home/C65845/VIMMP/Banc_integration.newer_odysee/environment/bin/python3 /home/C65845/VIMMP/Banc_integration.newer_odysee/environment/bin/ib-run --cocagne-neutro-solver SPN --cocagne-thermo-solver THERMOMI/TRMIC -- /home/C65845/VIMMP/Banc_integration.newer_odysee/integration_bench/tests/control_rod_ejection_small_core_cathare3_cocagne.comm /home/C65845/VIMMP/Banc_integration.newer_odysee/integration_bench/tests/control_rod_ejection_small_core_cathare3_cocagne_spn_thermomi-trmic_serial - -getResult=""" {variablesOutput} = study.get_result('{variablePostraitee}', {fonctionAggregation} ) +getResultCall=""" {variableOutput} = study.get_result('{variablePostraitee}', {fonctionAggregation} ) """ #------------------------- @@ -136,7 +133,7 @@ def _exec({chaineDesVariablesInput}): study.prepare_case() study.run_case() -{getResults} +{getAllResults} return {chaineDesVariablesOutput} """ -- 2.39.2