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 EvolutionErrorType is %s"%EvolutionErrorType)
167 logging.debug("CREATE EvolutionErrorStored is %s"%EvolutionErrorStored)
168 assim_study.setEvolutionErrorType(EvolutionErrorType)
169 assim_study.setEvolutionErrorStored(EvolutionErrorStored)
170 assim_study.setEvolutionError(EvolutionError)
172 # ObservationOperator
173 ObservationOperatorOk = 0
179 logging.debug("CREATE ObservationOperator is set")
180 logging.debug("CREATE ObservationOperatorType is %s"%ObservationOperatorType)
181 assim_study.setObservationOperatorType("Matrix", ObservationOperatorType)
182 assim_study.setObservationOperator("Matrix", ObservationOperator)
183 ObservationOperatorOk = 1
185 if ObservationOperatorOk == 0:
187 ObservationOperatorDirect
191 logging.debug("CREATE ObservationOperatorDirect is %s"%ObservationOperatorDirect)
192 assim_study.setObservationOperatorType("Direct", "Function")
193 assim_study.setObservationOperator("Direct", ObservationOperatorDirect)
195 ObservationOperatorTangent
199 logging.debug("CREATE ObservationOperatorTangent is %s"%ObservationOperatorTangent)
200 assim_study.setObservationOperatorType("Tangent", "Function")
201 assim_study.setObservationOperator("Tangent", ObservationOperatorTangent)
203 ObservationOperatorAdjoint
207 logging.debug("CREATE ObservationOperatorAdjoint is %s"%ObservationOperatorAdjoint)
208 assim_study.setObservationOperatorType("Adjoint", "Function")
209 assim_study.setObservationOperator("Adjoint", ObservationOperatorAdjoint)
218 logging.debug("CREATE EvolutionModel is set")
219 logging.debug("CREATE EvolutionModelType is %s"%EvolutionModelType)
220 assim_study.setEvolutionModelType("Matrix", EvolutionModelType)
221 assim_study.setEvolutionModel("Matrix", EvolutionModel)
224 if EvolutionModelOk == 0:
230 logging.debug("CREATE EvolutionModelDirect is %s"%EvolutionModelDirect)
231 assim_study.setEvolutionModelType("Direct", "Function")
232 assim_study.setEvolutionModel("Direct", EvolutionModelDirect)
234 EvolutionModelTangent
238 logging.debug("CREATE EvolutionModelTangent is %s"%EvolutionModelTangent)
239 assim_study.setEvolutionModelType("Tangent", "Function")
240 assim_study.setEvolutionModel("Tangent", EvolutionModelTangent)
242 EvolutionModelAdjoint
246 logging.debug("CREATE EvolutionModelAdjoint is %s"%EvolutionModelAdjoint)
247 assim_study.setEvolutionModelType("Adjoint", "Function")
248 assim_study.setEvolutionModel("Adjoint", EvolutionModelAdjoint)
251 for name, size in zip(InputVariablesNames, InputVariablesSizes):
252 assim_study.setInputVariable(name, size)
253 for name, size in zip(OutputVariablesNames, OutputVariablesSizes):
254 assim_study.setOutputVariable(name, size)
257 logging.debug("CREATE Observers keys are %s"%observers.keys())
258 # Adding observers to the study
259 for observer_name in observers.keys():
262 number = str(observers[observer_name]["number"])
263 if "scheduler" in observers[observer_name].keys():
264 scheduler = observers[observer_name]["scheduler"]
265 if "info" in observers[observer_name].keys():
266 info = observers[observer_name]["info"]
267 assim_study.addObserver(observer_name, scheduler, info, number)
272 <inport name="Name" type="string"/>
273 <inport name="Algorithm" type="string"/>
274 <inport name="Debug" type="bool"/>
275 <inport name="InputVariablesNames" type="stringvec"/>
276 <inport name="InputVariablesSizes" type="intvec"/>
277 <inport name="OutputVariablesNames" type="stringvec"/>
278 <inport name="OutputVariablesSizes" type="intvec"/>
279 <inport name="has_observers" type="bool"/>
280 <inport name="observers" type="pyobj"/>
281 <outport name="Study" type="pyobj"/>
284 <inline name="CreateNumpyMatrixFromString">
285 <script><code><![CDATA[
286 import numpy, logging
287 logging.debug("CREATE Entering in CreateNumpyMatrixFromString")
288 matrix = numpy.matrix(matrix_in_string)
290 logging.debug("CREATE Matrix is %s"%matrix)
292 <inport name="matrix_in_string" type="string"/>
293 <outport name="matrix" type="pyobj"/>
294 <outport name="type" type="string"/>
295 <outport name="stored" type="bool"/>
298 <inline name="CreateNumpyScalarSparseMatrixFromString">
299 <script><code><![CDATA[
300 import numpy, logging
301 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromString")
302 matrix = numpy.matrix(matrix_in_string)
303 type = "ScalarSparseMatrix"
304 logging.debug("CREATE ScalarSparseMatrix is %s"%matrix)
306 <inport name="matrix_in_string" type="string"/>
307 <outport name="matrix" type="pyobj"/>
308 <outport name="type" type="string"/>
309 <outport name="stored" type="bool"/>
312 <inline name="CreateNumpyDiagonalSparseMatrixFromString">
313 <script><code><![CDATA[
314 import numpy, logging
315 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromString")
316 matrix = numpy.matrix(matrix_in_string)
317 type = "DiagonalSparseMatrix"
318 logging.debug("CREATE DiagonalSparseMatrix is %s"%matrix)
320 <inport name="matrix_in_string" type="string"/>
321 <outport name="matrix" type="pyobj"/>
322 <outport name="type" type="string"/>
323 <outport name="stored" type="bool"/>
326 <inline name="CreateNumpyMatrixFromScript">
327 <script><code><![CDATA[
328 import logging, sys, os
329 logging.debug("CREATE Entering in CreateNumpyMatrixFromScript")
332 # Get file path and filename
333 filepath = os.path.dirname(script)
334 filename = os.path.basename(script)
335 module_name = os.path.splitext(filename)[0]
336 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
337 sys.path.insert(0,filepath)
340 __import__(module_name)
341 user_script_module = sys.modules[module_name]
343 # Get Data from script
345 <inport name="script" type="string"/>
346 <outport name="type" type="string"/>
347 <outport name="stored" type="bool"/>
350 <inline name="CreateNumpyScalarSparseMatrixFromScript">
351 <script><code><![CDATA[
352 import logging, sys, os
353 logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromScript")
354 type = "ScalarSparseMatrix"
356 # Get file path and filename
357 filepath = os.path.dirname(script)
358 filename = os.path.basename(script)
359 module_name = os.path.splitext(filename)[0]
360 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
361 sys.path.insert(0,filepath)
364 __import__(module_name)
365 user_script_module = sys.modules[module_name]
367 # Get Data from script
369 <inport name="script" type="string"/>
370 <outport name="type" type="string"/>
371 <outport name="stored" type="bool"/>
374 <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
375 <script><code><![CDATA[
376 import logging, sys, os
377 logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromScript")
378 type = "DiagonalSparseMatrix"
380 # Get file path and filename
381 filepath = os.path.dirname(script)
382 filename = os.path.basename(script)
383 module_name = os.path.splitext(filename)[0]
384 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
385 sys.path.insert(0,filepath)
388 __import__(module_name)
389 user_script_module = sys.modules[module_name]
391 # Get Data from script
393 <inport name="script" type="string"/>
394 <outport name="type" type="string"/>
395 <outport name="stored" type="bool"/>
398 <inline name="CreateNumpyVectorFromString">
399 <script><code><![CDATA[
400 import numpy, logging
401 logging.debug("CREATE Entering in CreateNumpyVectorFromString")
402 vector = numpy.matrix(vector_in_string)
404 logging.debug("Vector is %s"%vector)
406 <inport name="vector_in_string" type="string"/>
407 <outport name="vector" type="pyobj"/>
408 <outport name="type" type="string"/>
409 <outport name="stored" type="bool"/>
412 <inline name="CreateNumpyVectorFromScript">
413 <script><code><![CDATA[
414 import logging, sys, os
415 logging.debug("CREATE Entering in CreateNumpyVectorFromScript")
418 # Get file path and filename
419 filepath = os.path.dirname(script)
420 filename = os.path.basename(script)
421 module_name = os.path.splitext(filename)[0]
422 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
423 sys.path.insert(0,filepath)
426 __import__(module_name)
427 user_script_module = sys.modules[module_name]
429 # Get Data from script
431 <inport name="script" type="string"/>
432 <outport name="type" type="string"/>
433 <outport name="stored" type="bool"/>
436 <inline name="CreateNumpyVectorSerieFromString">
437 <script><code><![CDATA[
438 import numpy, logging
439 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromString")
440 vector_in_list = eval(str(vector_in_string),{},{})
441 vector = numpy.matrix(vector_in_list)
443 logging.debug("VectorSerie is %s"%vector)
445 <inport name="vector_in_string" type="string"/>
446 <outport name="vector" type="pyobj"/>
447 <outport name="type" type="string"/>
448 <outport name="stored" type="bool"/>
451 <inline name="CreateNumpyVectorSerieFromScript">
452 <script><code><![CDATA[
453 import logging, sys, os
454 logging.debug("CREATE Entering in CreateNumpyVectorSerieFromScript")
457 # Get file path and filename
458 filepath = os.path.dirname(script)
459 filename = os.path.basename(script)
460 module_name = os.path.splitext(filename)[0]
461 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
462 sys.path.insert(0,filepath)
465 __import__(module_name)
466 user_script_module = sys.modules[module_name]
468 # Get Data from script
470 <inport name="script" type="string"/>
471 <outport name="type" type="string"/>
472 <outport name="stored" type="bool"/>
475 <inline name="SimpleExecuteDirectAlgorithm">
476 <script><code><![CDATA[
478 logging.debug("EXECUTE Entering in SimpleExecuteDirectAlgorithm")
479 from daYacsIntegration.daStudy import *
480 ADD = Study.getAssimilationStudy()
483 <inport name="Study" type="pyobj"/>
484 <outport name="Study" type="pyobj"/>
487 <inline name="SimpleUserAnalysis">
488 <script><code><![CDATA[
489 #-*-coding:iso-8859-1-*-
491 logging.debug("TERMINATE Entering in SimpleUserAnalysis")
492 from daYacsIntegration.daStudy import *
493 ADD = Study.getAssimilationStudy()
497 <inport name="Study" type="pyobj"/>
500 <inline name="FakeOptimizerLoopNode">
501 <script><code><![CDATA[
503 logging.debug("EXECUTE Entering in FakeOptimizerLoopNode")
506 <inport name="computation" type="SALOME_TYPES/ParametricInput"/>
507 <outport name="result" type="SALOME_TYPES/ParametricOutput"/>
510 <inline name="CreateDictFromScript">
511 <script><code><![CDATA[
512 import logging, sys, os
513 logging.debug("CREATE Entering in CreateDictFromScript")
515 # Get file path and filename
516 filepath = os.path.dirname(script)
517 filename = os.path.basename(script)
518 module_name = os.path.splitext(filename)[0]
519 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
520 sys.path.insert(0,filepath)
523 __import__(module_name)
524 user_script_module = sys.modules[module_name]
526 # Get Data from script
528 <inport name="script" type="string"/>
531 <inline name="UserDataInitFromScript">
532 <script><code><![CDATA[
533 import logging, sys, os
534 logging.debug("CREATE Entering in UserDataInitFromScript")
536 # Get file path and filename
537 filepath = os.path.dirname(script)
538 filename = os.path.basename(script)
539 module_name = os.path.splitext(filename)[0]
540 if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
541 sys.path.insert(0,filepath)
544 __import__(module_name)
545 user_script_module = sys.modules[module_name]
547 # Get Data from script
549 <inport name="script" type="string"/>
550 <outport name="init_data" type="pyobj"/>
553 <inline name="ReadForSwitchNode">
554 <script><code><![CDATA[
556 logging.debug("CREATE Entering in ReadForSwitchNode")
557 logging.debug(" with input data : "+str(data["specificParameters"]))
559 for param in data["specificParameters"]:
560 if param["name"] == "switch_value":
561 switch_value = int(param["value"])
562 logging.debug(" switching to value : "+str(switch_value))
564 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
565 <outport name="data" type="SALOME_TYPES/ParametricInput"/>
566 <outport name="switch_value" type="int"/>
569 <inline name="ExtractDataNode">
570 <script><code><![CDATA[
572 logging.debug("TERMINATE Entering in ExtractDataNode")
574 from daCore.AssimilationStudy import AssimilationStudy
577 for param in data["specificParameters"]:
578 if param["name"] == "var":
579 var = cPickle.loads(param["value"])
580 if param["name"] == "info":
581 info = param["value"]
583 <inport name="data" type="SALOME_TYPES/ParametricInput"/>
584 <outport name="var" type="pyobj"/>
585 <outport name="info" type="pyobj"/>
588 <inline name="ObservationNodeString">
589 <script><code><![CDATA[]]></code></script>
590 <inport name="var" type="pyobj"/>
591 <inport name="info" type="pyobj"/>
594 <inline name="ObservationNodeFile">
595 <script><code><![CDATA[execfile(script)]]></code></script>
596 <inport name="var" type="pyobj"/>
597 <inport name="info" type="pyobj"/>
598 <inport name="script" type="string"/>
601 <inline name="EndObservationNode">
602 <script><code><![CDATA[
603 # Create a fake output object.
604 # An observer is always successful.
606 output["outputValues"] = [[[[]]]]
607 output["specificOutputInfos"] = []
608 output["returnCode"] = 0
609 output["errorMessage"] = ""
611 <outport name="output" type="SALOME_TYPES/ParametricOutput"/>
614 <inline name="SetObserversNode">
615 <script><code><![CDATA[
616 #print "Setting observers"
618 <outport name="has_observers" type="bool"/>
619 <outport name="observers" type="pyobj"/>