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