1 <?xml version='1.0' encoding='iso-8859-1' ?>
3 Copyright (C) 2010-2013 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 <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 logging.debug("CREATE Entering in CreateAssimilationStudy")
62 print "Entering in the assimilation study"
63 print "Name is set to........:", Name
64 print "Algorithm is set to...:", Algorithm
66 # Create Assimilation study
67 from daYacsIntegration.daStudy import *
68 assim_study = daStudy(Name, Algorithm, Debug)
70 logging.debug("CREATE Data entered are:")
72 # Algorithm parameters
78 logging.debug("CREATE AlgorithmParameters is %s"%AlgorithmParameters)
79 assim_study.setAlgorithmParameters(AlgorithmParameters)
87 logging.debug("CREATE Background is set")
88 logging.debug("CREATE BackgroundType is %s"%BackgroundType)
89 logging.debug("CREATE BackgroundStored is %s"%BackgroundStored)
90 assim_study.setBackgroundType(BackgroundType)
91 assim_study.setBackgroundStored(BackgroundStored)
92 assim_study.setBackground(Background)
100 logging.debug("CREATE CheckingPoint is set")
101 logging.debug("CREATE CheckingPointType is %s"%CheckingPointType)
102 logging.debug("CREATE CheckingPointStored is %s"%CheckingPointStored)
103 assim_study.setCheckingPointType(CheckingPointType)
104 assim_study.setCheckingPointStored(CheckingPointStored)
105 assim_study.setCheckingPoint(CheckingPoint)
113 logging.debug("CREATE ControlInput is set")
114 logging.debug("CREATE ControlInputType is %s"%ControlInputType)
115 logging.debug("CREATE ControlInputStored is %s"%ControlInputStored)
116 assim_study.setControlInputType(ControlInputType)
117 assim_study.setControlInputStored(ControlInputStored)
118 assim_study.setControlInput(ControlInput)
126 logging.debug("CREATE Observation is set")
127 logging.debug("CREATE ObservationType is %s"%ObservationType)
128 logging.debug("CREATE ObservationStored is %s"%ObservationStored)
129 assim_study.setObservationType(ObservationType)
130 assim_study.setObservationStored(ObservationStored)
131 assim_study.setObservation(Observation)
139 logging.debug("CREATE BackgroundError is set")
140 logging.debug("CREATE BackgroundErrorType is %s"%BackgroundErrorType)
141 logging.debug("CREATE BackgroundErrorStored is %s"%BackgroundErrorStored)
142 assim_study.setBackgroundErrorType(BackgroundErrorType)
143 assim_study.setBackgroundErrorStored(BackgroundErrorStored)
144 assim_study.setBackgroundError(BackgroundError)
152 logging.debug("CREATE ObservationError is set")
153 logging.debug("CREATE ObservationErrorType is %s"%ObservationErrorType)
154 logging.debug("CREATE ObservationErrorStored is %s"%ObservationErrorStored)
155 assim_study.setObservationErrorType(ObservationErrorType)
156 assim_study.setObservationErrorStored(ObservationErrorStored)
157 assim_study.setObservationError(ObservationError)
165 logging.debug("CREATE EvolutionError is set")
166 logging.debug("CREATE EvolutionErrorStored is %s"%EvolutionErrorStored)
167 assim_study.setEvolutionErrorStored(EvolutionErrorStored)
168 assim_study.setEvolutionError(EvolutionError)
170 # ObservationOperator
171 ObservationOperatorOk = 0
177 logging.debug("CREATE ObservationOperator is set")
178 logging.debug("CREATE ObservationOperatorType is %s"%ObservationOperatorType)
179 assim_study.setObservationOperatorType("Matrix", ObservationOperatorType)
180 assim_study.setObservationOperator("Matrix", ObservationOperator)
181 ObservationOperatorOk = 1
183 if ObservationOperatorOk == 0:
185 ObservationOperatorDirect
189 logging.debug("CREATE ObservationOperatorDirect is %s"%ObservationOperatorDirect)
190 assim_study.setObservationOperatorType("Direct", "Function")
191 assim_study.setObservationOperator("Direct", ObservationOperatorDirect)
193 ObservationOperatorTangent
197 logging.debug("CREATE ObservationOperatorTangent is %s"%ObservationOperatorTangent)
198 assim_study.setObservationOperatorType("Tangent", "Function")
199 assim_study.setObservationOperator("Tangent", ObservationOperatorTangent)
201 ObservationOperatorAdjoint
205 logging.debug("CREATE ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
206 assim_study.setObservationOperatorType("Adjoint", "Function")
207 assim_study.setObservationOperator("Adjoint", ObservationOperatorAdjoint)
216 logging.debug("CREATE EvolutionModel is set")
217 logging.debug("CREATE EvolutionModelType is %s"%EvolutionModelType)
218 assim_study.setEvolutionModelType("Matrix", EvolutionModelType)
219 assim_study.setEvolutionModel("Matrix", EvolutionModel)
222 if EvolutionModelOk == 0:
228 logging.debug("CREATE EvolutionModelDirect is %s"%EvolutionModelDirect)
229 assim_study.setEvolutionModelType("Direct", "Function")
230 assim_study.setEvolutionModel("Direct", EvolutionModelDirect)
232 EvolutionModelTangent
236 logging.debug("CREATE EvolutionModelTangent is %s"%EvolutionModelTangent)
237 assim_study.setEvolutionModelType("Tangent", "Function")
238 assim_study.setEvolutionModel("Tangent", EvolutionModelTangent)
240 EvolutionModelAdjoint
244 logging.debug("CREATE EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
245 assim_study.setEvolutionModelType("Adjoint", "Function")
246 assim_study.setEvolutionModel("Adjoint", EvolutionModelAdjoint)
249 for name, size in zip(InputVariablesNames, InputVariablesSizes):
250 assim_study.setInputVariable(name, size)
251 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
252 assim_study.setOutputVariable(name, size)
255 logging.debug("CREATE Observers keys are %s"%observers.keys())
256 # Adding observers to the study
257 for observer_name in observers.keys():
260 number = str(observers[observer_name]["number"])
261 if "scheduler" in observers[observer_name].keys():
262 scheduler = observers[observer_name]["scheduler"]
263 if "info" in observers[observer_name].keys():
264 info = observers[observer_name]["info"]
265 assim_study.addObserver(observer_name, scheduler, info, number)
270 <inport name="Name" type="string"/>
271 <inport name="Algorithm" type="string"/>
272 <inport name="Debug" type="bool"/>
273 <inport name="InputVariablesNames" type="stringvec"/>
274 <inport name="InputVariablesSizes" type="intvec"/>
275 <inport name="OutputVariablesNames" type="stringvec"/>
276 <inport name="OutputVariablesSizes" type="intvec"/>
277 <inport name="has_observers" type="bool"/>
278 <inport name="observers" type="pyobj"/>
279 <outport name="Study" type="pyobj"/>
282 <inline name="CreateNumpyMatrixFromString">
283 <script><code><![CDATA[
284 import numpy, logging
285 logging.debug("CREATE Entering in CreateNumpyMatrixFromString")
286 matrix = numpy.matrix(matrix_in_string)
288 logging.debug("CREATE Matrix is %s"%matrix)
290 <inport name="matrix_in_string" type="string"/>
291 <outport name="matrix" type="pyobj"/>
292 <outport name="type" type="string"/>
293 <outport name="stored" type="bool"/>
296 <inline name="CreateNumpyScalarSparseMatrixFromString">
297 <script><code><![CDATA[
298 import numpy, logging
299 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromString")
300 matrix = numpy.matrix(matrix_in_string)
301 type = "ScalarSparseMatrix"
302 logging.debug("CREATE ScalarSparseMatrix is %s"%matrix)
304 <inport name="matrix_in_string" type="string"/>
305 <outport name="matrix" type="pyobj"/>
306 <outport name="type" type="string"/>
307 <outport name="stored" type="bool"/>
310 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
311 <script><code><![CDATA[
312 import numpy, logging
313 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromString")
314 matrix = numpy.matrix(matrix_in_string)
315 type = "DiagonalSparseMatrix"
316 logging.debug("CREATE DiagonalSparseMatrix is %s"%matrix)
318 <inport name="matrix_in_string" type="string"/>
319 <outport name="matrix" type="pyobj"/>
320 <outport name="type" type="string"/>
321 <outport name="stored" type="bool"/>
324 <inline name="CreateNumpyMatrixFromScript">
325 <script><code><![CDATA[
326 import logging, sys, os
327 logging.debug("CREATE Entering in CreateNumpyMatrixFromScript")
330 # Get file path and filename
331 filepath = os.path.dirname(script)
332 filename = os.path.basename(script)
333 module_name = os.path.splitext(filename)[0]
334 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
335 sys.path.insert(0,filepath)
338 __import__(module_name)
339 user_script_module = sys.modules[module_name]
341 # Get Data from script
343 <inport name="script" type="string"/>
344 <outport name="type" type="string"/>
345 <outport name="stored" type="bool"/>
348 <inline name="CreateNumpyScalarSparseMatrixFromScript">
349 <script><code><![CDATA[
350 import logging, sys, os
351 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromScript")
352 type = "ScalarSparseMatrix"
354 # Get file path and filename
355 filepath = os.path.dirname(script)
356 filename = os.path.basename(script)
357 module_name = os.path.splitext(filename)[0]
358 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
359 sys.path.insert(0,filepath)
362 __import__(module_name)
363 user_script_module = sys.modules[module_name]
365 # Get Data from script
367 <inport name="script" type="string"/>
368 <outport name="type" type="string"/>
369 <outport name="stored" type="bool"/>
372 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
373 <script><code><![CDATA[
374 import logging, sys, os
375 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromScript")
376 type = "DiagonalSparseMatrix"
378 # Get file path and filename
379 filepath = os.path.dirname(script)
380 filename = os.path.basename(script)
381 module_name = os.path.splitext(filename)[0]
382 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
383 sys.path.insert(0,filepath)
386 __import__(module_name)
387 user_script_module = sys.modules[module_name]
389 # Get Data from script
391 <inport name="script" type="string"/>
392 <outport name="type" type="string"/>
393 <outport name="stored" type="bool"/>
396 <inline name="CreateNumpyVectorFromString">
397 <script><code><![CDATA[
398 import numpy, logging
399 logging.debug("CREATE Entering in CreateNumpyVectorFromString")
400 vector = numpy.matrix(vector_in_string)
402 logging.debug("Vector is %s"%vector)
404 <inport name="vector_in_string" type="string"/>
405 <outport name="vector" type="pyobj"/>
406 <outport name="type" type="string"/>
407 <outport name="stored" type="bool"/>
410 <inline name="CreateNumpyVectorFromScript">
411 <script><code><![CDATA[
412 import logging, sys, os
413 logging.debug("CREATE Entering in CreateNumpyVectorFromScript")
416 # Get file path and filename
417 filepath = os.path.dirname(script)
418 filename = os.path.basename(script)
419 module_name = os.path.splitext(filename)[0]
420 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
421 sys.path.insert(0,filepath)
424 __import__(module_name)
425 user_script_module = sys.modules[module_name]
427 # Get Data from script
429 <inport name="script" type="string"/>
430 <outport name="type" type="string"/>
431 <outport name="stored" type="bool"/>
434 <inline name="CreateNumpyVectorSerieFromString">
435 <script><code><![CDATA[
436 import numpy, logging
437 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromString")
438 vector_in_list = eval(str(vector_in_string),{},{})
439 vector = numpy.matrix(vector_in_list)
441 logging.debug("VectorSerie is %s"%vector)
443 <inport name="vector_in_string" type="string"/>
444 <outport name="vector" type="pyobj"/>
445 <outport name="type" type="string"/>
446 <outport name="stored" type="bool"/>
449 <inline name="CreateNumpyVectorSerieFromScript">
450 <script><code><![CDATA[
451 import logging, sys, os
452 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromScript")
455 # Get file path and filename
456 filepath = os.path.dirname(script)
457 filename = os.path.basename(script)
458 module_name = os.path.splitext(filename)[0]
459 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
460 sys.path.insert(0,filepath)
463 __import__(module_name)
464 user_script_module = sys.modules[module_name]
466 # Get Data from script
468 <inport name="script" type="string"/>
469 <outport name="type" type="string"/>
470 <outport name="stored" type="bool"/>
473 <inline name="SimpleExecuteDirectAlgorithm">
474 <script><code><![CDATA[
476 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
477 from daYacsIntegration.daStudy import *
478 ADD = Study.getAssimilationStudy()
481 <inport name="Study" type="pyobj"/>
482 <outport name="Study" type="pyobj"/>
485 <inline name="SimpleUserAnalysis">
486 <script><code><![CDATA[
487 #-*-coding:iso-8859-1-*-
489 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
490 from daYacsIntegration.daStudy import *
491 ADD = Study.getAssimilationStudy()
495 <inport name="Study" type="pyobj"/>
498 <inline name="FakeOptimizerLoopNode">
499 <script><code><![CDATA[
501 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
504 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
505 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
508 <inline name="CreateDictFromScript">
509 <script><code><![CDATA[
510 import logging, sys, os
511 logging.debug("CREATE Entering in CreateDictFromScript")
513 # Get file path and filename
514 filepath = os.path.dirname(script)
515 filename = os.path.basename(script)
516 module_name = os.path.splitext(filename)[0]
517 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
518 sys.path.insert(0,filepath)
521 __import__(module_name)
522 user_script_module = sys.modules[module_name]
524 # Get Data from script
526 <inport name="script" type="string"/>
529 <inline name="UserDataInitFromScript">
530 <script><code><![CDATA[
531 import logging, sys, os
532 logging.debug("CREATE Entering in UserDataInitFromScript")
534 # Get file path and filename
535 filepath = os.path.dirname(script)
536 filename = os.path.basename(script)
537 module_name = os.path.splitext(filename)[0]
538 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
539 sys.path.insert(0,filepath)
542 __import__(module_name)
543 user_script_module = sys.modules[module_name]
545 # Get Data from script
547 <inport name="script" type="string"/>
548 <outport name="init_data" type="pyobj"/>
551 <inline name="ReadForSwitchNode">
552 <script><code><![CDATA[
554 logging.debug("CREATE Entering in ReadForSwitchNode")
555 logging.debug(" with input data : "+str(data["specificParameters"]))
557 for param in data["specificParameters"]:
558 if param["name"] == "switch_value":
559 switch_value = int(param["value"])
560 logging.debug(" switching to value : "+str(switch_value))
562 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
563 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
564 <outport name="switch_value" type="int"/>
567 <inline name="ExtractDataNode">
568 <script><code><![CDATA[
570 logging.debug("TERMINATE Entering in ExtractDataNode")
572 from daCore.AssimilationStudy import AssimilationStudy
575 for param in data["specificParameters"]:
576 if param["name"] == "var":
577 var = cPickle.loads(param["value"])
578 if param["name"] == "info":
579 info = param["value"]
581 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
582 <outport name="var" type="pyobj"/>
583 <outport name="info" type="pyobj"/>
586 <inline name="ObservationNodeString">
587 <script><code><![CDATA[
588 #print "Entering in Observation"
591 <inport name="var" type="pyobj"/>
592 <inport name="info" type="pyobj"/>
595 <inline name="ObservationNodeFile">
596 <script><code><![CDATA[
597 #print "Entering in Observation"
601 <inport name="var" type="pyobj"/>
602 <inport name="info" type="pyobj"/>
603 <inport name="script" type="string"/>
606 <inline name="EndObservationNode">
607 <script><code><![CDATA[
608 # Create a fake output object.
609 # An observer is always successful.
611 output["outputValues"] = [[[[]]]]
612 output["specificOutputInfos"] = []
613 output["returnCode"] = 0
614 output["errorMessage"] = ""
616 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
619 <inline name="SetObserversNode">
620 <script><code><![CDATA[
621 #print "Setting observers"
623 <outport name="has_observers" type="bool"/>
624 <outport name="observers" type="pyobj"/>