From: Jean-Philippe ARGAUD Date: Wed, 12 Jun 2013 19:02:46 +0000 (+0200) Subject: Allowing diagonal sparse matrices to be entered X-Git-Tag: V7_3_0~45 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=033b696b9351e2d6653c9b880442b25723e89a7e;p=modules%2Fadao.git Allowing diagonal sparse matrices to be entered --- diff --git a/doc/reference.rst b/doc/reference.rst index 7158a99..824dd79 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -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 diff --git a/resources/ADAOSchemaCatalog.xml b/resources/ADAOSchemaCatalog.xml index b59710c..7c83a36 100644 --- a/resources/ADAOSchemaCatalog.xml +++ b/resources/ADAOSchemaCatalog.xml @@ -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) + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/daSalome/daYacsIntegration/daStudy.py b/src/daSalome/daYacsIntegration/daStudy.py index 0181032..bee61c7 100644 --- a/src/daSalome/daYacsIntegration/daStudy.py +++ b/src/daSalome/daYacsIntegration/daStudy.py @@ -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: diff --git a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py index f95b39d..c520708 100644 --- a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py +++ b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py @@ -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 = {} diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index c49e311..66c30db 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -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"])))