]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Updating copyright notices
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*-coding:iso-8859-1-*-
2 #
3 # Copyright (C) 2010-2012 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 setObservationType(self, Type):
161     if Type == "Vector" or Type == "VectorSerie":
162       self.ObservationType = Type
163     else:
164       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
165
166   def setObservationStored(self, Stored):
167     if Stored:
168       self.ObservationStored = True
169     else:
170       self.ObservationStored = False
171
172   def setObservation(self, Observation):
173     try:
174       self.ObservationType
175       self.ObservationStored
176     except AttributeError:
177       raise daError("[daStudy::setObservation] Type or Storage is not defined !")
178     if self.ObservationType == "Vector":
179       self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
180     if self.ObservationType == "VectorSerie":
181       self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
182
183   #--------------------------------------
184
185   def setObservationErrorStored(self, Stored):
186     if Stored:
187       self.ObservationErrorStored = True
188     else:
189       self.ObservationErrorStored = False
190
191   def setObservationError(self, ObservationError):
192     try:
193       self.ObservationErrorStored
194     except AttributeError:
195       raise daError("[daStudy::setObservationError] Storage is not defined !")
196     self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
197
198   #--------------------------------------
199
200   def getObservationOperatorType(self, Name):
201     rtn = None
202     try:
203       rtn = self.ObservationOperatorType[Name]
204     except:
205       pass
206     return rtn
207
208   def setObservationOperatorType(self, Name, Type):
209     if Type == "Matrix":
210       self.ObservationOperatorType[Name] = Type
211     elif Type == "Function":
212       self.ObservationOperatorType[Name] = Type
213     else:
214       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + ". Types are : Matrix, Function")
215
216   def setObservationOperator(self, Name, ObservationOperator):
217     try:
218       self.ObservationOperatorType[Name]
219     except AttributeError:
220       raise daError("[daStudy::setObservationOperator] Type is not defined !")
221     if self.ObservationOperatorType[Name] == "Matrix":
222       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
223     elif self.ObservationOperatorType[Name] == "Function":
224       self.FunctionObservationOperator[Name] = ObservationOperator
225
226   #--------------------------------------
227
228   def setEvolutionErrorStored(self, Stored):
229     if Stored:
230       self.EvolutionErrorStored = True
231     else:
232       self.EvolutionErrorStored = False
233
234   def setEvolutionError(self, EvolutionError):
235     try:
236       self.EvolutionErrorStored
237     except AttributeError:
238       raise daError("[daStudy::setEvolutionError] Storage is not defined !")
239     self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
240
241   #--------------------------------------
242
243   def getEvolutionModelType(self, Name):
244     rtn = None
245     try:
246       rtn = self.EvolutionModelType[Name]
247     except:
248       pass
249     return rtn
250
251   def setEvolutionModelType(self, Name, Type):
252     if Type == "Matrix":
253       self.EvolutionModelType[Name] = Type
254     elif Type == "Function":
255       self.EvolutionModelType[Name] = Type
256     else:
257       raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + ". Types are : Matrix, Function")
258
259   def setEvolutionModel(self, Name, EvolutionModel):
260     try:
261       self.EvolutionModelType[Name]
262     except AttributeError:
263       raise daError("[daStudy::setEvolutionModel] Type is not defined !")
264     if self.EvolutionModelType[Name] == "Matrix":
265       self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
266     elif self.EvolutionModelType[Name] == "Function":
267       self.FunctionEvolutionModel[Name] = EvolutionModel
268
269   #--------------------------------------
270
271   def addObserver(self, name, scheduler, info, number):
272     self.observers_dict[name] = {}
273     self.observers_dict[name]["scheduler"] = scheduler
274     self.observers_dict[name]["info"] = info
275     self.observers_dict[name]["number"] = number
276
277   def getObservers(self):
278     return self.observers_dict