1 #-*-coding:iso-8859-1-*-
2 # Copyright (C) 2010-2013 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
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 # --------------------------------------------------------
50 H = numpy.matrix(numpy.core.identity(dimension))
56 def AdjointH( (X, Y) ):
59 # The possible computations
60 # -------------------------
61 if method == "Direct":
62 logging.info("ComputationFunctionNode: Direct computation")
63 data = FunctionH(numpy.matrix( Xcurrent ).T)
65 if method == "Tangent":
66 logging.info("ComputationFunctionNode: Tangent computation")
67 data = FunctionH(numpy.matrix( Xcurrent ).T)
69 if method == "Adjoint":
70 logging.info("ComputationFunctionNode: Adjoint computation")
71 Ycurrent = computation["inputValues"][0][0][1]
72 data = AdjointH((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))
74 # Formatting the output
75 # ---------------------
76 logging.info("ComputationFunctionNode: Formatting the output")
78 outputValues = [[[[]]]]
80 outputValues[0][0][0].append(val)
83 result["outputValues"] = outputValues
84 result["specificOutputInfos"] = []
85 result["returnCode"] = 0
86 result["errorMessage"] = ""
88 logging.info("ComputationFunctionNode: End")