From 74317cd7f824debd820996462f7929c015abd061 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 21 Feb 2018 22:47:16 +0100 Subject: [PATCH] Corrections and improvements for instances and regul/time --- .../Physical_simulation_functions.py | 2 +- src/daComposant/daCore/Aidsm.py | 20 +++++++++- src/daComposant/daCore/BasicObjects.py | 39 +++++++++++++++++++ src/daComposant/daCore/Interfaces.py | 6 +-- src/daComposant/daCore/Persistence.py | 15 +++++++ .../daYacsSchemaCreator/infos_daComposant.py | 3 ++ src/daSalome/daYacsSchemaCreator/methods.py | 15 ++++++- 7 files changed, 93 insertions(+), 7 deletions(-) diff --git a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py index c4299fb..b8caec8 100644 --- a/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py +++ b/examples/daSkeletons/External_data_definition_by_scripts/Physical_simulation_functions.py @@ -49,7 +49,7 @@ def DirectOperator( XX ): return numpy.array( HX ) # ============================================================================== -from ApproximatedDerivatives import FDApproximation +from daNumerics.ApproximatedDerivatives import FDApproximation FDA = FDApproximation( DirectOperator ) TangentOperator = FDA.TangentOperator AdjointOperator = FDA.AdjointOperator diff --git a/src/daComposant/daCore/Aidsm.py b/src/daComposant/daCore/Aidsm.py index d951a0e..29d9143 100644 --- a/src/daComposant/daCore/Aidsm.py +++ b/src/daComposant/daCore/Aidsm.py @@ -31,7 +31,7 @@ import sys # from daCore.BasicObjects import State, Covariance, FullOperator, Operator from daCore.BasicObjects import AlgorithmAndParameters, DataObserver -from daCore.BasicObjects import CaseLogger +from daCore.BasicObjects import RegulationAndParameters, CaseLogger from daCore import PlatformInfo # from daCore import ExtendedLogging ; ExtendedLogging.ExtendedLogging() # A importer en premier @@ -65,6 +65,7 @@ class Aidsm(object): "Directory", "Debug", "NoDebug", + "RegulationParameters", "Observer", ] # @@ -119,6 +120,8 @@ class Aidsm(object): Script, Stored, ObjectMatrix, Checked ) elif Concept == "AlgorithmParameters": self.setAlgorithmParameters( Algorithm, Parameters, Script ) + elif Concept == "RegulationParameters": + self.setRegulationParameters( Algorithm, Parameters, Script ) elif Concept == "Name": self.setName(String) elif Concept == "Directory": @@ -461,6 +464,21 @@ class Aidsm(object): ) return 0 + def setRegulationParameters(self, + Algorithm = None, + Parameters = None, + Script = None): + "Definition d'un concept de calcul" + Concept = "RegulationParameters" + self.__case.register("set"+Concept, dir(), locals()) + self.__adaoObject[Concept] = RegulationAndParameters( + name = Concept, + asAlgorithm = Algorithm, + asDict = Parameters, + asScript = self.with_directory(Script), + ) + return 0 + def setObserver(self, Variable = None, Template = None, diff --git a/src/daComposant/daCore/BasicObjects.py b/src/daComposant/daCore/BasicObjects.py index e44ff41..64e8a6e 100644 --- a/src/daComposant/daCore/BasicObjects.py +++ b/src/daComposant/daCore/BasicObjects.py @@ -1095,6 +1095,45 @@ class AlgorithmAndParameters(object): # return 1 +# ============================================================================== +class RegulationAndParameters(object): + """ + Classe générale d'interface d'action pour la régulation et ses paramètres + """ + def __init__(self, + name = "GenericRegulation", + asAlgorithm = None, + asDict = None, + asScript = None, + ): + """ + """ + self.__name = str(name) + self.__P = {} + # + if asAlgorithm is None and asScript is not None: + __Algo = ImportFromScript(asScript).getvalue( "Algorithm" ) + else: + __Algo = asAlgorithm + # + if asDict is None and asScript is not None: + __Dict = ImportFromScript(asScript).getvalue( self.__name, "Parameters" ) + else: + __Dict = asDict + # + if __Dict is not None: + self.__P.update( dict(__Dict) ) + # + if __Algo is not None: + self.__P.update( {"Algorithm":self.__A} ) + + def get(self, key = None): + "Vérifie l'existence d'une clé de variable ou de paramètres" + if key in self.__P: + return self.__P[key] + else: + return self.__P + # ============================================================================== class DataObserver(object): """ diff --git a/src/daComposant/daCore/Interfaces.py b/src/daComposant/daCore/Interfaces.py index 3f9e8e9..be7a612 100644 --- a/src/daComposant/daCore/Interfaces.py +++ b/src/daComposant/daCore/Interfaces.py @@ -687,9 +687,9 @@ class _YACSViewer(GenericCaseViewer): # ----- if not PlatformInfo.has_salome or \ not PlatformInfo.has_adao: - raise ImportError("\n\n"+\ - "Unable to get SALOME or ADAO environnement variables.\n"+\ - "Please load the right environnement before trying to use it.\n") + 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() diff --git a/src/daComposant/daCore/Persistence.py b/src/daComposant/daCore/Persistence.py index 858c865..2b86087 100644 --- a/src/daComposant/daCore/Persistence.py +++ b/src/daComposant/daCore/Persistence.py @@ -670,6 +670,21 @@ class Persistence(object): def hasDataObserver(self): return bool(len(self.__dataobservers) > 0) +# ============================================================================== +class SchedulerTrigger(object): + """ + Classe générale d'interface de type Scheduler/Trigger + """ + def __init__(self, + simplifiedCombo = None, + startTime = 0, + endTime = int( 1e9 ), + timeDelay = 1, + timeUnit = 1, + frequency = None, + ): + pass + # ============================================================================== class OneScalar(Persistence): """ diff --git a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py index a9a0c09..9dd9ec9 100644 --- a/src/daSalome/daYacsSchemaCreator/infos_daComposant.py +++ b/src/daSalome/daYacsSchemaCreator/infos_daComposant.py @@ -286,3 +286,6 @@ ObserversList = [ "APosterioriVariances", "Residu", ] + +# Regulation : # of containers, 0 for no container +UseYACSContainer = 1 diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index c21aa42..32a9f3c 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -77,6 +77,8 @@ def create_yacs_proc(study_config): else: base_repertory = "" repertory = False + if UseYACSContainer: + mycontainer = proc.createContainer("AdaoContainer") # Create ADAO case bloc ADAO_Case = runtime.createBloc("ADAO_Case_Bloc") @@ -408,6 +410,9 @@ def create_yacs_proc(study_config): break # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") + if UseYACSContainer: + opt_script_nodeOO.setExecutionMode(SALOMERuntime.PythonNode.REMOTE_STR) + opt_script_nodeOO.setContainer(mycontainer) if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: @@ -436,6 +441,9 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") + if UseYACSContainer: + opt_script_nodeOO.setExecutionMode(SALOMERuntime.PythonNode.REMOTE_STR) + opt_script_nodeOO.setContainer(mycontainer) if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: @@ -516,6 +524,9 @@ def create_yacs_proc(study_config): # We create a new pyscript node opt_script_nodeOO = runtime.createScriptNode("", "FunctionNodeOO") + if UseYACSContainer: + opt_script_nodeOO.setExecutionMode(SALOMERuntime.PythonNode.REMOTE_STR) + opt_script_nodeOO.setContainer(mycontainer) if repertory and os.path.exists(os.path.join(base_repertory, os.path.basename(script_filename))): script_filename = os.path.join(base_repertory, os.path.basename(script_filename)) try: @@ -542,7 +553,7 @@ def create_yacs_proc(study_config): node_script += """ DirectOperator\n""" node_script += """except NameError:\n""" node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n""" - node_script += """import ApproximatedDerivatives\n""" + node_script += """from daNumerics import ApproximatedDerivatives\n""" node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n""" node_script += """ Function = DirectOperator,\n""" node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) @@ -739,7 +750,7 @@ def create_yacs_proc(study_config): node_script += """ DirectOperator\n""" node_script += """except NameError:\n""" node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n""" - node_script += """import ApproximatedDerivatives\n""" + node_script += """from daNumerics import ApproximatedDerivatives\n""" node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n""" node_script += """ Function = DirectOperator,\n""" node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) -- 2.39.2