Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GeoMechanicsApplication] extract SetConstitutiveParameters function #12382

Merged
merged 11 commits into from
May 17, 2024

Conversation

markelov208
Copy link
Contributor

@markelov208 markelov208 commented May 14, 2024

📝 Description

  • SetConstitutiveParameters function is moved to ConstitutiveLawUtilities
  • A unit test is added.

Gennady Markelov added 2 commits May 14, 2024 16:12
…or small_strain_U_Pw_diff_order_element and U_Pw_small_strain_element
@markelov208 markelov208 requested review from avdg81 and rfaasse and removed request for a team, avdg81 and rfaasse May 14, 2024 19:13
@markelov208 markelov208 requested review from rfaasse and avdg81 May 14, 2024 21:41
@rfaasse
Copy link
Contributor

rfaasse commented May 15, 2024

@markelov208 This looks like a very useful PR. However, it will give quite some merge conflicts with my current attempt to extract the constitutive matrix. Could we wait with merging this one until that has gone back (since you are also waiting for that one for the stiffness matrix)?

@markelov208
Copy link
Contributor Author

@markelov208 This looks like a very useful PR. However, it will give quite some merge conflicts with my current attempt to extract the constitutive matrix. Could we wait with merging this one until that has gone back (since you are also waiting for that one for the stiffness matrix)?

Sure, we can wait.

Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yet another PR that cleans up our code. What I like most about this PR is that the new interface is explicit about which parameters will be set, rather than giving it a data structure without knowing which members will be used. As before, I only have a few minor suggestions.

Comment on lines 27 to 29
strain_vector(0) = 1.0;
strain_vector(1) = 2.0;
strain_vector(2) = 3.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As for the other PR I have reviewed today, I would suggest to use the concise notation for assigning values to a vector (after including boost/numeric/ublas/assignment.hpp):

Suggested change
strain_vector(0) = 1.0;
strain_vector(1) = 2.0;
strain_vector(2) = 3.0;
strain_vector <<= 1.0, 2.0, 3.0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. fixed

Comment on lines 32 to 34
N(0) = 0.1;
N(1) = 0.2;
N(2) = 0.5;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And a similar change here:

Suggested change
N(0) = 0.1;
N(1) = 0.2;
N(2) = 0.5;
N <<= 0.1, 0.2, 0.5;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -24,6 +25,14 @@ class ConstitutiveLawUtilities
public:
static int GetStateVariableIndex(const Variable<double>& rThisVariable);

static void SetSixMechanicsConstitutiveParameters(ConstitutiveLaw::Parameters& rConstitutiveParameters,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps a name like SetConstitutiveParameters will also do?

Copy link
Contributor Author

@markelov208 markelov208 May 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Restored the old title. Agreed that the new title is not more informative.

Gennady Markelov added 2 commits May 15, 2024 17:04
# Conflicts:
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.hpp
@markelov208 markelov208 requested a review from avdg81 May 16, 2024 07:26
# Conflicts:
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_FIC_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_small_strain_interface_element.hpp
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_FIC_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/U_Pw_updated_lagrangian_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp
#	applications/GeoMechanicsApplication/custom_elements/updated_lagrangian_U_Pw_diff_order_element.cpp
@markelov208
Copy link
Contributor Author

@rfaasse , it looks that these changes are not needed any more due to your recent PR. Correct?

Copy link
Contributor

@rfaasse rfaasse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for extracting this function, again removing duplication!

It clashed a bit with the previous PR (sorry for the merge conflicts), but that also means that quite a few of the function calls are not necessary anymore after that commit. When looking at this PR, we only need to retain the places where previously this->SetConstitutiveParameters(Variables, ConstitutiveParameters); was called (right now we see that there are quite some lines added with respect to master).

Also we can use your new function in the CalculateAnyOfMaterialResponse function to make it shorter (both for diff order and non-diff order).

Please let me know if this is unclear (which I can imagine, because very specifically related to what I just merged).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear unit test! To reflect the name of the file it tests, we could also rename it to test_constitutive_law_utilities.cpp

@@ -26,4 +26,19 @@ int ConstitutiveLawUtilities::GetStateVariableIndex(const Variable<double>& rThi
return index - 1;
}

void ConstitutiveLawUtilities::SetConstitutiveParameters(ConstitutiveLaw::Parameters& rConstitutiveParameters,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice addition. I think it could also be used in the CalculateAnyOfMaterialResponse functions in the diff order and non-diff order elements!

Copy link
Contributor Author

@markelov208 markelov208 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for pointing. Added there.

Comment on lines 96 to 98
ConstitutiveLawUtilities::SetConstitutiveParameters(
ConstitutiveParameters, Variables.StrainVector, Variables.ConstitutiveMatrix,
Variables.Nu, Variables.DNu_DX, Variables.F, Variables.detF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call is no longer necessary, since the constitutive matrices are already calculated (they are only retrieved here from the vector).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -1353,6 +1363,9 @@ void SmallStrainUPwDiffOrderElement::CalculateMaterialStiffnessMatrix(MatrixType
Variables.F = deformation_gradients[GPoint];
Variables.StrainVector = strain_vectors[GPoint];
Variables.ConstitutiveMatrix = constitutive_matrices[GPoint];
ConstitutiveLawUtilities::SetConstitutiveParameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call is no longer necessary, since the constitutive matrices are already calculated (they are only retrieved here from the vector).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@@ -152,6 +153,9 @@ void UPwSmallStrainFICElement<TDim, TNumNodes>::InitializeNonLinearIteration(con
Variables.B = b_matrices[GPoint];
Variables.F = deformation_gradients[GPoint];
Variables.ConstitutiveMatrix = constitutive_matrices[GPoint];
ConstitutiveLawUtilities::SetConstitutiveParameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function call is no longer necessary, since the constitutive matrices are already calculated (they are only retrieved here from the vector). I think there will be only a few places left now after the changes of the PR for the lists of constitutive matrices. Basically everywhere we retrieve the Constitutive Matrix from a list (i.e. Variables.ConstitutiveMatrix = constitutive_matrices[GPoint];) we don't need this call anymore. I think it will be there in ~3 places for diff order and ~3 places for non-diff order.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. Removed in many places. But not all calls. ;)

@@ -169,8 +170,9 @@ void UPwSmallStrainElement<TDim, TNumNodes>::InitializeSolutionStep(const Proces
Variables.detF = determinants_of_deformation_gradients[GPoint];
Variables.StrainVector = strain_vectors[GPoint];

// Set Gauss points variables to constitutive law parameters
this->SetConstitutiveParameters(Variables, ConstitutiveParameters);
ConstitutiveLawUtilities::SetConstitutiveParameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call we need to retain, because the constitutive matrix was not calculated before the loop

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@@ -268,6 +270,9 @@ void UPwSmallStrainElement<TDim, TNumNodes>::InitializeNonLinearIteration(const
this->CalculateAnyOfMaterialResponse(deformation_gradients, ConstitutiveParameters,
Variables.NContainer, Variables.DN_DXContainer,
strain_vectors, mStressVector, constitutive_matrices);
ConstitutiveLawUtilities::SetConstitutiveParameters(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This we can also remove, because we already called CalculateAnyOfMaterialResponse

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

@markelov208 markelov208 requested a review from rfaasse May 17, 2024 09:41
Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no further comments. I believe this is ready to go. Thanks for the hard work Gennady!

@markelov208 markelov208 merged commit 4b60023 into master May 17, 2024
11 checks passed
@markelov208 markelov208 deleted the geo/extract-set-constitutive-parameters branch May 17, 2024 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Extract a static utility function for the calculation of the Stiffness Matrix (K)
3 participants