From: Jean-Philippe ARGAUD Date: Mon, 22 Apr 2013 15:19:11 +0000 (+0200) Subject: Improving control and documentation on Finite difference Approximations X-Git-Tag: V7_2_0^0 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ef89409fb968a6acf805ff5deafeb36fccded5c3;p=modules%2Fadao.git Improving control and documentation on Finite difference Approximations --- diff --git a/bin/AdaoCatalogGenerator.py b/bin/AdaoCatalogGenerator.py index 1628a51..c688365 100644 --- a/bin/AdaoCatalogGenerator.py +++ b/bin/AdaoCatalogGenerator.py @@ -61,6 +61,7 @@ def F_${data_name}(statut) : return FACT(statut = statut, SCRIPTWITHONEFUNCTION_FILE = SIMP(statut = "o", typ = "FichierNoAbs", validators=(OnlyStr()), fr="En attente d'un nom de fichier script, avec ou sans le chemin complet pour le trouver, contenant en variable interne une seule fonction de calcul nommée DirectOperator", ang="Waiting for a script file name, with or without the full path to find it, containing as internal variable only one function named DirectOperator"), DifferentialIncrement = SIMP(statut="o", typ = "R", val_min=0, val_max=1, defaut=0.01, fr="Incrément de la perturbation dX pour calculer la dérivée, construite en multipliant X par l'incrément en évitant les valeurs nulles", ang="Increment of dX perturbation to calculate the derivative, build multiplying X by the increment avoiding null values"), + CenteredFiniteDifference = SIMP(statut="o", typ = "I", into=(0, 1), defaut=0, fr="Formulation centrée (1) ou décentrée (0) pour la méthode des différences finies", ang="Centered (1) or uncentered (0) formulation for the finite difference method"), ), SCRIPTWITHSWITCH_DATA = BLOC ( condition = " FROM in ( 'ScriptWithSwitch', ) ", diff --git a/doc/reference.rst b/doc/reference.rst index ed57a45..3336d06 100644 --- a/doc/reference.rst +++ b/doc/reference.rst @@ -777,6 +777,11 @@ representation. First functional form: using "*ScriptWithOneFunction*" ++++++++++++++++++++++++++++++++++++++++++++++++++++++ +.. index:: single: ScriptWithOneFunction +.. index:: single: DirectOperator +.. index:: single: DifferentialIncrement +.. index:: single: CenteredFiniteDifference + The first one consist in providing only one potentially non-linear function, and to approximate the tangent and the adjoint operators. This is done by using the keyword "*ScriptWithOneFunction*" for the description of the chosen operator in @@ -794,7 +799,11 @@ template:: In this case, the user can also provide a value for the differential increment, using through the GUI the keyword "*DifferentialIncrement*", which has a default value of 1%. This coefficient will be used in the finite difference -approximation to build the tangent and adjoint operators. +approximation to build the tangent and adjoint operators. The finite difference +approximation order can also be chosen through the GUI, using the keyword +"*CenteredFiniteDifference*", with 0 for an uncentered schema of first order, +and with 1 for a centered schema of second order (of twice the first order +computational cost). The keyword has a default value of 0. This first operator definition allow easily to test the functional form before its use in an ADAO case, greatly reducing the complexity of implementation. @@ -806,6 +815,11 @@ The user has to treat these cases in his script. Second functional form: using "*ScriptWithFunctions*" +++++++++++++++++++++++++++++++++++++++++++++++++++++ +.. index:: single: ScriptWithFunctions +.. index:: single: DirectOperator +.. index:: single: TangentOperator +.. index:: single: AdjointOperator + The second one consist in providing directly the three associated operators :math:`O`, :math:`\mathbf{O}` and :math:`\mathbf{O}^*`. This is done by using the keyword "*ScriptWithFunctions*" for the description of the chosen operator @@ -846,6 +860,11 @@ these cases in his script. Third functional form: using "*ScriptWithSwitch*" +++++++++++++++++++++++++++++++++++++++++++++++++ +.. index:: single: ScriptWithSwitch +.. index:: single: DirectOperator +.. index:: single: TangentOperator +.. index:: single: AdjointOperator + This third form give more possibilities to control the execution of the three functions representing the operator, allowing advanced usage and control over each execution of the simulation code. This is done by using the keyword diff --git a/src/daComposant/daNumerics/ApproximatedDerivatives.py b/src/daComposant/daNumerics/ApproximatedDerivatives.py index 9e09e6d..95a4aca 100644 --- a/src/daComposant/daNumerics/ApproximatedDerivatives.py +++ b/src/daComposant/daNumerics/ApproximatedDerivatives.py @@ -68,7 +68,7 @@ class FDApproximation: c'est-à-dire le gradient de H en X. On utilise des différences finies directionnelles autour du point X. X est un numpy.matrix. - Différences finies centrées : + Différences finies centrées (approximation d'ordre 2): 1/ Pour chaque composante i de X, on ajoute et on enlève la perturbation dX[i] à la composante X[i], pour composer X_plus_dXi et X_moins_dXi, et on calcule les réponses HX_plus_dXi = H( X_plus_dXi ) et HX_moins_dXi = @@ -77,7 +77,7 @@ class FDApproximation: le pas 2*dXi 3/ Chaque résultat, par composante, devient une colonne de la Jacobienne - Différences finies non centrées : + Différences finies non centrées (approximation d'ordre 1): 1/ Pour chaque composante i de X, on ajoute la perturbation dX[i] à la composante X[i] pour composer X_plus_dXi, et on calcule la réponse HX_plus_dXi = H( X_plus_dXi ) diff --git a/src/daEficas/generator_adao.py b/src/daEficas/generator_adao.py index 85535fd..3e52568 100644 --- a/src/daEficas/generator_adao.py +++ b/src/daEficas/generator_adao.py @@ -210,6 +210,7 @@ class AdaoGenerator(PythonGenerator): self.text_da += data_name + "_ScriptWithOneFunction['Script']['Tangent'] = '" + data + "'\n" self.text_da += data_name + "_ScriptWithOneFunction['Script']['Adjoint'] = '" + data + "'\n" self.text_da += data_name + "_ScriptWithOneFunction['DifferentialIncrement'] = " + str(float(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__DifferentialIncrement"])) + "\n" + self.text_da += data_name + "_ScriptWithOneFunction['CenteredFiniteDifference'] = " + str(self.dictMCVal[search_type + "SCRIPTWITHONEFUNCTION_DATA__CenteredFiniteDifference"]) + "\n" self.text_da += data_name + "_config = {}\n" self.text_da += data_name + "_config['Type'] = 'Function'\n" self.text_da += data_name + "_config['From'] = 'ScriptWithOneFunction'\n" diff --git a/src/daSalome/daYacsSchemaCreator/methods.py b/src/daSalome/daYacsSchemaCreator/methods.py index 432ae3b..c49e311 100644 --- a/src/daSalome/daYacsSchemaCreator/methods.py +++ b/src/daSalome/daYacsSchemaCreator/methods.py @@ -583,8 +583,9 @@ def create_yacs_proc(study_config): node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n""" node_script += """import ApproximatedDerivatives\n""" node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n""" - node_script += """ Function = DirectOperator,\n""" - node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) + node_script += """ Function = DirectOperator,\n""" + node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) + node_script += """ centeredDF = %s,\n"""%str(ScriptWithOneFunction['CenteredFiniteDifference']) node_script += """ )\n""" node_script += """#\n""" node_script += """__data = []\n""" @@ -804,8 +805,9 @@ def create_yacs_proc(study_config): node_script += """ raise ValueError("ComputationFunctionNode: DirectOperator not found in the imported user script file")\n""" node_script += """import ApproximatedDerivatives\n""" node_script += """FDA = ApproximatedDerivatives.FDApproximation(\n""" - node_script += """ Function = DirectOperator,\n""" - node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) + node_script += """ Function = DirectOperator,\n""" + node_script += """ increment = %s,\n"""%str(ScriptWithOneFunction['DifferentialIncrement']) + node_script += """ centeredDF = %s,\n"""%str(ScriptWithOneFunction['CenteredFiniteDifference']) node_script += """ )\n""" node_script += """#\n""" node_script += """__data = []\n"""