diff --git a/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py b/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py index f88de059aa8d..08cdc92b257a 100644 --- a/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py +++ b/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py @@ -129,11 +129,11 @@ def CalculateGradient(self, physical_variable_collective_expressions: 'dict[Supp self.adjoint_analysis._GetSolver().GetComputingModelPart().ProcessInfo[KratosDT.TEST_ANALYSIS_NAME] = exec_policy.GetName() self.adjoint_analysis._GetSolver().GetComputingModelPart().ProcessInfo[Kratos.STEP] = self.optimization_problem.GetStep() self.adjoint_analysis.RunSolutionLoop() - sensitivities = self.adjoint_analysis.GetSensitivities() for physical_variable, collective_expression in physical_variable_collective_expressions.items(): sensitivity_variable = Kratos.KratosGlobals.GetVariable(f"{physical_variable.Name()}_SENSITIVITY") for container_expression in collective_expression.GetContainerExpressions(): + sensitivities = self.adjoint_analysis.GetSensitivities(container_expression.GetModelPart()) container_expression.SetExpression((container_expression.GetExpression() - sensitivities[sensitivity_variable].GetExpression() * test_case_weight)) container_expression.SetExpression(Kratos.Expression.Utils.Collapse(container_expression).GetExpression()) diff --git a/applications/SystemIdentificationApplication/python_scripts/sensor_sensitivity_solvers/system_identification_static_analysis.py b/applications/SystemIdentificationApplication/python_scripts/sensor_sensitivity_solvers/system_identification_static_analysis.py index 1fccbfd03e27..c7850fe6c853 100644 --- a/applications/SystemIdentificationApplication/python_scripts/sensor_sensitivity_solvers/system_identification_static_analysis.py +++ b/applications/SystemIdentificationApplication/python_scripts/sensor_sensitivity_solvers/system_identification_static_analysis.py @@ -92,7 +92,7 @@ def RunSolutionLoop(self): sensor.FinalizeSolutionStep() self.FinalizeSolutionStep() - sensitivities = self.GetSensitivities() + sensitivities = self.GetSensitivities(self._GetSolver().GetSensitivityModelPart()) for var, cexp in sensitivities.items(): exp_io.Write(f"{sensor.GetName()}_{var.Name()}", cexp) @@ -117,14 +117,13 @@ def PrintAnalysisStageProgressInformation(self): process_info = self._GetSolver().GetComputingModelPart().ProcessInfo Kratos.Logger.PrintInfo(self._GetSimulationName(), f"Computed sensitivities for {process_info[KratosSI.SENSOR_NAME]} using \"{process_info[KratosSI.TEST_ANALYSIS_NAME]}\" analysis.") - def GetSensitivities(self) -> 'dict[typing.Union[Kratos.DoubleVariable, Kratos.Array1DVariable3], ExpressionUnionType]': - sensitivity_model_part: Kratos.ModelPart = self._GetSolver().GetSensitivityModelPart() + def GetSensitivities(self, model_part: Kratos.ModelPart) -> 'dict[typing.Union[Kratos.DoubleVariable, Kratos.Array1DVariable3], ExpressionUnionType]': sensitivity_variables: 'dict[ExpressionDataLocation, list[typing.Union[Kratos.DoubleVariable, Kratos.Array1DVariable3]]]' = self._GetSolver().GetSensitivtyVariables() result: 'dict[typing.Union[Kratos.DoubleVariable, Kratos.Array1DVariable3], ExpressionUnionType]' = {} for data_location, variables in sensitivity_variables.items(): for variable in variables: - result[variable] = GetContainerExpression(sensitivity_model_part, data_location, variable) + result[variable] = GetContainerExpression(model_part, data_location, variable) return result if __name__ == "__main__":