From b912ef4751aca1c5935c91d3db8ac157ed21b6f0 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Fri, 30 Mar 2018 18:12:56 +0200 Subject: [PATCH] Update correction for YACS converter control --- doc/en/tui.rst | 57 +++++++++++++++++++++++++- doc/fr/tui.rst | 55 +++++++++++++++++++++++++ src/daComposant/daCore/Aidsm.py | 34 +++++++-------- src/daComposant/daCore/BasicObjects.py | 9 ++-- src/daComposant/daCore/Interfaces.py | 33 +++++---------- 5 files changed, 143 insertions(+), 45 deletions(-) diff --git a/doc/en/tui.rst b/doc/en/tui.rst index d524db9..ab2af91 100644 --- a/doc/en/tui.rst +++ b/doc/en/tui.rst @@ -54,7 +54,7 @@ ADAO calculation case. All the data are explicitly defined inside the script in order to make the reading easier. The whole set of commands is the following one:: - from numpy import array + from numpy import array, matrix import adaoBuilder case = adaoBuilder.New() case.set( 'AlgorithmParameters', Algorithm='3DVAR' ) @@ -272,7 +272,7 @@ are done by importing the interface module "*adaoBuilder*" and by by invoking its method "*New()*" as illustrated in the following lines (the ``case`` object name being let free to the user choice):: - from numpy import array + from numpy import array, matrix import adaoBuilder case = adaoBuilder.New() @@ -456,6 +456,16 @@ Setting the calculation, outputs, etc. the file must contain the two variables "*Algorithm*" and "*Parameters*" (or "*AlgorithmParameters*" equivalently). +.. index:: single: setName + +**setName** (*String*) + This command allows to set a short title for the calculation case. + +.. index:: single: setDirectory + +**setDirectory** (*String*) + This command allows to set the execution standard directory. + .. index:: single: setDebug **setDebug** () @@ -514,6 +524,49 @@ Get the calculation results separately :ref:`section_ref_output_variables` and to the individual documentations of the algorithms. +Saving, loading or converting calculation case commands ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +The saving or loading of a calculation case deals with quantities and actions +that are linked by the previous commands, excepted case external operations +(such as, for example, post-processing that can be developped after the +calculation cas). The registered or loaded commands remain fully compatible +with these Python external case operations. + +.. index:: single: load +.. index:: single: FileName +.. index:: single: Content +.. index:: single: Object +.. index:: single: Formater + +**load** (*FileName, Content, Object, Formater*) + This command allows to read or load a calculation case, from a file named + "*FileName*" or a content in memory by "*Content*" or "*Object*". The + "*Formater*" keyword can indicate "*TUI*" for commands of textual + application programming interface, and "*COM*" for commands of COMM type + coming from EFICAS interface for ADAO. + +.. index:: single: dump + +**dump** (*FileName, Formater*) + This command allows to save, in a file named "*FileName*", the commands of + the current calculation case. The "*Formater*" keyword can indicate "*TUI*" + for commands of textual application programming interface, and "*YACS*" for + commands of type YACS. + +.. index:: single: convert +.. index:: single: FileNameFrom +.. index:: single: ContentFrom +.. index:: single: ObjectFrom +.. index:: single: FormaterFrom +.. index:: single: FileNameTo +.. index:: single: FormaterTo + +**convert** (*FileNameFrom, ContentFrom, ObjectFrom, FormaterFrom, FileNameTo, FormaterTo*) + This command allows to convert directly from a known format to an another + one the commands establishing the current calculation case. Some formats + are only available as input or as output. + .. _subsection_tui_advanced: More advanced examples of ADAO TUI calculation case diff --git a/doc/fr/tui.rst b/doc/fr/tui.rst index 59b0a23..f50e9de 100644 --- a/doc/fr/tui.rst +++ b/doc/fr/tui.rst @@ -473,6 +473,16 @@ Paramétrer le calcul, les sorties, etc. "*Algorithm*" et "*Parameters*" (ou "*AlgorithmParameters*" de manière équivalente). +.. index:: single: setName + +**setName** (*String*) + Cette commande permet de donner un titre court au cas de calcul. + +.. index:: single: setDirectory + +**setDirectory** (*String*) + Cette commande permet d'indiquer le répertoire courant d'exécution. + .. index:: single: setDebug **setDebug** () @@ -536,6 +546,51 @@ Obtenir séparément les résultats de calcul fois aux :ref:`section_ref_output_variables` et aux documentations individuelles des algorithmes. +Enregistrer, charger ou convertir les commandes de cas de calcul +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +L'enregistrement ou le chargement d'un cas de calcul concernent les quantités +et les actions qui lui sont liées par les commandes précédentes, à l'exclusion +d'opérations externes au cas (comme par exemple le post-processing qui peut +être développé après le cas de calcul). Les commandes enregistrées ou chargées +restent néanmoins parfaitement compatibles avec ces opérations en Python +externes au cas. + +.. index:: single: load +.. index:: single: FileName +.. index:: single: Content +.. index:: single: Object +.. index:: single: Formater + +**load** (*FileName, Content, Object, Formater*) + Cette commande permet de lire ou charger un cas d'étude, à partir d'un + fichier "*FileName*" ou d'un contenu en mémoire par "*Content*" ou + "*Object*". Le mot-clé "*Formater*" peut désigner le format "*TUI*" pour + les commandes du type interface de programmation textuelle, et le format + "*COM*" pour les commandes du type COMM provenant de l'interface ADAO de + type EFICAS. + +.. index:: single: dump + +**dump** (*FileName, Formater*) + Cette commande permet d'enregistrer, dans un fichier "*FileName*", les + commandes du cas d'étude en cours. Le mot-clé "*Formater*" peut désigner + les formats "*TUI*" pour les commandes du type interface de programmation + textuelle, et "*YACS*" pour les commandes du type YACS. + +.. index:: single: convert +.. index:: single: FileNameFrom +.. index:: single: ContentFrom +.. index:: single: ObjectFrom +.. index:: single: FormaterFrom +.. index:: single: FileNameTo +.. index:: single: FormaterTo + +**convert** (*FileNameFrom, ContentFrom, ObjectFrom, FormaterFrom, FileNameTo, FormaterTo*) + Cette commande permet de convertir directement d'un format reconnu à un + autre les commandes établissant le cas de calcul en cours. Certains + formats ne sont disponibles qu'en entrée ou qu'en sortie. + .. _subsection_tui_advanced: Exemples plus avancés de cas de calcul TUI ADAO diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index 29d9143..5802c0c 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -168,7 +168,7 @@ class Aidsm(object): name = Concept, asVector = Vector, asPersistentVector = VectorSerie, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -190,7 +190,7 @@ class Aidsm(object): name = Concept, asVector = Vector, asPersistentVector = VectorSerie, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -212,7 +212,7 @@ class Aidsm(object): name = Concept, asVector = Vector, asPersistentVector = VectorSerie, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -234,7 +234,7 @@ class Aidsm(object): name = Concept, asVector = Vector, asPersistentVector = VectorSerie, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), scheduledBy = Scheduler, toBeChecked = Checked, ) @@ -259,7 +259,7 @@ class Aidsm(object): asEyeByScalar = ScalarSparseMatrix, asEyeByVector = DiagonalSparseMatrix, asCovObject = ObjectMatrix, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), toBeChecked = Checked, ) if Stored: @@ -283,7 +283,7 @@ class Aidsm(object): asEyeByScalar = ScalarSparseMatrix, asEyeByVector = DiagonalSparseMatrix, asCovObject = ObjectMatrix, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), toBeChecked = Checked, ) if Stored: @@ -307,7 +307,7 @@ class Aidsm(object): asEyeByScalar = ScalarSparseMatrix, asEyeByVector = DiagonalSparseMatrix, asCovObject = ObjectMatrix, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), toBeChecked = Checked, ) if Stored: @@ -332,7 +332,7 @@ class Aidsm(object): asMatrix = Matrix, asOneFunction = OneFunction, asThreeFunctions = ThreeFunctions, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), asDict = Parameters, appliedInX = AppliedInXb, avoidRC = AvoidRC, @@ -361,7 +361,7 @@ class Aidsm(object): asMatrix = Matrix, asOneFunction = OneFunction, asThreeFunctions = ThreeFunctions, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), asDict = Parameters, appliedInX = None, avoidRC = AvoidRC, @@ -390,7 +390,7 @@ class Aidsm(object): asMatrix = Matrix, asOneFunction = OneFunction, asThreeFunctions = ThreeFunctions, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), asDict = Parameters, appliedInX = None, avoidRC = AvoidRC, @@ -448,7 +448,7 @@ class Aidsm(object): name = Concept, asAlgorithm = Algorithm, asDict = Parameters, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), ) return 0 @@ -460,7 +460,7 @@ class Aidsm(object): raise ValueError("No algorithm registred, ask for one before updating parameters") self.__adaoObject["AlgorithmParameters"].updateParameters( asDict = Parameters, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), ) return 0 @@ -475,7 +475,7 @@ class Aidsm(object): name = Concept, asAlgorithm = Algorithm, asDict = Parameters, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), ) return 0 @@ -495,7 +495,7 @@ class Aidsm(object): onVariable = Variable, asTemplate = Template, asString = String, - asScript = self.with_directory(Script), + asScript = self.__with_directory(Script), asObsObject = ObjectFunction, withInfo = Info, scheduledBy = Scheduler, @@ -687,7 +687,9 @@ class Aidsm(object): "Effacement du contenu du cas en cours" self.__init__(self.__name) - def with_directory(self, __filename=None): + # ----------------------------------------------------------- + + def __with_directory(self, __filename=None): if os.path.exists(str(__filename)): __fullpath = __filename elif os.path.exists(os.path.join(str(self.__directory), str(__filename))): @@ -696,8 +698,6 @@ class Aidsm(object): __fullpath = __filename return __fullpath - # ----------------------------------------------------------- - def __dir__(self): "Clarifie la visibilité des méthodes" return ['set', 'get', 'execute', '__doc__', '__init__', '__module__'] diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index 6fcdcf3..7de386e 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -22,8 +22,6 @@ """ Définit les outils généraux élémentaires. - - Ce module est destiné à être appelée par AssimilationStudy. """ __author__ = "Jean-Philippe ARGAUD" __all__ = [] @@ -824,6 +822,9 @@ class AlgorithmAndParameters(object): "Permet de lancer le calcul d'assimilation" if FileName is None or not os.path.exists(FileName): raise ValueError("a YACS file name has to be given for YACS execution.\n") + else: + __file = os.path.abspath(FileName) + logging.debug("The YACS file name is \"%s\"."%__file) if not PlatformInfo.has_salome or \ not PlatformInfo.has_yacs or \ not PlatformInfo.has_adao: @@ -840,13 +841,13 @@ class AlgorithmAndParameters(object): xmlLoader = loader.YACSLoader() xmlLoader.registerProcCataLoader() try: - catalogAd = r.loadCatalog("proc", os.path.abspath(FileName)) + catalogAd = r.loadCatalog("proc", __file) r.addCatalog(catalogAd) except: pass try: - p = xmlLoader.load(os.path.abspath(FileName)) + p = xmlLoader.load(__file) except IOError as ex: print("The YACS XML schema file can not be loaded: %s"%(ex,)) diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index f8d484e..b0eb457 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -73,7 +73,7 @@ class GenericCaseViewer(object): __text +="\n" if __filename is not None: __file = os.path.abspath(__filename) - __fid = open(__file,"w") + __fid = open(__file,"w",0) __fid.write(__text) __fid.close() return __text @@ -462,38 +462,27 @@ class _YACSViewer(GenericCaseViewer): GenericCaseViewer.__init__(self, __name, __objname, __content, __object) self.__internalSCD = _SCDViewer(__name, __objname, __content, __object) self._append = self.__internalSCD._append - def dump(self, __filename=None, __convertSCDinMemory=True): + def dump(self, __filename=None, __upa=None): "Restitution normalisée des commandes" - self.__internalSCD._finalize() # ----- if __filename is None: raise ValueError("A file name has to be given for YACS XML output.") + else: + __file = os.path.abspath(__filename) + if os.path.isfile(__file) or os.path.islink(__file): + os.remove(__file) # ----- if not PlatformInfo.has_salome or \ not PlatformInfo.has_adao: raise ImportError( "Unable to get SALOME or ADAO environnement variables for YACS conversion.\n"+\ "Please load the right environnement before trying to use it.") - elif __convertSCDinMemory: - __file = os.path.abspath(__filename) - __SCDdump = self.__internalSCD.dump() - if os.path.isfile(__file) or os.path.islink(__file): - os.remove(__file) - from daYacsSchemaCreator.run import create_schema_from_content - create_schema_from_content(__SCDdump, __file) else: - __file = os.path.abspath(__filename) - __SCDfile = __file[:__file.rfind(".")] + '_SCD.py' - __SCDdump = self.__internalSCD.dump(__SCDfile) - if os.path.isfile(__file) or os.path.islink(__file): - os.remove(__file) - __converterExe = os.path.join(os.environ["ADAO_ROOT_DIR"], "bin/salome", "AdaoYacsSchemaCreator.py") - __args = ["python", __converterExe, __SCDfile, __file] - import subprocess - __p = subprocess.Popen(__args) - (__stdoutdata, __stderrdata) = __p.communicate() - __p.terminate() - os.remove(__SCDfile) + from daYacsSchemaCreator.run import create_schema_from_content + # ----- + self.__internalSCD._finalize(__upa) + __SCDdump = self.__internalSCD.dump() + create_schema_from_content(__SCDdump, __file) # ----- if not os.path.exists(__file): __msg = "An error occured during the ADAO YACS Schema build for\n" -- 2.39.2