From: Jean-Philippe ARGAUD Date: Mon, 21 Sep 2020 07:34:48 +0000 (+0200) Subject: Correction and support extension of YACS/TUI export (4) X-Git-Tag: V9_6_0a1^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=148a5508cb8dd732afb082a7230044796d67e9d4;p=modules%2Fadao.git Correction and support extension of YACS/TUI export (4) --- diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index 53070c6..402557d 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -624,7 +624,8 @@ class ImportFromScript(object): PlatformInfo.checkFileNameImportability( __basename+".py" ) self.__basename = __basename self.__filenspace = __import__(__basename, globals(), locals(), []) - self.__filestring = open(__filename,'r').read() + with open(__filename,'r') as fid: + self.__filestring = fid.read() def getvalue(self, __varname=None, __synonym=None ): "Renvoie la variable demandee par son nom ou son synonyme" if __varname is None: diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8f890c6..b53c4bd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -24,6 +24,6 @@ if(ADAO_SALOME_MODULE) else(ADAO_SALOME_MODULE) - install(DIRECTORY test1001 test1002 test6701 test6702 test6703 test6704 test6711 test6901 test6902 test6903 test6904 DESTINATION ${ADAO_TEST}) + install(DIRECTORY test1001 test1002 test6701 test6702 test6703 test6704 test6711 test6901 test6902 test6903 test6904 test6905 DESTINATION ${ADAO_TEST}) endif(ADAO_SALOME_MODULE) diff --git a/test/CTestTestfile.cmake b/test/CTestTestfile.cmake index 3365b20..63ff0c6 100644 --- a/test/CTestTestfile.cmake +++ b/test/CTestTestfile.cmake @@ -42,4 +42,5 @@ SUBDIRS( ${ADAO_ENGINE_ROOT_DIR}/share/test/adao/test6902 ${ADAO_ENGINE_ROOT_DIR}/share/test/adao/test6903 ${ADAO_ENGINE_ROOT_DIR}/share/test/adao/test6904 + ${ADAO_ENGINE_ROOT_DIR}/share/test/adao/test6905 ) diff --git a/test/Makefile.am b/test/Makefile.am index ee460db..4e3649f 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -40,6 +40,7 @@ install-data-local: cp -R $(DIR)test6902 $(SALOMETESTDIR) cp -R $(DIR)test6903 $(SALOMETESTDIR) cp -R $(DIR)test6904 $(SALOMETESTDIR) + cp -R $(DIR)test6905 $(SALOMETESTDIR) cp $(DIR)CTestTestfileInstall.cmake.in $(SALOMETESTDIR)/CTestTestfile.cmake uninstall-local: @@ -55,4 +56,5 @@ uninstall-local: rm -rf $(SALOMETESTDIR)/test6902 rm -rf $(SALOMETESTDIR)/test6903 rm -rf $(SALOMETESTDIR)/test6904 + rm -rf $(SALOMETESTDIR)/test6905 rm $(SALOMETESTDIR)/CTestTestfile.cmake diff --git a/test/test6905/CTestTestfile.cmake b/test/test6905/CTestTestfile.cmake new file mode 100644 index 0000000..884fc16 --- /dev/null +++ b/test/test6905/CTestTestfile.cmake @@ -0,0 +1,32 @@ +# Copyright (C) 2008-2020 EDF R&D +# +# This file is part of SALOME ADAO module +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# + +SET(TEST_NAMES + Verification_de_conversion_de_COMM_en_TUI + Verification_de_conversion_de_COMM_en_SCD + ) + +FOREACH(tfile ${TEST_NAMES}) + SET(TEST_NAME ADAO_${tfile}) + ADD_TEST(${TEST_NAME} python ${tfile}.py) + #ADD_TEST(${TEST_NAME} python ${SALOME_TEST_DRIVER} ${TIMEOUT} ${tfile}.py) + SET_TESTS_PROPERTIES(${TEST_NAME} PROPERTIES LABELS "${COMPONENT_NAME}") +ENDFOREACH() diff --git a/test/test6905/Verification_de_conversion_de_COMM_en_SCD.py b/test/test6905/Verification_de_conversion_de_COMM_en_SCD.py new file mode 100644 index 0000000..31003fd --- /dev/null +++ b/test/test6905/Verification_de_conversion_de_COMM_en_SCD.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2020 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D +"COMM/TUI/SCD/YACS: Conversion utilities verification" + +import sys, glob +import unittest +import numpy + +fichiers = glob.glob("*.comm") + +# ============================================================================== +class Test_Adao(unittest.TestCase): + def test1(self): + self.maxDiff = None + print(""" + Conversion utilities verification (COM->SCD) + ++++++++++++++++++++++++++++++++++++++++++++ + """) + # + import numpy + from adao import adaoBuilder + # + for fichier in fichiers: + basename = fichier.rstrip(".comm") + # + print(" Processing \"%s\""%basename) + with open(basename+".comm") as fid: + comm_content = fid.read() + # + comm_content = comm_content.replace("test001_ADAO_External_variables", "test914_Xternal_3_Variables") + comm_content = comm_content.replace("test020_Observation_and_Simulation", "test914_Xternal_4_Variables") + comm_content = comm_content.replace("test033_ADAO_Elementary_FunctionTest_Operators", "test914_Xternal_5_Variables") + # + case = adaoBuilder.New() + case.load( Content=comm_content, Formater="COM" ) + texte = case.dump(Formater="SCD") + del case + # + print(" ---> Ok, SCD file of COMM conversion is correct\n") + +# ============================================================================== +if __name__ == '__main__': + print("\nAUTODIAGNOSTIC\n==============") + sys.stderr = sys.stdout + unittest.main(verbosity=2) diff --git a/test/test6905/Verification_de_conversion_de_COMM_en_TUI.py b/test/test6905/Verification_de_conversion_de_COMM_en_TUI.py new file mode 100644 index 0000000..eb61ecc --- /dev/null +++ b/test/test6905/Verification_de_conversion_de_COMM_en_TUI.py @@ -0,0 +1,68 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2020 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D +"COMM/TUI/SCD/YACS: Conversion utilities verification" + +import sys, glob +import unittest +import numpy + +fichiers = glob.glob("*.comm") + +# ============================================================================== +class Test_Adao(unittest.TestCase): + def test1(self): + self.maxDiff = None + print(""" + Conversion utilities verification (COM->TUI) + ++++++++++++++++++++++++++++++++++++++++++++ + """) + # + import numpy + from adao import adaoBuilder + # + for fichier in fichiers: + basename = fichier.rstrip(".comm") + # + with open(basename+"_tui.py") as fid: + ref_content = fid.read() + # + print(" Processing \"%s\""%basename) + with open(basename+".comm") as fid: + comm_content = fid.read() + # + comm_content = comm_content.replace("test001_ADAO_External_variables", "test914_Xternal_3_Variables") + comm_content = comm_content.replace("test020_Observation_and_Simulation", "test914_Xternal_4_Variables") + comm_content = comm_content.replace("test033_ADAO_Elementary_FunctionTest_Operators", "test914_Xternal_5_Variables") + # + case = adaoBuilder.New() + case.load( Content=comm_content, Formater="COM" ) + texte = case.dump(Formater="TUI") + del case + # + self.assertEqual(texte, ref_content, msg="Differences encoutered in TUI file of COMM conversion") + print(" ---> Ok, TUI file of COMM conversion is correct\n") + +# ============================================================================== +if __name__ == '__main__': + print("\nAUTODIAGNOSTIC\n==============") + sys.stderr = sys.stdout + unittest.main(verbosity=2) diff --git a/test/test6905/test001_ADAO_Elementary_Blue.comm b/test/test6905/test001_ADAO_Elementary_Blue.comm new file mode 100644 index 0000000..02c8f1b --- /dev/null +++ b/test/test6905/test001_ADAO_Elementary_Blue.comm @@ -0,0 +1,30 @@ + +ASSIMILATION_STUDY(StudyName='Elementary algoritmic test', + AlgorithmParameters=_F(Algorithm='Blue',), + Background=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='0 0 0',),), + BackgroundError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + Observation=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='1 1 1',),), + ObservationError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + UserPostAnalysis=_F(FROM='String', + STRING= + """import numpy +numpy.set_printoptions(precision=3) +print("Analysis [0.5,0.5,0.5]:",numpy.ravel(ADD.get("Analysis")[-1]))""",),); +#VERSION_CATALOGUE:V9_5_0:FIN VERSION_CATALOGUE +#CHECKSUM:409a9a1b946bd4210b6ea1aa49b78d03 -:FIN CHECKSUM \ No newline at end of file diff --git a/test/test6905/test001_ADAO_Elementary_Blue_tui.py b/test/test6905/test001_ADAO_Elementary_Blue_tui.py new file mode 100644 index 0000000..2a5c06a --- /dev/null +++ b/test/test6905/test001_ADAO_Elementary_Blue_tui.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# +# Python script using ADAO TUI +# +from numpy import array, matrix +from adao import adaoBuilder +case = adaoBuilder.New('') +case.set( Algorithm='Blue', Concept='AlgorithmParameters' ) +case.set( Concept='Background', Vector='0 0 0' ) +case.set( Concept='BackgroundError', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='Name', String='Elementary algoritmic test' ) +case.set( Concept='Observation', Vector='1 1 1' ) +case.set( Concept='ObservationError', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='ObservationOperator', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='SupplementaryParameters', Parameters={'StudyType': 'ASSIMILATION_STUDY'} ) +case.set( Concept='UserPostAnalysis', String='import numpy\nnumpy.set_printoptions(precision=3)\nprint("Analysis [0.5,0.5,0.5]:",numpy.ravel(case.get("Analysis")[-1]))' ) +case.execute() +import numpy +numpy.set_printoptions(precision=3) +print("Analysis [0.5,0.5,0.5]:",numpy.ravel(case.get("Analysis")[-1])) diff --git a/test/test6905/test001_ADAO_External_variables_Blue.comm b/test/test6905/test001_ADAO_External_variables_Blue.comm new file mode 100644 index 0000000..56ea367 --- /dev/null +++ b/test/test6905/test001_ADAO_External_variables_Blue.comm @@ -0,0 +1,34 @@ + +ASSIMILATION_STUDY(StudyName='Elementary algoritmic test', + StudyRepertory='/home/test/ADAO', + AlgorithmParameters=_F(Algorithm='Blue', + Parameters='Dict', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + Background=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + BackgroundError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + Observation=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + ObservationError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + UserPostAnalysis=_F(FROM='String', + STRING= + """import numpy +numpy.set_printoptions(precision=3) +print("Analysis..............:",numpy.ravel(ADD.get("Analysis")[-1]))""",),); +#VERSION_CATALOGUE:V9_5_0:FIN VERSION_CATALOGUE +#CHECKSUM:fce7207a90a1736dfb2c42bfe7377b1f -:FIN CHECKSUM \ No newline at end of file diff --git a/test/test6905/test001_ADAO_External_variables_Blue_tui.py b/test/test6905/test001_ADAO_External_variables_Blue_tui.py new file mode 100644 index 0000000..f6a95fb --- /dev/null +++ b/test/test6905/test001_ADAO_External_variables_Blue_tui.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# +# Python script using ADAO TUI +# +from numpy import array, matrix +from adao import adaoBuilder +case = adaoBuilder.New('') +case.set( Algorithm='Blue', Concept='AlgorithmParameters', Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='Background', Script='test914_Xternal_3_Variables.py', Vector=True ) +case.set( Concept='BackgroundError', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='Directory', String='/home/test/ADAO' ) +case.set( Concept='Name', String='Elementary algoritmic test' ) +case.set( Concept='Observation', Script='test914_Xternal_3_Variables.py', Vector=True ) +case.set( Concept='ObservationError', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='ObservationOperator', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='SupplementaryParameters', Parameters={'StudyType': 'ASSIMILATION_STUDY'} ) +case.set( Concept='UserPostAnalysis', String='import numpy\nnumpy.set_printoptions(precision=3)\nprint("Analysis..............:",numpy.ravel(case.get("Analysis")[-1]))' ) +case.execute() +import numpy +numpy.set_printoptions(precision=3) +print("Analysis..............:",numpy.ravel(case.get("Analysis")[-1])) diff --git a/test/test6905/test002_ADAO_Elementary_3DVAR.comm b/test/test6905/test002_ADAO_Elementary_3DVAR.comm new file mode 100644 index 0000000..02e99c3 --- /dev/null +++ b/test/test6905/test002_ADAO_Elementary_3DVAR.comm @@ -0,0 +1,27 @@ + +ASSIMILATION_STUDY(StudyName='Elementary algoritmic test', + AlgorithmParameters=_F(Algorithm='3DVAR',), + Background=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='0 0 0',),), + BackgroundError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + Observation=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='String', + STRING='1 1 1',),), + ObservationError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='String', + STRING='1 0 0 ; 0 1 0 ; 0 0 1',),), + UserPostAnalysis=_F(FROM='String', + STRING='print("Analysis [0.5,0.5,0.5]:",ADD.get("Analysis")[-1])',),); +#VERSION_CATALOGUE:V9_6_0:FIN VERSION_CATALOGUE +#CHECKSUM:2f94cae3606cc1c7ad04aceb05588fdf -:FIN CHECKSUM \ No newline at end of file diff --git a/test/test6905/test002_ADAO_Elementary_3DVAR_tui.py b/test/test6905/test002_ADAO_Elementary_3DVAR_tui.py new file mode 100644 index 0000000..9afb343 --- /dev/null +++ b/test/test6905/test002_ADAO_Elementary_3DVAR_tui.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# +# Python script using ADAO TUI +# +from numpy import array, matrix +from adao import adaoBuilder +case = adaoBuilder.New('') +case.set( Algorithm='3DVAR', Concept='AlgorithmParameters' ) +case.set( Concept='Background', Vector='0 0 0' ) +case.set( Concept='BackgroundError', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='Name', String='Elementary algoritmic test' ) +case.set( Concept='Observation', Vector='1 1 1' ) +case.set( Concept='ObservationError', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='ObservationOperator', Matrix='1 0 0 ; 0 1 0 ; 0 0 1' ) +case.set( Concept='SupplementaryParameters', Parameters={'StudyType': 'ASSIMILATION_STUDY'} ) +case.set( Concept='UserPostAnalysis', String='print("Analysis [0.5,0.5,0.5]:",case.get("Analysis")[-1])' ) +case.execute() +print("Analysis [0.5,0.5,0.5]:",case.get("Analysis")[-1]) diff --git a/test/test6905/test002_ADAO_External_variables_3DVAR.comm b/test/test6905/test002_ADAO_External_variables_3DVAR.comm new file mode 100644 index 0000000..1415581 --- /dev/null +++ b/test/test6905/test002_ADAO_External_variables_3DVAR.comm @@ -0,0 +1,31 @@ + +ASSIMILATION_STUDY(StudyName='Elementary algoritmic test', + StudyRepertory='/home/test/ADAO', + AlgorithmParameters=_F(Algorithm='3DVAR', + Parameters='Dict', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + Background=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + BackgroundError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + Observation=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + ObservationError=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Matrix', + data=_F(FROM='Script', + SCRIPT_FILE='test001_ADAO_External_variables.py',),), + UserPostAnalysis=_F(FROM='String', + STRING='print("Analysis [1.0,1.0,1.0]:",ADD.get("Analysis")[-1])',),); +#VERSION_CATALOGUE:V9_5_0:FIN VERSION_CATALOGUE +#CHECKSUM:e93bb53361d5d6088a981d355b05fe16 -:FIN CHECKSUM \ No newline at end of file diff --git a/test/test6905/test002_ADAO_External_variables_3DVAR_tui.py b/test/test6905/test002_ADAO_External_variables_3DVAR_tui.py new file mode 100644 index 0000000..36b5eba --- /dev/null +++ b/test/test6905/test002_ADAO_External_variables_3DVAR_tui.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# +# Python script using ADAO TUI +# +from numpy import array, matrix +from adao import adaoBuilder +case = adaoBuilder.New('') +case.set( Algorithm='3DVAR', Concept='AlgorithmParameters', Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='Background', Script='test914_Xternal_3_Variables.py', Vector=True ) +case.set( Concept='BackgroundError', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='Directory', String='/home/test/ADAO' ) +case.set( Concept='Name', String='Elementary algoritmic test' ) +case.set( Concept='Observation', Script='test914_Xternal_3_Variables.py', Vector=True ) +case.set( Concept='ObservationError', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='ObservationOperator', Matrix=True, Script='test914_Xternal_3_Variables.py' ) +case.set( Concept='SupplementaryParameters', Parameters={'StudyType': 'ASSIMILATION_STUDY'} ) +case.set( Concept='UserPostAnalysis', String='print("Analysis [1.0,1.0,1.0]:",case.get("Analysis")[-1])' ) +case.execute() +print("Analysis [1.0,1.0,1.0]:",case.get("Analysis")[-1]) diff --git a/test/test6905/test020_ADAO_Elementary_GradientTest.comm b/test/test6905/test020_ADAO_Elementary_GradientTest.comm new file mode 100644 index 0000000..36621d2 --- /dev/null +++ b/test/test6905/test020_ADAO_Elementary_GradientTest.comm @@ -0,0 +1,20 @@ + +CHECKING_STUDY(StudyName='Elementary gradient test', + StudyRepertory='/home/test/ADAO', + ExecuteInContainer='Mono', + AlgorithmParameters=_F(Algorithm='GradientTest', + Parameters='Dict', + data=_F(FROM='Script', + SCRIPT_FILE='test020_Observation_and_Simulation.py',),), + CheckingPoint=_F(Stored=0, + INPUT_TYPE='Vector', + data=_F(FROM='Script', + SCRIPT_FILE='test020_Observation_and_Simulation.py',),), + ObservationOperator=_F(Stored=0, + INPUT_TYPE='Function', + data=_F(FROM='ScriptWithOneFunction', + SCRIPTWITHONEFUNCTION_FILE='test020_Observation_and_Simulation.py', + DifferentialIncrement=1e-06, + CenteredFiniteDifference=0,),),); +#VERSION_CATALOGUE:V9_5_0:FIN VERSION_CATALOGUE +#CHECKSUM:fb1ae3548f568cc1b97abf3fd9cc0c1e -:FIN CHECKSUM \ No newline at end of file diff --git a/test/test6905/test020_ADAO_Elementary_GradientTest_tui.py b/test/test6905/test020_ADAO_Elementary_GradientTest_tui.py new file mode 100644 index 0000000..4b1b49c --- /dev/null +++ b/test/test6905/test020_ADAO_Elementary_GradientTest_tui.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# +# Python script using ADAO TUI +# +from numpy import array, matrix +from adao import adaoBuilder +case = adaoBuilder.New('') +case.set( Algorithm='GradientTest', Concept='AlgorithmParameters', Script='test914_Xternal_4_Variables.py' ) +case.set( Concept='CheckingPoint', Script='test914_Xternal_4_Variables.py', Vector=True ) +case.set( Concept='Directory', String='/home/test/ADAO' ) +case.set( Concept='Name', String='Elementary gradient test' ) +case.set( Concept='ObservationOperator', OneFunction=True, Parameters={'DifferentialIncrement': 1e-06, 'CenteredFiniteDifference': 0}, Script='test914_Xternal_4_Variables.py' ) +case.set( Concept='SupplementaryParameters', Parameters={'StudyType': 'CHECKING_STUDY', 'ExecuteInContainer': 'Mono'} ) +case.execute() diff --git a/test/test6905/test914_Xternal_3_Variables.py b/test/test6905/test914_Xternal_3_Variables.py new file mode 100644 index 0000000..9219294 --- /dev/null +++ b/test/test6905/test914_Xternal_3_Variables.py @@ -0,0 +1,51 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2020 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +dimension = 5 + +Background = [-1. for i in range(dimension)] + +Observation = [1. for i in range(dimension)] + +sigmaB2 = 1. +BackgroundError = [[0. for i in range(dimension)] for i in range(dimension)] +for i in range(dimension): + BackgroundError[i][i] = sigmaB2 + +sigmaO2 = 1. +ObservationError = [[0. for i in range(dimension)] for i in range(dimension)] +for i in range(dimension): + ObservationError[i][i] = sigmaO2 + +ObservationOperator = [[0. for i in range(dimension)] for i in range(dimension)] +# dimension * [ dimension * [0.] ] +for i in range(dimension): + ObservationOperator[i][i] = 2. +for i in range(dimension-1): + ObservationOperator[i+1][i] = -1. + ObservationOperator[i][i+1] = -1. + +AlgorithmParameters = { + "SetSeed" : 1000, + "Minimizer" : "LBFGSB", + "MaximumNumberOfSteps" : 15, + } diff --git a/test/test6905/test914_Xternal_4_Variables.py b/test/test6905/test914_Xternal_4_Variables.py new file mode 100644 index 0000000..8db363e --- /dev/null +++ b/test/test6905/test914_Xternal_4_Variables.py @@ -0,0 +1,154 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2020 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +#=============================================================================== +import numpy +# donnees numeriques du modele +xdeb = 0. +xfin = 1. + +nx = 500 +dx=(xfin-xdeb)/nx +dim = nx+1 +p = 10 # nb de mesures + +class EqChaleur(object): + + def __init__(self,alpha): + + self.alpha = float(alpha) + + idx2 = 1./dx**2 + self.A=2*idx2*numpy.identity(dim) + for i in range(1,dim-2): + self.A[i,i+1]=-idx2 + self.A[i+1,i]=-idx2 + + def solve(self,S): + return numpy.linalg.solve(self.alpha*self.A,S) + + def get2ndMbre(self): + + S = numpy.zeros((dim,)) + c = numpy.pi*dx + pi2 = numpy.pi**2 + + for i in range(dim): + S[i] = pi2*numpy.sin(i*c) + return S + + def extract(self,champs,nbobs): + + incr = int(nx/nbobs) + return champs[::incr] + + def obs(self,nbobs): + + X = numpy.linspace(xdeb,xfin,dim) + S = self.get2ndMbre() + T = self.solve(S) + return self.extract(T,nbobs) + + def disp(self): + + X = numpy.linspace(xdeb,xfin,dim) + S = self.get2ndMbre() + T = self.solve(S) + + from matplotlib import pylab + pylab.plot(X,T) + pylab.show() + +class ExempleOperateurChaleur: + """ + Modelisation d'operateur non lineaire pour la diffusion de la chaleur dans + un mur d'epaisseur e, avec une production de chaleur r, pour un + environnement a temperature Ts. Les equations sont : + + T = Ts - r/2k x^2 + r e /2k x + """ + def __init__(self, e = 10., Ts = 100., nbpt = 1000, nbobs = 10): + self.e = float(e) + self.Ts = float(Ts) + self.nbpt = int(nbpt) + self.dx = self.e/(self.nbpt-1) + self.nbobs = min(int(nbobs),self.nbpt) + + def Direct(self, XX ): + if type(XX) is type(numpy.matrix([])): alpha = XX.A1 + elif type(XX) is type(numpy.array([])): alpha = numpy.matrix(XX).A1 + else: alpha = XX + # + eq=EqChaleur(alpha) + HX = eq.obs(self.nbobs) + # + return numpy.array( HX ) + + def DirectExp(self, XX ): # Version en Log/Exp + if type(XX) is type(numpy.matrix([])): alpha = XX.A1 + elif type(XX) is type(numpy.array([])): alpha = numpy.matrix(XX).A1 + else: alpha = XX + alpha = numpy.exp(alpha) + # + eq=EqChaleur(alpha) + HX = eq.obs(self.nbobs) + # + return numpy.array( HX ) + + + def Analytique(self, XX ): + amort = float(XX) + listresult = [] + for i in range(self.nbobs+1) : + ex = i * self.e/(self.nbobs) + eT = self.Ts - amort * ex**2 + self.e*amort*ex + listresult.append(eT) + return numpy.array(listresult) + + def Tangent(self, paire ): + (X, dX) = paire + pass + + def Adjoint(self, paire ): + (X, Y) = paire + pass + +#=============================================================================== + +CheckingPoint = [2.] + +AlgorithmParameters = { + "EpsilonMinimumExponent" : -10, + # "PlotAndSave" : True, + "SetSeed" : 1000, + "InitialDirection":CheckingPoint, + "AmplitudeOfInitialDirection":0.5, + } + +taille = 1000 +OP = ExempleOperateurChaleur(nbpt = taille) + +DirectOperator = OP.Direct + +# JPA : probleme : il faut que le nom d'origine, qui est une méthode de classe, +# existe explicitement pour permettre le parallelisme ! +Direct = DirectOperator diff --git a/test/test6905/test914_Xternal_5_Variables.py b/test/test6905/test914_Xternal_5_Variables.py new file mode 100644 index 0000000..8bea167 --- /dev/null +++ b/test/test6905/test914_Xternal_5_Variables.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2008-2020 EDF R&D +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +# +# Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D + +#=============================================================================== +import numpy +ObservationError = numpy.matrix('1 0 ; 0 1') +Background = numpy.array([1, 1]) + +def DirectOperator(x): + return numpy.array(x) +def TangentOperator(paire): + x,dx = paire + return numpy.array(dx) +def AdjointOperator(paire): + x,dy = paire + return numpy.array(dy) + +#=============================================================================== +if __name__ == "__main__": + print("\nAUTODIAGNOSTIC\n==============") + print("ObservationError = %s"%(ObservationError,)) + print("Background = %s"%(Background,)) + print("DirectOperator = %s"%(DirectOperator([2,5,3]),)) + print("TangentOperator = %s"%(TangentOperator(([2,5,3],[1,1,1])),)) + print("AdjointOperator = %s"%(AdjointOperator(([2,5,3],[0,0,0])),)) + print("")