1 #-*-coding:iso-8859-1-*-
4 logging.info("ComputationFunctionNode: Begin")
5 # ==============================================================================
6 # Input data and parameters: all is in the required input variable
7 # "computation", containing for example:
8 # {'inputValues': [[[[0.0, 0.0, 0.0]]]],
9 # 'inputVarList': ['adao_default'],
10 # 'outputVarList': ['adao_default'],
11 # 'specificParameters': [{'name': 'method', 'value': 'Direct'}]}
12 # ==============================================================================
14 # Recovering the type of computation: "Direct", "Tangent" or "Adjoint"
15 # --------------------------------------------------------------------
17 for param in computation["specificParameters"]:
18 if param["name"] == "method":
19 method = param["value"]
20 logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)
22 # Recovering the current control state X
23 # --------------------------------------
24 Xcurrent = computation["inputValues"][0][0][0]
26 # Building explicit calculation or requiring external ones
27 # --------------------------------------------------------
28 dimension = len( Xcurrent )
29 H = numpy.matrix(numpy.core.identity(dimension))
34 def AdjointH( (X, Y) ):
37 # The possible computations
38 # -------------------------
39 if method == "Direct":
40 logging.info("ComputationFunctionNode: Direct computation")
41 data = FunctionH(numpy.matrix( Xcurrent ).T)
43 if method == "Tangent":
44 logging.info("ComputationFunctionNode: Tangent computation")
45 data = FunctionH(numpy.matrix( Xcurrent ).T)
47 if method == "Adjoint":
48 logging.info("ComputationFunctionNode: Adjoint computation")
49 Ycurrent = computation["inputValues"][0][0][1]
50 data = AdjointH((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))
52 # Formatting the output
53 # ---------------------
54 logging.info("ComputationFunctionNode: Formatting the output")
56 outputValues = [[[[]]]]
58 outputValues[0][0][0].append(val)
61 result["outputValues"] = outputValues
62 result["specificOutputInfos"] = []
63 result["returnCode"] = 0
64 result["errorMessage"] = ""
66 logging.info("ComputationFunctionNode: End")