-
Notifications
You must be signed in to change notification settings - Fork 249
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
[GeoMechanicsApplication] Reduce use of ElementVariables in element strain vector calculations #12361
Conversation
…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
…train-vector-calculations
…trix, displacements and UseHenckyStrainFlag instead of using ElementVariables
…b matrix, displacements and UseHenckyStrainFlag instead of using ElementVariables
…train-vector-calculations
There was a problem hiding this 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.
if (UseHenckyStrain) { | ||
return StressStrainUtilities::CalculateHenckyStrain(rDeformationGradient, VoigtSize); | ||
} else { | ||
this->CalculateCauchyStrain(rVariables); | ||
return this->CalculateCauchyStrain(rB, rDisplacements); | ||
} | ||
} |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, makes it cleaner!
virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements); | ||
virtual Vector CalculateStrain(const Matrix& rDeformationGradient, | ||
const Matrix& rB, | ||
const Vector& rDisplacements, | ||
bool UseHenckyStrain); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
} else { | ||
this->CalculateCauchyStrain(rVariables); | ||
return this->CalculateCauchyStrain(rB, rDisplacements); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
virtual Vector CalculateCauchyStrain(const Matrix& rB, const Vector& rDisplacements); | ||
virtual Vector CalculateStrain(const Matrix& rDeformationGradient, | ||
const Matrix& rB, | ||
const Vector& rDisplacements, | ||
bool UseHenckyStrain); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go.
📝 Description
This PR changes the signature of the
CalculateStrain
andCalculateCauchyStrain
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