Salome HOME
Allowing diagonal sparse matrices to be entered
authorJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 12 Jun 2013 19:02:46 +0000 (21:02 +0200)
committerJean-Philippe ARGAUD <jean-philippe.argaud@edf.fr>
Wed, 12 Jun 2013 19:02:46 +0000 (21:02 +0200)
doc/reference.rst
resources/ADAOSchemaCatalog.xml
src/daSalome/daYacsIntegration/daStudy.py
src/daSalome/daYacsSchemaCreator/infos_daComposant.py
src/daSalome/daYacsSchemaCreator/methods.py

index 7158a99c3fb122babbffb8e44e43271bc788a7f0..824dd792770139485a9339fc2f3a98a983096128 100644 (file)
@@ -27,6 +27,8 @@ List of possible input types
 .. index:: single: Dict
 .. index:: single: Function
 .. index:: single: Matrix
+.. index:: single: ScalarSparseMatrix
+.. index:: single: DiagonalSparseMatrix
 .. index:: single: String
 .. index:: single: Script
 .. index:: single: Vector
@@ -46,14 +48,24 @@ different pseudo-types are:
     This indicates a variable that has to be filled by a matrix, usually given
     either as a string or as a script.
 
-**String**
-    This indicates a string giving a literal representation of a matrix, a
-    vector or a vector serie, such as "1 2 ; 3 4" for a square 2x2 matrix.
+**ScalarSparseMatrix**
+    This indicates a variable that has to be filled by a unique number, which
+    will be used to multiply an identity matrix, usually given either as a
+    string or as a script.
+
+**DiagonalSparseMatrix**
+    This indicates a variable that has to be filled by a vector, which will be
+    over the diagonal of an identity matrix, usually given either as a string or
+    as a script.
 
 **Script**
     This indicates a script given as an external file. It can be described by a
     full absolute path name or only by the file name without path.
 
+**String**
+    This indicates a string giving a literal representation of a matrix, a
+    vector or a vector serie, such as "1 2 ; 3 4" for a square 2x2 matrix.
+
 **Vector**
     This indicates a variable that has to be filled by a vector, usually given
     either as a string or as a script.
@@ -125,7 +137,8 @@ following:
 **BackgroundError**
     *Required command*. This indicates the background error covariance matrix,
     previously noted as :math:`\mathbf{B}`. It is defined as a "*Matrix*" type
-    object, that is, given either as a string or as a script.
+    object, a "*ScalarSparseMatrix*" type object, or a "*DiagonalSparseMatrix*"
+    type object, that is, given either as a string or as a script.
 
 **ControlInput**
     *Optional command*. This indicates the control vector used to force the
@@ -142,7 +155,8 @@ following:
 **EvolutionError**
     *Optional command*. This indicates the evolution error covariance matrix,
     usually noted as :math:`\mathbf{Q}`. It is defined as a "*Matrix*" type
-    object, that is, given either as a string or as a script.
+    object, a "*ScalarSparseMatrix*" type object, or a "*DiagonalSparseMatrix*"
+    type object, that is, given either as a string or as a script.
 
 **EvolutionModel**
     *Optional command*. This indicates the evolution model operator, usually
@@ -167,7 +181,8 @@ following:
 **ObservationError**
     *Required command*. This indicates the observation error covariance matrix,
     previously noted as :math:`\mathbf{R}`. It is defined as a "*Matrix*" type
-    object, that is, given either as a string or as a script.
+    object, a "*ScalarSparseMatrix*" type object, or a "*DiagonalSparseMatrix*"
+    type object, that is, given either as a string or as a script.
 
 **ObservationOperator**
     *Required command*. This indicates the observation operator, previously
index b59710c983de71c9c1a061f74c09d981739df7b3..7c83a362c5ee30fa19f80093cc0b639d15e14ada 100644 (file)
@@ -137,7 +137,9 @@ except NameError:
   pass
 else:
   logging.debug("CREATE BackgroundError is set")
+  logging.debug("CREATE BackgroundErrorType is %s"%BackgroundErrorType)
   logging.debug("CREATE BackgroundErrorStored is %s"%BackgroundErrorStored)
+  assim_study.setBackgroundErrorType(BackgroundErrorType)
   assim_study.setBackgroundErrorStored(BackgroundErrorStored)
   assim_study.setBackgroundError(BackgroundError)
 
@@ -148,7 +150,9 @@ except NameError:
   pass
 else:
   logging.debug("CREATE ObservationError is set")
+  logging.debug("CREATE ObservationErrorType is %s"%ObservationErrorType)
   logging.debug("CREATE ObservationErrorStored is %s"%ObservationErrorStored)
+  assim_study.setObservationErrorType(ObservationErrorType)
   assim_study.setObservationErrorStored(ObservationErrorStored)
   assim_study.setObservationError(ObservationError)
 
@@ -289,6 +293,34 @@ logging.debug("CREATE Matrix is %s"%matrix)
     <outport name="stored" type="bool"/>
   </inline>
 
+  <inline name="CreateNumpyScalarSparseMatrixFromString">
+    <script><code><![CDATA[
+import numpy, logging
+logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromString")
+matrix = numpy.matrix(matrix_in_string)
+type = "ScalarSparseMatrix"
+logging.debug("CREATE ScalarSparseMatrix is %s"%matrix)
+]]></code></script>
+    <inport name="matrix_in_string" type="string"/>
+    <outport name="matrix" type="pyobj"/>
+    <outport name="type" type="string"/>
+    <outport name="stored" type="bool"/>
+  </inline>
+
+  <inline name="CreateNumpyDiagonalSparseMatrixFromString">
+    <script><code><![CDATA[
+import numpy, logging
+logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromString")
+matrix = numpy.matrix(matrix_in_string)
+type = "DiagonalSparseMatrix"
+logging.debug("CREATE DiagonalSparseMatrix is %s"%matrix)
+]]></code></script>
+    <inport name="matrix_in_string" type="string"/>
+    <outport name="matrix" type="pyobj"/>
+    <outport name="type" type="string"/>
+    <outport name="stored" type="bool"/>
+  </inline>
+
   <inline name="CreateNumpyMatrixFromScript">
     <script><code><![CDATA[
 import logging
@@ -308,6 +340,58 @@ if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index
 __import__(module_name)
 user_script_module = sys.modules[module_name]
 
+# Get Data from script
+]]></code></script>
+    <inport name="script" type="string"/>
+    <outport name="type" type="string"/>
+    <outport name="stored" type="bool"/>
+  </inline>
+
+  <inline name="CreateNumpyScalarSparseMatrixFromScript">
+    <script><code><![CDATA[
+import logging
+logging.debug("CREATE Entering in CreateNumpyScalarSparseMatrixFromScript")
+type = "ScalarSparseMatrix"
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
+    sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
+# Get Data from script
+]]></code></script>
+    <inport name="script" type="string"/>
+    <outport name="type" type="string"/>
+    <outport name="stored" type="bool"/>
+  </inline>
+
+  <inline name="CreateNumpyDiagonalSparseMatrixFromScript">
+    <script><code><![CDATA[
+import logging
+logging.debug("CREATE Entering in CreateNumpyDiagonalSparseMatrixFromScript")
+type = "DiagonalSparseMatrix"
+
+# Get file path and filename
+import sys
+import os
+filepath = os.path.dirname(script)
+filename = os.path.basename(script)
+module_name = os.path.splitext(filename)[0]
+if sys.path.count(filepath)==0 or (sys.path.count(filepath)>0 and sys.path.index(filepath)>0):
+    sys.path.insert(0,filepath)
+
+# Import script
+__import__(module_name)
+user_script_module = sys.modules[module_name]
+
 # Get Data from script
 ]]></code></script>
     <inport name="script" type="string"/>
index 018103208c86ae043f1bfff35c7af4904d7d7073..bee61c775f7d936e0310c1cdd91f098a4f58122c 100644 (file)
@@ -95,7 +95,7 @@ class daStudy:
     if Type == "Vector":
       self.BackgroundType = Type
     else:
-      raise daError("[daStudy::setBackgroundType] Type is unkown : " + Type + ". Types are : Vector")
+      raise daError("[daStudy::setBackgroundType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
 
   def setBackgroundStored(self, Stored):
     if Stored:
@@ -122,7 +122,7 @@ class daStudy:
     if Type == "Vector":
       self.CheckingPointType = Type
     else:
-      raise daError("[daStudy::setCheckingPointType] Type is unkown : " + Type + ". Types are : Vector")
+      raise daError("[daStudy::setCheckingPointType] The following type is unkown : %s. Authorized types are : Vector"%(Type,))
 
   def setCheckingPointStored(self, Stored):
     if Stored:
@@ -142,6 +142,12 @@ class daStudy:
 
   #--------------------------------------
 
+  def setBackgroundErrorType(self, Type):
+    if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
+      self.BackgroundErrorType = Type
+    else:
+      raise daError("[daStudy::setBackgroundErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
+
   def setBackgroundErrorStored(self, Stored):
     if Stored:
       self.BackgroundErrorStored = True
@@ -150,18 +156,24 @@ class daStudy:
 
   def setBackgroundError(self, BackgroundError):
     try:
+      self.BackgroundErrorType
       self.BackgroundErrorStored
     except AttributeError:
-      raise daError("[daStudy::setBackgroundError] Storage is not defined !")
-    self.ADD.setBackgroundError(asCovariance = BackgroundError, toBeStored = self.BackgroundErrorStored)
+      raise daError("[daStudy::setBackgroundError] Type or Storage is not defined !")
+    if self.BackgroundErrorType == "Matrix":
+      self.ADD.setBackgroundError(asCovariance  = BackgroundError, toBeStored = self.BackgroundErrorStored)
+    if self.BackgroundErrorType == "ScalarSparseMatrix":
+      self.ADD.setBackgroundError(asEyeByScalar = BackgroundError, toBeStored = self.BackgroundErrorStored)
+    if self.BackgroundErrorType == "DiagonalSparseMatrix":
+      self.ADD.setBackgroundError(asEyeByVector = BackgroundError, toBeStored = self.BackgroundErrorStored)
 
   #--------------------------------------
 
   def setControlInputType(self, Type):
-    if Type == "Vector" or Type == "VectorSerie":
+    if Type in ("Vector", "VectorSerie"):
       self.ControlInputType = Type
     else:
-      raise daError("[daStudy::setControlInputType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
+      raise daError("[daStudy::setControlInputType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
 
   def setControlInputStored(self, Stored):
     if Stored:
@@ -183,10 +195,10 @@ class daStudy:
   #--------------------------------------
 
   def setObservationType(self, Type):
-    if Type == "Vector" or Type == "VectorSerie":
+    if Type in ("Vector", "VectorSerie"):
       self.ObservationType = Type
     else:
-      raise daError("[daStudy::setObservationType] Type is unkown : " + Type + ". Types are : Vector, VectorSerie")
+      raise daError("[daStudy::setObservationType] The following type is unkown : %s. Authorized types are : Vector, VectorSerie"%(Type,))
 
   def setObservationStored(self, Stored):
     if Stored:
@@ -207,6 +219,12 @@ class daStudy:
 
   #--------------------------------------
 
+  def setObservationErrorType(self, Type):
+    if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
+      self.ObservationErrorType = Type
+    else:
+      raise daError("[daStudy::setObservationErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
+
   def setObservationErrorStored(self, Stored):
     if Stored:
       self.ObservationErrorStored = True
@@ -215,10 +233,16 @@ class daStudy:
 
   def setObservationError(self, ObservationError):
     try:
+      self.ObservationErrorType
       self.ObservationErrorStored
     except AttributeError:
-      raise daError("[daStudy::setObservationError] Storage is not defined !")
-    self.ADD.setObservationError(asCovariance = ObservationError, toBeStored = self.ObservationErrorStored)
+      raise daError("[daStudy::setObservationError] Type or Storage is not defined !")
+    if self.ObservationErrorType == "Matrix":
+      self.ADD.setObservationError(asCovariance  = ObservationError, toBeStored = self.ObservationErrorStored)
+    if self.ObservationErrorType == "ScalarSparseMatrix":
+      self.ADD.setObservationError(asEyeByScalar = ObservationError, toBeStored = self.ObservationErrorStored)
+    if self.ObservationErrorType == "DiagonalSparseMatrix":
+      self.ADD.setObservationError(asEyeByVector = ObservationError, toBeStored = self.ObservationErrorStored)
 
   #--------------------------------------
 
@@ -231,12 +255,10 @@ class daStudy:
     return rtn
 
   def setObservationOperatorType(self, Name, Type):
-    if Type == "Matrix":
-      self.ObservationOperatorType[Name] = Type
-    elif Type == "Function":
+    if Type in ("Matrix", "Function"):
       self.ObservationOperatorType[Name] = Type
     else:
-      raise daError("[daStudy::setObservationOperatorType] Type is unkown : " + Type + ". Types are : Matrix, Function")
+      raise daError("[daStudy::setObservationOperatorType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
 
   def setObservationOperator(self, Name, ObservationOperator):
     try:
@@ -250,6 +272,12 @@ class daStudy:
 
   #--------------------------------------
 
+  def setEvolutionErrorType(self, Type):
+    if Type in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"):
+      self.EvolutionErrorType = Type
+    else:
+      raise daError("[daStudy::setEvolutionErrorType] The following type is unkown : %s. Authorized types are : Matrix, ScalarSparseMatrix, DiagonalSparseMatrix"%(Type,))
+
   def setEvolutionErrorStored(self, Stored):
     if Stored:
       self.EvolutionErrorStored = True
@@ -258,10 +286,16 @@ class daStudy:
 
   def setEvolutionError(self, EvolutionError):
     try:
+      self.EvolutionErrorType
       self.EvolutionErrorStored
     except AttributeError:
-      raise daError("[daStudy::setEvolutionError] Storage is not defined !")
-    self.ADD.setEvolutionError(asCovariance = EvolutionError, toBeStored = self.EvolutionErrorStored)
+      raise daError("[daStudy::setEvolutionError] Type or Storage is not defined !")
+    if self.EvolutionErrorType == "Matrix":
+      self.ADD.setEvolutionError(asCovariance  = EvolutionError, toBeStored = self.EvolutionErrorStored)
+    if self.EvolutionErrorType == "ScalarSparseMatrix":
+      self.ADD.setEvolutionError(asEyeByScalar = EvolutionError, toBeStored = self.EvolutionErrorStored)
+    if self.EvolutionErrorType == "DiagonalSparseMatrix":
+      self.ADD.setEvolutionError(asEyeByVector = EvolutionError, toBeStored = self.EvolutionErrorStored)
 
   #--------------------------------------
 
@@ -274,12 +308,10 @@ class daStudy:
     return rtn
 
   def setEvolutionModelType(self, Name, Type):
-    if Type == "Matrix":
-      self.EvolutionModelType[Name] = Type
-    elif Type == "Function":
+    if Type in ("Matrix", "Function"):
       self.EvolutionModelType[Name] = Type
     else:
-      raise daError("[daStudy::setEvolutionModelType] Type is unkown : " + Type + ". Types are : Matrix, Function")
+      raise daError("[daStudy::setEvolutionModelType] The following type is unkown : %s. Authorized types are : Matrix, Function"%(Type,))
 
   def setEvolutionModel(self, Name, EvolutionModel):
     try:
index f95b39d509eee9e0c85cb04ecae1bcc2a3b3de1b..c5207081be03122dcbaaa22139b41ce265d3865d 100644 (file)
@@ -36,23 +36,25 @@ AssimData = ["Background", "BackgroundError",
 
 AssimType = {}
 AssimType["Background"]          = ["Vector"]
-AssimType["BackgroundError"]     = ["Matrix"]
+AssimType["BackgroundError"]     = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimType["Observation"]         = ["Vector", "VectorSerie"]
-AssimType["ObservationError"]    = ["Matrix"]
+AssimType["ObservationError"]    = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimType["ObservationOperator"] = ["Matrix", "Function"]
 AssimType["EvolutionModel"]      = ["Matrix", "Function"]
-AssimType["EvolutionError"]      = ["Matrix"]
+AssimType["EvolutionError"]      = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimType["AlgorithmParameters"] = ["Dict"]
 AssimType["UserDataInit"]        = ["Dict"]
 AssimType["CheckingPoint"]       = ["Vector"]
 AssimType["ControlInput"]        = ["Vector", "VectorSerie"]
 
 FromNumpyList = {}
-FromNumpyList["Vector"]      = ["String", "Script"]
-FromNumpyList["VectorSerie"] = ["String", "Script"]
-FromNumpyList["Matrix"]      = ["String", "Script"]
-FromNumpyList["Function"]    = ["ScriptWithOneFunction", "ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"]
-FromNumpyList["Dict"]        = ["Script"]
+FromNumpyList["Vector"]               = ["String", "Script"]
+FromNumpyList["VectorSerie"]          = ["String", "Script"]
+FromNumpyList["Matrix"]               = ["String", "Script"]
+FromNumpyList["ScalarSparseMatrix"]   = ["String", "Script"]
+FromNumpyList["DiagonalSparseMatrix"] = ["String", "Script"]
+FromNumpyList["Function"]             = ["ScriptWithOneFunction", "ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"]
+FromNumpyList["Dict"]                 = ["Script"]
 
 # -- Infos from daAlgorithms --
 AssimAlgos = [
@@ -158,28 +160,32 @@ BasicDataInputs = ["String", "Script", "ScriptWithOneFunction", "ScriptWithFunct
 
 # Data input dict
 DataTypeDict = {}
-DataTypeDict["Vector"]      = ["String", "Script"]
-DataTypeDict["VectorSerie"] = ["String", "Script"]
-DataTypeDict["Matrix"]      = ["String", "Script"]
-DataTypeDict["Function"]    = ["ScriptWithOneFunction", "ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"]
-DataTypeDict["Dict"]        = ["Script"]
+DataTypeDict["Vector"]               = ["String", "Script"]
+DataTypeDict["VectorSerie"]          = ["String", "Script"]
+DataTypeDict["Matrix"]               = ["String", "Script"]
+DataTypeDict["ScalarSparseMatrix"]   = ["String", "Script"]
+DataTypeDict["DiagonalSparseMatrix"] = ["String", "Script"]
+DataTypeDict["Function"]             = ["ScriptWithOneFunction", "ScriptWithFunctions", "ScriptWithSwitch", "FunctionDict"]
+DataTypeDict["Dict"]                 = ["Script"]
 
 DataTypeDefaultDict = {}
-DataTypeDefaultDict["Vector"]      = "Script"
-DataTypeDefaultDict["VectorSerie"] = "Script"
-DataTypeDefaultDict["Matrix"]      = "Script"
-DataTypeDefaultDict["Function"]    = "ScriptWithOneFunction"
-DataTypeDefaultDict["Dict"]        = "Script"
+DataTypeDefaultDict["Vector"]               = "Script"
+DataTypeDefaultDict["VectorSerie"]          = "Script"
+DataTypeDefaultDict["Matrix"]               = "Script"
+DataTypeDefaultDict["ScalarSparseMatrix"]   = "String"
+DataTypeDefaultDict["DiagonalSparseMatrix"] = "String"
+DataTypeDefaultDict["Function"]             = "ScriptWithOneFunction"
+DataTypeDefaultDict["Dict"]                 = "Script"
 
 # Assimilation data input
 AssimDataDict = {}
 AssimDataDict["Background"]          = ["Vector"]
-AssimDataDict["BackgroundError"]     = ["Matrix"]
+AssimDataDict["BackgroundError"]     = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimDataDict["Observation"]         = ["Vector", "VectorSerie"]
-AssimDataDict["ObservationError"]    = ["Matrix"]
+AssimDataDict["ObservationError"]    = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimDataDict["ObservationOperator"] = ["Matrix", "Function"]
 AssimDataDict["EvolutionModel"]      = ["Matrix", "Function"]
-AssimDataDict["EvolutionError"]      = ["Matrix"]
+AssimDataDict["EvolutionError"]      = ["Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 AssimDataDict["AlgorithmParameters"] = ["Dict"]
 AssimDataDict["UserDataInit"]        = ["Dict"]
 AssimDataDict["CheckingPoint"]       = ["Vector"]
@@ -198,7 +204,7 @@ AssimDataDefaultDict["UserDataInit"]        = "Dict"
 AssimDataDefaultDict["CheckingPoint"]       = "Vector"
 AssimDataDefaultDict["ControlInput"]        = "Vector"
 
-StoredAssimData = ["Vector", "VectorSerie", "Matrix"]
+StoredAssimData = ["Vector", "VectorSerie", "Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix"]
 
 # Assimilation optional nodes
 OptDict = {}
index c49e3112b98b3eaef8351b423b8420d3ff604d56..66c30db351501c81a86b3313e9e9ed41ee852333 100644 (file)
@@ -263,9 +263,9 @@ def create_yacs_proc(study_config):
           ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data"))
         back_node.setScript(back_node_script)
 
-      if data_config["Type"] == "Matrix" and data_config["From"] == "String":
+      if data_config["Type"] in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix") and data_config["From"] == "String":
         # Create node
-        factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyMatrixFromString")
+        factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpy%sFromString"%(data_config["Type"],))
         back_node = factory_back_node.cloneNode("Get" + key)
         back_node.getInputPort("matrix_in_string").edInitPy(data_config["Data"])
         ADAO_Case.edAddChild(back_node)
@@ -285,9 +285,9 @@ def create_yacs_proc(study_config):
           ADAO_Case.edAddDFLink(init_node.getOutputPort("init_data"), back_node.getInputPort("init_data"))
         back_node.setScript(back_node_script)
 
-      if data_config["Type"] == "Matrix" and data_config["From"] == "Script":
+      if data_config["Type"] in ("Matrix", "ScalarSparseMatrix", "DiagonalSparseMatrix") and data_config["From"] == "Script":
         # Create node
-        factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpyMatrixFromScript")
+        factory_back_node = catalogAd.getNodeFromNodeMap("CreateNumpy%sFromScript"%(data_config["Type"],))
         back_node = factory_back_node.cloneNode("Get" + key)
         if repertory:
           back_node.getInputPort("script").edInitPy(os.path.join(base_repertory, os.path.basename(data_config["Data"])))