From 32b6235bc956678ddd095f0db1d05754bdbb620b Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Wed, 15 May 2024 16:58:42 +0200 Subject: [PATCH 1/6] removed CalculateStrain function --- .../U_Pw_small_strain_element.cpp | 13 ++---------- .../U_Pw_small_strain_element.hpp | 11 ++++------ .../small_strain_U_Pw_diff_order_element.cpp | 21 +++++-------------- .../small_strain_U_Pw_diff_order_element.hpp | 9 +++----- 4 files changed, 14 insertions(+), 40 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp index 726ffbe69c9c..c4f555449ce7 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp @@ -1558,16 +1558,6 @@ void UPwSmallStrainElement::CalculateAndAddFluidBodyFlow(Vector KRATOS_CATCH("") } -template -Vector UPwSmallStrainElement::CalculateStrain(const Matrix& rDeformationGradient, - const Matrix& rB, - const Vector& rDisplacements, - bool UseHenckyStrain) const -{ - return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) - : this->CalculateCauchyStrain(rB, rDisplacements); -} - template std::vector UPwSmallStrainElement::CalculateStrains(const std::vector& rDeformationGradients, const std::vector& rBs, @@ -1578,7 +1568,8 @@ std::vector UPwSmallStrainElement::CalculateStrains(con std::transform( rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), [this, &rDisplacements, UseHenckyStrain](const auto& rDeformationGradient, const auto& rB) { - return CalculateStrain(rDeformationGradient, rB, rDisplacements, UseHenckyStrain); + return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) + : this->CalculateCauchyStrain(rB, rDisplacements); }); return result; diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp index 139f01fa0a42..f38c4ee9a811 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp @@ -273,12 +273,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa double CalculateBulkModulus(const Matrix& ConstitutiveMatrix) const; double CalculateBiotCoefficient(const ElementVariables& rVariables, bool hasBiotCoefficient) const; - virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; - virtual Vector CalculateStrain(const Matrix& rDeformationGradient, - const Matrix& rB, - const Vector& rDisplacements, - bool UseHenckyStrain) const; + virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; + virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; + std::vector CalculateStrains(const std::vector& rDeformationGradients, const std::vector& rBs, const Vector& rDisplacements, @@ -291,7 +288,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa void InitializeNodalPorePressureVariables(ElementVariables& rVariables); void InitializeNodalVolumeAccelerationVariables(ElementVariables& rVariables); - void InitializeProperties(ElementVariables& rVariables); + void InitializeProperties(ElementVariables& rVariables); [[nodiscard]] double CalculateFluidPressure(const ElementVariables& rVariables) const; std::vector> CalculateFluidFluxes(const std::vector& rPermeabilityUpdateFactors, const ProcessInfo& rCurrentProcessInfo); diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp index d6d321b44d52..67f553c8199b 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp @@ -2025,29 +2025,18 @@ std::vector SmallStrainUPwDiffOrderElement::CalculateStrains(const std:: bool UseHenckyStrain) const { std::vector result; + const SizeType VoigtSize = + (GetGeometry().WorkingSpaceDimension() == N_DIM_3D ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN); std::transform( rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), - [this, &rDisplacements, UseHenckyStrain](const auto& rDeformationGradient, const auto& rB) { - return CalculateStrain(rDeformationGradient, rB, rDisplacements, UseHenckyStrain); + [this, &rDisplacements, UseHenckyStrain, VoigtSize](const auto& rDeformationGradient, const auto& rB) { + return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) + : this->CalculateCauchyStrain(rB, rDisplacements); }); return result; } -Vector SmallStrainUPwDiffOrderElement::CalculateStrain(const Matrix& rDeformationGradient, - const Matrix& rB, - const Vector& rDisplacements, - bool UseHenckyStrain) const -{ - if (UseHenckyStrain) { - const SizeType Dim = GetGeometry().WorkingSpaceDimension(); - const SizeType VoigtSize = (Dim == N_DIM_3D ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN); - return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize); - } - - return this->CalculateCauchyStrain(rB, rDisplacements); -} - Vector SmallStrainUPwDiffOrderElement::CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const { return prod(rB, rDisplacements); diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp index dc6490f901cd..12153b25602c 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp @@ -293,12 +293,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub void AssignPressureToIntermediateNodes(); - virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; - virtual Vector CalculateStrain(const Matrix& rDeformationGradient, - const Matrix& rB, - const Vector& rDisplacements, - bool UseHenckyStrain) const; + virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; + virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; + std::vector CalculateStrains(const std::vector& rDeformationGradients, const std::vector& rBs, const Vector& rDisplacements, From 7106bc6c84fedce324de248bd5eaa675024fb4ab Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Wed, 15 May 2024 23:22:58 +0200 Subject: [PATCH 2/6] moved CalculateCauchyStrain to stress_strain_utilities --- .../custom_elements/U_Pw_small_strain_element.cpp | 11 +++-------- .../custom_elements/U_Pw_small_strain_element.hpp | 1 - .../small_strain_U_Pw_diff_order_element.cpp | 10 +++------- .../small_strain_U_Pw_diff_order_element.hpp | 1 - .../updated_lagrangian_U_Pw_diff_order_element.hpp | 1 - .../custom_utilities/stress_strain_utilities.cpp | 4 ++++ .../custom_utilities/stress_strain_utilities.h | 1 + 7 files changed, 11 insertions(+), 18 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp index c4f555449ce7..f964c27b76d5 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp @@ -782,7 +782,8 @@ void UPwSmallStrainElement::CalculateOnIntegrationPoints(const Variables.B = this->CalculateBMatrix(Variables.GradNpTInitialConfiguration, Variables.Np); // Compute infinitesimal strain - Variables.StrainVector = this->CalculateCauchyStrain(Variables.B, Variables.DisplacementVector); + Variables.StrainVector = + StressStrainUtilities::CalculateCauchyStrain(Variables.B, Variables.DisplacementVector); if (rOutput[GPoint].size() != Variables.StrainVector.size()) rOutput[GPoint].resize(Variables.StrainVector.size(), false); @@ -1569,18 +1570,12 @@ std::vector UPwSmallStrainElement::CalculateStrains(con rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), [this, &rDisplacements, UseHenckyStrain](const auto& rDeformationGradient, const auto& rB) { return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) - : this->CalculateCauchyStrain(rB, rDisplacements); + : StressStrainUtilities::CalculateCauchyStrain(rB, rDisplacements); }); return result; } -template -Vector UPwSmallStrainElement::CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const -{ - return prod(rB, rDisplacements); -} - template Vector UPwSmallStrainElement::CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const { diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp index f38c4ee9a811..fc88f5da7189 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp @@ -274,7 +274,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa double CalculateBiotCoefficient(const ElementVariables& rVariables, bool hasBiotCoefficient) const; virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; std::vector CalculateStrains(const std::vector& rDeformationGradients, const std::vector& rBs, diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp index 67f553c8199b..80ae594a110e 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp @@ -1094,7 +1094,8 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable Variables.B = this->CalculateBMatrix(Variables.DNu_DXInitialConfiguration, Variables.Nu); // Compute infinitesimal strain - Variables.StrainVector = this->CalculateCauchyStrain(Variables.B, Variables.DisplacementVector); + Variables.StrainVector = + StressStrainUtilities::CalculateCauchyStrain(Variables.B, Variables.DisplacementVector); if (rOutput[GPoint].size() != Variables.StrainVector.size()) rOutput[GPoint].resize(Variables.StrainVector.size(), false); @@ -2031,17 +2032,12 @@ std::vector SmallStrainUPwDiffOrderElement::CalculateStrains(const std:: rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), [this, &rDisplacements, UseHenckyStrain, VoigtSize](const auto& rDeformationGradient, const auto& rB) { return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) - : this->CalculateCauchyStrain(rB, rDisplacements); + : StressStrainUtilities::CalculateCauchyStrain(rB, rDisplacements); }); return result; } -Vector SmallStrainUPwDiffOrderElement::CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const -{ - return prod(rB, rDisplacements); -} - Vector SmallStrainUPwDiffOrderElement::CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const { return mpStressStatePolicy->CalculateGreenLagrangeStrain(rDeformationGradient); diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp index 12153b25602c..d61e9ed24664 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp @@ -294,7 +294,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub void AssignPressureToIntermediateNodes(); virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) const; std::vector CalculateStrains(const std::vector& rDeformationGradients, const std::vector& rBs, diff --git a/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.hpp b/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.hpp index 6c992886e133..1fbdec4e411f 100644 --- a/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.hpp @@ -67,7 +67,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UpdatedLagrangianUPwDiffOrderElement /// The definition of the sizetype using SizeType = std::size_t; - using SmallStrainUPwDiffOrderElement::CalculateCauchyStrain; using SmallStrainUPwDiffOrderElement::CalculateDerivativesOnInitialConfiguration; using SmallStrainUPwDiffOrderElement::CalculateGreenLagrangeStrain; using SmallStrainUPwDiffOrderElement::mConstitutiveLawVector; diff --git a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp index baf741afb2bf..81a0253e4faf 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp +++ b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp @@ -152,4 +152,8 @@ Matrix StressStrainUtilities::CalculateGreenLagrangeStrainTensor(const Matrix& r IdentityMatrix(rDeformationGradient.size1())); } +Vector StressStrainUtilities::CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements) +{ + return prod(rB, rDisplacements); +} } // namespace Kratos diff --git a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h index 1e3e1c5d2aa6..486fdf9eceb4 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h +++ b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h @@ -32,6 +32,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) StressStrainUtilities static double CalculateVonMisesStrain(const Vector& rStrainVector); static Vector CalculateHenckyStrain(const Matrix& rDeformationGradient, size_t VoigtSize); static Matrix CalculateGreenLagrangeStrainTensor(const Matrix& rDeformationGradient); + static Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements); private: static double CalculateQMohrCoulomb(const Vector& rStressVector, double C, double Phi); From 7bde46b288900e2627bbdddd63102d8f79018d9c Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Wed, 15 May 2024 23:45:12 +0200 Subject: [PATCH 3/6] moved CalculateStrains to stress_strain_utilities --- .../U_Pw_small_strain_FIC_element.cpp | 12 ++--- .../U_Pw_small_strain_element.cpp | 54 +++++++------------ .../U_Pw_small_strain_element.hpp | 5 -- .../U_Pw_updated_lagrangian_FIC_element.cpp | 4 +- .../U_Pw_updated_lagrangian_element.cpp | 4 +- .../small_strain_U_Pw_diff_order_element.cpp | 52 ++++++++---------- .../small_strain_U_Pw_diff_order_element.hpp | 5 +- ...ted_lagrangian_U_Pw_diff_order_element.cpp | 5 +- .../stress_strain_utilities.cpp | 18 +++++++ .../stress_strain_utilities.h | 5 ++ 10 files changed, 79 insertions(+), 85 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_FIC_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_FIC_element.cpp index 1d2648c0726c..f5f77316063e 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_FIC_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_FIC_element.cpp @@ -141,8 +141,8 @@ void UPwSmallStrainFICElement::InitializeNonLinearIteration(con const auto deformation_gradients = this->CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -202,8 +202,8 @@ void UPwSmallStrainFICElement::FinalizeNonLinearIteration(const const auto deformation_gradients = this->CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -465,8 +465,8 @@ void UPwSmallStrainFICElement::CalculateAll(MatrixType& rLeftHa const auto deformation_gradients = this->CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp index f964c27b76d5..099cd2e1f3a3 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp @@ -155,8 +155,8 @@ void UPwSmallStrainElement::InitializeSolutionStep(const Proces const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -269,8 +269,8 @@ void UPwSmallStrainElement::InitializeNonLinearIteration(const const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -328,8 +328,8 @@ void UPwSmallStrainElement::FinalizeSolutionStep(const ProcessI const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); Matrix StressContainer(NumGPoints, mStressVector[0].size()); // Loop over integration points @@ -596,8 +596,8 @@ void UPwSmallStrainElement::CalculateOnIntegrationPoints(const const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); for (unsigned int GPoint = 0; GPoint < mConstitutiveLawVector.size(); ++GPoint) { const PropertiesType& rProp = this->GetProperties(); @@ -658,8 +658,8 @@ void UPwSmallStrainElement::CalculateOnIntegrationPoints( const auto b_matrices = CalculateBMatrices(Variables.DN_DXContainer, Variables.NContainer); const auto deformation_gradients = CalculateDeformationGradients(); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); std::vector permeability_update_factors; for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -731,8 +731,8 @@ void UPwSmallStrainElement::CalculateOnIntegrationPoints(const const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Loop over integration points for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { @@ -796,8 +796,9 @@ void UPwSmallStrainElement::CalculateOnIntegrationPoints(const const auto b_matrices = CalculateBMatrices(Variables.DN_DXContainer, Variables.NContainer); const auto deformation_gradients = CalculateDeformationGradients(); - rOutput = CalculateStrains(deformation_gradients, b_matrices, Variables.DisplacementVector, - Variables.UseHenckyStrain); + rOutput = StressStrainUtilities::CalculateStrains(deformation_gradients, b_matrices, + Variables.DisplacementVector, + Variables.UseHenckyStrain, VoigtSize); } else if (rProp.Has(rVariable)) { // Map initial material property to Gauss points, as required for the output rOutput.clear(); @@ -909,8 +910,8 @@ void UPwSmallStrainElement::CalculateMaterialStiffnessMatrix(Ma const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { // Compute Np, GradNpT, B and StrainVector @@ -1038,8 +1039,8 @@ void UPwSmallStrainElement::CalculateAll(MatrixType& rLe const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { // Compute GradNpT, B and StrainVector @@ -1559,23 +1560,6 @@ void UPwSmallStrainElement::CalculateAndAddFluidBodyFlow(Vector KRATOS_CATCH("") } -template -std::vector UPwSmallStrainElement::CalculateStrains(const std::vector& rDeformationGradients, - const std::vector& rBs, - const Vector& rDisplacements, - bool UseHenckyStrain) const -{ - std::vector result; - std::transform( - rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), - [this, &rDisplacements, UseHenckyStrain](const auto& rDeformationGradient, const auto& rB) { - return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) - : StressStrainUtilities::CalculateCauchyStrain(rB, rDisplacements); - }); - - return result; -} - template Vector UPwSmallStrainElement::CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const { diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp index fc88f5da7189..4b0e2a5467be 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp @@ -275,11 +275,6 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) UPwSmallStrainElement : public UPwBa virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - std::vector CalculateStrains(const std::vector& rDeformationGradients, - const std::vector& rBs, - const Vector& rDisplacements, - bool UseHenckyStrain) const; - Matrix CalculateDeformationGradient(unsigned int GPoint) const; std::vector CalculateDeformationGradients() const; diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp index 93b137e8f687..9f6df847037e 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp @@ -79,8 +79,8 @@ void UPwUpdatedLagrangianFICElement::CalculateAll(MatrixType& r const auto deformation_gradients = this->CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Computing in all integrations points for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp index 607f1db1e7be..ad0337bd2973 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp @@ -90,8 +90,8 @@ void UPwUpdatedLagrangianElement::CalculateAll(MatrixType& rLef const auto deformation_gradients = this->CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); // Computing in all integrations points for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp index 80ae594a110e..397d62afaead 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp @@ -320,8 +320,9 @@ void SmallStrainUPwDiffOrderElement::InitializeSolutionStep(const ProcessInfo& r const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + GetVoigtSize()); // Loop over integration points for (unsigned int GPoint = 0; GPoint < mConstitutiveLawVector.size(); ++GPoint) { @@ -535,8 +536,9 @@ void SmallStrainUPwDiffOrderElement::FinalizeSolutionStep(const ProcessInfo& rCu const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + GetVoigtSize()); // Loop over integration points for (unsigned int GPoint = 0; GPoint < mConstitutiveLawVector.size(); ++GPoint) { @@ -1002,8 +1004,9 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable RetentionLaw::Parameters RetentionParameters(GetProperties(), rCurrentProcessInfo); const auto b_matrices = CalculateBMatrices(Variables.DNu_DXContainer, Variables.NuContainer); const auto deformation_gradients = CalculateDeformationGradients(); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, + Variables.UseHenckyStrain, GetVoigtSize()); // Loop over integration points for (unsigned int GPoint = 0; GPoint < mConstitutiveLawVector.size(); ++GPoint) { @@ -1108,8 +1111,9 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable this->InitializeElementVariables(Variables, rCurrentProcessInfo); const auto b_matrices = CalculateBMatrices(Variables.DNu_DXContainer, Variables.NuContainer); const auto deformation_gradients = CalculateDeformationGradients(); - rOutput = CalculateStrains(deformation_gradients, b_matrices, Variables.DisplacementVector, - Variables.UseHenckyStrain); + rOutput = StressStrainUtilities::CalculateStrains(deformation_gradients, b_matrices, + Variables.DisplacementVector, + Variables.UseHenckyStrain, GetVoigtSize()); } else if (rVariable == TOTAL_STRESS_VECTOR) { // Definition of variables ElementVariables Variables; @@ -1139,8 +1143,9 @@ void SmallStrainUPwDiffOrderElement::CalculateOnIntegrationPoints(const Variable const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, + Variables.UseHenckyStrain, GetVoigtSize()); // Loop over integration points for (unsigned int GPoint = 0; GPoint < mConstitutiveLawVector.size(); ++GPoint) { @@ -1288,8 +1293,9 @@ void SmallStrainUPwDiffOrderElement::CalculateAll(MatrixType& rLeftHandSi GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); const auto integration_coefficients = CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJuContainer); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + GetVoigtSize()); for (unsigned int GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { // compute element kinematics (Np, gradNpT, |J|, B, strains) @@ -1353,8 +1359,9 @@ void SmallStrainUPwDiffOrderElement::CalculateMaterialStiffnessMatrix(MatrixType const auto deformation_gradients = CalculateDeformationGradients(); const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); - const auto strain_vectors = CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + GetVoigtSize()); for (unsigned int GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { // compute element kinematics (Np, gradNpT, |J|, B, strains) @@ -2020,22 +2027,9 @@ GeometryData::IntegrationMethod SmallStrainUPwDiffOrderElement::GetIntegrationMe return GI_GAUSS; } -std::vector SmallStrainUPwDiffOrderElement::CalculateStrains(const std::vector& rDeformationGradients, - const std::vector& rBs, - const Vector& rDisplacements, - bool UseHenckyStrain) const +SizeType SmallStrainUPwDiffOrderElement::GetVoigtSize() const { - std::vector result; - const SizeType VoigtSize = - (GetGeometry().WorkingSpaceDimension() == N_DIM_3D ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN); - std::transform( - rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), - [this, &rDisplacements, UseHenckyStrain, VoigtSize](const auto& rDeformationGradient, const auto& rB) { - return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize) - : StressStrainUtilities::CalculateCauchyStrain(rB, rDisplacements); - }); - - return result; + return (GetGeometry().WorkingSpaceDimension() == N_DIM_3D ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN); } Vector SmallStrainUPwDiffOrderElement::CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const diff --git a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp index d61e9ed24664..eaae388f0061 100644 --- a/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp +++ b/applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.hpp @@ -295,10 +295,7 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub virtual Vector CalculateGreenLagrangeStrain(const Matrix& rDeformationGradient) const; - std::vector CalculateStrains(const std::vector& rDeformationGradients, - const std::vector& rBs, - const Vector& rDisplacements, - bool UseHenckyStrain) const; + SizeType GetVoigtSize() const; Matrix CalculateDeformationGradient(unsigned int GPoint) const; std::vector CalculateDeformationGradients() const; diff --git a/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.cpp b/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.cpp index 8572b942b86a..7e913be5e0b7 100644 --- a/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.cpp @@ -77,8 +77,9 @@ void UpdatedLagrangianUPwDiffOrderElement::CalculateAll(MatrixType& rLeft GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); const auto integration_coefficients = this->CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJuContainer); - const auto strain_vectors = this->CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain); + const auto strain_vectors = StressStrainUtilities::CalculateStrains( + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + this->GetVoigtSize()); // Computing in all integrations points for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { diff --git a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp index 81a0253e4faf..588edc3dc170 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp +++ b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.cpp @@ -156,4 +156,22 @@ Vector StressStrainUtilities::CalculateCauchyStrain(const Matrix& rB, const Vect { return prod(rB, rDisplacements); } + +std::vector StressStrainUtilities::CalculateStrains(const std::vector& rDeformationGradients, + const std::vector& rBs, + const Vector& rDisplacements, + bool UseHenckyStrain, + std::size_t VoigtSize) +{ + std::vector result; + std::transform( + rDeformationGradients.begin(), rDeformationGradients.end(), rBs.begin(), std::back_inserter(result), + [&rDisplacements, UseHenckyStrain, VoigtSize](const auto& rDeformationGradient, const auto& rB) { + return UseHenckyStrain ? CalculateHenckyStrain(rDeformationGradient, VoigtSize) + : CalculateCauchyStrain(rB, rDisplacements); + }); + + return result; +} + } // namespace Kratos diff --git a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h index 486fdf9eceb4..37240ea31f73 100644 --- a/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h +++ b/applications/GeoMechanicsApplication/custom_utilities/stress_strain_utilities.h @@ -33,6 +33,11 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) StressStrainUtilities static Vector CalculateHenckyStrain(const Matrix& rDeformationGradient, size_t VoigtSize); static Matrix CalculateGreenLagrangeStrainTensor(const Matrix& rDeformationGradient); static Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements); + static std::vector CalculateStrains(const std::vector& rDeformationGradients, + const std::vector& rBs, + const Vector& rDisplacements, + bool UseHenckyStrain, + std::size_t VoigtSize); private: static double CalculateQMohrCoulomb(const Vector& rStressVector, double C, double Phi); From c5ad933d0f1b14ef7b63c97bf9deb8cde1206aa1 Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Thu, 16 May 2024 00:12:40 +0200 Subject: [PATCH 4/6] fixed error with undefined VoightSize --- .../custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp | 3 ++- .../custom_elements/U_Pw_updated_lagrangian_element.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp index 9f6df847037e..0cf67e138016 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp @@ -80,7 +80,8 @@ void UPwUpdatedLagrangianFICElement::CalculateAll(MatrixType& r const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); const auto strain_vectors = StressStrainUtilities::CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + this->VoigtSize); // Computing in all integrations points for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { diff --git a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp index ad0337bd2973..2a0183fb3343 100644 --- a/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp +++ b/applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp @@ -91,7 +91,8 @@ void UPwUpdatedLagrangianElement::CalculateAll(MatrixType& rLef const auto determinants_of_deformation_gradients = GeoMechanicsMathUtilities::CalculateDeterminants(deformation_gradients); const auto strain_vectors = StressStrainUtilities::CalculateStrains( - deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, VoigtSize); + deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain, + this->VoigtSize); // Computing in all integrations points for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { From 45d7cf4e340143dbd39eac4919185fc4b00e976a Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Thu, 16 May 2024 19:34:52 +0200 Subject: [PATCH 5/6] added 2 unit tests --- .../test_stress_strain_utitlities.cpp | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp b/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp index 40745b0cfd7f..6ae98ed083d0 100644 --- a/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp +++ b/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp @@ -8,6 +8,7 @@ // License: geo_mechanics_application/license.txt // // Main authors: Wijtze Pieter Kikstra +// Gennady Markelov // #include "custom_utilities/math_utilities.h" @@ -118,4 +119,69 @@ KRATOS_TEST_CASE_IN_SUITE(CheckCalculateMohrCoulombPressureCapacityShearOnly, Kr 1.E-10); } +KRATOS_TEST_CASE_IN_SUITE(CheckCalculateCauchyStrain, KratosGeoMechanicsFastSuite) +{ + Matrix B(5, 5); + // clang-format off + B <<=1.0, 2.0, 3.0, 4.0, 5.0, + 1.1, 1.2, 1.3, 1.4, 1.5, + 1.0, 0.9, 0.8, 0.7, 0.6, + 0.0, 1.0, 2.0, 3.0, 4.0, + 5.0, 4.0, 3.0, 2.0, 1.0; + // clang-format on + + Vector displacements(5); + displacements <<= 0.01, 0.02, 0.03, 0.04, 0.05; + + const auto strain = StressStrainUtilities::CalculateCauchyStrain(B, displacements); + + Vector expected_strain(5); + expected_strain <<= 0.55, 0.205, 0.11, 0.4, 0.35; + + KRATOS_EXPECT_VECTOR_NEAR(strain, expected_strain, 1.E-10); +} + +KRATOS_TEST_CASE_IN_SUITE(CheckCalculateStrains, KratosGeoMechanicsFastSuite) +{ + Matrix B(4, 4); + // clang-format off + B <<=1.0, 2.0, 3.0, 4.0, + 1.1, 1.2, 1.3, 1.4, + 1.0, 0.9, 0.8, 0.7, + 0.0, 1.0, 2.0, 3.0; + // clang-format on + + Vector displacements(4); + displacements <<= 0.01, 0.02, 0.03, 0.04; + + bool use_hencky_strain = false; + std::size_t voigt_size = 4; + + std::vector Bs; + Bs.push_back(B); + Bs.push_back(B); + + std::vector deformationGradients; + deformationGradients.push_back(B); + deformationGradients.push_back(B); + + auto strains = StressStrainUtilities::CalculateStrains(deformationGradients, Bs, displacements, + use_hencky_strain, voigt_size); + Vector expected_strain(4); + expected_strain <<= 0.3, 0.13, 0.08, 0.2; + std::vector expected_strains; + expected_strains.push_back(expected_strain); + expected_strains.push_back(expected_strain); + + for (size_t i = 0; i < strains.size(); ++i) + KRATOS_EXPECT_VECTOR_NEAR(strains[i], expected_strains[i], 1.E-10); + + /* use_hencky_strain = true; + strains = StressStrainUtilities::CalculateStrains(deformationGradients, Bs, displacements, + use_hencky_strain, voigt_size); + for (size_t i = 0; i < strains.size(); ++i) + KRATOS_EXPECT_VECTOR_NEAR(strains[i], expected_strains[i], 1.E-10); + */ +} + } // namespace Kratos::Testing \ No newline at end of file From ea2d9389cc4baef336bb960b53261a21f8a04e6c Mon Sep 17 00:00:00 2001 From: Gennady Markelov Date: Fri, 17 May 2024 10:47:43 +0200 Subject: [PATCH 6/6] corrected input for test on CalculateHenckyStrain --- .../test_stress_strain_utitlities.cpp | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp b/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp index 6ae98ed083d0..fe6b32a2486e 100644 --- a/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp +++ b/applications/GeoMechanicsApplication/tests/cpp_tests/test_stress_strain_utitlities.cpp @@ -161,11 +161,12 @@ KRATOS_TEST_CASE_IN_SUITE(CheckCalculateStrains, KratosGeoMechanicsFastSuite) Bs.push_back(B); Bs.push_back(B); - std::vector deformationGradients; - deformationGradients.push_back(B); - deformationGradients.push_back(B); + std::vector deformation_gradients; + Matrix deformation_gradient = std::sqrt(3.) * IdentityMatrix(3); + deformation_gradients.push_back(deformation_gradient); + deformation_gradients.push_back(deformation_gradient); - auto strains = StressStrainUtilities::CalculateStrains(deformationGradients, Bs, displacements, + auto strains = StressStrainUtilities::CalculateStrains(deformation_gradients, Bs, displacements, use_hencky_strain, voigt_size); Vector expected_strain(4); expected_strain <<= 0.3, 0.13, 0.08, 0.2; @@ -176,12 +177,17 @@ KRATOS_TEST_CASE_IN_SUITE(CheckCalculateStrains, KratosGeoMechanicsFastSuite) for (size_t i = 0; i < strains.size(); ++i) KRATOS_EXPECT_VECTOR_NEAR(strains[i], expected_strains[i], 1.E-10); - /* use_hencky_strain = true; - strains = StressStrainUtilities::CalculateStrains(deformationGradients, Bs, displacements, - use_hencky_strain, voigt_size); - for (size_t i = 0; i < strains.size(); ++i) - KRATOS_EXPECT_VECTOR_NEAR(strains[i], expected_strains[i], 1.E-10); - */ + use_hencky_strain = true; + strains = StressStrainUtilities::CalculateStrains(deformation_gradients, Bs, displacements, + use_hencky_strain, voigt_size); + + expected_strain <<= 0.549306, 0.549306, 0.549306, 0; + expected_strains.clear(); + expected_strains.push_back(expected_strain); + expected_strains.push_back(expected_strain); + + for (size_t i = 0; i < strains.size(); ++i) + KRATOS_EXPECT_VECTOR_NEAR(strains[i], expected_strains[i], 1.E-6); } } // namespace Kratos::Testing \ No newline at end of file