]> SALOME platform Git repositories - modules/adao.git/blob - src/daSalome/daYacsIntegration/daStudy.py
Salome HOME
cd708be99ea0445829af9d43f1452543f0077eb8
[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.InputVariables = {}
42     self.OutputVariables = {}
43     self.InputVariablesOrder = []
44     self.OutputVariablesOrder = []
45     self.observers_dict = {}
46
47     self.debug = debug
48     if self.debug:
49       logging.getLogger().setLevel(logging.DEBUG)
50     else:
51       logging.getLogger().setLevel(logging.WARNING)
52
53     # Observation Management
54     self.ObservationOperatorType = {}
55     self.EvolutionModelType = {}
56     self.FunctionObservationOperator = {}
57
58   #--------------------------------------
59
60   def setInputVariable(self, name, size):
61     self.InputVariables[name] = size
62     self.InputVariablesOrder.append(name)
63
64   def setOutputVariable(self, name, size):
65     self.OutputVariables[name] = size
66     self.OutputVariablesOrder.append(name)
67
68   #--------------------------------------
69
70   def setAlgorithmParameters(self, parameters):
71     self.algorithm_dict = parameters
72
73   #--------------------------------------
74
75   def initAlgorithm(self):
76     self.ADD.setAlgorithm(choice=self.algorithm)
77     if self.algorithm_dict != None:
78       logging.debug("ADD.setAlgorithm : "+str(self.algorithm_dict))
79       self.ADD.setAlgorithmParameters(asDico=self.algorithm_dict)
80
81   #--------------------------------------
82
83   def getAssimilationStudy(self):
84     return self.ADD
85
86   #--------------------------------------
87   # Methods to initialize AssimilationStudy
88
89   def setBackgroundType(self, Type):
90     if Type == "Vector":
91       self.BackgroundType = Type
92     else:
93       raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + " Types are : Vector")
94
95   def setBackground(self, Background):
96     try:
97       self.BackgroundType
98     except AttributeError:
99       raise daError("[daStudy::setBackground] Type is not defined !")
100     self.Background = Background
101     if self.BackgroundType == "Vector":
102       self.ADD.setBackground(asVector = Background)
103
104   def getBackground(self):
105     return self.Background
106
107   #--------------------------------------
108
109   def setBackgroundError(self, BackgroundError):
110     self.ADD.setBackgroundError(asCovariance = BackgroundError)
111
112   #--------------------------------------
113
114   def setObservationType(self, Type):
115     if Type == "Vector":
116       self.ObservationType = Type
117     else:
118       raise daError("[daStudy::setObservationType] Type is unkown : " + Type + " Types are : Vector")
119
120   def setObservation(self, Observation):
121     try:
122       self.ObservationType
123     except AttributeError:
124       raise daError("[daStudy::setObservation] Type is not defined !")
125     if self.ObservationType == "Vector":
126       self.ADD.setObservation(asVector = Observation)
127
128   #--------------------------------------
129
130   def setObservationError(self, ObservationError):
131     self.ADD.setObservationError(asCovariance = ObservationError)
132
133   #--------------------------------------
134
135   def getObservationOperatorType(self, Name):
136     rtn = None
137     try:
138       rtn = self.ObservationOperatorType[Name]
139     except:
140       pass
141     return rtn
142
143   def setObservationOperatorType(self, Name, Type):
144     if Type == "Matrix":
145       self.ObservationOperatorType[Name] = Type
146     elif Type == "Function":
147       self.ObservationOperatorType[Name] = Type
148     else:
149       raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + " Types are : Matrix, Function")
150
151   def setObservationOperator(self, Name, ObservationOperator):
152     try:
153       self.ObservationOperatorType[Name]
154     except AttributeError:
155       raise daError("[daStudy::setObservationOperator] Type is not defined !")
156     if self.ObservationOperatorType[Name] == "Matrix":
157       self.ADD.setObservationOperator(asMatrix = ObservationOperator)
158     elif self.ObservationOperatorType[Name] == "Function":
159       self.FunctionObservationOperator[Name] = ObservationOperator
160
161   #--------------------------------------
162
163   def getEvolutionModelType(self, Name):
164     rtn = None
165     try:
166       rtn = self.EvolutionModelType[Name]
167     except:
168       pass
169     return rtn
170
171   def setEvolutionModelType(self, Name, Type):
172     if Type == "Matrix":
173       self.EvolutionModelType[Name] = Type
174     elif Type == "Function":
175       self.EvolutionModelType[Name] = Type
176     else:
177       raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + " Types are : Matrix, Function")
178
179   def setEvolutionModel(self, Name, EvolutionModel):
180     try:
181       self.EvolutionModelType[Name]
182     except AttributeError:
183       raise daError("[daStudy::setEvolutionModel] Type is not defined !")
184     if self.EvolutionModelType[Name] == "Matrix":
185       self.ADD.setEvolutionModel(asMatrix = EvolutionModel)
186     elif self.EvolutionModelType[Name] == "Function":
187       self.FunctionEvolutionModel[Name] = EvolutionModel
188
189   #--------------------------------------
190
191   def addObserver(self, name, scheduler, info, number):
192     self.observers_dict[name] = {}
193     self.observers_dict[name]["scheduler"] = scheduler
194     self.observers_dict[name]["info"] = info
195     self.observers_dict[name]["number"] = number
196
197   def getObservers(self):
198     return self.observers_dict