]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
c25b454bde5586dc100ab2c72b3c11b7f371c3b0
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*-coding:iso-8859-1-*-
2 #
3 # Copyright (C) 2008-2015 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.ADD.setControls()
41     self.algorithm = algorithm
42     self.algorithm_dict = None
43     self.Background = None
44     self.CheckingPoint = None
45     self.InputVariables = {}
46     self.OutputVariables = {}
47     self.InputVariablesOrder = []
48     self.OutputVariablesOrder = []
49     self.observers_dict = {}
50
51     self.debug = debug
52     if self.debug:
53       logging.getLogger().setLevel(logging.DEBUG)
54     else:
55       logging.getLogger().setLevel(logging.WARNING)
56
57     # Observation Management
58     self.ObservationOperatorType = {}
59     self.FunctionObservationOperator = {}
60
61     # Evolution Management
62     self.EvolutionModelType = {}
63     self.FunctionEvolutionModel = {}
64
65   #--------------------------------------
66
67   def setInputVariable(self, name, size):
68     self.InputVariables[name] = size
69     self.InputVariablesOrder.append(name)
70
71   def setOutputVariable(self, name, size):
72     self.OutputVariables[name] = size
73     self.OutputVariablesOrder.append(name)
74
75   #--------------------------------------
76
77   def setAlgorithmParameters(self, parameters):
78     self.algorithm_dict = parameters
79
80   #--------------------------------------
81
82   def initAlgorithm(self):
83     self.ADD.setAlgorithm(choice=self.algorithm)
84     if self.algorithm_dict != None:
85       logging.debug("DASTUDY AlgorithmParameters: "+str(self.algorithm_dict))
86       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
87
88   #--------------------------------------
89
90   def __dir__(self):
91     return ['getResults', '__doc__', '__init__', '__module__']
92
93   def getAssimilationStudy(self):
94     # Ancien appel a resorber
95     return self.ADD
96
97   def getResults(self):
98     return self.ADD
99
100   #--------------------------------------
101   # Methods to initialize AssimilationStudy
102
103   def setBackgroundType(self, Type):
104     if Type == "Vector":
105       self.BackgroundType = Type
106     else:
107       raise daError("[daStudy::setBackgroundType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
108
109   def setBackgroundStored(self, Stored):
110     if Stored:
111       self.BackgroundStored = True
112     else:
113       self.BackgroundStored = False
114
115   def setBackground(self, Background):
116     try:
117       self.BackgroundType
118       self.BackgroundStored
119     except AttributeError:
120       raise daError("[daStudy::setBackground] Type or Storage is not defined !")
121     self.Background = Background
122     if self.BackgroundType == "Vector":
123       self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
124
125   def getBackground(self):
126     return self.Background
127
128   #--------------------------------------
129
130   def setCheckingPointType(self, Type):
131     if Type == "Vector":
132       self.CheckingPointType = Type
133     else:
134       raise daError("[daStudy::setCheckingPointType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
135
136   def setCheckingPointStored(self, Stored):
137     if Stored:
138       self.CheckingPointStored = True
139     else:
140       self.CheckingPointStored = False
141
142   def setCheckingPoint(self, CheckingPoint):
143     try:
144       self.CheckingPointType
145       self.CheckingPointStored
146     except AttributeError:
147       raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
148     self.CheckingPoint = CheckingPoint
149     if self.CheckingPointType == "Vector":
150       self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
151
152   #--------------------------------------
153
154   def setBackgroundErrorType(self, Type):
155     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
156       self.BackgroundErrorType = Type
157     else:
158       raise daError("[daStudy::setBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
159
160   def setBackgroundErrorStored(self, Stored):
161     if Stored:
162       self.BackgroundErrorStored = True
163     else:
164       self.BackgroundErrorStored = False
165
166   def setBackgroundError(self, BackgroundError):
167     try:
168       self.BackgroundErrorType
169       self.BackgroundErrorStored
170     except AttributeError:
171       raise daError("[daStudy::setBackgroundError] Type or Storage is not defined !")
172     if self.BackgroundErrorType == "Matrix":
173       self.ADD.setBackgroundError(asCovariance  = BackgroundError, toBeStored = self.BackgroundErrorStored)
174     if self.BackgroundErrorType == "ScalarSparseMatrix":
175       self.ADD.setBackgroundError(asEyeByScalar = BackgroundError, toBeStored = self.BackgroundErrorStored)
176     if self.BackgroundErrorType == "DiagonalSparseMatrix":
177       self.ADD.setBackgroundError(asEyeByVector = BackgroundError, toBeStored = self.BackgroundErrorStored)
178
179   #--------------------------------------
180
181   def setControlInputType(self, Type):
182     if Type in ("Vector", "VectorSerie"):
183       self.ControlInputType = Type
184     else:
185       raise daError("[daStudy::setControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
186
187   def setControlInputStored(self, Stored):
188     if Stored:
189       self.ControlInputStored = True
190     else:
191       self.ControlInputStored = False
192
193   def setControlInput(self, ControlInput):
194     try:
195       self.ControlInputType
196       self.ControlInputStored
197     except AttributeError:
198       raise daError("[daStudy::setControlInput] Type or Storage is not defined !")
199     if self.ControlInputType == "Vector":
200       self.ADD.setControlInput(asVector = ControlInput, toBeStored = self.ControlInputStored)
201     if self.ControlInputType == "VectorSerie":
202       self.ADD.setControlInput(asPersistentVector = ControlInput, toBeStored = self.ControlInputStored)
203
204   #--------------------------------------
205
206   def setObservationType(self, Type):
207     if Type in ("Vector", "VectorSerie"):
208       self.ObservationType = Type
209     else:
210       raise daError("[daStudy::setObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
211
212   def setObservationStored(self, Stored):
213     if Stored:
214       self.ObservationStored = True
215     else:
216       self.ObservationStored = False
217
218   def setObservation(self, Observation):
219     try:
220       self.ObservationType
221       self.ObservationStored
222     except AttributeError:
223       raise daError("[daStudy::setObservation] Type or Storage is not defined !")
224     if self.ObservationType == "Vector":
225       self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
226     if self.ObservationType == "VectorSerie":
227       self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
228
229   #--------------------------------------
230
231   def setObservationErrorType(self, Type):
232     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
233       self.ObservationErrorType = Type
234     else:
235       raise daError("[daStudy::setObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
236
237   def setObservationErrorStored(self, Stored):
238     if Stored:
239       self.ObservationErrorStored = True
240     else:
241       self.ObservationErrorStored = False
242
243   def setObservationError(self, ObservationError):
244     try:
245       self.ObservationErrorType
246       self.ObservationErrorStored
247     except AttributeError:
248       raise daError("[daStudy::setObservationError] Type or Storage is not defined !")
249     if self.ObservationErrorType == "Matrix":
250       self.ADD.setObservationError(asCovariance  = ObservationError, toBeStored = self.ObservationErrorStored)
251     if self.ObservationErrorType == "ScalarSparseMatrix":
252       self.ADD.setObservationError(asEyeByScalar = ObservationError, toBeStored = self.ObservationErrorStored)
253     if self.ObservationErrorType == "DiagonalSparseMatrix":
254       self.ADD.setObservationError(asEyeByVector = ObservationError, toBeStored = self.ObservationErrorStored)
255
256   #--------------------------------------
257
258   def getObservationOperatorType(self, Name):
259     rtn = None
260     try:
261       rtn = self.ObservationOperatorType[Name]
262     except:
263       pass
264     return rtn
265
266   def setObservationOperatorType(self, Name, Type):
267     if Type in ("Matrix", "Function"):
268       self.ObservationOperatorType[Name] = Type
269     else:
270       raise daError("[daStudy::setObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
271
272   def setObservationOperator(self, Name, ObservationOperator):
273     try:
274       self.ObservationOperatorType[Name]
275     except AttributeError:
276       raise daError("[daStudy::setObservationOperator] Type is not defined !")
277     if self.ObservationOperatorType[Name] == "Matrix":
278       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
279     elif self.ObservationOperatorType[Name] == "Function":
280       self.FunctionObservationOperator[Name] = ObservationOperator
281
282   #--------------------------------------
283
284   def setEvolutionErrorType(self, Type):
285     if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
286       self.EvolutionErrorType = Type
287     else:
288       raise daError("[daStudy::setEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
289
290   def setEvolutionErrorStored(self, Stored):
291     if Stored:
292       self.EvolutionErrorStored = True
293     else:
294       self.EvolutionErrorStored = False
295
296   def setEvolutionError(self, EvolutionError):
297     try:
298       self.EvolutionErrorType
299       self.EvolutionErrorStored
300     except AttributeError:
301       raise daError("[daStudy::setEvolutionError] Type or Storage is not defined !")
302     if self.EvolutionErrorType == "Matrix":
303       self.ADD.setEvolutionError(asCovariance  = EvolutionError, toBeStored = self.EvolutionErrorStored)
304     if self.EvolutionErrorType == "ScalarSparseMatrix":
305       self.ADD.setEvolutionError(asEyeByScalar = EvolutionError, toBeStored = self.EvolutionErrorStored)
306     if self.EvolutionErrorType == "DiagonalSparseMatrix":
307       self.ADD.setEvolutionError(asEyeByVector = EvolutionError, toBeStored = self.EvolutionErrorStored)
308
309   #--------------------------------------
310
311   def getEvolutionModelType(self, Name):
312     rtn = None
313     try:
314       rtn = self.EvolutionModelType[Name]
315     except:
316       pass
317     return rtn
318
319   def setEvolutionModelType(self, Name, Type):
320     if Type in ("Matrix", "Function"):
321       self.EvolutionModelType[Name] = Type
322     else:
323       raise daError("[daStudy::setEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
324
325   def setEvolutionModel(self, Name, EvolutionModel):
326     try:
327       self.EvolutionModelType[Name]
328     except AttributeError:
329       raise daError("[daStudy::setEvolutionModel] Type is not defined !")
330     if self.EvolutionModelType[Name] == "Matrix":
331       self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
332     elif self.EvolutionModelType[Name] == "Function":
333       self.FunctionEvolutionModel[Name] = EvolutionModel
334
335   #--------------------------------------
336
337   def addObserver(self, name, scheduler, info, number):
338     self.observers_dict[name] = {}
339     self.observers_dict[name]["scheduler"] = scheduler
340     self.observers_dict[name]["info"] = info
341     self.observers_dict[name]["number"] = number
342
343   def getObservers(self):
344     return self.observers_dict