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:
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)
${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
)
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:
rm -rf $(SALOMETESTDIR)/test6902
rm -rf $(SALOMETESTDIR)/test6903
rm -rf $(SALOMETESTDIR)/test6904
+ rm -rf $(SALOMETESTDIR)/test6905
rm $(SALOMETESTDIR)/CTestTestfile.cmake
--- /dev/null
+# 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()
--- /dev/null
+# -*- 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)
--- /dev/null
+# -*- 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)
--- /dev/null
+
+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
--- /dev/null
+# -*- 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]))
--- /dev/null
+
+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
--- /dev/null
+# -*- 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]))
--- /dev/null
+
+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
--- /dev/null
+# -*- 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])
--- /dev/null
+
+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
--- /dev/null
+# -*- 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])
--- /dev/null
+
+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
--- /dev/null
+# -*- 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()
--- /dev/null
+# -*- 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,
+ }
--- /dev/null
+# -*- 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
--- /dev/null
+# -*- 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("")