From d7019e6bd48127bc590587d9d85bdbb964111de9 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Mon, 11 Nov 2024 11:20:00 +0100 Subject: [PATCH 01/12] Remove probably redundant resets in geomechanics_analysis.py --- .../python_scripts/geomechanics_analysis.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py index d187b65fa541..26c2110bdce5 100644 --- a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py +++ b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py @@ -67,9 +67,6 @@ def ModifyInitialGeometry(self): # The reset needs to take place befor the Initialize of the processes, as these will set the Dirichlet condition. self._GetSolver().main_model_part.ProcessInfo[KratosGeo.RESET_DISPLACEMENTS] = self.reset_displacements if self.reset_displacements: - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION) - KratosMultiphysics.VariableUtils().UpdateCurrentToInitialConfiguration(self._GetSolver().GetComputingModelPart().Nodes) def Finalize(self): From 74ff1e1aeaa891ad304ef25d4f4c3410f492d46d Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Mon, 11 Nov 2024 14:13:03 +0100 Subject: [PATCH 02/12] Revert "Remove probably redundant resets in geomechanics_analysis.py" This reverts commit d7019e6bd48127bc590587d9d85bdbb964111de9. --- .../python_scripts/geomechanics_analysis.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py index 26c2110bdce5..d187b65fa541 100644 --- a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py +++ b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py @@ -67,6 +67,9 @@ def ModifyInitialGeometry(self): # The reset needs to take place befor the Initialize of the processes, as these will set the Dirichlet condition. self._GetSolver().main_model_part.ProcessInfo[KratosGeo.RESET_DISPLACEMENTS] = self.reset_displacements if self.reset_displacements: + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION) + KratosMultiphysics.VariableUtils().UpdateCurrentToInitialConfiguration(self._GetSolver().GetComputingModelPart().Nodes) def Finalize(self): From 496aad968330f9d39b453485548d46b2f92e6fb4 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Mon, 11 Nov 2024 16:36:16 +0100 Subject: [PATCH 03/12] Only reset displacements if dofs are not fixed and do the reset after the executeinitialize --- .../python_scripts/geomechanics_analysis.py | 17 +++++++++++------ .../ProjectParameters_stage2.json | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py index d187b65fa541..6818a55b8da6 100644 --- a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py +++ b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py @@ -57,18 +57,23 @@ def _CalculateTotalDisplacement(self,node, old_total_displacement): def ResetIfHasNodalSolutionStepVariable(self, variable): if self._GetSolver().main_model_part.HasNodalSolutionStepVariable(variable): - KratosMultiphysics.VariableUtils().SetHistoricalVariableToZero(variable, self._GetSolver().GetComputingModelPart().Nodes) for node in self._GetSolver().GetComputingModelPart().Nodes: - new_value = node.GetSolutionStepValue(variable, 0) - node.SetSolutionStepValue(variable, 1, new_value) + if not node.IsFixed(variable): + node.SetSolutionStepValue(variable, 0, 0.0) + new_value = node.GetSolutionStepValue(variable, 0) + node.SetSolutionStepValue(variable, 1, new_value) - def ModifyInitialGeometry(self): + def ModifyAfterSolverInitialize(self): # Overrides the base class. Necessary to let reset_displacements function correctly i.c.w. prescribed displacements/rotations. # The reset needs to take place befor the Initialize of the processes, as these will set the Dirichlet condition. self._GetSolver().main_model_part.ProcessInfo[KratosGeo.RESET_DISPLACEMENTS] = self.reset_displacements if self.reset_displacements: - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_X) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_Y) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_Z) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_X) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_Y) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_Z) KratosMultiphysics.VariableUtils().UpdateCurrentToInitialConfiguration(self._GetSolver().GetComputingModelPart().Nodes) diff --git a/applications/GeoMechanicsApplication/tests/truss_with_reset_displacement/ProjectParameters_stage2.json b/applications/GeoMechanicsApplication/tests/truss_with_reset_displacement/ProjectParameters_stage2.json index 42c9b17a1037..f370677acea1 100644 --- a/applications/GeoMechanicsApplication/tests/truss_with_reset_displacement/ProjectParameters_stage2.json +++ b/applications/GeoMechanicsApplication/tests/truss_with_reset_displacement/ProjectParameters_stage2.json @@ -30,7 +30,7 @@ "block_builder": true, "solution_type": "Quasi-Static", "scheme_type": "Newmark", - "reset_displacements": false, + "reset_displacements": true, "newmark_beta": 0.25, "newmark_gamma": 0.5, "newmark_theta": 0.5, From 04edb8dff57815d56b7c19744b6b31e30055281e Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 14:05:18 +0100 Subject: [PATCH 04/12] Re-use utility function --- .../add_custom_utilities_to_python.cpp | 13 +++++++---- .../custom_utilities/node_utilities.cpp | 10 ++++++++ .../custom_utilities/node_utilities.h | 6 +++++ .../python_scripts/geomechanics_analysis.py | 23 +++++++------------ 4 files changed, 32 insertions(+), 20 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp index 69124591620b..6dcff1addbe8 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp @@ -15,15 +15,18 @@ // Project includes #include "custom_python/add_custom_utilities_to_python.h" -#include "includes/kratos_parameters.h" -#include "custom_utilities/condition_utilities.hpp" -#include "custom_utilities/element_utilities.hpp" -#include "custom_utilities/interface_element_utilities.h" +#include "custom_utilities/node_utilities.h" namespace Kratos::Python { -void AddCustomUtilitiesToPython(pybind11::module&) { namespace py = pybind11; } +void AddCustomUtilitiesToPython(pybind11::module& m) +{ + pybind11::class_(m, "NodeUtilities") + .def(pybind11::init<>()) + .def("AssignUpdatedVectorVariableToNonFixedComponentsOfNodes", + &NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes); +} } // Namespace Kratos::Python. diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp index e98b14d2a230..86797291560c 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp @@ -38,4 +38,14 @@ void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, } } +void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( + const ModelPart::NodesContainerType& rNodes, + const Variable>& rDestinationVariable, + const array_1d& rNewValues) +{ + block_for_each(rNodes, [&rDestinationVariable, &rNewValues](Node& rNode) { + AssignUpdatedVectorVariableToNonFixedComponents(rNode, rDestinationVariable, rNewValues); + }); +} + } // namespace Kratos diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h index e0ddc41e6c4f..9eeb2b8b3031 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h @@ -23,9 +23,15 @@ class Node; class KRATOS_API(GEO_MECHANICS_APPLICATION) NodeUtilities { public: + KRATOS_CLASS_POINTER_DEFINITION(NodeUtilities); + static void AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, const Variable>& rDestinationVariable, const array_1d& rNewValues); + + static void AssignUpdatedVectorVariableToNonFixedComponentsOfNodes(const ModelPart::NodesContainerType& rNodes, + const Variable>& rDestinationVariable, + const array_1d& rNewValues); }; } // namespace Kratos diff --git a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py index 6818a55b8da6..1a3f13f840cc 100644 --- a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py +++ b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py @@ -57,23 +57,16 @@ def _CalculateTotalDisplacement(self,node, old_total_displacement): def ResetIfHasNodalSolutionStepVariable(self, variable): if self._GetSolver().main_model_part.HasNodalSolutionStepVariable(variable): - for node in self._GetSolver().GetComputingModelPart().Nodes: - if not node.IsFixed(variable): - node.SetSolutionStepValue(variable, 0, 0.0) - new_value = node.GetSolutionStepValue(variable, 0) - node.SetSolutionStepValue(variable, 1, new_value) - - def ModifyAfterSolverInitialize(self): - # Overrides the base class. Necessary to let reset_displacements function correctly i.c.w. prescribed displacements/rotations. - # The reset needs to take place befor the Initialize of the processes, as these will set the Dirichlet condition. + KratosGeo.NodeUtilities.AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( + self._GetSolver().GetComputingModelPart().Nodes, variable, Kratos.Array3([0.0, 0.0, 0.0])) + + def Initialize(self): + super().Initialize() + self._GetSolver().main_model_part.ProcessInfo[KratosGeo.RESET_DISPLACEMENTS] = self.reset_displacements if self.reset_displacements: - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_X) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_Y) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT_Z) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_X) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_Y) - self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION_Z) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.DISPLACEMENT) + self.ResetIfHasNodalSolutionStepVariable(KratosMultiphysics.ROTATION) KratosMultiphysics.VariableUtils().UpdateCurrentToInitialConfiguration(self._GetSolver().GetComputingModelPart().Nodes) From b40ab0c6b696c5b4672a41bbfd7eb9a7c062d76f Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 15:37:09 +0100 Subject: [PATCH 05/12] Formatting --- .../custom_elements/compressibility_calculator.cpp | 2 +- .../custom_elements/permeability_calculator.cpp | 10 +++++----- .../custom_elements/permeability_calculator.h | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_elements/compressibility_calculator.cpp b/applications/GeoMechanicsApplication/custom_elements/compressibility_calculator.cpp index 6a865db70e6a..394ef8313975 100644 --- a/applications/GeoMechanicsApplication/custom_elements/compressibility_calculator.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/compressibility_calculator.cpp @@ -38,7 +38,7 @@ Vector CompressibilityCalculator::RHSContribution(const Matrix& rCompressibility Matrix CompressibilityCalculator::LHSContribution(const Matrix& rCompressibilityMatrix) const { - return mInputProvider.GetMatrixScalarFactor()* rCompressibilityMatrix; + return mInputProvider.GetMatrixScalarFactor() * rCompressibilityMatrix; } std::pair CompressibilityCalculator::LocalSystemContribution() diff --git a/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.cpp b/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.cpp index 70c4452b6c34..64c698360706 100644 --- a/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.cpp @@ -44,11 +44,11 @@ Vector PermeabilityCalculator::RHSContribution(const Matrix& rPermeabilityMatrix Matrix PermeabilityCalculator::CalculatePermeabilityMatrix() const { RetentionLaw::Parameters retention_parameters(mInputProvider.GetElementProperties()); - const auto& r_properties = mInputProvider.GetElementProperties(); - auto integration_coefficients = mInputProvider.GetIntegrationCoefficients(); - const auto shape_function_gradients = mInputProvider.GetShapeFunctionGradients(); - const auto local_dimension = shape_function_gradients[0].size2(); - const Matrix constitutive_matrix = + const auto& r_properties = mInputProvider.GetElementProperties(); + auto integration_coefficients = mInputProvider.GetIntegrationCoefficients(); + const auto shape_function_gradients = mInputProvider.GetShapeFunctionGradients(); + const auto local_dimension = shape_function_gradients[0].size2(); + const Matrix constitutive_matrix = GeoElementUtilities::FillPermeabilityMatrix(r_properties, local_dimension); const auto number_of_nodes = shape_function_gradients[0].size1(); diff --git a/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.h b/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.h index 7f3329ead9db..86ffbee68004 100644 --- a/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.h +++ b/applications/GeoMechanicsApplication/custom_elements/permeability_calculator.h @@ -26,7 +26,7 @@ class PermeabilityCalculator : public ContributionCalculator class InputProvider { public: - InputProvider(std::function GetElementProperties, + InputProvider(std::function GetElementProperties, std::function&()> GetRetentionLaws, std::function GetIntegrationCoefficients, std::function&)> GetNodalValuesOf, @@ -39,9 +39,9 @@ class PermeabilityCalculator : public ContributionCalculator { } - [[nodiscard]] const Properties& GetElementProperties() const; + [[nodiscard]] const Properties& GetElementProperties() const; [[nodiscard]] const std::vector& GetRetentionLaws() const; - [[nodiscard]] Vector GetIntegrationCoefficients() const; + [[nodiscard]] Vector GetIntegrationCoefficients() const; [[nodiscard]] Vector GetNodalValues(const Variable& rVariable) const; [[nodiscard]] Geometry::ShapeFunctionsGradientsType GetShapeFunctionGradients() const; From 2f22df8737fc5545478a2843144a779a62f49a95 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 15:43:06 +0100 Subject: [PATCH 06/12] Removed redundant 'init' definition --- .../custom_python/add_custom_utilities_to_python.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp index 6dcff1addbe8..d258664f05c0 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp @@ -24,7 +24,6 @@ namespace Kratos::Python void AddCustomUtilitiesToPython(pybind11::module& m) { pybind11::class_(m, "NodeUtilities") - .def(pybind11::init<>()) .def("AssignUpdatedVectorVariableToNonFixedComponentsOfNodes", &NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes); } From 4cfb2be62b979ffd2d7fb1d48a863135baf50810 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 15:51:18 +0100 Subject: [PATCH 07/12] Added setting the previous value to zero as well --- .../custom_utilities/node_utilities.cpp | 12 +++++++----- .../custom_utilities/node_utilities.h | 6 ++++-- .../python_scripts/geomechanics_analysis.py | 5 ++++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp index 86797291560c..ef92902f0580 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp @@ -22,7 +22,8 @@ namespace Kratos void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, const Variable>& rDestinationVariable, - const array_1d& rNewValues) + const array_1d& rNewValues, + IndexType SolutionStepIndex) { const std::vector components = {"X", "Y", "Z"}; for (const auto& zipped : boost::combine(rNewValues, components)) { @@ -33,7 +34,7 @@ void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, if (const auto& component_variable = VariablesUtilities::GetComponentFromVectorVariable(rDestinationVariable.Name(), component); !rNode.IsFixed(component_variable)) { - rNode.FastGetSolutionStepValue(component_variable, 0) = new_value; + rNode.FastGetSolutionStepValue(component_variable, SolutionStepIndex) = new_value; } } } @@ -41,10 +42,11 @@ void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( const ModelPart::NodesContainerType& rNodes, const Variable>& rDestinationVariable, - const array_1d& rNewValues) + const array_1d& rNewValues, + IndexType SolutionStepIndex) { - block_for_each(rNodes, [&rDestinationVariable, &rNewValues](Node& rNode) { - AssignUpdatedVectorVariableToNonFixedComponents(rNode, rDestinationVariable, rNewValues); + block_for_each(rNodes, [&rDestinationVariable, &rNewValues, SolutionStepIndex](Node& rNode) { + AssignUpdatedVectorVariableToNonFixedComponents(rNode, rDestinationVariable, rNewValues, SolutionStepIndex); }); } diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h index 9eeb2b8b3031..127afe230553 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h @@ -27,11 +27,13 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) NodeUtilities static void AssignUpdatedVectorVariableToNonFixedComponents(Node& rNode, const Variable>& rDestinationVariable, - const array_1d& rNewValues); + const array_1d& rNewValues, + IndexType SolutionStepIndex = 0); static void AssignUpdatedVectorVariableToNonFixedComponentsOfNodes(const ModelPart::NodesContainerType& rNodes, const Variable>& rDestinationVariable, - const array_1d& rNewValues); + const array_1d& rNewValues, + IndexType SolutionStepIndex = 0); }; } // namespace Kratos diff --git a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py index 1a3f13f840cc..8e872345545a 100644 --- a/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py +++ b/applications/GeoMechanicsApplication/python_scripts/geomechanics_analysis.py @@ -57,8 +57,11 @@ def _CalculateTotalDisplacement(self,node, old_total_displacement): def ResetIfHasNodalSolutionStepVariable(self, variable): if self._GetSolver().main_model_part.HasNodalSolutionStepVariable(variable): + zero_vector = Kratos.Array3([0.0, 0.0, 0.0]) KratosGeo.NodeUtilities.AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( - self._GetSolver().GetComputingModelPart().Nodes, variable, Kratos.Array3([0.0, 0.0, 0.0])) + self._GetSolver().GetComputingModelPart().Nodes, variable, zero_vector, 0) + KratosGeo.NodeUtilities.AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( + self._GetSolver().GetComputingModelPart().Nodes, variable, zero_vector, 1) def Initialize(self): super().Initialize() From b8e14ceb3bba16c2f3ee887bfb7cdef7081ef583 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 17:03:15 +0100 Subject: [PATCH 08/12] Made same fix for C++ route --- .../custom_utilities/node_utilities.cpp | 2 +- .../custom_workflows/dgeosettlement.cpp | 14 ++++++-------- .../custom_workflows/dgeosettlement.h | 11 ++++------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp index ef92902f0580..7540210fc910 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.cpp @@ -43,7 +43,7 @@ void NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( const ModelPart::NodesContainerType& rNodes, const Variable>& rDestinationVariable, const array_1d& rNewValues, - IndexType SolutionStepIndex) + IndexType SolutionStepIndex) { block_for_each(rNodes, [&rDestinationVariable, &rNewValues, SolutionStepIndex](Node& rNode) { AssignUpdatedVectorVariableToNonFixedComponents(rNode, rDestinationVariable, rNewValues, SolutionStepIndex); diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp index cae242401994..9c763019a3f1 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp @@ -191,14 +191,6 @@ int KratosGeoSettlement::RunStage(const std::filesystem::path& rWorki std::vector> processes = GetProcesses(project_parameters); std::vector> process_observables(processes.begin(), processes.end()); - if (mpTimeLoopExecutor) { - mpTimeLoopExecutor->SetCancelDelegate(rShouldCancel); - mpTimeLoopExecutor->SetProgressDelegate(rProgressDelegate); - mpTimeLoopExecutor->SetProcessObservables(process_observables); - mpTimeLoopExecutor->SetTimeIncrementor(MakeTimeIncrementor(project_parameters)); - mpTimeLoopExecutor->SetSolverStrategyWrapper(MakeStrategyWrapper(project_parameters, rWorkingDirectory)); - } - for (const auto& process : processes) { process->ExecuteInitialize(); } @@ -208,6 +200,12 @@ int KratosGeoSettlement::RunStage(const std::filesystem::path& rWorki } if (mpTimeLoopExecutor) { + mpTimeLoopExecutor->SetCancelDelegate(rShouldCancel); + mpTimeLoopExecutor->SetProgressDelegate(rProgressDelegate); + mpTimeLoopExecutor->SetProcessObservables(process_observables); + mpTimeLoopExecutor->SetTimeIncrementor(MakeTimeIncrementor(project_parameters)); + mpTimeLoopExecutor->SetSolverStrategyWrapper(MakeStrategyWrapper(project_parameters, rWorkingDirectory)); + // For now, pass a dummy state. THIS PROBABLY NEEDS TO BE REFINED AT SOME POINT! TimeStepEndState start_of_loop_state; start_of_loop_state.convergence_state = TimeStepEndState::ConvergenceState::converged; diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h index b3fdf6e24c44..4b84c66aeeea 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h @@ -77,13 +77,10 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) KratosGeoSettlement { if (!GetComputationalModelPart().HasNodalSolutionStepVariable(rVariable)) return; - VariableUtils{}.SetHistoricalVariableToZero(rVariable, GetComputationalModelPart().Nodes()); - - block_for_each(GetComputationalModelPart().Nodes(), - [&rVariable, SourceIndex, DestinationIndex](auto& node) { - node.GetSolutionStepValue(rVariable, DestinationIndex) = - node.GetSolutionStepValue(rVariable, SourceIndex); - }); + NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( + GetComputationalModelPart().Nodes(), rVariable, ZeroVector{3}, 0); + NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( + GetComputationalModelPart().Nodes(), rVariable, ZeroVector{3}, 1); } template From cf2a96cc5dc2f3224ee950fe6d83a09b0beca895 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Tue, 12 Nov 2024 17:31:52 +0100 Subject: [PATCH 09/12] Add missing include --- .../GeoMechanicsApplication/custom_workflows/dgeosettlement.h | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h index 4b84c66aeeea..25a96bcd5782 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h @@ -19,6 +19,7 @@ #include "includes/kernel.h" #include "includes/kratos_export_api.h" +#include "custom_utilities/node_utilities.h" #include "custom_utilities/process_factory.hpp" #include "geo_mechanics_application.h" #include "linear_solvers_application.h" From 73b47c337457f18db87ae7a5d15a1e1a464f97ff Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Wed, 13 Nov 2024 10:39:38 +0100 Subject: [PATCH 10/12] Processing review comments --- .../custom_python/add_custom_utilities_to_python.cpp | 4 ++-- .../custom_python/add_custom_utilities_to_python.h | 2 +- .../GeoMechanicsApplication/custom_workflows/dgeosettlement.h | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp index d258664f05c0..b707e3e79703 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp @@ -21,9 +21,9 @@ namespace Kratos::Python { -void AddCustomUtilitiesToPython(pybind11::module& m) +void AddCustomUtilitiesToPython(pybind11::module& rModule) { - pybind11::class_(m, "NodeUtilities") + pybind11::class_(rModule, "NodeUtilities") .def("AssignUpdatedVectorVariableToNonFixedComponentsOfNodes", &NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes); } diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h index 3a3b6f8df4e9..4c814194dc1f 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h @@ -25,7 +25,7 @@ namespace Kratos::Python { -void AddCustomUtilitiesToPython(pybind11::module&); +void AddCustomUtilitiesToPython(pybind11::module& rModule); } // namespace Kratos::Python. diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h index 25a96bcd5782..d0700c825625 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h @@ -79,9 +79,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) KratosGeoSettlement if (!GetComputationalModelPart().HasNodalSolutionStepVariable(rVariable)) return; NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( - GetComputationalModelPart().Nodes(), rVariable, ZeroVector{3}, 0); + GetComputationalModelPart().Nodes(), rVariable, rVariable.Zero(), 0); NodeUtilities::AssignUpdatedVectorVariableToNonFixedComponentsOfNodes( - GetComputationalModelPart().Nodes(), rVariable, ZeroVector{3}, 1); + GetComputationalModelPart().Nodes(), rVariable, rVariable.Zero(), 1); } template From 014d94e83578222ead71b895f8460db91889bbe5 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Wed, 13 Nov 2024 14:58:05 +0100 Subject: [PATCH 11/12] add missing include to fix non-unity builds --- .../GeoMechanicsApplication/custom_utilities/node_utilities.h | 1 + 1 file changed, 1 insertion(+) diff --git a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h index 127afe230553..bcd77544f50e 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h +++ b/applications/GeoMechanicsApplication/custom_utilities/node_utilities.h @@ -14,6 +14,7 @@ #include "containers/array_1d.h" #include "containers/variable.h" +#include "includes/model_part.h" namespace Kratos { From c0a277c9de65e13c9be540ad268c297c7d497ad9 Mon Sep 17 00:00:00 2001 From: Richard Faasse Date: Thu, 14 Nov 2024 09:11:26 +0100 Subject: [PATCH 12/12] Fix sonarqube issues --- .../custom_python/add_custom_utilities_to_python.cpp | 2 +- .../custom_python/add_custom_utilities_to_python.h | 2 +- .../custom_workflows/dgeosettlement.cpp | 6 ++---- .../custom_workflows/dgeosettlement.h | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp index b707e3e79703..2ce29608bcb3 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.cpp @@ -21,7 +21,7 @@ namespace Kratos::Python { -void AddCustomUtilitiesToPython(pybind11::module& rModule) +void AddCustomUtilitiesToPython(const pybind11::module& rModule) { pybind11::class_(rModule, "NodeUtilities") .def("AssignUpdatedVectorVariableToNonFixedComponentsOfNodes", diff --git a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h index 4c814194dc1f..dd9edb7f77c6 100644 --- a/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h +++ b/applications/GeoMechanicsApplication/custom_python/add_custom_utilities_to_python.h @@ -25,7 +25,7 @@ namespace Kratos::Python { -void AddCustomUtilitiesToPython(pybind11::module& rModule); +void AddCustomUtilitiesToPython(const pybind11::module& rModule); } // namespace Kratos::Python. diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp index 9c763019a3f1..4447f27177fc 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.cpp @@ -339,10 +339,8 @@ std::shared_ptr KratosGeoSettlement::MakeStrategyWrapper(const GetMainModelPart().CloneTimeStep(); if (rProjectParameters["solver_settings"]["reset_displacements"].GetBool()) { - constexpr auto source_index = std::size_t{0}; - constexpr auto destination_index = std::size_t{1}; - RestoreValuesOfNodalVariable(DISPLACEMENT, source_index, destination_index); - RestoreValuesOfNodalVariable(ROTATION, source_index, destination_index); + ResetValuesOfNodalVariable(DISPLACEMENT); + ResetValuesOfNodalVariable(ROTATION); VariableUtils{}.UpdateCurrentToInitialConfiguration(GetComputationalModelPart().Nodes()); } diff --git a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h index d0700c825625..42c84579fc4c 100644 --- a/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h +++ b/applications/GeoMechanicsApplication/custom_workflows/dgeosettlement.h @@ -74,7 +74,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) KratosGeoSettlement const std::stringstream& rKratosLogBuffer) const; template - void RestoreValuesOfNodalVariable(const TVariableType& rVariable, Node::IndexType SourceIndex, Node::IndexType DestinationIndex) + void ResetValuesOfNodalVariable(const TVariableType& rVariable) { if (!GetComputationalModelPart().HasNodalSolutionStepVariable(rVariable)) return;