X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FdaComposant%2FdaAlgorithms%2FAdjointTest.py;h=162b79032d30406c91616901dc224cf763afcf42;hb=c84812addb1569e18c45566ff28b766c60aaba82;hp=77849fdcbb0aa840928e8ce95700a47e0f56be77;hpb=c73864264aff5fcc69c24cdcbc84af0d3e0179a6;p=modules%2Fadao.git diff --git a/src/daComposant/daAlgorithms/AdjointTest.py b/src/daComposant/daAlgorithms/AdjointTest.py index 77849fd..162b790 100644 --- a/src/daComposant/daAlgorithms/AdjointTest.py +++ b/src/daComposant/daAlgorithms/AdjointTest.py @@ -1,6 +1,6 @@ #-*-coding:iso-8859-1-*- # -# Copyright (C) 2008-2013 EDF R&D +# Copyright (C) 2008-2014 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 @@ -23,7 +23,6 @@ import logging from daCore import BasicObjects, PlatformInfo m = PlatformInfo.SystemUsage() - import numpy # ============================================================================== @@ -69,27 +68,20 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): message = "Titre du tableau et de la figure", ) - def run(self, Xb=None, Y=None, H=None, M=None, R=None, B=None, Q=None, Parameters=None): + def run(self, Xb=None, Y=None, U=None, HO=None, EM=None, CM=None, R=None, B=None, Q=None, Parameters=None): logging.debug("%s Lancement"%self._name) logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M"))) # - # Paramètres de pilotage - # ---------------------- self.setParameters(Parameters) # - # Opérateur d'observation - # ----------------------- - Hm = H["Direct"].appliedTo - Ht = H["Tangent"].appliedInXTo - Ha = H["Adjoint"].appliedInXTo + Hm = HO["Direct"].appliedTo + Ht = HO["Tangent"].appliedInXTo + Ha = HO["Adjoint"].appliedInXTo # - # Construction des perturbations - # ------------------------------ + # ---------- Perturbations = [ 10**i for i in xrange(self._parameters["EpsilonMinimumExponent"],1) ] Perturbations.reverse() # - # Calcul du point courant - # ----------------------- X = numpy.asmatrix(numpy.ravel( Xb )).T NormeX = numpy.linalg.norm( X ) if Y is None: @@ -97,8 +89,6 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Y = numpy.asmatrix(numpy.ravel( Y )).T NormeY = numpy.linalg.norm( Y ) # - # Fabrication de la direction de l'incrément dX - # ---------------------------------------------- if len(self._parameters["InitialDirection"]) == 0: dX0 = [] for v in X.A1: @@ -111,39 +101,38 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): # dX0 = float(self._parameters["AmplitudeOfInitialDirection"]) * numpy.matrix( dX0 ).T # - # Utilisation de F(X) si aucune observation n'est donnee - # ------------------------------------------------------ - # # Entete des resultats # -------------------- - if self._parameters["ResiduFormula"] is "ScalarProduct": - __doc__ = """ + __marge = 12*" " + if self._parameters["ResiduFormula"] == "ScalarProduct": + __entete = " i Alpha ||X|| ||Y|| ||dX|| R(Alpha) " + __msgdoc = """ On observe le residu qui est la difference de deux produits scalaires : - + R(Alpha) = | < TangentF_X(dX) , Y > - < dX , AdjointF_X(Y) > | - + qui doit rester constamment egal zero a la precision du calcul. On prend dX0 = Normal(0,X) et dX = Alpha*dX0. F est le code de calcul. Y doit etre dans l'image de F. S'il n'est pas donne, on prend Y = F(X). """ - else: - __doc__ = "" # - msgs = " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n" - msgs += " " + self._parameters["ResultTitle"] + "\n" - msgs += " ====" + "="*len(self._parameters["ResultTitle"]) + "====\n" - msgs += __doc__ + if len(self._parameters["ResultTitle"]) > 0: + msgs = "\n" + msgs += __marge + "====" + "="*len(self._parameters["ResultTitle"]) + "====\n" + msgs += __marge + " " + self._parameters["ResultTitle"] + "\n" + msgs += __marge + "====" + "="*len(self._parameters["ResultTitle"]) + "====\n" + else: + msgs = "" + msgs += __msgdoc # - msg = " i Alpha ||X|| ||Y|| ||dX|| R(Alpha) " - nbtirets = len(msg) - msgs += "\n" + "-"*nbtirets - msgs += "\n" + msg - msgs += "\n" + "-"*nbtirets + __nbtirets = len(__entete) + msgs += "\n" + __marge + "-"*__nbtirets + msgs += "\n" + __marge + __entete + msgs += "\n" + __marge + "-"*__nbtirets # Normalisation= -1 # - # Boucle sur les perturbations - # ---------------------------- + # ---------- for i,amplitude in enumerate(Perturbations): dX = amplitude * dX0 NormedX = numpy.linalg.norm( dX ) @@ -154,18 +143,21 @@ class ElementaryAlgorithm(BasicObjects.Algorithm): Residu = abs(float(numpy.dot( TangentFXdX.A1 , Y.A1 ) - numpy.dot( dX.A1 , AdjointFXY.A1 ))) # msg = " %2i %5.0e %9.3e %9.3e %9.3e | %9.3e"%(i,amplitude,NormeX,NormeY,NormedX,Residu) - msgs += "\n" + msg + msgs += "\n" + __marge + msg # self.StoredVariables["CostFunctionJ"].store( Residu ) - msgs += "\n" + "-"*nbtirets + # + msgs += "\n" + __marge + "-"*__nbtirets msgs += "\n" # # Sorties eventuelles # ------------------- print - print "Results of adjoint stability check:" + print "Results of adjoint check by \"%s\" formula:"%self._parameters["ResiduFormula"] print msgs # + logging.debug("%s Nombre d'évaluation(s) de l'opérateur d'observation direct/tangent/adjoint.: %i/%i/%i"%(self._name, HO["Direct"].nbcalls(0),HO["Tangent"].nbcalls(0),HO["Adjoint"].nbcalls(0))) + logging.debug("%s Nombre d'appels au cache d'opérateur d'observation direct/tangent/adjoint..: %i/%i/%i"%(self._name, HO["Direct"].nbcalls(3),HO["Tangent"].nbcalls(3),HO["Adjoint"].nbcalls(3))) logging.debug("%s Taille mémoire utilisée de %.1f Mo"%(self._name, m.getUsedMemory("M"))) logging.debug("%s Terminé"%self._name) #