2 # Copyright (C) 2010-2011 EDF R&D
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.
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.
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
18 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 # Author: André Ribes, andre.ribes@edf.fr, EDF R&D
22 from daCore.AssimilationStudy import AssimilationStudy
23 from daCore import Logging
26 class daError(Exception):
27 def __init__(self, value):
30 return repr(self.value)
34 def __init__(self, name, algorithm, debug):
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 = {}
50 logging.getLogger().setLevel(logging.DEBUG)
52 logging.getLogger().setLevel(logging.WARNING)
54 # Observation Management
55 self.ObservationOperatorType = {}
56 self.EvolutionModelType = {}
57 self.FunctionObservationOperator = {}
59 #--------------------------------------
61 def setInputVariable(self, name, size):
62 self.InputVariables[name] = size
63 self.InputVariablesOrder.append(name)
65 def setOutputVariable(self, name, size):
66 self.OutputVariables[name] = size
67 self.OutputVariablesOrder.append(name)
69 #--------------------------------------
71 def setAlgorithmParameters(self, parameters):
72 self.algorithm_dict = parameters
74 #--------------------------------------
76 def initAlgorithm(self):
77 self.ADD.setAlgorithm(choice=self.algorithm)
78 if self.algorithm_dict != None:
79 logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
80 self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
82 #--------------------------------------
84 def getAssimilationStudy(self):
87 #--------------------------------------
88 # Methods to initialize AssimilationStudy
90 def setBackgroundType(self, Type):
92 self.BackgroundType = Type
94 raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
96 def setBackground(self, Background):
99 except AttributeError:
100 raise daError("[daStudy::setBackground] Type is not defined !")
101 self.Background = Background
102 if self.BackgroundType == "Vector":
103 self.ADD.setBackground(asVector = Background)
105 def getBackground(self):
106 return self.Background
108 #--------------------------------------
110 def setCheckingPointType(self, Type):
112 self.CheckingPointType = Type
114 raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + " Types are : Vector")
116 def setCheckingPoint(self, CheckingPoint):
118 self.CheckingPointType
119 except AttributeError:
120 raise daError("[daStudy::setCheckingPoint] Type is not defined !")
121 self.CheckingPoint = CheckingPoint
122 if self.CheckingPointType == "Vector":
123 self.ADD.setBackground(asVector = CheckingPoint)
125 #--------------------------------------
127 def setBackgroundError(self, BackgroundError):
128 self.ADD.setBackgroundError(asCovariance = BackgroundError)
130 #--------------------------------------
132 def setObservationType(self, Type):
134 self.ObservationType = Type
136 raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
138 def setObservation(self, Observation):
141 except AttributeError:
142 raise daError("[daStudy::setObservation] Type is not defined !")
143 if self.ObservationType == "Vector":
144 self.ADD.setObservation(asVector = Observation)
146 #--------------------------------------
148 def setObservationError(self, ObservationError):
149 self.ADD.setObservationError(asCovariance = ObservationError)
151 #--------------------------------------
153 def getObservationOperatorType(self, Name):
156 rtn = self.ObservationOperatorType[Name]
161 def setObservationOperatorType(self, Name, Type):
163 self.ObservationOperatorType[Name] = Type
164 elif Type == "Function":
165 self.ObservationOperatorType[Name] = Type
167 raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
169 def setObservationOperator(self, Name, ObservationOperator):
171 self.ObservationOperatorType[Name]
172 except AttributeError:
173 raise daError("[daStudy::setObservationOperator] Type is not defined !")
174 if self.ObservationOperatorType[Name] == "Matrix":
175 self.ADD.setObservationOperator(asMatrix = ObservationOperator)
176 elif self.ObservationOperatorType[Name] == "Function":
177 self.FunctionObservationOperator[Name] = ObservationOperator
179 #--------------------------------------
181 def getEvolutionModelType(self, Name):
184 rtn = self.EvolutionModelType[Name]
189 def setEvolutionModelType(self, Name, Type):
191 self.EvolutionModelType[Name] = Type
192 elif Type == "Function":
193 self.EvolutionModelType[Name] = Type
195 raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
197 def setEvolutionModel(self, Name, EvolutionModel):
199 self.EvolutionModelType[Name]
200 except AttributeError:
201 raise daError("[daStudy::setEvolutionModel] Type is not defined !")
202 if self.EvolutionModelType[Name] == "Matrix":
203 self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
204 elif self.EvolutionModelType[Name] == "Function":
205 self.FunctionEvolutionModel[Name] = EvolutionModel
207 #--------------------------------------
209 def addObserver(self, name, scheduler, info, number):
210 self.observers_dict[name] = {}
211 self.observers_dict[name]["scheduler"] = scheduler
212 self.observers_dict[name]["info"] = info
213 self.observers_dict[name]["number"] = number
215 def getObservers(self):
216 return self.observers_dict