1 # -*- coding: utf-8 -*-
3 # Copyright (C) 2008-2024 EDF R&D
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
23 import numpy, logging, codecs, pickle
25 return pickle.loads(codecs.decode(data.encode(), "base64"))
26 logging.info("ComputationFunctionNode: Begin")
27 # ==============================================================================
28 # Input data and parameters: all is in the required input variable
29 # "computation", containing for example:
30 # {'inputValues': [[[[0.0, 0.0, 0.0]]]],
31 # 'inputVarList': ['adao_default'],
32 # 'outputVarList': ['adao_default'],
33 # 'specificParameters': [{'name': 'method', 'value': 'Direct'}]}
34 # ==============================================================================
36 # Recovering the type of computation: "Direct", "Tangent" or "Adjoint"
37 # --------------------------------------------------------------------
39 for param in computation["specificParameters"]:
40 if param["name"] == "method":
41 method = loads(param["value"])
42 logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)
44 # Recovering the current control state X
45 # --------------------------------------
46 Xcurrent = computation["inputValues"][0][0][0]
48 # Building explicit calculation or requiring external ones
49 # --------------------------------------------------------
50 dimension = len( Xcurrent )
51 H = numpy.matrix(numpy.core.identity(dimension))
56 def AdjointH( paire ):
60 # The possible computations
61 # -------------------------
62 if method == "Direct":
63 logging.info("ComputationFunctionNode: Direct computation")
64 data = FunctionH(numpy.matrix( Xcurrent ).T)
66 if method == "Tangent":
67 logging.info("ComputationFunctionNode: Tangent computation")
68 data = FunctionH(numpy.matrix( Xcurrent ).T)
70 if method == "Adjoint":
71 logging.info("ComputationFunctionNode: Adjoint computation")
72 Ycurrent = computation["inputValues"][0][0][1]
73 data = AdjointH((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))
75 # Formatting the output
76 # ---------------------
77 logging.info("ComputationFunctionNode: Formatting the output")
79 outputValues = [[[[]]]]
81 outputValues[0][0][0].append(val)
84 result["outputValues"] = outputValues
85 result["specificOutputInfos"] = []
86 result["returnCode"] = 0
87 result["errorMessage"] = ""
89 logging.info("ComputationFunctionNode: End")