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 list for constitutive matrices and stress vectors #12380

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented May 14, 2024

📝 Description
This PR extracts lists for constitutive matrices and stress vectors. In doing so we add two identical functions to diff order and to the non-diff order element, but we reduce a lot of other duplicated code. If anyone has ideas how to extract something generic here, please let me know. I think it would mean we need to pass on the constitutive laws and maybe make a vector of constitutive parameters and pass that on to make a separate utility function, but that's open for discussion.

@rfaasse rfaasse changed the title Geo/12319 extract list for constitutive matrices and stress vectors [GeoMechanicsApplication] Extract list for constitutive matrices and stress vectors May 15, 2024
@@ -1943,6 +1887,37 @@ Vector UPwSmallStrainElement<TDim, TNumNodes>::GetPressureSolutionVector()
return result;
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::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.

I know that we have two identical functions now for small strain and for diff order, but I still think in total we remove more duplication than we added and the duplication is a lot more localized now.

Comment on lines 470 to 471
GeoElementUtilities::CalculateNuMatrix<TDim, TNumNodes>(Variables.Nu, Variables.NContainer, GPoint);
GeoElementUtilities::InterpolateVariableWithComponents<TDim, TNumNodes>(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We checked that these functions don't change anything that the constitutive law uses (i.e. only Nu, while the constitutive law uses Np). Since we changed the order here, I'd like to double check with you: do you think this is correct @WPK4FEM?

Copy link
Contributor

Choose a reason for hiding this comment

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

When there is a difference between Nu and Np ( e.g. for reason of different interpolation orders of u and Pw ) the constitutive law ( relation between strain and stress ) should be using Nu. For same order interpolation Nu and Np will be equal, still the correct one should be used.

…ist-for-constitutive-matrices-and-stress-vectors
@rfaasse rfaasse marked this pull request as ready for review May 15, 2024 15:07
@rfaasse rfaasse requested review from WPK4FEM, avdg81 and markelov208 May 15, 2024 15:07
deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain);
std::vector<Matrix> constitutive_matrices;
this->CalculateAnyOfMaterialResponse(deformation_gradients, ConstitutiveParameters,
Copy link
Contributor

Choose a reason for hiding this comment

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

At very first sight this function name is not very descriptive for me. I have to learn what it does reading the function itself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, I was struggling with the name. Would CalculateAnyOfStressesStrainsOrConstitutiveMatrices be better?

Comment on lines 470 to 471
GeoElementUtilities::CalculateNuMatrix<TDim, TNumNodes>(Variables.Nu, Variables.NContainer, GPoint);
GeoElementUtilities::InterpolateVariableWithComponents<TDim, TNumNodes>(
Copy link
Contributor

Choose a reason for hiding this comment

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

When there is a difference between Nu and Np ( e.g. for reason of different interpolation orders of u and Pw ) the constitutive law ( relation between strain and stress ) should be using Nu. For same order interpolation Nu and Np will be equal, still the correct one should be used.

rConstitutiveParameters.SetStrainVector(rStrainVectors[GPoint]);
rConstitutiveParameters.SetShapeFunctionsDerivatives(rDNu_DXContainer[GPoint]);
rConstitutiveParameters.SetShapeFunctionsValues(row(rNuContainer, GPoint));
rConstitutiveParameters.SetDeterminantF(determinants_of_deformation_gradients[GPoint]);
Copy link
Contributor

Choose a reason for hiding this comment

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

A more logical order would be SetDeformationGradientF ( as F is the DeformationGradient, this is a repeat ) followed by SetDeterminantF ( which then would have had the expected name SetDeterminantDeformationGradientF ).
When F is given DetF could be computed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the order

///
/// \brief This function calculates the constitutive matrices, stresses and strains depending on the
/// constitutive parameters. Note that depending on the settings in the rConstitutiveParameters
/// the function could calculate the stress, the constitutive matrix, the strains, or a combination.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at 1896 of the corresponding cpp file, the strain is given. The implementation of CalculateMaterialResponseCauchy may decide to recompute ( for reasons of a different strain measure ) also the constitutive tensor and stress have their own steering through rConsitutiveParameters.GetOptions()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The strain is only given because we always use the line ConstitutiveParameters.Set(ConstitutiveLaw::USE_ELEMENT_PROVIDED_STRAIN); on the ConstitutiveLaw::Parameters we pass to this function. If we don't the strain could actually be calculated by the constitutive law. Therefore, rStrainVectors is a non-const&, because at this point the function is generic and at this point I'd like this to work with any ConstitutiveLaw::Parameters and any constitutive law

{
std::vector<Matrix> result;
const SizeType VoigtSize =
(GetGeometry().WorkingSpaceDimension() == 3 ? VOIGT_SIZE_3D : VOIGT_SIZE_2D_PLANE_STRAIN);
Copy link
Contributor

Choose a reason for hiding this comment

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

Are the ( ) necessary to encapsulate the ternary operator?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, removed!

@@ -1932,6 +1876,37 @@ Vector UPwSmallStrainElement<TDim, TNumNodes>::GetPressureSolutionVector()
return result;
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateAnyOfMaterialResponse(
Copy link
Contributor

Choose a reason for hiding this comment

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

For the naming of this function, it computes the indicated things for all i.p.
In other cases we indicated that with a trailing s. That can be done here too: CalculateMaterialResponses

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, either this, or we rename to something like CalculateAnyOfStressesStrainsOrConstitutiveMatrices (see other comment)

rfaasse added 3 commits May 16, 2024 10:30
…assume any of the stress, strain or matrices vector could be empty or filled and initialized variable_index to fix pipeline build
…ist-for-constitutive-matrices-and-stress-vectors
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.

Thank you very much for this great effort to compute the constitutive matrices in advance. That was definitely not an easy task, since the code was strongly coupled. As far as I can see you have done an excellent job. I only have a few minor comments and questions. None of them are blocking in my opinion.

Copy link
Contributor

@markelov208 markelov208 left a comment

Choose a reason for hiding this comment

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

Richard, a very useful step to improve the structure and to make functions more uniform. However, for my understand of the code it will be useful to split CalculateAnyOfMaterialResponse into three functions. What is your opinion? It can be next PR.

@rfaasse
Copy link
Contributor Author

rfaasse commented May 16, 2024

Richard, a very useful step to improve the structure and to make functions more uniform. However, for my understand of the code it will be useful to split CalculateAnyOfMaterialResponse into three functions. What is your opinion? It can be next PR.

@markelov208 I fully agree with this observation and would have preferred 3 functions as well (I would really like to decouple this). However, we are bound by the Constitutive Law interface which does all three at the same time in the CalculateMaterialResponseCauchy via the ConstitutiveLaw::Parameters&, so at this moment, I don't see a way to achieve this without doing the same calculation multiple times.

@rfaasse rfaasse requested a review from avdg81 May 16, 2024 12:02
@rfaasse rfaasse requested review from WPK4FEM and markelov208 May 16, 2024 12:02
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.

This looks good to go for me.

Copy link
Contributor

@WPK4FEM WPK4FEM left a comment

Choose a reason for hiding this comment

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

Looks consistent and is a step towards understandable code in the elements

@rfaasse rfaasse merged commit d759e7f into master May 16, 2024
11 checks passed
@rfaasse rfaasse deleted the geo/12319-extract-list-for-constitutive-matrices-and-stress-vectors branch May 16, 2024 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants