1 <?xml version='1.0' encoding='iso-8859-1' ?>
3 Copyright (C) 2010-2011 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: Andre Ribes, andre.ribes@edf.fr, EDF R&D
25 <objref name="computeAD" id="python:computeAD:1.0">
29 <!-- Types for parametric computations -->
30 <!-- TODO On devrait pouvoir le lire depuis le KERNEL !!!-->
31 <type name="long" kind="int"/>
32 <struct name="SALOME_TYPES/Parameter">
33 <member type="string" name="name"></member>
34 <member type="string" name="value"></member>
36 <sequence content="SALOME_TYPES/Parameter" name="SALOME_TYPES/ParameterList"></sequence>
37 <sequence content="double" name="SALOME_TYPES/Variable"></sequence>
38 <sequence content="SALOME_TYPES/Variable" name="SALOME_TYPES/VariableSequence"></sequence>
39 <sequence content="SALOME_TYPES/VariableSequence" name="SALOME_TYPES/StateSequence"></sequence>
40 <sequence content="SALOME_TYPES/StateSequence" name="SALOME_TYPES/TimeSequence"></sequence>
41 <sequence content="string" name="SALOME_TYPES/VarList"></sequence>
42 <struct name="SALOME_TYPES/ParametricInput">
43 <member type="SALOME_TYPES/VarList" name="inputVarList"></member>
44 <member type="SALOME_TYPES/VarList" name="outputVarList"></member>
45 <member type="SALOME_TYPES/TimeSequence" name="inputValues"></member>
46 <member type="SALOME_TYPES/ParameterList" name="specificParameters"></member>
48 <struct name="SALOME_TYPES/ParametricOutput">
49 <member type="SALOME_TYPES/TimeSequence" name="outputValues"></member>
50 <member type="SALOME_TYPES/ParameterList" name="specificOutputInfos"></member>
51 <member type="long" name="returnCode"></member>
52 <member type="string" name="errorMessage"></member>
56 <inline name="CreateAssimilationStudy">
61 print "Entering in CreateAssimilationStudy"
63 print "Algorithm is", Algorithm
64 print "Debug is set to", Debug
66 # Create Assimilation study
67 from daYacsIntegration.daStudy import *
68 assim_study = daStudy(Name, Algorithm, Debug)
70 # Algorithm parameters
76 assim_study.setAlgorithmParameters(AlgorithmParameters)
79 print "Data entered are:"
86 #print "Background is", Background
87 #print "BackgroundType is", BackgroundType
88 assim_study.setBackgroundType(BackgroundType)
89 assim_study.setBackground(Background)
97 #print "BackgroundError is", BackgroundError
98 #print "BackgroundErrorType is", BackgroundErrorType
99 assim_study.setBackgroundError(BackgroundError)
107 #print "Observation is", Observation
108 #print "ObservationType is", ObservationType
109 assim_study.setObservationType(ObservationType)
110 assim_study.setObservation(Observation)
118 #print "ObservationError is", ObservationError
119 #print "ObservationErrorType is", ObservationErrorType
120 assim_study.setObservationError(ObservationError)
122 # ObservationOperator
123 ObservationOperatorOk = 0
129 #print "ObservationOperator is", ObservationOperator
130 #print "ObservationOperatorType is", ObservationOperatorType
131 assim_study.setObservationOperatorType("Matrix", ObservationOperatorType)
132 assim_study.setObservationOperator("Matrix", ObservationOperator)
133 ObservationOperatorOk = 1
135 if ObservationOperatorOk == 0:
137 ObservationOperatorDirect
141 #print "ObservationOperatorDirect is", ObservationOperatorDirect
142 assim_study.setObservationOperatorType("Direct", "Function")
143 assim_study.setObservationOperator("Direct", ObservationOperatorDirect)
145 ObservationOperatorTangent
149 #print "ObservationOperatorTangent is", ObservationOperatorTangent
150 assim_study.setObservationOperatorType("Tangent", "Function")
151 assim_study.setObservationOperator("Tangent", ObservationOperatorTangent)
153 ObservationOperatorAdjoint
157 #print "ObservationOperatorAdjoint is", ObservationOperatorAdjoint
158 assim_study.setObservationOperatorType("Adjoint", "Function")
159 assim_study.setObservationOperator("Adjoint", ObservationOperatorAdjoint)
162 for name, size in zip(InputVariablesNames, InputVariablesSizes):
163 assim_study.setInputVariable(name, size)
164 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
165 assim_study.setOutputVariable(name, size)
168 # Adding observers to the study
169 for observer_name in observers.keys():
172 number = str(observers[observer_name]["number"])
173 if "scheduler" in observers[observer_name].keys():
174 scheduler = observers[observer_name]["scheduler"]
175 if "info" in observers[observer_name].keys():
176 info = observers[observer_name]["info"]
177 assim_study.addObserver(observer_name, scheduler, info, number)
182 <inport name="Name" type="string"/>
183 <inport name="Algorithm" type="string"/>
184 <inport name="Debug" type="bool"/>
185 <inport name="InputVariablesNames" type="stringvec"/>
186 <inport name="InputVariablesSizes" type="intvec"/>
187 <inport name="OutputVariablesNames" type="stringvec"/>
188 <inport name="OutputVariablesSizes" type="intvec"/>
189 <inport name="has_observers" type="bool"/>
190 <inport name="observers" type="pyobj"/>
191 <outport name="Study" type="pyobj"/>
194 <inline name="CreateNumpyMatrixFromString">
195 <script><code><![CDATA[
196 print "Entering in CreateNumpyMatrixFromString"
198 matrix = numpy.matrix(matrix_in_string)
200 print "Matrix is", matrix
202 <inport name="matrix_in_string" type="string"/>
203 <outport name="matrix" type="pyobj"/>
204 <outport name="type" type="string"/>
207 <inline name="CreateNumpyMatrixFromScript">
208 <script><code><![CDATA[
209 print "Entering in CreateNumpyMatrixFromScript"
212 # Get file path and filename
215 filepath = os.path.dirname(script)
216 filename = os.path.basename(script)
217 module_name = os.path.splitext(filename)[0]
218 sys.path.insert(0,filepath)
221 __import__(module_name)
222 user_script_module = sys.modules[module_name]
224 # Get Data from script
226 <inport name="script" type="string"/>
227 <outport name="type" type="string"/>
230 <inline name="CreateNumpyVectorFromString">
231 <script><code><![CDATA[
232 print "Entering in CreateNumpyVectorFromString"
234 vector = numpy.matrix(vector_in_string)
236 print "Vector is", vector
238 <inport name="vector_in_string" type="string"/>
239 <outport name="vector" type="pyobj"/>
240 <outport name="type" type="string"/>
243 <inline name="CreateNumpyVectorFromScript">
244 <script><code><![CDATA[
245 print "Entering in CreateNumpyVectorFromScript"
248 # Get file path and filename
251 filepath = os.path.dirname(script)
252 filename = os.path.basename(script)
253 module_name = os.path.splitext(filename)[0]
254 sys.path.insert(0,filepath)
257 __import__(module_name)
258 user_script_module = sys.modules[module_name]
260 # Get Data from script
262 <inport name="script" type="string"/>
263 <outport name="type" type="string"/>
266 <inline name="SimpleExecuteDirectAlgorithm">
267 <script><code><![CDATA[
268 print "Entering in SimpleExecuteDirectAlgorithm"
269 from daYacsIntegration.daStudy import *
270 ADD = Study.getAssimilationStudy()
273 <inport name="Study" type="pyobj"/>
274 <outport name="Study" type="pyobj"/>
277 <inline name="SimpleUserAnalysis">
278 <script><code><![CDATA[
279 #-*-coding:iso-8859-1-*-
280 print "Entering in SimpleUserAnalysis"
281 from daYacsIntegration.daStudy import *
282 ADD = Study.getAssimilationStudy()
286 <inport name="Study" type="pyobj"/>
289 <inline name="FakeOptimizerLoopNode">
290 <script><code><![CDATA[
291 print "Entering in FakeOptimizerLoopNode"
294 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
295 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
298 <inline name="CreateDictFromScript">
299 <script><code><![CDATA[
300 print "Entering in CreateDictFromScript"
302 # Get file path and filename
305 filepath = os.path.dirname(script)
306 filename = os.path.basename(script)
307 module_name = os.path.splitext(filename)[0]
308 sys.path.insert(0,filepath)
311 __import__(module_name)
312 user_script_module = sys.modules[module_name]
314 # Get Data from script
316 <inport name="script" type="string"/>
319 <inline name="UserDataInitFromScript">
320 <script><code><![CDATA[
321 print "Entering in UserDataInitFromScript"
323 # Get file path and filename
326 filepath = os.path.dirname(script)
327 filename = os.path.basename(script)
328 module_name = os.path.splitext(filename)[0]
329 sys.path.insert(0,filepath)
332 __import__(module_name)
333 user_script_module = sys.modules[module_name]
335 # Get Data from script
337 <inport name="script" type="string"/>
338 <outport name="init_data" type="pyobj"/>
341 <inline name="ReadForSwitchNode">
342 <script><code><![CDATA[
343 print "Entering in ReadForSwitch"
345 for param in data["specificParameters"]:
346 if param["name"] == "switch_value":
347 switch_value = int(param["value"])
349 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
350 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
351 <outport name="switch_value" type="int"/>
354 <inline name="ExtractDataNode">
355 <script><code><![CDATA[
357 from daCore.AssimilationStudy import AssimilationStudy
358 print "Entering in ExtractData"
361 for param in data["specificParameters"]:
362 if param["name"] == "var":
363 var = pickle.loads(param["value"])
364 if param["name"] == "info":
365 info = param["value"]
367 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
368 <outport name="var" type="pyobj"/>
369 <outport name="info" type="pyobj"/>
372 <inline name="ObservationNodeString">
373 <script><code><![CDATA[
374 print "Entering in Observation"
377 <inport name="var" type="pyobj"/>
378 <inport name="info" type="pyobj"/>
381 <inline name="ObservationNodeFile">
382 <script><code><![CDATA[
383 print "Entering in Observation"
387 <inport name="var" type="pyobj"/>
388 <inport name="info" type="pyobj"/>
389 <inport name="script" type="string"/>
392 <inline name="EndObservationNode">
393 <script><code><![CDATA[
394 # Create a fake output object.
395 # An observer is always successful.
397 output["outputValues"] = [[[[]]]]
398 output["specificOutputInfos"] = []
399 output["returnCode"] = 0
400 output["errorMessage"] = ""
402 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
405 <inline name="SetObserversNode">
406 <script><code><![CDATA[
407 print "Setting observers"
409 <outport name="has_observers" type="bool"/>
410 <outport name="observers" type="pyobj"/>