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] Reduce use of ElementVariables in element strain vector calculations #12361

Merged
merged 12 commits into from
May 10, 2024

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented May 8, 2024

📝 Description
This PR changes the signature of the CalculateStrain and CalculateCauchyStrain functions, so they no longer use ElementVariables for their in-/outputs. It introduces a bit of duplications, but that will be removed when we create lists for these inputs in later PRs. It was decided to create this PR now, since it is very narrowly scoped and therefore (hopefully) easy to review

rfaasse added 9 commits May 7, 2024 11:11
…Strain` to return a vector and takes relevant inputs instead of variables
…rn a vector and takes relevant inputs instead of variables
…) to return a vector instead of using the ElementVariables
…rmation gradient, instead of getting it from ElementVariables
…deformation gradient, instead of getting it from ElementVariables
…trix, displacements and UseHenckyStrainFlag instead of using ElementVariables
…b matrix, displacements and UseHenckyStrainFlag instead of using ElementVariables
@rfaasse rfaasse marked this pull request as ready for review May 8, 2024 12:18
@rfaasse rfaasse requested review from WPK4FEM, avdg81 and markelov208 May 8, 2024 12:18
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'm very satisfied with this clean-up action. In particular, I like that you have improved the function signatures (adding a proper return type and using specific function parameters rather than the ElementVariables container). Thank you for making these changes.

I have a few minor suggestions, none of them are blocking.

Comment on lines 1593 to 1598
if (UseHenckyStrain) {
return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize);
} else {
this->CalculateCauchyStrain(rVariables);
return this->CalculateCauchyStrain(rB, rDisplacements);
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We could simplify this even further by either using the ternary operator or by removing the explicit else keyword:

return UseHenckyStrain ? StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize)
                       : this->CalculateCauchyStrain(rB, rDisplacements);

Or, if that is too compact, use this:

if (UseHenckyStrain) {
    return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize);
}

return this->CalculateCauchyStrain(rB, rDisplacements);

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, makes it cleaner!

Comment on lines 279 to 283
virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements);
virtual Vector CalculateStrain(const Matrix& rDeformationGradient,
const Matrix& rB,
const Vector& rDisplacements,
bool UseHenckyStrain);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to make these member functions const, to express that they won't modify the element's state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 2095 to 2098
} else {
this->CalculateCauchyStrain(rVariables);
return this->CalculateCauchyStrain(rB, rDisplacements);
}
}
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 case of the small strain U-Pw element, I would remove the explicit else here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 297 to 301
virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements);
virtual Vector CalculateStrain(const Matrix& rDeformationGradient,
const Matrix& rB,
const Vector& rDisplacements,
bool UseHenckyStrain);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would like to suggest to make these member functions const.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@rfaasse rfaasse changed the title Geo/12319 extract strain vector calculations [GeoMechanicsApplication] Extract strain vector calculations May 8, 2024
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, thank you for this PR, it became more visible what should be defined and removed unnecessary actions. I have only general questions.

@@ -144,7 +144,10 @@ void UPwSmallStrainFICElement<TDim, TNumNodes>::InitializeNonLinearIteration(con
Variables.B = b_matrices[GPoint];

// Compute infinitessimal strain
this->CalculateStrain(Variables, GPoint);
Variables.F = this->CalculateDeformationGradient(GPoint);
Variables.detF = MathUtils<>::Det(Variables.F);
Copy link
Contributor

@markelov208 markelov208 May 8, 2024

Choose a reason for hiding this comment

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

I was wondering, putting this line into SetConstitutiveParameters function violates the title of this function? If not, then some duplications will go out now.
A general question is why some CalculateOnIntegrationPoints function call SetConstitutiveParameters when others do not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed we add a bit of extra duplication in this PR, it's a bit of a trade-off with limiting the use of the ElementVariables container. Since the Variables.F is used in the strain vector calculation and passed on to the constitutive parameters, I think it's better to keep it explicit like it is now.

In a next PR, which is now still in draft status, lists are extracted for F, detF and the strain vectors (see https://github.com/KratosMultiphysics/Kratos/pull/12363/files#diff-5a457c1c0c5d61a1ff97989e636c83f79506ea59254d16659303b48efde6f3cbR318-R333). I think that state is acceptable, especially since it becomes clearer and clearer who uses what (instead of everyone grabbing anything out of the ElementVariables bucket). I'm curious to know your opinion on this!

As for the question of when do/don't we use SetConstitutiveParameters: I think that depends on what we are actually calculating on the integration points. E.g. when just calculating the StrainVector, we don't need to use the constitutive law. However, if we want to convert that strain to a stress vector and generate that as an output, we do need to set the constitutive parameters.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hi Richard, thank you for the info. My message is not clear, probably, because it was done in the late evening. ;) My comment was on moving Variables.detF = MathUtils<>::Det(Variables.F); to SetConstitutiveParameters . It is clear that everything will change soon.
Concerning the next PR, it seems these functions are the same on the first glance. If it is true then they should be in utilities.

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.

This is a clear step towards getting rid of the bucket Variables.
The apparent increased line count ( caused by the explicit initialization of Variables.F, Variables.DetF etc. will disappear by the time that the bucket Variables is removed.

Your action also makes clear that the strain computation is a general continuum strain and not very element specific here.

Comment on lines 1588 to 1604
Vector UPwSmallStrainElement<TDim, TNumNodes>::CalculateStrain(const Matrix& rDeformationGradient,
const Matrix& rB,
const Vector& rDisplacements,
bool UseHenckyStrain)
{
if (rVariables.UseHenckyStrain) {
rVariables.F = this->CalculateDeformationGradient(GPoint);
rVariables.detF = MathUtils<>::Det(rVariables.F);
noalias(rVariables.StrainVector) = StressStrainUtilities::CalculateHenckyStrain(rVariables.F, VoigtSize);
if (UseHenckyStrain) {
return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize);
} else {
this->CalculateCauchyStrain(rVariables);
return this->CalculateCauchyStrain(rB, rDisplacements);
}
}

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateCauchyStrain(ElementVariables& rVariables)
Vector UPwSmallStrainElement<TDim, TNumNodes>::CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements)
{
noalias(rVariables.StrainVector) = prod(rVariables.B, rVariables.DisplacementVector);
return prod(rB, rDisplacements);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

With the argument lists showing precisely what is being used, it also becomes clear that also CalculateCauchyStrain is not element specific. It is always B * u and can be done in the stress strain utilities.
When VoigtSize is an argument of CalculateStrain, it can also be moved to the stress strain utilities.

What I did not check is whether the current member functions are part of the element base class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, we discussed this and agreed to leave these functions in place for this PR, but agreed that since this does not have any element-specific behavior, it should move to the stress strain utils (of course with UTs).

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

Good to go.

@rfaasse rfaasse changed the title [GeoMechanicsApplication] Extract strain vector calculations [GeoMechanicsApplication] Reduce use of ElementVariables in element strain vector calculations May 10, 2024
@rfaasse rfaasse merged commit dd52469 into master May 10, 2024
11 checks passed
@rfaasse rfaasse deleted the geo/12319-extract-strain-vector-calculations branch May 10, 2024 11:30
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