From 75f8158566e82e29a6a804994adeb157ecbb97a2 Mon Sep 17 00:00:00 2001 From: Eric Fayolle Date: Mon, 29 Aug 2022 16:29:47 +0200 Subject: [PATCH] Ajout des options de choix de scripts de post-traitement et Execution --- ReacteurNumerique/cata_RN_UQ.py | 4 +- ReacteurNumerique/cata_UQ.py | 18 +++- generator/post_csv_rn.py | 168 ++++++++++++++++++++++++++++++++ 3 files changed, 185 insertions(+), 5 deletions(-) create mode 100644 generator/post_csv_rn.py diff --git a/ReacteurNumerique/cata_RN_UQ.py b/ReacteurNumerique/cata_RN_UQ.py index 7a3a2159..c6a024b3 100644 --- a/ReacteurNumerique/cata_RN_UQ.py +++ b/ReacteurNumerique/cata_RN_UQ.py @@ -26,10 +26,12 @@ dictUQ = {'initial_power' : ({'Uniform' : {}}, {'TruncatedNormal' : {}}, {'UserD listeDesSortiesNeutro = ( "Boron concentration", "Kinetic reactivity", "Neutronic power", ) listeDesSortiesThermo = ("Average mass flux", "Boiling power fraction", "Enthalpy", "Fuel temperature", "Liquid power", "Mass flux", "Mass fraction", "Mass title", "Mixture density", "Mixture specific enthalpy", "Mixture temperature", "Outlet pressure", "Pollutant concentration", "Pressure ", "Rowlands fuel effective temp", "Thermal power", "Water density", "Water temperature", ) +scriptPosttraitement = os.path.join(repEficas,"generator","post_csv_rn.py") +scriptDeLancement = os.path.join(repInitial,"ib_test.sh") dicoDesSortiesPossibles={'Neutronics':listeDesSortiesNeutro,'Thermalhydraulics':listeDesSortiesThermo} #dicoDesSortiesPossibles={'Thermalhydraulics':listeDesSortiesThermo} from cata_UQ import creeOperExpressionIncertitude -ExpressionIncertitude=creeOperExpressionIncertitude(dictUQ, dicoDesSortiesPossibles) +ExpressionIncertitude=creeOperExpressionIncertitude(dictUQ, dicoDesSortiesPossibles, scriptPosttraitement, scriptDeLancement) #autonome=1 diff --git a/ReacteurNumerique/cata_UQ.py b/ReacteurNumerique/cata_UQ.py index c739c811..9ef64ae8 100644 --- a/ReacteurNumerique/cata_UQ.py +++ b/ReacteurNumerique/cata_UQ.py @@ -1365,7 +1365,7 @@ def changeIntoOuput(objPostPro): maDef.addInto(nomAProposer) -def creeOutput(monDicoVarSortie): +def creeOutput(monDicoVarSortie,scriptPosttraitement): intoVariable=list(monDicoVarSortie.keys()) lesBlocs={} Physique = SIMP (statut = "o", typ = "TXM",into = intoVariable,defaut=intoVariable[0]) @@ -1385,11 +1385,16 @@ def creeOutput(monDicoVarSortie): lesBlocs[nomBloc] = BLOC (condition=laCondition, VariablePhysique = VariablePhysique, **lesBlocsVar) FonctionDAggregation = SIMP(statut = 'o', typ= 'TXM', into = ('valeur à t=O', 'valeur à mi-temps', 'valeur à t final', 'valeur moyenne', 'valeur cumulée', 'valeur minimale', 'valeur maximale' ), defaut=('Max'), max='**', homo='SansOrdreNiDoublon') - VariableDeSortie = FACT ( max='**', statut ='o', Physique=Physique, **lesBlocs, FonctionDAggregation=FonctionDAggregation, Unit=Unit,Format=Format) + ScriptPosttraitement=SIMP( + fr="Nom du fichier Script de Postraitement", + ang="Postprocessing Script File", + statut="o", + typ=("Fichier", "All Files ()", "Sauvegarde"), defaut=scriptPosttraitement) + VariableDeSortie = FACT ( max='**', statut ='o', Physique=Physique, **lesBlocs, FonctionDAggregation=FonctionDAggregation, ScriptPosttraitement=ScriptPosttraitement, Unit=Unit,Format=Format) output = FACT (max=1, statut ='o', VariableDeSortie=VariableDeSortie) return output -def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie): +def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie,scriptPosttraitement, scriptDeLancement ): listeDesVariablesPossibles = list(monDicoVarDeter.keys()) #monOutput = creeOutput(monDicoVarSortie) objectName = SIMP ( statut = "f", typ = 'TXM', into=[], fenetreIhm='menuDeroulant', homo='constant' ) # on ne met pas [] pour la projection XSD, intoXML=? @@ -1495,7 +1500,7 @@ def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie): Methode = SIMP( statut = "o", typ = "TXM", max=1, into = ('SRS', 'Sobol'), defaut='Sobol'), ), # fin UraniePropagation ), # fin Propagation - Output=creeOutput(monDicoVarSortie), + Output=creeOutput(monDicoVarSortie,scriptPosttraitement), Execution = FACT (max=1, statut ='o', bloc_OT = BLOC (condition = 'UncertaintyTool == "OpenTurns"', ExecutionMode = SIMP ( statut = "o", typ = "TXM", into = ['desktop', 'cluster']), @@ -1519,6 +1524,11 @@ def creeOperExpressionIncertitude(monDicoVarDeter, monDicoVarSortie): # ResultDirectory = SIMP ( statut = 'o', typ='Repertoire' , defaut='/tmp/idefix_rn_job'), #TODO: JobName MultiJobStudy = SIMP ( statut = "o", typ = bool, defaut=False), ), + ScriptDeLancement=SIMP( + fr="Nom du fichier script de lancement", + ang="script File to launch", + statut="o", + typ=("Fichier", "All Files ()", "Sauvegarde"), defaut=scriptDeLancement) ), bloc_Uranie = BLOC (condition = 'UncertaintyTool == "Uranie"', DOEDimensions = SIMP ( statut = "o", typ = "I"), diff --git a/generator/post_csv_rn.py b/generator/post_csv_rn.py new file mode 100644 index 00000000..057e6386 --- /dev/null +++ b/generator/post_csv_rn.py @@ -0,0 +1,168 @@ +# Exemple de script pour lire la sortie csv du banc +# +# Lecture des valeurs dans le csv et renvoi de la valeur après application de la fonction d'agragation max,min et moy + +#To get the history in python +#print('\n'.join([str(readline.get_history_item(i + 1)) for i in range(readline.get_current_history_length())])) + +def vMax(arrayNx2): + import numpy as np + + return np.apply_along_axis(max, 0, arrayNx2[:,1]).item() + +def vMin(arrayNx2): + import numpy as np + + return np.apply_along_axis(min, 0, arrayNx2[:,1]).item() + +def vMean(arrayNx2): + import numpy as np + import statistics + + return np.apply_along_axis(statistics.mean, 0, arrayNx2[:,1]).item() + +def vSum(arrayNx2): + import numpy as np + + return np.apply_along_axis(sum, 0, arrayNx2[:,1]).item() + +def vInitialTime(arrayNx2): + import numpy as np + + #Dates on first column, Values on second one + timeColumn= arrayNx2[:,0] + # Tmin=np.apply_along_axis(min, 0, timeColumn) + # assert(arrayNx2[0,0]==Tmin) + idxTmin = timeColumn.argmin() + assert(idxTmin==0) + + valTmin= arrayNx2[idxTmin][1].item() + + return valTmin + +def vFinalTime(arrayNx2): + import numpy as np + + #Dates on first column, Values on second one + timeColumn= arrayNx2[:,0] + # Tmax=np.apply_along_axis(max, 0, timeColumn) + # assert(arrayNx2[timeColumn.size,0]==Tmax) + idxTmax = timeColumn.argmax() + idxMax=timeColumn.size-1 + assert(idxTmax==idxMax) + + valTmax= arrayNx2[idxTmax][1].item() + + return valTmax + +def vHalfTime(arrayNx2): + import numpy as np + + #Dates on first column, Values on second one + timeColumn= arrayNx2[:,0] + Tmin=np.apply_along_axis(min, 0, timeColumn) + Tmax=np.apply_along_axis(max, 0, timeColumn) + + Thalf=(Tmax-Tmin)/2+Tmin + idxThalf = (np.abs(timeColumn-Thalf)).argmin() + valThalf= arrayNx2[idxThalf][1].item() + + return valThalf + +def get_result_from_csv(variableName:str, functionList, filename:str=None, delimiter=','): + from csv import reader + import numpy as np + + transientName = 'Transient duration' + + #ex: file_csv = "Fuel temperature@Thermalhydraulics@MAX.csv" + if filename == None: filename = variableName+'.csv' + + with open(filename, "r") as csv_file: + csv_reader = reader(csv_file, delimiter=delimiter) + header = next(csv_reader) + header_transient_name=header[1] + header_variable_name=header[2] + if header_variable_name != variableName: + print(sys.stderr,"The variable name {} differs from the file's header one {}".format(variableName, header_variable_name)) + return -1 #TODO Exception ? + if header_transient_name != transientName: + print(sys.stderr,"The transient duration name {} differs from the file's header one {}".format(transientName, header_transient_name)) + return -1 #TODO Exception ? + + date_value_array=np.loadtxt(file_csv, delimiter = delimiter, skiprows = 1)[:,1:3] + valList=[] + for func in functionList: + valList.append(func(date_value_array)) + return valList + +def get_result_from_csv_v0(variableName:str, function, filename:str=None, delimiter=','): + from csv import reader + + #ex: file_csv = "Fuel temperature@Thermalhydraulics@MAX.csv" + if filename == None: filename = variableName+'.csv' + + with open(filename, "r") as csv_file: + csv_reader = reader(csv_file, delimiter=delimiter) + header = next(csv_reader) + header_variable_name=header[-1] + if header_variable_name != variableName: + print(sys.stderr,"The variable name {} differs from the file's header one {}".format(variableName, header_variable_name)) + return -1 #TODO Exception ? + # print("Header:") + # print(", ".join(header)) + # print("Values:") + # for row in csv_reader: + # print(", ".join(row)) + return function(csv_reader)[-1] + +# import csv + +# #fich_csv = "Execution_APOLLO3/Neutronic power@Neutronics@SUM.csv" +# fich_csv = "Fuel temperature@Thermalhydraulics@MAX.csv" +# file_csv = open(fich_csv) + +# fich_sort = 'point.res' + +# csvReader = csv.reader(file_csv, delimiter=',') +# header = [] +# header = next(csvReader) +# # Pour APOLLO3 ? +# # if len(header) != 2: +# # print("Correction des headers contenant des espaces") +# # tmp = header +# # header = [] +# # header.append(tmp[1]) +# # header.append(tmp[-2] + " " + tmp[-1]) +# print(header) + +# rows = [] +# for row in csvReader: +# ligne = [] +# for elem in row: +# if elem != '': +# ligne.append(float(elem)) +# rows.append(ligne) +# #print(ligne) +# print(rows) + +# # reperage des valeurs min et max +# point_min = rows[0] +# point_max = rows[0] +# for point in rows: +# if point[2] < point_min[2]: +# point_min = point +# if point[2] > point_max[2]: +# point_max = point + +# # impression dans un fichier res de sortie +# print("point min") +# print(point_min) +# print("point max") +# print(point_max) + +# txt = "# time_min min time_max max\n" +# txt += "{0} {1} {2} {3}".format(point_min[0],point_min[1],point_max[0],point_max[1]) + +# file_sort = open(fich_sort,'w') +# file_sort.write(txt) -- 2.39.2