]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Updating copyright dates
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2 # Copyright (C) 2010-2012 EDF R&D
3 #
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License.
8 #
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 # Lesser General Public License for more details.
13 #
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 #
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
21
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
24 import logging
25
26 class daError(Exception):
27   def __init__(self, value):
28     self.value = value
29   def __str__(self):
30     return repr(self.value)
31
32 class daStudy:
33
34   def __init__(self, name, algorithm, debug):
35
36     self.ADD = AssimilationStudy(name)
37     self.ADD.setControls()
38     self.algorithm = algorithm
39     self.algorithm_dict = None
40     self.Background = None
41     self.CheckingPoint = None
42     self.InputVariables = {}
43     self.OutputVariables = {}
44     self.InputVariablesOrder = []
45     self.OutputVariablesOrder = []
46     self.observers_dict = {}
47
48     self.debug = debug
49     if self.debug:
50       logging.getLogger().setLevel(logging.DEBUG)
51     else:
52       logging.getLogger().setLevel(logging.WARNING)
53
54     # Observation Management
55     self.ObservationOperatorType = {}
56     self.FunctionObservationOperator = {}
57
58     # Evolution Management
59     self.EvolutionModelType = {}
60     self.FunctionEvolutionModel = {}
61
62   #--------------------------------------
63
64   def setInputVariable(self, name, size):
65     self.InputVariables[name] = size
66     self.InputVariablesOrder.append(name)
67
68   def setOutputVariable(self, name, size):
69     self.OutputVariables[name] = size
70     self.OutputVariablesOrder.append(name)
71
72   #--------------------------------------
73
74   def setAlgorithmParameters(self, parameters):
75     self.algorithm_dict = parameters
76
77   #--------------------------------------
78
79   def initAlgorithm(self):
80     self.ADD.setAlgorithm(choice=self.algorithm)
81     if self.algorithm_dict != None:
82       logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
83       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
84
85   #--------------------------------------
86
87   def getAssimilationStudy(self):
88     return self.ADD
89
90   #--------------------------------------
91   # Methods to initialize AssimilationStudy
92
93   def setBackgroundType(self, Type):
94     if Type == "Vector":
95       self.BackgroundType = Type
96     else:
97       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + ". Types are : Vector")
98
99   def setBackgroundStored(self, Stored):
100     if Stored:
101       self.BackgroundStored = True
102     else:
103       self.BackgroundStored = False
104
105   def setBackground(self, Background):
106     try:
107       self.BackgroundType
108       self.BackgroundStored
109     except AttributeError:
110       raise daError("[daStudy::setBackground] Type or Storage is not defined !")
111     self.Background = Background
112     if self.BackgroundType == "Vector":
113       self.ADD.setBackground(asVector = Background, toBeStored = self.BackgroundStored)
114
115   def getBackground(self):
116     return self.Background
117
118   #--------------------------------------
119
120   def setCheckingPointType(self, Type):
121     if Type == "Vector":
122       self.CheckingPointType = Type
123     else:
124       raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + ". Types are : Vector")
125
126   def setCheckingPointStored(self, Stored):
127     if Stored:
128       self.CheckingPointStored = True
129     else:
130       self.CheckingPointStored = False
131
132   def setCheckingPoint(self, CheckingPoint):
133     try:
134       self.CheckingPointType
135       self.CheckingPointStored
136     except AttributeError:
137       raise daError("[daStudy::setCheckingPoint] Type or Storage is not defined !")
138     self.CheckingPoint = CheckingPoint
139     if self.CheckingPointType == "Vector":
140       self.ADD.setBackground(asVector = CheckingPoint, toBeStored = self.CheckingPointStored)
141
142   #--------------------------------------
143
144   def setBackgroundErrorStored(self, Stored):
145     if Stored:
146       self.BackgroundErrorStored = True
147     else:
148       self.BackgroundErrorStored = False
149
150   def setBackgroundError(self, BackgroundError):
151     try:
152       self.BackgroundErrorStored
153     except AttributeError:
154       raise daError("[daStudy::setBackgroundError] Storage is not defined !")
155     self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
156
157   #--------------------------------------
158
159   def setObservationType(self, Type):
160     if Type == "Vector" or Type == "VectorSerie":
161       self.ObservationType = Type
162     else:
163       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
164
165   def setObservationStored(self, Stored):
166     if Stored:
167       self.ObservationStored = True
168     else:
169       self.ObservationStored = False
170
171   def setObservation(self, Observation):
172     try:
173       self.ObservationType
174       self.ObservationStored
175     except AttributeError:
176       raise daError("[daStudy::setObservation] Type or Storage is not defined !")
177     if self.ObservationType == "Vector":
178       self.ADD.setObservation(asVector = Observation, toBeStored = self.ObservationStored)
179     if self.ObservationType == "VectorSerie":
180       self.ADD.setObservation(asPersistentVector = Observation, toBeStored = self.ObservationStored)
181
182   #--------------------------------------
183
184   def setObservationErrorStored(self, Stored):
185     if Stored:
186       self.ObservationErrorStored = True
187     else:
188       self.ObservationErrorStored = False
189
190   def setObservationError(self, ObservationError):
191     try:
192       self.ObservationErrorStored
193     except AttributeError:
194       raise daError("[daStudy::setObservationError] Storage is not defined !")
195     self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
196
197   #--------------------------------------
198
199   def getObservationOperatorType(self, Name):
200     rtn = None
201     try:
202       rtn = self.ObservationOperatorType[Name]
203     except:
204       pass
205     return rtn
206
207   def setObservationOperatorType(self, Name, Type):
208     if Type == "Matrix":
209       self.ObservationOperatorType[Name] = Type
210     elif Type == "Function":
211       self.ObservationOperatorType[Name] = Type
212     else:
213       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + ". Types are : Matrix, Function")
214
215   def setObservationOperator(self, Name, ObservationOperator):
216     try:
217       self.ObservationOperatorType[Name]
218     except AttributeError:
219       raise daError("[daStudy::setObservationOperator] Type is not defined !")
220     if self.ObservationOperatorType[Name] == "Matrix":
221       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
222     elif self.ObservationOperatorType[Name] == "Function":
223       self.FunctionObservationOperator[Name] = ObservationOperator
224
225   #--------------------------------------
226
227   def setEvolutionErrorStored(self, Stored):
228     if Stored:
229       self.EvolutionErrorStored = True
230     else:
231       self.EvolutionErrorStored = False
232
233   def setEvolutionError(self, EvolutionError):
234     try:
235       self.EvolutionErrorStored
236     except AttributeError:
237       raise daError("[daStudy::setEvolutionError] Storage is not defined !")
238     self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
239
240   #--------------------------------------
241
242   def getEvolutionModelType(self, Name):
243     rtn = None
244     try:
245       rtn = self.EvolutionModelType[Name]
246     except:
247       pass
248     return rtn
249
250   def setEvolutionModelType(self, Name, Type):
251     if Type == "Matrix":
252       self.EvolutionModelType[Name] = Type
253     elif Type == "Function":
254       self.EvolutionModelType[Name] = Type
255     else:
256       raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + ". Types are : Matrix, Function")
257
258   def setEvolutionModel(self, Name, EvolutionModel):
259     try:
260       self.EvolutionModelType[Name]
261     except AttributeError:
262       raise daError("[daStudy::setEvolutionModel] Type is not defined !")
263     if self.EvolutionModelType[Name] == "Matrix":
264       self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
265     elif self.EvolutionModelType[Name] == "Function":
266       self.FunctionEvolutionModel[Name] = EvolutionModel
267
268   #--------------------------------------
269
270   def addObserver(self, name, scheduler, info, number):
271     self.observers_dict[name] = {}
272     self.observers_dict[name]["scheduler"] = scheduler
273     self.observers_dict[name]["info"] = info
274     self.observers_dict[name]["number"] = number
275
276   def getObservers(self):
277     return self.observers_dict