3 # Copyright (C) 2008-2024 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.Aidsm import Aidsm
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 = Aidsm(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 = {}
52 logging.getLogger().setLevel(logging.DEBUG)
54 logging.getLogger().setLevel(logging.WARNING)
56 # Observation Management
57 self.ObservationOperatorType = {}
58 self.FunctionObservationOperator = {}
60 # Evolution Management
61 self.EvolutionModelType = {}
62 self.FunctionEvolutionModel = {}
64 def setYIInputVariable(self, name, size):
65 self.InputVariables[name] = size
66 self.InputVariablesOrder.append(name)
68 def setYIOutputVariable(self, name, size):
69 self.OutputVariables[name] = size
70 self.OutputVariablesOrder.append(name)
72 def setYIAlgorithmParameters(self, parameters):
73 self.algorithm_dict = parameters
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)
81 def YI_prepare_to_pickle(self):
82 return self.ADD.prepare_to_pickle()
84 #--------------------------------------
87 return ['getResults', '__doc__', '__init__', '__module__']
90 "Unique méthode à ne pas inclure YI"
93 #--------------------------------------
94 # Methods to initialize assimilation study
96 def setYIBackgroundType(self, Type):
98 self.BackgroundType = Type
100 raise daError("[daStudy::setYIBackgroundType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
102 def setYIBackgroundStored(self, Stored):
104 self.BackgroundStored = True
106 self.BackgroundStored = False
108 def setYIBackground(self, Background):
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)
118 def getYIBackground(self):
119 return self.Background
121 #--------------------------------------
123 def setYICheckingPointType(self, Type):
125 self.CheckingPointType = Type
127 raise daError("[daStudy::setYICheckingPointType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
129 def setYICheckingPointStored(self, Stored):
131 self.CheckingPointStored = True
133 self.CheckingPointStored = False
135 def setYICheckingPoint(self, CheckingPoint):
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)
145 #--------------------------------------
147 def setYIBackgroundErrorType(self, Type):
148 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
149 self.BackgroundErrorType = Type
151 raise daError("[daStudy::setYIBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
153 def setYIBackgroundErrorStored(self, Stored):
155 self.BackgroundErrorStored = True
157 self.BackgroundErrorStored = False
159 def setYIBackgroundError(self, BackgroundError):
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)
172 #--------------------------------------
174 def setYIControlInputType(self, Type):
175 if Type in ("Vector", "VectorSerie"):
176 self.ControlInputType = Type
178 raise daError("[daStudy::setYIControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
180 def setYIControlInputStored(self, Stored):
182 self.ControlInputStored = True
184 self.ControlInputStored = False
186 def setYIControlInput(self, ControlInput):
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)
197 #--------------------------------------
199 def setYIObservationType(self, Type):
200 if Type in ("Vector", "VectorSerie"):
201 self.ObservationType = Type
203 raise daError("[daStudy::setYIObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
205 def setYIObservationStored(self, Stored):
207 self.ObservationStored = True
209 self.ObservationStored = False
211 def setYIObservation(self, Observation):
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)
222 #--------------------------------------
224 def setYIObservationErrorType(self, Type):
225 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
226 self.ObservationErrorType = Type
228 raise daError("[daStudy::setYIObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
230 def setYIObservationErrorStored(self, Stored):
232 self.ObservationErrorStored = True
234 self.ObservationErrorStored = False
236 def setYIObservationError(self, ObservationError):
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)
249 #--------------------------------------
251 def getYIObservationOperatorType(self, Name):
254 rtn = self.ObservationOperatorType[Name]
259 def setYIObservationOperatorType(self, Name, Type):
260 if Type in ("Matrix", "Function"):
261 self.ObservationOperatorType[Name] = Type
263 raise daError("[daStudy::setYIObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
265 def setYIObservationOperator(self, Name, ObservationOperator):
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
275 #--------------------------------------
277 def setYIEvolutionErrorType(self, Type):
278 if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
279 self.EvolutionErrorType = Type
281 raise daError("[daStudy::setYIEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
283 def setYIEvolutionErrorStored(self, Stored):
285 self.EvolutionErrorStored = True
287 self.EvolutionErrorStored = False
289 def setYIEvolutionError(self, EvolutionError):
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)
302 #--------------------------------------
304 def getYIEvolutionModelType(self, Name):
307 rtn = self.EvolutionModelType[Name]
312 def setYIEvolutionModelType(self, Name, Type):
313 if Type in ("Matrix", "Function"):
314 self.EvolutionModelType[Name] = Type
316 raise daError("[daStudy::setYIEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
318 def setYIEvolutionModel(self, Name, EvolutionModel):
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
328 #--------------------------------------
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