]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
Adding checking algorithms environment
[modules/adao.git] / src / daSalome / daYacsIntegration / daStudy.py
1 #-*- coding: utf-8 -*-
2 # Copyright (C) 2010-2011 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.EvolutionModelType = {}
57     self.FunctionObservationOperator = {}
58
59   #--------------------------------------
60
61   def setInputVariable(self, name, size):
62     self.InputVariables[name] = size
63     self.InputVariablesOrder.append(name)
64
65   def setOutputVariable(self, name, size):
66     self.OutputVariables[name] = size
67     self.OutputVariablesOrder.append(name)
68
69   #--------------------------------------
70
71   def setAlgorithmParameters(self, parameters):
72     self.algorithm_dict = parameters
73
74   #--------------------------------------
75
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)
81
82   #--------------------------------------
83
84   def getAssimilationStudy(self):
85     return self.ADD
86
87   #--------------------------------------
88   # Methods to initialize AssimilationStudy
89
90   def setBackgroundType(self, Type):
91     if Type == "Vector":
92       self.BackgroundType = Type
93     else:
94       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
95
96   def setBackground(self, Background):
97     try:
98       self.BackgroundType
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)
104
105   def getBackground(self):
106     return self.Background
107
108   #--------------------------------------
109
110   def setCheckingPointType(self, Type):
111     if Type == "Vector":
112       self.CheckingPointType = Type
113     else:
114       raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + " Types are : Vector")
115
116   def setCheckingPoint(self, CheckingPoint):
117     try:
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)
124
125   #--------------------------------------
126
127   def setBackgroundError(self, BackgroundError):
128     self.ADD.setBackgroundError(asCovariance = BackgroundError)
129
130   #--------------------------------------
131
132   def setObservationType(self, Type):
133     if Type == "Vector":
134       self.ObservationType = Type
135     else:
136       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
137
138   def setObservation(self, Observation):
139     try:
140       self.ObservationType
141     except AttributeError:
142       raise daError("[daStudy::setObservation] Type is not defined !")
143     if self.ObservationType == "Vector":
144       self.ADD.setObservation(asVector = Observation)
145
146   #--------------------------------------
147
148   def setObservationError(self, ObservationError):
149     self.ADD.setObservationError(asCovariance = ObservationError)
150
151   #--------------------------------------
152
153   def getObservationOperatorType(self, Name):
154     rtn = None
155     try:
156       rtn = self.ObservationOperatorType[Name]
157     except:
158       pass
159     return rtn
160
161   def setObservationOperatorType(self, Name, Type):
162     if Type == "Matrix":
163       self.ObservationOperatorType[Name] = Type
164     elif Type == "Function":
165       self.ObservationOperatorType[Name] = Type
166     else:
167       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
168
169   def setObservationOperator(self, Name, ObservationOperator):
170     try:
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
178
179   #--------------------------------------
180
181   def getEvolutionModelType(self, Name):
182     rtn = None
183     try:
184       rtn = self.EvolutionModelType[Name]
185     except:
186       pass
187     return rtn
188
189   def setEvolutionModelType(self, Name, Type):
190     if Type == "Matrix":
191       self.EvolutionModelType[Name] = Type
192     elif Type == "Function":
193       self.EvolutionModelType[Name] = Type
194     else:
195       raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
196
197   def setEvolutionModel(self, Name, EvolutionModel):
198     try:
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
206
207   #--------------------------------------
208
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
214
215   def getObservers(self):
216     return self.observers_dict