Salome HOME
- Ajout de la phase de calcul
[modules/adao.git] / src / daSalome / daYacsSchemaCreator / methods.py
1 #-*-coding:iso-8859-1-*-
2 #  Copyright (C) 2010 EDF R&D
3 #
4 #  This library is free software; you can redistribute it and/or
5 #  modify it under the terms of the GNU General Public
6 #  License as published by the Free Software Foundation; either
7 #  version 2.1 of the License.
8 #
9 #  This library is distributed in the hope that it will be useful,
10 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 #  Lesser General Public License for more details.
13 #
14 #  You should have received a copy of the GNU Lesser General Public
15 #  License along with this library; if not, write to the Free Software
16 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # --
19 # Author : AndrĂ© RIBES (EDF R&D)
20 # --
21
22 import sys
23 import traceback
24 import logging
25 import pilot
26 import loader
27 import SALOMERuntime
28 import os
29
30 from daYacsSchemaCreator.infos_daComposant import *
31
32 def create_yacs_proc(study_config):
33
34   logging.debug("[create_yacs_proc]")
35
36   # Init part
37   SALOMERuntime.RuntimeSALOME_setRuntime()
38   l = loader.YACSLoader()
39   l.registerProcCataLoader()
40   runtime = pilot.getRuntime()
41   try:
42     catalogAd = runtime.loadCatalog("proc", os.environ["DATASSIM_ROOT_DIR"] + "/share/salome/resources/datassim/DATASSIMSchemaCatalog.xml")
43   except:
44     logging.fatal("Exception in loading DataAssim YACS catalog")
45     traceback.print_exc()
46     sys.exit(1)
47
48   # Starting creating proc
49   proc = runtime.createProc("proc")
50   proc.setTypeCode("pyobj", runtime.getTypeCode("pyobj"))
51   t_pyobj  = proc.getTypeCode("pyobj")
52   t_string = proc.getTypeCode("string")
53
54   # Step 0: create AssimilationStudyObject
55   factory_CAS_node = catalogAd._nodeMap["CreateAssimilationStudy"]
56   CAS_node = factory_CAS_node.cloneNode("CreateAssimilationStudy")
57   CAS_node.getInputPort("Name").edInitPy(study_config["Name"])
58   CAS_node.getInputPort("Algorithm").edInitPy(study_config["Algorithm"])
59   proc.edAddChild(CAS_node)
60
61   # Step 1: get input data from user configuration
62
63   for key in study_config.keys():
64     if key in AssimData:
65       data_config = study_config[key]
66
67       key_type = key + "Type"
68
69       if data_config["Type"] == "Vector" and data_config["From"] == "string":
70         # Create node
71         factory_back_node = catalogAd._nodeMap["CreateNumpyVectorFromString"]
72         back_node = factory_back_node.cloneNode("Get" + key)
73         back_node.getInputPort("vector_in_string").edInitPy(data_config["Data"])
74         proc.edAddChild(back_node)
75         # Connect node with CreateAssimilationStudy
76         CAS_node.edAddInputPort(key, t_pyobj)
77         CAS_node.edAddInputPort(key_type, t_string)
78         proc.edAddDFLink(back_node.getOutputPort("vector"), CAS_node.getInputPort(key))
79         proc.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type))
80
81       if data_config["Type"] == "Matrix" and data_config["From"] == "string":
82         # Create node
83         factory_back_node = catalogAd._nodeMap["CreateNumpyMatrixFromString"]
84         back_node = factory_back_node.cloneNode("Get" + key)
85         back_node.getInputPort("matrix_in_string").edInitPy(data_config["Data"])
86         proc.edAddChild(back_node)
87         # Connect node with CreateAssimilationStudy
88         CAS_node.edAddInputPort(key, t_pyobj)
89         CAS_node.edAddInputPort(key_type, t_string)
90         proc.edAddDFLink(back_node.getOutputPort("matrix"), CAS_node.getInputPort(key))
91         proc.edAddDFLink(back_node.getOutputPort("type"), CAS_node.getInputPort(key_type))
92
93
94   # Step 3: create compute bloc
95   compute_bloc = runtime.createBloc("compute_bloc")
96   proc.edAddChild(compute_bloc)
97   proc.edAddCFLink(CAS_node, compute_bloc)
98
99   if AlgoType[study_config["Algorithm"]] == "Direct":
100     # We don't need to use an optimizer loop
101     factory_execute_node = catalogAd._nodeMap["SimpleExecuteDirectAlgorithm"]
102     execute_node = factory_execute_node.cloneNode("Execute" + study_config["Algorithm"])
103     compute_bloc.edAddChild(execute_node)
104     proc.edAddDFLink(CAS_node.getOutputPort("Study"), execute_node.getInputPort("Study"))
105
106   # Step 4: create post-processing from user configuration
107
108   return proc
109
110 def write_yacs_proc(proc, yacs_schema_filename):
111
112   proc.saveSchema(yacs_schema_filename)
113