1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2017 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
25 logging.info("ComputationFunctionNode: Begin")
26 # ==============================================================================
27 # Input data and parameters: all is in the required input variable
28 # "computation", containing for example:
29 # {'inputValues': [[[[0.0, 0.0, 0.0]]]],
30 # 'inputVarList': ['adao_default'],
31 # 'outputVarList': ['adao_default'],
32 # 'specificParameters': [{'name': 'method', 'value': 'Direct'}]}
33 # ==============================================================================
35 # Recovering the type of computation: "Direct", "Tangent" or "Adjoint"
36 # --------------------------------------------------------------------
38 for param in computation["specificParameters"]:
39 if param["name"] == "method":
40 method = param["value"]
41 logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)
43 # Recovering the current control state X
44 # --------------------------------------
45 Xcurrent = computation["inputValues"][0][0][0]
47 # Building explicit calculation or requiring external ones
48 # --------------------------------------------------------
49 dimension = len( Xcurrent )
50 H = numpy.matrix(numpy.core.identity(dimension))
55 def AdjointH( (X, Y) ):
58 # The possible computations
59 # -------------------------
60 if method == "Direct":
61 logging.info("ComputationFunctionNode: Direct computation")
62 data = FunctionH(numpy.matrix( Xcurrent ).T)
64 if method == "Tangent":
65 logging.info("ComputationFunctionNode: Tangent computation")
66 data = FunctionH(numpy.matrix( Xcurrent ).T)
68 if method == "Adjoint":
69 logging.info("ComputationFunctionNode: Adjoint computation")
70 Ycurrent = computation["inputValues"][0][0][1]
71 data = AdjointH((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))
73 # Formatting the output
74 # ---------------------
75 logging.info("ComputationFunctionNode: Formatting the output")
77 outputValues = [[[[]]]]
79 outputValues[0][0][0].append(val)
82 result["outputValues"] = outputValues
83 result["specificOutputInfos"] = []
84 result["returnCode"] = 0
85 result["errorMessage"] = ""
87 logging.info("ComputationFunctionNode: End")