From 11a6eb74fefa16f04b4ddfb01e3889ffa1986f71 Mon Sep 17 00:00:00 2001 From: JonasHill Date: Wed, 13 Nov 2024 13:57:46 +0100 Subject: [PATCH 1/3] fixing adjoint static LHS --- .../adjoint_elements/adjoint_finite_difference_base_element.h | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/StructuralMechanicsApplication/custom_response_functions/adjoint_elements/adjoint_finite_difference_base_element.h b/applications/StructuralMechanicsApplication/custom_response_functions/adjoint_elements/adjoint_finite_difference_base_element.h index 83b7b9c64860..7f1d3c4da084 100644 --- a/applications/StructuralMechanicsApplication/custom_response_functions/adjoint_elements/adjoint_finite_difference_base_element.h +++ b/applications/StructuralMechanicsApplication/custom_response_functions/adjoint_elements/adjoint_finite_difference_base_element.h @@ -175,6 +175,7 @@ class AdjointFiniteDifferencingBaseElement : public Element { mpPrimalElement->CalculateLeftHandSide(rLeftHandSideMatrix, rCurrentProcessInfo); + noalias(rLeftHandSideMatrix) = -1.0 * rLeftHandSideMatrix; } void CalculateRightHandSide(VectorType& rRightHandSideVector, From e2c4cc2b37571a78155800d16a2047186337f99e Mon Sep 17 00:00:00 2001 From: JonasHill Date: Wed, 13 Nov 2024 14:06:51 +0100 Subject: [PATCH 2/3] fixing struct static responses --- .../adjoint_local_stress_response_function.cpp | 1 - .../adjoint_max_stress_response_function.cpp | 1 - .../adjoint_nodal_displacement_response_function.cpp | 6 +++--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_local_stress_response_function.cpp b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_local_stress_response_function.cpp index f7f70ce2e61c..ce4429b458a5 100644 --- a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_local_stress_response_function.cpp +++ b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_local_stress_response_function.cpp @@ -87,7 +87,6 @@ namespace Kratos KRATOS_ERROR_IF(rResponseGradient.size() != rResidualGradient.size1()) << "Size of stress displacement derivative does not fit!" << std::endl; - rResponseGradient *= (-1); } else { diff --git a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_max_stress_response_function.cpp b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_max_stress_response_function.cpp index 1ab7f7076d61..bc69998e7b72 100644 --- a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_max_stress_response_function.cpp +++ b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_max_stress_response_function.cpp @@ -101,7 +101,6 @@ namespace Kratos KRATOS_ERROR_IF(rResponseGradient.size() != rResidualGradient.size1()) << "AdjointMaxStressResponseFunction::CalculateGradient: Size of stress displacement derivative does not fit!" << std::endl; - rResponseGradient *= (-1); } else { diff --git a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_nodal_displacement_response_function.cpp b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_nodal_displacement_response_function.cpp index 6f39afba242d..3b1c4ed23afd 100644 --- a/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_nodal_displacement_response_function.cpp +++ b/applications/StructuralMechanicsApplication/custom_response_functions/response_utilities/adjoint_nodal_displacement_response_function.cpp @@ -73,9 +73,9 @@ namespace Kratos for(IndexType i = 0; i < dofs_of_element.size(); ++i) { if (dofs_of_element[i]->Id() == node_id && dofs_of_element[i]->GetVariable() == *adjoint_solution_variable) { - rResponseGradient[i] = -1 * mResponseDirection[0]; - rResponseGradient[i+1] = -1 * mResponseDirection[1]; - rResponseGradient[i+2] = -1 * mResponseDirection[2]; + rResponseGradient[i] = mResponseDirection[0]; + rResponseGradient[i+1] = mResponseDirection[1]; + rResponseGradient[i+2] = mResponseDirection[2]; break; } } From 7e699f52e44983ad842ee5cc1059803a4f4ea7e0 Mon Sep 17 00:00:00 2001 From: JonasHill Date: Wed, 20 Nov 2024 18:13:03 +0100 Subject: [PATCH 3/3] fixing damage detection response --- .../python_scripts/responses/damage_detection_response.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py b/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py index 08cdc92b257a..39612981587c 100644 --- a/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py +++ b/applications/SystemIdentificationApplication/python_scripts/responses/damage_detection_response.py @@ -134,7 +134,7 @@ def CalculateGradient(self, physical_variable_collective_expressions: 'dict[Supp 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((container_expression.GetExpression() + sensitivities[sensitivity_variable].GetExpression() * test_case_weight)) container_expression.SetExpression(Kratos.Expression.Utils.Collapse(container_expression).GetExpression()) def __GetSensor(self, sensor_name: str) -> KratosDT.Sensors.Sensor: