Salome HOME
e631d2af12d422e59ceed9e6815c542ab898bb31
[modules/adao.git] / examples / daSkeletons / External_data_definition_by_scripts / Script_ObservationOperator_H.py
1 #-*-coding:iso-8859-1-*-
2 #
3 #  Copyright (C) 2008-2015 EDF R&D
4 #
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.
9 #
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.
14 #
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
18 #
19 #  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21 #  Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
22
23 __doc__ = """
24     ADAO skeleton case, for wide script usage in case definition
25     ------------------------------------------------------------
26
27     Script defining the ObservationOperator
28     """
29 __author__ = "Jean-Philippe ARGAUD"
30 #
31 # ==============================================================================
32 #
33 import Physical_simulation_functions
34 import numpy, logging
35 #
36 # -----------------------------------------------------------------------
37 # SALOME input data and parameters: all information are the required input
38 # variable "computation", containing for example:
39 #      {'inputValues': [[[[0.0, 0.0, 0.0]]]],
40 #       'inputVarList': ['adao_default'],
41 #       'outputVarList': ['adao_default'],
42 #       'specificParameters': [{'name': 'method', 'value': 'Direct'}]}
43 # -----------------------------------------------------------------------
44 #
45 # Recovering the type of computation: "Direct", "Tangent" or "Adjoint"
46 # --------------------------------------------------------------------
47 method = ""
48 for param in computation["specificParameters"]:
49     if param["name"] == "method":
50         method = param["value"]
51 logging.info("ComputationFunctionNode: Found method is \'%s\'"%method)
52 #
53 # Loading the H operator functions from external definitions
54 # ----------------------------------------------------------
55 logging.info("ComputationFunctionNode: Loading operator functions")
56 DirectOperator = Physical_simulation_functions.DirectOperator
57 TangentOperator  = Physical_simulation_functions.TangentOperator
58 AdjointOperator  = Physical_simulation_functions.AdjointOperator
59 #
60 # Executing the possible computations
61 # -----------------------------------
62 if method == "Direct":
63     logging.info("ComputationFunctionNode: Direct computation")
64     Xcurrent = computation["inputValues"][0][0][0]
65     data = DirectOperator(numpy.matrix( Xcurrent ).T)
66 #
67 if method == "Tangent":
68     logging.info("ComputationFunctionNode: Tangent computation")
69     Xcurrent = computation["inputValues"][0][0][0]
70     data = TangentOperator(numpy.matrix( Xcurrent ).T)
71 #
72 if method == "Adjoint":
73     logging.info("ComputationFunctionNode: Adjoint computation")
74     Xcurrent = computation["inputValues"][0][0][0]
75     Ycurrent = computation["inputValues"][0][0][1]
76     data = AdjointOperator((numpy.matrix( Xcurrent ).T, numpy.matrix( Ycurrent ).T))
77 #
78 # Formatting the output
79 # ---------------------
80 logging.info("ComputationFunctionNode: Formatting the output")
81 it = data.flat
82 outputValues = [[[[]]]]
83 for val in it:
84   outputValues[0][0][0].append(val)
85 #
86 # Creating the required ADAO variable
87 # -----------------------------------
88 result = {}
89 result["outputValues"]        = outputValues
90 result["specificOutputInfos"] = []
91 result["returnCode"]          = 0
92 result["errorMessage"]        = ""
93 #
94 # ==============================================================================