Salome HOME
Updating copyright date information (2)
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*-coding:utf-8-*-
2 #
3 # Copyright (C) 2008-2019 EDF R&D
4 #
5 # This file is part of SALOME ADAO module
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
20 #
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 #
23 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
24
25 from daCore.AssimilationStudy import AssimilationStudy
26 #from daCore import Logging
27 import logging
28
29 class daError(Exception):
30   def __init__(self, value):
31     self.value = value
32   def __str__(self):
33     return repr(self.value)
34
35 class daStudy:
36
37   def __init__(self, name, algorithm, debug):
38
39     self.ADD = AssimilationStudy(name)
40     self.algorithm = algorithm
41     self.algorithm_dict = None
42     self.Background = None
43     self.CheckingPoint = None
44     self.InputVariables = {}
45     self.OutputVariables = {}
46     self.InputVariablesOrder = []
47     self.OutputVariablesOrder = []
48     self.observers_dict = {}
49
50     self.debug = debug
51     if self.debug:
52       logging.getLogger().setLevel(logging.DEBUG)
53     else:
54       logging.getLogger().setLevel(logging.WARNING)
55
56     # Observation Management
57     self.ObservationOperatorType = {}
58     self.FunctionObservationOperator = {}
59
60     # Evolution Management
61     self.EvolutionModelType = {}
62     self.FunctionEvolutionModel = {}
63
64   def setYIInputVariable(self, name, size):
65     self.InputVariables[name] = size
66     self.InputVariablesOrder.append(name)
67
68   def setYIOutputVariable(self, name, size):
69     self.OutputVariables[name] = size
70     self.OutputVariablesOrder.append(name)
71
72   def setYIAlgorithmParameters(self, parameters):
73     self.algorithm_dict = parameters
74
75   def initYIAlgorithm(self):
76     self.ADD.setAlgorithmParameters(Algorithm=self.algorithm)
77     if self.algorithm_dict != None:
78       logging.debug("DASTUDY AlgorithmParameters: "+str(self.algorithm_dict))
79       self.ADD.updateAlgorithmParameters(Parameters=self.algorithm_dict)
80
81   def YI_prepare_to_pickle(self):
82     return self.ADD.prepare_to_pickle()
83
84   #--------------------------------------
85
86   def __dir__(self):
87     return ['getResults', '__doc__', '__init__', '__module__']
88
89   def getResults(self):
90     "Unique méthode à ne pas inclure YI"
91     return self.ADD
92
93   #--------------------------------------
94   # Methods to initialize AssimilationStudy
95
96   def setYIBackgroundType(self, Type):
97     if Type == "Vector":
98       self.BackgroundType = Type
99     else:
100       raise daError("[daStudy::setYIBackgroundType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
101
102   def setYIBackgroundStored(self, Stored):
103     if Stored:
104       self.BackgroundStored = True
105     else:
106       self.BackgroundStored = False
107
108   def setYIBackground(self, Background):
109     try:
110       self.BackgroundType
111       self.BackgroundStored
112     except AttributeError:
113       raise daError("[daStudy::setYIBackground] Type or Storage is not defined !")
114     self.Background = Background
115     if self.BackgroundType == "Vector":
116       self.ADD.setBackground(Vector = Background, Stored = self.BackgroundStored)
117
118   def getYIBackground(self):
119     return self.Background
120
121   #--------------------------------------
122
123   def setYICheckingPointType(self, Type):
124     if Type == "Vector":
125       self.CheckingPointType = Type
126     else:
127       raise daError("[daStudy::setYICheckingPointType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
128
129   def setYICheckingPointStored(self, Stored):
130     if Stored:
131       self.CheckingPointStored = True
132     else:
133       self.CheckingPointStored = False
134
135   def setYICheckingPoint(self, CheckingPoint):
136     try:
137       self.CheckingPointType
138       self.CheckingPointStored
139     except AttributeError:
140       raise daError("[daStudy::setYICheckingPoint] Type or Storage is not defined !")
141     self.CheckingPoint = CheckingPoint
142     if self.CheckingPointType == "Vector":
143       self.ADD.setBackground(Vector = CheckingPoint, Stored = self.CheckingPointStored)
144
145   #--------------------------------------
146
147   def setYIBackgroundErrorType(self, Type):
148     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
149       self.BackgroundErrorType = Type
150     else:
151       raise daError("[daStudy::setYIBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
152
153   def setYIBackgroundErrorStored(self, Stored):
154     if Stored:
155       self.BackgroundErrorStored = True
156     else:
157       self.BackgroundErrorStored = False
158
159   def setYIBackgroundError(self, BackgroundError):
160     try:
161       self.BackgroundErrorType
162       self.BackgroundErrorStored
163     except AttributeError:
164       raise daError("[daStudy::setYIBackgroundError] Type or Storage is not defined !")
165     if self.BackgroundErrorType == "Matrix":
166       self.ADD.setBackgroundError(Matrix = BackgroundError, Stored = self.BackgroundErrorStored)
167     if self.BackgroundErrorType == "ScalarSparseMatrix":
168       self.ADD.setBackgroundError(ScalarSparseMatrix = BackgroundError, Stored = self.BackgroundErrorStored)
169     if self.BackgroundErrorType == "DiagonalSparseMatrix":
170       self.ADD.setBackgroundError(DiagonalSparseMatrix = BackgroundError, Stored = self.BackgroundErrorStored)
171
172   #--------------------------------------
173
174   def setYIControlInputType(self, Type):
175     if Type in ("Vector", "VectorSerie"):
176       self.ControlInputType = Type
177     else:
178       raise daError("[daStudy::setYIControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
179
180   def setYIControlInputStored(self, Stored):
181     if Stored:
182       self.ControlInputStored = True
183     else:
184       self.ControlInputStored = False
185
186   def setYIControlInput(self, ControlInput):
187     try:
188       self.ControlInputType
189       self.ControlInputStored
190     except AttributeError:
191       raise daError("[daStudy::setYIControlInput] Type or Storage is not defined !")
192     if self.ControlInputType == "Vector":
193       self.ADD.setControlInput(Vector = ControlInput, Stored = self.ControlInputStored)
194     if self.ControlInputType == "VectorSerie":
195       self.ADD.setControlInput(VectorSerie = ControlInput, Stored = self.ControlInputStored)
196
197   #--------------------------------------
198
199   def setYIObservationType(self, Type):
200     if Type in ("Vector", "VectorSerie"):
201       self.ObservationType = Type
202     else:
203       raise daError("[daStudy::setYIObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
204
205   def setYIObservationStored(self, Stored):
206     if Stored:
207       self.ObservationStored = True
208     else:
209       self.ObservationStored = False
210
211   def setYIObservation(self, Observation):
212     try:
213       self.ObservationType
214       self.ObservationStored
215     except AttributeError:
216       raise daError("[daStudy::setYIObservation] Type or Storage is not defined !")
217     if self.ObservationType == "Vector":
218       self.ADD.setObservation(Vector = Observation, Stored = self.ObservationStored)
219     if self.ObservationType == "VectorSerie":
220       self.ADD.setObservation(VectorSerie = Observation, Stored = self.ObservationStored)
221
222   #--------------------------------------
223
224   def setYIObservationErrorType(self, Type):
225     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
226       self.ObservationErrorType = Type
227     else:
228       raise daError("[daStudy::setYIObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
229
230   def setYIObservationErrorStored(self, Stored):
231     if Stored:
232       self.ObservationErrorStored = True
233     else:
234       self.ObservationErrorStored = False
235
236   def setYIObservationError(self, ObservationError):
237     try:
238       self.ObservationErrorType
239       self.ObservationErrorStored
240     except AttributeError:
241       raise daError("[daStudy::setYIObservationError] Type or Storage is not defined !")
242     if self.ObservationErrorType == "Matrix":
243       self.ADD.setObservationError(Matrix = ObservationError, Stored = self.ObservationErrorStored)
244     if self.ObservationErrorType == "ScalarSparseMatrix":
245       self.ADD.setObservationError(ScalarSparseMatrix = ObservationError, Stored = self.ObservationErrorStored)
246     if self.ObservationErrorType == "DiagonalSparseMatrix":
247       self.ADD.setObservationError(DiagonalSparseMatrix = ObservationError, Stored = self.ObservationErrorStored)
248
249   #--------------------------------------
250
251   def getYIObservationOperatorType(self, Name):
252     rtn = None
253     try:
254       rtn = self.ObservationOperatorType[Name]
255     except:
256       pass
257     return rtn
258
259   def setYIObservationOperatorType(self, Name, Type):
260     if Type in ("Matrix", "Function"):
261       self.ObservationOperatorType[Name] = Type
262     else:
263       raise daError("[daStudy::setYIObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
264
265   def setYIObservationOperator(self, Name, ObservationOperator):
266     try:
267       self.ObservationOperatorType[Name]
268     except AttributeError:
269       raise daError("[daStudy::setYIObservationOperator] Type is not defined !")
270     if self.ObservationOperatorType[Name] == "Matrix":
271       self.ADD.setObservationOperator(Matrix = ObservationOperator)
272     elif self.ObservationOperatorType[Name] == "Function":
273       self.FunctionObservationOperator[Name] = ObservationOperator
274
275   #--------------------------------------
276
277   def setYIEvolutionErrorType(self, Type):
278     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
279       self.EvolutionErrorType = Type
280     else:
281       raise daError("[daStudy::setYIEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
282
283   def setYIEvolutionErrorStored(self, Stored):
284     if Stored:
285       self.EvolutionErrorStored = True
286     else:
287       self.EvolutionErrorStored = False
288
289   def setYIEvolutionError(self, EvolutionError):
290     try:
291       self.EvolutionErrorType
292       self.EvolutionErrorStored
293     except AttributeError:
294       raise daError("[daStudy::setYIEvolutionError] Type or Storage is not defined !")
295     if self.EvolutionErrorType == "Matrix":
296       self.ADD.setEvolutionError(Matrix = EvolutionError, Stored = self.EvolutionErrorStored)
297     if self.EvolutionErrorType == "ScalarSparseMatrix":
298       self.ADD.setEvolutionError(ScalarSparseMatrix = EvolutionError, Stored = self.EvolutionErrorStored)
299     if self.EvolutionErrorType == "DiagonalSparseMatrix":
300       self.ADD.setEvolutionError(DiagonalSparseMatrix = EvolutionError, Stored = self.EvolutionErrorStored)
301
302   #--------------------------------------
303
304   def getYIEvolutionModelType(self, Name):
305     rtn = None
306     try:
307       rtn = self.EvolutionModelType[Name]
308     except:
309       pass
310     return rtn
311
312   def setYIEvolutionModelType(self, Name, Type):
313     if Type in ("Matrix", "Function"):
314       self.EvolutionModelType[Name] = Type
315     else:
316       raise daError("[daStudy::setYIEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
317
318   def setYIEvolutionModel(self, Name, EvolutionModel):
319     try:
320       self.EvolutionModelType[Name]
321     except AttributeError:
322       raise daError("[daStudy::setYIEvolutionModel] Type is not defined !")
323     if self.EvolutionModelType[Name] == "Matrix":
324       self.ADD.setEvolutionModel(Matrix = EvolutionModel)
325     elif self.EvolutionModelType[Name] == "Function":
326       self.FunctionEvolutionModel[Name] = EvolutionModel
327
328   #--------------------------------------
329
330   def addYIObserver(self, name, scheduler, info, number):
331     self.observers_dict[name] = {}
332     self.observers_dict[name]["scheduler"] = scheduler
333     self.observers_dict[name]["info"] = info
334     self.observers_dict[name]["number"] = number
335