]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Adding storage capacity of some input variables
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2 # Copyright (C) 2010-2011 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 Lesser 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 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
21
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
24 import logging
25
26 class daError(Exception):
27   def __init__(self, value):
28     self.value = value
29   def __str__(self):
30     return repr(self.value)
31
32 class daStudy:
33
34   def __init__(self, name, algorithm, debug):
35
36     self.ADD = AssimilationStudy(name)
37     self.ADD.setControls()
38     self.algorithm = algorithm
39     self.algorithm_dict = None
40     self.Background = None
41     self.CheckingPoint = None
42     self.InputVariables = {}
43     self.OutputVariables = {}
44     self.InputVariablesOrder = []
45     self.OutputVariablesOrder = []
46     self.observers_dict = {}
47
48     self.debug = debug
49     if self.debug:
50       logging.getLogger().setLevel(logging.DEBUG)
51     else:
52       logging.getLogger().setLevel(logging.WARNING)
53
54     # Observation Management
55     self.ObservationOperatorType = {}
56     self.EvolutionModelType = {}
57     self.FunctionObservationOperator = {}
58
59   #--------------------------------------
60
61   def setInputVariable(self, name, size):
62     self.InputVariables[name] = size
63     self.InputVariablesOrder.append(name)
64
65   def setOutputVariable(self, name, size):
66     self.OutputVariables[name] = size
67     self.OutputVariablesOrder.append(name)
68
69   #--------------------------------------
70
71   def setAlgorithmParameters(self, parameters):
72     self.algorithm_dict = parameters
73
74   #--------------------------------------
75
76   def initAlgorithm(self):
77     self.ADD.setAlgorithm(choice=self.algorithm)
78     if self.algorithm_dict != None:
79       logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
80       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
81
82   #--------------------------------------
83
84   def getAssimilationStudy(self):
85     return self.ADD
86
87   #--------------------------------------
88   # Methods to initialize AssimilationStudy
89
90   def setBackgroundType(self, Type):
91     if Type == "Vector":
92       self.BackgroundType = Type
93     else:
94       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
95
96   def setBackgroundStored(self, Stored):
97     if Stored:
98       self.BackgroundStored = True
99     else:
100       self.BackgroundStored = False
101
102   def setBackground(self, Background):
103     try:
104       self.BackgroundType
105       self.BackgroundStored
106     except AttributeError:
107       raise daError("[daStudy::setBackground] Type or Storage is not defined !")
108     self.Background = Background
109     if self.BackgroundType == "Vector":
110       self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
111
112   def getBackground(self):
113     return self.Background
114
115   #--------------------------------------
116
117   def setCheckingPointType(self, Type):
118     if Type == "Vector":
119       self.CheckingPointType = Type
120     else:
121       raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + " Types are : Vector")
122
123   def setCheckingPointStored(self, Stored):
124     if Stored:
125       self.CheckingPointStored = True
126     else:
127       self.CheckingPointStored = False
128
129   def setCheckingPoint(self, CheckingPoint):
130     try:
131       self.CheckingPointType
132       self.CheckingPointStored
133     except AttributeError:
134       raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
135     self.CheckingPoint = CheckingPoint
136     if self.CheckingPointType == "Vector":
137       self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
138
139   #--------------------------------------
140
141   def setBackgroundErrorStored(self, Stored):
142     if Stored:
143       self.BackgroundErrorStored = True
144     else:
145       self.BackgroundErrorStored = False
146
147   def setBackgroundError(self, BackgroundError):
148     try:
149       self.BackgroundErrorStored
150     except AttributeError:
151       raise daError("[daStudy::setBackgroundError] Storage is not defined !")
152     self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
153
154   #--------------------------------------
155
156   def setObservationType(self, Type):
157     if Type == "Vector":
158       self.ObservationType = Type
159     else:
160       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
161
162   def setObservationStored(self, Stored):
163     if Stored:
164       self.ObservationStored = True
165     else:
166       self.ObservationStored = False
167
168   def setObservation(self, Observation):
169     try:
170       self.ObservationType
171       self.ObservationStored
172     except AttributeError:
173       raise daError("[daStudy::setObservation] Type or Storage is not defined !")
174     if self.ObservationType == "Vector":
175       self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
176
177   #--------------------------------------
178
179   def setObservationErrorStored(self, Stored):
180     if Stored:
181       self.ObservationErrorStored = True
182     else:
183       self.ObservationErrorStored = False
184
185   def setObservationError(self, ObservationError):
186     try:
187       self.ObservationErrorStored
188     except AttributeError:
189       raise daError("[daStudy::setObservationError] Storage is not defined !")
190     self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
191
192   #--------------------------------------
193
194   def getObservationOperatorType(self, Name):
195     rtn = None
196     try:
197       rtn = self.ObservationOperatorType[Name]
198     except:
199       pass
200     return rtn
201
202   def setObservationOperatorType(self, Name, Type):
203     if Type == "Matrix":
204       self.ObservationOperatorType[Name] = Type
205     elif Type == "Function":
206       self.ObservationOperatorType[Name] = Type
207     else:
208       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
209
210   def setObservationOperator(self, Name, ObservationOperator):
211     try:
212       self.ObservationOperatorType[Name]
213     except AttributeError:
214       raise daError("[daStudy::setObservationOperator] Type is not defined !")
215     if self.ObservationOperatorType[Name] == "Matrix":
216       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
217     elif self.ObservationOperatorType[Name] == "Function":
218       self.FunctionObservationOperator[Name] = ObservationOperator
219
220   #--------------------------------------
221
222   def getEvolutionModelType(self, Name):
223     rtn = None
224     try:
225       rtn = self.EvolutionModelType[Name]
226     except:
227       pass
228     return rtn
229
230   def setEvolutionModelType(self, Name, Type):
231     if Type == "Matrix":
232       self.EvolutionModelType[Name] = Type
233     elif Type == "Function":
234       self.EvolutionModelType[Name] = Type
235     else:
236       raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
237
238   def setEvolutionModel(self, Name, EvolutionModel):
239     try:
240       self.EvolutionModelType[Name]
241     except AttributeError:
242       raise daError("[daStudy::setEvolutionModel] Type is not defined !")
243     if self.EvolutionModelType[Name] == "Matrix":
244       self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
245     elif self.EvolutionModelType[Name] == "Function":
246       self.FunctionEvolutionModel[Name] = EvolutionModel
247
248   #--------------------------------------
249
250   def addObserver(self, name, scheduler, info, number):
251     self.observers_dict[name] = {}
252     self.observers_dict[name]["scheduler"] = scheduler
253     self.observers_dict[name]["info"] = info
254     self.observers_dict[name]["number"] = number
255
256   def getObservers(self):
257     return self.observers_dict