From a2ea6cbfdedb69279182855cede0a1050f097139 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Thu, 12 May 2016 14:41:50 +0200 Subject: [PATCH] Add tests for salome test --- test/CTestTestfileInstall.cmake.in | 8 +- test/Makefile.am | 8 +- test/test6701/CTestTestfile.cmake | 33 +++++++++ test/test6701/Doc_TUI_Exemple_01.py | 46 ++++++++++++ test/test6702/CTestTestfile.cmake | 33 +++++++++ test/test6702/Doc_TUI_Exemple_02.py | 71 ++++++++++++++++++ test/test6703/CTestTestfile.cmake | 33 +++++++++ test/test6703/Doc_TUI_Exemple_03.py | 111 ++++++++++++++++++++++++++++ 8 files changed, 340 insertions(+), 3 deletions(-) create mode 100644 test/test6701/CTestTestfile.cmake create mode 100644 test/test6701/Doc_TUI_Exemple_01.py create mode 100644 test/test6702/CTestTestfile.cmake create mode 100644 test/test6702/Doc_TUI_Exemple_02.py create mode 100644 test/test6703/CTestTestfile.cmake create mode 100644 test/test6703/Doc_TUI_Exemple_03.py diff --git a/test/CTestTestfileInstall.cmake.in b/test/CTestTestfileInstall.cmake.in index 27aef2d..ecc955c 100644 --- a/test/CTestTestfileInstall.cmake.in +++ b/test/CTestTestfileInstall.cmake.in @@ -25,6 +25,10 @@ SET(COMPONENT_NAME ADAO) SET(TIMEOUT 500) # Add all test subdirs -SUBDIRS( test1001 - test1002 +SUBDIRS( + test1001 + test1002 + test6701 + test6702 + test6703 ) diff --git a/test/Makefile.am b/test/Makefile.am index c7df128..03009fc 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -21,7 +21,7 @@ include $(top_srcdir)/adm_local/make_common_starter.am -EXTRA_DIST = test1001 test1002 CTestTestfileInstall.cmake.in +EXTRA_DIST = test1001 test1002 test6701 test6702 test6703 CTestTestfileInstall.cmake.in DIR = $(top_srcdir)/test/ @@ -31,10 +31,16 @@ install-data-local: ${mkinstalldirs} $(SALOMETESTDIR) cp -R $(DIR)test1001 $(SALOMETESTDIR) cp -R $(DIR)test1002 $(SALOMETESTDIR) + cp -R $(DIR)test6701 $(SALOMETESTDIR) + cp -R $(DIR)test6702 $(SALOMETESTDIR) + cp -R $(DIR)test6703 $(SALOMETESTDIR) cp $(DIR)CTestTestfileInstall.cmake.in $(SALOMETESTDIR)/CTestTestfile.cmake uninstall-local: chmod -R +w $(SALOMETESTDIR) rm -rf $(SALOMETESTDIR)/test1001 rm -rf $(SALOMETESTDIR)/test1002 + rm -rf $(SALOMETESTDIR)/test6701 + rm -rf $(SALOMETESTDIR)/test6702 + rm -rf $(SALOMETESTDIR)/test6703 rm $(SALOMETESTDIR)/CTestTestfile.cmake diff --git a/test/test6701/CTestTestfile.cmake b/test/test6701/CTestTestfile.cmake new file mode 100644 index 0000000..ab76b31 --- /dev/null +++ b/test/test6701/CTestTestfile.cmake @@ -0,0 +1,33 @@ +# Copyright (C) 2008-2016 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 +# + +#FILE(GLOB ADAO_TEST1001_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +SET(TEST_NAMES + Doc_TUI_Exemple_01 + ) + +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/test6701/Doc_TUI_Exemple_01.py b/test/test6701/Doc_TUI_Exemple_01.py new file mode 100644 index 0000000..7b90248 --- /dev/null +++ b/test/test6701/Doc_TUI_Exemple_01.py @@ -0,0 +1,46 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2016 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 + +# ============================================================================== +def test1(): + + from numpy import array, matrix + import adaoBuilder + case = adaoBuilder.New() + case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) + case.set( 'Background', Vector=[0, 1, 2] ) + case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) + case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) + case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) + case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) + case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) + case.execute() + +# ============================================================================== +if __name__ == "__main__": + print '\n AUTODIAGNOSTIC \n' + print """Exemple de la doc : + + Un exemple simple de création d'un cas de calcul TUI ADAO + +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + """ + test1() diff --git a/test/test6702/CTestTestfile.cmake b/test/test6702/CTestTestfile.cmake new file mode 100644 index 0000000..1a76e0e --- /dev/null +++ b/test/test6702/CTestTestfile.cmake @@ -0,0 +1,33 @@ +# Copyright (C) 2008-2016 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 +# + +#FILE(GLOB ADAO_TEST1001_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +SET(TEST_NAMES + Doc_TUI_Exemple_02 + ) + +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/test6702/Doc_TUI_Exemple_02.py b/test/test6702/Doc_TUI_Exemple_02.py new file mode 100644 index 0000000..9ab9ad1 --- /dev/null +++ b/test/test6702/Doc_TUI_Exemple_02.py @@ -0,0 +1,71 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2016 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 + +# ============================================================================== +def test1(): + + from numpy import array, matrix + import adaoBuilder + case = adaoBuilder.New() + case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) + case.set( 'Background', Vector=[0, 1, 2] ) + case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) + case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) + case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) + case.set( 'ObservationOperator', Matrix='1 0 0;0 2 0;0 0 3' ) + case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) + case.execute() + +def test2(): + + from numpy import array, matrix + import adaoBuilder + case = adaoBuilder.New() + case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) + case.set( 'Background', Vector=[0, 1, 2] ) + case.set( 'BackgroundError', ScalarSparseMatrix=1.0 ) + case.set( 'Observation', Vector=array([0.5, 1.5, 2.5]) ) + case.set( 'ObservationError', DiagonalSparseMatrix='1 1 1' ) + def simulation(x): + import numpy + __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T + __H = numpy.matrix("1 0 0;0 2 0;0 0 3") + return __H * __x + # + case.set( 'ObservationOperator', + OneFunction = simulation, + Parameters = {"DifferentialIncrement":0.01}, + ) + case.set( 'Observer', Variable="Analysis", Template="ValuePrinter" ) + case.execute() + +# ============================================================================== +if __name__ == "__main__": + print '\n AUTODIAGNOSTIC \n' + print """Exemple de la doc : + + Création détaillée d'un cas de calcul TUI ADAO + ++++++++++++++++++++++++++++++++++++++++++++++ + Les deux résultats doivent être identiques. + """ + test1() + test2() diff --git a/test/test6703/CTestTestfile.cmake b/test/test6703/CTestTestfile.cmake new file mode 100644 index 0000000..7c6544a --- /dev/null +++ b/test/test6703/CTestTestfile.cmake @@ -0,0 +1,33 @@ +# Copyright (C) 2008-2016 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 +# + +#FILE(GLOB ADAO_TEST1001_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.py") + +SET(TEST_NAMES + Doc_TUI_Exemple_03 + ) + +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/test6703/Doc_TUI_Exemple_03.py b/test/test6703/Doc_TUI_Exemple_03.py new file mode 100644 index 0000000..ce2b304 --- /dev/null +++ b/test/test6703/Doc_TUI_Exemple_03.py @@ -0,0 +1,111 @@ +#-*-coding:iso-8859-1-*- +# +# Copyright (C) 2008-2016 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 +"Vérification d'un exemple de la documentation" + +# ============================================================================== + +# +# Construction artificielle d'un exemple de données utilisateur +# ------------------------------------------------------------- +alpha = 5. +beta = 7 +gamma = 9.0 +# +alphamin, alphamax = 0., 10. +betamin, betamax = 3, 13 +gammamin, gammamax = 1.5, 15.5 +# +def simulation(x): + "Fonction de simulation H pour effectuer Y=H(X)" + import numpy + __x = numpy.matrix(numpy.ravel(numpy.matrix(x))).T + __H = numpy.matrix("1 0 0;0 2 0;0 0 3; 1 2 3") + return __H * __x +# +# Observations obtenues par simulation +# ------------------------------------ +observations = simulation((2, 3, 4)) + +# ============================================================================== +def test1(): + "Test" + import numpy + import adaoBuilder + # + # Mise en forme des entrées + # ------------------------- + Xb = (alpha, beta, gamma) + Bounds = ( + (alphamin, alphamax), + (betamin, betamax ), + (gammamin, gammamax)) + # + # TUI ADAO + # -------- + case = adaoBuilder.New() + case.set( + 'AlgorithmParameters', + Algorithm = '3DVAR', + Parameters = { + "Bounds":Bounds, + "MaximumNumberOfSteps":100, + "StoreSupplementaryCalculations":[ + "CostFunctionJ", + "CurrentState", + "SimulatedObservationAtOptimum", + ], + } + ) + case.set( 'Background', Vector = numpy.array(Xb), Stored = True ) + case.set( 'Observation', Vector = numpy.array(observations) ) + case.set( 'BackgroundError', ScalarSparseMatrix = 1.0e10 ) + case.set( 'ObservationError', ScalarSparseMatrix = 1.0 ) + case.set( + 'ObservationOperator', + OneFunction = simulation, + Parameters = {"DifferentialIncrement":0.0001}, + ) + case.set( 'Observer', Variable="CurrentState", Template="ValuePrinter" ) + case.execute() + # + # Exploitation indépendante + # ------------------------- + Xbackground = case.get("Background") + Xoptimum = case.get("Analysis")[-1] + FX_at_optimum = case.get("SimulatedObservationAtOptimum")[-1] + J_values = case.get("CostFunctionJ")[:] + print + print "Nombre d'itérations internes...: %i"%len(J_values) + print "Etat initial...................:",numpy.ravel(Xbackground) + print "Etat optimal...................:",numpy.ravel(Xoptimum) + print "Simulation à l'état optimal....:",numpy.ravel(FX_at_optimum) + print + +# ============================================================================== +if __name__ == "__main__": + print '\n AUTODIAGNOSTIC \n' + print """Exemple de la doc : + + Exploitation indépendante des résultats d'un cas de calcul + ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + """ + test1() -- 2.39.2