From b93ac6bca3ea2e6826f22ea8390747cb41e17939 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20Ribes?= Date: Thu, 26 May 2011 15:59:53 +0200 Subject: [PATCH] Ajout d'un nouvel exemple --- configure.ac | 1 + examples/daSalome/Makefile.am | 8 ++- .../daSalome/test005_ADAO_Operators.comm.in | 31 +++++++++ .../daSalome/test005_ADAO_scripts_for_JDC.py | 66 +++++++++++++++++++ 4 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 examples/daSalome/test005_ADAO_Operators.comm.in create mode 100644 examples/daSalome/test005_ADAO_scripts_for_JDC.py diff --git a/configure.ac b/configure.ac index 885875e..6c6ae7a 100644 --- a/configure.ac +++ b/configure.ac @@ -126,6 +126,7 @@ AC_CONFIG_FILES([ examples/daSalome/Makefile examples/daSalome/test003_ADAO_JDC_using_scripts.comm examples/daSalome/test004_ADAO_JDC_using_scripts.comm + examples/daSalome/test005_ADAO_Operators.comm bin/Makefile bin/qtEficas_adao_study.py doc/Makefile diff --git a/examples/daSalome/Makefile.am b/examples/daSalome/Makefile.am index 77d4f1d..f149f4d 100644 --- a/examples/daSalome/Makefile.am +++ b/examples/daSalome/Makefile.am @@ -6,7 +6,9 @@ DATA_INST = \ test003_ADAO_JDC_using_scripts.comm \ test003_ADAO_scripts_for_JDC.py \ test004_ADAO_JDC_using_scripts.comm \ - test004_ADAO_scripts_for_JDC.py + test004_ADAO_scripts_for_JDC.py \ + test005_ADAO_Operators.comm \ + test005_ADAO_scripts_for_JDC.py examplesdasalome_DATA = ${DATA_INST} @@ -16,4 +18,6 @@ EXTRA_DIST = \ test003_ADAO_JDC_using_scripts.comm.in \ test003_ADAO_scripts_for_JDC.py \ test004_ADAO_JDC_using_scripts.comm.in \ - test004_ADAO_scripts_for_JDC.py + test004_ADAO_scripts_for_JDC.py \ + test005_ADAO_Operators.comm.in \ + test005_ADAO_scripts_for_JDC.py diff --git a/examples/daSalome/test005_ADAO_Operators.comm.in b/examples/daSalome/test005_ADAO_Operators.comm.in new file mode 100644 index 0000000..160a7fe --- /dev/null +++ b/examples/daSalome/test005_ADAO_Operators.comm.in @@ -0,0 +1,31 @@ + +ASSIMILATION_STUDY(Study_name='Test', + Study_repertory='@prefix@/share/salome/adao_examples/daSalome', + Debug=0, + Algorithm='3DVAR', + Background=_F(INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='0 0 0',),), + BackgroundError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + Observation=_F(INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='1 1 1',),), + ObservationError=_F(INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + ObservationOperator=_F(INPUT_TYPE='Function', + data=_F(FROM='FunctionDict', + FUNCTIONDICT_FILE='test005_ADAO_scripts_for_JDC.py',),), + UserPostAnalysis=_F(FROM='String', + STRING= +"""import numpy +Xb = Study.getBackground() +Xa = ADD.get("Analysis").valueserie(-1) +print +print "Size of Background...........= %i"%len(Xb.A1) +print "Size of Analysis.............= %i"%len(Xa) +print "Min, mean, max of Analysis...= %8.3f, %8.3f, %8.3f"%(min(Xa),numpy.mean(Xa),max(Xa)) +print +""",),); diff --git a/examples/daSalome/test005_ADAO_scripts_for_JDC.py b/examples/daSalome/test005_ADAO_scripts_for_JDC.py new file mode 100644 index 0000000..78ef8a3 --- /dev/null +++ b/examples/daSalome/test005_ADAO_scripts_for_JDC.py @@ -0,0 +1,66 @@ +#-*-coding:iso-8859-1-*- +import numpy +import logging +logging.info("ComputationFunctionNode: Begin") +# ============================================================================== +# Input data and parameters: all is in the required input variable +# "computation", containing for example: +# {'inputValues': [[[[0.0, 0.0, 0.0]]]], +# 'inputVarList': ['adao_default'], +# 'outputVarList': ['adao_default'], +# 'specificParameters': [{'name': 'method', 'value': 'Direct'}]} +# ============================================================================== +# +# Recovering the type of computation: "Direct", "Tangent" or "Adjoint" +# -------------------------------------------------------------------- +method = "" +for param in computation["specificParameters"]: + if param["name"] == "method": + method = param["value"] +logging.info("ComputationFunctionNode: Found method is \'%s\'"%method) +# +# Recovering the current control state X +# -------------------------------------- +Xcurrent = computation["inputValues"][0][0][0] +# +# Building explicit calculation or requiring external ones +# -------------------------------------------------------- +dimension = len( Xcurrent ) +H = numpy.matrix(numpy.core.identity(dimension)) +# +def FunctionH( X ): + return H * X +# +def AdjointH( (X, Y) ): + return H.T * Y +# +# The possible computations +# ------------------------- +if method == "Direct": + logging.info("ComputationFunctionNode: Direct computation") + data = FunctionH(numpy.matrix( Xcurrent ).T) +# +if method == "Tangent": + logging.info("ComputationFunctionNode: Tangent computation") + data = FunctionH(numpy.matrix( Xcurrent ).T) +# +if method == "Adjoint": + logging.info("ComputationFunctionNode: Adjoint computation") + Ycurrent = computation["inputValues"][0][0][1] + data = AdjointH((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T)) +# +# Formatting the output +# --------------------- +logging.info("ComputationFunctionNode: Formatting the output") +it = data.flat +outputValues = [[[[]]]] +for val in it: + outputValues[0][0][0].append(val) +# +result = {} +result["outputValues"] = outputValues +result["specificOutputInfos"] = [] +result["returnCode"] = 0 +result["errorMessage"] = "" +# +logging.info("ComputationFunctionNode: End") -- 2.39.2