From 3e3ff72afc0e265e86836ec8e83e6459accfd824 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Mon, 4 Apr 2011 15:53:32 +0200 Subject: [PATCH] ASTER Ok MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Il semble que la sortie soit différente selon le code direct ou adjoint. J'ai donc pris le parti de ne pas utiliser les informations sur les sorties de l'utilisateur et de tout prendre. --- configure.ac | 4 +- resources/ADAOSchemaCatalog.xml | 11 +- .../daGUI/daGuiImpl/adaoGuiManager.py | 9 +- .../daYacsIntegration/daOptimizerLoop.py | 56 ++++++--- src/daSalome/daYacsIntegration/daStudy.py | 15 ++- src/daSalome/daYacsSchemaCreator/methods.py | 17 +++ src/tests/daSalome/Makefile.am | 13 +- src/tests/daSalome/test017.comm.in | 42 +++++++ .../daSalome/test017_3DVAR_par_fonction.py.in | 62 --------- src/tests/daSalome/test_aster_zzzz159a.py.in | 119 ------------------ .../test_aster_zzzz159a_LBFGSB.comm.in | 98 +++++++++++++++ .../daSalome/test_aster_zzzz159a_LBFGSB.py.in | 119 ------------------ .../daSalome/test_aster_zzzz159a_functions.py | 51 ++++++-- 13 files changed, 273 insertions(+), 343 deletions(-) create mode 100644 src/tests/daSalome/test017.comm.in delete mode 100644 src/tests/daSalome/test017_3DVAR_par_fonction.py.in delete mode 100644 src/tests/daSalome/test_aster_zzzz159a.py.in create mode 100644 src/tests/daSalome/test_aster_zzzz159a_LBFGSB.comm.in delete mode 100644 src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in diff --git a/configure.ac b/configure.ac index c268939..b7c5314 100644 --- a/configure.ac +++ b/configure.ac @@ -121,11 +121,9 @@ AC_CONFIG_FILES([ src/tests/Makefile src/tests/daSalome/Makefile src/tests/daSalome/test000_Blue_AnalysisFile.py - src/tests/daSalome/test017_3DVAR_par_fonction.py src/tests/daSalome/test017.comm src/tests/daSalome/test_aster_zzzz159a_init_parameters.py - src/tests/daSalome/test_aster_zzzz159a.py - src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py + src/tests/daSalome/test_aster_zzzz159a_LBFGSB.comm src/tests/daSalome/zzzz159a.export.esclave bin/Makefile bin/qtEficas_adao_study.py diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index e6883b3..9190aea 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -1,6 +1,6 @@ - + pyobj @@ -136,6 +136,11 @@ if ObservationOperatorOk == 0: assim_study.setObservationOperatorType("Adjoint", "Function") assim_study.setObservationOperator("Adjoint", ObservationOperatorAdjoint) +# Variables +for name, size in zip(InputVariablesNames, InputVariablesSizes): + assim_study.setInputVariable(name, size) +for name, size in zip(OutputVariablesNames, OutputVariablesSizes): + assim_study.setOutputVariable(name, size) Study = assim_study ]]> @@ -144,6 +149,10 @@ Study = assim_study + + + + diff --git a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py index 766903a..45c0f66 100644 --- a/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py +++ b/src/daSalome/daGUI/daGuiImpl/adaoGuiManager.py @@ -138,10 +138,11 @@ class AdaoCaseManager(EficasObserver): """ adaoLogger.debug("currentSelectionChanged") salomeStudyItem = adaoGuiHelper.getSelectedItem() - for case_editor, adao_case in self.cases.iteritems(): - if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): - self.eficas_manager.selectCase(adao_case.eficas_editor) - break + if salomeStudyItem is not None: + for case_editor, adao_case in self.cases.iteritems(): + if adao_case.salome_study_item.GetID() == salomeStudyItem.GetID(): + self.eficas_manager.selectCase(adao_case.eficas_editor) + break # Depuis Eficas def _processEficasTabChanged(self, eficasWrapper, eficasEvent): diff --git a/src/daSalome/daYacsIntegration/daOptimizerLoop.py b/src/daSalome/daYacsIntegration/daOptimizerLoop.py index 7487d9d..e29795b 100644 --- a/src/daSalome/daYacsIntegration/daOptimizerLoop.py +++ b/src/daSalome/daYacsIntegration/daOptimizerLoop.py @@ -24,8 +24,10 @@ class OptimizerHooks: # TODO Input, Output VarList inputVarList = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string")) outputVarList = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("string")) - inputVarList.pushBack("adao_default") - outputVarList.pushBack("adao_default") + for var in self.optim_algo.da_study.InputVariables: + inputVarList.pushBack(var) + for var in self.optim_algo.da_study.OutputVariables: + outputVarList.pushBack(var) sample.setEltAtRank("inputVarList", inputVarList) sample.setEltAtRank("outputVarList", outputVarList) @@ -49,24 +51,50 @@ class OptimizerHooks: parameter_1D = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double")) parameter_2D = pilot.SequenceAny_New(parameter_1D.getType()) parameters_3D = pilot.SequenceAny_New(parameter_2D.getType()) + + print "Input Data", data if isinstance(data, type((1,2))): - for dat in data: - param = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double")) - it = dat.flat - for val in it: - param.pushBack(val) - parameter_2D.pushBack(param) + self.add_parameters(data[0], parameter_2D) + self.add_parameters(data[1], parameter_2D, Output=True) else: - param = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double")) - it = data.flat - for val in it: - param.pushBack(val) - parameter_2D.pushBack(param) + self.add_parameters(data, parameter_2D) parameters_3D.pushBack(parameter_2D) sample.setEltAtRank("inputValues", parameters_3D) - return sample + def add_parameters(self, data, parameter_2D, Output=False): + param = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double")) + elt_list = 0 # index dans la liste des arguments + val_number = 0 # nbre dans l'argument courant + if not Output: + val_end = self.optim_algo.da_study.InputVariables[self.optim_algo.da_study.InputVariablesOrder[elt_list]] # nbr de l'argument courant (-1 == tout) + else: + val_end = self.optim_algo.da_study.OutputVariables[self.optim_algo.da_study.OutputVariablesOrder[elt_list]] # nbr de l'argument courant (-1 == tout) + + it = data.flat + for val in it: + param.pushBack(val) + val_number += 1 + # Test si l'argument est ok + if val_end != -1: + if val_number == val_end: + parameter_2D.pushBack(param) + param = pilot.SequenceAny_New(self.optim_algo.runtime.getTypeCode("double")) + val_number = 0 + elt_list += 1 + if not Output: + if elt_list < len(self.optim_algo.da_study.InputVariablesOrder): + val_end = self.optim_algo.da_study.InputVariables[self.optim_algo.da_study.InputVariablesOrder[elt_list]] + else: + break + else: + if elt_list < len(self.optim_algo.da_study.OutputVariablesOrder): + val_end = self.optim_algo.da_study.OutputVariables[self.optim_algo.da_study.OutputVariablesOrder[elt_list]] + else: + break + if val_end == -1: + parameter_2D.pushBack(param) + def get_data_from_any(self, any_data): error = any_data["returnCode"].getIntValue() if error != 0: diff --git a/src/daSalome/daYacsIntegration/daStudy.py b/src/daSalome/daYacsIntegration/daStudy.py index bc63073..f48ee26 100644 --- a/src/daSalome/daYacsIntegration/daStudy.py +++ b/src/daSalome/daYacsIntegration/daStudy.py @@ -2,6 +2,7 @@ from daCore.AssimilationStudy import AssimilationStudy from daCore import Logging +import logging class daError(Exception): def __init__(self, value): @@ -18,19 +19,29 @@ class daStudy: self.algorithm = algorithm self.algorithm_dict = None self.Background = None + self.InputVariables = {} + self.OutputVariables = {} + self.InputVariablesOrder = [] + self.OutputVariablesOrder = [] self.debug = debug - import logging if self.debug: logging.getLogger().setLevel(logging.DEBUG) else: logging.getLogger().setLevel(logging.INFO) - # Observation Management self.ObservationOperatorType = {} self.FunctionObservationOperator = {} + def setInputVariable(self, name, size): + self.InputVariables[name] = size + self.InputVariablesOrder.append(name) + + def setOutputVariable(self, name, size): + self.OutputVariables[name] = size + self.OutputVariablesOrder.append(name) + def setAlgorithmParameters(self, parameters): self.algorithm_dict = parameters diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index bc58afc..f1f2983 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -70,6 +70,23 @@ def create_yacs_proc(study_config): CAS_node.getInputPort("Debug").edInitPy(False) else: CAS_node.getInputPort("Debug").edInitPy(True) + + # Ajout des Variables + InputVariablesNames = [] + InputVariablesSizes = [] + for var in study_config["InputVariables"]["Order"]: + InputVariablesNames.append(var) + InputVariablesSizes.append(int(study_config["InputVariables"][var])) + CAS_node.getInputPort("InputVariablesNames").edInitPy(InputVariablesNames) + CAS_node.getInputPort("InputVariablesSizes").edInitPy(InputVariablesSizes) + OutputVariablesNames = [] + OutputVariablesSizes = [] + for var in study_config["OutputVariables"]["Order"]: + OutputVariablesNames.append(var) + OutputVariablesSizes.append(int(study_config["OutputVariables"][var])) + CAS_node.getInputPort("OutputVariablesNames").edInitPy(OutputVariablesNames) + CAS_node.getInputPort("OutputVariablesSizes").edInitPy(OutputVariablesSizes) + proc.edAddChild(CAS_node) # Step 0.5: Find if there is a user init node diff --git a/src/tests/daSalome/Makefile.am b/src/tests/daSalome/Makefile.am index 8c2fcee..76b3268 100644 --- a/src/tests/daSalome/Makefile.am +++ b/src/tests/daSalome/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am DATA_INST = \ test000_Blue_AnalysisCode.py test000_Blue_AnalysisFile.py test000_Blue.py \ - test017_3DVAR_par_fonction.py test017_3DVAR_function_script.py test017_3DVAR_init_data.py \ + test017_3DVAR_function_script.py test017_3DVAR_init_data.py \ test017.comm \ test_aster_zzzz159a_background_error.py \ test_aster_zzzz159a_background.py \ @@ -12,15 +12,14 @@ DATA_INST = \ test_aster_zzzz159a_aster_functions.py \ test_aster_zzzz159a_init_algorithm.py \ test_aster_zzzz159a_init_parameters.py \ - test_aster_zzzz159a.py \ - test_aster_zzzz159a_LBFGSB.py \ test_aster_zzzz159a_init_algorithm_LBFGSB.py \ - zzzz159a.3 zzzz159a.export.esclave zzzz159a.mail + zzzz159a.3 zzzz159a.export.esclave zzzz159a.mail \ + test_aster_zzzz159a_LBFGSB.comm testsdasalome_DATA = ${DATA_INST} EXTRA_DIST = test000_Blue_AnalysisCode.py test000_Blue_AnalysisFile.py.in test000_Blue.py \ - test017_3DVAR_par_fonction.py.in test017_3DVAR_function_script.py test017_3DVAR_init_data.py \ + test017_3DVAR_function_script.py test017_3DVAR_init_data.py \ test017.comm.in \ test_aster_zzzz159a_background_error.py \ test_aster_zzzz159a_background.py \ @@ -31,6 +30,6 @@ EXTRA_DIST = test000_Blue_AnalysisCode.py test000_Blue_AnalysisFile.py.in test00 test_aster_zzzz159a_init_algorithm.py \ test_aster_zzzz159a_init_parameters.py.in \ test_aster_zzzz159a.py.in \ - test_aster_zzzz159a_LBFGSB.py.in \ test_aster_zzzz159a_init_algorithm_LBFGSB.py \ - zzzz159a.3 zzzz159a.export.esclave.in zzzz159a.mail + zzzz159a.3 zzzz159a.export.esclave.in zzzz159a.mail \ + test_aster_zzzz159a_LBFGSB.comm.in diff --git a/src/tests/daSalome/test017.comm.in b/src/tests/daSalome/test017.comm.in new file mode 100644 index 0000000..2a56c7d --- /dev/null +++ b/src/tests/daSalome/test017.comm.in @@ -0,0 +1,42 @@ + +ASSIMILATION_STUDY(Study_name='test017', + Study_repertory='@prefix@/tests/daSalome', + Debug=0, + Algorithm='3DVAR', + Background=_F(INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test017_3DVAR_init_data.py',),), + BackgroundError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test017_3DVAR_init_data.py',),), + Observation=_F(INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test017_3DVAR_init_data.py',),), + ObservationError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test017_3DVAR_init_data.py',),), + ObservationOperator=_F(INPUT_TYPE='Function', + data=_F(FROM='FunctionDict', + FUNCTIONDICT_FILE= + 'test017_3DVAR_function_script.py',),), + UserPostAnalysis=_F(FROM='String', + STRING= +"""import numpy +dimension = 300 +precision = 1.e-10 +xt = numpy.matrix(numpy.arange(dimension)).T +xb = Study.getBackground() +xa = numpy.array(ADD.get("Analysis").valueserie(0)) +d = numpy.array(ADD.get("Innovation").valueserie(0)) +# +# Verification du resultat +# ------------------------ +if max(abs(xa - (xb+xt.A1)/2)) > precision: + raise ValueError("Resultat du test errone (1)") +else: + print " Test correct, erreur maximale inferieure à %s"%precision +""",),); diff --git a/src/tests/daSalome/test017_3DVAR_par_fonction.py.in b/src/tests/daSalome/test017_3DVAR_par_fonction.py.in deleted file mode 100644 index 90a75fd..0000000 --- a/src/tests/daSalome/test017_3DVAR_par_fonction.py.in +++ /dev/null @@ -1,62 +0,0 @@ -#-*-coding:iso-8859-1-*- -study_config = {} -study_config["Name"] = "test017_3DVAR" -study_config["Algorithm"] = "3DVAR" - -Background_config = {} -Background_config["Data"] = "@prefix@/tests/daSalome/test017_3DVAR_init_data.py" -Background_config["Type"] = "Vector" -Background_config["From"] = "Script" -study_config["Background"] = Background_config - -BackgroundError_config = {} -BackgroundError_config["Data"] = "@prefix@/tests/daSalome/test017_3DVAR_init_data.py" -BackgroundError_config["Type"] = "Matrix" -BackgroundError_config["From"] = "Script" -study_config["BackgroundError"] = BackgroundError_config - -Observation_config = {} -Observation_config["Data"] = "@prefix@/tests/daSalome/test017_3DVAR_init_data.py" -Observation_config["Type"] = "Vector" -Observation_config["From"] = "Script" -study_config["Observation"] = Observation_config - -ObservationError_config = {} -ObservationError_config["Data"] = "@prefix@/tests/daSalome/test017_3DVAR_init_data.py" -ObservationError_config["Type"] = "Matrix" -ObservationError_config["From"] = "Script" -study_config["ObservationError"] = ObservationError_config - -FunctionDict = {} -FunctionDict["Function"] = ["Direct", "Tangent", "Adjoint"] -FunctionDict["Script"] = {} -FunctionDict["Script"]["Direct"] = "@prefix@/tests/daSalome/test017_3DVAR_function_script.py" -FunctionDict["Script"]["Tangent"] = "@prefix@/tests/daSalome/test017_3DVAR_function_script.py" -FunctionDict["Script"]["Adjoint"] = "@prefix@/tests/daSalome/test017_3DVAR_function_script.py" -ObservationOperator_config = {} -ObservationOperator_config["Data"] = FunctionDict -ObservationOperator_config["Type"] = "Function" -ObservationOperator_config["From"] = "FunctionDict" -study_config["ObservationOperator"] = ObservationOperator_config - -Analysis_config = {} -Analysis_config["Data"] = """ -import numpy - -dimension = 300 -precision = 1.e-10 -xt = numpy.matrix(numpy.arange(dimension)).T -xb = Study.getBackground() - -xa = numpy.array(ADD.get("Analysis").valueserie(0)) -d = numpy.array(ADD.get("Innovation").valueserie(0)) -# -# Verification du resultat -# ------------------------ -if max(abs(xa - (xb+xt.A1)/2)) > precision: - raise ValueError("Resultat du test errone (1)") -else: - print " Test correct, erreur maximale inferieure à %s"%precision -""" -Analysis_config["From"] = "String" -study_config["Analysis"] = Analysis_config diff --git a/src/tests/daSalome/test_aster_zzzz159a.py.in b/src/tests/daSalome/test_aster_zzzz159a.py.in deleted file mode 100644 index 3aa8f8d..0000000 --- a/src/tests/daSalome/test_aster_zzzz159a.py.in +++ /dev/null @@ -1,119 +0,0 @@ -#-*-coding:iso-8859-1-*- -study_config = {} -study_config["Name"] = "test_aster_zzzz159a" -study_config["Algorithm"] = "3DVAR" - -Init_config = {} -Init_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_parameters.py" -Init_config["Type"] = "Dict" -Init_config["From"] = "Script" -Init_config["Target"] = ["AlgorithmParameters", "Background", "BackgroundError", - "Observation", "ObservationError", "ObservationOperator", "Analysis"] -study_config["Init"] = Init_config - -Algorithm_config = {} -Algorithm_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_algorithm.py" -Algorithm_config["Type"] = "Dict" -Algorithm_config["From"] = "Script" -study_config["AlgorithmParameters"] = Algorithm_config - -Background_config = {} -Background_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background.py" -Background_config["Type"] = "Vector" -Background_config["From"] = "Script" -study_config["Background"] = Background_config - -BackgroundError_config = {} -BackgroundError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background_error.py" -BackgroundError_config["Type"] = "Matrix" -BackgroundError_config["From"] = "Script" -study_config["BackgroundError"] = BackgroundError_config - -Observation_config = {} -Observation_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation.py" -Observation_config["Type"] = "Vector" -Observation_config["From"] = "Script" -study_config["Observation"] = Observation_config - -ObservationError_config = {} -ObservationError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation_error.py" -ObservationError_config["Type"] = "Matrix" -ObservationError_config["From"] = "Script" -study_config["ObservationError"] = ObservationError_config - -FunctionDict = {} -FunctionDict["Function"] = ["Direct", "Tangent", "Adjoint"] -FunctionDict["Script"] = {} -FunctionDict["Script"]["Direct"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -FunctionDict["Script"]["Tangent"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -FunctionDict["Script"]["Adjoint"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -ObservationOperator_config = {} -ObservationOperator_config["Data"] = FunctionDict -ObservationOperator_config["Type"] = "Function" -ObservationOperator_config["From"] = "FunctionDict" -study_config["ObservationOperator"] = ObservationOperator_config - -Analysis_config = {} -Analysis_config["Data"] = """ -import numpy - -xa = ADD.get("Analysis").valueserie(0) -Innovation = ADD.get("Innovation").valueserie(0) -A = [] -J = ADD.get("CostFunctionJ").valueserie() -# -ADD.setDiagnostic("PlotVectors", "J") -MonPlot = ADD.get("J") -MonPlot.calculate([J,ADD.get("CostFunctionJb").valueserie(),ADD.get("CostFunctionJo").valueserie()], - title = "Fonctionnelles J, Jb et Jo", - ltitle = ["J","Jb","Jo"], - xlabel = "Pas", ylabel = "Valeur", - filename = "recherche_xx_Fonctionnelles.ps", - pause = False ) - - -nbmesures = 11 # De 0 à 1 par pas de 0.1 -instants = numpy.array([0.1*i for i in range(nbmesures)]) -yo = [] -for reponse in init_data['experience']: - for t,v in list(reponse): - if min(abs(t - instants)) < 1.e-8: - yo.append(v) -xb = [] -Bornes = [] -for parametre in init_data['parametres']: - xb.append( parametre[1] ) - Bornes.append( parametre[2:4] ) -B = numpy.matrix(numpy.core.identity(len(xb))) -alpha = 1.e14 -B[0,0] = alpha * 100 -B[1,1] = alpha * 10 -B[2,2] = alpha * 1 - -# Calcul de la RMS -# ---------------- -import test_aster_zzzz159a_aster_functions as Code_Aster -Hxa = Code_Aster.Calcul_Aster_Ponctuel( xa ) -V1 = numpy.array(Hxa) -V2 = numpy.array(yo) -import math -rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) - -print -print "=========" -print "Ebauche = ",xb -print "Analyse = ",xa -print "RMS = ",rms -print -print "NbSteps = ",len(J) -print "J = ",J -print -print "B[0,0] = ",B[0,0] -print "B[1,1] = ",B[1,1] -print "B[2,2] = ",B[2,2] -print "Bornes = ",Bornes -print "=========" -print -""" -Analysis_config["From"] = "String" -study_config["Analysis"] = Analysis_config diff --git a/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.comm.in b/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.comm.in new file mode 100644 index 0000000..fcfe703 --- /dev/null +++ b/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.comm.in @@ -0,0 +1,98 @@ + +ASSIMILATION_STUDY(Study_name='aster_zzzz159a_LBFGSB', + Study_repertory='@prefix@/tests/daSalome', + Debug=0, + Algorithm='3DVAR', + Background=_F(INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test_aster_zzzz159a_background.py',),), + BackgroundError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test_aster_zzzz159a_background_error.py',),), + Observation=_F(INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test_aster_zzzz159a_observation.py',),), + ObservationError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test_aster_zzzz159a_observation_error.py',),), + ObservationOperator=_F(INPUT_TYPE='Function', + data=_F(FROM='FunctionDict', + FUNCTIONDICT_FILE= + 'test_aster_zzzz159a_functions.py',),), + AlgorithmParameters=_F(INPUT_TYPE='Dict', + data=_F(FROM='Script', + SCRIPT_FILE= + 'test_aster_zzzz159a_init_algorithm_LBFGSB.py',),), + UserDataInit=_F(INIT_FILE= + 'test_aster_zzzz159a_init_parameters.py', + TARGET_LIST= + ('BackgroundError','Observation', + 'ObservationError','ObservationOperator','AlgorithmParameters', + 'UserPostAnalysis','Background',),), + UserPostAnalysis=_F(FROM='String', + STRING= +"""import numpy +import os +xa = ADD.get("Analysis").valueserie(0) +Innovation = ADD.get("Innovation").valueserie(0) +A = [] +J = ADD.get("CostFunctionJ").valueserie() +ADD.setDiagnostic("PlotVectors", "J") +MonPlot = ADD.get("J") +if os.path.isfile("recherche_xx_Fonctionnelles.ps"): + os.remove("recherche_xx_Fonctionnelles.ps") +MonPlot.calculate([J,ADD.get("CostFunctionJb").valueserie(),ADD.get("CostFunctionJo").valueserie()], + title = "Fonctionnelles J, Jb et Jo", + ltitle = ["J","Jb","Jo"], + xlabel = "Pas", ylabel = "Valeur", + filename = "recherche_xx_Fonctionnelles.ps", + pause = False ) +nbmesures = 11 # De 0 vers 1 par pas de 0.1 +instants = numpy.array([0.1*i for i in range(nbmesures)]) +yo = [] +for reponse in init_data['experience']: + for t,v in list(reponse): + if min(abs(t - instants)) < 1.e-8: + yo.append(v) +xb = [] +Bornes = [] +for parametre in init_data['parametres']: + xb.append( parametre[1] ) + Bornes.append( parametre[2:4] ) +B = numpy.matrix(numpy.core.identity(len(xb))) +alpha = 1.e14 +B[0,0] = alpha * 100 +B[1,1] = alpha * 10 +B[2,2] = alpha * 1 +# Calcul de la RMS +# ---------------- +import test_aster_zzzz159a_aster_functions as Code_Aster +Hxa = Code_Aster.Calcul_Aster_Ponctuel( xa ) +V1 = numpy.array(Hxa) +V2 = numpy.array(yo) +import math +rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) +print +print "=========" +print "Ebauche = ",xb +print "Analyse = ",xa +print "RMS = ",rms +print +print "NbSteps = ",len(J) +print "J = ",J +print +print "B[0,0] = ",B[0,0] +print "B[1,1] = ",B[1,1] +print "B[2,2] = ",B[2,2] +print "Bornes = ",Bornes +print "=========" +print +""",), + InputVariables=_F(NAMES=('YOUN__','DSDE__','SIGY__',), + SIZES=(1,1,1,),), + OutputVariables=_F(NAMES=('REPONSE1','REPONSE2',), + SIZES=(11,11,),),); diff --git a/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in b/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in deleted file mode 100644 index 8e58ed1..0000000 --- a/src/tests/daSalome/test_aster_zzzz159a_LBFGSB.py.in +++ /dev/null @@ -1,119 +0,0 @@ -#-*-coding:iso-8859-1-*- -study_config = {} -study_config["Name"] = "test_aster_zzzz159a" -study_config["Algorithm"] = "3DVAR" - -Init_config = {} -Init_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_parameters.py" -Init_config["Type"] = "Dict" -Init_config["From"] = "Script" -Init_config["Target"] = ["AlgorithmParameters", "Background", "BackgroundError", - "Observation", "ObservationError", "ObservationOperator", "Analysis"] -study_config["Init"] = Init_config - -Algorithm_config = {} -Algorithm_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_init_algorithm_LBFGSB.py" -Algorithm_config["Type"] = "Dict" -Algorithm_config["From"] = "Script" -study_config["AlgorithmParameters"] = Algorithm_config - -Background_config = {} -Background_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background.py" -Background_config["Type"] = "Vector" -Background_config["From"] = "Script" -study_config["Background"] = Background_config - -BackgroundError_config = {} -BackgroundError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_background_error.py" -BackgroundError_config["Type"] = "Matrix" -BackgroundError_config["From"] = "Script" -study_config["BackgroundError"] = BackgroundError_config - -Observation_config = {} -Observation_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation.py" -Observation_config["Type"] = "Vector" -Observation_config["From"] = "Script" -study_config["Observation"] = Observation_config - -ObservationError_config = {} -ObservationError_config["Data"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_observation_error.py" -ObservationError_config["Type"] = "Matrix" -ObservationError_config["From"] = "Script" -study_config["ObservationError"] = ObservationError_config - -FunctionDict = {} -FunctionDict["Function"] = ["Direct", "Tangent", "Adjoint"] -FunctionDict["Script"] = {} -FunctionDict["Script"]["Direct"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -FunctionDict["Script"]["Tangent"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -FunctionDict["Script"]["Adjoint"] = "@prefix@/tests/daSalome/test_aster_zzzz159a_functions.py" -ObservationOperator_config = {} -ObservationOperator_config["Data"] = FunctionDict -ObservationOperator_config["Type"] = "Function" -ObservationOperator_config["From"] = "FunctionDict" -study_config["ObservationOperator"] = ObservationOperator_config - -Analysis_config = {} -Analysis_config["Data"] = """ -import numpy - -xa = ADD.get("Analysis").valueserie(0) -Innovation = ADD.get("Innovation").valueserie(0) -A = [] -J = ADD.get("CostFunctionJ").valueserie() -# -ADD.setDiagnostic("PlotVectors", "J") -MonPlot = ADD.get("J") -MonPlot.calculate([J,ADD.get("CostFunctionJb").valueserie(),ADD.get("CostFunctionJo").valueserie()], - title = "Fonctionnelles J, Jb et Jo", - ltitle = ["J","Jb","Jo"], - xlabel = "Pas", ylabel = "Valeur", - filename = "recherche_xx_Fonctionnelles.ps", - pause = False ) - - -nbmesures = 11 # De 0 à 1 par pas de 0.1 -instants = numpy.array([0.1*i for i in range(nbmesures)]) -yo = [] -for reponse in init_data['experience']: - for t,v in list(reponse): - if min(abs(t - instants)) < 1.e-8: - yo.append(v) -xb = [] -Bornes = [] -for parametre in init_data['parametres']: - xb.append( parametre[1] ) - Bornes.append( parametre[2:4] ) -B = numpy.matrix(numpy.core.identity(len(xb))) -alpha = 1.e14 -B[0,0] = alpha * 100 -B[1,1] = alpha * 10 -B[2,2] = alpha * 1 - -# Calcul de la RMS -# ---------------- -import test_aster_zzzz159a_aster_functions as Code_Aster -Hxa = Code_Aster.Calcul_Aster_Ponctuel( xa ) -V1 = numpy.array(Hxa) -V2 = numpy.array(yo) -import math -rms = math.sqrt( ((V2 - V1)**2).sum() / float(V1.size) ) - -print -print "=========" -print "Ebauche = ",xb -print "Analyse = ",xa -print "RMS = ",rms -print -print "NbSteps = ",len(J) -print "J = ",J -print -print "B[0,0] = ",B[0,0] -print "B[1,1] = ",B[1,1] -print "B[2,2] = ",B[2,2] -print "Bornes = ",Bornes -print "=========" -print -""" -Analysis_config["From"] = "String" -study_config["Analysis"] = Analysis_config diff --git a/src/tests/daSalome/test_aster_zzzz159a_functions.py b/src/tests/daSalome/test_aster_zzzz159a_functions.py index aa95b29..ca37753 100644 --- a/src/tests/daSalome/test_aster_zzzz159a_functions.py +++ b/src/tests/daSalome/test_aster_zzzz159a_functions.py @@ -14,16 +14,43 @@ Code_Aster.calcul = init_data["calcul"] Code_Aster.parametres = init_data["parametres"] Code_Aster.python_version = init_data["python_version"] -print computation["method"] - -if computation["method"] == "Direct": - result = Code_Aster.Calcul_Aster_Ponctuel(computation["data"]) - -if computation["method"] == "Tangent": - result = Code_Aster.Calcul_Aster_Ponctuel(computation["data"]) - -if computation["method"] == "Adjoint": - result = Code_Aster.Calcul_Aster_Adjoint(computation["data"]) - +print computation +method = "" +for param in computation["specificParameters"]: + if param["name"] == "method": + method = param["value"] + +# Extraction des données et remise en forme (normalement à faire +# dans le code +# On sait qu'on a trois variables +input_data = [] +for i in range(3): + input_data.append(computation["inputValues"][0][i][0]) + +if method == "Adjoint": + input_data = (input_data, []) + for i in range(22): + if i < 11: + input_data[1].append(computation["inputValues"][0][3][i]) + else: + input_data[1].append(computation["inputValues"][0][4][i-11]) + +if method == "Direct": + output_data = Code_Aster.Calcul_Aster_Ponctuel(input_data) + +if method == "Tangent": + output_data = Code_Aster.Calcul_Aster_Ponctuel(input_data) + +if method == "Adjoint": + output_data = Code_Aster.Calcul_Aster_Adjoint(input_data) + +outputValues = [[[]]] +for val in output_data: + outputValues[0][0].append(val) + +result = {} +result["outputValues"] = outputValues +result["specificOutputInfos"] = [] +result["returnCode"] = 0 +result["errorMessage"] = "" print "Computation end" - -- 2.39.2