1 #-*-coding:iso-8859-1-*-
3 # Copyright (C) 2008-2015 EDF R&D
5 # This file is part of SALOME ADAO module
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.
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.
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
21 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 # Author: Jean-Philippe Argaud, jean-philippe.argaud@edf.fr, EDF R&D
25 from daCore.AssimilationStudy import AssimilationStudy
26 #from daCore import Logging
29 class daError(Exception):
30 def __init__(self, value):
33 return repr(self.value)
37 def __init__(self, name, algorithm, debug):
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 = {}
53 logging.getLogger().setLevel(logging.DEBUG)
55 logging.getLogger().setLevel(logging.WARNING)
57 # Observation Management
58 self.ObservationOperatorType = {}
59 self.FunctionObservationOperator = {}
61 # Evolution Management
62 self.EvolutionModelType = {}
63 self.FunctionEvolutionModel = {}
65 #--------------------------------------
67 def setInputVariable(self, name, size):
68 self.InputVariables[name] = size
69 self.InputVariablesOrder.append(name)
71 def setOutputVariable(self, name, size):
72 self.OutputVariables[name] = size
73 self.OutputVariablesOrder.append(name)
75 #--------------------------------------
77 def setAlgorithmParameters(self, parameters):
78 self.algorithm_dict = parameters
80 #--------------------------------------
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)
88 #--------------------------------------
91 return ['getResults', '__doc__', '__init__', '__module__']
93 def getAssimilationStudy(self):
94 # Ancien appel a resorber
100 #--------------------------------------
101 # Methods to initialize AssimilationStudy
103 def setBackgroundType(self, Type):
105 self.BackgroundType = Type
107 raise daError("[daStudy::setBackgroundType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
109 def setBackgroundStored(self, Stored):
111 self.BackgroundStored = True
113 self.BackgroundStored = False
115 def setBackground(self, Background):
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)
125 def getBackground(self):
126 return self.Background
128 #--------------------------------------
130 def setCheckingPointType(self, Type):
132 self.CheckingPointType = Type
134 raise daError("[daStudy::setCheckingPointType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
136 def setCheckingPointStored(self, Stored):
138 self.CheckingPointStored = True
140 self.CheckingPointStored = False
142 def setCheckingPoint(self, CheckingPoint):
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)
152 #--------------------------------------
154 def setBackgroundErrorType(self, Type):
155 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
156 self.BackgroundErrorType = Type
158 raise daError("[daStudy::setBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
160 def setBackgroundErrorStored(self, Stored):
162 self.BackgroundErrorStored = True
164 self.BackgroundErrorStored = False
166 def setBackgroundError(self, BackgroundError):
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)
179 #--------------------------------------
181 def setControlInputType(self, Type):
182 if Type in ("Vector", "VectorSerie"):
183 self.ControlInputType = Type
185 raise daError("[daStudy::setControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
187 def setControlInputStored(self, Stored):
189 self.ControlInputStored = True
191 self.ControlInputStored = False
193 def setControlInput(self, ControlInput):
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)
204 #--------------------------------------
206 def setObservationType(self, Type):
207 if Type in ("Vector", "VectorSerie"):
208 self.ObservationType = Type
210 raise daError("[daStudy::setObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
212 def setObservationStored(self, Stored):
214 self.ObservationStored = True
216 self.ObservationStored = False
218 def setObservation(self, Observation):
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)
229 #--------------------------------------
231 def setObservationErrorType(self, Type):
232 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
233 self.ObservationErrorType = Type
235 raise daError("[daStudy::setObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
237 def setObservationErrorStored(self, Stored):
239 self.ObservationErrorStored = True
241 self.ObservationErrorStored = False
243 def setObservationError(self, ObservationError):
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)
256 #--------------------------------------
258 def getObservationOperatorType(self, Name):
261 rtn = self.ObservationOperatorType[Name]
266 def setObservationOperatorType(self, Name, Type):
267 if Type in ("Matrix", "Function"):
268 self.ObservationOperatorType[Name] = Type
270 raise daError("[daStudy::setObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
272 def setObservationOperator(self, Name, ObservationOperator):
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
282 #--------------------------------------
284 def setEvolutionErrorType(self, Type):
285 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
286 self.EvolutionErrorType = Type
288 raise daError("[daStudy::setEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
290 def setEvolutionErrorStored(self, Stored):
292 self.EvolutionErrorStored = True
294 self.EvolutionErrorStored = False
296 def setEvolutionError(self, EvolutionError):
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)
309 #--------------------------------------
311 def getEvolutionModelType(self, Name):
314 rtn = self.EvolutionModelType[Name]
319 def setEvolutionModelType(self, Name, Type):
320 if Type in ("Matrix", "Function"):
321 self.EvolutionModelType[Name] = Type
323 raise daError("[daStudy::setEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
325 def setEvolutionModel(self, Name, EvolutionModel):
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
335 #--------------------------------------
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
343 def getObservers(self):
344 return self.observers_dict