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